McpSchema.ts
McpSchema.ts overview
Section titled “McpSchema.ts overview”Defines schemas for Model Context Protocol messages.
MCP clients and servers use these schemas to describe the JSON-RPC requests, notifications, results, and errors that can cross the protocol boundary. This module focuses on message shapes: it defines the shared protocol data model, groups related messages for the RPC layer, and provides helpers for optional fields and parameter metadata. Transport and server behavior live in other modules.
Since v4.0.0
Exports Grouped by Category
Section titled “Exports Grouped by Category”- annotations
- autocomplete
- cancellation
- client
- constants
- elicitation
- errors
- initialization
- logging
- middleware
- models
- parameters
- ping
- progress
- protocols
- ClientFailureEncoded (type alias)
- ClientNotificationEncoded (type alias)
- ClientNotificationRpcs (class)
- ClientRequestEncoded (type alias)
- ClientRequestRpcs (class)
- ClientRpcs (class)
- ClientSuccessEncoded (type alias)
- FailureEncoded (type alias)
- FromClientEncoded (type alias)
- FromServerEncoded (type alias)
- GetPrompt (class)
- ListPrompts (class)
- NotificationEncoded (type alias)
- PromptListChangedNotification (class)
- RequestEncoded (type alias)
- ServerFailureEncoded (type alias)
- ServerNotificationEncoded (type alias)
- ServerNotificationRpcs (class)
- ServerRequestEncoded (type alias)
- ServerRequestRpcs (class)
- ServerResultEncoded (type alias)
- ServerSuccessEncoded (type alias)
- SuccessEncoded (type alias)
- resources
- BlobResourceContents (class)
- ListResourceTemplates (class)
- ListResourceTemplatesResult (class)
- ListResources (class)
- ListResourcesResult (class)
- ReadResource (class)
- ReadResourceResult (class)
- Resource (class)
- ResourceContents (class)
- ResourceListChangedNotification (class)
- ResourceTemplate (class)
- ResourceUpdatedNotification (class)
- Subscribe (class)
- TextResourceContents (class)
- Unsubscribe (class)
- roots
- sampling
- schemas
- Annotations (class)
- AudioContent (class)
- ClientCapabilities (class)
- ContentBlock
- Cursor
- EmbeddedResource (class)
- GetPromptResult (class)
- ImageContent (class)
- Implementation (class)
- ListPromptsResult (class)
- McpErrorBase (class)
- NotificationMeta (class)
- PaginatedRequestMeta (class)
- PaginatedResultMeta (class)
- ProgressToken
- Prompt (class)
- PromptArgument (class)
- PromptMessage (class)
- RequestId
- RequestMeta (class)
- ResourceLink (class)
- ResultMeta (class)
- Role
- ServerCapabilities (class)
- TextContent (class)
- optional
- optionalWithDefault
- tools
annotations
Section titled “annotations”EnabledWhen (class)
Section titled “EnabledWhen (class)”Annotation to conditionally enable or disable tools based on client information.
Signature
declare class EnabledWhenSince v4.0.0
autocomplete
Section titled “autocomplete”Complete (class)
Section titled “Complete (class)”Sent from the client to the server to ask for completion options.
Signature
declare class CompleteSince v4.0.0
CompleteResult (class)
Section titled “CompleteResult (class)”Schema for the server’s response to a completion/complete request.
Signature
declare class CompleteResultSince v4.0.0
PromptReference (class)
Section titled “PromptReference (class)”Schema for a prompt reference used in autocomplete requests.
Signature
declare class PromptReferenceSince v4.0.0
ResourceReference (class)
Section titled “ResourceReference (class)”Schema for a reference to a resource or resource template definition.
Signature
declare class ResourceReferenceSince v4.0.0
cancellation
Section titled “cancellation”CancelledNotification (class)
Section titled “CancelledNotification (class)”Sent from either peer to cancel a previously issued request in the same direction.
Details
The payload identifies the request to cancel and may include a human-readable reason.
Signature
declare class CancelledNotificationSince v4.0.0
client
Section titled “client”McpServerClient (class)
Section titled “McpServerClient (class)”Service available while handling an MCP client request.
Details
It exposes the current client id, the client’s initialize payload, and a scoped RPC client for server-initiated requests back to that client.
Signature
declare class McpServerClientSince v4.0.0
constants
Section titled “constants”INTERNAL_ERROR_CODE
Section titled “INTERNAL_ERROR_CODE”Represents the JSON-RPC error code for internal server errors.
When to use
Use when building an MCP/JSON-RPC error response for an unexpected server-side failure.
Signature
declare const INTERNAL_ERROR_CODE: -32603Since v4.0.0
INVALID_PARAMS_ERROR_CODE
Section titled “INVALID_PARAMS_ERROR_CODE”Represents the JSON-RPC error code for invalid method parameters.
When to use
Use when building an MCP/JSON-RPC error response for decoded request parameters that fail method-specific validation.
Signature
declare const INVALID_PARAMS_ERROR_CODE: -32602Since v4.0.0
INVALID_REQUEST_ERROR_CODE
Section titled “INVALID_REQUEST_ERROR_CODE”Represents the JSON-RPC error code for requests that are not valid request objects.
When to use
Use when building an MCP/JSON-RPC error response for a syntactically parsed request object that fails request-shape validation.
Signature
declare const INVALID_REQUEST_ERROR_CODE: -32600Since v4.0.0
METHOD_NOT_FOUND_ERROR_CODE
Section titled “METHOD_NOT_FOUND_ERROR_CODE”Represents the JSON-RPC error code for requests whose method does not exist or is not available.
When to use
Use when building an MCP/JSON-RPC error response for a request whose
method is unknown or unavailable.
Signature
declare const METHOD_NOT_FOUND_ERROR_CODE: -32601Since v4.0.0
PARSE_ERROR_CODE
Section titled “PARSE_ERROR_CODE”Represents the JSON-RPC error code for invalid JSON that could not be parsed.
When to use
Use when building an MCP/JSON-RPC error response before a request object is available because the JSON payload could not be parsed.
Signature
declare const PARSE_ERROR_CODE: -32700Since v4.0.0
elicitation
Section titled “elicitation”Elicit (class)
Section titled “Elicit (class)”Sent from the server asking the client to collect structured input from the user.
Details
The client responds with accepted content, an explicit decline, or a cancellation.
Signature
declare class ElicitSince v4.0.0
ElicitAcceptResult (class)
Section titled “ElicitAcceptResult (class)”Schema for an accepted client response to an elicitation request.
Signature
declare class ElicitAcceptResultSince v4.0.0
ElicitDeclineResult (class)
Section titled “ElicitDeclineResult (class)”Schema for a declined or canceled client response to an elicitation request.
Signature
declare class ElicitDeclineResultSince v4.0.0
ElicitResult
Section titled “ElicitResult”Schema for every client response to an elicitation request.
Signature
declare const ElicitResult: Schema.Union<readonly [typeof ElicitAcceptResult, typeof ElicitDeclineResult]>Since v4.0.0
ElicitationDeclined (class)
Section titled “ElicitationDeclined (class)”Error raised when an MCP elicitation request is declined or fails before accepted content is returned.
Details
The error stores the original elicitation request and, when available, the underlying cause.
Signature
declare class ElicitationDeclinedSince v4.0.0
errors
Section titled “errors”InternalError (class)
Section titled “InternalError (class)”Represents an MCP/JSON-RPC error for unexpected internal server failures.
When to use
Use to report an unexpected server-side failure while handling a valid request.
Details
Uses the standard JSON-RPC internal error code -32603 and includes
InternalError.notImplemented for unimplemented handlers.
Signature
declare class InternalErrorSince v4.0.0
InvalidParams (class)
Section titled “InvalidParams (class)”Represents an MCP/JSON-RPC error for invalid method parameters.
When to use
Use to report a request whose method parameters do not match the method schema.
Details
Uses the standard JSON-RPC invalid params code -32602.
Signature
declare class InvalidParamsSince v4.0.0
InvalidRequest (class)
Section titled “InvalidRequest (class)”Represents an MCP/JSON-RPC error for a request object that is not valid.
When to use
Use to report a syntactically parsed JSON-RPC request that is not a valid request object.
Details
Uses the standard JSON-RPC invalid request code -32600.
Signature
declare class InvalidRequestSince v4.0.0
McpError
Section titled “McpError”Schema for MCP protocol errors returned in JSON-RPC failure responses,
including standard protocol errors and custom McpErrorBase values.
Signature
declare const McpError: Schema.Union< readonly [ typeof ParseError, typeof InvalidRequest, typeof MethodNotFound, typeof InvalidParams, typeof InternalError, typeof McpErrorBase ]>Since v4.0.0
MethodNotFound (class)
Section titled “MethodNotFound (class)”Represents an MCP/JSON-RPC error for an unavailable method.
When to use
Use to report a JSON-RPC method that does not exist or is not available.
Details
Uses the standard JSON-RPC method-not-found code -32601.
Signature
declare class MethodNotFoundSince v4.0.0
ParseError (class)
Section titled “ParseError (class)”Represents an MCP/JSON-RPC error for invalid JSON that could not be parsed.
When to use
Use to report a JSON parse failure before a valid JSON-RPC request object is available.
Details
Uses the standard JSON-RPC parse error code -32700.
Signature
declare class ParseErrorSince v4.0.0
initialization
Section titled “initialization”Initialize (class)
Section titled “Initialize (class)”Sent from the client to the server when it first connects, asking it to begin initialization.
Signature
declare class InitializeSince v4.0.0
InitializeResult (class)
Section titled “InitializeResult (class)”Schema for the server’s response to an initialize request from the client.
Signature
declare class InitializeResultSince v4.0.0
InitializedNotification (class)
Section titled “InitializedNotification (class)”Sent from the client to the server after initialization has finished.
Signature
declare class InitializedNotificationSince v4.0.0
logging
Section titled “logging”LoggingLevel
Section titled “LoggingLevel”Schema for log message severity levels, mapped to syslog message severities as specified in RFC 5424 section 6.2.1: https://datatracker.ietf.org/doc/html/rfc5424#section-6.2.1.
Signature
declare const LoggingLevel: Schema.Literals< ["debug", "info", "notice", "warning", "error", "critical", "alert", "emergency"]>Since v4.0.0
LoggingLevel (type alias)
Section titled “LoggingLevel (type alias)”Type represented by the MCP logging level schema, mapped to syslog message severities as specified in RFC 5424 section 6.2.1: https://datatracker.ietf.org/doc/html/rfc5424#section-6.2.1.
Signature
type LoggingLevel = typeof LoggingLevel.TypeSince v4.0.0
LoggingMessageNotification (class)
Section titled “LoggingMessageNotification (class)”Sent from the server to the client carrying a log message.
Details
The notification includes the severity level, optional logger name, and JSON-serializable log data.
Signature
declare class LoggingMessageNotificationSince v4.0.0
SetLevel (class)
Section titled “SetLevel (class)”Sent from the client to the server to enable or adjust logging.
Signature
declare class SetLevelSince v4.0.0
middleware
Section titled “middleware”McpServerClientMiddleware (class)
Section titled “McpServerClientMiddleware (class)”RPC middleware that provides McpServerClient to handlers for initialized
MCP clients.
Signature
declare class McpServerClientMiddlewareSince v4.0.0
models
Section titled “models”Cursor (type alias)
Section titled “Cursor (type alias)”Type represented by the MCP cursor schema.
Details
A cursor is an opaque string token used to continue paginated requests.
Signature
type Cursor = typeof Cursor.TypeSince v4.0.0
ProgressToken (type alias)
Section titled “ProgressToken (type alias)”Type represented by the MCP progress token schema.
Signature
type ProgressToken = typeof ProgressToken.TypeSince v4.0.0
RequestId (type alias)
Section titled “RequestId (type alias)”Type represented by the JSON-RPC request identifier schema.
Signature
type RequestId = typeof RequestId.TypeSince v4.0.0
Role (type alias)
Section titled “Role (type alias)”Type represented by the MCP role schema.
Details
Valid roles are "user" and "assistant".
Signature
type Role = typeof Role.TypeSince v4.0.0
optionalWithDefault (interface)
Section titled “optionalWithDefault (interface)”Schema type returned by optionalWithDefault.
Details
It represents an optional struct field that supplies a default value when the field is absent during decoding or construction.
Signature
export interface optionalWithDefault< S extends Schema.Constraint & Schema.WithoutConstructorDefault> extends Schema.withConstructorDefault<Schema.decodeTo<Schema.toType<Schema.optionalKey<S>>, Schema.optionalKey<S>>> {}Since v4.0.0
parameters
Section titled “parameters”Param (interface)
Section titled “Param (interface)”Schema wrapper used for resource URI template parameters.
Details
A Param behaves like the wrapped schema while carrying the parameter name
used for template compilation and completion lookup.
Signature
export interface Param<Name extends string, S extends Schema.Constraint> extends Schema.BottomLazy< S["ast"], Param<Name, S>, S["~type.parameters"], S["~type.mutability"], S["~type.optionality"], S["~type.constructor.default"], S["~encoded.mutability"], S["~encoded.optionality"]> { readonly Type: S["Type"] readonly Encoded: S["Encoded"] readonly DecodingServices: S["DecodingServices"] readonly EncodingServices: S["EncodingServices"] readonly Rebuild: Param<Name, S> readonly "~type.make.in": S["~type.make.in"] readonly "~type.make": S["~type.make"] readonly Iso: S["Iso"] readonly [ParamSchemaTypeId]: typeof ParamSchemaTypeId readonly name: Name readonly schema: S}Since v4.0.0
isParam
Section titled “isParam”Returns true when a schema was created with param and therefore carries
a resource URI template parameter name.
Signature
declare const isParam: (schema: Schema.Constraint) => schema is Param<string, Schema.Top>Since v4.0.0
Creates a parameter for a resource URI template.
Signature
declare const param: <const Name extends string, S extends Schema.Constraint>(name: Name, schema: S) => Param<Name, S>Since v4.0.0
Ping (class)
Section titled “Ping (class)”Represents an MCP ping request used to check whether the peer is still alive.
When to use
Use to implement client or server liveness checks.
Details
The receiver should respond promptly; otherwise the sender may disconnect.
Signature
declare class PingSince v4.0.0
progress
Section titled “progress”ProgressNotification (class)
Section titled “ProgressNotification (class)”Sent from either peer to report progress for a long-running request.
Signature
declare class ProgressNotificationSince v4.0.0
protocols
Section titled “protocols”ClientFailureEncoded (type alias)
Section titled “ClientFailureEncoded (type alias)”Encoded failure response sent by a client for a server-initiated request.
Signature
type ClientFailureEncoded = FailureEncoded<typeof ServerRequestRpcs>Since v4.0.0
ClientNotificationEncoded (type alias)
Section titled “ClientNotificationEncoded (type alias)”Encoded union of all client-to-server MCP notification messages.
Signature
type ClientNotificationEncoded = NotificationEncoded<typeof ClientNotificationRpcs>Since v4.0.0
ClientNotificationRpcs (class)
Section titled “ClientNotificationRpcs (class)”RPC group for notifications that MCP clients send to the server, such as cancellation, progress, initialization completion, and roots list changes.
Signature
declare class ClientNotificationRpcsSince v4.0.0
ClientRequestEncoded (type alias)
Section titled “ClientRequestEncoded (type alias)”Encoded union of all client-to-server MCP request messages.
Signature
type ClientRequestEncoded = RequestEncoded<typeof ClientRequestRpcs>Since v4.0.0
ClientRequestRpcs (class)
Section titled “ClientRequestRpcs (class)”RPC group for requests that MCP clients send to the server.
Details
The group includes initialization, resource, prompt, tool, logging,
completion, and ping requests, and installs McpServerClientMiddleware for
handlers.
Signature
declare class ClientRequestRpcsSince v4.0.0
ClientRpcs (class)
Section titled “ClientRpcs (class)”RPC group combining all client-to-server MCP requests and notifications.
Signature
declare class ClientRpcsSince v4.0.0
ClientSuccessEncoded (type alias)
Section titled “ClientSuccessEncoded (type alias)”Encoded success response sent by a client for a server-initiated request.
Signature
type ClientSuccessEncoded = SuccessEncoded<typeof ServerRequestRpcs>Since v4.0.0
FailureEncoded (type alias)
Section titled “FailureEncoded (type alias)”Encoded failure response for an RPC in Group, containing the original
request id and encoded error.
Signature
type FailureEncoded<Group> = RpcGroup.Rpcs<Group> extends infer Rpc ? Rpc extends Rpc.Rpc<infer _Tag, infer _Payload, infer _Success, infer _Error, infer _Middleware> ? { readonly _tag: "Failure" readonly id: string | number readonly error: _Error["Encoded"] } : never : neverSince v4.0.0
FromClientEncoded (type alias)
Section titled “FromClientEncoded (type alias)”Encoded MCP messages accepted from a client by the server protocol: client requests and client notifications.
Signature
type FromClientEncoded = ClientRequestEncoded | ClientNotificationEncodedSince v4.0.0
FromServerEncoded (type alias)
Section titled “FromServerEncoded (type alias)”Encoded MCP messages emitted by the server protocol to a client: server responses and server notifications.
Signature
type FromServerEncoded = ServerResultEncoded | ServerNotificationEncodedSince v4.0.0
GetPrompt (class)
Section titled “GetPrompt (class)”Sent from the client to get a prompt provided by the server.
Signature
declare class GetPromptSince v4.0.0
ListPrompts (class)
Section titled “ListPrompts (class)”Sent from the client to request a list of prompts and prompt templates the server has.
Signature
declare class ListPromptsSince v4.0.0
NotificationEncoded (type alias)
Section titled “NotificationEncoded (type alias)”Encoded notification message for an RPC in Group, including the method and
encoded payload without a request id.
Signature
type NotificationEncoded<Group> = RpcGroup.Rpcs<Group> extends infer Rpc ? Rpc extends Rpc.Rpc<infer _Tag, infer _Payload, infer _Success, infer _Error, infer _Middleware> ? { readonly _tag: "Notification" readonly method: _Tag readonly payload: _Payload["Encoded"] } : never : neverSince v4.0.0
PromptListChangedNotification (class)
Section titled “PromptListChangedNotification (class)”Represents a notification that the server’s prompt list changed.
When to use
Use to notify clients that prompts/list should be requested again.
Details
Servers may send this notification without a previous client subscription.
Signature
declare class PromptListChangedNotificationSince v4.0.0
RequestEncoded (type alias)
Section titled “RequestEncoded (type alias)”Encoded JSON-RPC request message for an RPC in Group, including the request
id, method, and encoded payload.
Signature
type RequestEncoded<Group> = RpcGroup.Rpcs<Group> extends infer Rpc ? Rpc extends Rpc.Rpc<infer _Tag, infer _Payload, infer _Success, infer _Error, infer _Middleware> ? { readonly _tag: "Request" readonly id: string | number readonly method: _Tag readonly payload: _Payload["Encoded"] } : never : neverSince v4.0.0
ServerFailureEncoded (type alias)
Section titled “ServerFailureEncoded (type alias)”Encoded failure response sent by the server for a client-initiated request.
Signature
type ServerFailureEncoded = FailureEncoded<typeof ClientRequestRpcs>Since v4.0.0
ServerNotificationEncoded (type alias)
Section titled “ServerNotificationEncoded (type alias)”Encoded union of all server-to-client MCP notification messages.
Signature
type ServerNotificationEncoded = NotificationEncoded<typeof ServerNotificationRpcs>Since v4.0.0
ServerNotificationRpcs (class)
Section titled “ServerNotificationRpcs (class)”RPC group for notifications that an MCP server can send to a client, including cancellation, progress, logging, and list or resource update notifications.
Signature
declare class ServerNotificationRpcsSince v4.0.0
ServerRequestEncoded (type alias)
Section titled “ServerRequestEncoded (type alias)”Encoded union of all server-to-client MCP request messages.
Signature
type ServerRequestEncoded = RequestEncoded<typeof ServerRequestRpcs>Since v4.0.0
ServerRequestRpcs (class)
Section titled “ServerRequestRpcs (class)”RPC group for requests that an MCP server can send to a client, including ping, sampling, roots listing, and elicitation.
Signature
declare class ServerRequestRpcsSince v4.0.0
ServerResultEncoded (type alias)
Section titled “ServerResultEncoded (type alias)”Encoded server response to a client request, either success or failure.
Signature
type ServerResultEncoded = ServerSuccessEncoded | ServerFailureEncodedSince v4.0.0
ServerSuccessEncoded (type alias)
Section titled “ServerSuccessEncoded (type alias)”Encoded success response sent by the server for a client-initiated request.
Signature
type ServerSuccessEncoded = SuccessEncoded<typeof ClientRequestRpcs>Since v4.0.0
SuccessEncoded (type alias)
Section titled “SuccessEncoded (type alias)”Encoded success response for an RPC in Group, containing the original
request id and encoded result.
Signature
type SuccessEncoded<Group> = RpcGroup.Rpcs<Group> extends infer Rpc ? Rpc extends Rpc.Rpc<infer _Tag, infer _Payload, infer _Success, infer _Error, infer _Middleware> ? { readonly _tag: "Success" readonly id: string | number readonly result: _Success["Encoded"] } : never : neverSince v4.0.0
resources
Section titled “resources”BlobResourceContents (class)
Section titled “BlobResourceContents (class)”Schema for binary resource contents represented as a Uint8Array.
Signature
declare class BlobResourceContentsSince v4.0.0
ListResourceTemplates (class)
Section titled “ListResourceTemplates (class)”Sent from the client to request a list of resource templates the server has.
Signature
declare class ListResourceTemplatesSince v4.0.0
ListResourceTemplatesResult (class)
Section titled “ListResourceTemplatesResult (class)”Schema for the server’s response to a resources/templates/list request from the client.
Signature
declare class ListResourceTemplatesResultSince v4.0.0
ListResources (class)
Section titled “ListResources (class)”Sent from the client to request a list of resources the server has.
Signature
declare class ListResourcesSince v4.0.0
ListResourcesResult (class)
Section titled “ListResourcesResult (class)”Schema for the server’s response to a resources/list request from the client.
Signature
declare class ListResourcesResultSince v4.0.0
ReadResource (class)
Section titled “ReadResource (class)”Sent from the client to the server, to read a specific resource URI.
Signature
declare class ReadResourceSince v4.0.0
ReadResourceResult (class)
Section titled “ReadResourceResult (class)”Schema for the server’s response to a resources/read request from the client.
Signature
declare class ReadResourceResultSince v4.0.0
Resource (class)
Section titled “Resource (class)”Schema for a known resource that the server is capable of reading.
Signature
declare class ResourceSince v4.0.0
ResourceContents (class)
Section titled “ResourceContents (class)”Schema for the contents of a specific resource or sub-resource.
Signature
declare class ResourceContentsSince v4.0.0
ResourceListChangedNotification (class)
Section titled “ResourceListChangedNotification (class)”Represents a notification that the server’s resource list changed.
When to use
Use to notify clients that resources/list should be requested again.
Details
Servers may send this notification without a previous client subscription.
Signature
declare class ResourceListChangedNotificationSince v4.0.0
ResourceTemplate (class)
Section titled “ResourceTemplate (class)”Schema for a template description of resources available on the server.
Signature
declare class ResourceTemplateSince v4.0.0
ResourceUpdatedNotification (class)
Section titled “ResourceUpdatedNotification (class)”Sent from the server when a subscribed resource URI has changed.
Details
The URI may identify a sub-resource of the resource that the client originally subscribed to.
Signature
declare class ResourceUpdatedNotificationSince v4.0.0
Subscribe (class)
Section titled “Subscribe (class)”Sent from the client to request resources/updated notifications from the server whenever a particular resource changes.
Signature
declare class SubscribeSince v4.0.0
TextResourceContents (class)
Section titled “TextResourceContents (class)”Schema for text resource contents represented as a string.
Signature
declare class TextResourceContentsSince v4.0.0
Unsubscribe (class)
Section titled “Unsubscribe (class)”Sent from the client to request cancellation of resources/updated notifications from the server. This should follow a previous resources/subscribe request.
Signature
declare class UnsubscribeSince v4.0.0
ListRoots (class)
Section titled “ListRoots (class)”Sent from the server to request a list of root URIs from the client. Roots allow servers to ask for specific directories or files to operate on. A common example for roots is providing a set of repositories or directories a server should operate on.
Details
This request is typically used when the server needs to understand the file system structure or access specific locations that the client has permission to read from.
Signature
declare class ListRootsSince v4.0.0
ListRootsResult (class)
Section titled “ListRootsResult (class)”Represents a client response containing the roots available to the server.
When to use
Use to return the directories or files that an MCP server may operate on.
Signature
declare class ListRootsResultSince v4.0.0
Root (class)
Section titled “Root (class)”Represents a root directory or file that the server can operate on.
Signature
declare class RootSince v4.0.0
RootsListChangedNotification (class)
Section titled “RootsListChangedNotification (class)”Represents a notification that the client’s root list changed.
When to use
Use to tell the server that it should request an updated roots list.
Details
Send this when the client adds, removes, or modifies a root.
Signature
declare class RootsListChangedNotificationSince v4.0.0
sampling
Section titled “sampling”CreateMessage (class)
Section titled “CreateMessage (class)”Represents a server request for the client to sample an LLM.
When to use
Use when you need to request model sampling from an MCP client on behalf of a server.
Details
The client chooses the model and should ask the user to approve the sampling request before it begins.
Signature
declare class CreateMessageSince v4.0.0
CreateMessageResult (class)
Section titled “CreateMessageResult (class)”Represents a client response to an MCP sampling request.
When to use
Use to return the message produced by client-side model sampling.
Details
The client should let the user inspect the sampled message before returning it to the server.
Signature
declare class CreateMessageResultSince v4.0.0
ModelHint (class)
Section titled “ModelHint (class)”Schema for model selection hints.
Details
Keys not declared here are currently left unspecified by the spec and are up to the client to interpret.
Signature
declare class ModelHintSince v4.0.0
ModelPreferences (class)
Section titled “ModelPreferences (class)”Schema for the server’s model selection preferences requested of the client during sampling.
Details
Because LLMs can vary along multiple dimensions, choosing the “best” model is rarely straightforward. Different models excel in different areas, some are faster but less capable, others are more capable but more expensive, and so on. This interface allows servers to express their priorities across multiple dimensions to help clients make an appropriate selection for their use case.
Gotchas
These preferences are always advisory. The client MAY ignore them. It is also up to the client to decide how to interpret these preferences and how to balance them against other considerations.
Signature
declare class ModelPreferencesSince v4.0.0
SamplingMessage (class)
Section titled “SamplingMessage (class)”Describes a message issued to or received from an LLM API.
Signature
declare class SamplingMessageSince v4.0.0
schemas
Section titled “schemas”Annotations (class)
Section titled “Annotations (class)”Schema for optional client-facing annotations on MCP objects.
When to use
Use to describe intended audience and priority metadata for objects shown or processed by a client.
Signature
declare class AnnotationsSince v4.0.0
AudioContent (class)
Section titled “AudioContent (class)”Represents audio content provided to or from an LLM.
Signature
declare class AudioContentSince v4.0.0
ClientCapabilities (class)
Section titled “ClientCapabilities (class)”Describes capabilities advertised by an MCP client.
When to use
Use to describe which optional MCP features a client supports during initialization.
Details
Known capabilities are represented by this schema, but the capability set is open and clients may define additional capabilities.
Signature
declare class ClientCapabilitiesSince v4.0.0
ContentBlock
Section titled “ContentBlock”Schema for MCP content blocks that can appear in prompt messages or tool results.
Signature
declare const ContentBlock: Schema.Union< readonly [typeof TextContent, typeof ImageContent, typeof AudioContent, typeof EmbeddedResource, typeof ResourceLink]>Since v4.0.0
Cursor
Section titled “Cursor”Schema for opaque cursor tokens used in pagination.
Signature
declare const Cursor: Schema.StringSince v4.0.0
EmbeddedResource (class)
Section titled “EmbeddedResource (class)”Represents resource contents embedded into a prompt or tool call result.
Details
It is up to the client how best to render embedded resources for the benefit of the LLM and/or the user.
Signature
declare class EmbeddedResourceSince v4.0.0
GetPromptResult (class)
Section titled “GetPromptResult (class)”Represents the server response to a prompts/get request from the client.
Signature
declare class GetPromptResultSince v4.0.0
ImageContent (class)
Section titled “ImageContent (class)”Represents image content provided to or from an LLM.
Signature
declare class ImageContentSince v4.0.0
Implementation (class)
Section titled “Implementation (class)”Describes the name and version of an MCP implementation.
Signature
declare class ImplementationSince v4.0.0
ListPromptsResult (class)
Section titled “ListPromptsResult (class)”Represents the server response to a prompts/list request from the client.
Signature
declare class ListPromptsResultSince v4.0.0
McpErrorBase (class)
Section titled “McpErrorBase (class)”Schema for MCP and JSON-RPC error objects.
Details
It contains the numeric error code, a concise message, and optional
sender-defined data.
Signature
declare class McpErrorBaseSince v4.0.0
NotificationMeta (class)
Section titled “NotificationMeta (class)”Schema for optional MCP notification metadata.
Details
The _meta field is reserved for protocol, extension, or implementation
metadata attached to a notification.
Signature
declare class NotificationMetaSince v4.0.0
PaginatedRequestMeta (class)
Section titled “PaginatedRequestMeta (class)”Schema for MCP request metadata used by paginated requests.
Details
It includes the base request metadata fields plus an optional cursor indicating where the server should continue listing results.
Signature
declare class PaginatedRequestMetaSince v4.0.0
PaginatedResultMeta (class)
Section titled “PaginatedResultMeta (class)”Schema for MCP result metadata returned by paginated operations.
Details
It includes the base result metadata fields plus an optional nextCursor,
which indicates that more results may be available.
Signature
declare class PaginatedResultMetaSince v4.0.0
ProgressToken
Section titled “ProgressToken”Schema for MCP progress tokens that associate progress notifications with the original request.
Signature
declare const ProgressToken: Schema.Union<[Schema.String, Schema.Number]>Since v4.0.0
Prompt (class)
Section titled “Prompt (class)”Represents a prompt or prompt template that the server offers.
Signature
declare class PromptSince v4.0.0
PromptArgument (class)
Section titled “PromptArgument (class)”Describes an argument that a prompt can accept.
Signature
declare class PromptArgumentSince v4.0.0
PromptMessage (class)
Section titled “PromptMessage (class)”Describes a message returned as part of a prompt.
Details
This is similar to SamplingMessage, but also supports the embedding of
resources from the MCP server.
Signature
declare class PromptMessageSince v4.0.0
RequestId
Section titled “RequestId”Schema for JSON-RPC request identifiers, allowing string or number ids.
Signature
declare const RequestId: Schema.Union<[Schema.String, Schema.Number]>Since v4.0.0
RequestMeta (class)
Section titled “RequestMeta (class)”Schema for optional MCP request metadata.
Details
Request metadata may include a progress token that asks the receiver to send out-of-band progress notifications for the request.
Signature
declare class RequestMetaSince v4.0.0
ResourceLink (class)
Section titled “ResourceLink (class)”Represents a readable resource included in a prompt or tool call result.
Gotchas
Resource links returned by tools are not guaranteed to appear in the results
of resources/list requests.
Signature
declare class ResourceLinkSince v4.0.0
ResultMeta (class)
Section titled “ResultMeta (class)”Schema for optional MCP result metadata.
Details
The _meta field is reserved for protocol, extension, or implementation
metadata attached to a result.
Signature
declare class ResultMetaSince v4.0.0
Schema for MCP conversation roles, allowing user and assistant.
Signature
declare const Role: Schema.Literals<["user", "assistant"]>Since v4.0.0
ServerCapabilities (class)
Section titled “ServerCapabilities (class)”Describes capabilities advertised by an MCP server.
When to use
Use to describe which optional MCP features a server supports during initialization.
Details
Known capabilities are represented by this schema, but the capability set is open and servers may define additional capabilities.
Signature
declare class ServerCapabilitiesSince v4.0.0
TextContent (class)
Section titled “TextContent (class)”Represents text content provided to or from an LLM.
Signature
declare class TextContentSince v4.0.0
optional
Section titled “optional”Creates an optional MCP struct-field schema from a required schema.
Details
The field may be absent, and explicit undefined values are omitted when
encoding.
Signature
declare const optional: <S extends Schema.Constraint>( schema: S) => Schema.decodeTo<Schema.optional<S>, Schema.optionalKey<S>>Since v4.0.0
optionalWithDefault
Section titled “optionalWithDefault”Marks a struct field as optional and supplies defaultValue when the field
is absent.
Details
The default is used during decoding and as the constructor default for the schema field.
Signature
declare const optionalWithDefault: <S extends Schema.Constraint & Schema.WithoutConstructorDefault>( schema: S, defaultValue: () => Schema.optionalKey<S>["Type"]) => optionalWithDefault<S>Since v4.0.0
CallTool (class)
Section titled “CallTool (class)”Represents a client request to invoke a tool provided by the server.
When to use
Use when you need to represent a client request that already knows the tool name and asks the server to execute it with argument values.
See
ListToolsfor discovering available tools before calling oneCallToolResultfor the successful tool-call result shape
Signature
declare class CallToolSince v4.0.0
CallToolResult (class)
Section titled “CallToolResult (class)”Schema for the server’s response to a tool call.
Details
Any errors that originate from the tool SHOULD be reported inside the result
object, with isError set to true, not as an MCP protocol-level error
response. Otherwise, the LLM would not be able to see that an error occurred
and self-correct. However, any errors in finding the tool, an error
indicating that the server does not support tool calls, or any other
exceptional conditions, should be reported as an MCP error response.
Signature
declare class CallToolResultSince v4.0.0
ListTools (class)
Section titled “ListTools (class)”Sent from the client to request a list of tools the server has.
Signature
declare class ListToolsSince v4.0.0
ListToolsResult (class)
Section titled “ListToolsResult (class)”Schema for the server’s response to a tools/list request from the client.
Signature
declare class ListToolsResultSince v4.0.0
Tool (class)
Section titled “Tool (class)”Schema for the definition of a tool the client can call.
Signature
declare class ToolSince v4.0.0
ToolAnnotations (class)
Section titled “ToolAnnotations (class)”Schema for additional properties describing a tool to clients.
Details
NOTE: all properties in ToolAnnotations are hints. They are not
guaranteed to provide a faithful description of tool behavior (including
descriptive properties like title).
Gotchas
Clients should never make tool use decisions based on ToolAnnotations received from untrusted servers.
Signature
declare class ToolAnnotationsSince v4.0.0
ToolListChangedNotification (class)
Section titled “ToolListChangedNotification (class)”Represents a notification that the server’s tool list changed.
When to use
Use to notify clients that tools/list should be requested again.
Details
Servers may send this notification without a previous client subscription.
Signature
declare class ToolListChangedNotificationSince v4.0.0