Browse guides · Serverless MCPs

The ClosedMCP library

What you use depends on where your MCP server runs.

Your MCP runs...
On ClosedMCP (a Serverless MCP)
Use
the hosted contract below: four headers in, two _meta keys out. Nothing to install.
Your MCP runs...
On your own servers
Use
the Log in with ClosedMCP SDK (@closedmcp/sdk for TypeScript, closedmcp for Python, also Go and Rust). See SDK reference.

Do not wrap a hosted app with the SDK's server wrapper (serveWithClosedMcp / serve_with_closedmcp). It expects an OAuth access token in Authorization: Bearer, and ClosedMCP removes that header before a call reaches a hosted app, so every call would be rejected.

The SDKs' hosted module (closedmcp.hosted in Python, @closedmcp/sdk/hosted in TypeScript, both in the base image) reads the caller, builds the _meta keys below and, from SDK 0.3.0, serves the app:

Python
serve(mcp)
TypeScript
serve(() => server)
Does
serves MCP at /mcp on 0.0.0.0:8080, stateless (0.3.0+)
Python
caller(), try_caller()
TypeScript
caller(extra), tryCaller(extra)
Does
the person calling, from the headers below
Python
open_channel(...), events([...])
TypeScript
openChannel({...}), events([...])
Does
the _meta keys below, checked against the limits
Python
database_url()
TypeScript
databaseUrl()
Does
DATABASE_URL, or an error if no database is enabled

closedmcp_create_project starts every project with this already wired up; give your AI app the closedmcp-builder skill (how to install) too.

What is already installed

Every hosted app and every closedmcp_run sandbox starts from the same base image:

  • Node 22 with @modelcontextprotocol/sdk, fastmcp, @closedmcp/sdk, pg and postgres, found through NODE_PATH (so load them with require).
  • Python 3.12 with mcp, fastmcp 2, psycopg[binary], SQLAlchemy, uvicorn and closedmcp.
  • psql, bash, git, curl and jq.

Your own node_modules or Python packages win over these.

In: who is calling

Header
X-ClosedMCP-User
Meaning
the person's ID, stable
Header
X-ClosedMCP-Email
Meaning
their email
Header
X-ClosedMCP-Org
Meaning
their company's org ID, the slug (e.g. dacme_io)
Header
X-ClosedMCP-Client
Meaning
the AI app they use; display only

ClosedMCP sets these on every call and removes copies sent by anyone else.

  • Python (FastMCP 2): get_http_headers(include_all=True).get("x-closedmcp-email"), with from fastmcp.server.dependencies import get_http_headers.
  • Node (official MCP SDK): extra.requestInfo?.headers["x-closedmcp-email"] in the tool handler.

Out: event channels

_meta key in a tool result
"closedmcp/channel": {name, topic, ttl}
Effect
opens a channel the caller can wait on
_meta key in a tool result
"closedmcp/events": [{topic, data}, ...]
Effect
delivers each data to every open channel of this app with that topic
  • Python (FastMCP 2): return ToolResult(content="...", meta={...}), with from fastmcp.tools.tool import ToolResult.
  • Node (official MCP SDK): return { content: [...], _meta: {...} }.

Details and limits: Event channels.

Already-built HTTP MCP images do not need the ClosedMCP SDK. See Publish an already-built image for the supported private HTTP contract, human key setup and runtime limits. Read the trusted caller headers directly if your framework does not use the SDK. The application must enforce its own caller data boundaries; neither the SDK nor gateway authentication adds per-user row isolation to arbitrary application code.

For AI agents: this page as markdown is at /docs/library.md, and the closedmcp_guide tool returns it with topic library.