public class McpSyncClient extends Object implements AutoCloseable
McpAsyncClient to provide blocking operations.
This client implements the MCP specification by delegating to an asynchronous client and blocking on the results. Key features include:
The client follows the same lifecycle as its async counterpart:
This implementation implements AutoCloseable for resource cleanup and provides
both immediate and graceful shutdown options. All operations block until completion or
timeout, making it suitable for traditional synchronous programming models.
McpClient,
McpAsyncClient,
McpSchema| Constructor and Description |
|---|
McpSyncClient(McpAsyncClient delegate)
Deprecated.
This method will be removed in 0.9.0. Use
McpClient.sync(McpClientTransport) to obtain an instance. |
| Modifier and Type | Method and Description |
|---|---|
void |
addRoot(McpSchema.Root root)
Add a roots dynamically.
|
McpSchema.CallToolResult |
callTool(McpSchema.CallToolRequest callToolRequest)
Calls a tool provided by the server.
|
void |
close() |
boolean |
closeGracefully() |
McpSchema.ClientCapabilities |
getClientCapabilities()
Get the client capabilities that define the supported features and functionality.
|
McpSchema.Implementation |
getClientInfo()
Get the client implementation information.
|
McpSchema.GetPromptResult |
getPrompt(McpSchema.GetPromptRequest getPromptRequest) |
McpSchema.ServerCapabilities |
getServerCapabilities()
Get the server capabilities that define the supported features and functionality.
|
McpSchema.Implementation |
getServerInfo()
Get the server implementation information.
|
McpSchema.InitializeResult |
initialize()
The initialization phase MUST be the first interaction between client and server.
|
boolean |
isInitialized()
Check if the client-server connection is initialized.
|
McpSchema.ListPromptsResult |
listPrompts() |
McpSchema.ListPromptsResult |
listPrompts(String cursor) |
McpSchema.ListResourcesResult |
listResources()
Send a resources/list request.
|
McpSchema.ListResourcesResult |
listResources(String cursor)
Send a resources/list request.
|
McpSchema.ListResourceTemplatesResult |
listResourceTemplates()
Request a list of resource templates the server has.
|
McpSchema.ListResourceTemplatesResult |
listResourceTemplates(String cursor)
Resource templates allow servers to expose parameterized resources using URI
templates.
|
McpSchema.ListToolsResult |
listTools()
Retrieves the list of all tools provided by the server.
|
McpSchema.ListToolsResult |
listTools(String cursor)
Retrieves a paginated list of tools provided by the server.
|
Object |
ping()
Send a synchronous ping request.
|
McpSchema.ReadResourceResult |
readResource(McpSchema.ReadResourceRequest readResourceRequest)
Send a resources/read request.
|
McpSchema.ReadResourceResult |
readResource(McpSchema.Resource resource)
Send a resources/read request.
|
void |
removeRoot(String rootUri)
Remove a root dynamically.
|
void |
rootsListChangedNotification()
Send a roots/list_changed notification.
|
void |
setLoggingLevel(McpSchema.LoggingLevel loggingLevel)
Client can set the minimum logging level it wants to receive from the server.
|
void |
subscribeResource(McpSchema.SubscribeRequest subscribeRequest)
Subscriptions.
|
void |
unsubscribeResource(McpSchema.UnsubscribeRequest unsubscribeRequest)
Send a resources/unsubscribe request.
|
@Deprecated public McpSyncClient(McpAsyncClient delegate)
McpClient.sync(McpClientTransport) to obtain an instance.delegate - the asynchronous kernel on top of which this synchronous client
provides a blocking API.public McpSchema.ServerCapabilities getServerCapabilities()
public McpSchema.Implementation getServerInfo()
public boolean isInitialized()
public McpSchema.ClientCapabilities getClientCapabilities()
public McpSchema.Implementation getClientInfo()
public void close()
close in interface AutoCloseablepublic boolean closeGracefully()
public McpSchema.InitializeResult initialize()
McpSchema.ServerCapabilities. public void rootsListChangedNotification()
public void addRoot(McpSchema.Root root)
public void removeRoot(String rootUri)
public Object ping()
public McpSchema.CallToolResult callTool(McpSchema.CallToolRequest callToolRequest)
callToolRequest - The request containing: - name: The name of the tool to call
(must match a tool name from tools/list) - arguments: Arguments that conform to the
tool's input schemapublic McpSchema.ListToolsResult listTools()
public McpSchema.ListToolsResult listTools(String cursor)
cursor - Optional pagination cursor from a previous list requestpublic McpSchema.ListResourcesResult listResources(String cursor)
cursor - the cursorpublic McpSchema.ListResourcesResult listResources()
public McpSchema.ReadResourceResult readResource(McpSchema.Resource resource)
resource - the resource to readpublic McpSchema.ReadResourceResult readResource(McpSchema.ReadResourceRequest readResourceRequest)
readResourceRequest - the read resource request.public McpSchema.ListResourceTemplatesResult listResourceTemplates(String cursor)
cursor - the cursorpublic McpSchema.ListResourceTemplatesResult listResourceTemplates()
public void subscribeResource(McpSchema.SubscribeRequest subscribeRequest)
subscribeRequest - the subscribe request contains the uri of the resource to
subscribe to.public void unsubscribeResource(McpSchema.UnsubscribeRequest unsubscribeRequest)
unsubscribeRequest - the unsubscribe request contains the uri of the resource
to unsubscribe from.public McpSchema.ListPromptsResult listPrompts(String cursor)
public McpSchema.ListPromptsResult listPrompts()
public McpSchema.GetPromptResult getPrompt(McpSchema.GetPromptRequest getPromptRequest)
public void setLoggingLevel(McpSchema.LoggingLevel loggingLevel)
loggingLevel - the min logging levelCopyright © 2025. All rights reserved.