add server capabilities derivation
This commit is contained in:
parent
dcc30bea49
commit
bcb4b219ee
2 changed files with 46 additions and 10 deletions
|
|
@ -1,6 +1,7 @@
|
|||
import { Protocol } from "../shared/protocol.js";
|
||||
import {
|
||||
ClientCapabilities,
|
||||
ClientRequest,
|
||||
Implementation,
|
||||
InitializedNotificationSchema,
|
||||
InitializeRequest,
|
||||
|
|
@ -10,6 +11,11 @@ import {
|
|||
ServerNotification,
|
||||
ServerRequest,
|
||||
ServerResult,
|
||||
ServerCapabilities,
|
||||
ListResourcesRequestSchema,
|
||||
ListToolsRequestSchema,
|
||||
ListPromptsRequestSchema,
|
||||
SetLevelRequestSchema,
|
||||
} from "../types.js";
|
||||
|
||||
/**
|
||||
|
|
@ -58,7 +64,7 @@ export class Server extends Protocol<
|
|||
|
||||
return {
|
||||
protocolVersion: PROTOCOL_VERSION,
|
||||
capabilities: {},
|
||||
capabilities: this.getCapabilities(),
|
||||
serverInfo: this._serverInfo,
|
||||
};
|
||||
}
|
||||
|
|
@ -76,4 +82,21 @@ export class Server extends Protocol<
|
|||
getClientVersion(): Implementation | undefined {
|
||||
return this._clientVersion;
|
||||
}
|
||||
|
||||
private getCapability(
|
||||
reqType: ClientRequest["method"],
|
||||
): ServerCapabilities[keyof ServerCapabilities] {
|
||||
return this._requestHandlers.has(reqType as string) ? {} : undefined;
|
||||
}
|
||||
|
||||
private getCapabilities(): ServerCapabilities {
|
||||
return {
|
||||
prompts: this.getCapability(ListPromptsRequestSchema.shape.method.value),
|
||||
resources: this.getCapability(
|
||||
ListResourcesRequestSchema.shape.method.value,
|
||||
),
|
||||
tools: this.getCapability(ListToolsRequestSchema.shape.method.value),
|
||||
logging: this.getCapability(SetLevelRequestSchema.shape.method.value),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ export class Protocol<
|
|||
> {
|
||||
private _transport?: Transport;
|
||||
private _requestMessageId = 0;
|
||||
private _requestHandlers: Map<
|
||||
protected _requestHandlers: Map<
|
||||
string,
|
||||
(request: JSONRPCRequest) => Promise<SendResultT>
|
||||
> = new Map();
|
||||
|
|
|
|||
Loading…
Reference in a new issue