ResourcesSupport mixin base

A mixin for MCP servers which support the resources capability.

Servers should add Resources using the addResource method, typically inside the initialize method or constructor, but they may also be added after initialization if needed.

Resources can later be removed using removeResource, or the client can be notified of updates using updateResource.

Implements the subscribe and listChanges capabilities for clients, so they can be notified of changes to resources.

Any ResourceTemplates, should typically be added in initialize method or the constructor using addResourceTemplate. There is no notification protocol for templates which are added after a client requests them once, so they should be added eagerly.

See https://modelcontextprotocol.io/docs/concepts/resources.

Superclass constraints

Properties

clientCapabilities ClientCapabilities
The capabilities of the client.
getter/setter pairinherited
clientInfo Implementation
The client implementation information provided during initialization.
getter/setter pairinherited
done Future<void>
Completes after shutdown is called.
no setterinherited
hashCode int
The hash code for this object.
no setterinherited
implementation Implementation
The name, current version, and other info to give to the client.
finalinherited
initialized Future<void>
Completes when this server has finished initialization and gotten the final ack from the client.
no setterinherited
instructions String?
Instructions for how to use this server, which are given to the client.
finalinherited
isActive bool
Whether the connection with the peer is active.
no setterinherited
name String
The name of the associated server.
no setterinherited
protocolVersion ProtocolVersion
The negotiated protocol version.
getter/setter pairinherited
ready bool
Whether this server is still active and has completed initialization.
no setterinherited
resourceUpdateThrottleDelay Duration
At most, updates for the same resource or list of resources will only be sent once per this Duration.
no setter
rootsListChanged Stream<RootsListChangedNotification>?
Emits an event any time the client notifies us of a change to the list of roots it supports.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

addResource(Resource resource, FutureOr<ReadResourceResult> impl(ReadResourceRequest)) → void
Register resource to call impl when invoked.
addResourceTemplate(ResourceTemplate template, ReadResourceHandler handler) → void
Adds the ResourceTemplate template with handler.
createMessage(CreateMessageRequest request) Future<CreateMessageResult>
A request to prompt the LLM owned by the client with a message.
inherited
handleInitialized(InitializedNotification notification) → void
Called by the client after accepting our InitializeResult.
inherited
initialize(InitializeRequest request) FutureOr<InitializeResult>
Invoked by the client as a part of initialization.
override
listRoots(ListRootsRequest request) Future<ListRootsResult>
Lists all the root URIs from the client.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
notifyProgress(ProgressNotification notification) → void
Notifies the peer of progress towards completing some request.
inherited
onProgress(Request request) Stream<ProgressNotification>
A stream of progress notifications for a given request.
inherited
ping({Duration timeout = const Duration(seconds: 1)}) Future<bool>
Pings the peer, and returns whether or not it responded within timeout.
inherited
registerNotificationHandler<T extends Notification?>(String name, void impl(T)) → void
Registers a notification handler named name on this server.
inherited
registerRequestHandler<T extends Request?, R extends Result?>(String name, FutureOr<R> impl(T)) → void
Registers a handler for the method name on this server.
inherited
removeResource(String uri) → void
Removes a Resource by uri.
sendNotification(String method, [Notification? notification]) → void
Sends a notification to the peer.
inherited
sendRequest<T extends Result?>(String methodName, [Request? request]) Future<T>
Sends request to the peer, and handles coercing the response to the type T.
inherited
shutdown() Future<void>
Handles cleanup of all streams and other resources on shutdown.
override
toString() String
A string representation of this object.
inherited
updateResource(Resource resource, {FutureOr<ReadResourceResult> impl(ReadResourceRequest)?}) → void
Notifies the client that resource has been updated.

Operators

operator ==(Object other) bool
The equality operator.
inherited