public static class McpServer.AsyncSpecification
extends java.lang.Object
限定符和类型 | 方法和说明 |
---|---|
McpAsyncServer |
build()
Builds an asynchronous MCP server that provides non-blocking operations.
|
McpServer.AsyncSpecification |
capabilities(McpSchema.ServerCapabilities serverCapabilities)
Sets the server capabilities that will be advertised to clients during
connection initialization.
|
McpServer.AsyncSpecification |
objectMapper(com.fasterxml.jackson.databind.ObjectMapper objectMapper)
Sets the object mapper to use for serializing and deserializing JSON messages.
|
McpServer.AsyncSpecification |
prompts(java.util.List<McpServerFeatures.AsyncPromptSpecification> prompts)
Registers multiple prompts with their handlers using a List.
|
McpServer.AsyncSpecification |
prompts(java.util.Map<java.lang.String,McpServerFeatures.AsyncPromptSpecification> prompts)
Registers multiple prompts with their handlers using a Map.
|
McpServer.AsyncSpecification |
prompts(McpServerFeatures.AsyncPromptSpecification... prompts)
Registers multiple prompts with their handlers using varargs.
|
McpServer.AsyncSpecification |
resources(java.util.List<McpServerFeatures.AsyncResourceSpecification> resourceSpecifications)
Registers multiple resources with their handlers using a List.
|
McpServer.AsyncSpecification |
resources(java.util.Map<java.lang.String,McpServerFeatures.AsyncResourceSpecification> resourceSpecifications)
Registers multiple resources with their handlers using a Map.
|
McpServer.AsyncSpecification |
resources(McpServerFeatures.AsyncResourceSpecification... resourceSpecifications)
Registers multiple resources with their handlers using varargs.
|
McpServer.AsyncSpecification |
resourceTemplates(java.util.List<McpServerFeatures.AsyncResourceTemplateSpecification> resourceTemplates)
Sets the resource templates that define patterns for dynamic resource access.
|
McpServer.AsyncSpecification |
resourceTemplates(McpServerFeatures.AsyncResourceTemplateSpecification... resourceTemplates)
Sets the resource templates using varargs for convenience.
|
McpServer.AsyncSpecification |
rootsChangeHandler(java.util.function.BiFunction<McpAsyncServerExchange,java.util.List<McpSchema.Root>,reactor.core.publisher.Mono<java.lang.Void>> handler)
Registers a consumer that will be notified when the list of roots changes.
|
McpServer.AsyncSpecification |
rootsChangeHandlers(java.util.function.BiFunction<McpAsyncServerExchange,java.util.List<McpSchema.Root>,reactor.core.publisher.Mono<java.lang.Void>>... handlers)
Registers multiple consumers that will be notified when the list of roots
changes using varargs.
|
McpServer.AsyncSpecification |
rootsChangeHandlers(java.util.List<java.util.function.BiFunction<McpAsyncServerExchange,java.util.List<McpSchema.Root>,reactor.core.publisher.Mono<java.lang.Void>>> handlers)
Registers multiple consumers that will be notified when the list of roots
changes.
|
McpServer.AsyncSpecification |
serverInfo(McpSchema.Implementation serverInfo)
Sets the server implementation information that will be shared with clients
during connection initialization.
|
McpServer.AsyncSpecification |
serverInfo(java.lang.String name,
java.lang.String version)
Sets the server implementation information using name and version strings.
|
McpServer.AsyncSpecification |
tool(McpSchema.Tool tool,
java.util.function.BiFunction<McpAsyncServerExchange,java.util.Map<java.lang.String,java.lang.Object>,reactor.core.publisher.Mono<McpSchema.CallToolResult>> handler)
Adds a single tool with its implementation handler to the server.
|
McpServer.AsyncSpecification |
tools(java.util.List<McpServerFeatures.AsyncToolSpecification> toolSpecifications)
Adds multiple tools with their handlers to the server using a List.
|
McpServer.AsyncSpecification |
tools(McpServerFeatures.AsyncToolSpecification... toolSpecifications)
Adds multiple tools with their handlers to the server using varargs.
|
public McpServer.AsyncSpecification serverInfo(McpSchema.Implementation serverInfo)
serverInfo
- The server implementation details including name and version.
Must not be null.java.lang.IllegalArgumentException
- if serverInfo is nullpublic McpServer.AsyncSpecification serverInfo(java.lang.String name, java.lang.String version)
serverInfo(McpSchema.Implementation)
.name
- The server name. Must not be null or empty.version
- The server version. Must not be null or empty.java.lang.IllegalArgumentException
- if name or version is null or emptyserverInfo(McpSchema.Implementation)
public McpServer.AsyncSpecification capabilities(McpSchema.ServerCapabilities serverCapabilities)
serverCapabilities
- The server capabilities configuration. Must not be
null.java.lang.IllegalArgumentException
- if serverCapabilities is nullpublic McpServer.AsyncSpecification tool(McpSchema.Tool tool, java.util.function.BiFunction<McpAsyncServerExchange,java.util.Map<java.lang.String,java.lang.Object>,reactor.core.publisher.Mono<McpSchema.CallToolResult>> handler)
McpServerFeatures.AsyncToolSpecification
explicitly.
Example usage:
.tool(
new Tool("calculator", "Performs calculations", schema),
(exchange, args) -> Mono.fromSupplier(() -> calculate(args))
.map(result -> new CallToolResult("Result: " + result))
)
tool
- The tool definition including name, description, and schema. Must
not be null.handler
- The function that implements the tool's logic. Must not be null.
The function's first argument is an McpAsyncServerExchange
upon which
the server can interact with the connected client. The second argument is the
map of arguments passed to the tool.java.lang.IllegalArgumentException
- if tool or handler is nullpublic McpServer.AsyncSpecification tools(java.util.List<McpServerFeatures.AsyncToolSpecification> toolSpecifications)
toolSpecifications
- The list of tool specifications to add. Must not be
null.java.lang.IllegalArgumentException
- if toolSpecifications is nulltools(McpServerFeatures.AsyncToolSpecification...)
public McpServer.AsyncSpecification tools(McpServerFeatures.AsyncToolSpecification... toolSpecifications)
Example usage:
.tools(
new McpServerFeatures.AsyncToolSpecification(calculatorTool, calculatorHandler),
new McpServerFeatures.AsyncToolSpecification(weatherTool, weatherHandler),
new McpServerFeatures.AsyncToolSpecification(fileManagerTool, fileManagerHandler)
)
toolSpecifications
- The tool specifications to add. Must not be null.java.lang.IllegalArgumentException
- if toolSpecifications is nulltools(List)
public McpServer.AsyncSpecification resources(java.util.Map<java.lang.String,McpServerFeatures.AsyncResourceSpecification> resourceSpecifications)
resourceSpecifications
- Map of resource name to specification. Must not
be null.java.lang.IllegalArgumentException
- if resourceSpecifications is nullresources(McpServerFeatures.AsyncResourceSpecification...)
public McpServer.AsyncSpecification resources(java.util.List<McpServerFeatures.AsyncResourceSpecification> resourceSpecifications)
resourceSpecifications
- List of resource specifications. Must not be
null.java.lang.IllegalArgumentException
- if resourceSpecifications is nullresources(McpServerFeatures.AsyncResourceSpecification...)
public McpServer.AsyncSpecification resources(McpServerFeatures.AsyncResourceSpecification... resourceSpecifications)
Example usage:
.resources(
new McpServerFeatures.AsyncResourceSpecification(fileResource, fileHandler),
new McpServerFeatures.AsyncResourceSpecification(dbResource, dbHandler),
new McpServerFeatures.AsyncResourceSpecification(apiResource, apiHandler)
)
resourceSpecifications
- The resource specifications to add. Must not be
null.java.lang.IllegalArgumentException
- if resourceSpecifications is nullpublic McpServer.AsyncSpecification resourceTemplates(java.util.List<McpServerFeatures.AsyncResourceTemplateSpecification> resourceTemplates)
Example usage:
.resourceTemplates(
new ResourceTemplate("file://{path}", "Access files by path"),
new ResourceTemplate("db://{table}/{id}", "Access database records")
)
resourceTemplates
- List of resource templates. If null, clears existing
templates.java.lang.IllegalArgumentException
- if resourceTemplates is null.resourceTemplates(McpServerFeatures.AsyncResourceTemplateSpecification...)
public McpServer.AsyncSpecification resourceTemplates(McpServerFeatures.AsyncResourceTemplateSpecification... resourceTemplates)
resourceTemplates(List)
.resourceTemplates
- The resource templates to set.java.lang.IllegalArgumentException
- if resourceTemplates is null.resourceTemplates(List)
public McpServer.AsyncSpecification prompts(java.util.Map<java.lang.String,McpServerFeatures.AsyncPromptSpecification> prompts)
Example usage:
.prompts(Map.of("analysis", new McpServerFeatures.AsyncPromptSpecification(
new Prompt("analysis", "Code analysis template"),
request -> Mono.fromSupplier(() -> generateAnalysisPrompt(request))
.map(GetPromptResult::new)
)));
prompts
- Map of prompt name to specification. Must not be null.java.lang.IllegalArgumentException
- if prompts is nullpublic McpServer.AsyncSpecification prompts(java.util.List<McpServerFeatures.AsyncPromptSpecification> prompts)
prompts
- List of prompt specifications. Must not be null.java.lang.IllegalArgumentException
- if prompts is nullprompts(McpServerFeatures.AsyncPromptSpecification...)
public McpServer.AsyncSpecification prompts(McpServerFeatures.AsyncPromptSpecification... prompts)
Example usage:
.prompts(
new McpServerFeatures.AsyncPromptSpecification(analysisPrompt, analysisHandler),
new McpServerFeatures.AsyncPromptSpecification(summaryPrompt, summaryHandler),
new McpServerFeatures.AsyncPromptSpecification(reviewPrompt, reviewHandler)
)
prompts
- The prompt specifications to add. Must not be null.java.lang.IllegalArgumentException
- if prompts is nullpublic McpServer.AsyncSpecification rootsChangeHandler(java.util.function.BiFunction<McpAsyncServerExchange,java.util.List<McpSchema.Root>,reactor.core.publisher.Mono<java.lang.Void>> handler)
handler
- The handler to register. Must not be null. The function's first
argument is an McpAsyncServerExchange
upon which the server can
interact with the connected client. The second argument is the list of roots.java.lang.IllegalArgumentException
- if consumer is nullpublic McpServer.AsyncSpecification rootsChangeHandlers(java.util.List<java.util.function.BiFunction<McpAsyncServerExchange,java.util.List<McpSchema.Root>,reactor.core.publisher.Mono<java.lang.Void>>> handlers)
handlers
- The list of handlers to register. Must not be null.java.lang.IllegalArgumentException
- if consumers is nullrootsChangeHandler(BiFunction)
public McpServer.AsyncSpecification rootsChangeHandlers(java.util.function.BiFunction<McpAsyncServerExchange,java.util.List<McpSchema.Root>,reactor.core.publisher.Mono<java.lang.Void>>... handlers)
handlers
- The handlers to register. Must not be null.java.lang.IllegalArgumentException
- if consumers is nullrootsChangeHandlers(List)
public McpServer.AsyncSpecification objectMapper(com.fasterxml.jackson.databind.ObjectMapper objectMapper)
objectMapper
- the instance to use. Must not be null.java.lang.IllegalArgumentException
- if objectMapper is nullpublic McpAsyncServer build()
McpAsyncServer
configured with this builder's
settings.