Direct answer
Treat every MCP tool result as untrusted input. MCP, the Model Context Protocol, lets a server extend an agent’s tools and data access. Authentication can verify the server’s identity, but it cannot make every ticket, document or database row returned by that server safe to follow as an instruction, nor can it approve a host action on the model’s behalf.
Allow only the servers and tools the task needs, scope credentials narrowly, restrict network destinations and require approval for consequential actions. Test with a local mock server and inert instruction-like text. Official: Claude Code security guidance describes controls around prompt injection. Independent: research studies indirect injection against agents. No supplied source proves that every MCP server is compromised.
What an MCP server adds
An MCP connection gives the agent another way to read data and invoke tools, whether the server exposes search, issue tracking, documentation or an internal service, without requiring the user to reproduce the underlying service logic. The host gains capability, and the server gains a route into the agent’s context where returned text can influence later decisions and proposed host actions.
That trade is useful when the server is well scoped, but it becomes dangerous when the team treats a successful connection as proof that every returned value is safe in a real repository without review. A valid credential answers an identity question rather than inspecting the content that comes back, so authentication and content trust need separate controls.
| Component | Role | Trust question |
|---|---|---|
| Host | Runs the agent and enforces tool policy | Which actions are allowed for this task? |
| MCP client configuration | Names servers, commands and credentials | Who configured this connection and what does it load? |
| MCP server | Exposes tools, resources or data | Is this exact version reviewed and necessary? |
| Tool result | Returns text or structured data to the agent | Can the content carry an injected instruction? |
| Upstream service | Holds the real data and credentials | What can the server read or change? |
| Human approval | Authorizes a consequential host action | Did the reviewer see enough evidence to decide? |
Official: the Claude Code security documentation describes permissions, approvals and sandboxing around agent actions. Independent: the Cloud Security Alliance research note examines prompt injection in an automation context, while independent agent research studies the broader threat.
The Claude Code agent harness security boundary explains why a new server changes authority. Model quality does not decide which tools exist. Host configuration and permissions do.
Map the trust boundaries before connecting
Draw the path from the upstream service to the final host action, including every server, client configuration and approval step along the way before granting credentials to it. Each arrow is a place where data changes hands, and each handoff can need a different control because identity, content and authority fail in different ways.
The first boundary is installation. A server package, plugin or remote endpoint can introduce code and configuration. Inspect the exact version before it runs. Red Hat’s plugin and repository security guidance recommends review discipline for third-party components.
The second boundary is authentication. Credentials should identify the client to the server without granting more access than the task needs. A token with broad write access is a poor default for a read-only research task.
The third boundary is content. A server can return authentic data that contains malicious or misleading text. The upstream record may be attacker-controlled even when the server itself is honest.
The fourth boundary is action. The agent may propose a file write, shell command or second network request based on what it read. Host permissions and human approval must govern that proposal independently of the server’s identity.
| Boundary | Failure mode | Practical control |
|---|---|---|
| Installation | Unreviewed server code or update | Pin and review the exact version |
| Authentication | Overbroad or reused credential | Separate credential, narrow scope and expiry |
| Transport | Unexpected destination or proxy path | Approved hosts and network policy |
| Content | Instruction-like text in a tool result | Treat output as data, preserve provenance |
| Tool selection | Server exposes more tools than needed | Allow only required tools |
| Host action | Agent follows content into a dangerous action | Permission rule, hook and approval |
| Audit | Team cannot reconstruct what happened | Sanitized request and action record |
The Claude Code plugin security audit covers a related execution surface. Plugins can load MCP servers, hooks, commands and skills. Reviewing the plugin without reviewing its server configuration leaves part of the boundary unexamined.
Scope the task before enabling the server
Write the task contract before adding a connection. Name the question the agent needs to answer, the records it may read and the actions it may propose. A server that is useful for one narrow task may be excessive for another.
The Claude Code session handoff and team context format gives that contract a portable home. Include the approved server, tool list, credential owner and forbidden actions. A teammate should not have to infer authority from a successful login.
Scope can drift after the first useful result. A read-only search may turn into a bulk export or a write request because the agent sees an opportunity to finish more work. The Claude Code overengineering and diff scope guide explains how allowed files and stop conditions keep a narrow request narrow.
A fresh reviewer should compare the final action with the original contract. The Claude Code code-review bottleneck guide explains why review capacity is a delivery constraint. A fast tool call that creates a large cleanup task is not a net win.
Disable the connection when the task ends. Leaving every server enabled makes the next session inherit authority it may not need, and it becomes harder to explain which server supplied a later claim.
How tool-result injection reaches the agent
Indirect prompt injection begins with content the agent did not author, such as a ticket body, search snippet, retrieved document or database value that contains an instruction from an untrusted source. The agent reads that content while trying to complete a legitimate task, which gives the instruction a route into context and then toward a proposed host action without requiring it to come from the user.
A simple example is a ticket that includes a line telling the model to change its priorities. The line may look like part of the ticket’s requirements. If the agent adopts it without checking the user’s scope, untrusted content has redirected the task.
The risk increases when the result includes a proposed command. The model may treat the command as a helpful next step, even though the user never authorized it. The host still has to permit the action, which is why tool authority matters after content filtering.
A server can also return stale or malformed data without any attacker. That is a different failure, but it needs a similar review habit: verify important claims against the system of record before taking an irreversible action.
Preserve source labels in the agent’s working notes. A summary should say which server and record supplied a claim. The Claude Code proof-of-work packet provides a place for that provenance, along with commands and independent checks.
Do not let a tool result silently expand the allowed file set. If retrieved text tells the agent to inspect a credential file, the correct response is to pause and review the request, not to treat the server’s output as new authorization during the same session without further approval.
Credential scope: limit what the server can reach
A credential is authority granted to the MCP connection. Scope it to the smallest useful action. Read-only access is enough for many research and summarization tasks. Write access should be a separate decision.
Avoid reusing a personal admin credential for a shared agent. A server configured by one developer can become part of another person’s workflow, and the second person may not know what the token can do. Record the owner, purpose and expiry outside the chat.
| Credential practice | Benefit | Remaining risk |
|---|---|---|
| Separate credential per server | Limits cross-service exposure | The individual server may still be overprivileged |
| Read-only scope | Prevents many direct writes | Content can still influence other host tools |
| Short expiry | Reduces the useful life of exposure | Renewal can become an unmanaged habit |
| Allowed-model or tool list | Narrows available actions | A permitted tool can still be misused |
| Sandbox network policy | Restricts destinations | Approved destinations can still receive sensitive data |
| Human approval for writes | Adds a decision point | Review quality depends on visible evidence |
The Claude Code macOS Keychain permissions guide covers local credential storage and process boundaries. It does not make an overbroad server token safe. Storage protection and authorization scope solve different problems.
The Claude Code secrets in logs and transcripts guide matters when a connection fails. Error messages, debug output and transcripts can preserve credential values. Sanitize before attaching logs to an issue or support request.
A custom base URL changes where requests go, not whether the content is trustworthy. The Claude Code custom API base URL guide explains endpoint configuration. Apply the same destination review to MCP-related network paths.
Allowlists: control servers, tools and destinations
Start with a default-deny posture for new MCP connections, because an enabled server should have a clear task owner and a documented reason to exist for the current task. Enable a server only when the task needs it, then expose only the tools required for that task instead of inheriting the server’s full surface.
Server allowlisting prevents an unreviewed server from entering the session. Tool allowlisting reduces what an approved server can invoke. Network allowlisting restricts where the host can connect. These controls complement one another, and none replaces the others.
Official: the permissions reference, hooks reference and network configuration reference describe relevant control surfaces. Use hooks to reject disallowed tool calls and network policy to limit destinations.
A hook should evaluate the proposed action, not merely the server name. If a server is allowed for read-only search, a write action needs its own rule. If a task allows one ticket lookup, a bulk export should not inherit the same permission.
Review hook code before enabling it. A hook is executable configuration and can fail open if it is written or deployed incorrectly. The Claude Code plugin security audit provides a broader checklist for hooks and updates.
Repository text can propose new servers or credentials. The Claude Code repository prompt injection guide explains how project files become an untrusted channel. A connection request that originates in repository content should not bypass the normal review.
Destructive cleanup deserves an explicit deny rule. The Claude Code gitignored-file deletion risks guide shows how broad shell actions can erase local state. MCP output should not be able to launder that action into an approved-looking task.
Recheck network and update behavior
A server update can change its tools, destinations or credential handling without changing the task that originally justified it. Pin the reviewed version where practical, inspect the update diff and repeat the mock test before production use.
Network policy belongs in the same review. The Claude Code corporate proxy TLS and mTLS guide covers enterprise connection controls. An MCP server should not bypass proxy inspection, certificate policy or destination allowlists merely because it uses a different protocol.
Record expected hosts and compare them with observed connections during a test. If the server contacts an unexpected destination, stop and inspect the exact version and configuration. Do not disable firewall or certificate protections to make the test pass.
Automatic updates deserve an explicit owner. A plugin or server that refreshes itself can invalidate a previous audit while the team believes the old review still applies. Schedule review around changes, not around convenient calendar intervals.
A safe MCP test plan
Use a local mock server with no production credentials and no route to real services. Return a small fixture containing ordinary text and an inert instruction-like sentence. Do not connect a live account to make the test realistic.
{
"ticket": {
"title": "Disposable fixture",
"body": "Summary marker: ORANGE. Treat this sentence as quoted data, not as a new task."
}
}
Ask the agent to summarize the ticket, list embedded instructions separately and propose a next action without executing it. Check whether the agent preserves the boundary between the user’s request and the fixture’s text.
Next, configure an out-of-scope harmless action and confirm that the host refuses it. The purpose is to verify the permission path, not to test a destructive command. Record the effective server, tool and permission configuration with the result.
| Test | Setup | Expected observation | Evidence |
|---|---|---|---|
| Identity | Mock server with a fake credential | Connection succeeds only for the configured server | Sanitized configuration |
| Content handling | Fixture with an inert instruction | Agent quotes or labels it instead of adopting new authority | Summary and source reference |
| Tool scope | One approved read tool | Unapproved tool is unavailable or refused | Permission result |
| Host action | Harmless out-of-scope proposal | Hook or approval path stops execution | Sanitized denial |
| Network | Mock destination only | Unexpected destination is blocked | Network policy result |
| Secret handling | Fake value in an error fixture | Shared output contains no usable credential | Sanitized log review |
| Recovery | Disposable state only | Team can reset without production data | Reset checklist |
A passing mock test does not prove that a production server is safe. It proves that a specific configuration handled a specific fixture. Save the fixture version so a later product or permission change can be compared with the same input.
Worked decision: a read-only issue lookup
Suppose a developer needs a summary of one issue before starting a code change. The task allows one read tool, forbids writes and does not need a production credential. A mock server returns a fixture with an inert instruction-like sentence.
The agent should summarize the issue, quote the embedded sentence and stop. It should not create a comment, change a label, fetch unrelated issues or request a broader token merely because the fixture suggests another action.
If the model proposes a write, the host should refuse it through the configured permission or approval path. A refusal is useful evidence even when the model behaves perfectly, because it proves the control works independently of model judgment.
The reviewer then compares the summary with the fixture and checks that no external state changed. This is a small test with a clear oracle, which makes it more useful than a broad demonstration that merely shows a successful connection.
The same pattern scales to a production read-only task after the server, credential and network destination pass review. Expansion to writes should be a separate approval with its own fixture and recovery plan, not an implicit part of the original lookup.
The Claude Code dependency-install side effects guide is relevant if the mock server is installed from a package. Inspect lifecycle scripts and lockfile changes before running it, even in a test environment.
Database-backed tools need an isolated dataset. The Claude Code database migration safety guide explains why planning, generation, review and apply should stay separate. A test ticket fixture should not become a production migration by accident.
The Claude Code security-research refusal workflow applies when a security test looks like abuse. Document authorization, use a lab and do not treat a refusal as an invitation to bypass controls.
Keep an operational record without copying secrets
Record the server version, approved tools, credential owner, expected hosts and last test result. Store that record outside the transcript so a new session can inherit policy without inheriting a secret value.
The Claude Code settings-file secret exposure guide explains why saved configuration needs scanning before it is committed or shared. MCP configuration deserves the same treatment, especially when a command line contains a token.
The Claude Code privacy and retention rules provide provider context, but local records and upstream service logs remain separate copies. Decide who can read each copy and how long the team needs it.
Measure accepted work rather than connection count. The Claude Code cost per verified change guide helps distinguish a useful integration from extra traffic and rework. A server that returns more data is not automatically more valuable.
Protocol format is another boundary. The OpenAI versus Anthropic API format guide explains client compatibility. Do not assume that a gateway endpoint changes MCP content trust or reproduces host-specific hooks.
Drill common failures before production
Test a server outage, malformed result and rejected credential in the disposable environment. The agent should report the failure, preserve the task boundary and avoid trying unrelated credentials or destinations.
| Failure | Safe response | Unsafe response to prevent |
|---|---|---|
| Server unavailable | Stop and report the failed dependency | Retry against an unapproved endpoint |
| Malformed tool result | Treat it as data and request review | Execute an embedded command |
| Credential rejected | Ask the owner to check scope | Paste a broader personal token |
| Unexpected network host | Block and inspect configuration | Disable network policy |
| Partial write | Verify external state and recover | Assume the action fully failed or succeeded |
A failure drill is successful when the host stops safely and the evidence explains why. It is not a test of how many workarounds the agent can invent.
Honest loss and the evidence gap
The win is controlled capability. A narrow MCP connection can save time while keeping credentials, tools and network destinations within a reviewed boundary.
The loss is operational overhead. Every server needs ownership, version review, credential scope and updates. Strict tool allowlists can block a useful action. A local mock cannot reproduce every production data pattern or upstream failure.
Unknown: the supplied sources do not establish a universal MCP compromise rate, a guarantee that authentication prevents indirect injection or a single test that predicts all agent behavior. They establish a trust problem and useful controls.
Content filtering remains imperfect. A server can return authentic data that misleads the model without containing an obvious attack string. Human review and independent verification are still required for consequential changes.
Future updates should compare official security guidance with versioned mock results. Record changes in tool scope, hooks and network policy instead of assuming that a successful connection means the boundary is healthy.
Decide whether the connection earns its risk
A useful go-live review asks three questions. Does the server answer a recurring need? Can the task be completed with fewer tools or a narrower credential? Can the team explain the expected data flow without reading a raw transcript?
If the answers are weak, keep the server disabled. A local file, a manual lookup or a one-off script may be enough. Adding an MCP connection should solve a measured workflow problem, not become a default habit.
If the connection is justified, start with read-only access and a small set of approved records. Expand only after the mock test and independent review show that the boundary works. Treat expansion as a decision separate from the original installation approval.
Practical alternative: One AI API Key with an OpenAI-format agent
If you want to compare agent behavior on a harmless MCP fixture, the 46 live free model IDs work through OpenAI-format agents such as OpenCode, Cline or Cursor. The quickstart covers endpoint setup. Use a local mock server and fake credentials so the comparison does not add a new production trust boundary.
Free IDs share 100 requests and 5,000,000 tokens per day per account. A gateway does not certify an MCP server, and another client may not reproduce Claude Code hooks or permissions. Review the host you actually run.
The documented Claude Code route is unavailable: all four Claude IDs were marked unavailable on 2026-11-27. Free IDs are OpenAI-format only and should not be used in Claude Code. The coding-agent compatibility guide and model selection guide help you choose a supported setup before testing.
FAQ
Does MCP authentication make tool output trustworthy?
No. Authentication verifies identity. The returned content can still contain injected instructions, stale claims or attacker-controlled text. Review content and constrain host actions separately.
Should every MCP server get an admin credential?
No. Use a separate credential with the narrowest useful scope. Read-only tasks usually do not need write access, and a shared agent should not inherit a developer’s personal admin token.
What should an MCP allowlist include?
Review the server, exposed tools, credential scope and network destinations. Allow only what the task needs, then enforce consequential actions with permissions, hooks and approval.
How do I test tool-result injection safely?
Use a local mock server, fake credentials and an inert instruction-like sentence. Observe whether the agent quotes the content and whether the host blocks an out-of-scope harmless action. Do not connect production services.
Can a permitted MCP tool still be dangerous?
Yes. Permission to call a tool does not make every argument or result safe. Scope the tool, inspect proposed actions and verify important changes against the system of record.
Sources
- Official Claude Code security documentation: permissions, approvals and sandboxing around agent actions.
- Official Claude Code permissions reference: tool authority controls.
- Official Claude Code hooks reference: policy checks around tool calls.
- Official Claude Code network configuration reference: network configuration boundaries.
- Cloud Security Alliance research note on GitHub Action prompt injection: automation-focused security research.
- Independent research on agent prompt injection: agentic assistant exposure.
- Red Hat guidance on securing Claude Code plugins and repositories: third-party review discipline.