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

MCP TypeScript SDK / inMemory

inMemory

Classes

InMemoryTransport

Defined in: src/inMemory.ts:13

In-memory transport for creating clients and servers that talk to each other within the same process.

Implements

Constructors

Constructor

new InMemoryTransport(): InMemoryTransport

Returns

InMemoryTransport

Properties

onclose?

optional onclose?: () => void

Defined in: src/inMemory.ts:17

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: src/inMemory.ts:18

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, extra?) => void

Defined in: src/inMemory.ts:19

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

Includes the requestInfo and authInfo if the transport is authenticated.

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

Parameters
message

JSONRPCMessage

extra?
authInfo?

AuthInfo

Returns

void

Implementation of

Transport.onmessage

sessionId?

optional sessionId?: string

Defined in: src/inMemory.ts:20

The session ID generated for this connection.

Implementation of

Transport.sessionId

Methods

close()

close(): Promise<void>

Defined in: src/inMemory.ts:41

Closes the connection.

Returns

Promise<void>

Implementation of

Transport.close

send()

send(message, options?): Promise<void>

Defined in: src/inMemory.ts:52

Sends a message with optional auth info. This is useful for testing authentication scenarios.

Parameters
message

JSONRPCMessage

options?
authInfo?

AuthInfo

relatedRequestId?

RequestId

Returns

Promise<void>

Implementation of

Transport.send

start()

start(): Promise<void>

Defined in: src/inMemory.ts:33

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, Server, or Protocol classes, as they will implicitly call start().

Returns

Promise<void>

Implementation of

Transport.start

createLinkedPair()

static createLinkedPair(): [InMemoryTransport, InMemoryTransport]

Defined in: src/inMemory.ts:25

Creates a pair of linked in-memory transports that can communicate with each other. One should be passed to a Client and one to a Server.

Returns

[InMemoryTransport, InMemoryTransport]