How to Self-Host an MCP Server for a Local or Internal API

By

Tom Dallimore

Published

Self-hosted MCP Server

Running an MCP server on your laptop is easy. Keeping one alive behind your firewall, reachable by the right AI assistants, protected by sane authentication, and not leaking internal credentials is where the fun begins.

That is the actual difference between a local MCP experiment and a self hosted MCP server people can depend on. The protocol is the easy part. The production deployment around it - network access, identity access control, credential management, logging, updates and boring operational ownership - is the bit that decides whether the setup is useful or becomes another box nobody wants to touch.

If your API already exists, you do not need to rebuild the application just because an AI client wants to call it. Your MCP server implementation should sit around the capability you already have. If you need custom tools or transformations, start with How to Build an MCP Server for an Existing API. If you already have a decent OpenAPI document, the OpenAPI-to-MCP route is usually much faster.

This guide focuses on the next question: when you want that MCP server to run on infrastructure you control, what do you actually need to self-host it properly?

When should you self-host an MCP server?

A self hosted MCP server makes sense when the server needs deep access to systems that should not be handed to a third-party runtime, or when your team needs complete control over where tool execution, data and credentials live. The MCP server runs inside your operational boundary, so you keep full control over the runtime and network path.

The strongest cases are pretty predictable:

  • Internal APIs and databases on a private network, VPC, VPN, or on premise environment.

  • Sensitive data where external data processing concerns, residency rules or security policies make a hosted service awkward.

  • Production tools used by different teams where you need consistent authentication, audit trails and access rules.

  • Restricted environments where backend servers cannot simply be exposed to the public internet.

  • Teams that already operate Docker, Kubernetes, VMs or internal platform infrastructure and are happy owning the operational burden.

Self-hosting is not automatically the more serious choice. If one developer wants filesystem access on one laptop, local MCP is simpler. If the capability is a public SaaS integration and you do not want to operate a server, hosted MCP is often the better trade-off. Owning more infrastructure is not a personality trait. These self hosted options are useful when control solves a real constraint, not as a default badge of seriousness.

Pattern

Where it runs

Best for

Who owns operations

Local MCP

Developer machines / local environment

Personal workflows, local resources, experiments

The individual developer

Hosted MCP

Third-party hosted server

Public APIs, SaaS tools, low-ops integrations

The provider

Self hosted MCP server

Your cloud, private network, datacenter or on premise infrastructure

Internal APIs, production systems, sensitive data

Your team

MCP server, MCP client and MCP gateway: the three pieces

The Model Context Protocol gives AI tools a standard way to discover capabilities and call them. The names are simple, but mixing them up makes architecture diagrams look much more mysterious than they need to be.

  • MCP server: the process exposing MCP tools, resources or other capabilities. It receives JSON RPC messages, validates a tool call, runs the underlying operation and returns the result.

  • MCP client: the AI client or agent connecting to the server. Cursor, Claude, ChatGPT integrations, coding agents and custom AI assistants can all act as clients depending on the setup.

  • MCP gateway: an optional control layer in front of one or more servers. It can provide centralized control for authentication, routing, policy enforcement, tool visibility and audit logging.

The MCP gateway is useful once you have several servers, environments or teams. It is not a requirement for your first server. One small server does not need an enterprise diagram with twelve arrows just to feel important.

Local MCP vs remote MCP: transport matters

Local vs hosted vs self-hosted MCP

There are two separate questions people often squash together: where the server runs, and how the client reaches it.

A local MCP server normally runs as a subprocess on the same machine as the client. That is perfect for local resources, command-line tools, personal workflows and a development environment where direct access is useful. There is no network hop because everything stays on the same machine. In that setup the client can reach the server directly without a remote URL.

A remote MCP server is reached over the network. For modern remote deployments, Streamable HTTP is the transport you care about. A hosted MCP server and a self hosted MCP server can both look identical to the client: they are remote URLs. The difference is who runs the backend servers and who controls the data.

That distinction matters because a hosted server can still be private and secure, while a self hosted server can still be badly exposed. “Self hosted” tells you who owns the infrastructure. It does not magically solve security for you.

What a production-ready self-hosted MCP stack actually needs

Self hosting is more than getting the server process to return 200. A useful production stack normally has these pieces:

  • Server implementation. The actual MCP code, tool definitions, validation and connection to the internal API or data source.

  • Streamable HTTP. The network transport for a remote URL, normally behind TLS.

  • Authentication and authorization. Verify the human user, service account or agent identity before tool execution.

  • Credential management. Upstream API keys, database passwords and other secrets should come from a secret store or protected environment references, not be pasted into client configuration.

  • Network access. Decide whether the server is reachable over a VPN, private network, public HTTPS endpoint, or through a controlled gateway.

  • Observability. Logs, traces, latency, failures and enough metadata to reconstruct what happened without logging every secret in the building.

  • Production deployment. Docker on a VM is often enough to start. A Kubernetes cluster can make sense later when availability, rollout strategy or scale actually requires it.

A reverse proxy such as Nginx, Caddy or Traefik can be the middleware manager for TLS termination and ordinary HTTP routing. That is useful infrastructure, but it is not the same thing as an MCP gateway that understands MCP tools and policy.

Design the smallest useful tool surface first

Do not start by exposing every backend function because the API happens to have 150 endpoints. Start with one capability and the specific tools the AI agents actually need.

For a first pilot, read-only tools are usually the sensible place to start. Query a customer, fetch an order, inspect an alert, search internal documentation. Once arbitrary code execution, destructive writes or shell commands enter the picture, the security bar rises quickly.

Ask four boring questions before you write code:

  • What data can this server access?

  • Which users or AI assistants should be allowed to access it?

  • Which operations are read-only, and which can mutate production systems?

  • What project context does the model actually need to choose the right tool?

Natural language queries do not remove the need for precise tool definitions. The model still needs a clear name, description and schema for each capability. “Do stuff” is not a tool contract. It is a cry for help.

Build it by hand, or compile the API you already have

There are two sensible routes.

Hand-built server implementation. Use this when the MCP layer needs custom orchestration, transformations, approvals, permissions or logic that is genuinely different from the API underneath it. The full walkthrough is in How to Build an MCP Server for an Existing API.

OpenAPI to MCP. If your REST API already has a clean OpenAPI 3.0 or 3.1 spec, compiling the existing contract is normally cleaner than copying every endpoint into MCP decorators. The practical flow is covered in How to Turn an OpenAPI Spec into an MCP Server.

Fetch Hive's open-source mcp-gateway uses the second approach. It compiles OpenAPI into MCP tools, serves over Streamable HTTP or stdio, and can inject upstream credentials from environment or file references. It is Apache 2.0, so you can run the whole thing yourself.

A practical self-hosted flow with the open-source gateway

If the internal API is already running on your machine or private network, the local development flow is deliberately explicit about the risk. Private addresses are blocked unless you opt in, and plain HTTP is only allowed when you explicitly say you want it.


BASH
mcp-gateway init --allow-private-networks

 mcp-gateway add-spec --name internal-api --file ./openapi.yaml \
   --base-url http://127.0.0.1:3000 --insecure-http

 export MCP_GATEWAY_TOKEN=…
 mcp-gateway test internal-api list_orders --args '{}'
 mcp-gateway serve internal-api
 mcp-gateway inspect internal-api --client cursor

That is still local MCP from a network perspective: the gateway binds to loopback by default, the API stays private, and the client on the same machine can call it directly. For RFC1918 or other private network addresses, the same explicit private-network opt-in applies.

From internal API to self-hosted MCP

The useful bit is that the exact same compiled tool surface can move into a self hosted deployment later. You are not building one set of tool definitions for local development and another for production.

Let remote MCP clients reach it without casually exposing your network

The moment a client lives on another machine, you need a remote URL. That does not mean opening your internal API to the internet.

You have a few options:

  • Private connectivity. Keep the MCP server inside the private network and require corporate VPN, private link, peering or another approved path.

  • Public HTTPS edge. Put a reverse proxy or MCP gateway at the edge, authenticate there, then route to private backend servers.

  • Development tunnel. For temporary remote testing, the open-source CLI can keep the process on loopback and create an outbound tunnel to a public HTTPS MCP URL. No inbound port is required.

That last option is useful when ChatGPT, Claude or another remote client needs to call a server on your laptop. It is development convenience, not the same thing as a permanent self hosted production deployment.

Whatever route you choose, client configuration should contain the remote URL and the credential the client is allowed to use - not the upstream database password or private API key.

When an MCP gateway starts earning its keep

One server can be managed directly. Five servers, three environments and different teams are where centralized control starts to save time.

A gateway becomes useful when you want one place for:

  • Authentication and identity access control across clients.

  • Tool-level access and policy enforcement.

  • Routing across different MCP servers or environments.

  • Rate limits and quotas before requests hit backend systems.

  • Credential management so clients do not receive upstream secrets.

  • Audit trails and threat detection across every tool call.

A generic reverse proxy can route HTTP. An MCP gateway understands the MCP surface: which tools exist, which client can see them, and which calls should be allowed. That distinction matters once tool access itself becomes part of the security model.

Security: the part that makes self-hosting real

A public URL with TLS is not “production ready”. It is simply a public URL with TLS.

Authentication and identity access control

