Skip to content

Add per-install authentication for the MCP server - #1

Open
ksa-real wants to merge 2 commits into
feat/start-debugging-with-configfrom
feat/mcp-auth-token
Open

Add per-install authentication for the MCP server#1
ksa-real wants to merge 2 commits into
feat/start-debugging-with-configfrom
feat/mcp-auth-token

Conversation

@ksa-real

Copy link
Copy Markdown
Owner

Summary

  • mint and persist a per-install MCP auth token in VS Code SecretStorage
  • require the token on DebugMCP HTTP requests using Bearer authentication or the Cursor-compatible query fallback
  • register the authenticated server with Cursor and VS Code while preserving agent configuration support
  • add constant-time token validation and live authentication coverage

Stack

This PR is stacked on feat/start-debugging-with-config, which is the head of microsoft#99. It contains only the authentication and editor-registration changes above that branch.

Testing

  • DebugMCPServer security tests cover valid, missing, and incorrect tokens
  • TypeScript compile and ESLint run through the project test workflow

ksa-real added 2 commits June 26, 2026 00:05
The loopback HTTP server was unauthenticated: any local process that could
reach 127.0.0.1:<port> could drive the full tool surface (which is code
execution by design). Add a per-install bearer token, minted on activation and
stored in SecretStorage.

- Server: when a token is configured, every request must present it via an
  `Authorization: Bearer` header or a `?token=` query param (constant-time
  compare). Unset = legacy unauthenticated mode (back-compat).
- VS Code: deliver the token via vscode.lm.registerMcpServerDefinitionProvider
  + McpHttpServerDefinition headers (the editor injects the Authorization
  header; token never written to disk).
- Cursor: deliver via vscode.cursor.mcp.registerServer. Cursor currently drops
  programmatically-supplied headers (cursor/cursor#3536), so the token is also
  carried in the URL query, which the server accepts.
- Config-file agents: the written URL carries `?token=`, uniform across JSON
  and Codex TOML; migration refreshes existing entries so they keep
  authenticating.

Adds unit + live tests: 401 without/with wrong token, accepted via Bearer
header and via ?token= query.
Editor registration previously preferred the VS Code
`lm.registerMcpServerDefinitionProvider` API. Cursor exposes that API too, but
its "Tools & MCPs" UI does not surface lm-provider registrations, so the
token-gated server never appeared in Cursor.

In Cursor, register via the documented `vscode.cursor.mcp.registerServer` API
instead, carrying the auth token in the URL query to work around Cursor's
known dropped-headers bug (the Authorization header is still sent for when the
upstream fix lands). The `lm` provider API is now used only outside Cursor, and
writing a single `debugmcp` entry to `~/.cursor/mcp.json` remains a last-resort
fallback for Cursor builds lacking the extension API.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant