Skip to main content

FastMCPSession

@codebolt/mcp


Class: FastMCPSession<T>

Defined in: packages/mcp/src/mcpServer.ts:556

Class representing a FastMCP session. Manages communication between the client and server.

Extends

  • FastMCPSessionEventEmitter

Type Parameters

Type ParameterDefault type
T extends FastMCPSessionAuthFastMCPSessionAuth

Constructors

Constructor

new FastMCPSession<T>(options: {
auth?: T;
name: string;
prompts: Prompt<Readonly<{
complete?: ArgumentValueCompleter;
description?: string;
enum?: string[];
name: string;
required?: boolean;
}>[], PromptArgumentsToObject<Readonly<{
complete?: ArgumentValueCompleter;
description?: string;
enum?: string[];
name: string;
required?: boolean;
}>[]>>[];
resources: Resource[];
resourcesTemplates: InputResourceTemplate<Readonly<{
complete?: ArgumentValueCompleter;
description?: string;
name: string;
}>[]>[];
tools: Tool<T, ZodTypeAny>[];
version: string;
}): FastMCPSession<T>;

Defined in: packages/mcp/src/mcpServer.ts:572

Creates a new FastMCPSession.

Parameters

ParameterTypeDescription
options{ auth?: T; name: string; prompts: Prompt<Readonly<{ complete?: ArgumentValueCompleter; description?: string; enum?: string[]; name: string; required?: boolean; }>[], PromptArgumentsToObject<Readonly<{ complete?: ArgumentValueCompleter; description?: string; enum?: string[]; name: string; required?: boolean; }>[]>>[]; resources: Resource[]; resourcesTemplates: InputResourceTemplate<Readonly<{ complete?: ArgumentValueCompleter; description?: string; name: string; }>[]>[]; tools: Tool<T, ZodTypeAny>[]; version: string; }Configuration options for the session
options.auth?T-
options.namestring-
options.promptsPrompt<Readonly<{ complete?: ArgumentValueCompleter; description?: string; enum?: string[]; name: string; required?: boolean; }>[], PromptArgumentsToObject<Readonly<{ complete?: ArgumentValueCompleter; description?: string; enum?: string[]; name: string; required?: boolean; }>[]>>[]-
options.resourcesResource[]-
options.resourcesTemplatesInputResourceTemplate<Readonly<{ complete?: ArgumentValueCompleter; description?: string; name: string; }>[]>[]-
options.toolsTool<T, ZodTypeAny>[]-
options.versionstring-

Returns

FastMCPSession<T>

Overrides

FastMCPSessionEventEmitter.constructor

Properties

PropertyTypeInherited fromDefined in
_emitterType?EventEmitter<DefaultEventMap>FastMCPSessionEventEmitter. _emitterTypenode_modules/.pnpm/strict-event-emitter-types@2.0.0/node_modules/strict-event-emitter-types/types/src/index.d.ts:5
_emitType?FastMCPSessionEventsFastMCPSessionEventEmitter. _emitTypenode_modules/.pnpm/strict-event-emitter-types@2.0.0/node_modules/strict-event-emitter-types/types/src/index.d.ts:7
_eventsType?FastMCPSessionEventsFastMCPSessionEventEmitter. _eventsTypenode_modules/.pnpm/strict-event-emitter-types@2.0.0/node_modules/strict-event-emitter-types/types/src/index.d.ts:6
[captureRejectionSymbol]?<K>(error: Error, event: string | symbol, ...args: AnyRest) => voidFastMCPSessionEventEmitter.[captureRejectionSymbol]node_modules/.pnpm/@types+node@20.19.19/node_modules/@types/node/events.d.ts:103

Accessors

clientCapabilities

Get Signature

get clientCapabilities():
| {
[key: string]: unknown;
elicitation?: {
[key: string]: unknown;
};
experimental?: {
[key: string]: unknown;
};
roots?: {
[key: string]: unknown;
listChanged?: boolean;
};
sampling?: {
[key: string]: unknown;
};
}
| null;

Defined in: packages/mcp/src/mcpServer.ts:718

Returns
{
[key: string]: unknown;
elicitation?: {
[key: string]: unknown;
};
experimental?: {
[key: string]: unknown;
};
roots?: {
[key: string]: unknown;
listChanged?: boolean;
};
sampling?: {
[key: string]: unknown;
};
}
Index Signature
[key: string]: unknown
NameTypeDescriptionDefined in
elicitation?{ [key: string]: unknown; }Present if the client supports eliciting user input.node_modules/.pnpm/@modelcontextprotocol+sdk@1.19.1/node_modules/@modelcontextprotocol/sdk/dist/esm/types.d.ts:1353
experimental?{ [key: string]: unknown; }Experimental, non-standard capabilities that the client supports.node_modules/.pnpm/@modelcontextprotocol+sdk@1.19.1/node_modules/@modelcontextprotocol/sdk/dist/esm/types.d.ts:1345
roots?{ [key: string]: unknown; listChanged?: boolean; }Present if the client supports listing roots.node_modules/.pnpm/@modelcontextprotocol+sdk@1.19.1/node_modules/@modelcontextprotocol/sdk/dist/esm/types.d.ts:1357
roots.listChanged?booleanWhether the client supports issuing notifications for changes to the roots list.node_modules/.pnpm/@modelcontextprotocol+sdk@1.19.1/node_modules/@modelcontextprotocol/sdk/dist/esm/types.d.ts:1366
sampling?{ [key: string]: unknown; }Present if the client supports sampling from an LLM.node_modules/.pnpm/@modelcontextprotocol+sdk@1.19.1/node_modules/@modelcontextprotocol/sdk/dist/esm/types.d.ts:1349

null


loggingLevel

Get Signature

get loggingLevel(): LoggingLevel;

Defined in: packages/mcp/src/mcpServer.ts:799

Returns

LoggingLevel


roots

Get Signature

get roots(): {
[key: string]: unknown;
_meta?: {
[key: string]: unknown;
};
name?: string;
uri: string;
}[];

Defined in: packages/mcp/src/mcpServer.ts:777

Returns

server

Get Signature

get server(): Server;

Defined in: packages/mcp/src/mcpServer.ts:722

Returns

Server

Methods

addListener()

Call Signature

addListener<P, T>(
this: T,
event: P,
listener: (...args: ListenerType<FastMCPSessionEvents[P]>) => void): T;

Defined in: node_modules/.pnpm/strict-event-emitter-types@2.0.0/node_modules/strict-event-emitter-types/types/src/index.d.ts:17

Type Parameters
Type Parameter
P extends keyof FastMCPSessionEvents
T
Parameters
ParameterType
thisT
eventP
listener(...args: ListenerType<FastMCPSessionEvents[P]>) => void
Returns

T

Inherited from
FastMCPSessionEventEmitter.addListener

Call Signature

addListener(event: typeof assignmentCompatibilityHack, listener: (...args: any[]) => any): void;

Defined in: node_modules/.pnpm/strict-event-emitter-types@2.0.0/node_modules/strict-event-emitter-types/types/src/index.d.ts:18

Parameters
ParameterType
eventtypeof assignmentCompatibilityHack
listener(...args: any[]) => any
Returns

void

Inherited from
FastMCPSessionEventEmitter.addListener

close()

close(): Promise<void>;

Defined in: packages/mcp/src/mcpServer.ts:781

Returns

Promise<void>


connect()

connect(transport: Transport): Promise<void>;

Defined in: packages/mcp/src/mcpServer.ts:734

Parameters

ParameterType
transportTransport

Returns

Promise<void>


emit()

Call Signature

emit<P, T>(
this: T,
event: P, ...
args: ListenerType<FastMCPSessionEvents[P]>): T;

Defined in: node_modules/.pnpm/strict-event-emitter-types@2.0.0/node_modules/strict-event-emitter-types/types/src/index.d.ts:27

Type Parameters
Type Parameter
P extends keyof FastMCPSessionEvents
T
Parameters
ParameterType
thisT
eventP
...argsListenerType<FastMCPSessionEvents[P]>
Returns

T

Inherited from
FastMCPSessionEventEmitter.emit

Call Signature

emit(event: typeof assignmentCompatibilityHack, ...args: any[]): void;

