This is the documentation for v1.x — looking for the v2 beta documentation?
Skip to content

MCP TypeScript SDK / server

server

Classes

Server

Defined in: src/server/index.ts:121

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:

typescript
// Custom schemas
const CustomRequestSchema = RequestSchema.extend({...})
const CustomNotificationSchema = NotificationSchema.extend({...})
const CustomResultSchema = ResultSchema.extend({...})

// Type aliases
type CustomRequest = z.infer<typeof CustomRequestSchema>
type CustomNotification = z.infer<typeof CustomNotificationSchema>
type CustomResult = z.infer<typeof CustomResultSchema>

// Create typed server
const server = new Server<CustomRequest, CustomNotification, CustomResult>({
  name: "CustomServer",
  version: "1.0.0"
})

Deprecated

Use McpServer instead for the high-level API. Only use Server for advanced use cases.

Extends

Type Parameters

RequestT

RequestT extends Request = Request

NotificationT

NotificationT extends Notification = Notification

ResultT

ResultT extends Result = Result

Constructors

Constructor

new Server<RequestT, NotificationT, ResultT>(_serverInfo, options?): Server<RequestT, NotificationT, ResultT>

Defined in: src/server/index.ts:141

Initializes this server with the given name and version information.

Parameters
_serverInfo
description?

string = ...

An 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.

icons?

object[] = ...

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)
name

string = ...

Intended for programmatic or logical use, but used as a display name in past specs or fallback

title?

string = ...

Intended 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).

version

string = ...

websiteUrl?

string = ...

An optional URL of the website for this implementation.

options?

ServerOptions

Returns

Server<RequestT, NotificationT, ResultT>

Overrides

Protocol.constructor

Properties

fallbackNotificationHandler?

optional fallbackNotificationHandler?: (notification) => Promise<void>

Defined in: src/shared/protocol.ts:364

A handler to invoke for any notification types that do not have their own handler installed.

Parameters
notification
method

string = ...

params?

{[key: string]: unknown; _meta?: {[key: string]: unknown; io.modelcontextprotocol/related-task?: { taskId: string; }; progressToken?: string | number; }; } = ...

params._meta?

{[key: string]: unknown; io.modelcontextprotocol/related-task?: { taskId: string; }; progressToken?: string | number; } = ...

See MCP specification for notes on _meta usage.

{ taskId: string; } = ...

If specified, this request is related to the provided task.

string = ...

params._meta.progressToken?

string | number = ...

If 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.

Returns

Promise<void>

Inherited from

Protocol.fallbackNotificationHandler

fallbackRequestHandler?

optional fallbackRequestHandler?: (request, extra) => Promise<ResultT | ServerResult>

Defined in: src/shared/protocol.ts:359

A handler to invoke for any request types that do not have their own handler installed.

Parameters
request
id

string | number = RequestIdSchema

jsonrpc

"2.0" = ...

method

string = ...

params?

{[key: string]: unknown; _meta?: {[key: string]: unknown; io.modelcontextprotocol/related-task?: { taskId: string; }; progressToken?: string | number; }; } = ...

params._meta?

{[key: string]: unknown; io.modelcontextprotocol/related-task?: { taskId: string; }; progressToken?: string | number; } = ...

See General fields: _meta for notes on _meta usage.

{ taskId: string; } = ...

If specified, this request is related to the provided task.

string = ...

params._meta.progressToken?

string | number = ...

If 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.

extra

RequestHandlerExtra<RequestT | ServerRequest, NotificationT | ServerNotification>

Returns

Promise<ResultT | ServerResult>

Inherited from

Protocol.fallbackRequestHandler

onclose?

optional onclose?: () => void

Defined in: src/shared/protocol.ts:347

Callback for when the connection is closed for any reason.

This is invoked when close() is called as well.

Returns

void

Inherited from

Protocol.onclose

onerror?

optional onerror?: (error) => void

Defined in: src/shared/protocol.ts:354

Callback 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.

Parameters
error

Error

Returns

void

Inherited from

Protocol.onerror

oninitialized?

optional oninitialized?: () => void

Defined in: src/server/index.ts:136

Callback for when initialization has fully completed (i.e., the client has sent an initialized notification).

Returns

void

Accessors

experimental
Get Signature

get experimental(): object

Defined in: src/server/index.ts:174

Experimental

Access experimental features.

WARNING: These APIs are experimental and may change without notice.

Returns

object

tasks

tasks: ExperimentalServerTasks<RequestT, NotificationT, ResultT>

transport
Get Signature

get transport(): Transport | undefined

Defined in: src/shared/protocol.ts:935

Returns

Transport | undefined

Inherited from

Protocol.transport

Methods

assertCanSetRequestHandler()

assertCanSetRequestHandler(method): void

Defined in: src/shared/protocol.ts:1444

Asserts that a request handler has not already been set for the given method, in preparation for a new one being automatically installed.

Parameters
method

string

Returns

void

Inherited from

Protocol.assertCanSetRequestHandler

assertCapabilityForMethod()

protected assertCapabilityForMethod(method): void

Defined in: src/server/index.ts:277

A 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.

Parameters
method

RequestT["method"]

Returns

void

Overrides

Protocol.assertCapabilityForMethod

assertNotificationCapability()

protected assertNotificationCapability(method): void

Defined in: src/server/index.ts:303

A 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.

Parameters
method

NotificationT | ServerNotification["method"]

Returns

void

Overrides

Protocol.assertNotificationCapability

assertRequestHandlerCapability()

protected assertRequestHandlerCapability(method): void

Defined in: src/server/index.ts:346

A 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.

Parameters
method

string

Returns

void

Overrides

Protocol.assertRequestHandlerCapability

assertTaskCapability()

protected assertTaskCapability(method): void

Defined in: src/server/index.ts:404

A method to check if task creation is supported for the given request method.

This should be implemented by subclasses.

Parameters
method

string

Returns

void

Overrides

Protocol.assertTaskCapability

assertTaskHandlerCapability()

protected assertTaskHandlerCapability(method): void

Defined in: src/server/index.ts:408

A 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.

Parameters
method

string

Returns

void

Overrides

Protocol.assertTaskHandlerCapability

cancelTask()

protected cancelTask(params, options?): Promise<{ _meta?: {[key: string]: unknown; io.modelcontextprotocol/related-task?: { taskId: string; }; progressToken?: string | number; }; createdAt: string; lastUpdatedAt: string; pollInterval?: number; status: "working" | "input_required" | "completed" | "failed" | "cancelled"; statusMessage?: string; taskId: string; ttl: number | null; }>

