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.
|
McpAsyncServer |
getAsyncServer()
Get the underlying async server instance.
|
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()
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()
Copyright © 2025. All rights reserved.