Authentication for MCP servers using @modelcontextprotocol/typescript-sdk
07:19 29 Mar 2026

I'm trying to build an MCP server that uses oauth and lets users perform CRUD operations on their data using Claude.

1. Is it correct that we should be creating a new MCP server (new McpServer) for every request? Every example does this, e.g. https://github.com/modelcontextprotocol/typescript-sdk/blob/main/examples/server/src/simpleStatelessStreamableHttp.ts. Is it safe to reuse the server instead?

2. When using oauth, how to access the auth context in a tool? E.g. get the user id. All of their examples have tools that don't depend on user data. The only solution I can think of is using AsyncLocalStorage, but I'd be surprised if there isn't an official way to do this.

javascript typescript large-language-model model-context-protocol