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.SyncToolSpecification), addResource(io.modelcontextprotocol.server.McpServerFeatures.SyncResourceSpecification), and addPrompt(io.modelcontextprotocol.server.McpServerFeatures.SyncPromptSpecification), 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.SyncPromptSpecification promptSpecification)
Add a new prompt handler.
|
void |
addResource(McpServerFeatures.SyncResourceSpecification resourceHandler)
Add a new resource handler.
|
void |
addResourceTemplate(McpServerFeatures.SyncResourceTemplateSpecification resourceHandler)
Add a new resource template handler.
|
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.
|
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 |
removeResourceTemplate(String resourceUri)
Remove a resource template handler.
|
void |
removeTool(String toolName)
Remove a tool handler.
|
public McpSyncServer(McpAsyncServer asyncServer)
asyncServer - The async server to wrappublic void addTool(McpServerFeatures.SyncToolSpecification toolHandler)
toolHandler - The tool handler to addpublic void removeTool(String toolName)
toolName - The name of the tool handler to removepublic void addResource(McpServerFeatures.SyncResourceSpecification resourceHandler)
resourceHandler - The resource handler to addpublic void removeResource(String resourceUri)
resourceUri - The URI of the resource handler to removepublic void addResourceTemplate(McpServerFeatures.SyncResourceTemplateSpecification resourceHandler)
resourceHandler - The resource handler to addpublic void removeResourceTemplate(String resourceUri)
resourceUri - The URI of the resource template handler to removepublic 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.