MCP Python Starter
This server does not currently have a deployable release on Glama. Follow the repository's setup instructions to install and configure it for your MCP client, including any required credentials and local dependencies.
Remote MCP server in Python that scales to zero
A stateless Streamable HTTP MCP server in
Python (server.py), ready to deploy as a remote HTTPS endpoint on
Gregale. Runs from Python's standard library + PyJWT
and jsonschema, enforces bounded framing and per-tool OAuth scopes, and parks
to zero when idle.
Run locally
python3 -m venv .venv
. .venv/bin/activate
pip install -r requirements.txt
python -m unittest discover -s . -p 'test_*.py'
python server.pyVerify the server locally with the Gregale CLI:
gregale mcp server doctor --url http://127.0.0.1:8080/mcp --legacy
gregale mcp client tools --url http://127.0.0.1:8080/mcp
gregale mcp client call --url http://127.0.0.1:8080/mcp --tool add --arguments '{"a":7,"b":5}'Related MCP server: MCP Feature Reference Server
Add a tool
Register tools in server.py with register_tool:
register_tool({
"name": "lookup",
"description": "Find a record by key.",
"inputSchema": {
"type": "object",
"properties": {"key": {"type": "string"}},
"required": ["key"],
},
}, lookup)In external-oauth mode, add any new tool name to auth.tool_scopes in
gregale-mcp.json.
Deploy
gregale mcp server deploy --path . --name my-mcp --size smallAn AGENTS.md guide for coding agents (Claude Code, Cursor, Antigravity,
Codex) is included in this repository.
License
MIT — see LICENSE.
Reference
MCP Python starter
A small stateless Streamable HTTP MCP server built on Python's standard
library, with PyJWT for external OAuth.
It advertises the greet, add, stream_demo, and build_report tools, a
welcome resource, a customer-record resource template and a summarize prompt.
It supports the current Gregale MCP protocol plus legacy discovery. It
is open-access by default and supports external OAuth with signed RS256/ES256
JWT validation and per-tool tool_scopes, resource_scopes and prompt_scopes.
It supports bounded prompt and resource completions and streamed progress.
Every tool call is answered in its response; this starter has no durable MCP
Tasks.
The HTTP endpoint accepts Content-Length or chunked request framing. Decoded bodies and aggregate chunk metadata are each limited to 1 MiB, with chunk-size and trailer lines limited to 64 KiB. Trailers cannot change authentication or MCP headers. Malformed or ambiguous framing receives an error and closes the connection; valid requests can reuse the connection.
python -m pip install -r requirements.txt
python -m unittest discover -s . -p 'test_*.py'
python server.py
gregale mcp server doctor --url http://127.0.0.1:8080/mcp --legacy
gregale mcp server doctor --url http://127.0.0.1:8080/mcp --stream-tool stream_demo
gregale mcp client call --url http://127.0.0.1:8080/mcp --tool add --arguments '{"a":7,"b":5}'
gregale mcp client complete --url http://127.0.0.1:8080/mcp --prompt summarize --argument style --value exec
gregale mcp server deploy --path . --name my-mcpgregale mcp server init --runtime python --path ./my-mcp creates the starter files.
Read gregale-mcp.json, server.py and auth.py before deploying.
Configure auth.mode: "external-oauth", the issuer, JWKS URL, resource URL, endpoint
scopes, and each catalog entry's scopes before exposing private tools, resources
or prompts. Configured policy maps are allowlists: entries missing from a map
are hidden and denied. Resource scope keys can be exact URIs or simple URI
templates such as customer://records/{recordId}; each template variable
matches one URI segment. The sample rejects browser Origin headers unless explicitly allowlisted; it accepts
non-browser MCP clients that omit that header.
The starter supports subscriptions/listen for registered resource URIs, plus
tool, resource, and prompt list-change notifications. Call notify_resource_updated(uri) after changing
an application-owned resource. The default update adapter is process-local;
install a shared adapter with set_resource_update_adapter before starting the
HTTP server when resources can change on another web replica.
The server bounds JSON request bodies, returns JSON responses without creating
sessions, and exposes /healthz for platform readiness. PyJWT validates
external OAuth tokens; install it with requirements.txt. Extend the catalogs
deliberately, keep schemas aligned with handlers, and add ownership checks to
resource reads that access application data.
Runtime catalog changes
server.py exposes process-local register_tool, replace_tool,
remove_tool, register_resource, replace_resource, remove_resource,
register_prompt, replace_prompt, and remove_prompt functions. Add entries
before the ThreadingHTTPServer starts, or call the mutation functions from
application code while the process runs. For example:
def lookup(arguments, caller):
key = arguments.get("key")
value = lookup_record(key, caller)
return {"content": [{"type": "text", "text": value}]}
register_tool({
"name": "lookup",
"description": "Find a record by key.",
"inputSchema": {
"type": "object",
"properties": {"key": {"type": "string"}},
"required": ["key"],
},
}, lookup)The starter validates a custom tool's declared inputSchema before invoking
its handler. JSON Schema validation supports local references,
does not retrieve external references, and does not coerce values or insert
defaults. Boolean property schemas, including nested true and false schemas,
work with modern request headers; argument validation still enforces them.
Handlers enforce business rules and ownership and return a normal
MCP tool result. Successful custom tool handler results must include
structuredContent matching a declared outputSchema; isError: true
results and intermediate input_required responses may omit it. Both schemas
are checked when registering or replacing the tool, and invalid results
produce a redacted tool error.
Resource handlers receive (uri, variables, caller)
and return a list of MCP resource contents. Prompt handlers receive
(arguments, caller) and return the MCP prompt result. caller contains the
verified subject, client ID, and scopes, but no bearer token. Mutations send
list-change notifications only when the subscribing caller's authorized view
changed. In external OAuth mode, add dynamic entry names and resource patterns
to the corresponding scope allow-lists. The registry is process-local, so
every serving replica needs the same application registration code.
For custom resource subscriptions, pass authorize= to register_resource and
replace_resource. The synchronous callback receives (uri, context) with the
verified subject, client ID and scopes; return True to permit access. Reads,
subscription setup and update delivery share the callback. Custom resources
without a callback remain readable through their handlers but cannot be subscribed.
gregale mcp server deploy reads this digest from its zero-traffic candidate and pins
the promoted deployment revision with MCP_CATALOG_EXPECTED_SHA256. For other
deploy paths, set that variable to the /healthz digest on every serving
replica. Remove any existing app-wide env or secret with this key before using
gregale mcp server deploy; those runtime layers take precedence over deployment
overrides. A mismatch makes /healthz return 503 and blocks MCP requests.
The health response includes the serving instance from Gregale's
X-Faas-Instance-Id request header. (FAAS_INSTANCE_ID is set at boot, so every
instance restored from one snapshot would report the same value.) In addition,
gregale mcp server status receives the selected replica identity from Gregale's
authenticated exact-instance probes. It initializes MCP and lists the
caller-visible catalogs on every running replica without invoking tools,
reading resources, or relying on load-balancer sampling. Use --token-env or
--release-policy for external OAuth endpoints. The
digest covers advertised definitions, OAuth per-entry allow-lists, not handler
implementation; deploy the same reviewed build to all
replicas.
Durable MCP Tasks
This starter answers every tool call in its response and ships without durable Task code. For long-running tools that return a durable MCP Task handle (PostgreSQL task store, workers, encrypted payloads), start from the Tasks starter instead:
gregale init --template mcp-python-tasks --path ./my-mcp
gregale mcp server init --runtime python --tasks --name <prefix> --path ./my-mcpGraceful shutdown
On SIGTERM/SIGINT the server stops accepting new requests and waits for open
HTTP connections, including progress streams, to finish. Set
MCP_DRAIN_TIMEOUT_SECONDS (default 10; range 1–300) below the worker's
drain_timeout, with at least 10 seconds left for cleanup. Observe the request
cancellation signal in long-running tools.
Run locally
python -m venv .venv
. .venv/bin/activate
pip install -r requirements.txt
python -m unittest
python server.py
gregale mcp server doctor --url http://127.0.0.1:8080/mcp
gregale mcp client tools --url http://127.0.0.1:8080/mcp
gregale mcp client call --url http://127.0.0.1:8080/mcp --tool greet --arguments '{"name":"Ada"}'
gregale mcp client resources --url http://127.0.0.1:8080/mcp
gregale mcp client read --url http://127.0.0.1:8080/mcp --uri 'customer://records/example-1'
gregale mcp client prompts --url http://127.0.0.1:8080/mcp
gregale mcp client render --url http://127.0.0.1:8080/mcp --prompt summarize --arguments '{"text":"weekly report"}'
gregale mcp client complete --url http://127.0.0.1:8080/mcp --prompt summarize --argument style --value exec
gregale mcp client complete --url http://127.0.0.1:8080/mcp --resource-template 'customer://records/{recordId}' --argument recordId --value example-For a protected deployment, pass an MCP access token with --token-env MCP_TOKEN. Keep that token out of shell history. Add object or tenant ownership
checks inside resource and tool handlers before connecting real customer data.
Deploy
gregale mcp server deploy --path . --name <slug>The deploy command stages a zero-traffic candidate, verifies its MCP endpoint, and promotes only after the previous serving revision still owns all traffic.
Browser clients
Configure exact origins in allowed_origins. The MCP endpoint accepts browser
OPTIONS preflight before authentication and allows GET/POST with Authorization,
Content-Type, Accept, MCP-Protocol-Version, MCP-Method, MCP-Name and valid
MCP-Param-* headers. Responses expose WWW-Authenticate, MCP-Protocol-Version and
Streaming-Status, including authorization failures and streamed responses.
Untrusted origins, unsupported requested methods/headers and duplicate Origin
headers are rejected. Actual MCP requests still require the configured bearer
and scopes; cookies and credentialed CORS are not enabled.
Protocol telemetry
The server emits structured mcp_protocol_request events from actual parsed RPC
methods and response objects, including tool errors returned with HTTP 200.
Method and tool categories are fixed; custom tool names use other. Events do
not contain arguments, results, resource URIs, error messages, bearer values or
RPC IDs. Valid UUID X-Faas-Request-Id and nonzero version-00 traceparent IDs
support correlation with Gregale request evidence; they are not trusted identity.
execution_duration_ms ends at response construction (subscription acknowledgment
for subscription setup). stream_duration_ms measures SSE lifetime separately;
the durations overlap. Unobserved timings are omitted. Protocol outcomes and
stream termination are separate, so delivery failure does not erase an observed
result. Typed
termination distinguishes cancellation and timeout without adding tool deadlines.
Aggregate only this event family into counters/histograms. This is structured logging, not a public metrics endpoint. Pre-parse/pre-dispatch authentication failures and notifications are outside coverage. Keep correlation IDs out of metric labels and use existing log retention/access controls.
Telemetry heartbeats
The web process emits a payload-free mcp_telemetry_heartbeat immediately and
every 30 seconds, independent of RPC traffic. Shutdown stops the emitter.
This is process telemetry, not an MCP readiness check. Set
MCP_TELEMETRY_LOSS_ALERT=true to opt into platform operator alerts for lost
heartbeats; customer performance webhook settings are separate.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
This server cannot be deployed
Maintenance
Related MCP Connectors
Remote MCP server exposing SMI Aware tools, resources, and skills over Streamable HTTP.
MCP server for your apps' tools and custom tools, plus hosted AI agents and approval-gated workflows
Streamable HTTP MCP server for Google Calendar and Sheets with OAuth login.
The Stytch MCP server is a reference implementation that demonstrates remote MCP server authentication and authorization using Stytch Connected Apps. It provides OAuth 2.1-compliant authorization (including PKCE), Dynamic Client Registration, and validates Stytch-issued access tokens to enable AI agents to securely interact with external services through permissioned access, supporting scopes like openid, email, profile, and manage:project_data.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceA minimal MCP server with sample tools, resources, and prompts, plus an aggregator to connect multiple external MCP servers and REST APIs, including experimental OAuth support.MIT
- AlicenseNot gradedqualityDmaintenanceA complete MCP server implementation demonstrating all protocol features (tools, resources, prompts, sampling, and elicitation) with OAuth authentication, serving as a learning resource and starting template for building MCP servers.MIT
- FlicenseNot gradedqualityCmaintenanceEnables deployment and connection to a minimal Streamable HTTP MCP server with bearer-token authentication, a health endpoint, and an example tool, while allowing developers to add custom tools.-
- AlicenseNot gradedqualityBmaintenanceEnables MCP clients to discover and call three tools over Streamable HTTP: generating personalized greetings, retrieving the current ISO 8601 date/time in a configured timezone, and performing addition, subtraction, multiplication, or division with clear error handling. It runs locally or in Docker and exposes a health endpoint for monitoring.MIT