Dev.to Security 🔐 Cybersecurity 👁 0 📖 4 min read

Cursor MCP Auth and Token Setup: A Practical Guide

Quick answer: Configure MCP auth in Cursor by transport. A local stdio server runs as a child process and reads a secret from an env variable in its config entry, with no HTTP header to set. A remote HTTP or SSE server i

Quick answer: Configure MCP auth in Cursor by transport. A local stdio server runs as a child process and reads a secret from an env variable in its config entry, with no HTTP header to set. A remote HTTP or SSE server is reached over the network and takes a bearer token in an Authorization header, or completes an OAuth flow with PKCE the editor starts for you. Either way, put the credential in env or headers, never in args or a committed repo.

Two transports, two auth models

The first decision is how the server is reached, not which token to paste. A stdio server is launched locally by the editor and talks over standard input and output, so the editor is its parent process and passes a secret through the environment, with no network hop or bearer header. A remote server runs at a URL, the editor connects over HTTPS, and every call carries auth, either a static header or an OAuth token the client renews.

Transport How it runs Where the secret goes Renewal
Local stdio Child process, stdin and stdout env field in the entry None, static secret
Remote HTTP or SSE HTTPS to a URL Authorization header Manual token or OAuth
Remote with OAuth HTTPS to a URL Client-managed access token Refresh on 401, often PKCE

Prefer OAuth for a remote server you do not control: short-lived access tokens cap the damage from a leak, and the editor holds the refresh token instead of a permanent password.

Where the token goes in the config

The editor reads entries from its MCP config file, global for your machine or project-level with the code. Each named entry uses either command fields or a url. A stdio entry uses command, args, and env; a remote entry uses url and headers. Mixing them is the most common error: a command on a remote entry or a header on a stdio entry leaves the server unreachable.

{
  "mcpServers": {
    "local-data": { "command": "npx", "args": ["-y", "data-mcp"], "env": { "DATA_API_KEY": "your-secret" } },
    "remote-search": { "url": "https://example.com/mcp", "headers": { "Authorization": "Bearer your-token" } }
  }
}

The local server reads DATA_API_KEY from its environment; the remote one reads the header. Never put a secret in args, which show in a process listing and bug reports. In a shared config, inject values from your shell or an untracked file instead.

Step-by-step setup

  1. Confirm the transport from the server docs, then use command fields for stdio or a url for remote.
  2. Put the credential in env for stdio or an Authorization header for remote. If OAuth is offered, run the sign-in flow and let the editor manage the token.
  3. Save and reload the MCP connection so the editor spawns or reconnects the server.
  4. List the tools; an empty list after reload usually means auth failed before discovery.
  5. Call one read-only tool. A returned result proves the full path, including the token, works.

Failures that look like auth bugs

Symptom Likely cause Fix
403 on every call Token scope too narrow Reissue with the scope the tools need
401 after working for a while Access token expired Renew or re-run OAuth
Works in a terminal, not the editor Env not inherited by GUI apps Set it inside the config env field
Server never appears command on a remote URL, or url on stdio Match fields to the transport
Token leaks after a commit Secret in a tracked config Move it to env, rotate the value

A 403 differs from a 401: 401 means unauthenticated, often an expired or missing token, while 403 means the credential was accepted but lacks permission for that tool, so re-pasting the same token will not help. A GUI app launched from the dock may not inherit shell variables from a terminal profile, which is why the config's own env field beats exporting elsewhere.

For a hosted endpoint the same field rules apply. A Powerduck Cloud hosted MCP endpoint issues a separate MCP access key for agents, which you place in a header or env like any other token instead of reusing an account password, and it stays off until you expose it. For how the editor compares with a dedicated review and testing workflow, see the comparison hub.

Frequently asked questions

Why does my stdio server reject the Authorization header? Because stdio has no HTTP layer. Pass the secret through the env field and read it from the process environment inside the server.

Is OAuth always required for remote servers? No. Some accept a static bearer token in headers, but OAuth with short-lived access tokens is the safer choice when the server offers it.

How do I check that auth worked? Reload, confirm the tool list is populated, then call one read-only tool. A visible result is stronger than a green connection indicator.

The bottom line

Cursor MCP auth follows the transport: stdio takes an env secret on a child process, remote takes a header or an OAuth token on every HTTPS call. Keep credentials out of args and tracked files, verify with a real read-only call, and read a 403 as a scope problem. Match the field to the transport first, and most setup failures never reach the auth stage.

📰 Read the original article on Dev.to Security

Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.