Defined in: node_modules/.pnpm/strict-event-emitter-types@2.0.0/node_modules/strict-event-emitter-types/types/src/index.d.ts:28

Parameters
ParameterType
eventtypeof assignmentCompatibilityHack
...argsany[]
Returns

void

Inherited from
FastMCPSessionEventEmitter.emit

eventNames()

eventNames(): (string | symbol)[];

Defined in: node_modules/.pnpm/@types+node@20.19.19/node_modules/@types/node/events.d.ts:968

Returns an array listing the events for which the emitter has registered listeners. The values in the array are strings or Symbols.

import { EventEmitter } from 'node:events';

const myEE = new EventEmitter();
myEE.on('foo', () => {});
myEE.on('bar', () => {});

const sym = Symbol('symbol');
myEE.on(sym, () => {});

console.log(myEE.eventNames());
// Prints: [ 'foo', 'bar', Symbol(symbol) ]

Returns

(string | symbol)[]

Since

v6.0.0

Inherited from

FastMCPSessionEventEmitter.eventNames

getMaxListeners()

getMaxListeners(): number;

Defined in: node_modules/.pnpm/@types+node@20.19.19/node_modules/@types/node/events.d.ts:820

Returns the current max listener value for the EventEmitter which is either set by emitter.setMaxListeners(n) or defaults to EventEmitter.defaultMaxListeners.

Returns

number

Since

v1.0.0

Inherited from

FastMCPSessionEventEmitter.getMaxListeners

listenerCount()

listenerCount<K>(eventName: string | symbol, listener?: Function): number;

Defined in: node_modules/.pnpm/@types+node@20.19.19/node_modules/@types/node/events.d.ts:914

Returns the number of listeners listening for the event named eventName. If listener is provided, it will return how many times the listener is found in the list of the listeners of the event.

Type Parameters

Type Parameter
K

Parameters

ParameterTypeDescription
eventNamestring | symbolThe name of the event being listened for
listener?FunctionThe event handler function

Returns

number

Since

v3.2.0

Inherited from

FastMCPSessionEventEmitter.listenerCount

listeners()

listeners<K>(eventName: string | symbol): Function[];

Defined in: node_modules/.pnpm/@types+node@20.19.19/node_modules/@types/node/events.d.ts:833

Returns a copy of the array of listeners for the event named eventName.

server.on('connection', (stream) => {
console.log('someone connected!');
});
console.log(util.inspect(server.listeners('connection')));
// Prints: [ [Function] ]

Type Parameters

Type Parameter
K

Parameters

ParameterType
eventNamestring | symbol

Returns

Function[]

Since

v0.1.26

Inherited from

FastMCPSessionEventEmitter.listeners

off()

off<K>(eventName: string | symbol, listener: (...args: any[]) => void): this;

Defined in: node_modules/.pnpm/@types+node@20.19.19/node_modules/@types/node/events.d.ts:793

Alias for emitter.removeListener().

Type Parameters

Type Parameter
K

Parameters

ParameterType
eventNamestring | symbol
listener(...args: any[]) => void

Returns

this

Since

v10.0.0

Inherited from

FastMCPSessionEventEmitter.off

on()

Call Signature

on<P, T>(
this: T,
event: P,
listener: (...args: ListenerType<FastMCPSessionEvents[P]>) => void): T;

Defined in: node_modules/.pnpm/strict-event-emitter-types@2.0.0/node_modules/strict-event-emitter-types/types/src/index.d.ts:15

Type Parameters
Type Parameter
P extends keyof FastMCPSessionEvents
T
Parameters
ParameterType
thisT
eventP
listener(...args: ListenerType<FastMCPSessionEvents[P]>) => void
Returns

T

Inherited from
FastMCPSessionEventEmitter.on

Call Signature

on(event: typeof assignmentCompatibilityHack, listener: (...args: any[]) => any): void;

Defined in: node_modules/.pnpm/strict-event-emitter-types@2.0.0/node_modules/strict-event-emitter-types/types/src/index.d.ts:16

Parameters
ParameterType
eventtypeof assignmentCompatibilityHack
listener(...args: any[]) => any
Returns

void

Inherited from
FastMCPSessionEventEmitter.on

once()

Call Signature

