@@ -231,6 +231,25 @@ export type BaseContext = {
231231 * Task context, available when task storage is configured.
232232 */
233233 task ?: TaskContext ;
234+
235+ /** @deprecated Use `ctx.mcpReq.signal`. Removed in v3. */
236+ signal : AbortSignal ;
237+ /** @deprecated Use `ctx.mcpReq.id`. Removed in v3. */
238+ requestId : RequestId ;
239+ /** @deprecated Use `ctx.mcpReq._meta`. Removed in v3. */
240+ _meta ?: RequestMeta ;
241+ /** @deprecated Use `ctx.http?.authInfo`. Removed in v3. */
242+ authInfo ?: AuthInfo ;
243+ /** @deprecated Use `ctx.mcpReq.notify`. Removed in v3. */
244+ sendNotification : ( notification : Notification ) => Promise < void > ;
245+ /** @deprecated Use `ctx.mcpReq.send`. Removed in v3. */
246+ sendRequest : < T extends AnySchema > ( request : Request , resultSchema : T , options ?: RequestOptions ) => Promise < SchemaOutput < T > > ;
247+ /** @deprecated Use `ctx.task?.store`. Removed in v3. */
248+ taskStore ?: TaskContext [ 'store' ] ;
249+ /** @deprecated Use `ctx.task?.id`. Removed in v3. */
250+ taskId ?: TaskContext [ 'id' ] ;
251+ /** @deprecated Use `ctx.task?.requestedTtl`. Removed in v3. */
252+ taskRequestedTtl ?: TaskContext [ 'requestedTtl' ] ;
234253} ;
235254
236255/**
@@ -283,6 +302,54 @@ export type ServerContext = BaseContext & {
283302 */
284303export type ClientContext = BaseContext ;
285304
305+ /**
306+ * Flat-field shape of the v1 handler context. v2 nests these under
307+ * {@linkcode BaseContext.mcpReq | ctx.mcpReq} / {@linkcode BaseContext.http | ctx.http }.
308+ * Kept as deprecated forwarding properties on the context object so v1 handlers
309+ * compile and run unchanged.
310+ *
311+ * @deprecated Use the nested fields on `ctx.mcpReq` / `ctx.http` instead. Will be removed in v3.
312+ */
313+ // eslint-disable-next-line @typescript-eslint/no-unused-vars -- phantom params kept for v1 source compatibility
314+ export type RequestHandlerExtra < _Req = unknown , _Notif = unknown > = ServerContext ;
315+
316+ // --- v1-compat: flat ctx.* getters (internal) ---
317+
318+ function legacyFieldGetter ( key : string , target : string , value : ( ) => unknown ) : PropertyDescriptor {
319+ return {
320+ enumerable : false ,
321+ configurable : true ,
322+ get ( ) {
323+ deprecate ( `ctx.${ key } ` , `ctx.${ key } is deprecated. Use ${ target } instead. Removed in v3.` ) ;
324+ return value ( ) ;
325+ }
326+ } ;
327+ }
328+
329+ /**
330+ * Attaches v1's flat `extra.*` fields to the context object as deprecated
331+ * forwarding getters. v2 nests these under `ctx.mcpReq` / `ctx.http`.
332+ *
333+ * @internal
334+ */
335+ function attachLegacyContextFields (
336+ ctx : BaseContext ,
337+ sendRequest : < T extends AnySchema > ( r : Request , s : T , o ?: RequestOptions ) => Promise < SchemaOutput < T > > ,
338+ sendNotification : ( n : Notification ) => Promise < void >
339+ ) : void {
340+ Object . defineProperties ( ctx , {
341+ signal : legacyFieldGetter ( 'signal' , 'ctx.mcpReq.signal' , ( ) => ctx . mcpReq . signal ) ,
342+ requestId : legacyFieldGetter ( 'requestId' , 'ctx.mcpReq.id' , ( ) => ctx . mcpReq . id ) ,
343+ _meta : legacyFieldGetter ( '_meta' , 'ctx.mcpReq._meta' , ( ) => ctx . mcpReq . _meta ) ,
344+ authInfo : legacyFieldGetter ( 'authInfo' , 'ctx.http?.authInfo' , ( ) => ctx . http ?. authInfo ) ,
345+ sendNotification : legacyFieldGetter ( 'sendNotification' , 'ctx.mcpReq.notify' , ( ) => sendNotification ) ,
346+ sendRequest : legacyFieldGetter ( 'sendRequest' , 'ctx.mcpReq.send' , ( ) => sendRequest ) ,
347+ taskStore : legacyFieldGetter ( 'taskStore' , 'ctx.task?.store' , ( ) => ctx . task ?. store ) ,
348+ taskId : legacyFieldGetter ( 'taskId' , 'ctx.task?.id' , ( ) => ctx . task ?. id ) ,
349+ taskRequestedTtl : legacyFieldGetter ( 'taskRequestedTtl' , 'ctx.task?.requestedTtl' , ( ) => ctx . task ?. requestedTtl )
350+ } ) ;
351+ }
352+
286353/**
287354 * Information about a request's timeout state
288355 */
@@ -652,8 +719,11 @@ export abstract class Protocol<ContextT extends BaseContext = BaseContext, S ext
652719 } ,
653720 http : extra ?. authInfo ? { authInfo : extra . authInfo } : undefined ,
654721 task : taskContext
655- } ;
722+ // Deprecated flat fields (signal, requestId, sendNotification, sendRequest, task*) are
723+ // attached as getters by attachLegacyContextFields() below.
724+ } as BaseContext ;
656725 const ctx = this . buildContext ( baseCtx , extra ) ;
726+ attachLegacyContextFields ( ctx , sendRequest , sendNotification ) ;
657727
658728 // Starting with Promise.resolve() puts any synchronous errors into the monad as well.
659729 Promise . resolve ( )
0 commit comments