closedmcp
A small Python wrapper for Log in with ClosedMCP. It protects Streamable HTTP requests made to the official SDK’s Server or built-in FastMCP, or standalone FastMCP 2, verifies a signed pass on every call, and serves MCP protected-resource metadata.
The public wrapper in 0.4.0 accepts OAuth resource access tokens with type at+jwt, a
client_id, the mcp:tools scope and an audience matching the configured MCP URL.
Company claims use the https://closedmcp.com/claims/ namespace; the person helper
keeps its existing fields. Old pass tokens and the implicit legacy issuer are
rejected. The token follows RFC9068's claims and type using EdDSA; its mandatory
RS256 support is not implemented. This is MCP OAuth, not ID-JAG/enterprise-managed
authorization. Hosted caller helpers use their separate private contract.
Add to an existing server
Keep your existing official mcp.server.fastmcp.FastMCP or standalone fastmcp.FastMCP 2 instance. Replace its HTTP serving call with:
import os
from closedmcp import current_user, serve_with_closedmcp
serve_with_closedmcp(app, resource=os.environ["MCP_URL"], allowed_domains=os.environ["ALLOWED_DOMAINS"].split(","))
In any tool, use current_user().email or current_user().org. For an existing ASGI host, serve closedmcp_app(app, resource=..., allowed_domains=...) instead. Install with pip install closedmcp for the official SDK or pip install 'closedmcp[fastmcp]' for standalone FastMCP 2.
Hello
from mcp.server.fastmcp import FastMCP
from closedmcp import current_user, serve_with_closedmcp
app = FastMCP("hello")
@app.tool()
def hello() -> str:
return f"Hello {current_user().email}"
serve_with_closedmcp(
app,
resource="https://example.com/mcp",
allowed_domains=["example.com"])
Replace the first import with from fastmcp import FastMCP to use standalone FastMCP 2. Install with pip install closedmcp for the official SDK or pip install 'closedmcp[fastmcp]' for both. This repository also has a runnable template: install the package locally with pip install -e ., then run MCP_URL=https://example.com/mcp ALLOWED_DOMAINS=example.com python template/server.py. Set PORT and HOST for the listening socket. CLOSEDMCP_ORIGIN and CLOSEDMCP_JWKS_URL are available for local integration tests.
resource is the exact public MCP URL and JWT audience. allowed_domains must contain at least one verified company domain. By default, the wrapper accepts only https://closedmcp.com. An explicit issuer accepts only that issuer. The wrapper checks the EdDSA signature, issuer, exact audience, expiry, five-minute maximum lifetime, required identity claims, and company domain. Unknown key IDs trigger at most one JWKS refresh per 30 seconds. current_user() returns a Person with id, email, company, org, and optional aiApp; it raises outside a verified request. aiApp is a client supplied display value.
For /mcp, metadata is at /.well-known/oauth-protected-resource/mcp and the generic metadata path. A missing or invalid pass receives 401 with WWW-Authenticate: Bearer resource_metadata="<metadata URL>". Authenticated non-POST requests receive 405. To use another ASGI server, call closedmcp_app(app, resource=..., allowed_domains=...) and serve the returned ASGI app. Its lifespan must be run by the ASGI server.
Hosted on ClosedMCP (Serverless MCPs)
An app hosted on ClosedMCP does not use sign-in: ClosedMCP checks the caller and strips Authorization (so serve_with_closedmcp would reject every call). Use closedmcp.hosted instead. serve(mcp) (0.3.0+) serves /mcp on 0.0.0.0:8080, stateless, the way ClosedMCP calls it; do not use mcp.run(), which talks stdio and never goes live.
from fastmcp import FastMCP
from fastmcp.tools.tool import ToolResult
from closedmcp.hosted import caller, events, open_channel, serve
mcp = FastMCP("chat")
@mcp.tool
def watch(room: str) -> ToolResult:
return ToolResult(content=f"Watching #{room}.", meta=open_channel(f"room:{room}", name=f"#{room}"))
@mcp.tool
def post(room: str, text: str) -> ToolResult:
return ToolResult(content="Sent.", meta=events([{"topic": f"room:{room}", "data": {"from": caller().email, "text": text}}]))
if __name__ == "__main__":
serve(mcp)
serve(server)takes a FastMCP 2 server, an officialmcpFastMCP or a low-levelServerand blocks.http_app(server)returns the same ASGI app if you run it yourself.caller()returnsCaller(id, email, org, client)from theX-ClosedMCP-*headers of the current request and raises when they are missing. It works in FastMCP 2 and officialmcpSDK tools; you may also pass a toolContext, a StarletteRequest, or a headers mapping.try_caller()returnsNoneinstead of raising.open_channel(topic, name=None, ttl=None)andevents([{"topic", "data"}])build the_metakeys and raiseValueErroron anything ClosedMCP would drop or change (topic at most 200 characters, name 80,ttlwhole seconds from 30 to 7 days, at most 20 events,dataat most 8 KB as JSON). Combine them with{**open_channel(...), **events(...)}. With the official SDK, returnCallToolResult(content=..., _meta=...).database_url()returnsDATABASE_URL(raises if no database is enabled);live_database_url()returns the read-only live URL inclosedmcp_runsandboxes.
See the ClosedMCP documentation.
Metadata
Release files for closedmcp 0.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| closedmcp-0.4.0.tar.gz | 21.2 kB | Without provenance | Details for closedmcp-0.4.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| closedmcp-0.4.0-py3-none-any.whl | Python 3 | none | any | Details for closedmcp-0.4.0-py3-none-any.whl |
Total release size: 35.9 kB
Release files / closedmcp-0.4.0.tar.gz
| Download URL | closedmcp-0.4.0.tar.gz |
|---|---|
| Size | 21.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9401e43240783229ca06313c5f86fb1c8593c769e3d66fcc6d56f22e25a25c32
|
|
BLAKE2b-256 checksum How to use checksums |
57c988ce9a314efa1831447ecf08260d3347c1d917352945354e03c1e83bb310
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / closedmcp-0.4.0-py3-none-any.whl
| Download URL | closedmcp-0.4.0-py3-none-any.whl |
|---|---|
| Size | 14.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
51cdaa52b486ccade587a51c7ff39bf3df63b38e72093246cf944d954df50d64
|
|
BLAKE2b-256 checksum How to use checksums |
894ed1342aba32da31abf4c265f7d1f992af00cbcd921c04e01b8a0a035f0e2b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Security for closedmcp 0.4.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.