MCPcopy Index your code
hub / github.com/modelcontextprotocol/typescript-sdk / setRequestHandler

Function setRequestHandler

src/shared/protocol.ts:1418–1432  ·  view source on GitHub ↗

* Registers a handler to invoke when this protocol object receives a request with the given method. * * Note that this will replace any previous request handler for the same method.

(
        requestSchema: T,
        handler: (
            request: SchemaOutput<T>,
            extra: RequestHandlerExtra<SendRequestT, SendNotificationT>
        ) => SendResultT | Promise<SendResultT>
    )

Source from the content-addressed store, hash-verified

1416 * Note that this will replace any previous request handler for the same method.
1417 */
1418 setRequestHandler<T extends AnyObjectSchema>(
1419 requestSchema: T,
1420 handler: (
1421 request: SchemaOutput<T>,
1422 extra: RequestHandlerExtra<SendRequestT, SendNotificationT>
1423 ) => SendResultT | Promise<SendResultT>
1424 ): void {
1425 const method = getMethodLiteral(requestSchema);
1426 this.assertRequestHandlerCapability(method);
1427
1428 this._requestHandlers.set(method, (request, extra) => {
1429 const parsed = parseWithCompat(requestSchema, request) as SchemaOutput<T>;
1430 return Promise.resolve(handler(parsed, extra));
1431 });
1432 }
1433
1434 /**
1435 * Removes the request handler for the given method.

Callers

nothing calls this directly

Calls 3

getMethodLiteralFunction · 0.90
parseWithCompatFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…