Initializes this server with the given name and version information.
Optionaldescription?: stringAn optional human-readable description of what this implementation does.
This can be used by clients or servers to provide context about their purpose and capabilities. For example, a server might describe the types of resources or tools it provides, while a client might describe its intended use case.
Optionalicons?: { mimeType?: string; sizes?: string[]; src: string; theme?: "light" | "dark" }[]Optional set of sized icons that the client can display in a user interface.
Clients that support rendering icons MUST support at least the following MIME types:
image/png - PNG images (safe, universal compatibility)image/jpeg (and image/jpg) - JPEG images (safe, universal compatibility)Clients that support rendering icons SHOULD also support:
image/svg+xml - SVG images (scalable but requires security precautions)image/webp - WebP images (modern, efficient format)Intended for programmatic or logical use, but used as a display name in past specs or fallback
Optionaltitle?: stringIntended for UI and end-user contexts — optimized to be human-readable and easily understood, even by those unfamiliar with domain-specific terminology.
If not provided, the name should be used for display (except for Tool,
where annotations.title should be given precedence over using name,
if present).
OptionalwebsiteUrl?: stringAn optional URL of the website for this implementation.
Optionaloptions: ServerOptionsOptionalfallbackA handler to invoke for any notification types that do not have their own handler installed.
OptionalfallbackA handler to invoke for any request types that do not have their own handler installed.
OptionaloncloseCallback for when the connection is closed for any reason.
This is invoked when close() is called as well.
OptionalonerrorCallback for when an error occurs.
Note that errors are not necessarily fatal; they are used for reporting any kind of exceptional condition out of band.
OptionaloninitializedCallback for when initialization has fully completed (i.e., the client has sent an initialized notification).
ExperimentalAccess experimental features.
WARNING: These APIs are experimental and may change without notice.
Asserts that a request handler has not already been set for the given method, in preparation for a new one being automatically installed.
ProtectedassertA method to check if a capability is supported by the remote side, for the given method to be called.
This should be implemented by subclasses.
ProtectedassertA method to check if a notification is supported by the local side, for the given method to be sent.
This should be implemented by subclasses.
ProtectedassertA method to check if a request handler is supported by the local side, for the given method to be handled.
This should be implemented by subclasses.
ProtectedassertA method to check if task creation is supported for the given request method.
This should be implemented by subclasses.
ProtectedassertA method to check if task handler is supported by the local side, for the given method to be handled.
This should be implemented by subclasses.
ProtectedcancelExperimentalCancels a specific task.
Use client.experimental.tasks.cancelTask() to access this method.
Optionaloptions: RequestOptionsCloses the connection.
Attaches to the given transport, starts it, and starts listening for messages.
The Protocol object assumes ownership of the Transport, replacing any callbacks that have already been set, and expects that it is the only user of the Transport instance going forward.
Creates a reusable callback that, when invoked, will send a notifications/elicitation/complete
notification for the specified elicitation ID.
The ID of the elicitation to mark as complete.
Optionaloptions: NotificationOptionsOptional notification options. Useful when the completion notification should be related to a prior request.
A function that emits the completion notification when awaited.
Request LLM sampling from the client (without tools). Returns single content block for backwards compatibility.
Optionaloptions: RequestOptionsRequest LLM sampling from the client with tool support. Returns content that may be a single block or array (for parallel tool calls).
Optionaloptions: RequestOptionsRequest LLM sampling from the client. When tools may or may not be present, returns the union type.
Optional_meta?: {See General fields: _meta for notes on _meta usage.
Optionalio.modelcontextprotocol/related-task?: { taskId: string }If specified, this request is related to the provided task.
OptionalprogressToken?: string | numberIf specified, the caller is requesting out-of-band progress notifications for this request (as represented by notifications/progress). The value of this parameter is an opaque token that will be attached to any subsequent notifications. The receiver is not obligated to provide these notifications.
OptionalincludeContext?: "none" | "thisServer" | "allServers"A request to include context from one or more MCP servers (including the caller), to be attached to the prompt. The client MAY ignore this request.
Default is "none". Values "thisServer" and "allServers" are soft-deprecated. Servers SHOULD only use these values if the client declares ClientCapabilities.sampling.context. These values may be removed in future spec releases.
The requested maximum number of tokens to sample (to prevent runaway completions).
The client MAY choose to sample fewer tokens than the requested maximum.
Optionalmetadata?: objectOptional metadata to pass through to the LLM provider. The format of this metadata is provider-specific.
OptionalmodelPreferences?: {The server's preferences for which model to select. The client MAY modify or omit this request.
OptionalcostPriority?: numberHow much to prioritize cost when selecting a model.
Optionalhints?: { name?: string }[]Optional hints to use for model selection.
OptionalintelligencePriority?: numberHow much to prioritize intelligence and capabilities when selecting a model.
OptionalspeedPriority?: numberHow much to prioritize sampling speed (latency) when selecting a model.
OptionalstopSequences?: string[]OptionalsystemPrompt?: stringAn optional system prompt the server wants to use for sampling. The client MAY modify or omit this prompt.
Optionaltask?: { ttl?: number }If specified, the caller is requesting task-augmented execution for this request. The request will return a CreateTaskResult immediately, and the actual result can be retrieved later via tasks/result.
Task augmentation is subject to capability negotiation - receivers MUST declare support for task augmentation of specific request types in their capabilities.
Optionaltemperature?: numberOptionaltoolChoice?: { mode?: "required" | "none" | "auto" }Controls how the model uses tools.
The client MUST return an error if this field is provided but ClientCapabilities.sampling.tools is not declared.
Default is { mode: "auto" }.
Optionalmode?: "required" | "none" | "auto"Controls when tools are used:
Optionaltools?: {Tools that the model may use during generation. The client MUST return an error if this field is provided but ClientCapabilities.sampling.tools is not declared.
Optionaloptions: RequestOptionsCreates an elicitation request for the given parameters.
For backwards compatibility, mode may be omitted for form requests and will default to 'form'.
The parameters for the elicitation request.
Optional_meta?: {See General fields: _meta for notes on _meta usage.
Optionalio.modelcontextprotocol/related-task?: { taskId: string }If specified, this request is related to the provided task.
OptionalprogressToken?: string | numberIf specified, the caller is requesting out-of-band progress notifications for this request (as represented by notifications/progress). The value of this parameter is an opaque token that will be attached to any subsequent notifications. The receiver is not obligated to provide these notifications.
The message to present to the user describing what information is being requested.
Optionalmode?: "form"The elicitation mode.
Optional for backward compatibility. Clients MUST treat missing mode as "form".
A restricted subset of JSON Schema. Only top-level properties are allowed, without nesting.
Optionaltask?: { ttl?: number }If specified, the caller is requesting task-augmented execution for this request. The request will return a CreateTaskResult immediately, and the actual result can be retrieved later via tasks/result.
Task augmentation is subject to capability negotiation - receivers MUST declare support for task augmentation of specific request types in their capabilities.
Optional_meta?: {See General fields: _meta for notes on _meta usage.
Optionalio.modelcontextprotocol/related-task?: { taskId: string }If specified, this request is related to the provided task.
OptionalprogressToken?: string | numberIf specified, the caller is requesting out-of-band progress notifications for this request (as represented by notifications/progress). The value of this parameter is an opaque token that will be attached to any subsequent notifications. The receiver is not obligated to provide these notifications.
The ID of the elicitation, which must be unique within the context of the server. The client MUST treat this ID as an opaque value.
The message to present to the user explaining why the interaction is needed.
The elicitation mode.
Optionaltask?: { ttl?: number }If specified, the caller is requesting task-augmented execution for this request. The request will return a CreateTaskResult immediately, and the actual result can be retrieved later via tasks/result.
Task augmentation is subject to capability negotiation - receivers MUST declare support for task augmentation of specific request types in their capabilities.
The URL that the user should navigate to.
Optionaloptions: RequestOptionsOptional request options.
The result of the elicitation request.
After initialization has completed, this will be populated with the client's reported capabilities.
Optionalelicitation?: {Present if the client supports eliciting user input.
Optionalexperimental?: { [key: string]: object }Experimental, non-standard capabilities that the client supports.
Optionalroots?: { listChanged?: boolean }Present if the client supports listing roots.
OptionallistChanged?: booleanWhether the client supports issuing notifications for changes to the roots list.
Optionalsampling?: { context?: object; tools?: object }Present if the client supports sampling from an LLM.
Optionalcontext?: objectPresent if the client supports context inclusion via includeContext parameter.
If not declared, servers SHOULD only use includeContext: "none" (or omit it).
Optionaltools?: objectPresent if the client supports tool use via tools and toolChoice parameters.
Optionaltasks?: {Present if the client supports task creation.
Optionalcancel?: objectPresent if the client supports cancelling tasks.
Optionallist?: objectPresent if the client supports listing tasks.
Optionalrequests?: {Capabilities for task creation on specific request types.
Optionalelicitation?: { create?: object; [key: string]: unknown }Task support for elicitation requests.
Optionalsampling?: { createMessage?: object; [key: string]: unknown }Task support for sampling requests.
After initialization has completed, this will be populated with information about the client's name and version.
Optionaldescription?: stringAn optional human-readable description of what this implementation does.
This can be used by clients or servers to provide context about their purpose and capabilities. For example, a server might describe the types of resources or tools it provides, while a client might describe its intended use case.
Optionalicons?: { mimeType?: string; sizes?: string[]; src: string; theme?: "light" | "dark" }[]Optional set of sized icons that the client can display in a user interface.
Clients that support rendering icons MUST support at least the following MIME types:
image/png - PNG images (safe, universal compatibility)image/jpeg (and image/jpg) - JPEG images (safe, universal compatibility)Clients that support rendering icons SHOULD also support:
image/svg+xml - SVG images (scalable but requires security precautions)image/webp - WebP images (modern, efficient format)Intended for programmatic or logical use, but used as a display name in past specs or fallback
Optionaltitle?: stringIntended for UI and end-user contexts — optimized to be human-readable and easily understood, even by those unfamiliar with domain-specific terminology.
If not provided, the name should be used for display (except for Tool,
where annotations.title should be given precedence over using name,
if present).
OptionalwebsiteUrl?: stringAn optional URL of the website for this implementation.
ProtectedgetExperimentalGets the current status of a task.
Use client.experimental.tasks.getTask() to access this method.
Optional_meta?: {See General fields: _meta for notes on _meta usage.
Optionalio.modelcontextprotocol/related-task?: { taskId: string }If specified, this request is related to the provided task.
OptionalprogressToken?: string | numberIf specified, the caller is requesting out-of-band progress notifications for this request (as represented by notifications/progress). The value of this parameter is an opaque token that will be attached to any subsequent notifications. The receiver is not obligated to provide these notifications.
Optionaloptions: RequestOptionsProtectedgetExperimentalRetrieves the result of a completed task.
Use client.experimental.tasks.getTaskResult() to access this method.
Optional_meta?: {See General fields: _meta for notes on _meta usage.
Optionalio.modelcontextprotocol/related-task?: { taskId: string }If specified, this request is related to the provided task.
OptionalprogressToken?: string | numberIf specified, the caller is requesting out-of-band progress notifications for this request (as represented by notifications/progress). The value of this parameter is an opaque token that will be attached to any subsequent notifications. The receiver is not obligated to provide these notifications.
Optionaloptions: RequestOptionsOptionalparams: {Optional_meta?: {See General fields: _meta for notes on _meta usage.
Optionalio.modelcontextprotocol/related-task?: { taskId: string }If specified, this request is related to the provided task.
OptionalprogressToken?: string | numberIf specified, the caller is requesting out-of-band progress notifications for this request (as represented by notifications/progress). The value of this parameter is an opaque token that will be attached to any subsequent notifications. The receiver is not obligated to provide these notifications.
Optionaloptions: RequestOptionsProtectedlistExperimentalLists tasks, optionally starting from a pagination cursor.
Use client.experimental.tasks.listTasks() to access this method.
Optionalparams: { cursor?: string }Optionaloptions: RequestOptionsEmits a notification, which is a one-way message that does not expect a response.
Optionaloptions: NotificationOptionsRegisters new capabilities. This can only be called before connecting to a transport.
The new capabilities will be merged with any existing capabilities previously given (e.g., at initialization).
Optionalcompletions?: objectPresent if the server supports sending completions to the client.
Optionalexperimental?: { [key: string]: object }Experimental, non-standard capabilities that the server supports.
Optionallogging?: objectPresent if the server supports sending log messages to the client.
Optionalprompts?: { listChanged?: boolean }Present if the server offers any prompt templates.
OptionallistChanged?: booleanWhether this server supports issuing notifications for changes to the prompt list.
Optionalresources?: { listChanged?: boolean; subscribe?: boolean }Present if the server offers any resources to read.
OptionallistChanged?: booleanWhether this server supports issuing notifications for changes to the resource list.
Optionalsubscribe?: booleanWhether this server supports clients subscribing to resource updates.
Optionaltasks?: {Present if the server supports task creation.
Optionalcancel?: objectPresent if the server supports cancelling tasks.
Optionallist?: objectPresent if the server supports listing tasks.
Optionalrequests?: { tools?: { call?: object; [key: string]: unknown }; [key: string]: unknown }Capabilities for task creation on specific request types.
Optionaltools?: { call?: object; [key: string]: unknown }Task support for tool requests.
Optionaltools?: { listChanged?: boolean }Present if the server offers any tools to call.
OptionallistChanged?: booleanWhether this server supports issuing notifications for changes to the tool list.
Removes the notification handler for the given method.
Removes the request handler for the given method.
Sends a request and waits for a response.
Do not use this method to emit notifications! Use notification() instead.
Optionaloptions: RequestOptionsProtectedrequestExperimentalSends a request and returns an AsyncGenerator that yields response messages. The generator is guaranteed to end with either a 'result' or 'error' message.
Optionaloptions: RequestOptionsconst stream = protocol.requestStream(request, resultSchema, options);
for await (const message of stream) {
switch (message.type) {
case 'taskCreated':
console.log('Task created:', message.task.taskId);
break;
case 'taskStatus':
console.log('Task status:', message.task.status);
break;
case 'result':
console.log('Final result:', message.result);
break;
case 'error':
console.error('Error:', message.error);
break;
}
}
Use client.experimental.tasks.requestStream() to access this method.
Sends a logging message to the client, if connected. Note: You only need to send the parameters object, not the entire JSON RPC message
Optional_meta?: {See MCP specification for notes on _meta usage.
Optionalio.modelcontextprotocol/related-task?: { taskId: string }If specified, this request is related to the provided task.
OptionalprogressToken?: string | numberIf specified, the caller is requesting out-of-band progress notifications for this request (as represented by notifications/progress). The value of this parameter is an opaque token that will be attached to any subsequent notifications. The receiver is not obligated to provide these notifications.
The data to be logged, such as a string message or an object. Any JSON serializable type is allowed here.
The severity of this log message.
Optionallogger?: stringAn optional name of the logger issuing this message.
OptionalsessionId: stringoptional for stateless and backward compatibility
Optional_meta?: {See MCP specification for notes on _meta usage.
Optionalio.modelcontextprotocol/related-task?: { taskId: string }If specified, this request is related to the provided task.
OptionalprogressToken?: string | numberIf specified, the caller is requesting out-of-band progress notifications for this request (as represented by notifications/progress). The value of this parameter is an opaque token that will be attached to any subsequent notifications. The receiver is not obligated to provide these notifications.
The URI of the resource that has been updated. This might be a sub-resource of the one that the client actually subscribed to.
Registers a handler to invoke when this protocol object receives a notification with the given method.
Note that this will replace any previous notification handler for the same method.
Override request handler registration to enforce server-side validation for tools/call.
An MCP server on top of a pluggable transport.
This server will automatically respond to the initialization flow as initiated from the client.
To use with custom types, extend the base Request/Notification/Result types and pass them as type parameters:
Deprecated
Use
McpServerinstead for the high-level API. Only useServerfor advanced use cases.