Initializes this client with the given name and version information.
Intended for programmatic or logical use, but used as a display name in past specs or fallback
Optionaltitle?: stringIntended for UI and end-user contexts — optimized to be human-readable and easily understood, even by those unfamiliar with domain-specific terminology.
If not provided, the name should be used for display (except for Tool,
where annotations.title should be given precedence over using name,
if present).
Optionaloptions: ClientOptionsOptionalfallbackA handler to invoke for any notification types that do not have their own handler installed.
OptionalfallbackA handler to invoke for any request types that do not have their own handler installed.
OptionaloncloseCallback for when the connection is closed for any reason.
This is invoked when close() is called as well.
OptionalonerrorCallback for when an error occurs.
Note that errors are not necessarily fatal; they are used for reporting any kind of exceptional condition out of band.
Asserts that a request handler has not already been set for the given method, in preparation for a new one being automatically installed.
ProtectedassertProtectedassertA method to check if a capability is supported by the remote side, for the given method to be called.
This should be implemented by subclasses.
ProtectedassertA method to check if a notification is supported by the local side, for the given method to be sent.
This should be implemented by subclasses.
ProtectedassertA method to check if a request handler is supported by the local side, for the given method to be handled.
This should be implemented by subclasses.
Optionaloptions: RequestOptionsCloses the connection.
Optional_meta?: { progressToken?: string | number; [key: string]: unknown }OptionalprogressToken?: string | numberIf specified, the caller is requesting out-of-band progress notifications for this request (as represented by notifications/progress). The value of this parameter is an opaque token that will be attached to any subsequent notifications. The receiver is not obligated to provide these notifications.
The argument's information
The name of the argument
The value of the argument to use for completion matching.
Optionalcontext?: { arguments?: { [key: string]: string } }Optionalarguments?: { [key: string]: string }Previously-resolved variables in a URI template or prompt.
Optionaloptions: RequestOptionsAttaches 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.
Optionaloptions: RequestOptionsAfter initialization has completed, this may be populated with information about the server's instructions.
Optional_meta?: { progressToken?: string | number; [key: string]: unknown }OptionalprogressToken?: string | numberIf specified, the caller is requesting out-of-band progress notifications for this request (as represented by notifications/progress). The value of this parameter is an opaque token that will be attached to any subsequent notifications. The receiver is not obligated to provide these notifications.
Optionalarguments?: { [key: string]: string }Arguments to use for templating the prompt.
The name of the prompt or prompt template.
Optionaloptions: RequestOptionsAfter initialization has completed, this will be populated with the server's reported capabilities.
Optionalcompletions?: { [key: string]: unknown }Present if the server supports sending completions to the client.
Optionalexperimental?: { [key: string]: unknown }Experimental, non-standard capabilities that the server supports.
Optionallogging?: { [key: string]: unknown }Present if the server supports sending log messages to the client.
Optionalprompts?: { listChanged?: boolean; [key: string]: unknown }Present if the server offers any prompt templates.
OptionallistChanged?: booleanWhether this server supports issuing notifications for changes to the prompt list.
Optionalresources?: { listChanged?: boolean; subscribe?: boolean; [key: string]: unknown }Present if the server offers any resources to read.
OptionallistChanged?: booleanWhether this server supports issuing notifications for changes to the resource list.
Optionalsubscribe?: booleanWhether this server supports clients subscribing to resource updates.
Optionaltools?: { listChanged?: boolean; [key: string]: unknown }Present if the server offers any tools to call.
OptionallistChanged?: booleanWhether this server supports issuing notifications for changes to the tool list.
After initialization has completed, this will be populated with information about the server's name and version.
Intended for programmatic or logical use, but used as a display name in past specs or fallback
Optionaltitle?: stringIntended for UI and end-user contexts — optimized to be human-readable and easily understood, even by those unfamiliar with domain-specific terminology.
If not provided, the name should be used for display (except for Tool,
where annotations.title should be given precedence over using name,
if present).
Optionalparams: {Optional_meta?: { progressToken?: string | number; [key: string]: unknown }OptionalprogressToken?: string | numberIf specified, the caller is requesting out-of-band progress notifications for this request (as represented by notifications/progress). The value of this parameter is an opaque token that will be attached to any subsequent notifications. The receiver is not obligated to provide these notifications.
Optionalcursor?: stringAn opaque token representing the current pagination position. If provided, the server should return results starting after this cursor.
Optionaloptions: RequestOptionsOptionalparams: {Optional_meta?: { progressToken?: string | number; [key: string]: unknown }OptionalprogressToken?: string | numberIf specified, the caller is requesting out-of-band progress notifications for this request (as represented by notifications/progress). The value of this parameter is an opaque token that will be attached to any subsequent notifications. The receiver is not obligated to provide these notifications.
Optionalcursor?: stringAn opaque token representing the current pagination position. If provided, the server should return results starting after this cursor.
Optionaloptions: RequestOptionsOptionalparams: {Optional_meta?: { progressToken?: string | number; [key: string]: unknown }OptionalprogressToken?: string | numberIf specified, the caller is requesting out-of-band progress notifications for this request (as represented by notifications/progress). The value of this parameter is an opaque token that will be attached to any subsequent notifications. The receiver is not obligated to provide these notifications.
Optionalcursor?: stringAn opaque token representing the current pagination position. If provided, the server should return results starting after this cursor.
Optionaloptions: RequestOptionsOptionalparams: {Optional_meta?: { progressToken?: string | number; [key: string]: unknown }OptionalprogressToken?: string | numberIf specified, the caller is requesting out-of-band progress notifications for this request (as represented by notifications/progress). The value of this parameter is an opaque token that will be attached to any subsequent notifications. The receiver is not obligated to provide these notifications.
Optionalcursor?: stringAn opaque token representing the current pagination position. If provided, the server should return results starting after this cursor.
Optionaloptions: RequestOptionsEmits a notification, which is a one-way message that does not expect a response.
Optionaloptions: NotificationOptionsOptionaloptions: RequestOptionsOptional_meta?: { progressToken?: string | number; [key: string]: unknown }OptionalprogressToken?: string | numberIf specified, the caller is requesting out-of-band progress notifications for this request (as represented by notifications/progress). The value of this parameter is an opaque token that will be attached to any subsequent notifications. The receiver is not obligated to provide these notifications.
The URI of the resource to read. The URI can use any protocol; it is up to the server how to interpret it.
Optionaloptions: RequestOptionsRegisters 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).
Optionalelicitation?: { [key: string]: unknown }Present if the client supports eliciting user input.
Optionalexperimental?: { [key: string]: unknown }Experimental, non-standard capabilities that the client supports.
Optionalroots?: { listChanged?: boolean; [key: string]: unknown }Present if the client supports listing roots.
OptionallistChanged?: booleanWhether the client supports issuing notifications for changes to the roots list.
Optionalsampling?: { [key: string]: unknown }Present if the client supports sampling from an LLM.
Removes the notification handler for the given method.
Removes the request handler for the given method.
Sends a request and wait for a response.
Do not use this method to emit notifications! Use notification() instead.
Optionaloptions: RequestOptionsOptionaloptions: RequestOptionsRegisters 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.
Registers a handler to invoke when this protocol object receives a request with the given method.
Note that this will replace any previous request handler for the same method.
Optional_meta?: { progressToken?: string | number; [key: string]: unknown }OptionalprogressToken?: string | numberIf specified, the caller is requesting out-of-band progress notifications for this request (as represented by notifications/progress). The value of this parameter is an opaque token that will be attached to any subsequent notifications. The receiver is not obligated to provide these notifications.
The URI of the resource to subscribe to. The URI can use any protocol; it is up to the server how to interpret it.
Optionaloptions: RequestOptionsOptional_meta?: { progressToken?: string | number; [key: string]: unknown }OptionalprogressToken?: string | numberIf specified, the caller is requesting out-of-band progress notifications for this request (as represented by notifications/progress). The value of this parameter is an opaque token that will be attached to any subsequent notifications. The receiver is not obligated to provide these notifications.
The URI of the resource to unsubscribe from.
Optionaloptions: RequestOptions
An MCP client on top of a pluggable transport.
The client will automatically begin the initialization flow with the server when connect() is called.
To use with custom types, extend the base Request/Notification/Result types and pass them as type parameters: