MCP Shipyard
← Rules catalog

API key or token in the MCP server URL (?key=): why it fails and how to fix

The MCP authorization spec says access tokens must not be in the URI query string. Move keys to an Authorization header or use OAuth.

majorauth.credential-in-urlClaude, ChatGPT, General

Accept credentials in an Authorization or x-api-key header, or use OAuth, instead of ?key= in the connector URL. The rule auth.credential-in-url is a major finding for Claude, ChatGPT and general use.

What you see

  • A scan reports auth.credential-in-url: "URL carries a credential query parameter".
  • The rule matches a query parameter named key, api_key, api-key, apikey, token, access_token, secret or auth.

Why it happens

A URL with the key in it is the easiest thing to paste into a client's connector box, and some clients only offer a URL field. The cost: URLs are written to access logs, proxy logs, browser history, screenshots and support tickets.

The MCP authorization spec is explicit: clients must send Authorization: Bearer <access-token> on every HTTP request, and "Access tokens MUST NOT be included in the URI query string". The rule's fix text adds that you can keep a query-key fallback for legacy clients, as long as you do not publish it in listings.

Check it yourself

Look at the URL you publish, then confirm the header route works:

curl -s -o /dev/null -w '%{http_code}\n' -X POST "https://mcp.acme.example/mcp" \
  -H 'Content-Type: application/json' \
  -H 'Accept: application/json, text/event-stream' \
  -H "Authorization: Bearer $TOKEN" \
  -d '{"jsonrpc":"2.0","id":1,"method":"tools/list"}'

A 200 means header auth works. A 401 means you have not built it yet.

Fix

  1. Read the credential from the Authorization header (and x-api-key for custom connectors that add headers).
  2. Prefer OAuth for directory listings; see auth.api-key-only.
  3. Publish the clean URL (https://mcp.acme.example/mcp) in docs and listings.
  4. If you keep a ?key= fallback, rotate any key that has appeared in a shared URL and strip the query string from your own logs.

Verify

Scan the clean URL. The finding should pass. Then run auth.https and auth.api-key-only checks.

Which clients care

Claude and ChatGPT, plus general, per the rule.

Source

MCP authorization spec: https://modelcontextprotocol.io/specification/2026-07-28/basic/authorization

Claude authentication guide: https://claude.com/docs/connectors/building/authentication

Run a free scan at https://mcpshipyard.com/scan to check every rule at once.

Check every rule at once

A free scan runs this check and the other 152 against your live URL.

Scan a server