Defined in: src/shared/protocol.ts:1295

Experimental

Cancels a specific task.

Use client.experimental.tasks.cancelTask() to access this method.

Parameters
params
taskId

string

options?

RequestOptions

Returns

Promise<{ _meta?: {[key: string]: unknown; io.modelcontextprotocol/related-task?: { taskId: string; }; progressToken?: string | number; }; createdAt: string; lastUpdatedAt: string; pollInterval?: number; status: "working" | "input_required" | "completed" | "failed" | "cancelled"; statusMessage?: string; taskId: string; ttl: number | null; }>

Inherited from

Protocol.cancelTask

close()

close(): Promise<void>

Defined in: src/shared/protocol.ts:942

Closes the connection.

Returns

Promise<void>

Inherited from

Protocol.close

connect()

connect(transport): Promise<void>

Defined in: src/shared/protocol.ts:607

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.

Parameters
transport

Transport

Returns

Promise<void>

Inherited from

Protocol.connect

createElicitationCompletionNotifier()

createElicitationCompletionNotifier(elicitationId, options?): () => Promise<void>

Defined in: src/server/index.ts:594

Creates a reusable callback that, when invoked, will send a notifications/elicitation/complete notification for the specified elicitation ID.

Parameters
elicitationId

string

The ID of the elicitation to mark as complete.

options?

NotificationOptions

Optional notification options. Useful when the completion notification should be related to a prior request.

Returns

A function that emits the completion notification when awaited.

() => Promise<void>

createMessage()
Call Signature

createMessage(params, options?): Promise<{[key: string]: unknown; _meta?: {[key: string]: unknown; io.modelcontextprotocol/related-task?: { taskId: string; }; progressToken?: string | number; }; content: { _meta?: {[key: string]: unknown; }; annotations?: { audience?: ("user" | "assistant")[]; lastModified?: string; priority?: number; }; text: string; type: "text"; } | { _meta?: {[key: string]: unknown; }; annotations?: { audience?: ("user" | "assistant")[]; lastModified?: string; priority?: number; }; data: string; mimeType: string; type: "image"; } | { _meta?: {[key: string]: unknown; }; annotations?: { audience?: ("user" | "assistant")[]; lastModified?: string; priority?: number; }; data: string; mimeType: string; type: "audio"; }; model: string; role: "user" | "assistant"; stopReason?: string; }>

Defined in: src/server/index.ts:460

Request LLM sampling from the client (without tools). Returns single content block for backwards compatibility.

Parameters
params

CreateMessageRequestParamsBase

options?

RequestOptions

Returns

Promise<{[key: string]: unknown; _meta?: {[key: string]: unknown; io.modelcontextprotocol/related-task?: { taskId: string; }; progressToken?: string | number; }; content: { _meta?: {[key: string]: unknown; }; annotations?: { audience?: ("user" | "assistant")[]; lastModified?: string; priority?: number; }; text: string; type: "text"; } | { _meta?: {[key: string]: unknown; }; annotations?: { audience?: ("user" | "assistant")[]; lastModified?: string; priority?: number; }; data: string; mimeType: string; type: "image"; } | { _meta?: {[key: string]: unknown; }; annotations?: { audience?: ("user" | "assistant")[]; lastModified?: string; priority?: number; }; data: string; mimeType: string; type: "audio"; }; model: string; role: "user" | "assistant"; stopReason?: string; }>

Call Signature

createMessage(params, options?): Promise<{[key: string]: unknown; _meta?: {[key: string]: unknown; io.modelcontextprotocol/related-task?: { taskId: string; }; progressToken?: string | number; }; content: { _meta?: {[key: string]: unknown; }; annotations?: { audience?: ("user" | "assistant")[]; lastModified?: string; priority?: number; }; text: string; type: "text"; } | { _meta?: {[key: string]: unknown; }; annotations?: { audience?: ("user" | "assistant")[]; lastModified?: string; priority?: number; }; data: string; mimeType: string; type: "image"; } | { _meta?: {[key: string]: unknown; }; annotations?: { audience?: ("user" | "assistant")[]; lastModified?: string; priority?: number; }; data: string; mimeType: string; type: "audio"; } | { _meta?: {[key: string]: unknown; }; id: string; input: {[key: string]: unknown; }; name: string; type: "tool_use"; } | { _meta?: {[key: string]: unknown; }; content: ({ _meta?: {[key: string]: unknown; }; annotations?: { audience?: ...[]; lastModified?: string; priority?: number; }; text: string; type: "text"; } | { _meta?: {[key: string]: unknown; }; annotations?: { audience?: ...[]; lastModified?: string; priority?: number; }; data: string; mimeType: string; type: "image"; } | { _meta?: {[key: string]: unknown; }; annotations?: { audience?: ...[]; lastModified?: string; priority?: number; }; data: string; mimeType: string; type: "audio"; } | { _meta?: {[key: string]: unknown; }; annotations?: { audience?: ...[]; lastModified?: string; priority?: number; }; description?: string; icons?: object[]; mimeType?: string; name: string; size?: number; title?: string; type: "resource_link"; uri: string; } | { _meta?: {[key: string]: unknown; }; annotations?: { audience?: ...[]; lastModified?: string; priority?: number; }; resource: { _meta?: {[key: ...]: ...; }; mimeType?: string; text: string; uri: string; } | { _meta?: {[key: ...]: ...; }; blob: string; mimeType?: string; uri: string; }; type: "resource"; })[]; isError?: boolean; structuredContent?: {[key: string]: unknown; }; toolUseId: string; type: "tool_result"; } | ({ _meta?: {[key: string]: unknown; }; annotations?: { audience?: (... | ...)[]; lastModified?: string; priority?: number; }; text: string; type: "text"; } | { _meta?: {[key: string]: unknown; }; annotations?: { audience?: (... | ...)[]; lastModified?: string; priority?: number; }; data: string; mimeType: string; type: "image"; } | { _meta?: {[key: string]: unknown; }; annotations?: { audience?: (... | ...)[]; lastModified?: string; priority?: number; }; data: string; mimeType: string; type: "audio"; } | { _meta?: {[key: string]: unknown; }; id: string; input: {[key: string]: unknown; }; name: string; type: "tool_use"; } | { _meta?: {[key: string]: unknown; }; content: ({ _meta?: {[key: ...]: ...; }; annotations?: { audience?: ...; lastModified?: ...; priority?: ...; }; text: string; type: "text"; } | { _meta?: {[key: ...]: ...; }; annotations?: { audience?: ...; lastModified?: ...; priority?: ...; }; data: string; mimeType: string; type: "image"; } | { _meta?: {[key: ...]: ...; }; annotations?: { audience?: ...; lastModified?: ...; priority?: ...; }; data: string; mimeType: string; type: "audio"; } | { _meta?: {[key: ...]: ...; }; annotations?: { audience?: ...; lastModified?: ...; priority?: ...; }; description?: string; icons?: ...[]; mimeType?: string; name: string; size?: number; title?: string; type: "resource_link"; uri: string; } | { _meta?: {[key: ...]: ...; }; annotations?: { audience?: ...; lastModified?: ...; priority?: ...; }; resource: { _meta?: ...; mimeType?: ...; text: ...; uri: ...; } | { _meta?: ...; blob: ...; mimeType?: ...; uri: ...; }; type: "resource"; })[]; isError?: boolean; structuredContent?: {[key: string]: unknown; }; toolUseId: string; type: "tool_result"; })[]; model: string; role: "user" | "assistant"; stopReason?: string; }>

Defined in: src/server/index.ts:466

Request LLM sampling from the client with tool support. Returns content that may be a single block or array (for parallel tool calls).

Parameters
params

CreateMessageRequestParamsWithTools

options?

RequestOptions

Returns

Promise<{[key: string]: unknown; _meta?: {[key: string]: unknown; io.modelcontextprotocol/related-task?: { taskId: string; }; progressToken?: string | number; }; content: { _meta?: {[key: string]: unknown; }; annotations?: { audience?: ("user" | "assistant")[]; lastModified?: string; priority?: number; }; text: string; type: "text"; } | { _meta?: {[key: string]: unknown; }; annotations?: { audience?: ("user" | "assistant")[]; lastModified?: string; priority?: number; }; data: string; mimeType: string; type: "image"; } | { _meta?: {[key: string]: unknown; }; annotations?: { audience?: ("user" | "assistant")[]; lastModified?: string; priority?: number; }; data: string; mimeType: string; type: "audio"; } | { _meta?: {[key: string]: unknown; }; id: string; input: {[key: string]: unknown; }; name: string; type: "tool_use"; } | { _meta?: {[key: string]: unknown; }; content: ({ _meta?: {[key: string]: unknown; }; annotations?: { audience?: ...[]; lastModified?: string; priority?: number; }; text: string; type: "text"; } | { _meta?: {[key: string]: unknown; }; annotations?: { audience?: ...[]; lastModified?: string; priority?: number; }; data: string; mimeType: string; type: "image"; } | { _meta?: {[key: string]: unknown; }; annotations?: { audience?: ...[]; lastModified?: string; priority?: number; }; data: string; mimeType: string; type: "audio"; } | { _meta?: {[key: string]: unknown; }; annotations?: { audience?: ...[]; lastModified?: string; priority?: number; }; description?: string; icons?: object[]; mimeType?: string; name: string; size?: number; title?: string; type: "resource_link"; uri: string; } | { _meta?: {[key: string]: unknown; }; annotations?: { audience?: ...[]; lastModified?: string; priority?: number; }; resource: { _meta?: {[key: ...]: ...; }; mimeType?: string; text: string; uri: string; } | { _meta?: {[key: ...]: ...; }; blob: string; mimeType?: string; uri: string; }; type: "resource"; })[]; isError?: boolean; structuredContent?: {[key: string]: unknown; }; toolUseId: string; type: "tool_result"; } | ({ _meta?: {[key: string]: unknown; }; annotations?: { audience?: (... | ...)[]; lastModified?: string; priority?: number; }; text: string; type: "text"; } | { _meta?: {[key: string]: unknown; }; annotations?: { audience?: (... | ...)[]; lastModified?: string; priority?: number; }; data: string; mimeType: string; type: "image"; } | { _meta?: {[key: string]: unknown; }; annotations?: { audience?: (... | ...)[]; lastModified?: string; priority?: number; }; data: string; mimeType: string; type: "audio"; } | { _meta?: {[key: string]: unknown; }; id: string; input: {[key: string]: unknown; }; name: string; type: "tool_use"; } | { _meta?: {[key: string]: unknown; }; content: ({ _meta?: {[key: ...]: ...; }; annotations?: { audience?: ...; lastModified?: ...; priority?: ...; }; text: string; type: "text"; } | { _meta?: {[key: ...]: ...; }; annotations?: { audience?: ...; lastModified?: ...; priority?: ...; }; data: string; mimeType: string; type: "image"; } | { _meta?: {[key: ...]: ...; }; annotations?: { audience?: ...; lastModified?: ...; priority?: ...; }; data: string; mimeType: string; type: "audio"; } | { _meta?: {[key: ...]: ...; }; annotations?: { audience?: ...; lastModified?: ...; priority?: ...; }; description?: string; icons?: ...[]; mimeType?: string; name: string; size?: number; title?: string; type: "resource_link"; uri: string; } | { _meta?: {[key: ...]: ...; }; annotations?: { audience?: ...; lastModified?: ...; priority?: ...; }; resource: { _meta?: ...; mimeType?: ...; text: ...; uri: ...; } | { _meta?: ...; blob: ...; mimeType?: ...; uri: ...; }; type: "resource"; })[]; isError?: boolean; structuredContent?: {[key: string]: unknown; }; toolUseId: string; type: "tool_result"; })[]; model: string; role: "user" | "assistant"; stopReason?: string; }>

Call Signature

