Authentication

MCP Authentication

Learn how to secure your MCP servers with authentication for remote deployments.
typescript
// For stdio servers: use environment variables
// Claude Desktop passes env vars to your server
{
  "mcpServers": {
    "my-server": {
      "command": "npx",
      "args": ["tsx", "src/index.ts"],
      "env": {
        "API_KEY": "your-api-key",
        "DATABASE_URL": "postgres://..."
      }
    }
  }
}

Tip:For remote HTTP servers, implement OAuth 2.0 or API key authentication in your transport layer.

PreviewTypeScriptRead Only
Copy this code and run it locally with npx tsx server.ts

💬 Got questions? Ask me anything!