Add per-install authentication for the MCP server - #1
Open
ksa-real wants to merge 2 commits into
Open
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
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