How to get the request URL (path/query) in MCP TypeScript SDK server handlers?
In the MCP TypeScript SDK, a server can be served on multiple endpoints at once (for example / and /mcp), and Claude requires a hash of the MCP URL in the resource _meta. To compute _meta.domain I need to know which endpoint handled the request, but RequestInfo has no url property. How can handlers access the request path or query parameters?
Originally asked on GitHub: https://github.com/modelcontextprotocol/typescript-sdk/issues/1530
4 answers
Status: fixed — a contributor confirmed on 2026-03-31 that PR #1822 resolved this by replacing the custom
RequestInfotype with the standard WebRequestobject.In a handler,
ctx.http?.reqis now aRequest, so you can read the path directly:tsconst pathname = new URL(ctx.http.req.url).pathname;and query parameters:
tsconst param = new URL(ctx.http.req.url).searchParams.get("param");That lets you distinguish which endpoint served the request (for example
/vs/mcp) when computing_meta.domainfor Claude's resource metadata.Earlier in the thread, PR #1353 was pending, and PR #1656 proposed adding a
urlproperty toRequestInfoand threading it through the HTTP request context, but the contributor's fix (#1822) used the standardRequestobject instead. The thread does not name an SDK version that includes #1822, so check that your installed SDK has it before relying onctx.http.req.url.Did this work for you?What @paulleseute tried on GitHub (Outcome unclear)
A commenter pointed to PR #1353 as a pending fix for the missing url property.
Did this work for you?What @theamodhshetty tried on GitHub (Outcome unclear)
A commenter said they would investigate and write a small fix with tests if the issue still reproduced on the current branch.
Did this work for you?What @theamodhshetty tried on GitHub (Outcome unclear)
PR #1656 added the full request URL to RequestInfo, threaded it through the existing HTTP request context, and extended the request-info test to assert query parameters are preserved.
Did this work for you?
Related questions
- MCP TypeScript SDK StreamableHttp without sticky sessions in multi-replica deployments?
- MCP stdio server: SyntaxError Unexpected token in deserializeMessage when using console.log
- MCP typescript-sdk: tool inputSchema/outputSchema reject JSON Schema type 'array'?
- Use Zod union/intersection as MCP tool paramsSchema in typescript-sdk?
- MCP Inspector: "Invalid transport type: undefined" when connecting to an SSE server