Class McpServerConfig
McpRevision.
Applications register a single McpServerConfig (typically as a bean in their RestContext
bean store) listing the tools, prompts, resources, and resource templates to expose, plus optional server
metadata and a pagination strategy.
This type is revision-neutral: it holds no field typed with any protocol revision's wire beans, and
in particular holds no capabilities field in any form. The protocol version is owned by
McpRevision.protocolVersion(), and an explicit capabilities advertisement is owned by a
revision-specific hook on that revision's servlet or endpoint mixin.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordThe result ofresolveResourceTemplate(String): the winning resource-template handler paired with the variables decoded from the concrete request URI. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddPrompt(McpPromptHandler... handlers) Convenience: append one or more prompt handlers.addResource(McpResourceHandler... handlers) Convenience: append one or more resource handlers.addResourceTemplate(McpResourceTemplateHandler... values) Convenience: append one or more resource-template handlers.addResourceTemplate(McpResourceTemplateSpec... values) Convenience: append one or more resource-template descriptors as built-in listing-only handlers.addTool(McpToolHandler... handlers) Convenience: append one or more tool handlers.addTool(McpTypedToolHandler<?, ?> handler) Convenience: adapt and append a single typed tool handler.completer(McpCompletionRef ref, String argumentName) Unified neutral completion lookup: resolves the completer for acompletion/completetarget, dispatching byMcpCompletionRef.KindtopromptCompleter(String, String)ortemplateCompleter(String, String).Pagination strategy forlistdispatchers (tools / prompts / resources / resource templates).Optional instructions surfaced viainitialize.getName()Server name reported ininitialize.Registered prompt handlers.Registered resource handlers.Registered resource-template handlers.getTools()Registered tool handlers.Server version reported ininitialize.booleanReports whethercompletionscapability should be advertised: whether at least one registered prompt argument or resource-template variable currently declares a non-nullcompleter.promptCompleter(String promptName, String argumentName) Resolves the completer registered for one declared argument of a registered prompt, by exact prompt name and exact argument name.Resolves the concreteresources/readrequest URIuriagainst the registered resource-template registry, selecting the single winning template handler using the deterministic specificity ranking shared identically by both dated adapters.Sets the pagination strategy.setInstructions(String instructions) Sets initialize instructions.Sets the server name.setPrompts(List<McpPromptHandler> prompts) Sets the prompt handler list.setResources(List<McpResourceHandler> resources) Sets the resource handler list.Sets the resource-template handler list.Sets the resource-template registry from bare descriptors, replacing each with a built-in listing-only handler equivalent to whataddResourceTemplate(McpResourceTemplateSpec...)wraps.setTools(List<McpToolHandler> tools) Sets the tool handler list.setVersion(String value) Sets the server version.templateCompleter(String uriTemplate, String variableName) Resolves the completer registered for one declared variable of a registered resource-template, by exact registereduriTemplatestring and exact variable name.
-
Constructor Details
-
McpServerConfig
public McpServerConfig()
-
-
Method Details
-
getName
Server name reported ininitialize.When both this and
getVersion()arenull, the bound revision substitutes its own default server identity.- Returns:
- The name, or
nullif not set.
-
setName
Sets the server name.- Parameters:
value- The new value. Can benull to unset the property.- Returns:
- This object.
-
getVersion
Server version reported ininitialize.- Returns:
- The version, or
nullif not set.
-
setVersion
Sets the server version.- Parameters:
value- The new value. Can benull to unset the property.- Returns:
- This object.
-
getInstructions
Optional instructions surfaced viainitialize.- Returns:
- The instructions, or
nullif not set.
-
setInstructions
Sets initialize instructions.- Parameters:
instructions- The new value.- Returns:
- This object (for method chaining).
-
getTools
Registered tool handlers.- Returns:
- Mutable list of handlers. Never
null.
-
setTools
Sets the tool handler list.- Parameters:
tools- The new value (ornullto clear).- Returns:
- This object (for method chaining).
-
addTool
Convenience: append one or more tool handlers.- Parameters:
handlers- Handlers to add.- Returns:
- This object (for method chaining).
-
addTool
Convenience: adapt and append a single typed tool handler.The handler is bridged into a raw
McpToolHandlerviaMcpTypedHandlers.adaptTool(McpTypedToolHandler)before it is stored. This overload is intentionally singular: a typed varargs overload would makeaddTool()ambiguous. To register multiple typed handlers, use chainedaddTool(...)calls, or adapt them explicitly withMcpTypedHandlers.adaptTool(McpTypedToolHandler)and pass the results toaddTool(McpToolHandler...).- Parameters:
handler- The typed handler to adapt and add.- Returns:
- This object (for method chaining).
-
getPrompts
Registered prompt handlers.- Returns:
- Mutable list of handlers. Never
null.
-
setPrompts
Sets the prompt handler list.The complete resulting registry is validated before publication; on failure, the previously published registry is left unchanged. See
addPrompt(McpPromptHandler...)for the validated conditions.- Parameters:
prompts- The new value (ornullto clear).- Returns:
- This object (for method chaining).
- Throws:
IllegalArgumentException- If the resulting registry would be invalid.
-
addPrompt
Convenience: append one or more prompt handlers.The complete resulting registry - the handlers already registered plus
handlers- is validated before publication; on failure, the previously published registry is left unchanged. Fails fast withIllegalArgumentExceptionfor a single prompt whose declaredMcpPromptArgumentlist either:- repeats a non-
nullargument name; or - attaches a non-
nullcompleterto anullor blank argument name.
- Parameters:
handlers- Handlers to add.- Returns:
- This object (for method chaining).
- Throws:
IllegalArgumentException- If the resulting registry would be invalid.
- repeats a non-
-
getResources
Registered resource handlers.- Returns:
- Mutable list of handlers. Never
null.
-
setResources
Sets the resource handler list.- Parameters:
resources- The new value (ornullto clear).- Returns:
- This object (for method chaining).
-
addResource
Convenience: append one or more resource handlers.- Parameters:
handlers- Handlers to add.- Returns:
- This object (for method chaining).
-
getResourceTemplates
Registered resource-template handlers.Every read of this property (re)validates the current registry if the list has been mutated directly since the last validated
setResourceTemplates(List),addResourceTemplate(McpResourceTemplateHandler...),addResourceTemplate(McpResourceTemplateSpec...), orsetResourceTemplateSpecs(List)call, so direct-list corruption is caught on first consumption rather than silently propagating to dispatch. A registry that has not been mutated since its last successful validation is returned without recompiling its templates.- Returns:
- Mutable list of handlers. Never
null. - Throws:
IllegalArgumentException- If the list was mutated directly into an invalid state (seeaddResourceTemplate(McpResourceTemplateHandler...)for the validated conditions).
-
setResourceTemplates
Sets the resource-template handler list.The complete resulting registry is validated before publication; on failure, the previously published registry is left unchanged. See
addResourceTemplate(McpResourceTemplateHandler...)for the validated conditions.- Parameters:
value- The new value (ornullto clear).- Returns:
- This object (for method chaining).
- Throws:
IllegalArgumentException- If the resulting registry would be invalid.
-
setResourceTemplateSpecs
Sets the resource-template registry from bare descriptors, replacing each with a built-in listing-only handler equivalent to whataddResourceTemplate(McpResourceTemplateSpec...)wraps.The complete resulting registry is validated before publication; on failure, the previously published registry is left unchanged.
- Parameters:
value- The new descriptor list (ornullto clear).- Returns:
- This object (for method chaining).
- Throws:
IllegalArgumentException- If the resulting registry would be invalid.
-
addResourceTemplate
Convenience: append one or more resource-template handlers.The complete resulting registry - the handlers already registered plus
values- is validated before publication; on failure, the previously published registry is left unchanged. Fails fast withIllegalArgumentExceptionnaming the offending registration index and template for:- a
nullhandler; - a handler whose
McpResourceTemplateHandler.descriptor()returnsnull; - a descriptor with a
nullor blankuriTemplate; - a malformed
uriTemplate(delegated toMcpUriTemplateMatcher.compile(String)); and - an exact-duplicate
uriTemplatestring within the resulting registry.
uriTemplateoutsideMcpUriTemplateMatcher's reverse-matchable subset is a legal registration, not an error.- Parameters:
values- Handlers to add.- Returns:
- This object (for method chaining).
- Throws:
IllegalArgumentException- If the resulting registry would be invalid.
- a
-
addResourceTemplate
Convenience: append one or more resource-template descriptors as built-in listing-only handlers.Each descriptor is wrapped in a handler whose
McpResourceTemplateHandler.descriptor()returns that same descriptor instance, whosereadalways returnsnull, and whosecompleteralways returnsnull. The resulting registry is validated exactly as inaddResourceTemplate(McpResourceTemplateHandler...).- Parameters:
values- Descriptors to add.- Returns:
- This object (for method chaining).
- Throws:
IllegalArgumentException- If the resulting registry would be invalid.
-
resolveResourceTemplate
Resolves the concreteresources/readrequest URIuriagainst the registered resource-template registry, selecting the single winning template handler using the deterministic specificity ranking shared identically by both dated adapters.A candidate is every reverse-matchable (
McpUriTemplateMatcher.isReverseMatchable()) template handler whoseMcpUriTemplateMatcher.match(String)succeeds againsturi; a non-reverse-matchable or non-matching template handler is never a candidate. Successful candidates are ranked, highest priority first, by exactly:- greater
literalOctetCount; - then fewer
variableCount; and - then earlier registration index (candidates are scanned in registration order and a later candidate only displaces the current winner on a strictly better key, so the first-registered candidate wins a complete tie).
This method does not consult exact
McpResourceHandlerregistrations. Exact lookup is unconditionally higher precedence than any template match; callers must perform exact lookup first and invoke this method only on an exact miss.- Parameters:
uri- The concrete request URI. Can benull, in which case this method returnsnull.- Returns:
- The winning match (handler plus its immutable, insertion-ordered decoded variable map), or
nullif no registered reverse-matchable template matchesuri.
- greater
-
promptCompleter
Resolves the completer registered for one declared argument of a registered prompt, by exact prompt name and exact argument name.This is one half of the neutral cross-target completion lookup shared identically by both dated adapters; see
templateCompleter(String, String)for the resource-template half andcompleter(McpCompletionRef, String)for the unified entry point.- Parameters:
promptName- The exact prompt name to look up. Can benull, in which case this method returnsnull.argumentName- The exact argument name to look up. Can benull, in which case this method returnsnull.- Returns:
- The argument's completer, or
nullif the prompt is unknown, the argument is undeclared, or the argument declares no completer. Never invokes the completer.
-
templateCompleter
Resolves the completer registered for one declared variable of a registered resource-template, by exact registereduriTemplatestring and exact variable name.Matching is against the exact registered template string, not a reverse-match against a concrete URI: a
completion/completereference names the declaration being completed, never a concrete/expanded URI. This is one half of the neutral cross-target completion lookup shared identically by both dated adapters; seepromptCompleter(String, String)for the prompt half andcompleter(McpCompletionRef, String)for the unified entry point. Delegates the "variable must be declared by the template" check toresourceTemplateCompleter(McpResourceTemplateHandler, String)rather than re-parsing.- Parameters:
uriTemplate- The exact registereduriTemplateto look up. Can benull, in which case this method returnsnull.variableName- The exact variable name to look up. Can benull, in which case this method returnsnull.- Returns:
- The variable's completer, or
nullif the template is unregistered, the variable is undeclared, or the handler declares no completer for it. Never invokes the completer.
-
completer
Unified neutral completion lookup: resolves the completer for acompletion/completetarget, dispatching byMcpCompletionRef.KindtopromptCompleter(String, String)ortemplateCompleter(String, String).Both dated adapters call this same method for both target kinds, so template/prompt resolution policy is defined exactly once, in this neutral module.
- Parameters:
ref- The completion reference identifying the exact prompt name or registered template string. Can benull, in which case this method returnsnull.argumentName- The exact argument/variable name to look up. Can benull, in which case this method returnsnull.- Returns:
- The resolved completer, or
nullifrefisnull/has nokind, or if the target-specific lookup finds none. Never invokes the completer.
-
hasAnyCompleter
Reports whethercompletionscapability should be advertised: whether at least one registered prompt argument or resource-template variable currently declares a non-nullcompleter.This never invokes a completer; it only detects registration, so both dated adapters can use it for auto-derived capability advertisement without side effects.
- Returns:
trueif at least one prompt-argument completer or resource-template variable completer is registered.
-
getCursor
Pagination strategy forlistdispatchers (tools / prompts / resources / resource templates).- Returns:
- The cursor. Never
null(defaults toMcpCursor.SINGLE_PAGE).
-
setCursor
Sets the pagination strategy.- Parameters:
cursor- The new value (ornullto reset toMcpCursor.SINGLE_PAGE).- Returns:
- This object (for method chaining).
-