public class McpAsyncServer
extends java.lang.Object
This server implements the MCP specification, enabling AI models to expose tools, resources, and prompts through a standardized interface. Key features include:
The server follows a lifecycle:
This implementation uses Project Reactor for non-blocking operations, making it suitable for high-throughput scenarios and reactive applications. All operations return Mono or Flux types that can be composed into reactive pipelines.
The server supports runtime modification of its capabilities through methods like
addTool(io.modelcontextprotocol.server.McpServerFeatures.AsyncToolSpecification), addResource(io.modelcontextprotocol.server.McpServerFeatures.AsyncResourceSpecification), and addPrompt(io.modelcontextprotocol.server.McpServerFeatures.AsyncPromptSpecification), automatically notifying
connected clients of changes when configured to do so.
McpServer,
McpSchema,
McpClientSession| 限定符和类型 | 方法和说明 |
|---|---|
reactor.core.publisher.Mono<java.lang.Void> |
addPrompt(McpServerFeatures.AsyncPromptSpecification promptSpecification)
Add a new prompt handler at runtime.
|
reactor.core.publisher.Mono<java.lang.Void> |
addResource(McpServerFeatures.AsyncResourceSpecification resourceSpecification)
Add a new resource handler at runtime.
|
reactor.core.publisher.Mono<java.lang.Void> |
addResourceTemplate(McpServerFeatures.AsyncResourceTemplateSpecification resourceTemplateSpecification)
Add a new resource template at runtime.
|
reactor.core.publisher.Mono<java.lang.Void> |
addTool(McpServerFeatures.AsyncToolSpecification toolSpecification)
Add a new tool call specification at runtime.
|
void |
close()
Close the server immediately.
|
reactor.core.publisher.Mono<java.lang.Void> |
closeGracefully()
Gracefully closes the server, allowing any in-progress operations to complete.
|
McpSchema.ServerCapabilities |
getServerCapabilities()
Get the server capabilities that define the supported features and functionality.
|
McpSchema.Implementation |
getServerInfo()
Get the server implementation information.
|
reactor.core.publisher.Flux<McpSchema.Prompt> |
listPrompts()
List all registered prompts.
|
reactor.core.publisher.Flux<McpSchema.Resource> |
listResources()
List all registered resources.
|
reactor.core.publisher.Flux<McpSchema.ResourceTemplate> |
listResourceTemplates()
List all registered resource templates.
|
reactor.core.publisher.Flux<McpSchema.Tool> |
listTools()
List all registered tools.
|
reactor.core.publisher.Mono<java.lang.Void> |
loggingNotification(McpSchema.LoggingMessageNotification loggingMessageNotification)
已过时。
Use
McpAsyncServerExchange#loggingNotification(LoggingMessageNotification)
instead. |
reactor.core.publisher.Mono<java.lang.Void> |
notifyPromptsListChanged()
Notifies clients that the list of available prompts has changed.
|
reactor.core.publisher.Mono<java.lang.Void> |
notifyResourcesListChanged()
Notifies clients that the list of available resources has changed.
|
reactor.core.publisher.Mono<java.lang.Void> |
notifyResourcesUpdated(McpSchema.ResourcesUpdatedNotification resourcesUpdatedNotification)
Notifies clients that the resources have updated.
|
reactor.core.publisher.Mono<java.lang.Void> |
notifyToolsListChanged()
Notifies clients that the list of available tools has changed.
|
reactor.core.publisher.Mono<java.lang.Void> |
removePrompt(java.lang.String promptName)
Remove a prompt handler at runtime.
|
reactor.core.publisher.Mono<java.lang.Void> |
removeResource(java.lang.String resourceUri)
Remove a resource handler at runtime.
|
reactor.core.publisher.Mono<java.lang.Void> |
removeResourceTemplate(java.lang.String uriTemplate)
Remove a resource template at runtime.
|
reactor.core.publisher.Mono<java.lang.Void> |
removeTool(java.lang.String toolName)
Remove a tool handler at runtime.
|
public McpSchema.ServerCapabilities getServerCapabilities()
public McpSchema.Implementation getServerInfo()
public reactor.core.publisher.Mono<java.lang.Void> closeGracefully()
public void close()
public reactor.core.publisher.Mono<java.lang.Void> addTool(McpServerFeatures.AsyncToolSpecification toolSpecification)
toolSpecification - The tool specification to addpublic reactor.core.publisher.Flux<McpSchema.Tool> listTools()
public reactor.core.publisher.Mono<java.lang.Void> removeTool(java.lang.String toolName)
toolName - The name of the tool handler to removepublic reactor.core.publisher.Mono<java.lang.Void> notifyToolsListChanged()
public reactor.core.publisher.Mono<java.lang.Void> addResource(McpServerFeatures.AsyncResourceSpecification resourceSpecification)
resourceSpecification - The resource handler to addpublic reactor.core.publisher.Flux<McpSchema.Resource> listResources()
public reactor.core.publisher.Mono<java.lang.Void> removeResource(java.lang.String resourceUri)
resourceUri - The URI of the resource handler to removepublic reactor.core.publisher.Mono<java.lang.Void> addResourceTemplate(McpServerFeatures.AsyncResourceTemplateSpecification resourceTemplateSpecification)
resourceTemplateSpecification - The resource template to addpublic reactor.core.publisher.Flux<McpSchema.ResourceTemplate> listResourceTemplates()
public reactor.core.publisher.Mono<java.lang.Void> removeResourceTemplate(java.lang.String uriTemplate)
uriTemplate - The URI template of the resource template to removepublic reactor.core.publisher.Mono<java.lang.Void> notifyResourcesListChanged()
public reactor.core.publisher.Mono<java.lang.Void> notifyResourcesUpdated(McpSchema.ResourcesUpdatedNotification resourcesUpdatedNotification)
public reactor.core.publisher.Mono<java.lang.Void> addPrompt(McpServerFeatures.AsyncPromptSpecification promptSpecification)
promptSpecification - The prompt handler to addpublic reactor.core.publisher.Flux<McpSchema.Prompt> listPrompts()
public reactor.core.publisher.Mono<java.lang.Void> removePrompt(java.lang.String promptName)
promptName - The name of the prompt handler to removepublic reactor.core.publisher.Mono<java.lang.Void> notifyPromptsListChanged()
@Deprecated public reactor.core.publisher.Mono<java.lang.Void> loggingNotification(McpSchema.LoggingMessageNotification loggingMessageNotification)
McpAsyncServerExchange#loggingNotification(LoggingMessageNotification)
instead.loggingMessageNotification - The logging message to send