Class McpResourceRegistration
Registration is staged so a handler must be supplied before optional
descriptor metadata can be configured. Exact and template registrations
intentionally expose different builders: only an exact resource may
advertise a size. The registration cache policy owns the fixed scope and
default time to live for reads; the default is
McpCachePolicy.privateNoCacheInstance().
Registration validates address structure and routing, not deployment safety. The application owns an allowlist based on how each URI is delivered or dereferenced. Direct-client addresses and handler-only custom addresses commonly require different scheme, authority, credential, query, and fragment rules. A filesystem-backed handler additionally owns canonical root containment, symlink policy, authorization, and safe opening; Soklet does not map registered URIs to files.
- Author:
- Mark Allen
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classMutable builder for an immutable exact-resource registration.static final classRequired-handler stage for an exact resource.static final classMutable builder for an immutable URI-template resource registration.static final classRequired-handler stage for a URI-template resource. -
Method Summary
Modifier and TypeMethodDescriptionReturns the template's argument completer, when configured.getIcons()Returns the input requests this resource-read operation may emit.getName()Returns the request-state contract for this resource-read operation.Returns the exact resource's advertised size.getTitle()getUri()withUriAndName(@NonNull URI uri, @NonNull String name, @NonNull Set<@NonNull McpProtocolVersion> protocolVersions) Begins a staged exact-resource registration.withUriTemplateAndName(@NonNull String uriTemplate, @NonNull String name, @NonNull Set<@NonNull McpProtocolVersion> protocolVersions) Begins a staged URI-template resource registration.
-
Method Details
-
withUriAndName
public static @NonNull McpResourceRegistration.ExactHandlerStage withUriAndName(@NonNull URI uri, @NonNull String name, @NonNull Set<@NonNull McpProtocolVersion> protocolVersions) Begins a staged exact-resource registration.Acceptance here does not mean that the URI is safe for direct client loading or for application-side dereference. Apply a deployment policy for the address's intended delivery path.
This method validates the URI's shape. Construction of the enclosing
McpServerlater applies the 1,048,576-byte ASCII wire limit and complete endpoint route validation. IPv6 zone identifiers are excluded from the RFC 3986 URI contract.- Parameters:
uri- absolute normalized resource URI in ASCII wire formname- nonblank resource nameprotocolVersions- nonempty exact revisions serving this resource- Returns:
- required-handler stage
- Throws:
IllegalArgumentException- if the URI is relative, not normalized, not in ASCII wire form, contains an IPv6 zone identifier, or the name is blank
-
withUriTemplateAndName
public static @NonNull McpResourceRegistration.TemplateHandlerStage withUriTemplateAndName(@NonNull String uriTemplate, @NonNull String name, @NonNull Set<@NonNull McpProtocolVersion> protocolVersions) Begins a staged URI-template resource registration.This method performs inexpensive local validation. Construction of the enclosing
McpServerperforms complete RFC 6570 Level 1 parsing and route validation, including the template-size, variable-name, variable-count, and overlap-work limits documented in the MCP guide. It also enforces the limit of 256 URI templates per endpoint at server construction. IPv6 zone identifiers are excluded from the RFC 3986 URI contract, including identifiers containing template variables.Level 1 simple variables do not consume a raw slash. For example,
file:///{path}matchesfile:///src%2Fmain.rswith variable valuesrc/main.rs, but does not matchfile:///src/main.rs. Captured values are UTF-8 percent-decoded exactly once;%252Fbecomes the literal string%2F. Reserved expansion ({+path}), explode and prefix modifiers are unsupported.Neither validation step authorizes expanded URIs or establishes that their scheme is safe for the application's delivery intent.
- Parameters:
uriTemplate- nonblank URI template containing simple{variable}expressionsname- nonblank resource nameprotocolVersions- nonempty exact revisions serving this resource- Returns:
- required-handler stage
- Throws:
IllegalArgumentException- if the template fails local structural validation or the name is blank
-
getAddressType
- Returns:
- whether this registration uses an exact URI or URI template
-
getUri
-
getUriTemplate
- Returns:
- resource URI template, or empty for an exact registration
-
getName
-
getProtocolVersions
- Returns:
- exact protocol revisions on which this resource is available
-
getTitle
-
getDescription
- Returns:
- human-readable description, if configured
-
getMimeType
- Returns:
- resource MIME type, if configured
-
getIcons
-
getAnnotations
- Returns:
- content annotations, if configured
-
getSizeInBytes
Returns the exact resource's advertised size.- Returns:
- nonnegative byte count, or empty when omitted or templated
-
getCachePolicy
- Returns:
- fixed scope and default time to live for resource reads
-
getInputRequestDeclarations
Returns the input requests this resource-read operation may emit.- Returns:
- immutable declarations in registration order
-
getRequestStateMode
Returns the request-state contract for this resource-read operation.- Returns:
- request-state mode
-
getMetadata
- Returns:
- immutable protocol extension metadata
-
getHandler
- Returns:
- resource-read handler
-
getCompletionHandler
Returns the template's argument completer, when configured.- Returns:
- configured completer, or empty for exact resources and templates without one
-
getCompletionProtocolVersions
- Returns:
- exact revisions on which the completion handler is available
-