@@ -229,11 +229,21 @@ export type BaseContext = {
229229 * Sends a request that relates to the current request being handled.
230230 *
231231 * This is used by certain transports to correctly associate related messages.
232+ *
233+ * Two call forms (mirrors {@linkcode Protocol.request | request()}):
234+ * - **Spec method** — `send({ method: 'sampling/createMessage', params }, options?)`.
235+ * The result schema is resolved from the method name and the return is typed by it.
236+ * - **With explicit result schema** — `send({ method, params }, resultSchema, options?)`
237+ * for non-spec methods or custom result shapes.
232238 */
233- send : < M extends RequestMethod > (
234- request : { method : M ; params ?: Record < string , unknown > } ,
235- options ?: TaskRequestOptions
236- ) => Promise < ResultTypeMap [ M ] > ;
239+ send : {
240+ < M extends RequestMethod > (
241+ request : { method : M ; params ?: Record < string , unknown > } ,
242+ options ?: TaskRequestOptions
243+ ) : Promise < ResultTypeMap [ M ] > ;
244+ /** @deprecated For spec methods, the result schema is resolved automatically; use `send(req)`. */
245+ < T extends AnySchema > ( request : Request , resultSchema : T , options ?: TaskRequestOptions ) : Promise < SchemaOutput < T > > ;
246+ } ;
237247
238248 /**
239249 * Sends a notification that relates to the current request being handled.
@@ -706,10 +716,13 @@ export abstract class Protocol<ContextT extends BaseContext = BaseContext, SpecT
706716 method : request . method ,
707717 _meta : request . params ?. _meta ,
708718 signal : abortController . signal ,
709- send : < M extends RequestMethod > ( r : { method : M ; params ?: Record < string , unknown > } , options ?: TaskRequestOptions ) => {
710- const resultSchema = getResultSchema ( r . method ) ;
711- return sendRequest ( r as Request , resultSchema , options ) as Promise < ResultTypeMap [ M ] > ;
712- } ,
719+ send : ( ( r : Request , optionsOrSchema ?: TaskRequestOptions | AnySchema , maybeOptions ?: TaskRequestOptions ) => {
720+ if ( optionsOrSchema && '~standard' in optionsOrSchema ) {
721+ return sendRequest ( r , optionsOrSchema , maybeOptions ) ;
722+ }
723+ const resultSchema = getResultSchema ( r . method as RequestMethod ) ;
724+ return sendRequest ( r , resultSchema , optionsOrSchema ) ;
725+ } ) as BaseContext [ 'mcpReq' ] [ 'send' ] ,
713726 notify : sendNotification
714727 } ,
715728 http : extra ?. authInfo ? { authInfo : extra . authInfo } : undefined ,
@@ -1206,8 +1219,8 @@ export abstract class Protocol<ContextT extends BaseContext = BaseContext, SpecT
12061219
12071220 /**
12081221 * Dispatches the Zod-schema form of `setRequestHandler` — extracts the method literal from the
1209- * schema and registers a handler that parses the full request through it. Called by
1210- * `Client`/`Server` overrides to avoid forwarding through their own overload set .
1222+ * schema and registers a handler that parses the full request through it. Called by the base
1223+ * { @linkcode Protocol.setRequestHandler} overload dispatcher for the schema-first signature .
12111224 */
12121225 protected _registerCompatRequestHandler (
12131226 requestSchema : ZodLikeRequestSchema ,
0 commit comments