ServerConnection class base

An active server connection.

Constructors

ServerConnection.fromStreamChannel(StreamChannel<Map<String, Object?>> channel, {Sink<String>? protocolLogSink, RootsSupport? rootsSupport, SamplingSupport? samplingSupport, @Deprecated('Use elicitationFormSupport instead') ElicitationSupport? elicitationSupport, ElicitationFormSupport? elicitationFormSupport, ElicitationUrlSupport? elicitationUrlSupport})
A 1:1 connection from a client to a server using channel.

Properties

cachedResponseCount → int
The number of stored responses on this connection.
no setter
cancellations → Stream<CancelledNotification>
Every notifications/cancelled the peer sends with a JSON-RPC requestId, in arrival order.
no setterinherited
done → Future<void>
Completes after shutdown is called.
no setterinherited
hashCode → int
The hash code for this object.
no setterinherited
inputRequiredRetryDelay ↔ Duration?
How long sendRequestWithInputs waits before a retry that carries no input requests, including an empty map, or null for no wait.
getter/setter pair
isActive → bool
Whether the connection with the peer is active.
no setterinherited
maxCachedResponses ↔ int
The maximum number of responses cached by this connection.
getter/setter pair
maxCachedResponseTtl ↔ Duration
The maximum TTL accepted for responses received by this connection.
getter/setter pair
maxInputRequiredRounds ↔ int?
How many input_required rounds sendRequestWithInputs answers before it gives up, or null for as many as the server sends.
getter/setter pair
name → String
The name of the associated server.
no setter
onElicitationComplete → Stream<ElicitationCompleteNotification>
Emits an event any time the server sends an elicitation complete notification.
no setter
onLog → Stream<LoggingMessageNotification>
Emits an event any time the server sends a log message.
no setter
promptListChanged → Stream<PromptListChangedNotification?>
Emits an event any time the server notifies us of a change to the list of prompts it supports.
no setter
protocolVersion ↔ ProtocolVersion?
The version of the protocol this connection speaks, or null until one is settled.
getter/setter pair
resourceListChanged → Stream<ResourceListChangedNotification?>
Emits an event any time the server notifies us of a change to the list of resources it supports.
no setter
resourceUpdated → Stream<ResourceUpdatedNotification>
Emits an event any time the server notifies us of a change to a resource that this client has subscribed to.
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
serverCapabilities ↔ ServerCapabilities
The ServerCapabilities the server declared.
getter/setter pair
serverInfo ↔ Implementation?
The Implementation the server described itself with, or null until one settles it.
getter/setter pair
toolListChanged → Stream<ToolListChangedNotification?>
Emits an event any time the server notifies us of a change to the list of tools it supports.
no setter

Methods

callTool(CallToolRequest request) → Future<CallToolResult>
Invokes a Tool returned from the ListToolsResult.
captureIncomingRequestActivity() → bool Function()
Captures whether the current incoming request has not been cancelled.
inherited
closeProgress(Request? request) → Future<void>
Closes the stream onProgress returned for request, if it opened one.
inherited
discover({required ProtocolVersion protocolVersion, required ClientCapabilities capabilities, Implementation? clientInfo, LoggingLevel? logLevel, ProgressToken? progressToken}) → Future<DiscoverResult>
Asks the server which protocol versions and capabilities it supports, see DiscoverRequest.
elapseCachedResponses(Duration duration) → void
Advances the cache clock by duration.
getPrompt(GetPromptRequest request) → Future<GetPromptResult>
Gets the requested Prompt from the server.
initialize(InitializeRequest request) → Future<InitializeResult>
Initializes the server, this should be done before anything else.
initializeAcrossVersions(MCPServerInitialization initialization, {Duration discoverTimeout = const Duration(seconds: 10)}) → Future<InitializedServer>
Initializes this connection through discovery or legacy initialization, following https://modelcontextprotocol.io/specification/2026-07-28/basic/versioning#backward-compatibility-with-initialization-based-versions.
listAllPrompts({ListPromptsRequest? request, int? maxPageCount = 64}) → Stream<Prompt>
Every Prompt on this server, walking prompts/list pages until one reports no nextCursor.
listAllResources({ListResourcesRequest? request, int? maxPageCount = 64}) → Stream<Resource>
Every Resource on this server, walking resources/list pages until one reports no nextCursor.
listAllResourceTemplates({ListResourceTemplatesRequest? request, int? maxPageCount = 64}) → Stream<ResourceTemplate>
Every ResourceTemplate on this server, walking resources/templates/list pages until one reports no nextCursor.
listAllTools({ListToolsRequest? request, int? maxPageCount = 64}) → Stream<Tool>
Every Tool on this server, walking tools/list pages until one reports no nextCursor.
listen(SubscriptionFilter notifications, {required MetaWithRequestEnvelope meta}) → Subscription
Opens a subscription for the types notifications names across protocol versions.
listPrompts([ListPromptsRequest? request]) → Future<ListPromptsResult>
Lists all the prompts from this server.
listResources([ListResourcesRequest? request]) → Future<ListResourcesResult>
Lists all the Resources from this server.
listResourceTemplates([ListResourceTemplatesRequest? request]) → Future<ListResourceTemplatesResult>
Lists all the ResourceTemplates from this server.
listTools([ListToolsRequest? request]) → Future<ListToolsResult>
List all the tools from this server.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
notifyInitialized([InitializedNotification? notification]) → void
Called after a successful call to initialize.
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
pauseCachedResponseClock() → void
Stops the real-time part of the cache clock.
ping({Duration timeout = const Duration(seconds: 1), PingRequest? request}) → Future<bool>
Pings the peer, and returns whether or not it responded within timeout.
inherited
protocolLog(String message) → void
Writes message to the protocol log, if the caller asked for one.
inherited
readResource(ReadResourceRequest request) → Future<ReadResourceResult>
Reads a Resource returned from the ListResourcesResult or matching a ResourceTemplate from a ListResourceTemplatesResult.
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
requestCompletions(CompleteRequest request) → Future<CompleteResult>
Sends a request to get completions from the server.
runOutsideRequest<T>(T callback()) → T
Runs callback without associating its asynchronous work with a request.
inherited
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
sendRequestKeepingProgress<T extends Result?>(String methodName, [Request? request]) → Future<T>
Sends a request to the server, and answers it from this connection's response cache where the 2026-07-28 caching rules allow it.
sendRequestWithId<T extends Result?>(String methodName, {Request? request}) → ({RequestId id, Future<T> result, Future<void> sent})
Sends methodName and hands back the JSON-RPC ID it goes out under.
inherited
sendRequestWithInputs<T extends Result>(String methodName, WithInputResponses request) → Future<T>
Sends request like sendRequest does, answering any input_required result before it returns.
setLogLevel(SetLevelRequest request) → Future<void>
Sends a request to change the current logging level.
shutdown() → Future<void>
Close all connections and streams so the process can cleanly exit.
subscribeResource(SubscribeRequest request) → Future<void>
Subscribes this client to a resource by URI (at request.uri).
toString() → String
A string representation of this object.
inherited
unsubscribeResource(UnsubscribeRequest request) → Future<void>
Unsubscribes this client to a resource by URI (at request.uri).

Operators

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