Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/fix-exact-optional-types.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@modelcontextprotocol/core': patch
'@modelcontextprotocol/server': patch
---

Add explicit `| undefined` to optional properties in Transport interface and related option types to support TypeScript's `exactOptionalPropertyTypes` compiler option
14 changes: 7 additions & 7 deletions packages/core/src/shared/transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export type TransportSendOptions = {
*
* This allows clients to persist the latest token for potential reconnection.
*/
onresumptiontoken?: (token: string) => void;
onresumptiontoken?: ((token: string) => void) | undefined;
};
/**
* Describes the minimal contract for an MCP transport that a client or server can communicate over.
Expand Down Expand Up @@ -98,14 +98,14 @@ export interface Transport {
*
* This should be invoked when close() is called as well.
*/
onclose?: () => void;
onclose?: (() => void) | undefined;

/**
* 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.
*/
onerror?: (error: Error) => void;
onerror?: ((error: Error) => void) | undefined;

/**
* Callback for when a message (request or response) is received over the connection.
Expand All @@ -114,21 +114,21 @@ export interface Transport {
*
* The requestInfo can be used to get the original request information (headers, etc.)
*/
onmessage?: <T extends JSONRPCMessage>(message: T, extra?: MessageExtraInfo) => void;
onmessage?: (<T extends JSONRPCMessage>(message: T, extra?: MessageExtraInfo) => void) | undefined;

/**
* The session ID generated for this connection.
*/
sessionId?: string;
sessionId?: string | undefined;

/**
* Sets the protocol version used for the connection (called when the initialize response is received).
*/
setProtocolVersion?: (version: string) => void;
setProtocolVersion?: ((version: string) => void) | undefined;

/**
* Sets the supported protocol versions for header validation (called during connect).
* This allows the server to pass its supported versions to the transport.
*/
setSupportedProtocolVersions?: (versions: string[]) => void;
setSupportedProtocolVersions?: ((versions: string[]) => void) | undefined;
}
6 changes: 3 additions & 3 deletions packages/server/src/server/streamableHttp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export interface WebStandardStreamableHTTPServerTransportOptions {
*
* If not provided, session management is disabled (stateless mode).
*/
sessionIdGenerator?: () => string;
sessionIdGenerator?: (() => string) | undefined;

/**
* A callback for session initialization events
Expand All @@ -86,7 +86,7 @@ export interface WebStandardStreamableHTTPServerTransportOptions {
* and need to keep track of them.
* @param sessionId The generated session ID
*/
onsessioninitialized?: (sessionId: string) => void | Promise<void>;
onsessioninitialized?: ((sessionId: string) => void | Promise<void>) | undefined;

/**
* A callback for session close events
Expand All @@ -98,7 +98,7 @@ export interface WebStandardStreamableHTTPServerTransportOptions {
* session open/running.
* @param sessionId The session ID that was closed
*/
onsessionclosed?: (sessionId: string) => void | Promise<void>;
onsessionclosed?: ((sessionId: string) => void | Promise<void>) | undefined;

/**
* If true, the server will return JSON responses instead of starting an SSE stream.
Expand Down
Loading