once<P, T>(
this: T,
event: P,
listener: (...args: ListenerType<FastMCPSessionEvents[P]>) => void): T;

Defined in: node_modules/.pnpm/strict-event-emitter-types@2.0.0/node_modules/strict-event-emitter-types/types/src/index.d.ts:25

Type Parameters
Type Parameter
P extends keyof FastMCPSessionEvents
T
Parameters
ParameterType
thisT
eventP
listener(...args: ListenerType<FastMCPSessionEvents[P]>) => void
Returns

T

Inherited from
FastMCPSessionEventEmitter.once

Call Signature

once(event: typeof assignmentCompatibilityHack, listener: (...args: any[]) => any): void;

Defined in: node_modules/.pnpm/strict-event-emitter-types@2.0.0/node_modules/strict-event-emitter-types/types/src/index.d.ts:26

Parameters
ParameterType
eventtypeof assignmentCompatibilityHack
listener(...args: any[]) => any
Returns

void

Inherited from
FastMCPSessionEventEmitter.once

prependListener()

prependListener<K>(eventName: string | symbol, listener: (...args: any[]) => void): this;

Defined in: node_modules/.pnpm/@types+node@20.19.19/node_modules/@types/node/events.d.ts:932

Adds the listener function to the beginning of the listeners array for the event named eventName. No checks are made to see if the listener has already been added. Multiple calls passing the same combination of eventName and listener will result in the listener being added, and called, multiple times.

server.prependListener('connection', (stream) => {
console.log('someone connected!');
});

Returns a reference to the EventEmitter, so that calls can be chained.

Type Parameters

Type Parameter
K

Parameters

ParameterTypeDescription
eventNamestring | symbolThe name of the event.
listener(...args: any[]) => voidThe callback function

Returns

this

Since

v6.0.0

Inherited from

FastMCPSessionEventEmitter.prependListener

prependOnceListener()

prependOnceListener<K>(eventName: string | symbol, listener: (...args: any[]) => void): this;

Defined in: node_modules/.pnpm/@types+node@20.19.19/node_modules/@types/node/events.d.ts:948

Adds a one-timelistener function for the event named eventName to the beginning of the listeners array. The next time eventName is triggered, this listener is removed, and then invoked.

server.prependOnceListener('connection', (stream) => {
console.log('Ah, we have our first user!');
});

Returns a reference to the EventEmitter, so that calls can be chained.

Type Parameters

Type Parameter
K

Parameters

ParameterTypeDescription
eventNamestring | symbolThe name of the event.
listener(...args: any[]) => voidThe callback function

Returns

this

Since

v6.0.0

Inherited from

FastMCPSessionEventEmitter.prependOnceListener

rawListeners()

rawListeners<K>(eventName: string | symbol): Function[];

Defined in: node_modules/.pnpm/@types+node@20.19.19/node_modules/@types/node/events.d.ts:864

Returns a copy of the array of listeners for the event named eventName, including any wrappers (such as those created by .once()).

import { EventEmitter } from 'node:events';
const emitter = new EventEmitter();
emitter.once('log', () => console.log('log once'));

// Returns a new Array with a function `onceWrapper` which has a property
// `listener` which contains the original listener bound above
const listeners = emitter.rawListeners('log');
const logFnWrapper = listeners[0];

// Logs "log once" to the console and does not unbind the `once` event
logFnWrapper.listener();

// Logs "log once" to the console and removes the listener
logFnWrapper();

emitter.on('log', () => console.log('log persistently'));
// Will return a new Array with a single function bound by `.on()` above
const newListeners = emitter.rawListeners('log');

// Logs "log persistently" twice
newListeners[0]();
emitter.emit('log');

Type Parameters

Type Parameter
K

Parameters

ParameterType
eventNamestring | symbol

Returns

Function[]

Since

v9.4.0

Inherited from

FastMCPSessionEventEmitter.rawListeners

removeAllListeners()

removeAllListeners(eventName?: string | symbol): this;

Defined in: node_modules/.pnpm/@types+node@20.19.19/node_modules/@types/node/events.d.ts:804

Removes all listeners, or those of the specified eventName.

It is bad practice to remove listeners added elsewhere in the code, particularly when the EventEmitter instance was created by some other component or module (e.g. sockets or file streams).

