Insights

MCP server authentication: How to protect and test your server

Local stdio servers can use process credentials. Protected HTTP MCP servers validate OAuth tokens and check permissions before tools run.

Illustration of token-operated turnstile with one open lane.
On this page

Model Context Protocol (MCP) server authentication starts with how the client connects: a protected remote server over Hypertext Transfer Protocol (HTTP) uses an access token issued by an OAuth 2.1 authorization server. A local server that uses standard input and output (stdio) can get credentials from its environment instead of using the HTTP authorization flow. Your HTTP server checks that the token is valid and meant for it, then checks whether the caller has permission to run the tool.

In short:

  • Choose by transport. Use local credentials for stdio and MCP authorization for protected HTTP.
  • Validate the token. Reject tokens issued for a different resource.
  • Check tool permissions. Require the right access before the tool runs.

Where the client gets its credentials

Use the July 2026 MCP authorization flow for a protected HTTP endpoint, even if the endpoint is private. What matters is how the client connects, not whether the endpoint is reachable from the public internet. Authorization is optional in MCP, but that doesn't make it a good idea to leave sensitive tools open.

For a local stdio server, the March 2025 MCP tutorial gives environment-based credentials as an option. For example, you can supply a credential in the process environment when you launch the server. Protect who can launch that process and who can read its credentials.

Check which calls your server allows

Use a staging endpoint you operate and pick one harmless call, such as reading a test record. Get three otherwise valid tokens from the same trusted issuer: one for your server with the needed scope, one for a different test resource, and one for your server without the needed scope. A scope is a named permission granted to a token.

Repeat the same call with the same arguments each time. Record which check made the decision and whether the tool ran, without logging token values.

  1. Use the token with the needed scope. Expect the tool to run and return the test record. This shows that the call works when both token validation and the permission check pass.
  2. Send no token. Expect the call to fail at token validation. In the March 2025 MCP tutorial's discovery example, the 401 Unauthorized response includes a Bearer challenge in the WWW-Authenticate header. Check that the challenge's resource_metadata parameter points to your server's Protected Resource Metadata document.
  3. Use the token for the other resource. Expect the token check to reject it even though you trust its issuer. If it passes that check, inspect how your server validates the audience, meaning the token's intended recipient.
  4. Use the token without the needed scope. Expect the token check to pass and the permission check to deny the call. If the tool runs, check whether your server enforces the scope on the call itself.

Only the first call should run the tool and return the test record. None of the denied calls should run the tool or return protected data. This checks the path for that call, not every tool on your server.

The March 2025 MCP specification uses 401 Unauthorized when authorization is missing or the token is invalid, and 403 Forbidden for insufficient scope. Use that distinction to guide debugging, then check which gate denied the call before changing credentials or widening access. The older mapping doesn't specify every challenge field a July 2026 server needs to send.

How the server knows a token is meant for it

  1. Publish protected resource metadata. The July 2026 authorization specification requires OAuth 2.0 Protected Resource Metadata for this flow. The client reads that document to find the authorization server.
  2. Request a token for the MCP resource. The client must send the authorization server a resource parameter that identifies the MCP resource the token is for. That makes the intended recipient explicit at the time of the request.
  3. Validate the token before processing the request. Check both that the token is valid and that it was issued for your MCP server. If the tool calls another service, don't forward the incoming token to that service.

What a valid token still doesn't allow

A token can be valid for your server and still grant read access only. It may let the caller view a record without letting them edit it. Check the permissions needed for the requested action before the tool runs. Filtering the list of tools doesn't replace checking the call itself.

Have clients request only the scopes they need. If the token has the required scope but a tool-specific rule still denies the call, check that rule before changing access. Don't assume the tool's own denial uses the same response as a scope failure.

Where doxx.net fits. An authorized agent can use doxx.net's MCP tools to create tunnels and manage firewall rules on the private network within the access you give it. To try those network tools, create an account, download the doxx.net app and connect a device or agent.

Ask an AI assistant

Share this article

Private Everywhere

Stop giving the internet everything

Keep your browsing, messages, files, and agents private.