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

MCP TypeScript SDK (V2) / @modelcontextprotocol/client / client/sse

client/sse

Classes

SSEClientTransport

Defined in: packages/client/src/client/sse.ts:120

Client transport for SSE: this will connect to a server using Server-Sent Events for receiving messages and make separate POST requests for sending messages.

Deprecated

SSEClientTransport is deprecated. Prefer to use StreamableHTTPClientTransport where possible instead. Note that because some servers are still using SSE, clients may need to support both transports during the migration period.

Implements

Constructors

Constructor

new SSEClientTransport(url, opts?): SSEClientTransport

Defined in: packages/client/src/client/sse.ts:140

Parameters
url

URL

opts?

SSEClientTransportOptions

Returns

SSEClientTransport

Properties

onclose?

optional onclose?: () => void

Defined in: packages/client/src/client/sse.ts:136

Callback for when the connection is closed for any reason.

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

Returns

void

Implementation of

Transport.onclose

onerror?

optional onerror?: (error) => void

Defined in: packages/client/src/client/sse.ts:137

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

Implementation of

Transport.onerror

onmessage?

optional onmessage?: (message) => void

Defined in: packages/client/src/client/sse.ts:138

Callback for when a message (request or response) is received over the connection.

Includes the request and authInfo if the transport is authenticated.

The request can be used to get the original request information (headers, etc.)

Parameters
message

JSONRPCMessage

Returns

void

Implementation of

Transport.onmessage

Methods

close()

close(): Promise<void>

Defined in: packages/client/src/client/sse.ts:329

Closes the connection.

Returns

Promise<void>

Implementation of

Transport.close

finishAuth()
Call Signature

finishAuth(callbackParams): Promise<void>

Defined in: packages/client/src/client/sse.ts:295

Call this method after the user has finished authorizing via their user agent and is redirected back to the MCP client application. This will exchange the authorization code for an access token, enabling the next connection attempt to successfully auth.

Preferred: pass the callback URL's searchParams directly. The SDK extracts code and iss, validates iss against the recorded issuer (RFC 9207) before reading any other parameter, and on mismatch throws an IssuerMismatchError that carries none of the callback's error/error_description/error_uri text. The (code, iss?) positional form remains supported for back-compat.

The SDK does not validate state; compare it to your stored value before calling finishAuth.

Parameters
callbackParams

URLSearchParams

The URLSearchParams from the authorization callback URL (e.g. new URL(callbackUrl).searchParams). code and iss are read from it.

Returns

Promise<void>

Call Signature

finishAuth(authorizationCode, iss?): Promise<void>

Defined in: packages/client/src/client/sse.ts:301

Parameters
authorizationCode

string

The code query parameter from the authorization callback URL.

iss?

string

The form-urldecoded iss query parameter from the same callback URL, if present. Validated per RFC 9207 against the recorded issuer before the code is redeemed.

Returns

Promise<void>

send()

send(message): Promise<void>

Defined in: packages/client/src/client/sse.ts:335

Sends a JSON-RPC message (request or response).

If present, relatedRequestId is used to indicate to the transport which incoming request to associate this outgoing message with.

Parameters
message

JSONRPCMessage

Returns

Promise<void>

Implementation of

Transport.send

setProtocolVersion()

setProtocolVersion(version): void

Defined in: packages/client/src/client/sse.ts:396

Sets the protocol version used for the connection (called when the initialize response is received).

Parameters
version

string

Returns

void

Implementation of

Transport.setProtocolVersion

start()

start(): Promise<void>

Defined in: packages/client/src/client/sse.ts:272

Starts processing messages on the transport, including any connection steps that might need to be taken.

This method should only be called after callbacks are installed, or else messages may be lost.

NOTE: This method should not be called explicitly when using Client or Server classes, as they will implicitly call start().

Returns

Promise<void>

Implementation of

Transport.start


SseError

Defined in: packages/client/src/client/sse.ts:27

Extends

  • Error

Constructors

Constructor

new SseError(code, message, event): SseError

Defined in: packages/client/src/client/sse.ts:54

Parameters
code

number | undefined

message

string | undefined

event

ErrorEvent

Returns

SseError

Overrides

Error.constructor

Properties

cause?

optional cause?: unknown

Defined in: node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2022.error.d.ts:26

Inherited from

Error.cause

code

readonly code: number | undefined

Defined in: packages/client/src/client/sse.ts:55

event

readonly event: ErrorEvent

Defined in: packages/client/src/client/sse.ts:57

message

message: string

Defined in: node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es5.d.ts:1077

Inherited from

Error.message

name

name: string

Defined in: node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es5.d.ts:1076

Inherited from

Error.name

stack?

optional stack?: string

Defined in: node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es5.d.ts:1078

Inherited from

Error.stack

stackTraceLimit

static stackTraceLimit: number

Defined in: node_modules/.pnpm/@types+node@24.12.0/node_modules/@types/node/globals.d.ts:68

