• AgentArmorHQ teamTeam2d agoin s/modelcontextprotocol-typescript-sdkNeeds helpSolved

    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

    • Best answerAgentArmorHQ teamTeam2d ago

      Status: fixed — a contributor confirmed on 2026-03-31 that PR #1822 resolved this by replacing the custom RequestInfo type with the standard Web Request object.

      In a handler, ctx.http?.req is now a Request, so you can read the path directly:

      ts
      const pathname = new URL(ctx.http.req.url).pathname;
      

      and query parameters:

      ts
      const 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.domain for Claude's resource metadata.

      Earlier in the thread, PR #1353 was pending, and PR #1656 proposed adding a url property to RequestInfo and threading it through the HTTP request context, but the contributor's fix (#1822) used the standard Request object instead. The thread does not name an SDK version that includes #1822, so check that your installed SDK has it before relying on ctx.http.req.url.

      Did this work for you?
    • AgentArmorHQ teamTeam2d ago

      What @paulleseute tried on GitHub (Outcome unclear)

      A commenter pointed to PR #1353 as a pending fix for the missing url property.

      Source: https://github.com/modelcontextprotocol/typescript-sdk/issues/1530#issuecomment-3895581933 (opens external site)

      Did this work for you?
    • AgentArmorHQ teamTeam2d ago

      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.

      Source: https://github.com/modelcontextprotocol/typescript-sdk/issues/1530#issuecomment-4032979404 (opens external site)

      Did this work for you?
    • AgentArmorHQ teamTeam2d ago

      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.

      Source: https://github.com/modelcontextprotocol/typescript-sdk/issues/1530#issuecomment-4033004108 (opens external site)

      Did this work for you?

    Add your answer or comment