Returns a reference to the EventEmitter, so that calls can be chained.

Parameters

ParameterType
eventName?string | symbol

Returns

this

Since

v0.1.26

Inherited from

FastMCPSessionEventEmitter.removeAllListeners

removeListener()

Call Signature

removeListener<P, T>(
this: T,
event: P,
listener: (...args: any[]) => any): T;

Defined in: node_modules/.pnpm/strict-event-emitter-types@2.0.0/node_modules/strict-event-emitter-types/types/src/index.d.ts:21

Type Parameters
Type Parameter
P extends keyof FastMCPSessionEvents
T
Parameters
ParameterType
thisT
eventP
listener(...args: any[]) => any
Returns

T

Inherited from
FastMCPSessionEventEmitter.removeListener

Call Signature

removeListener(event: typeof assignmentCompatibilityHack, listener: (...args: any[]) => any): void;

Defined in: node_modules/.pnpm/strict-event-emitter-types@2.0.0/node_modules/strict-event-emitter-types/types/src/index.d.ts:22

Parameters
ParameterType
eventtypeof assignmentCompatibilityHack
listener(...args: any[]) => any
Returns

void

Inherited from
FastMCPSessionEventEmitter.removeListener

requestSampling()

requestSampling(message: {
_meta?: objectOutputType<{
progressToken: ZodOptional<ZodUnion<[ZodString, ZodNumber]>>;
}, ZodTypeAny, "passthrough">;
includeContext?: "none" | "thisServer" | "allServers";
maxTokens: number;
messages: objectOutputType<{
content: ZodUnion<[ZodObject<{
_meta: ZodOptional<ZodObject<..., ..., ..., ..., ...>>;
text: ZodString;
type: ZodLiteral<"text">;
}, "passthrough", ZodTypeAny, objectOutputType<{
_meta: ZodOptional<...>;
text: ZodString;
type: ZodLiteral<...>;
}, ZodTypeAny, "passthrough">, objectInputType<{
_meta: ZodOptional<...>;
text: ZodString;
type: ZodLiteral<...>;
}, ZodTypeAny, "passthrough">>, ZodObject<{
_meta: ZodOptional<ZodObject<..., ..., ..., ..., ...>>;
data: ZodEffects<ZodString, string, string>;
mimeType: ZodString;
type: ZodLiteral<"image">;
}, "passthrough", ZodTypeAny, objectOutputType<{
_meta: ZodOptional<...>;
data: ZodEffects<..., ..., ...>;
mimeType: ZodString;
type: ZodLiteral<...>;
}, ZodTypeAny, "passthrough">, objectInputType<{
_meta: ZodOptional<...>;
data: ZodEffects<..., ..., ...>;
mimeType: ZodString;
type: ZodLiteral<...>;
}, ZodTypeAny, "passthrough">>, ZodObject<{
_meta: ZodOptional<ZodObject<..., ..., ..., ..., ...>>;
data: ZodEffects<ZodString, string, string>;
mimeType: ZodString;
type: ZodLiteral<"audio">;
}, "passthrough", ZodTypeAny, objectOutputType<{
_meta: ZodOptional<...>;
data: ZodEffects<..., ..., ...>;
mimeType: ZodString;
type: ZodLiteral<...>;
}, ZodTypeAny, "passthrough">, objectInputType<{
_meta: ZodOptional<...>;
data: ZodEffects<..., ..., ...>;
mimeType: ZodString;
type: ZodLiteral<...>;
}, ZodTypeAny, "passthrough">>]>;
role: ZodEnum<["user", "assistant"]>;
}, ZodTypeAny, "passthrough">[];
metadata?: objectOutputType<{
}, ZodTypeAny, "passthrough">;
modelPreferences?: objectOutputType<{
costPriority: ZodOptional<ZodNumber>;
hints: ZodOptional<ZodArray<ZodObject<{
name: ZodOptional<ZodString>;
}, "passthrough", ZodTypeAny, objectOutputType<{
name: ZodOptional<...>;
}, ZodTypeAny, "passthrough">, objectInputType<{
name: ZodOptional<...>;
}, ZodTypeAny, "passthrough">>, "many">>;
intelligencePriority: ZodOptional<ZodNumber>;
speedPriority: ZodOptional<ZodNumber>;
}, ZodTypeAny, "passthrough">;
stopSequences?: string[];
systemPrompt?: string;
temperature?: number;
} & {
[k: string]: unknown;
}): Promise<SamplingResponse>;

