@@ -158,37 +158,40 @@ server.setRequestHandler(CallToolRequestSchema, async (request, ctx) => {
158158
159159### Request Handler Context
160160
161- The ` ctx ` parameter in handlers provides a structured context with three layers:
162-
163- ** ` ctx.mcpCtx ` ** - MCP-level context:
164-
165- - ` requestId ` : JSON-RPC message ID
166- - ` method ` : The method being called
167- - ` _meta ` : Request metadata
168- - ` sessionId ` : Transport session identifier
169-
170- ** ` ctx.requestCtx ` ** - Request-level context:
171-
172- - ` signal ` : AbortSignal for cancellation
173- - ` authInfo ` : Validated auth token info (if authenticated)
174- - For server: ` uri ` , ` headers ` , ` stream ` (HTTP details)
175-
176- ** ` ctx.taskCtx ` ** - Task context (when tasks are enabled):
177-
178- - ` id ` : Current task ID (updates after ` store.createTask() ` )
179- - ` store ` : Request-scoped task store (` RequestTaskStore ` )
180- - ` requestedTtl ` : Requested TTL for the task
181-
182- ** Context methods** :
183-
184- - ` ctx.sendNotification(notification) ` : Send notification back
185- - ` ctx.sendRequest(request, schema) ` : Send request (for bidirectional flows)
186-
187- For server contexts, additional helpers:
188-
189- - ` ctx.loggingNotification(level, data, logger) ` : Send logging notification
190- - ` ctx.requestSampling(params) ` : Request sampling from client
191- - ` ctx.elicitInput(params) ` : Request user input from client
161+ The ` ctx ` parameter in handlers provides a structured context with grouped fields:
162+
163+ ** Common structure (both Client and Server)** :
164+
165+ - ` ctx.sessionId ` : Transport session identifier (top-level)
166+ - ` ctx.mcpReq ` : MCP protocol context
167+ - ` id ` : JSON-RPC message ID
168+ - ` method ` : The method being called
169+ - ` _meta ` : Request metadata
170+ - ` signal ` : AbortSignal for cancellation
171+ - ` ctx.req ` : Request context with authentication and send method
172+ - ` authInfo ` : Validated auth token info (if authenticated)
173+ - ` send(request, schema, options?) ` : Send request (for bidirectional flows)
174+ - ` ctx.task ` : Task context (when tasks are enabled)
175+ - ` id ` : Current task ID (updates after ` store.createTask() ` )
176+ - ` store ` : Request-scoped task store (` RequestTaskStore ` )
177+ - ` requestedTtl ` : Requested TTL for the task
178+ - ` ctx.notification ` : Notification context
179+ - ` send(notification) ` : Send notification back
180+
181+ ** Server-specific additions** :
182+
183+ - ` ctx.req.raw ` : Raw fetch Request object (access to URL, headers, etc.)
184+ - ` ctx.notification ` : Extended with logging methods
185+ - ` log(params) ` : Send logging notification
186+ - ` debug(message, extraLogData?) ` : Send debug log
187+ - ` info(message, extraLogData?) ` : Send info log
188+ - ` warning(message, extraLogData?) ` : Send warning log
189+ - ` error(message, extraLogData?) ` : Send error log
190+ - ` ctx.stream ` : SSE stream control
191+ - ` closeSSE?() ` : Close SSE stream for polling
192+ - ` closeStandaloneSSE?() ` : Close standalone SSE stream
193+ - ` ctx.requestSampling(params, options?) ` : Request sampling from client
194+ - ` ctx.elicitInput(params, options?) ` : Request user input from client
192195
193196### Capability Checking
194197
@@ -231,7 +234,7 @@ client.setRequestHandler(CreateMessageRequestSchema, async (request, ctx) => {
231234
232235``` typescript
233236server .setRequestHandler (SomeRequestSchema , async (request , ctx ) => {
234- // ctx provides mcpCtx, requestCtx, taskCtx , sendNotification, sendRequest
237+ // ctx provides mcpCtx, requestCtx, task , sendNotification, sendRequest
235238 return {
236239 /* result */
237240 };
0 commit comments