Run your own MCP stack
A hosted MCP vendor gives you one URL and a monthly bill. Running your own stack gives you the source, the logs and the keys. This guide shows the layout we use for the McpStamp servers: what the parts are, how to host them, what to lock down and what it costs.
Vendor or your own stack?
Use a hosted vendor when you need one or two integrations this week and nobody on the team wants to run a server. Run your own stack when one of these is true:
- The tools touch customer data, invoices or credentials, and you must know where that data goes.
- You need a tool the vendor does not have, or you need to change how a tool behaves.
- You pay per seat or per call, and the usage grows faster than the value.
- You must pass a security review that asks for the source, the logs and the data location.
The work is smaller than it sounds. An MCP server is a small program that lists tools and answers tool calls. The hard parts are the same as for any small API: auth, limits, logs and updates.
Architecture
The layout has four parts. Each part is replaceable.
- One server per job. Each server is a small package with a short list of tools (for example, invoice: create, list, export PDF). It speaks MCP over stdio, so it runs on a laptop with no network. Keep a written contract for each tool: input schema, output, errors. Small servers are easy to review and easy to delete.
- One gateway Worker. A single HTTP service imports the tool sets of every server and serves each one at its own path, for example
/mcp/invoice, over MCP streamable HTTP. The stdio package stays the source of truth. A build step copies (vendors) its source into the gateway, so the hosted tools never drift from the local ones. - Auth in front of tools. The gateway can answer
initializeandtools/listwithout a token, so a client can discover the server. Everytools/callneeds a token: a per-user token in the URL for simple clients, or OAuth for clients that support it. - Small state store. A key-value store keeps token records, usage counters and per-user settings. Tool data that a user owns (documents, logs) stays in the user's own storage or is returned as a file, not kept on the gateway.
Claude / ChatGPT / Cursor
| MCP streamable HTTP + token
v
gateway Worker /mcp/<server>
| checks token, limits, logs the call
+--> tool set: invoice (vendored from servers/invoice)
+--> tool set: docx (vendored from servers/docx)
+--> tool set: currency (vendored from servers/currency)
|
v
key-value store: tokens, counters (no tool payloads) This is how our hosted endpoints run: one Cloudflare Worker serves the tool sets of several servers at mcp.zovo.one/mcp/<name>, and every server also runs locally over stdio. The source is on GitHub.
Self-hosting steps
- Start local. Run each server over stdio in Claude Desktop or Cursor first. Fix the tool names, descriptions and schemas there. A model chooses tools by their descriptions, so write them for the model: what the tool does, when not to use it, what each field means.
- Add the gateway. Create one Worker (or a small Node service) with a route per server. Use the official MCP TypeScript SDK transport for streamable HTTP. Keep one build script that vendors each server's source into the gateway, and run it in CI so a change to a server always reaches the hosted copy.
- Add tokens. Mint a random token per user (at least 128 bits), store only its hash with the user id and plan, and check it on every
tools/call. Let users revoke and rotate tokens. Add OAuth later if your clients need it. - Add limits. Count calls per token per day in the key-value store. Keep counters in memory per request batch and write them in batches, so a busy token does not cost one write per call. Return a clear MCP error when a limit is reached.
- Add a check to CI. After each deploy, call
initialize,tools/listand one harmlesstools/callper server, and fail the deploy if any of them breaks. You can run the same checks by hand with the free McpStamp check. - Connect clients. Give each user a connect page that shows the full URL with their token, plus the config snippet for each client. A bare URL without a token should list tools but refuse calls, with an error that says how to get a token.
Security checklist
- Least privilege per server. Each server gets only the secrets and scopes its tools need. Do not give the gateway one master API key for everything.
- Validate every input against the tool's schema before you act on it. Reject unknown fields. Cap sizes of strings, files and arrays.
- Treat tool output as untrusted text. Content that a tool fetches (a web page, an email, a document) can carry instructions aimed at the model. Return data, label it as data, and do not let one tool's output trigger a write in another tool without the user's confirmation.
- Confirm destructive actions. Tools that send, pay, delete or publish need an explicit confirm field or a two-step flow.
- Check the Origin header on the HTTP transport and allow only the clients you expect. Serve only over HTTPS.
- Log calls, not payloads. Log the token id, tool name, status and duration. Do not log documents, prompts or personal data.
- Pin versions. Pin the SDK and every dependency, review updates, and keep the tool list stable. A tool whose description changes silently is a supply-chain risk for every client that trusts it.
- Keep secrets out of the repo. Use the platform's secret store, and rotate a secret when someone leaves the team.
What it costs
MCP calls are small HTTP requests, so the hosting cost is low. On Cloudflare Workers (list prices, November 2026; check the current pricing page before you plan):
- Free plan: 100,000 requests a day and 1,000 key-value writes a day. That is enough for a small team that makes a few thousand tool calls a day.
- Paid plan: about $5 a month, with 10 million requests a month included and a small fee for each extra million.
- The real cost is time. Plan about 1 to 2 days to set up the gateway, tokens and CI, then about 1 to 2 hours a month for dependency updates and checks.
Compare that with a per-seat vendor price multiplied by your team size and the number of months, and with the cost of a security review for a third party that sees your data.
MCP stack template, $29
The layout from this guide as a repo you can fork: a gateway Worker with a route per server, a vendoring build script, token mint and revoke, per-token daily limits, an example server with a written tool contract, and a CI workflow that checks every endpoint after deploy. Zero runtime dependencies: Node 18+ locally, Cloudflare Workers for hosting. The included tests (stdio server, token auth, limits, revoke, Origin check, batched counters) and the smoke check run without a Cloudflare account. Token auth only (no OAuth) and request/response tools only; the README lists these limits.
One payment through Stripe, no account. Zip download right after payment. Use it for your own and your clients' projects.
Do not want to run it yourself? Our McpStamp servers run locally or at a hosted URL today. All paid servers, $39 once ยท Pricing