DevsAgentic

AI Engineering

MCP Security for Developers: Trust Boundaries, Tools, and Tokens

By Ali Raza • • 8 min read

Updated November 29, 2026

TL;DR — Model Context Protocol standardizes how an AI host connects to tools and context; it does not make a server, tool, or returned document trustworthy. Treat each server as a privileged integration: verify its identity, expose only necessary capabilities, validate authorization at the server, require confirmation for consequential actions, and treat tool results as untrusted input.

What MCP standardizes—and what it leaves to you

The Model Context Protocol (MCP) gives AI applications a common way to discover and use capabilities exposed by servers. A host may connect to several servers; each server can offer tools, resources, or prompts. That shared interface can reduce one-off integration work, but protocol compatibility is not a security review. A correctly formatted tool can still have excessive permissions, a vulnerable implementation, or an unexpected side effect.

Start by deciding what a connection is allowed to do. Reading a documentation index is different from sending messages, changing access controls, or deleting records. Model selection should never be the authorization boundary: enforce the user’s permissions in the host and again in the server that performs the action.

Review server identity and deployment mode

For a local server, review its publisher, source, executable, arguments, environment, and update path. A process started by an AI application may inherit filesystem access and credentials from the user who launched it. For a remote server, verify the HTTPS endpoint and how it authenticates clients; do not treat a familiar display name or icon as proof of ownership.

Keep development, staging, and production connections distinct. Prefer a test account with synthetic data while evaluating a new server. If the integration supports permissions or scopes, grant only the actions and resources the feature needs. Disable unused servers and tools instead of leaving them available “just in case.”

Authenticate the actual resource

A bearer token is not safe merely because it is signed. The MCP authorization specification requires protected servers to validate tokens intended for that server, including the audience, and to reject invalid or expired credentials. Never forward a token issued for one API to another service simply because the model requested it. Use a maintained OAuth implementation, verify scopes at each operation, and avoid inventing an authentication flow around a static shared secret.

Keep credentials out of prompts, tool descriptions, logs, source control, and model output. Use short-lived, user-scoped credentials where the provider supports them. When an integration needs a secret on the server, retrieve it through a secret manager or a protected runtime environment rather than passing it through model-visible context.

Choose the transport with its trust model in mind

A local stdio server and a remote HTTP server have different boundaries. With stdio, the host launches a local process and communicates over its input and output streams; review the executable, arguments, inherited environment, and local file permissions. With a remote server, the connection crosses a network boundary, so use HTTPS, validate the server identity, and follow the protocol’s authorization requirements when the server is protected. Do not copy one transport’s authentication assumptions to the other.

Keep transport and permission decisions visible in configuration. A developer installing a local server should be able to understand which files it can read and which credentials it receives. A team onboarding a remote service should know who operates it, what data is sent, how access is revoked, and how version changes are reviewed. If those questions have no clear answer, postpone connecting production data.

Design tools with narrow, explicit effects

A tool named manage_account that accepts an arbitrary action string is difficult to review. Separate read-only operations from mutations, use precise names, and define schemas that constrain the allowed fields and values. Reject unknown parameters rather than silently ignoring them. Add size limits and timeouts, and return only the fields needed by the next step.

The following is framework-agnostic pseudocode, not an MCP SDK implementation. Its important property is that policy and validation happen before the side effect:

async function handleToolCall(user, call) {
  const tool = registry.get(call.name);
  if (!tool || !policy.canUse(user, tool.name)) {
    throw new Error('Tool is not permitted');
  }

  const input = tool.inputSchema.parse(call.arguments);
  const result = await tool.execute(input, { userId: user.id });
  return tool.outputSchema.parse(result);
}

Schema validation does not replace authorization. A well-formed request to read a different tenant’s records is still forbidden. Bind the execution to the authenticated user or service identity and check object-level permissions where the data is accessed.

Assume retrieved content can be hostile

Tool output and resources may contain instructions that were written by an attacker, copied from an issue, or embedded in a document. The model can mistake that text for directions. Treat external content as data, not authority: keep system policy separate, limit which tools can be called after retrieval, and require an independent authorization check for every action. A prompt warning helps explain the boundary; it does not enforce it.

Avoid feeding complete credentials, private records, or unrelated search results into the model. Redact sensitive fields before returning data, limit response size, and consider whether outputs should be displayed to a user or passed to another tool. Downstream systems should validate model-generated arguments again.

A tool description should state its purpose, required inputs, and side effects in plain language. This helps the model choose among capabilities, but the description itself is not a permission rule. A malicious or confusing resource could still steer a model toward a dangerous action, so the host must independently decide whether the current user and workflow are permitted to invoke that tool. Never treat “the model chose it” as authorization.

Put a human checkpoint around high-impact actions

For actions such as publishing content, issuing a refund, changing permissions, or deleting data, show the user the proposed operation and its target before execution. The confirmation should be tied to the exact action and parameters, not a vague “continue” that could be reused for a different request. Make cancellation possible and record who approved what.

Make repeated requests safe where possible. An idempotency key or a stored operation identifier can prevent a timeout and retry from creating duplicate side effects. If the downstream result is uncertain, report that uncertainty instead of claiming success.

Test the boundaries, not only a successful demo

  • Try missing, malformed, expired, and wrong-audience credentials.
  • Attempt access to a record the authenticated user does not own.
  • Send unknown fields, oversized values, and unexpected tool output.
  • Include hostile instructions in a retrieved document and verify they cannot bypass policy.
  • Simulate timeouts and duplicate calls for operations with side effects.
  • Confirm that logs exclude tokens, secrets, and unnecessary personal data.

MCP can make integrations more interoperable, but it does not remove the ordinary responsibilities of API security. Review each server as an independently privileged component and keep the user, host, and server authorization checks explicit.

For a quick first pass over a tool definition, use the AI Tool Schema Validator. It checks basic structure and descriptions, but it cannot replace the authorization and implementation review described above.

References

MCPAI AgentsSecurityTool Calling
AR

About Ali Raza

Ali is a software engineering student at Riphah International University and the founder of the digital agency Ionix Growth. He writes about modern web architecture, developer tooling, and integrating AI workflows into web applications.