public abstract static class McpServer.AsyncSpecification<S extends McpServer.AsyncSpecification<S>>
extends java.lang.Object
构造器和说明 |
---|
AsyncSpecification() |
限定符和类型 | 方法和说明 |
---|---|
abstract McpAsyncServer |
build() |
McpServer.AsyncSpecification<S> |
capabilities(McpSchema.ServerCapabilities serverCapabilities)
Sets the server capabilities that will be advertised to clients during
connection initialization.
|
McpServer.AsyncSpecification<S> |
completions(java.util.List<McpServerFeatures.AsyncCompletionSpecification> completions)
Registers multiple completions with their handlers using a List.
|
McpServer.AsyncSpecification<S> |
completions(McpServerFeatures.AsyncCompletionSpecification... completions)
Registers multiple completions with their handlers using varargs.
|
McpServer.AsyncSpecification<S> |
instructions(java.lang.String instructions)
Sets the server instructions that will be shared with clients during connection
initialization.
|
McpServer.AsyncSpecification<S> |
jsonSchemaValidator(JsonSchemaValidator jsonSchemaValidator)
Sets the JSON schema validator to use for validating tool and resource schemas.
|
McpServer.AsyncSpecification<S> |
objectMapper(com.fasterxml.jackson.databind.ObjectMapper objectMapper)
Sets the object mapper to use for serializing and deserializing JSON messages.
|
McpServer.AsyncSpecification<S> |
prompts(java.util.List<McpServerFeatures.AsyncPromptSpecification> prompts)
Registers multiple prompts with their handlers using a List.
|
McpServer.AsyncSpecification<S> |
prompts(java.util.Map<java.lang.String,McpServerFeatures.AsyncPromptSpecification> prompts)
Registers multiple prompts with their handlers using a Map.
|
McpServer.AsyncSpecification<S> |
prompts(McpServerFeatures.AsyncPromptSpecification... prompts)
Registers multiple prompts with their handlers using varargs.
|
McpServer.AsyncSpecification<S> |
requestTimeout(java.time.Duration requestTimeout)
Sets the duration to wait for server responses before timing out requests.
|
McpServer.AsyncSpecification<S> |
resources(java.util.List<McpServerFeatures.AsyncResourceSpecification> resourceSpecifications)
Registers multiple resources with their handlers using a List.
|
McpServer.AsyncSpecification<S> |
resources(java.util.Map<java.lang.String,McpServerFeatures.AsyncResourceSpecification> resourceSpecifications)
Registers multiple resources with their handlers using a Map.
|
McpServer.AsyncSpecification<S> |
resources(McpServerFeatures.AsyncResourceSpecification... resourceSpecifications)
Registers multiple resources with their handlers using varargs.
|
McpServer.AsyncSpecification<S> |
resourceTemplates(java.util.List<McpSchema.ResourceTemplate> resourceTemplates)
Sets the resource templates that define patterns for dynamic resource access.
|
McpServer.AsyncSpecification<S> |
resourceTemplates(McpSchema.ResourceTemplate... resourceTemplates)
Sets the resource templates using varargs for convenience.
|
McpServer.AsyncSpecification<S> |
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<S> |
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<S> |
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<S> |
serverInfo(McpSchema.Implementation serverInfo)
Sets the server implementation information that will be shared with clients
during connection initialization.
|
McpServer.AsyncSpecification<S> |
serverInfo(java.lang.String name,
java.lang.String version)
Sets the server implementation information using name and version strings.
|
McpServer.AsyncSpecification<S> |
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)
已过时。
Use
toolCall(McpSchema.Tool, BiFunction) instead for tool
calls that require a request object. |
McpServer.AsyncSpecification<S> |
toolCall(McpSchema.Tool tool,
java.util.function.BiFunction<McpAsyncServerExchange,McpSchema.CallToolRequest,reactor.core.publisher.Mono<McpSchema.CallToolResult>> callHandler)
Adds a single tool with its implementation handler to the server.
|
McpServer.AsyncSpecification<S> |
tools(java.util.List<McpServerFeatures.AsyncToolSpecification> toolSpecifications)
Adds multiple tools with their handlers to the server using a List.
|
McpServer.AsyncSpecification<S> |
tools(McpServerFeatures.AsyncToolSpecification... toolSpecifications)
Adds multiple tools with their handlers to the server using varargs.
|
McpServer.AsyncSpecification<S> |
uriTemplateManagerFactory(McpUriTemplateManagerFactory uriTemplateManagerFactory)
Sets the URI template manager factory to use for creating URI templates.
|
public abstract McpAsyncServer build()
public McpServer.AsyncSpecification<S> uriTemplateManagerFactory(McpUriTemplateManagerFactory uriTemplateManagerFactory)
uriTemplateManagerFactory
- The factory to use. Must not be null.java.lang.IllegalArgumentException
- if uriTemplateManagerFactory is nullpublic McpServer.AsyncSpecification<S> requestTimeout(java.time.Duration requestTimeout)
requestTimeout
- The duration to wait before timing out requests. Must not
be null.java.lang.IllegalArgumentException
- if requestTimeout is nullpublic McpServer.AsyncSpecification<S> 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<S> 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<S> instructions(java.lang.String instructions)
instructions
- The instructions text. Can be null or empty.public McpServer.AsyncSpecification<S> capabilities(McpSchema.ServerCapabilities serverCapabilities)
serverCapabilities
- The server capabilities configuration. Must not be
null.java.lang.IllegalArgumentException
- if serverCapabilities is null@Deprecated public McpServer.AsyncSpecification<S> 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)
toolCall(McpSchema.Tool, BiFunction)
instead for tool
calls that require a request object.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<S> toolCall(McpSchema.Tool tool, java.util.function.BiFunction<McpAsyncServerExchange,McpSchema.CallToolRequest,reactor.core.publisher.Mono<McpSchema.CallToolResult>> callHandler)
McpServerFeatures.AsyncToolSpecification
explicitly.tool
- The tool definition including name, description, and schema. Must
not be null.callHandler
- 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 McpSchema.CallToolRequest
object containing the tool calljava.lang.IllegalArgumentException
- if tool or handler is nullpublic McpServer.AsyncSpecification<S> 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<S> tools(McpServerFeatures.AsyncToolSpecification... toolSpecifications)
Example usage:
.tools(
McpServerFeatures.AsyncToolSpecification.builder().tool(calculatorTool).callTool(calculatorHandler).build(),
McpServerFeatures.AsyncToolSpecification.builder().tool(weatherTool).callTool(weatherHandler).build(),
McpServerFeatures.AsyncToolSpecification.builder().tool(fileManagerTool).callTool(fileManagerHandler).build()
)
toolSpecifications
- The tool specifications to add. Must not be null.java.lang.IllegalArgumentException
- if toolSpecifications is nullpublic McpServer.AsyncSpecification<S> 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<S> 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<S> 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<S> resourceTemplates(java.util.List<McpSchema.ResourceTemplate> 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(ResourceTemplate...)
public McpServer.AsyncSpecification<S> resourceTemplates(McpSchema.ResourceTemplate... resourceTemplates)
resourceTemplates(List)
.resourceTemplates
- The resource templates to set.java.lang.IllegalArgumentException
- if resourceTemplates is null.resourceTemplates(List)
public McpServer.AsyncSpecification<S> 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<S> 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<S> 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<S> completions(java.util.List<McpServerFeatures.AsyncCompletionSpecification> completions)
completions
- List of completion specifications. Must not be null.java.lang.IllegalArgumentException
- if completions is nullpublic McpServer.AsyncSpecification<S> completions(McpServerFeatures.AsyncCompletionSpecification... completions)
completions
- Array of completion specifications. Must not be null.java.lang.IllegalArgumentException
- if completions is nullpublic McpServer.AsyncSpecification<S> 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<S> 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<S> 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<S> objectMapper(com.fasterxml.jackson.databind.ObjectMapper objectMapper)
objectMapper
- the instance to use. Must not be null.java.lang.IllegalArgumentException
- if objectMapper is nullpublic McpServer.AsyncSpecification<S> jsonSchemaValidator(JsonSchemaValidator jsonSchemaValidator)
jsonSchemaValidator
- The validator to use. Must not be null.java.lang.IllegalArgumentException
- if jsonSchemaValidator is null