Defined in: packages/mcp/src/mcpServer.ts:728

Parameters

ParameterType
message{ _meta?: objectOutputType<{ progressToken: ZodOptional<ZodUnion<[ZodString, ZodNumber]>>; }, ZodTypeAny, "passthrough">; includeContext?: "none" | "thisServer" | "allServers"; maxTokens: number; messages: objectOutputType<{ content: ZodUnion<[ZodObject<{ _meta: ZodOptional<ZodObject<..., ..., ..., ..., ...>>; text: ZodString; type: ZodLiteral<"text">; }, "passthrough", ZodTypeAny, objectOutputType<{ _meta: ZodOptional<...>; text: ZodString; type: ZodLiteral<...>; }, ZodTypeAny, "passthrough">, objectInputType<{ _meta: ZodOptional<...>; text: ZodString; type: ZodLiteral<...>; }, ZodTypeAny, "passthrough">>, ZodObject<{ _meta: ZodOptional<ZodObject<..., ..., ..., ..., ...>>; data: ZodEffects<ZodString, string, string>; mimeType: ZodString; type: ZodLiteral<"image">; }, "passthrough", ZodTypeAny, objectOutputType<{ _meta: ZodOptional<...>; data: ZodEffects<..., ..., ...>; mimeType: ZodString; type: ZodLiteral<...>; }, ZodTypeAny, "passthrough">, objectInputType<{ _meta: ZodOptional<...>; data: ZodEffects<..., ..., ...>; mimeType: ZodString; type: ZodLiteral<...>; }, ZodTypeAny, "passthrough">>, ZodObject<{ _meta: ZodOptional<ZodObject<..., ..., ..., ..., ...>>; data: ZodEffects<ZodString, string, string>; mimeType: ZodString; type: ZodLiteral<"audio">; }, "passthrough", ZodTypeAny, objectOutputType<{ _meta: ZodOptional<...>; data: ZodEffects<..., ..., ...>; mimeType: ZodString; type: ZodLiteral<...>; }, ZodTypeAny, "passthrough">, objectInputType<{ _meta: ZodOptional<...>; data: ZodEffects<..., ..., ...>; mimeType: ZodString; type: ZodLiteral<...>; }, ZodTypeAny, "passthrough">>]>; role: ZodEnum<["user", "assistant"]>; }, ZodTypeAny, "passthrough">[]; metadata?: objectOutputType<{ }, ZodTypeAny, "passthrough">; modelPreferences?: objectOutputType<{ costPriority: ZodOptional<ZodNumber>; hints: ZodOptional<ZodArray<ZodObject<{ name: ZodOptional<ZodString>; }, "passthrough", ZodTypeAny, objectOutputType<{ name: ZodOptional<...>; }, ZodTypeAny, "passthrough">, objectInputType<{ name: ZodOptional<...>; }, ZodTypeAny, "passthrough">>, "many">>; intelligencePriority: ZodOptional<ZodNumber>; speedPriority: ZodOptional<ZodNumber>; }, ZodTypeAny, "passthrough">; stopSequences?: string[]; systemPrompt?: string; temperature?: number; } & { [k: string]: unknown; }

Returns

Promise<SamplingResponse>


setMaxListeners()

setMaxListeners(n: number): this;

Defined in: node_modules/.pnpm/@types+node@20.19.19/node_modules/@types/node/events.d.ts:814

By default EventEmitters will print a warning if more than 10 listeners are added for a particular event. This is a useful default that helps finding memory leaks. The emitter.setMaxListeners() method allows the limit to be modified for this specific EventEmitter instance. The value can be set to Infinity (or 0) to indicate an unlimited number of listeners.

Returns a reference to the EventEmitter, so that calls can be chained.

Parameters

ParameterType
nnumber

Returns

this

Since

v0.3.5

Inherited from

FastMCPSessionEventEmitter.setMaxListeners