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

MCP TypeScript SDK (V2) / @modelcontextprotocol/server / server/serverEventBus

server/serverEventBus ​

Classes ​

InMemoryServerEventBus ​

Defined in: packages/server/src/server/serverEventBus.ts:60

A ServerEventBus backed by an in-process listener set.

publish() delivers synchronously to the live listener set (a listener unsubscribing itself mid-dispatch is safe; the entry's listen-router listeners never unsubscribe peers). A throwing listener does not stop delivery to the others.

Implements ​

Constructors ​

Constructor ​

new InMemoryServerEventBus(onerror?): InMemoryServerEventBus

Defined in: packages/server/src/server/serverEventBus.ts:67

Parameters ​
onerror? ​

(error) => void

Optional callback for errors thrown by listeners during dispatch.

Returns ​

InMemoryServerEventBus

Accessors ​

listenerCount ​
Get Signature ​

get listenerCount(): number

Defined in: packages/server/src/server/serverEventBus.ts:90

The number of currently registered listeners (test/introspection only — the routers track capacity via their own open-subscription set).

Returns ​

number

Methods ​

publish() ​

publish(event): void

Defined in: packages/server/src/server/serverEventBus.ts:69

Publish a change event to every registered listener.

Parameters ​
event ​

ServerEvent

Returns ​

void

Implementation of ​

ServerEventBus.publish

subscribe() ​

subscribe(listener): () => void

Defined in: packages/server/src/server/serverEventBus.ts:79

Register a listener; returns an idempotent unsubscribe function.

Parameters ​
listener ​

(event) => void

Returns ​

() => void

Implementation of ​

ServerEventBus.subscribe

Interfaces ​

ServerEventBus ​

Defined in: packages/server/src/server/serverEventBus.ts:41

The server-side change-event seam for subscriptions/listen.

The serving entry (createMcpHandler) owns the per-stream listen router: each open subscriptions/listen stream registers a listener via subscribe(), and consumer code (typically via handler.notify.* sugar) publishes change events via publish(). In-process servers can use the default InMemoryServerEventBus; multi-process deployments implement this interface over their own pub/sub.

The SDK owns wire semantics (ack-first, filtering, subscription-id stamping, teardown); a ServerEventBus only sources the events. It MUST NOT echo back to the listener that published an event when called from inside that listener (no surprise here — the default delivers synchronously and listeners never publish).

Methods ​

publish() ​

publish(event): void

Defined in: packages/server/src/server/serverEventBus.ts:45

Publish a change event to every registered listener.

Parameters ​
event ​

ServerEvent

Returns ​

void

subscribe() ​

subscribe(listener): () => void

Defined in: packages/server/src/server/serverEventBus.ts:49

Register a listener; returns an idempotent unsubscribe function.

Parameters ​
listener ​

(event) => void

Returns ​

() => void


ServerNotifier ​

Defined in: packages/server/src/server/serverEventBus.ts:100

Typed publish-side facade over bus.publish returned by createMcpHandler: each method publishes the corresponding ServerEvent. Prefer this over calling bus.publish directly — the names match the wire methods.

Methods ​

promptsChanged() ​

promptsChanged(): void

Defined in: packages/server/src/server/serverEventBus.ts:104

Publish notifications/prompts/list_changed to every open subscription that opted in.

Returns ​

void

resourcesChanged() ​

resourcesChanged(): void

Defined in: packages/server/src/server/serverEventBus.ts:106

Publish notifications/resources/list_changed to every open subscription that opted in.

Returns ​

void

resourceUpdated() ​

resourceUpdated(uri): void

Defined in: packages/server/src/server/serverEventBus.ts:108

Publish notifications/resources/updated for uri to every open subscription that opted in to that URI.

Parameters ​
uri ​

string

Returns ​

void

toolsChanged() ​

toolsChanged(): void

Defined in: packages/server/src/server/serverEventBus.ts:102

Publish notifications/tools/list_changed to every open subscription that opted in.

Returns ​

void

Type Aliases ​

ServerEvent ​

ServerEvent = { kind: "tools_list_changed"; } | { kind: "prompts_list_changed"; } | { kind: "resources_list_changed"; } | { kind: "resource_updated"; uri: string; } & object

Defined in: packages/server/src/server/serverEventBus.ts:15

A change event a server publishes for delivery on open subscriptions/listen streams. Each variant maps onto exactly one notification method:

  • tools_list_changed → notifications/tools/list_changed
  • prompts_list_changed → notifications/prompts/list_changed
  • resources_list_changed → notifications/resources/list_changed
  • resource_updated → notifications/resources/updated (carries the URI)

The bus carries the event and any forwarded notification params — the entry's listen router owns subscription-id stamping and per-stream filtering.

Type Declaration ​

params? ​

optional params?: JSONRPCNotification["params"]

Forwarded notification params; the router stamps its own subscription ID and the event's resource URI.

Functions ​

createServerNotifier() ​

createServerNotifier(bus): ServerNotifier

Defined in: packages/server/src/server/serverEventBus.ts:112

Build a ServerNotifier over a bus.

Parameters ​

bus ​

ServerEventBus

Returns ​

ServerNotifier


honoredSubset() ​

honoredSubset(requested, capabilities?): object

Defined in: packages/server/src/server/serverEventBus.ts:166

The honored subset of a requested filter: keeps only the fields the client explicitly opted in to (drops false and absent fields), narrowed against the server's declared capabilities when supplied. The serving entry sends this back in notifications/subscriptions/acknowledged so the ack reflects what the server can actually deliver.

  • toolsListChanged is honored only when capabilities.tools.listChanged is advertised; likewise promptsListChanged / resourcesListChanged.
  • resourceSubscriptions is honored only when capabilities.resources.subscribe is advertised.

capabilities is optional on this pure helper for test convenience only — both wired routers REQUIRE capabilities at the call site (the HTTP router's serve() takes a required parameter; StdioListenRouter.serve() throws before setServerCapabilities() was called), so the fail-open undefined → honor everything branch is never reachable on a wired entry.

Parameters ​

requested ​
promptsListChanged? ​

boolean = ...

If true, receive notifications/prompts/list_changed.

resourcesListChanged? ​

boolean = ...

If true, receive notifications/resources/list_changed.

resourceSubscriptions? ​

string[] = ...

Subscribe to notifications/resources/updated for these resource URIs. Replaces the former resources/subscribe RPC on the 2026-07-28 revision.

toolsListChanged? ​

boolean = ...

If true, receive notifications/tools/list_changed.

capabilities? ​
completions? ​

{[key: string]: string | number | boolean | { [x: string]: string | number | boolean | ... | (string | number | boolean | ... | (string | number | boolean | ... | (string | number | boolean | ... | (string | number | boolean | ... | (string | ... 4 more ... | null)[] | null)[] | null)[] | null)[] | null)[] | null; } | string | number | boolean | { [x: string]: string | number | boolean | ... | (string | number | boolean | ... | (string | number | boolean | ... | (string | number | boolean | ... | (string | ... 4 more ... | null)[] | null)[] | null)[] | null)[] | null; } | (string | ... 4 more ... | null)[] | null[] | null; } = ...

Present if the server supports sending completions to the client.

experimental? ​

{[key: string]: object; } = ...

Experimental, non-standard capabilities that the server supports.

extensions? ​

{[key: string]: object; } = ...

Extensions that the server supports. Keys are extension identifiers (vendor-prefix/extension-name).

logging? ​

{[key: string]: string | number | boolean | { [x: string]: string | number | boolean | ... | (string | number | boolean | ... | (string | number | boolean | ... | (string | number | boolean | ... | (string | number | boolean | ... | (string | ... 4 more ... | null)[] | null)[] | null)[] | null)[] | null)[] | null; } | string | number | boolean | { [x: string]: string | number | boolean | ... | (string | number | boolean | ... | (string | number | boolean | ... | (string | number | boolean | ... | (string | ... 4 more ... | null)[] | null)[] | null)[] | null)[] | null; } | (string | ... 4 more ... | null)[] | null[] | null; } = ...

Present if the server supports sending log messages to the client.

Deprecated

Deprecated as of protocol version 2026-07-28 (SEP-2577); remains in the specification for at least twelve months. Migrate to stderr logging (STDIO servers) or OpenTelemetry.

prompts? ​

{ listChanged?: boolean; } = ...

Present if the server offers any prompt templates.

prompts.listChanged? ​

boolean = ...

Whether this server supports issuing notifications for changes to the prompt list.

resources? ​

{ listChanged?: boolean; subscribe?: boolean; } = ...

Present if the server offers any resources to read.

resources.listChanged? ​

boolean = ...

Whether this server supports issuing notifications for changes to the resource list.

resources.subscribe? ​

boolean = ...

Whether this server supports clients subscribing to resource updates.

tasks? ​

{[key: string]: unknown; cancel?: {[key: string]: string | number | boolean | { [x: string]: string | number | boolean | ... | (string | number | boolean | ... | (string | number | boolean | ... | (string | number | boolean | ... | (string | number | boolean | ... | (string | ... 4 more ... | null)[] | null)[] | null)[] | null)[] | null)[] | null; } | string | number | boolean | { [x: string]: string | number | boolean | ... | (string | number | boolean | ... | (string | number | boolean | ... | (string | number | boolean | ... | (string | ... 4 more ... | null)[] | null)[] | null)[] | null)[] | null; } | (string | ... 4 more ... | null)[] | null[] | null; }; list?: {[key: string]: string | number | boolean | { [x: string]: string | number | boolean | ... | (string | number | boolean | ... | (string | number | boolean | ... | (string | number | boolean | ... | (string | number | boolean | ... | (string | ... 4 more ... | null)[] | null)[] | null)[] | null)[] | null)[] | null; } | string | number | boolean | { [x: string]: string | number | boolean | ... | (string | number | boolean | ... | (string | number | boolean | ... | (string | number | boolean | ... | (string | ... 4 more ... | null)[] | null)[] | null)[] | null)[] | null; } | (string | ... 4 more ... | null)[] | null[] | null; }; requests?: {[key: string]: unknown; tools?: {[key: string]: unknown; call?: {[key: string]: ... | ... | ... | ... | ... | ... | ...; }; }; }; } = ...

Present if the server supports task creation.

Deprecated

2025-11-25 wire vocabulary with no SDK runtime; parsed for interoperability only — servers built on this SDK never advertise it.

tasks.cancel? ​

{[key: string]: string | number | boolean | { [x: string]: string | number | boolean | ... | (string | number | boolean | ... | (string | number | boolean | ... | (string | number | boolean | ... | (string | number | boolean | ... | (string | ... 4 more ... | null)[] | null)[] | null)[] | null)[] | null)[] | null; } | string | number | boolean | { [x: string]: string | number | boolean | ... | (string | number | boolean | ... | (string | number | boolean | ... | (string | number | boolean | ... | (string | ... 4 more ... | null)[] | null)[] | null)[] | null)[] | null; } | (string | ... 4 more ... | null)[] | null[] | null; } = ...

Present if the server supports cancelling tasks.

tasks.list? ​

{[key: string]: string | number | boolean | { [x: string]: string | number | boolean | ... | (string | number | boolean | ... | (string | number | boolean | ... | (string | number | boolean | ... | (string | number | boolean | ... | (string | ... 4 more ... | null)[] | null)[] | null)[] | null)[] | null)[] | null; } | string | number | boolean | { [x: string]: string | number | boolean | ... | (string | number | boolean | ... | (string | number | boolean | ... | (string | number | boolean | ... | (string | ... 4 more ... | null)[] | null)[] | null)[] | null)[] | null; } | (string | ... 4 more ... | null)[] | null[] | null; } = ...

Present if the server supports listing tasks.

tasks.requests? ​

{[key: string]: unknown; tools?: {[key: string]: unknown; call?: {[key: string]: ... | ... | ... | ... | ... | ... | ...; }; }; } = ...

Capabilities for task creation on specific request types.

tasks.requests.tools? ​

{[key: string]: unknown; call?: {[key: string]: ... | ... | ... | ... | ... | ... | ...; }; } = ...

Task support for tool requests.

tasks.requests.tools.call? ​

{[key: string]: ... | ... | ... | ... | ... | ... | ...; } = ...

tools? ​

{ listChanged?: boolean; } = ...

Present if the server offers any tools to call.

tools.listChanged? ​

boolean = ...

Whether this server supports issuing notifications for changes to the tool list.

Returns ​

promptsListChanged? ​

optional promptsListChanged?: boolean

If true, receive notifications/prompts/list_changed.

resourcesListChanged? ​

optional resourcesListChanged?: boolean

If true, receive notifications/resources/list_changed.

resourceSubscriptions? ​

optional resourceSubscriptions?: string[]

Subscribe to notifications/resources/updated for these resource URIs. Replaces the former resources/subscribe RPC on the 2026-07-28 revision.

toolsListChanged? ​

optional toolsListChanged?: boolean

If true, receive notifications/tools/list_changed.


listenFilterAccepts() ​

listenFilterAccepts(filter, event): boolean

Defined in: packages/server/src/server/serverEventBus.ts:131

Whether a subscriptions/listen filter accepts a given change event.

Pure: no I/O, no mutation. The filter governs ONLY the four subscription-gated change types — non-gated notifications never reach the bus and are not modeled here.

resource_updated matches only when resourceSubscriptions is present and contains the event's URI exactly (per the spec: "for these resource URIs").

Parameters ​

filter ​
promptsListChanged? ​

boolean = ...

If true, receive notifications/prompts/list_changed.

resourcesListChanged? ​

boolean = ...

If true, receive notifications/resources/list_changed.

resourceSubscriptions? ​

string[] = ...

Subscribe to notifications/resources/updated for these resource URIs. Replaces the former resources/subscribe RPC on the 2026-07-28 revision.

toolsListChanged? ​

boolean = ...

If true, receive notifications/tools/list_changed.

event ​

ServerEvent

Returns ​

boolean


serverEventToNotification() ​

serverEventToNotification(event): object

Defined in: packages/server/src/server/serverEventBus.ts:183

Map a ServerEvent onto its wire notification {method, params}.

Parameters ​

event ​

ServerEvent

Returns ​

object

method ​

method: string

params? ​

optional params?: object

Index Signature ​

[key: string]: unknown

params._meta? ​

optional _meta?: object

See MCP specification for notes on _meta usage.

Index Signature ​

[key: string]: unknown

optional io.modelcontextprotocol/related-task?: object

If specified, this request is related to the provided task.

taskId: string

params._meta.progressToken? ​

optional progressToken?: string | number

If 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.