feat: support extending McpServer with subclass
This commit is contained in:
parent
592c91fc86
commit
3571fc353f
2 changed files with 27 additions and 19 deletions
|
|
@ -93,6 +93,11 @@ export type RequestHandlerExtra = {
|
|||
* The session ID from the transport, if available.
|
||||
*/
|
||||
sessionId?: string;
|
||||
|
||||
/**
|
||||
* The authenticated user, if available.
|
||||
*/
|
||||
user?: unknown;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -316,6 +321,7 @@ export abstract class Protocol<
|
|||
const extra: RequestHandlerExtra = {
|
||||
signal: abortController.signal,
|
||||
sessionId: this._transport?.sessionId,
|
||||
user: this._transport?.user,
|
||||
};
|
||||
|
||||
// Starting with Promise.resolve() puts any synchronous errors into the monad as well.
|
||||
|
|
@ -361,7 +367,7 @@ export abstract class Protocol<
|
|||
private _onprogress(notification: ProgressNotification): void {
|
||||
const { progressToken, ...params } = notification.params;
|
||||
const messageId = Number(progressToken);
|
||||
|
||||
|
||||
const handler = this._progressHandlers.get(messageId);
|
||||
if (!handler) {
|
||||
this._onerror(new Error(`Received a progress notification for an unknown token: ${JSON.stringify(notification)}`));
|
||||
|
|
|
|||
|
|
@ -46,4 +46,9 @@ export interface Transport {
|
|||
* The session ID generated for this connection.
|
||||
*/
|
||||
sessionId?: string;
|
||||
|
||||
/**
|
||||
* The authenticated user for this transport session.
|
||||
*/
|
||||
user?: unknown;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue