MCP TypeScript SDK (V2) / @modelcontextprotocol/server / server/invoke
server/invoke
Interfaces
InvokeContext
Defined in: packages/server/src/server/invoke.ts:26
Per-exchange context for invoke.
Properties
authInfo?
optionalauthInfo?:AuthInfo
Defined in: packages/server/src/server/invoke.ts:35
Validated authentication information supplied by the caller. Strictly pass-through — never derived from request headers by this seam.
classification
classification:
MessageClassification
Defined in: packages/server/src/server/invoke.ts:28
The edge classification of the message (computed once, at the entry boundary).
request?
optionalrequest?:Request
Defined in: packages/server/src/server/invoke.ts:30
The original HTTP request, when serving HTTP traffic.
responseMode?
optionalresponseMode?:PerRequestResponseMode
Defined in: packages/server/src/server/invoke.ts:37
Response shaping for the exchange; defaults to auto (lazy SSE upgrade).
Functions
invoke()
invoke(
server,message,ctx):Promise<Response>
Defined in: packages/server/src/server/invoke.ts:54
Serves one classified inbound message on the given server instance and returns the HTTP response for the exchange.
The instance is connected to a fresh single-exchange transport, the message is injected through the normal transport message path, and whatever the dispatch layer produces (the handler result, a protocol-level rejection, or streamed related messages followed by the result) is captured as the returned Response. For request exchanges, teardown rides the transport's close chain once the terminal response has been delivered; notification exchanges resolve with the 202 response immediately and do NOT run the close chain — the transport stays connected until the caller closes it or drops the per-request instance, which is the caller's choice either way.
Parameters
server
message
{ id: string | number; jsonrpc: "2.0"; method: string; params?: {[key: string]: unknown; _meta?: {[key: string]: unknown; io.modelcontextprotocol/related-task?: { taskId: string; }; progressToken?: string | number; }; }; } | { jsonrpc: "2.0"; method: string; params?: {[key: string]: unknown; _meta?: {[key: string]: unknown; io.modelcontextprotocol/related-task?: { taskId: string; }; progressToken?: string | number; }; }; }
ctx
Returns
Promise<Response>