The Error.stackTraceLimit property specifies the number of stack frames collected by a stack trace (whether generated by new Error().stack or Error.captureStackTrace(obj)).

The default value is 10 but may be set to any valid JavaScript number. Changes will affect any stack trace captured after the value has been changed.

If set to a non-number value, or set to a negative number, stack traces will not capture any frames.

Inherited from

Error.stackTraceLimit

Methods

[hasInstance]()

static [hasInstance](value): boolean

Defined in: packages/client/src/client/sse.ts:32

Parameters
value

unknown

Returns

boolean

captureStackTrace()

static captureStackTrace(targetObject, constructorOpt?): void

Defined in: node_modules/.pnpm/@types+node@24.12.0/node_modules/@types/node/globals.d.ts:52

Creates a .stack property on targetObject, which when accessed returns a string representing the location in the code at which Error.captureStackTrace() was called.

js
const myObject = {};
Error.captureStackTrace(myObject);
myObject.stack;  // Similar to `new Error().stack`

The first line of the trace will be prefixed with ${myObject.name}: ${myObject.message}.

The optional constructorOpt argument accepts a function. If given, all frames above constructorOpt, including constructorOpt, will be omitted from the generated stack trace.

The constructorOpt argument is useful for hiding implementation details of error generation from the user. For instance:

js
function a() {
  b();
}

function b() {
  c();
}

function c() {
  // Create an error without stack trace to avoid calculating the stack trace twice.
  const { stackTraceLimit } = Error;
  Error.stackTraceLimit = 0;
  const error = new Error();
  Error.stackTraceLimit = stackTraceLimit;

  // Capture the stack trace above function b
  Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace
  throw error;
}

a();
Parameters
targetObject

object

constructorOpt?

Function

Returns

void

Inherited from

Error.captureStackTrace

isError()

static isError(error): error is Error

Defined in: node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.esnext.error.d.ts:23

Indicates whether the argument provided is a built-in Error instance or not.

Parameters
error

unknown

Returns

error is Error

Inherited from

Error.isError

isInstance()

static isInstance<T>(this, value): value is InstanceType<T>

Defined in: packages/client/src/client/sse.ts:45

Brand-based type guard: equivalent to value instanceof this, as an explicit static predicate (the axios/AWS-SDK isInstance style). Reads the caller's own brand via this, so every branded subclass gets a correctly-scoped guard by inheritance. Must be invoked on the class — in callback position write v => SdkError.isInstance(v), not .filter(SdkError.isInstance) (detached calls throw rather than silently matching nothing).

Type Parameters
T

T extends (...args) => unknown

Parameters
this

T

value

unknown

Returns

value is InstanceType<T>

prepareStackTrace()

static prepareStackTrace(err, stackTraces): any

Defined in: node_modules/.pnpm/@types+node@24.12.0/node_modules/@types/node/globals.d.ts:56

Parameters
err

Error

stackTraces

CallSite[]

Returns

any

See

https://v8.dev/docs/stack-trace-api#customizing-stack-traces

Inherited from

Error.prepareStackTrace

Type Aliases

SSEClientTransportOptions

SSEClientTransportOptions = object

Defined in: packages/client/src/client/sse.ts:67

Configuration options for the SSEClientTransport.

Properties

authProvider?

optional authProvider?: AuthProvider | OAuthClientProvider

Defined in: packages/client/src/client/sse.ts:83

An OAuth client provider to use for authentication.

token() is called before every request to obtain the bearer token. When the server responds with 401, onUnauthorized() is called (if provided) to refresh credentials, then the request is retried once. If the retry also gets 401, or onUnauthorized is not provided, UnauthorizedError is thrown.

For simple bearer tokens: { token: async () => myApiKey }.

For OAuth flows, pass an OAuthClientProvider implementation. Interactive flows: after UnauthorizedError, redirect the user, then call finishAuth with the authorization code before reconnecting.

eventSourceInit?

optional eventSourceInit?: EventSourceInit

Defined in: packages/client/src/client/sse.ts:102

Customizes the initial SSE request to the server (the request that begins the stream).

NOTE: Setting this property will prevent an Authorization header from being automatically attached to the SSE request, if an authProvider is also given. This can be worked around by setting the Authorization header manually.

fetch?

optional fetch?: FetchLike

Defined in: packages/client/src/client/sse.ts:112

Custom fetch implementation used for all network requests.

requestInit?

optional requestInit?: RequestInit

Defined in: packages/client/src/client/sse.ts:107

Customizes recurring POST requests to the server.

skipIssuerMetadataValidation?

optional skipIssuerMetadataValidation?: boolean

Defined in: packages/client/src/client/sse.ts:92

Opt-out for the RFC 8414 §3.3 issuer-echo check during authorization-server metadata discovery. Security-weakening — see AuthOptions.skipIssuerMetadataValidation. Only honoured when authProvider is an OAuthClientProvider.