createMessage(params, options?): Promise<{[key: string]: unknown; _meta?: {[key: string]: unknown; io.modelcontextprotocol/related-task?: { taskId: string; }; progressToken?: string | number; }; content: { _meta?: {[key: string]: unknown; }; annotations?: { audience?: ("user" | "assistant")[]; lastModified?: string; priority?: number; }; text: string; type: "text"; } | { _meta?: {[key: string]: unknown; }; annotations?: { audience?: ("user" | "assistant")[]; lastModified?: string; priority?: number; }; data: string; mimeType: string; type: "image"; } | { _meta?: {[key: string]: unknown; }; annotations?: { audience?: ("user" | "assistant")[]; lastModified?: string; priority?: number; }; data: string; mimeType: string; type: "audio"; }; model: string; role: "user" | "assistant"; stopReason?: string; } | {[key: string]: unknown; _meta?: {[key: string]: unknown; io.modelcontextprotocol/related-task?: { taskId: string; }; progressToken?: string | number; }; content: { _meta?: {[key: string]: unknown; }; annotations?: { audience?: ("user" | "assistant")[]; lastModified?: string; priority?: number; }; text: string; type: "text"; } | { _meta?: {[key: string]: unknown; }; annotations?: { audience?: ("user" | "assistant")[]; lastModified?: string; priority?: number; }; data: string; mimeType: string; type: "image"; } | { _meta?: {[key: string]: unknown; }; annotations?: { audience?: ("user" | "assistant")[]; lastModified?: string; priority?: number; }; data: string; mimeType: string; type: "audio"; } | { _meta?: {[key: string]: unknown; }; id: string; input: {[key: string]: unknown; }; name: string; type: "tool_use"; } | { _meta?: {[key: string]: unknown; }; content: ({ _meta?: {[key: string]: unknown; }; annotations?: { audience?: ... | ...; lastModified?: ... | ...; priority?: ... | ...; }; text: string; type: "text"; } | { _meta?: {[key: string]: unknown; }; annotations?: { audience?: ... | ...; lastModified?: ... | ...; priority?: ... | ...; }; data: string; mimeType: string; type: "image"; } | { _meta?: {[key: string]: unknown; }; annotations?: { audience?: ... | ...; lastModified?: ... | ...; priority?: ... | ...; }; data: string; mimeType: string; type: "audio"; } | { _meta?: {[key: string]: unknown; }; annotations?: { audience?: ... | ...; lastModified?: ... | ...; priority?: ... | ...; }; description?: string; icons?: object[]; mimeType?: string; name: string; size?: number; title?: string; type: "resource_link"; uri: string; } | { _meta?: {[key: string]: unknown; }; annotations?: { audience?: ... | ...; lastModified?: ... | ...; priority?: ... | ...; }; resource: { _meta?: ... | ...; mimeType?: ... | ...; text: string; uri: string; } | { _meta?: ... | ...; blob: string; mimeType?: ... | ...; uri: string; }; type: "resource"; })[]; isError?: boolean; structuredContent?: {[key: string]: unknown; }; toolUseId: string; type: "tool_result"; } | ({ _meta?: {[key: string]: unknown; }; annotations?: { audience?: ...[]; lastModified?: string; priority?: number; }; text: string; type: "text"; } | { _meta?: {[key: string]: unknown; }; annotations?: { audience?: ...[]; lastModified?: string; priority?: number; }; data: string; mimeType: string; type: "image"; } | { _meta?: {[key: string]: unknown; }; annotations?: { audience?: ...[]; lastModified?: string; priority?: number; }; data: string; mimeType: string; type: "audio"; } | { _meta?: {[key: string]: unknown; }; id: string; input: {[key: string]: unknown; }; name: string; type: "tool_use"; } | { _meta?: {[key: string]: unknown; }; content: ({ _meta?: ... | ...; annotations?: ... | ...; text: string; type: "text"; } | { _meta?: ... | ...; annotations?: ... | ...; data: string; mimeType: string; type: "image"; } | { _meta?: ... | ...; annotations?: ... | ...; data: string; mimeType: string; type: "audio"; } | { _meta?: ... | ...; annotations?: ... | ...; description?: ... | ...; icons?: ... | ...; mimeType?: ... | ...; name: string; size?: ... | ...; title?: ... | ...; type: "resource_link"; uri: string; } | { _meta?: ... | ...; annotations?: ... | ...; resource: ... | ...; type: "resource"; })[]; isError?: boolean; structuredContent?: {[key: string]: unknown; }; toolUseId: string; type: "tool_result"; })[]; model: string; role: "user" | "assistant"; stopReason?: string; }>

Defined in: src/server/index.ts:472

Request LLM sampling from the client. When tools may or may not be present, returns the union type.

Parameters
params
_meta?

{[key: string]: unknown; io.modelcontextprotocol/related-task?: { taskId: string; }; progressToken?: string | number; } = ...

See General fields: _meta for notes on _meta usage.

{ taskId: string; } = ...

If specified, this request is related to the provided task.

string = ...

_meta.progressToken?

string | number = ...

If 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.

includeContext?

"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.

maxTokens

number = ...

The requested maximum number of tokens to sample (to prevent runaway completions).

The client MAY choose to sample fewer tokens than the requested maximum.

messages

object[] = ...

metadata?

object = ...

Optional metadata to pass through to the LLM provider. The format of this metadata is provider-specific.

modelPreferences?

{ costPriority?: number; hints?: object[]; intelligencePriority?: number; speedPriority?: number; } = ...

The server's preferences for which model to select. The client MAY modify or omit this request.

modelPreferences.costPriority?

number = ...

How much to prioritize cost when selecting a model.

modelPreferences.hints?

object[] = ...

Optional hints to use for model selection.

modelPreferences.intelligencePriority?

number = ...

How much to prioritize intelligence and capabilities when selecting a model.

modelPreferences.speedPriority?

number = ...

How much to prioritize sampling speed (latency) when selecting a model.

stopSequences?

string[] = ...

systemPrompt?

string = ...

An optional system prompt the server wants to use for sampling. The client MAY modify or omit this prompt.

task?