Every authentication event should map to a real user, workload or agent identity where possible. Avoid one shared token for an entire company if you need complete audit trails later. OAuth/OIDC, mTLS or scoped bearer tokens can all be reasonable depending on the environment.

Authorization and tool access

Authentication answers who is calling. Authorization answers what they can do. Keep read and write capabilities separate, apply least privilege, and expose only the tools required for the role or workflow.

Credential management

Keep API keys, database passwords and service credentials out of the model context and out of repository config. Use Vault, cloud secret stores, Kubernetes secrets, encrypted files or another mechanism your security team already trusts. The exact product matters less than the boundary: the AI client should not need the raw secret just to perform a tool call.

Input validation, command injection and arbitrary code execution

Treat tool inputs as untrusted. Validate types and ranges, constrain file paths and commands, and do not turn a free-form string into shell execution because the model sounded confident. Command injection and arbitrary code execution are not exciting AI-specific problems. They are old security problems with a very enthusiastic new caller.

Network access and private boundaries

Keep backend servers private where possible. Expose the minimum network surface, restrict ingress, and make the gateway or edge layer the deliberate entry point. Direct access from every developer laptop to every production service is not a security architecture.

Logs and audit trails

For sensitive tool execution, log the caller identity, tool name, outcome, duration and safe request metadata. Redact credentials and sensitive payloads before they hit logs. Complete audit trails are useful only if the audit system does not become the easiest place to steal the data.

The operational playbook nobody gets excited about

Self hosting buys control by giving you work. That is the trade.

  • Security patches. Keep the MCP SDK, base image, reverse proxy and gateway current rather than treating the first successful deployment as a fossil.

  • Monitoring. Alert on latency, error rates, authentication failures, backend health and unusual tool execution patterns.

  • Environment separation. Keep development, staging and production credentials and endpoints distinct.

  • Backups. Back up configuration, policy and any state the server actually owns. Then test the restore instead of admiring the backup job in a dashboard.

  • Incident response. Know how to revoke access, rotate credentials and disable a dangerous tool quickly.

  • Capacity. Watch CPU, memory and concurrent requests, but do not introduce a Kubernetes cluster because three developers opened Cursor at the same time.

A Docker Compose deployment on one well-managed VM can be perfectly respectable for a small internal service. Kubernetes becomes useful when high availability, scaling, rollout controls or your existing platform standards justify the complexity.

The benefits of having a hosted MCP gateway

Local, hosted or self-hosted MCP: choose per capability

Most real environments will mix all three. MCP adoption tends to move this way naturally as experiments become shared infrastructure.

Choose

When it fits

Typical examples

Local MCP

One developer, local environment, no sharing required

Filesystem tools, CLI helpers, semantic search over personal files, local search engines

Hosted MCP

Public capability, low operational appetite, trusted provider

SaaS tools, commodity integrations, public APIs

Self hosted MCP

Private data, internal systems, custom security, team-wide production use

Finance APIs, internal databases, source-code systems, on premise services

The sensible architecture is often hybrid: local MCP for developer workflows, hosted MCP for public SaaS tools, and self hosted MCP for the internal systems you want to keep inside your own trust boundary. Large language models and AI agents do not care which ownership model you chose as long as the MCP client can discover the right tools and authenticate correctly.

Should I self-host MCP?

Where Fetch Hive fits

If you want to stay fully self hosted, the Fetch Hive open-source mcp-gateway is the cleanest starting point. It is Apache 2.0, supports OpenAPI 3.0/3.1, Streamable HTTP and stdio, private-network opt-in, upstream credential injection, and deployment guides for common PaaS/VPS routes.

If you are still developing locally but a remote AI client needs access, the same CLI can create a temporary bearer-protected tunnel while your process stays on loopback. If the endpoint eventually needs to stay online without your machine, the hosted Fetch Hive MCP Gateway uses the same compiler and adds the hosted operational layer: readiness reports, access tokens, quotas, tool policy, upstream authentication, request logs and a playground.

That split is intentional. Build and test locally with the open-source tool. Self-host it when you need to own the infrastructure. Use hosted MCP when you would rather stop operating the gateway yourself. Same protocol, different operational boundary.

Start small, then make the self-hosted MCP server boring

The first version does not need a giant gateway stack, a Kubernetes cluster and six pages of policy.

Start with one internal API, a narrow tool surface and a client you actually use. Keep the server on infrastructure you control. Add authentication. Make secrets boring. Log enough to debug failures. Test the ugly paths. Then introduce a gateway, stronger policy enforcement and more backend servers when the operational pain gives you a reason.

That is the useful version of self hosting: not “we own every box because control sounds cool”, but “we know exactly where the tool runs, which data it can touch, who can call it, and how to find out what happened when something goes wrong.”

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.