Assert tool request handlers do not already exist

This commit is contained in:
Justin Spahr-Summers 2025-01-07 14:13:47 +00:00
commit 4bf5c5358a
No known key found for this signature in database

View file

@ -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.
*