public abstract static class McpServer.SyncSpecification<S extends McpServer.SyncSpecification<S>>
extends java.lang.Object
构造器和说明 |
---|
SyncSpecification() |
限定符和类型 | 方法和说明 |
---|---|
abstract McpSyncServer |
build() |
McpServer.SyncSpecification<S> |
capabilities(McpSchema.ServerCapabilities serverCapabilities)
Sets the server capabilities that will be advertised to clients during
connection initialization.
|
McpServer.SyncSpecification<S> |
completions(java.util.List<McpServerFeatures.SyncCompletionSpecification> completions)
Registers multiple completions with their handlers using a List.
|
McpServer.SyncSpecification<S> |
completions(McpServerFeatures.SyncCompletionSpecification... completions)
Registers multiple completions with their handlers using varargs.
|
McpServer.SyncSpecification<S> |
immediateExecution(boolean immediateExecution)
Enable on "immediate execution" of the operations on the underlying
McpAsyncServer . |
McpServer.SyncSpecification<S> |
instructions(java.lang.String instructions)
Sets the server instructions that will be shared with clients during connection
initialization.
|
McpServer.SyncSpecification<S> |
jsonSchemaValidator(JsonSchemaValidator jsonSchemaValidator) |
McpServer.SyncSpecification<S> |
objectMapper(com.fasterxml.jackson.databind.ObjectMapper objectMapper)
Sets the object mapper to use for serializing and deserializing JSON messages.
|
McpServer.SyncSpecification<S> |
prompts(java.util.List<McpServerFeatures.SyncPromptSpecification> prompts)
Registers multiple prompts with their handlers using a List.
|
McpServer.SyncSpecification<S> |
prompts(java.util.Map<java.lang.String,McpServerFeatures.SyncPromptSpecification> prompts)
Registers multiple prompts with their handlers using a Map.
|
McpServer.SyncSpecification<S> |
prompts(McpServerFeatures.SyncPromptSpecification... prompts)
Registers multiple prompts with their handlers using varargs.
|
McpServer.SyncSpecification<S> |
requestTimeout(java.time.Duration requestTimeout)
Sets the duration to wait for server responses before timing out requests.
|
McpServer.SyncSpecification<S> |
resources(java.util.List<McpServerFeatures.SyncResourceSpecification> resourceSpecifications)
Registers multiple resources with their handlers using a List.
|
McpServer.SyncSpecification<S> |
resources(java.util.Map<java.lang.String,McpServerFeatures.SyncResourceSpecification> resourceSpecifications)
Registers multiple resources with their handlers using a Map.
|
McpServer.SyncSpecification<S> |
resources(McpServerFeatures.SyncResourceSpecification... resourceSpecifications)
Registers multiple resources with their handlers using varargs.
|
McpServer.SyncSpecification<S> |
resourceTemplates(java.util.List<McpSchema.ResourceTemplate> resourceTemplates)
Sets the resource templates that define patterns for dynamic resource access.
|
McpServer.SyncSpecification<S> |
resourceTemplates(McpSchema.ResourceTemplate... resourceTemplates)
Sets the resource templates using varargs for convenience.
|
McpServer.SyncSpecification<S> |
rootsChangeHandler(java.util.function.BiConsumer<McpSyncServerExchange,java.util.List<McpSchema.Root>> handler)
Registers a consumer that will be notified when the list of roots changes.
|
McpServer.SyncSpecification<S> |
rootsChangeHandlers(java.util.function.BiConsumer<McpSyncServerExchange,java.util.List<McpSchema.Root>>... handlers)
Registers multiple consumers that will be notified when the list of roots
changes using varargs.
|
McpServer.SyncSpecification<S> |
rootsChangeHandlers(java.util.List<java.util.function.BiConsumer<McpSyncServerExchange,java.util.List<McpSchema.Root>>> handlers)
Registers multiple consumers that will be notified when the list of roots
changes.
|
McpServer.SyncSpecification<S> |
serverInfo(McpSchema.Implementation serverInfo)
Sets the server implementation information that will be shared with clients
during connection initialization.
|
McpServer.SyncSpecification<S> |
serverInfo(java.lang.String name,
java.lang.String version)
Sets the server implementation information using name and version strings.
|
McpServer.SyncSpecification<S> |
tool(McpSchema.Tool tool,
java.util.function.BiFunction<McpSyncServerExchange,java.util.Map<java.lang.String,java.lang.Object>,McpSchema.CallToolResult> handler)
已过时。
Use
toolCall(McpSchema.Tool, BiFunction) instead for tool
calls that require a request object. |
McpServer.SyncSpecification<S> |
toolCall(McpSchema.Tool tool,
java.util.function.BiFunction<McpSyncServerExchange,McpSchema.CallToolRequest,McpSchema.CallToolResult> handler)
Adds a single tool with its implementation handler to the server.
|
McpServer.SyncSpecification<S> |
tools(java.util.List<McpServerFeatures.SyncToolSpecification> toolSpecifications)
Adds multiple tools with their handlers to the server using a List.
|
McpServer.SyncSpecification<S> |
tools(McpServerFeatures.SyncToolSpecification... toolSpecifications)
Adds multiple tools with their handlers to the server using varargs.
|
McpServer.SyncSpecification<S> |
uriTemplateManagerFactory(McpUriTemplateManagerFactory uriTemplateManagerFactory)
Sets the URI template manager factory to use for creating URI templates.
|
public abstract McpSyncServer build()
public McpServer.SyncSpecification<S> uriTemplateManagerFactory(McpUriTemplateManagerFactory uriTemplateManagerFactory)
uriTemplateManagerFactory
- The factory to use. Must not be null.java.lang.IllegalArgumentException
- if uriTemplateManagerFactory is nullpublic McpServer.SyncSpecification<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.SyncSpecification<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.SyncSpecification<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.SyncSpecification<S> instructions(java.lang.String instructions)
instructions
- The instructions text. Can be null or empty.public McpServer.SyncSpecification<S> capabilities(McpSchema.ServerCapabilities serverCapabilities)
serverCapabilities
- The server capabilities configuration. Must not be
null.java.lang.IllegalArgumentException
- if serverCapabilities is null@Deprecated public McpServer.SyncSpecification<S> tool(McpSchema.Tool tool, java.util.function.BiFunction<McpSyncServerExchange,java.util.Map<java.lang.String,java.lang.Object>,McpSchema.CallToolResult> handler)
toolCall(McpSchema.Tool, BiFunction)
instead for tool
calls that require a request object.McpServerFeatures.SyncToolSpecification
explicitly.
Example usage:
.tool(
new Tool("calculator", "Performs calculations", schema),
(exchange, args) -> new CallToolResult("Result: " + calculate(args))
)
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 McpSyncServerExchange
upon which
the server can interact with the connected client. The second argument is the
list of arguments passed to the tool.java.lang.IllegalArgumentException
- if tool or handler is nullpublic McpServer.SyncSpecification<S> toolCall(McpSchema.Tool tool, java.util.function.BiFunction<McpSyncServerExchange,McpSchema.CallToolRequest,McpSchema.CallToolResult> handler)
McpServerFeatures.SyncToolSpecification
explicitly.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 McpSyncServerExchange
upon which
the server can interact with the connected client. The second argument is the
list of arguments passed to the tool.java.lang.IllegalArgumentException
- if tool or handler is nullpublic McpServer.SyncSpecification<S> tools(java.util.List<McpServerFeatures.SyncToolSpecification> toolSpecifications)
toolSpecifications
- The list of tool specifications to add. Must not be
null.java.lang.IllegalArgumentException
- if toolSpecifications is nulltools(McpServerFeatures.SyncToolSpecification...)
public McpServer.SyncSpecification<S> tools(McpServerFeatures.SyncToolSpecification... toolSpecifications)
Example usage:
.tools(
new ToolSpecification(calculatorTool, calculatorHandler),
new ToolSpecification(weatherTool, weatherHandler),
new ToolSpecification(fileManagerTool, fileManagerHandler)
)
toolSpecifications
- The tool specifications to add. Must not be null.java.lang.IllegalArgumentException
- if toolSpecifications is nulltools(List)
public McpServer.SyncSpecification<S> resources(java.util.Map<java.lang.String,McpServerFeatures.SyncResourceSpecification> resourceSpecifications)
resourceSpecifications
- Map of resource name to specification. Must not
be null.java.lang.IllegalArgumentException
- if resourceSpecifications is nullresources(McpServerFeatures.SyncResourceSpecification...)
public McpServer.SyncSpecification<S> resources(java.util.List<McpServerFeatures.SyncResourceSpecification> resourceSpecifications)
resourceSpecifications
- List of resource specifications. Must not be
null.java.lang.IllegalArgumentException
- if resourceSpecifications is nullresources(McpServerFeatures.SyncResourceSpecification...)
public McpServer.SyncSpecification<S> resources(McpServerFeatures.SyncResourceSpecification... resourceSpecifications)
Example usage:
.resources(
new ResourceSpecification(fileResource, fileHandler),
new ResourceSpecification(dbResource, dbHandler),
new ResourceSpecification(apiResource, apiHandler)
)
resourceSpecifications
- The resource specifications to add. Must not be
null.java.lang.IllegalArgumentException
- if resourceSpecifications is nullpublic McpServer.SyncSpecification<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.SyncSpecification<S> resourceTemplates(McpSchema.ResourceTemplate... resourceTemplates)
resourceTemplates(List)
.resourceTemplates
- The resource templates to set.java.lang.IllegalArgumentException
- if resourceTemplates is nullresourceTemplates(List)
public McpServer.SyncSpecification<S> prompts(java.util.Map<java.lang.String,McpServerFeatures.SyncPromptSpecification> prompts)
Example usage:
Map<String, PromptSpecification> prompts = new HashMap<>();
prompts.put("analysis", new PromptSpecification(
new Prompt("analysis", "Code analysis template"),
(exchange, request) -> new GetPromptResult(generateAnalysisPrompt(request))
));
.prompts(prompts)
prompts
- Map of prompt name to specification. Must not be null.java.lang.IllegalArgumentException
- if prompts is nullpublic McpServer.SyncSpecification<S> prompts(java.util.List<McpServerFeatures.SyncPromptSpecification> prompts)
prompts
- List of prompt specifications. Must not be null.java.lang.IllegalArgumentException
- if prompts is nullprompts(McpServerFeatures.SyncPromptSpecification...)
public McpServer.SyncSpecification<S> prompts(McpServerFeatures.SyncPromptSpecification... prompts)
Example usage:
.prompts(
new PromptSpecification(analysisPrompt, analysisHandler),
new PromptSpecification(summaryPrompt, summaryHandler),
new PromptSpecification(reviewPrompt, reviewHandler)
)
prompts
- The prompt specifications to add. Must not be null.java.lang.IllegalArgumentException
- if prompts is nullpublic McpServer.SyncSpecification<S> completions(java.util.List<McpServerFeatures.SyncCompletionSpecification> completions)
completions
- List of completion specifications. Must not be null.java.lang.IllegalArgumentException
- if completions is nullcompletions(McpServerFeatures.SyncCompletionSpecification...)
public McpServer.SyncSpecification<S> completions(McpServerFeatures.SyncCompletionSpecification... completions)
completions
- Array of completion specifications. Must not be null.java.lang.IllegalArgumentException
- if completions is nullpublic McpServer.SyncSpecification<S> rootsChangeHandler(java.util.function.BiConsumer<McpSyncServerExchange,java.util.List<McpSchema.Root>> handler)
handler
- The handler to register. Must not be null. The function's first
argument is an McpSyncServerExchange
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.SyncSpecification<S> rootsChangeHandlers(java.util.List<java.util.function.BiConsumer<McpSyncServerExchange,java.util.List<McpSchema.Root>>> handlers)
handlers
- The list of handlers to register. Must not be null.java.lang.IllegalArgumentException
- if consumers is nullrootsChangeHandler(BiConsumer)
public McpServer.SyncSpecification<S> rootsChangeHandlers(java.util.function.BiConsumer<McpSyncServerExchange,java.util.List<McpSchema.Root>>... handlers)
handlers
- The handlers to register. Must not be null.java.lang.IllegalArgumentException
- if consumers is nullrootsChangeHandlers(List)
public McpServer.SyncSpecification<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.SyncSpecification<S> jsonSchemaValidator(JsonSchemaValidator jsonSchemaValidator)
public McpServer.SyncSpecification<S> immediateExecution(boolean immediateExecution)
McpAsyncServer
. Defaults to false, which does blocking code offloading
to prevent accidental blocking of the non-blocking transport.
Do NOT set to true if the underlying transport is a non-blocking implementation.
immediateExecution
- When true, do not offload work asynchronously.