public class McpSyncServer extends Object
McpAsyncServer to provide blocking operations. This class delegates all
operations to an underlying async server instance while providing a simpler,
synchronous API for scenarios where reactive programming is not required.
The MCP server enables AI models to expose tools, resources, and prompts through a standardized interface. Key features available through this synchronous API include:
While McpAsyncServer uses Project Reactor's Mono and Flux types for
non-blocking operations, this class converts those into blocking calls, making it more
suitable for:
The server supports runtime modification of its capabilities through methods like
addTool(io.modelcontextprotocol.server.McpServerFeatures.SyncToolRegistration), addResource(io.modelcontextprotocol.server.McpServerFeatures.SyncResourceRegistration), and addPrompt(io.modelcontextprotocol.server.McpServerFeatures.SyncPromptRegistration), automatically notifying
connected clients of changes when configured to do so.
McpAsyncServer,
McpSchema| Constructor and Description |
|---|
McpSyncServer(McpAsyncServer asyncServer)
Creates a new synchronous server that wraps the provided async server.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addPrompt(McpServerFeatures.SyncPromptRegistration promptRegistration)
Deprecated.
This method will be removed in 0.9.0. Use
addPrompt(McpServerFeatures.SyncPromptSpecification). |
void |
addPrompt(McpServerFeatures.SyncPromptSpecification promptSpecification)
Add a new prompt handler.
|
void |
addResource(McpServerFeatures.SyncResourceRegistration resourceHandler)
Deprecated.
This method will be removed in 0.9.0. Use
addResource(McpServerFeatures.SyncResourceSpecification). |
void |
addResource(McpServerFeatures.SyncResourceSpecification resourceHandler)
Add a new resource handler.
|
void |
addTool(McpServerFeatures.SyncToolRegistration toolHandler)
Deprecated.
This method will be removed in 0.9.0. Use
addTool(McpServerFeatures.SyncToolSpecification). |
void |
addTool(McpServerFeatures.SyncToolSpecification toolHandler)
Add a new tool handler.
|
void |
close()
Close the server immediately.
|
void |
closeGracefully()
Close the server gracefully.
|
McpSchema.CreateMessageResult |
createMessage(McpSchema.CreateMessageRequest createMessageRequest)
Deprecated.
This method will be removed in 0.9.0. Use
McpSyncServerExchange.createMessage(McpSchema.CreateMessageRequest). |
McpAsyncServer |
getAsyncServer()
Get the underlying async server instance.
|
McpSchema.ClientCapabilities |
getClientCapabilities()
Deprecated.
This method will be removed in 0.9.0. Use
McpSyncServerExchange.getClientCapabilities(). |
McpSchema.Implementation |
getClientInfo()
Deprecated.
This method will be removed in 0.9.0. Use
McpSyncServerExchange.getClientInfo(). |
McpSchema.ServerCapabilities |
getServerCapabilities()
Get the server capabilities that define the supported features and functionality.
|
McpSchema.Implementation |
getServerInfo()
Get the server implementation information.
|
McpSchema.ListRootsResult |
listRoots()
Deprecated.
This method will be removed in 0.9.0. Use
McpSyncServerExchange.listRoots(). |
McpSchema.ListRootsResult |
listRoots(String cursor)
Deprecated.
This method will be removed in 0.9.0. Use
McpSyncServerExchange.listRoots(String). |
void |
loggingNotification(McpSchema.LoggingMessageNotification loggingMessageNotification)
Send a logging message notification to all clients.
|
void |
notifyPromptsListChanged()
Notify clients that the list of available prompts has changed.
|
void |
notifyResourcesListChanged()
Notify clients that the list of available resources has changed.
|
void |
notifyToolsListChanged()
Notify clients that the list of available tools has changed.
|
void |
removePrompt(String promptName)
Remove a prompt handler.
|
void |
removeResource(String resourceUri)
Remove a resource handler.
|
void |
removeTool(String toolName)
Remove a tool handler.
|
public McpSyncServer(McpAsyncServer asyncServer)
asyncServer - The async server to wrap@Deprecated public McpSchema.ListRootsResult listRoots()
McpSyncServerExchange.listRoots().@Deprecated public McpSchema.ListRootsResult listRoots(String cursor)
McpSyncServerExchange.listRoots(String).cursor - Optional pagination cursor from a previous list request@Deprecated public void addTool(McpServerFeatures.SyncToolRegistration toolHandler)
addTool(McpServerFeatures.SyncToolSpecification).toolHandler - The tool handler to addpublic void addTool(McpServerFeatures.SyncToolSpecification toolHandler)
toolHandler - The tool handler to addpublic void removeTool(String toolName)
toolName - The name of the tool handler to remove@Deprecated public void addResource(McpServerFeatures.SyncResourceRegistration resourceHandler)
addResource(McpServerFeatures.SyncResourceSpecification).resourceHandler - The resource handler to addpublic void addResource(McpServerFeatures.SyncResourceSpecification resourceHandler)
resourceHandler - The resource handler to addpublic void removeResource(String resourceUri)
resourceUri - The URI of the resource handler to remove@Deprecated public void addPrompt(McpServerFeatures.SyncPromptRegistration promptRegistration)
addPrompt(McpServerFeatures.SyncPromptSpecification).promptRegistration - The prompt registration to addpublic void addPrompt(McpServerFeatures.SyncPromptSpecification promptSpecification)
promptSpecification - The prompt specification to addpublic void removePrompt(String promptName)
promptName - The name of the prompt handler to removepublic void notifyToolsListChanged()
public McpSchema.ServerCapabilities getServerCapabilities()
public McpSchema.Implementation getServerInfo()
@Deprecated public McpSchema.ClientCapabilities getClientCapabilities()
McpSyncServerExchange.getClientCapabilities().@Deprecated public McpSchema.Implementation getClientInfo()
McpSyncServerExchange.getClientInfo().public void notifyResourcesListChanged()
public void notifyPromptsListChanged()
public void loggingNotification(McpSchema.LoggingMessageNotification loggingMessageNotification)
loggingMessageNotification - The logging message notification to sendpublic void closeGracefully()
public void close()
public McpAsyncServer getAsyncServer()
@Deprecated public McpSchema.CreateMessageResult createMessage(McpSchema.CreateMessageRequest createMessageRequest)
McpSyncServerExchange.createMessage(McpSchema.CreateMessageRequest).This flow allows clients to maintain control over model access, selection, and permissions while enabling servers to leverage AI capabilities—with no server API keys necessary. Servers can request text or image-based interactions and optionally include context from MCP servers in their prompts.
Unlike its async counterpart, this method blocks until the message creation is complete, making it easier to use in synchronous code paths.
createMessageRequest - The request to create a new messageMcpError - if the client has not been initialized or does not support
sampling capabilitiesMcpError - if the client does not support the createMessage methodMcpSchema.CreateMessageRequest,
McpSchema.CreateMessageResult,
Sampling
SpecificationCopyright © 2025. All rights reserved.