Home / Insights / AI Agents and Automation

AI Agents and Automation

Building an MCP Server for an Internal System: Scope, Security and Permissions

An MCP server turns an internal system into tools an AI agent can call. That makes it a new front door to your data. This guide covers how to scope it, authenticate it and limit what it can do, based on the June 2025 revision of the specification.

TopicsAI Agents and AutomationArchitecture and Modernization

Key takeaways

  • Scope an MCP server around the jobs an agent must do, not around every endpoint your API offers; each tool you add widens what a manipulated model can attempt.
  • For remote servers, the 2025-06-18 specification treats the MCP server as an OAuth 2.1 resource server: validate token audience, publish protected resource metadata and never pass client tokens through to upstream APIs.
  • Enforce permissions in the server and the systems behind it, never by trusting the model to decide what is allowed.
  • Separate read and write tools, validate every input, return structured output and require human confirmation for consequential actions.
  • Treat the tool list as a controlled interface: version it, review changes and test agents against it before release.

Once a team understands what the Model Context Protocol does, the next question is usually practical: “We want our agents to use our order system, our CMDB or our document store. How do we build the server without creating a security problem?”

The question matters more now than it did a few months ago. The June 2025 revision of the MCP specification made the authorisation model considerably more concrete for HTTP-based servers, and more teams are moving from local experiments to remote servers that several people and agents share. A remote MCP server is, in effect, a new API with an unusual caller: a language model that can be persuaded by the content it reads.

This article is written for CTOs, architects and engineering leads planning their first production MCP server for an internal system. It covers how to decide scope, which transport and deployment model fits, how authentication and authorisation work under the current specification, how to design tools that are safe to call, which threats are specific to MCP, and how to test and operate the result. If you need the business-level overview first, start with MCP explained for business leaders.

Scope the server around jobs, not endpoints

The most common mistake is wrapping an entire internal API as MCP tools. It is quick, and it gives the agent dozens of capabilities nobody has thought through. The OWASP Top 10 for LLM Applications 2025 calls this “excessive functionality” and lists it as a root cause of Excessive Agency, alongside excessive permissions and excessive autonomy.

Start from the workflow

Write down the two or three jobs the agent must do, then derive the minimum tools. For example, an operations team at a 40-person distributor might want an agent to answer “where is order 4471 and why is it late?” That job needs an order lookup, a shipment status lookup and perhaps a read of the exception notes. It does not need order cancellation, price changes or customer deletion, even if the API offers them.

Decide what each capability becomes

MCP gives you three primitives, and choosing the right one is part of scoping:

CapabilityExpose asReason
Look up a specific record by ID or filterTool (read-only)The model decides when it needs it; inputs can be validated
Reference content such as a policy or schemaResourceContext the host or user selects, rather than an action
A repeatable workflow a user startsPromptUser-controlled template, not model-initiated
Create or update a recordTool (write), with confirmationConsequential; needs approval and audit
Bulk export, delete, admin functionsDo not exposeBlast radius too large for model-initiated calls
Free-form query or shell accessDo not expose; build narrow tools insteadOWASP advises granular extensions over open-ended ones

Write down what is out of scope

Record explicitly which data fields the server must never return, such as salary data, health information or authentication secrets. It is easier to defend a written exclusion list than to discover later that a “get employee” tool returned everything in the row.

Choose the transport and deployment model

The specification defines two standard transports. Your choice affects who can reach the server, how it authenticates and how you operate it.

Factorstdio (local process)Streamable HTTP (remote service)
Where it runsOn the user’s machine, launched by the hostOn your infrastructure, reached over the network
CredentialsThe specification says stdio servers should retrieve credentials from the environment rather than use the OAuth flowOAuth 2.1 flow defined in the authorisation specification
Who can use itOne user, one hostMany users and agents, centrally managed
Upgrade and patchingEvery installation must be updatedDeploy once
Logging and auditScattered across devicesCentralised
Typical fitDeveloper tools, personal productivity, prototypesShared internal systems, production agents

For an internal business system used by more than a handful of people, a remote server over Streamable HTTP is usually the right production choice because it centralises identity, logging and updates. A local stdio server is useful for prototyping, but holding a long-lived system credential in an environment variable on many laptops is hard to govern.

Where to place it

  • Run the server as its own service with its own identity, not inside the system it fronts.
  • Put it behind your existing API gateway or ingress so rate limits, TLS and network controls apply.
  • Keep it stateless where you can; if you need sessions, read the session guidance below.

Authenticate and authorise under the June 2025 specification