{ 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.

task.ttl?

number = ...

temperature?

number = ...

toolChoice?

{ 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" }.

toolChoice.mode?

"required" | "none" | "auto" = ...

Controls when tools are used:

  • "auto": Model decides whether to use tools (default)
  • "required": Model MUST use at least one tool before completing
  • "none": Model MUST NOT use any tools
tools?

object[] = ...

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.

options?

RequestOptions

Returns

Promise<{[key: string]: unknown; _meta?: {[key: string]: unknown; io.modelcontextprotocol/related-task?: { taskId: string; }; progressToken?: string | number; }; content: { _meta?: {[key: string]: unknown; }; annotations?: { audience?: ("user" | "assistant")[]; lastModified?: string; priority?: number; }; text: string; type: "text"; } | { _meta?: {[key: string]: unknown; }; annotations?: { audience?: ("user" | "assistant")[]; lastModified?: string; priority?: number; }; data: string; mimeType: string; type: "image"; } | { _meta?: {[key: string]: unknown; }; annotations?: { audience?: ("user" | "assistant")[]; lastModified?: string; priority?: number; }; data: string; mimeType: string; type: "audio"; }; model: string; role: "user" | "assistant"; stopReason?: string; } | {[key: string]: unknown; _meta?: {[key: string]: unknown; io.modelcontextprotocol/related-task?: { taskId: string; }; progressToken?: string | number; }; content: { _meta?: {[key: string]: unknown; }; annotations?: { audience?: ("user" | "assistant")[]; lastModified?: string; priority?: number; }; text: string; type: "text"; } | { _meta?: {[key: string]: unknown; }; annotations?: { audience?: ("user" | "assistant")[]; lastModified?: string; priority?: number; }; data: string; mimeType: string; type: "image"; } | { _meta?: {[key: string]: unknown; }; annotations?: { audience?: ("user" | "assistant")[]; lastModified?: string; priority?: number; }; data: string; mimeType: string; type: "audio"; } | { _meta?: {[key: string]: unknown; }; id: string; input: {[key: string]: unknown; }; name: string; type: "tool_use"; } | { _meta?: {[key: string]: unknown; }; content: ({ _meta?: {[key: string]: unknown; }; annotations?: { audience?: ... | ...; lastModified?: ... | ...; priority?: ... | ...; }; text: string; type: "text"; } | { _meta?: {[key: string]: unknown; }; annotations?: { audience?: ... | ...; lastModified?: ... | ...; priority?: ... | ...; }; data: string; mimeType: string; type: "image"; } | { _meta?: {[key: string]: unknown; }; annotations?: { audience?: ... | ...; lastModified?: ... | ...; priority?: ... | ...; }; data: string; mimeType: string; type: "audio"; } | { _meta?: {[key: string]: unknown; }; annotations?: { audience?: ... | ...; lastModified?: ... | ...; priority?: ... | ...; }; description?: string; icons?: object[]; mimeType?: string; name: string; size?: number; title?: string; type: "resource_link"; uri: string; } | { _meta?: {[key: string]: unknown; }; annotations?: { audience?: ... | ...; lastModified?: ... | ...; priority?: ... | ...; }; resource: { _meta?: ... | ...; mimeType?: ... | ...; text: string; uri: string; } | { _meta?: ... | ...; blob: string; mimeType?: ... | ...; uri: string; }; type: "resource"; })[]; isError?: boolean; structuredContent?: {[key: string]: unknown; }; toolUseId: string; type: "tool_result"; } | ({ _meta?: {[key: string]: unknown; }; annotations?: { audience?: ...[]; lastModified?: string; priority?: number; }; text: string; type: "text"; } | { _meta?: {[key: string]: unknown; }; annotations?: { audience?: ...[]; lastModified?: string; priority?: number; }; data: string; mimeType: string; type: "image"; } | { _meta?: {[key: string]: unknown; }; annotations?: { audience?: ...[]; lastModified?: string; priority?: number; }; data: string; mimeType: string; type: "audio"; } | { _meta?: {[key: string]: unknown; }; id: string; input: {[key: string]: unknown; }; name: string; type: "tool_use"; } | { _meta?: {[key: string]: unknown; }; content: ({ _meta?: ... | ...; annotations?: ... | ...; text: string; type: "text"; } | { _meta?: ... | ...; annotations?: ... | ...; data: string; mimeType: string; type: "image"; } | { _meta?: ... | ...; annotations?: ... | ...; data: string; mimeType: string; type: "audio"; } | { _meta?: ... | ...; annotations?: ... | ...; description?: ... | ...; icons?: ... | ...; mimeType?: ... | ...; name: string; size?: ... | ...; title?: ... | ...; type: "resource_link"; uri: string; } | { _meta?: ... | ...; annotations?: ... | ...; resource: ... | ...; type: "resource"; })[]; isError?: boolean; structuredContent?: {[key: string]: unknown; }; toolUseId: string; type: "tool_result"; })[]; model: string; role: "user" | "assistant"; stopReason?: string; }>

elicitInput()

elicitInput(params, options?): Promise<{[key: string]: unknown; _meta?: {[key: string]: unknown; io.modelcontextprotocol/related-task?: { taskId: string; }; progressToken?: string | number; }; action: "cancel" | "accept" | "decline"; content?: {[key: string]: string | number | boolean | string[]; }; }>

Defined in: src/server/index.ts:538

Creates an elicitation request for the given parameters. For backwards compatibility, mode may be omitted for form requests and will default to 'form'.

Parameters
params

{ _meta?: {[key: string]: unknown; io.modelcontextprotocol/related-task?: { taskId: string; }; progressToken?: string | number; }; message: string; mode?: "form"; requestedSchema: { properties: {[key: string]: { default?: string; description?: string; enum: string[]; enumNames?: string[]; title?: string; type: "string"; } | { default?: string; description?: string; enum: string[]; title?: string; type: "string"; } | { default?: string; description?: string; oneOf: object[]; title?: string; type: "string"; } | { default?: string[]; description?: string; items: { enum: string[]; type: "string"; }; maxItems?: number; minItems?: number; title?: string; type: "array"; } | { default?: string[]; description?: string; items: { anyOf: object[]; }; maxItems?: number; minItems?: number; title?: string; type: "array"; } | { default?: boolean; description?: string; title?: string; type: "boolean"; } | { default?: string; description?: string; format?: "date" | "uri" | "email" | "date-time"; maxLength?: number; minLength?: number; title?: string; type: "string"; } | { default?: number; description?: string; maximum?: number; minimum?: number; title?: string; type: "number" | "integer"; }; }; required?: string[]; type: "object"; }; task?: { ttl?: number; }; } | { _meta?: {[key: string]: unknown; io.modelcontextprotocol/related-task?: { taskId: string; }; progressToken?: string | number; }; elicitationId: string; message: string; mode: "url"; task?: { ttl?: number; }; url: string; }

The parameters for the elicitation request.

Type Literal

{ _meta?: {[key: string]: unknown; io.modelcontextprotocol/related-task?: { taskId: string; }; progressToken?: string | number; }; message: string; mode?: "form"; requestedSchema: { properties: {[key: string]: { default?: string; description?: string; enum: string[]; enumNames?: string[]; title?: string; type: "string"; } | { default?: string; description?: string; enum: string[]; title?: string; type: "string"; } | { default?: string; description?: string; oneOf: object[]; title?: string; type: "string"; } | { default?: string[]; description?: string; items: { enum: string[]; type: "string"; }; maxItems?: number; minItems?: number; title?: string; type: "array"; } | { default?: string[]; description?: string; items: { anyOf: object[]; }; maxItems?: number; minItems?: number; title?: string; type: "array"; } | { default?: boolean; description?: string; title?: string; type: "boolean"; } | { default?: string; description?: string; format?: "date" | "uri" | "email" | "date-time"; maxLength?: number; minLength?: number; title?: string; type: "string"; } | { default?: number; description?: string; maximum?: number; minimum?: number; title?: string; type: "number" | "integer"; }; }; required?: string[]; type: "object"; }; task?: { ttl?: number; }; }

The parameters for the elicitation request.

_meta?

{[key: string]: unknown; io.modelcontextprotocol/related-task?: { taskId: string; }; progressToken?: string | number; } = ...

See General fields: _meta for notes on _meta usage.

{ taskId: string; } = ...

If specified, this request is related to the provided task.

string = ...

_meta.progressToken?

string | number = ...

If 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.

message

string = ...

The message to present to the user describing what information is being requested.

mode?

"form" = ...

The elicitation mode.

Optional for backward compatibility. Clients MUST treat missing mode as "form".

requestedSchema

{ properties: {[key: string]: { default?: string; description?: string; enum: string[]; enumNames?: string[]; title?: string; type: "string"; } | { default?: string; description?: string; enum: string[]; title?: string; type: "string"; } | { default?: string; description?: string; oneOf: object[]; title?: string; type: "string"; } | { default?: string[]; description?: string; items: { enum: string[]; type: "string"; }; maxItems?: number; minItems?: number; title?: string; type: "array"; } | { default?: string[]; description?: string; items: { anyOf: object[]; }; maxItems?: number; minItems?: number; title?: string; type: "array"; } | { default?: boolean; description?: string; title?: string; type: "boolean"; } | { default?: string; description?: string; format?: "date" | "uri" | "email" | "date-time"; maxLength?: number; minLength?: number; title?: string; type: "string"; } | { default?: number; description?: string; maximum?: number; minimum?: number; title?: string; type: "number" | "integer"; }; }; required?: string[]; type: "object"; } = ...

A restricted subset of JSON Schema. Only top-level properties are allowed, without nesting.

requestedSchema.properties

{[key: string]: { default?: string; description?: string; enum: string[]; enumNames?: string[]; title?: string; type: "string"; } | { default?: string; description?: string; enum: string[]; title?: string; type: "string"; } | { default?: string; description?: string; oneOf: object[]; title?: string; type: "string"; } | { default?: string[]; description?: string; items: { enum: string[]; type: "string"; }; maxItems?: number; minItems?: number; title?: string; type: "array"; } | { default?: string[]; description?: string; items: { anyOf: object[]; }; maxItems?: number; minItems?: number; title?: string; type: "array"; } | { default?: boolean; description?: string; title?: string; type: "boolean"; } | { default?: string; description?: string; format?: "date" | "uri" | "email" | "date-time"; maxLength?: number; minLength?: number; title?: string; type: "string"; } | { default?: number; description?: string; maximum?: number; minimum?: number; title?: string; type: "number" | "integer"; }; } = ...

requestedSchema.required?

string[] = ...

requestedSchema.type

"object" = ...

task?

{ 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.

task.ttl?

number = ...


Type Literal

{ _meta?: {[key: string]: unknown; io.modelcontextprotocol/related-task?: { taskId: string; }; progressToken?: string | number; }; elicitationId: string; message: string; mode: "url"; task?: { ttl?: number; }; url: string; }

The parameters for the elicitation request.

_meta?

{[key: string]: unknown; io.modelcontextprotocol/related-task?: { taskId: string; }; progressToken?: string | number; } = ...

See General fields: _meta for notes on _meta usage.

{ taskId: string; } = ...

If specified, this request is related to the provided task.

string = ...

_meta.progressToken?

string | number = ...

If 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.

elicitationId

string = ...

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.

message

string = ...

The message to present to the user explaining why the interaction is needed.

mode

"url" = ...

The elicitation mode.

task?

{ 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.

task.ttl?

number = ...

url

string = ...

The URL that the user should navigate to.

options?

RequestOptions

Optional request options.

Returns

Promise<{[key: string]: unknown; _meta?: {[key: string]: unknown; io.modelcontextprotocol/related-task?: { taskId: string; }; progressToken?: string | number; }; action: "cancel" | "accept" | "decline"; content?: {[key: string]: string | number | boolean | string[]; }; }>

The result of the elicitation request.

getClientCapabilities()

getClientCapabilities(): { elicitation?: {[key: string]: unknown; form?: {[key: string]: unknown; applyDefaults?: boolean; }; url?: object; }; experimental?: {[key: string]: object; }; extensions?: {[key: string]: object; }; roots?: { listChanged?: boolean; }; sampling?: { context?: object; tools?: object; }; tasks?: {[key: string]: unknown; cancel?: object; list?: object; requests?: {[key: string]: unknown; elicitation?: {[key: string]: unknown; create?: object; }; sampling?: {[key: string]: unknown; createMessage?: object; }; }; }; } | undefined

Defined in: src/server/index.ts:437

After initialization has completed, this will be populated with the client's reported capabilities.

Returns
Type Literal

{ elicitation?: {[key: string]: unknown; form?: {[key: string]: unknown; applyDefaults?: boolean; }; url?: object; }; experimental?: {[key: string]: object; }; extensions?: {[key: string]: object; }; roots?: { listChanged?: boolean; }; sampling?: { context?: object; tools?: object; }; tasks?: {[key: string]: unknown; cancel?: object; list?: object; requests?: {[key: string]: unknown; elicitation?: {[key: string]: unknown; create?: object; }; sampling?: {[key: string]: unknown; createMessage?: object; }; }; }; }

elicitation?

optional elicitation?: object

Present if the client supports eliciting user input.

Index Signature

[key: string]: unknown

elicitation.form?

optional form?: object

Index Signature

[key: string]: unknown

elicitation.form.applyDefaults?

optional applyDefaults?: boolean

elicitation.url?

optional url?: object

experimental?

optional experimental?: object

Experimental, non-standard capabilities that the client supports.

Index Signature

[key: string]: object

extensions?

optional extensions?: object

Extensions that the client supports. Keys are extension identifiers (vendor-prefix/extension-name).

Index Signature

[key: string]: object

roots?

optional roots?: object

Present if the client supports listing roots.

roots.listChanged?

optional listChanged?: boolean

Whether the client supports issuing notifications for changes to the roots list.

sampling?

optional sampling?: object

Present if the client supports sampling from an LLM.

sampling.context?

optional context?: object

Present if the client supports context inclusion via includeContext parameter. If not declared, servers SHOULD only use includeContext: "none" (or omit it).

sampling.tools?

optional tools?: object

Present if the client supports tool use via tools and toolChoice parameters.

tasks?

optional tasks?: object

Present if the client supports task creation.

Index Signature

[key: string]: unknown

tasks.cancel?

optional cancel?: object

Present if the client supports cancelling tasks.

tasks.list?

optional list?: object

Present if the client supports listing tasks.

tasks.requests?

optional requests?: object

Capabilities for task creation on specific request types.

Index Signature

[key: string]: unknown

tasks.requests.elicitation?

optional elicitation?: object

Task support for elicitation requests.

Index Signature

[key: string]: unknown

tasks.requests.elicitation.create?

optional create?: object

tasks.requests.sampling?

optional sampling?: object

Task support for sampling requests.

Index Signature

[key: string]: unknown

tasks.requests.sampling.createMessage?

optional createMessage?: object


undefined

getClientVersion()

getClientVersion(): { description?: string; icons?: object[]; name: string; title?: string; version: string; websiteUrl?: string; } | undefined

Defined in: src/server/index.ts:444

After initialization has completed, this will be populated with information about the client's name and version.

Returns
Type Literal

{ description?: string; icons?: object[]; name: string; title?: string; version: string; websiteUrl?: string; }

description?

optional description?: string

An 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.

icons?

optional icons?: object[]

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)
name

name: string

Intended for programmatic or logical use, but used as a display name in past specs or fallback

title?

optional title?: string

Intended 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).

version

version: string

websiteUrl?

optional websiteUrl?: string

An optional URL of the website for this implementation.


undefined

getTask()

protected getTask(params, options?): Promise<{ _meta?: {[key: string]: unknown; io.modelcontextprotocol/related-task?: { taskId: string; }; progressToken?: string | number; }; createdAt: string; lastUpdatedAt: string; pollInterval?: number; status: "working" | "input_required" | "completed" | "failed" | "cancelled"; statusMessage?: string; taskId: string; ttl: number | null; }>

Defined in: src/shared/protocol.ts:1261

Experimental

Gets the current status of a task.

Use client.experimental.tasks.getTask() to access this method.

Parameters
params
_meta?

{[key: string]: unknown; io.modelcontextprotocol/related-task?: { taskId: string; }; progressToken?: string | number; } = ...

See General fields: _meta for notes on _meta usage.

{ taskId: string; } = ...

If specified, this request is related to the provided task.

string = ...

_meta.progressToken?

string | number = ...

If 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.

taskId

string = ...

options?

RequestOptions

Returns

Promise<{ _meta?: {[key: string]: unknown; io.modelcontextprotocol/related-task?: { taskId: string; }; progressToken?: string | number; }; createdAt: string; lastUpdatedAt: string; pollInterval?: number; status: "working" | "input_required" | "completed" | "failed" | "cancelled"; statusMessage?: string; taskId: string; ttl: number | null; }>

Inherited from

Protocol.getTask

getTaskResult()

protected getTaskResult<T>(params, resultSchema, options?): Promise<SchemaOutput<T>>

Defined in: src/shared/protocol.ts:1271

Experimental

Retrieves the result of a completed task.

Use client.experimental.tasks.getTaskResult() to access this method.

Type Parameters
T

T extends AnySchema

Parameters
params
_meta?

{[key: string]: unknown; io.modelcontextprotocol/related-task?: { taskId: string; }; progressToken?: string | number; } = ...

See General fields: _meta for notes on _meta usage.

{ taskId: string; } = ...

If specified, this request is related to the provided task.

string = ...

_meta.progressToken?

string | number = ...

If 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.

taskId

string = ...

resultSchema

T

options?

RequestOptions

Returns

Promise<SchemaOutput<T>>

Inherited from

Protocol.getTaskResult

listRoots()

listRoots(params?, options?): Promise<{[key: string]: unknown; _meta?: {[key: string]: unknown; io.modelcontextprotocol/related-task?: { taskId: string; }; progressToken?: string | number; }; roots: object[]; }>

Defined in: src/server/index.ts:611

Parameters
params?
_meta?

{[key: string]: unknown; io.modelcontextprotocol/related-task?: { taskId: string; }; progressToken?: string | number; } = ...

See General fields: _meta for notes on _meta usage.

{ taskId: string; } = ...

If specified, this request is related to the provided task.

string = ...

_meta.progressToken?

string | number = ...

If 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.

options?

RequestOptions

Returns

Promise<{[key: string]: unknown; _meta?: {[key: string]: unknown; io.modelcontextprotocol/related-task?: { taskId: string; }; progressToken?: string | number; }; roots: object[]; }>

listTasks()

protected listTasks(params?, options?): Promise<{[key: string]: unknown; _meta?: {[key: string]: unknown; io.modelcontextprotocol/related-task?: { taskId: string; }; progressToken?: string | number; }; nextCursor?: string; tasks: object[]; }>

Defined in: src/shared/protocol.ts:1285

Experimental

Lists tasks, optionally starting from a pagination cursor.

Use client.experimental.tasks.listTasks() to access this method.

Parameters
params?
cursor?

string

options?

RequestOptions

Returns

Promise<{[key: string]: unknown; _meta?: {[key: string]: unknown; io.modelcontextprotocol/related-task?: { taskId: string; }; progressToken?: string | number; }; nextCursor?: string; tasks: object[]; }>

Inherited from

Protocol.listTasks

notification()

notification(notification, options?): Promise<void>

Defined in: src/shared/protocol.ts:1303

Emits a notification, which is a one-way message that does not expect a response.

Parameters
notification

NotificationT | ServerNotification

options?

NotificationOptions

Returns

Promise<void>

Inherited from

Protocol.notification

ping()

ping(): Promise<{ _meta?: {[key: string]: unknown; io.modelcontextprotocol/related-task?: { taskId: string; }; progressToken?: string | number; }; }>

Defined in: src/server/index.ts:452

Returns

Promise<{ _meta?: {[key: string]: unknown; io.modelcontextprotocol/related-task?: { taskId: string; }; progressToken?: string | number; }; }>

registerCapabilities()

registerCapabilities(capabilities): void

Defined in: src/server/index.ts:200

Registers 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).

Parameters
capabilities
completions?

object = ...

Present if the server supports sending completions to the client.

experimental?

{[key: string]: object; } = ...

Experimental, non-standard capabilities that the server supports.

extensions?

{[key: string]: object; } = ...

Extensions that the server supports. Keys are extension identifiers (vendor-prefix/extension-name).

logging?

object = ...

Present if the server supports sending log messages to the client.

prompts?

{ listChanged?: boolean; } = ...

Present if the server offers any prompt templates.

prompts.listChanged?

boolean = ...

Whether this server supports issuing notifications for changes to the prompt list.

resources?

{ listChanged?: boolean; subscribe?: boolean; } = ...

Present if the server offers any resources to read.

resources.listChanged?

boolean = ...

Whether this server supports issuing notifications for changes to the resource list.

resources.subscribe?

boolean = ...

Whether this server supports clients subscribing to resource updates.

tasks?

{[key: string]: unknown; cancel?: object; list?: object; requests?: {[key: string]: unknown; tools?: {[key: string]: unknown; call?: object; }; }; } = ...

Present if the server supports task creation.

tasks.cancel?

object = ...

Present if the server supports cancelling tasks.

tasks.list?

object = ...

Present if the server supports listing tasks.

tasks.requests?

{[key: string]: unknown; tools?: {[key: string]: unknown; call?: object; }; } = ...

Capabilities for task creation on specific request types.

tasks.requests.tools?

{[key: string]: unknown; call?: object; } = ...

Task support for tool requests.

tasks.requests.tools.call?

object = ...

tools?

{ listChanged?: boolean; } = ...

Present if the server offers any tools to call.

tools.listChanged?

boolean = ...

Whether this server supports issuing notifications for changes to the tool list.

Returns

void

removeNotificationHandler()

removeNotificationHandler(method): void

Defined in: src/shared/protocol.ts:1469

Removes the notification handler for the given method.

Parameters
method

string

Returns

void

Inherited from

Protocol.removeNotificationHandler

removeRequestHandler()

removeRequestHandler(method): void

Defined in: src/shared/protocol.ts:1437

Removes the request handler for the given method.

Parameters
method

string

Returns

void

Inherited from

Protocol.removeRequestHandler

request()

request<T>(request, resultSchema, options?): Promise<SchemaOutput<T>>

Defined in: src/shared/protocol.ts:1098

Sends a request and waits for a response.

Do not use this method to emit notifications! Use notification() instead.

Type Parameters
T

T extends AnySchema

Parameters
request

RequestT | ServerRequest

resultSchema

T

options?

RequestOptions

Returns

Promise<SchemaOutput<T>>

Inherited from

Protocol.request

requestStream()

protected requestStream<T>(request, resultSchema, options?): AsyncGenerator<ResponseMessage<SchemaOutput<T>>, void, void>

Defined in: src/shared/protocol.ts:1008

Experimental

Sends a request and returns an AsyncGenerator that yields response messages. The generator is guaranteed to end with either a 'result' or 'error' message.

Type Parameters
T

T extends AnySchema

Parameters
request

RequestT | ServerRequest

resultSchema

T

options?

RequestOptions

Returns

AsyncGenerator<ResponseMessage<SchemaOutput<T>>, void, void>

Example
typescript
const 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.

Inherited from

Protocol.requestStream

sendLoggingMessage()

sendLoggingMessage(params, sessionId?): Promise<void>

Defined in: src/server/index.ts:622

Sends a logging message to the client, if connected. Note: You only need to send the parameters object, not the entire JSON RPC message

Parameters
params
_meta?

{[key: string]: unknown; io.modelcontextprotocol/related-task?: { taskId: string; }; progressToken?: string | number; } = ...

See MCP specification for notes on _meta usage.

{ taskId: string; } = ...

If specified, this request is related to the provided task.

string = ...

_meta.progressToken?

string | number = ...

If 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.

data

unknown = ...

The data to be logged, such as a string message or an object. Any JSON serializable type is allowed here.

level

"error" | "debug" | "info" | "notice" | "warning" | "critical" | "alert" | "emergency" = LoggingLevelSchema

The severity of this log message.

logger?

string = ...

An optional name of the logger issuing this message.

sessionId?

string

optional for stateless and backward compatibility

Returns

Promise<void>

See

LoggingMessageNotification

sendPromptListChanged()

sendPromptListChanged(): Promise<void>

Defined in: src/server/index.ts:647

Returns

Promise<void>

sendResourceListChanged()

sendResourceListChanged(): Promise<void>

Defined in: src/server/index.ts:637

Returns

Promise<void>

sendResourceUpdated()

sendResourceUpdated(params): Promise<void>

Defined in: src/server/index.ts:630

Parameters
params
_meta?

{[key: string]: unknown; io.modelcontextprotocol/related-task?: { taskId: string; }; progressToken?: string | number; } = ...

See MCP specification for notes on _meta usage.

{ taskId: string; } = ...

If specified, this request is related to the provided task.

string = ...

_meta.progressToken?

string | number = ...

If 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.

uri

string = ...

The URI of the resource that has been updated. This might be a sub-resource of the one that the client actually subscribed to.

Returns

Promise<void>

sendToolListChanged()

sendToolListChanged(): Promise<void>

Defined in: src/server/index.ts:643

Returns

Promise<void>

setNotificationHandler()

setNotificationHandler<T>(notificationSchema, handler): void

Defined in: src/shared/protocol.ts:1455

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.

Type Parameters
T

T extends AnyObjectSchema

Parameters
notificationSchema

T

handler

(notification) => void | Promise<void>

Returns

void

Inherited from

Protocol.setNotificationHandler

setRequestHandler()

setRequestHandler<T>(requestSchema, handler): void

Defined in: src/server/index.ts:210

Override request handler registration to enforce server-side validation for tools/call.

Type Parameters
T

T extends AnyObjectSchema

Parameters
requestSchema

T

handler

(request, extra) => ResultT | ServerResult | Promise<ResultT | ServerResult>

Returns

void

Overrides

Protocol.setRequestHandler

Type Aliases

ServerOptions

ServerOptions = ProtocolOptions & object

Defined in: src/server/index.ts:52

Type Declaration

capabilities?

optional capabilities?: ServerCapabilities

Capabilities to advertise as being supported by this server.

instructions?

optional instructions?: string

Optional instructions describing how to use the server and its features.

jsonSchemaValidator?

optional jsonSchemaValidator?: jsonSchemaValidator

JSON Schema validator for elicitation response validation.

The validator is used to validate user input returned from elicitation requests against the requested schema.

Default
ts
AjvJsonSchemaValidator
Example
typescript
// ajv (default)
const server = new Server(
  { name: 'my-server', version: '1.0.0' },
  {
    capabilities: {}
    jsonSchemaValidator: new AjvJsonSchemaValidator()
  }
);

// @cfworker/json-schema
const server = new Server(
  { name: 'my-server', version: '1.0.0' },
  {
    capabilities: {},
    jsonSchemaValidator: new CfWorkerJsonSchemaValidator()
  }
);