fix(core): add explicit | undefined to Transport interface optional properties (#1766)
This commit is contained in:
parent
9d924b1550
commit
48aba0d3c3
2 changed files with 18 additions and 9 deletions
|
|
@ -0,0 +1,9 @@
|
|||
---
|
||||
'@modelcontextprotocol/core': patch
|
||||
---
|
||||
|
||||
Add explicit `| undefined` to optional properties on the `Transport` interface and `TransportSendOptions` (`onclose`, `onerror`, `onmessage`, `sessionId`, `setProtocolVersion`, `setSupportedProtocolVersions`, `onresumptiontoken`).
|
||||
|
||||
This fixes TS2420 errors for consumers using `exactOptionalPropertyTypes: true` without `skipLibCheck`, where the emitted `.d.ts` for implementing classes included `| undefined` but the interface did not.
|
||||
|
||||
Workaround for older SDK versions: enable `skipLibCheck: true` in your tsconfig.
|
||||
|
|
@ -52,21 +52,21 @@ export type TransportSendOptions = {
|
|||
/**
|
||||
* If present, `relatedRequestId` is used to indicate to the transport which incoming request to associate this outgoing message with.
|
||||
*/
|
||||
relatedRequestId?: RequestId;
|
||||
relatedRequestId?: RequestId | undefined;
|
||||
|
||||
/**
|
||||
* The resumption token used to continue long-running requests that were interrupted.
|
||||
*
|
||||
* This allows clients to reconnect and continue from where they left off, if supported by the transport.
|
||||
*/
|
||||
resumptionToken?: string;
|
||||
resumptionToken?: string | undefined;
|
||||
|
||||
/**
|
||||
* A callback that is invoked when the resumption token changes, if supported by the transport.
|
||||
*
|
||||
* 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.
|
||||
|
|
@ -98,14 +98,14 @@ export interface Transport {
|
|||
*
|
||||
* This should be invoked when {@linkcode Transport.close | 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.
|
||||
|
|
@ -114,21 +114,21 @@ export interface Transport {
|
|||
*
|
||||
* The {@linkcode MessageExtraInfo.requestInfo | 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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue