Assert tool request handlers do not already exist
This commit is contained in:
parent
f8f5686966
commit
4bf5c5358a
2 changed files with 12 additions and 1 deletions
|
|
@ -343,7 +343,9 @@ export class Server<
|
|||
}
|
||||
|
||||
private setToolRequestHandlers() {
|
||||
// TODO: Check that these handlers do not already exist
|
||||
this.assertCanSetRequestHandler(ListToolsRequestSchema.shape.method.value);
|
||||
this.assertCanSetRequestHandler(CallToolRequestSchema.shape.method.value);
|
||||
|
||||
// TODO: Register tool capability
|
||||
|
||||
this.setRequestHandler(ListToolsRequestSchema, (): ListToolsResult => ({
|
||||
|
|
|
|||
|
|
@ -511,6 +511,15 @@ export abstract class Protocol<
|
|||
this._requestHandlers.delete(method);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that a request handler has not already been set for the given method, in preparation for a new one being automatically installed.
|
||||
*/
|
||||
protected assertCanSetRequestHandler(method: string): void {
|
||||
if (this._requestHandlers.has(method)) {
|
||||
throw new Error(`A request handler for ${method} already exists, which would be overridden`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a handler to invoke when this protocol object receives a notification with the given method.
|
||||
*
|
||||
|
|
|
|||
Loading…
Reference in a new issue