Model Context Protocol security depends on treating every MCP server as a separate trust boundary, not as a harmless adapter between an AI assistant and your systems. Use OAuth scopes to limit what the server can do, bind each token to its intended server, and enforce record-level rules before a tool reaches a downstream system. This guide takes you through the design and implementation decisions for a custom remote MCP server, with a separate path for local servers.
If you are building a server rather than reviewing one, start with our MCP server development service. The same controls matter when you move an agent from a prototype into production, which is why security belongs in the design of AI agents and automation, not as a final deployment checklist.
What does Model Context Protocol security need to protect?
MCP connects an AI host to tools, resources and prompt templates exposed by a server. The server may then connect to systems such as a CRM, finance platform, document store or internal API. Those are distinct components, and each has its own identity and permissions.
In a remote deployment, think in terms of three actors:
- MCP host or client: The application that calls the server on a user or agent's behalf.
- MCP server: The protected service that offers MCP tools and resources. For OAuth purposes, it acts as a resource server.
- Authorisation server: The identity provider that authenticates users or workloads and issues access tokens.
A downstream system is a fourth trust boundary. It might be called directly by the MCP server after a tool request is authorised. Do not treat the token used to call the MCP server as a general-purpose credential for that downstream system.
That separation is the basis of the MCP authorisation specification. The specification describes OAuth-based authorisation for HTTP transports. Local stdio servers have a different security model because they run as a local process started by the host. The MCP security best practices provide the wider threat-model context.
An important distinction: OAuth scopes are useful for limiting broad capabilities, but they do not prove that a particular record, customer or transaction is safe to access. A scope such as mcp:finance:invoices:read might let a caller read invoices generally. Separate policy checks must decide which entity's invoices the caller can read.
What do you need before you implement OAuth?
Before writing an authorisation handler, document the system it will protect. A short design record is more useful than adding an OAuth library to an unclear architecture.
Map the trust boundaries
Draw the request path from the user to the data. Include the AI host, MCP client, server, identity provider, policy engine and every downstream API. For each connection, note who presents a credential, who validates it and what that credential is allowed to access.
Ask these questions:
- Is the server remote over HTTP, or is it a local
stdioprocess? - Is the host acting for a signed-in person, a service account, or both?
- Which systems of record can each tool call?
- Can the server read data, change it, or perform a high-impact action such as paying an invoice?
- Does the downstream service require the user's identity, the server's identity, or a delegated identity?
- Where will access decisions and tool outcomes be logged?
If you cannot answer these questions for a tool, do not expose it to a production agent yet.
Inventory tools, data and consequences
List every tool and resource the server exposes. Classify them by action and impact. A tool that lists a user's own open tickets is not equivalent to a tool that closes tickets for an entire organisation. A tool that drafts a payment is not equivalent to one that submits it.
For each capability, record:
| Capability | Example | Starting permission | Additional control |
|---|---|---|---|
| Read a permitted record | Fetch an invoice | Narrow read scope | Check tenant, entity and user access |
| Search records | Find invoices by supplier | Read scope | Limit fields, results and search range |
| Prepare a change | Draft an invoice update | Separate draft scope | Validate proposed values |
| Commit a change | Pay an invoice | Dedicated write scope | Human approval or step-up authorisation |
| Administer access | Change user roles | Separate administrative capability | Strong identity check and audit trail |
This inventory gives you a basis for scope design, test cases and approval rules. It also supports wider architecture work, including the enterprise platform design and engineering that surrounds an agent deployment.
Confirm the identity provider and client model
Find out whether your identity provider supports the grant types and metadata discovery your design needs. Decide whether MCP clients will be pre-registered, use an approved client metadata approach, or operate under an enterprise-managed authorisation arrangement. Do not assume every enterprise authorisation server supports Dynamic Client Registration.
The research dossier reports that only 4 percent of enterprise authorisation servers support Dynamic Client Registration, citing research by AuthZed and Obsidian Security published in 2026. Treat this as a warning against building a production design around a capability your identity provider may not offer, rather than as a universal measure of every provider. Confirm support with your own provider and its current documentation.
Define the resource identifier
Choose the canonical URI that identifies the MCP server as a protected resource. Use it consistently in the server configuration, protected resource metadata and token audience validation. Document how you will handle environments such as development, staging and production. A token intended for staging should not be accepted by production just because both servers share a codebase.
How should you design scopes for an MCP server?
Scopes should describe a bounded capability that a client needs, not the entire range of actions a server could technically perform. Keep them understandable to security reviewers and separate read operations from changes that create or approve business outcomes.
A practical naming convention can be:
mcp:<server>:<resource>:<action>
For example:
mcp:finance:invoices:read
mcp:finance:invoices:draft
mcp:finance:invoices:pay
mcp:operations:work-orders:read
mcp:operations:work-orders:close
This is a design pattern, not a scope format mandated by OAuth or MCP. Your identity provider may have naming constraints, and your organisation may already have a permission vocabulary. Keep the underlying principle: use distinct, reviewable permissions for materially different actions.
Step 1: Write down the action each tool performs
Describe each tool in terms of its effect on data or a system. Avoid relying on the tool name alone. A tool called update_invoice could change a note, alter a supplier bank account or submit a payment. Those are different capabilities and should not automatically share one authorisation decision.
For every tool, specify:
- The resources it can access.
- Whether it reads, drafts, changes or commits data.
- The user or workload whose authority it uses.
- The maximum scope of a single request, such as one record or one tenant.
- The consequences if an attacker or a mistaken agent invokes it.
If the tool performs multiple actions with different risk levels, split it. A separate draft and submit tool is often easier to secure and audit than a single tool with a hidden mode switch.
Step 2: Separate read, write and privileged permissions
Start with read-only scopes for tasks that only need information. Give write actions their own scopes, and reserve high-impact operations for a narrower permission with stronger checks. Do not issue a broad scope because it makes a demo easier.
A practical mapping might look like this:
| Scope | Intended use | Should not permit |
|---|---|---|
mcp:finance:invoices:read |
Read authorised invoice data | Creating, editing or paying invoices |
mcp:finance:invoices:draft |
Prepare a proposed invoice change | Submitting or approving that change |
mcp:finance:invoices:pay |
Submit an eligible payment | Changing supplier access or payment limits |
mcp:infra:clusters:read |
Inspect approved cluster status | Restarting or reconfiguring a cluster |
mcp:infra:clusters:restart |
Request a controlled restart | Changing cluster policy or credentials |
The examples illustrate a design approach. They are not standard scopes. Name scopes to match the actions and data in your environment.
Step 3: Request the minimum permissions at sign-in
The client should request only the scopes needed for the task or session. Do not request every possible permission at connection time just in case a future prompt asks for it. A token with broad permissions increases the damage possible from a compromised host, malicious tool description or prompt injection.
Where an operation needs extra authority, use a defined step-up process. The server can reject the operation when the token lacks the required permission and return an appropriate authorisation challenge. The client or user can then request the specific additional access if the identity provider and client support that flow. Do not silently convert a missing permission into an administrator token.
Step 4: Connect each tool to an explicit permission check
Do not infer authorisation from a tool being visible to the model. The server must check the validated token and the tool's required scope at execution time. Check again for every call, including calls inside a multi-step agent run.
A tool registry can declare its required scope and policy attributes alongside its input schema. The execution path should then:
- Validate the token and its audience.
- Confirm the required scope is present.
- Validate the request arguments and resolve the target resource.
- Apply record-level and business policy checks.
- Call the downstream system with the correct credential.
- Record the decision and outcome without logging secrets.
Keep this path centralised so a new tool cannot accidentally skip authorisation. If security logic is duplicated in each handler, inconsistent checks are likely.
How do OAuth tokens stop cross-server leakage?
A bearer token is a credential. Anyone who possesses it may be able to use it until it expires or is revoked, subject to the server's checks. Scope limitations help, but they are not enough if the token is accepted by the wrong server or replayed to a different API.
Step 5: Bind the token to the intended MCP resource
Use a resource indicator so the authorisation server knows which protected resource the client is requesting a token for. The resource identifier should name the specific MCP server. The server must then validate that the token's audience matches its own canonical resource URI.
This is the purpose of RFC 8707, Resource Indicators for OAuth 2.0. In practical terms, a token issued for one MCP server must not be treated as a general token for every server your organisation operates. Reject a token with a missing or mismatched audience rather than trying to infer its intended destination.
When you have several servers, give each its own resource identity and test the boundaries between them. For example, a finance MCP server should not accept a token issued for a customer support MCP server simply because the same identity provider signed it.
Step 6: Discover and validate authorisation metadata
For protected HTTP servers, publish protected resource metadata as described by RFC 9728. The metadata tells clients which authorisation server is relevant and what resource identifier and scopes are supported. The authorisation server's own metadata, described by RFC 8414, can then provide endpoints and key information needed by the client.
Use discovery to avoid hardcoding assumptions about endpoints, but do not treat discovered URLs as trusted just because they came from a server response. Validate issuer identity and the relationship between the protected resource and its listed authorisation server. The MCP authorisation and security documentation describes the intended flow and its security considerations in more detail.
Step 7: Validate the full token, not just its signature
A valid signature proves that a trusted issuer signed a token. It does not prove the token is intended for your server or valid for the requested operation. Validate the issuer, audience, expiry, not-before time where present, and the scopes or other claims your policy requires.
Use a well-maintained OAuth or JWT library rather than writing cryptographic validation yourself. Keep signing keys and issuer configuration under controlled change management. If you use token introspection instead of locally validating a signed token, protect that call and define what happens when the identity provider is unavailable. Do not fail open for sensitive operations.
Step 8: Never pass the MCP access token through to another API
Do not forward the caller's bearer token to a downstream service unless that token was explicitly issued for that service and the architecture is designed to delegate it. An MCP access token should be meant for the MCP resource. Reusing it elsewhere breaks audience boundaries and can create a confused deputy problem.
A confused deputy is a service with legitimate privileges that an attacker tricks into using those privileges for the attacker's benefit. For example, a gateway with a powerful shared credential might let a low-privilege user ask an agent to perform an action the user could not perform directly.
Instead, obtain a separate downstream credential. Depending on the architecture, that can be a service credential with narrow permissions or a delegated token produced through an approved token exchange flow such as RFC 8693. If the downstream call must act as the user, preserve that delegation explicitly and verify that the resulting token has the right audience and permissions. Do not solve identity complexity by sending the original token everywhere.
How do you enforce access below the scope level?
OAuth scopes answer a broad question: may this client invoke a category of action? They do not answer every business question. A finance scope alone cannot determine which legal entity a person represents, which invoices they may see, or whether a particular payment is within their approval limit.
Step 9: Add a policy decision for the target record
Use an explicit policy decision for user, resource and action attributes. The MCP server can act as a Policy Enforcement Point, or PEP, which means it enforces the decision. A separate Policy Decision Point, or PDP, evaluates the facts and returns allow or deny. The PDP may be an existing policy service or logic maintained in a controlled authorisation layer.
A policy input might include:
- The authenticated subject and relevant group or role claims.
- The requested action, such as
invoice.readorinvoice.pay. - The record's tenant, legal entity, owner or sensitivity classification.
- Transaction amount and approval status where relevant.
- The calling application or agent identity.
- Context such as environment, authentication strength and time.
The server should deny by default if required attributes are absent or the policy service cannot return a trustworthy decision. Keep the policy check close to the action. Checking only when a tool is listed or a session begins is not enough because permissions and target records can differ from call to call.
The Cerbos discussion of OAuth scopes and AuthZEN describes how coarse scopes can be paired with finer-grained authorisation. Treat any specific binding or extension as something to verify against its current specification and your chosen implementation before adopting it.
Step 10: Keep tool responses within the authorised boundary
Access control applies to returned data as well as actions. A server might correctly check that a user can query invoices but still return fields they should not see, such as bank details, personal data or internal approval notes.
Apply field-level filtering before data reaches the model. Limit query results, pagination and search breadth. Avoid returning whole database records when the task needs only a status and amount. Treat tool output as data that may be copied into later prompts, logs or summaries, and minimise it accordingly.
Step 11: Design approval for consequential actions
A model's decision to call a tool is not a substitute for an authorised human decision. For high-impact actions, separate preparation from approval and execution. The model can assemble a proposed transaction, while a user with the correct authority confirms it through a controlled interface.
An approval should be bound to the specific action and its material details. If the amount, destination or target record changes after approval, require a new decision. Avoid vague approvals such as allowing all future payments during an agent session.
How should you secure local stdio servers?
A local stdio server runs as a process launched by the host, often with access to the host user's environment and filesystem. The remote HTTP OAuth flow is not the default pattern for this transport. The MCP specification's authorisation model applies to HTTP-based transports; local processes instead depend heavily on the host's operating system controls and configuration.
That does not make local servers automatically safe. Apply these controls:
- Run the server with a dedicated, low-privilege operating system identity where practical.
- Provide only the environment variables and filesystem paths it needs.
- Keep secrets in a local secret manager or controlled credential store, not in a committed configuration file.
- Review commands and arguments the host uses to start the process.
- Pin and verify the package or executable source, and update dependencies through a controlled process.
- Restrict access to configuration and token files to the owner.
- Do not let the process inherit broad cloud credentials just because they are available in the user's shell.
If a local server needs to call a cloud API, authenticate that call using an appropriate local credential mechanism. Do not bolt on a remote OAuth flow simply to claim the server is protected. The security model should match the transport and deployment.
How do you implement the remote OAuth flow safely?
For a remote Streamable HTTP deployment, use the following implementation sequence. The MCP specification dated 28 July 2026 identifies Streamable HTTP as the standard remote transport and deprecates HTTP+SSE. Confirm the version your host and SDK actually support before planning a migration.
Step 12: Publish protected resource metadata
Expose the resource metadata endpoint required by the MCP authorisation model. Declare the canonical resource URI, supported authorisation server or servers, and supported scopes. Keep this metadata consistent with production routing and token validation.
Test what happens when metadata is missing, malformed or points to an unexpected issuer. A safe client must not blindly follow an attacker-controlled discovery response. A safe server must not accept tokens from an issuer it did not approve.
Step 13: Use the correct OAuth client flow
Use an authorisation code flow with PKCE for an interactive public client where appropriate. PKCE binds the authorisation request to the later token exchange, reducing the value of an intercepted authorisation code. The research notes identify S256 as the required PKCE method in the OAuth 2.1 draft baseline. Confirm the current specification and provider behaviour at implementation time because OAuth 2.1 remains a draft in the supplied standards baseline.
Do not use the implicit or password grant as shortcuts. Do not put a client secret into a public desktop or browser client and assume it can remain confidential. For service-to-service use, select a supported workload or confidential-client flow and protect its credentials accordingly.
Step 14: Protect issuer identity and registration
Validate the authorisation server's issuer identifier through discovery and during the authorisation flow. RFC 9207 provides issuer identification intended to reduce authorisation server mix-up risks. A client that supports multiple issuers must ensure the response came from the issuer it selected.
Be cautious with automatic client registration. The research dossier states that the MCP specification dated 28 July 2026 deprecated RFC 7591 Dynamic Client Registration in favour of Client ID Metadata Documents or pre-registration. Check the current MCP specification and your provider's supported options. For a controlled enterprise environment, registering approved clients through change management can be simpler to govern than allowing arbitrary client creation.
Step 15: Return clear challenges and fail closed
When a request has no valid credential, return the appropriate unauthorised response and OAuth challenge. When a valid identity lacks permission for an action, return a forbidden response and, where supported, identify the missing scope in the challenge. Do not reveal internal policy rules or sensitive record details in an error message.
Use consistent behaviour across every tool. A missing scope should not sometimes return an empty result, sometimes succeed through a different handler and sometimes produce a server error. Clients need predictable signals, and security teams need reliable logs.
How do you test for leakage and broken authorisation?
A successful OAuth login is not a security test. Build a test matrix around identity, scope, audience, resource and action. Include negative tests, because most access-control failures occur when a system accepts something it should reject.
Test at least these cases:
- No token, malformed token, expired token and token from an untrusted issuer.
- Correct signature but wrong audience, including a token issued for a different MCP server.
- Valid token with no scope, a read scope on a write tool, and one scope missing from a multi-scope requirement.
- Valid scope but a record belonging to another tenant, legal entity or user.
- A tool call with extra fields, unexpected identifiers or altered values after approval.
- Downstream API calls that would fail if the MCP server accidentally forwarded the incoming token.
- Identity provider, policy service or downstream API outage, with checks that sensitive operations fail closed.
- Logs and error messages, confirming they do not contain bearer tokens, refresh tokens, secrets or unnecessary personal data.
- Tool description or prompt changes, confirming that the same server-side permission checks still apply.
- Token refresh, revocation and session expiry behaviour.
Test the complete path, not only the MCP handler. A gateway may validate the token while a background worker later performs the action with a broad service credential. Include those workers and queues in the same threat model.
What mistakes should security architects avoid?
One broad scope for every tool
A single scope such as mcp:admin is easy to issue and hard to constrain. It increases the consequences of a compromised host or manipulated agent. Split permissions by meaningful resource and action, then keep the initial grant narrow.
Treating scopes as row-level security
A scope can permit invoice reading without deciding which invoices are in bounds. Enforce tenant, record, field and business-rule checks separately. Make the policy decision using trusted identity and resource attributes, not values supplied only by the model.
Forwarding tokens downstream
Passing the MCP bearer token to an ERP or third-party API ignores its intended audience and can create a confused deputy. Use separate credentials or an explicit token exchange designed for the downstream resource.
Trusting tool descriptions or model intent
A tool description tells the model what a tool does. It does not authorise the call. Prompt injection and tool poisoning can influence the model, so permission checks must live in the server and remain effective even when the model's reasoning is manipulated.
Storing static credentials in client configuration
A key in an mcp.json file can be copied, committed to source control, included in backups or shared with the wrong user. Long-lived shared credentials also make it difficult to attribute actions to a person or session. Prefer short-lived, audience-bound credentials where OAuth is appropriate, and store secrets outside source-controlled configuration.
Treating metadata discovery as harmless
Discovery saves hardcoded configuration, but it introduces trust decisions about issuers and endpoints. Validate those relationships, pin approved providers where required, and test failure cases. The MCP SDK advisory in the supplied research describes a vulnerability involving issuer validation during fallback discovery. Review the CSA research note on the MCP Python SDK OAuth flaw and ensure deployed SDK versions include the relevant fixes.
Ignoring local credential files
The NVD entry for CVE-2026-77268 describes an MCP Atlassian Server issue involving insufficient permissions on OAuth token files in affected versions. The operational lesson is broader than one implementation: protect local token files with owner-only permissions, check SDK and server advisories, and rotate credentials if exposure is suspected.
What does good look like in production?
A well-designed deployment has a small set of clear controls that can be tested and audited:
- Every remote MCP server has a canonical resource URI and validates token audience.
- Clients request only the scopes they need, and tools enforce those scopes on every call.
- High-impact operations use distinct permissions and explicit approval controls.
- Record-level decisions use trusted policy attributes, not scopes alone.
- Downstream services receive credentials intended for them, not a replayed MCP token.
- Discovery and issuer validation are tested, and SDKs are kept current.
- Logs capture who requested what, which policy decision applied and what happened, without storing bearer tokens.
- Local
stdioprocesses run with least privilege and do not inherit unnecessary secrets. - Deny cases, outages and cross-tenant attempts are part of automated tests.
For Australian financial services and insurance teams, map these controls into your existing technology risk, access management and incident processes. OAuth does not by itself demonstrate compliance with APRA CPS 234 or CPS 230. Your control evidence needs to show how access is approved, enforced, monitored and reviewed in the context of the service. See how this fits into our work on AI for financial services.
Where PADISO fits
We help teams design MCP servers, agent permissions and the platform controls around them. Our MCP server development work can start with a threat-model and access-control review, then turn the findings into an implementation plan and testable controls.
Wrap-up: make each boundary explicit
The safest MCP server is not the one with the longest list of OAuth features. It is the one that knows which resource it protects, validates tokens for that resource, checks the right permission for each action and limits what downstream systems can do. Start with one server and one sensitive workflow, write the negative tests first, then expand only when the controls hold.
Your next step is to map one production tool from client to downstream system and check its scope, audience and record-level policy. If you want help turning that review into a delivery plan, talk to PADISO about MCP server development.