MCP Server Security for Safe API Access

By

Tom Dallimore

Published

MCP Security. Control tool access. Protect credentials. Block unsafe requests.

Giving an AI agent a tool that can fetch any URL, read files and call your internal API with an admin key is certainly one way to make the demo impressive. It is also a fairly efficient way to turn one bad decision into several systems having a very bad afternoon.

MCP server security starts with a boring question: what can this server actually do if the agent asks for the wrong thing?

The answer includes its network access, credentials, filesystem permissions and the operations exposed as tools. A model refusing a suspicious request is helpful. A server refusing an unauthorized action is the security boundary you can build around.

The Model Context Protocol makes tools easier to connect to AI applications. It does not make an overpowered tool safe just because the arguments arrived in a valid request.

This guide covers SSRF, prompt injection, credential leaks and safe API access, with practical controls for local and remote deployments. I would start by reducing what each tool can reach, separating credentials and testing the operations that must fail. You can buy a more expensive model later. It still should not need your production admin key.

Where the Model Context Protocol security boundary sits

A typical Model Context Protocol MCP connection has a client discovering available tools on an MCP server, then invoking one tool with arguments. The server performs the operation against downstream data sources and returns a result. In the MCP API, those discovery and invocation methods are tools/list and tools/call.

The important path is simple: client → MCP server → REST API, database or other system. MCP tools expose operations along that path. Results travel back into the application and may become context for AI models.

Each step has its own trust decision. Is the caller authenticated? Can this specific user access that record? Can the server reach the destination? Does the upstream credential permit the operation? What sensitive data comes back?

One correction to older MCP security advice: the protocol does define an authorization framework for HTTP transports. The MCP authorization specification covers that flow. You still implement application permissions and protect downstream systems. A valid access token does not automatically authorize every tool action.

Local stdio is different. The client launches a process, and that process can inherit credentials and access from its environment. There may be no listening endpoint, but the process still needs limits. A local call is not automatically a harmless call.

If you want the implementation context first, my guide to building an MCP server around an existing API explains the adapter layer this security model needs to protect.

Four MCP security checks covering caller identity, tool authorization, network access and upstream API permissions.

The MCP security vulnerabilities worth checking first

Before collecting a spreadsheet of scary percentages, inventory your actual capabilities. Can the server issue arbitrary HTTP requests? Does it have write access? Can it launch commands, read sensitive files or use credentials shared by several teams?

I would group the initial review into five failure modes:

  • An attacker influences the model through untrusted input, and the resulting tool call is allowed to do too much.

  • A network tool reaches an unintended destination, including internal services or cloud metadata.

  • A legitimate caller accesses another user's records or performs an operation outside their role.

  • A server or dependency is compromised and uses the permissions it already holds.

  • Secrets or sensitive results escape through responses, configuration files or logs.

These security vulnerabilities can overlap. Prompt injection may initiate a request, excessive permissions may allow it, and missing audit logging may leave nobody able to explain what happened.

The useful review question is therefore concrete: which controls stop this action even if the model requests it? “The system prompt says not to” is going to need some friends.

Prompt injection and AI agents with too much authority

Imagine a support agent reads a web page containing instructions to export customer records. The page is task data, but the model may treat the untrusted text as an instruction and request another tool call.

A malicious MCP server can also place manipulative content in tool descriptions or other tool metadata. Review the complete definition, including schemas and annotations, rather than trusting a reassuring name. A tool called safe_customer_lookup has not passed a security review by naming itself nicely.

The goal of the attacker may be to exfiltrate data, misuse another tool or redirect the workflow. This becomes a confused-deputy problem when a component uses its authority for an action the caller was not entitled to request.

Keep trusted instructions separate from external content, inspect tool outputs and review changes to tool definitions. But assume screening can miss an attack. Enforce permissions and validate tool inputs at execution time. OWASP's prompt injection guidance makes that distinction explicit: prompt wording is not an enforcement boundary.

For a high-impact action, require approval for the actual operation, target and arguments. A model claiming “the user approved this” should not create approval. Nor should permission to summarize a customer record quietly become permission to email the entire database elsewhere.

SSRF when a useful fetch tool becomes a network proxy

Server-side request forgery happens when an attacker causes software to request an unintended destination. An MCP tool that accepts a URL to fetch data can expose the server's network position to whoever influences those arguments.

The risky design is a generic http_request tool accepting a destination, arbitrary headers and any method. Your agent now has a configurable HTTP client sitting wherever you deployed the server. If that environment can reach internal admin systems, the tool may be able to reach them too.

For an external fetch tool, restrict destinations and methods. Validate parsed URLs, resolved IPv4 and IPv6 addresses, and the destination used by the actual connection. Disable automatic redirects or revalidate every hop. Apply the same policy to retries; a safe first lookup does not justify an unchecked second one.

Use an egress proxy or network policy as another enforcement layer. A hostname allowlist alone does not solve DNS rebinding, where resolution changes between checking a host and connecting to it. OWASP's SSRF prevention guidance explains why application validation and network restrictions belong together.

MCP destination checks allow approved public APIs while blocking private networks, cloud metadata and unsafe redirects.

Internal API access needs an explicit exception

An internal integration obviously has to reach an internal system. The answer is to permit the exact service and operation needed, while keeping a general web-fetch tool away from that network.

For example, a support tool could call a fixed customer API using a validated customer ID. The model supplies the identifier; configuration selects the host, route and credential. It should not supply a replacement base URL or an Authorization header.

Keep production and staging destinations separate. Security groups, routing and application rules should agree about which services a workload can reach. “It is inside the VPC” describes a location, not an authorization decision.

For the deployment side, the self-hosted MCP server guide covers working with local and internal APIs. Explicit private-network access should remain a deliberate deployment choice.

Cloud metadata and discovery URLs need attention too

Block access to cloud metadata endpoints from tools that do not require it. On EC2, require IMDSv2 when metadata access is needed, but do not treat it as a complete SSRF fix. AWS documents that IMDSv2 uses a token obtained through a PUT request. An unrestricted client that can reproduce the necessary requests still needs network controls.

The MCP client side also matters. A remote server can supply URLs during authorization discovery. Those URLs need destination checks too; protecting your fetch_url tool while leaving metadata discovery unrestricted is an awkward way to recreate the same problem elsewhere. The official MCP security guidance covers this attack surface.

Credentials should not turn one server into an admin account collection

An MCP server may hold API keys, database credentials, SSH keys and service tokens. If they all provide broad access, a single breach can spread across every connected system. That is the privilege-concentrator problem in fairly unglamorous terms. Reduce the permissions and you reduce the blast radius.

Separate credentials by service, environment and purpose. Prefer scoped, short-lived credentials where the upstream supports them. If an API only offers a static key, use a dedicated restricted account, store the secret securely and make revocation practical. “We will wait until every vendor supports perfect identity federation” is not an implementation plan.

A secret manager can centralize storage, access controls and rotation. An environment variable can be a delivery mechanism, but it is not a secret lifecycle. Avoid baking secrets into images, putting them in version control or returning them in errors. OWASP's secrets management guidance covers the lifecycle beyond initial storage.

Keep client authentication separate from upstream authentication. The credential accepted by the MCP endpoint is not automatically the token to forward to a backend. Validate audience, expiry and other required token properties; use credentials intended for the downstream API. Unvalidated token passthrough breaks that security boundary.

Test secret rotation before an incident. Know which tools depend on each secret, how to revoke it and whether old credentials remain usable. Restarting the server does not revoke a stolen key at the service that issued it.

A client token authenticates to the MCP server, while a separate scoped credential authorizes upstream API access.

Least privilege for tools and data access

Least privilege should be visible in the tool interface. Prefer get_order_status(order_id) over a general tool that accepts SQL, a hostname and whatever headers the agent feels like sending today.

Narrow tools make review easier than generic tools because their purpose and allowed effects are clear. Expose only the tools required for a workflow, then constrain the resources behind them. A support assistant may need to read delivery status without receiving payment details or permission to cancel an order.

Filter the catalog by role where useful, but enforce authorization on every invocation. Hiding a tool from discovery is not enough if a caller can invoke it by name. Bind agent identity and any delegated user identity to trusted authentication context, rather than accepting user_id or tenant_id as proof of authority. OWASP's authorization guidance recommends checking permissions on every request and denying access by default.

For filesystem tools, constrain the permitted directory and account for traversal and symlinks. For database tools, use parameterized queries and a restricted database role. A read-only tool can still disclose sensitive data, so assess the records and fields it can return as carefully as write access.

Valid JSON is only the first check. A perfectly valid request to delete somebody else's invoice is still a bad request.

Server security for local processes and the supply chain

Installing a third-party MCP server means trusting executable code as well as its tool descriptions. A process can do things that never appear in its advertised tool catalog.

Run local servers with a dedicated identity, limited filesystem access and only the environment they need. Avoid handing every process the developer's home directory, cloud credentials and SSH agent. Containerization can help, but a container with the host filesystem mounted and unrestricted network access remains a very generous gift.

Treat npx and uvx launches as software installation, not harmless configuration. Pin reviewed versions, verify the publisher and package identity, and review updates before deployment. Use signatures, provenance and an SBOM when available, alongside dependency scanning and code review. None of those proves the package is safe on its own. OWASP's supply chain guidance treats supplier and dependency review as ongoing work.

Keep an inventory of approved servers, versions, tool definitions, credentials and owners. With many MCP servers, search client configuration and deployment records for unapproved instances. There is no universal MCP port that makes network scanning a complete inventory.

A control plane that can actually enforce policy

A gateway can provide a common entry point for authentication, tool policy, limits and an audit trail. A control plane can manage configuration and credential references. The backend server still implements its capability, and the underlying API should continue enforcing its own permissions.