The 2025-06-18 authorisation specification is optional for MCP implementations, but if you build an HTTP-based server that touches internal data you should treat it as mandatory. Its core model is clear:

  • The MCP server is an OAuth 2.1 resource server. It accepts and validates access tokens; it does not need to be the identity provider.
  • The MCP client is an OAuth 2.1 client acting on behalf of the user.
  • A separate authorisation server, typically your existing identity provider, issues the tokens.

What the server must do

  1. Publish protected resource metadata. Servers must implement OAuth 2.0 Protected Resource Metadata (RFC 9728) so clients can discover which authorisation server to use, and must return a WWW-Authenticate header with 401 responses pointing to it.
  2. Validate audience. Servers must check that each token was issued specifically for them. Clients must send the RFC 8707 resource parameter so tokens are bound to the intended server.
  3. Return the right errors. 401 for missing or invalid tokens, 403 for insufficient scopes or permissions.
  4. Never accept or forward other tokens. The specification says MCP servers must not accept or transit tokens issued for other resources.

No token passthrough

This is the rule most likely to be broken by a quick implementation. If your MCP server calls an upstream internal API, it must use a separate token issued for that API, not the token it received from the client. The MCP security best practices explain why: passthrough bypasses controls such as rate limiting and request validation that depend on token audience, breaks the audit trail because upstream logs show the wrong identity, and lets a stolen token turn your server into an exfiltration proxy.

User context or service account?

OWASP recommends running actions in the user’s own context with least-privilege scopes. In practice:

  • Prefer mapping each call to the end user’s identity so the internal system’s existing permissions apply. An agent should never see more than the person it is working for.
  • If the internal system only supports a service account, implement per-user authorisation inside the MCP server and restrict the service account to the minimum operations the tools need.
  • Use scopes that match tools, for example separate scopes for read and write, so a token for a read-only use case cannot invoke write tools.

Above all, enforce authorisation in code. OWASP is explicit that downstream systems should enforce authorisation rather than relying on the model to decide whether an action is allowed.

Design tools that are safe to call

The tools section of the specification sets baseline security requirements: servers must validate all tool inputs, implement access controls, rate limit invocations and sanitise outputs. Clients should prompt for confirmation on sensitive operations, show tool inputs to the user and log tool usage. Turning that into design rules:

Inputs

  • Use tight JSON Schemas: enumerations instead of free text, explicit formats for IDs and dates, maximum lengths.
  • Validate again in server code. Schemas guide the model; they are not a security boundary.
  • Reject unexpected fields rather than ignoring them.

Outputs

  • The June 2025 revision added outputSchema and structuredContent. If you declare an output schema, the server must return results that conform to it, which makes behaviour easier to test.
  • Return only the fields the job needs. Filtering at the server is your main data-minimisation control.
  • Report business failures as tool execution errors with isError: true, so the model can recover, and keep protocol errors for unknown tools or malformed requests.

Write actions

  • Keep write tools separate from read tools, with separate scopes.
  • Make them idempotent where possible, for example by requiring a client-generated request ID.
  • Design for confirmation: the specification says there should always be a human in the loop able to deny tool invocations. A useful pattern is a “propose” tool that returns a draft change and a separate “commit” step that a person approves.
  • Remember that tool annotations describing behaviour, such as whether a tool is read-only, are hints. The specification says clients must treat them as untrusted unless they come from trusted servers, so they cannot replace server-side enforcement.

Descriptions

Models choose tools from their names and descriptions. Write them like API documentation for a careful but literal reader: what the tool does, when to use it, what it will not do, and what each parameter means. Ambiguous descriptions cause wrong calls that look like model failures.

Threats specific to MCP servers and how to control them

An MCP server inherits ordinary API risks and adds some of its own. The table maps the main ones to controls.

ThreatHow it happensPrimary controls
Indirect prompt injectionA record, document or email returned by a tool contains instructions the model followsLeast-privilege tools; segregate untrusted content; human approval for writes; do not combine untrusted-content readers and high-impact writers in one agent without review
Excessive agencyTools or permissions broader than the job needsMinimal tool set; granular tools; read-only scopes by default (OWASP LLM06)
Token passthroughServer forwards client tokens to upstream APIsSeparate upstream credentials; audience validation; reject foreign tokens
Confused deputyA proxy server with a static client ID to a third-party API is abused to obtain authorisation without the user’s consentPer-client consent before forwarding to third-party authorisation, as the specification requires for proxy servers
Session hijackingAn attacker obtains or guesses a session ID and injects events or impersonates the clientVerify every request; never use sessions for authentication; secure random session IDs bound to the user
Data over-exposureTools return whole records including sensitive fieldsField-level filtering; written exclusion list; output schemas
Abuse and runaway loopsAn agent calls a tool repeatedly or at high volumeRate limits per user and per tool; step limits in the host; alerts

The session guidance is worth stating precisely because it catches teams scaling out to several server instances: the security best practices say servers that implement authorisation must verify all inbound requests, must not use sessions for authentication, and should bind session IDs to user-specific information, for example keying queued events by user ID and session ID together.

Test, log and operate the server

An MCP server needs two kinds of testing: conventional tests of the server as an API, and evaluations of how agents behave when using it.

Server tests

  • Contract tests for every tool’s input and output schema.
  • Authorisation tests: wrong audience, expired token, missing scope, user without access to the record. Each should fail in the expected way.
  • Negative input tests: oversized strings, injection payloads, unexpected fields.
  • Security scanning in the pipeline; our DevSecOps checklist covers the stages.

Agent evaluations

  • A set of realistic requests with the expected tool calls and arguments.
  • Adversarial cases: records containing injected instructions, requests for data outside the user’s permissions, ambiguous requests that should trigger a clarifying question.
  • Run the set whenever a tool description, schema or model changes.

Operations

  • Log each call with user identity, client, tool, arguments (redacted where needed), result status and latency.
  • Version the tool list. Servers can notify clients when tools change, which means a deployment can change agent behaviour immediately. Treat adding or widening a tool like an API change: review, test, release notes.
  • Alert on unusual patterns such as spikes in denied calls or a single user calling write tools repeatedly.
  • Plan for specification change. MCP has had several revisions in its first year; budget time to track them.

Build checklist for an internal MCP server

  1. The jobs the agent must do are written down, and every tool maps to one of them.
  2. An exclusion list names data fields and operations the server must never expose.
  3. Read and write tools are separate, with separate OAuth scopes.
  4. Remote servers implement protected resource metadata, audience validation and correct 401 and 403 responses.
  5. No client token is ever forwarded upstream; upstream calls use their own credentials.
  6. Calls run in the user’s context, or per-user authorisation is enforced in the server.
  7. Inputs are validated in code; outputs are filtered and, where practical, schema-defined.
  8. Write actions require human confirmation in the first release.
  9. Sessions are never used for authentication; session IDs are random and bound to the user.
  10. Rate limits apply per user and per tool.
  11. Every call is logged with identity, tool, arguments and outcome.
  12. An agent evaluation set, including adversarial cases, runs before each release.
  13. Tool list changes go through review like any API change.

PoliteTech’s AI agent development team builds this kind of integration layer: tools as typed functions with input validation, permission checks and rate limits, retrieval scoped to what the user may access, and approval queues and audit logs for oversight. For the policy side of the same question, see AI agent permissions and approvals.

Frequently asked questions

Should we build our own MCP server or use a community one?

If the vendor of the underlying system publishes and maintains an MCP server, evaluate it first. For internal systems you will usually build your own, because you need control over scope, identity and data filtering. Review any third-party server’s code and run it with minimal permissions.

Can we reuse our existing identity provider?

Usually yes. The specification separates the authorisation server from the MCP server, so your existing OAuth or OpenID Connect provider can issue tokens, provided it supports the required metadata and, ideally, resource indicators for audience binding.

Is a local stdio server safer because it never leaves the laptop?

Not necessarily. It avoids network exposure, but credentials sit in local environment variables, updates must reach every machine and logs are scattered. For shared internal systems, a central remote server is usually easier to secure and audit.

How do we stop an agent doing something harmful with a write tool?

Combine several controls: least-privilege scopes, server-side authorisation, input validation, rate limits and human confirmation before the action is committed. Do not rely on instructions in the prompt alone.

How many tools should a first server expose?

As few as the job requires. A first release with a handful of well-described read tools is easier to evaluate and secure than a broad wrapper around the whole API.

Sources and methodology

Guidance reflects PoliteTech delivery experience. The external references below informed specific points in this article.

  1. Model Context Protocol: Authorization, revision 2025-06-18 — accessed 9 November 2026. MCP server as OAuth 2.1 resource server; RFC 9728 metadata; RFC 8707 resource parameter and audience validation; prohibition on accepting or transiting other tokens; stdio credentials from the environment; 401/403 handling.
  2. Model Context Protocol: Security Best Practices — accessed 9 November 2026. Risks of token passthrough, the confused deputy problem for proxy servers, and session hijacking mitigations.
  3. Model Context Protocol: Tools, revision 2025-06-18 — accessed 9 November 2026. Server and client security requirements, human-in-the-loop guidance, output schemas and structured content, error types, and untrusted annotations.
  4. OWASP GenAI Security Project: LLM06:2025 Excessive Agency — accessed 9 November 2026. Excessive functionality, permissions and autonomy; granular tools; user-context execution; enforcing authorisation downstream rather than via the model.

Planning an MCP server for one of your internal systems?

Share the system and the jobs you want agents to do. We will help you define the tool scope, identity model and approval points before any code is written.