The architecture only helps if those controls are on the execution path. A beautiful policy dashboard achieves very little when clients can bypass it and call an overprivileged backend directly.

For remote communication, use HTTPS and strong authentication appropriate to the deployment. For local servers, protect the launch process and inherited environment. Apply rate limits, timeouts and resource budgets so one tool call cannot run indefinitely or return an unlimited amount of data.

Start with the smallest design that enforces the necessary rules. You do not need five extra services to protect two narrow tools. Once ownership, identities and backends multiply, the MCP gateway architecture guide explains where central coordination becomes useful.

Audit logging without creating another credential leak

Your audit controls should answer who called which tool, on whose behalf, against what resource, with what decision and result. Record correlation IDs, timestamps, server and tool versions, latency and failures so security teams can follow an action across systems.

Do not log every request and response indiscriminately. Redact secrets and minimize personal data. Restrict log access and protect records against unauthorized alteration; apply retention appropriate to the data and investigation requirements. OWASP's logging guidance covers both useful event context and information that should stay out of logs.

An audit trail containing every API key you carefully removed from the rest of the application is a rather counterproductive achievement.

Monitor denied requests as well as successful ones. Repeated attempts to reach blocked destinations, unexpected data exports or a sudden change in tool usage deserve investigation. Off-hours activity may be normal for automation; compare it with the workload's expected behaviour rather than declaring every agent session after dinner suspicious.

Test the actions your MCP deployment must refuse

A successful tool call proves the happy path works. Server security needs evidence that the forbidden paths fail too. Use controlled test services and synthetic secrets in an environment you own.

  • Submit private, loopback and link-local destinations to external fetch tools. Test redirects, IPv6 and DNS changes as well as literal IP addresses.

  • Attempt cross-user and cross-tenant reads. Verify authorization still runs when the caller guesses a tool name or changes a resource ID.

  • Put adversarial instructions in a test document and tool result. Check that they cannot grant authority, expose secrets or authorize another action.

  • Exercise path traversal, symlink escapes and invalid tool inputs. Verify the server rejects them before executing an operation.

  • Revoke a credential and an approval. Confirm subsequent calls fail, including retries and replayed requests with changed arguments.

  • Inspect error responses and logs for credential leaks. Check that disabling a tool stops new calls and account for work already in flight.

The OWASP MCP security checklist is a useful review companion. Turn the failures you discover into regression tests, then rerun them when code, tool definitions, credentials or network policy changes.

Keep a response plan too. Know how to disable affected tools, revoke access, preserve redacted evidence and identify downstream systems touched by the compromised identity. A kill switch nobody has tested is mostly a reassuring label.

MCP readiness report by Fetch Hive. Check if your API is MCP ready.

Where Fetch Hive fits

Fetch Hive's MCP Gateway gives you an OpenAPI-to-MCP route with controls around the resulting endpoint. The hosted product offers access tokens, rate limits, quotas, tool policy, request logs and a playground. The open-source CLI supports local or self-hosted use, with explicit opt-in for localhost, plain HTTP and private networks.

If your starting point is an existing spec, the OpenAPI to MCP guide walks through that workflow. Review the generated tools and upstream permissions before connecting a client. Generating a schema does not establish that every endpoint in the spec belongs in an agent's toolset.

You still own the security of the underlying API and the permissions you grant. I would rather expose a few useful operations with clear limits than turn an entire admin API into available tools and hope the model develops excellent judgement.

MCP security checklist covering permissions, destinations, secrets, input validation, approvals, audit logs and tests confirming forbidden requests fail.

The takeaway

MCP makes connecting AI agents to systems easier. That is exactly why the permissions deserve attention before the connection reaches production.

Start with an inventory. Pick the most powerful tool and trace its caller identity, credential, network access and returned data. Reduce broad access, make the server-side checks explicit and test a request that should be denied.

You cannot guarantee that a model will never follow the wrong instruction. You can design the system so that one wrong instruction does not come with permission to read every file, call every internal service and export the customer database.

That is a much more useful definition of secure than “it worked in MCP Inspector.”

THE FETCH HIVE FIELD NOTES

Make your APIs useful to AI.

Get practical guides on MCP, API integrations and connecting AI tools, alongside lessons from building Fetch Hive.

Get Fetch Hive guides and occasional product updates. Unsubscribe anytime.

THE FETCH HIVE FIELD NOTES

Make your APIs useful to AI.

Get practical guides on MCP, API integrations and connecting AI tools, alongside lessons from building Fetch Hive.

Get Fetch Hive guides and occasional product updates. Unsubscribe anytime.

Share this post

THE FETCH HIVE FIELD NOTES

Make your APIs useful to AI.

Get practical guides on MCP, API integrations and connecting AI tools, alongside lessons from building Fetch Hive.

Get Fetch Hive guides and occasional product updates. Unsubscribe anytime.