Skip to main content

AgentRuntime MCP SDK (decorators, runtime, middleware, schemas, proxy)

Project description

AgentRuntime MCP SDK (Python)

Opinionated SDK for MCP connectors using FastMCP with the same Control integration as agentruntime-mcp-go: optional POST /mcp/config, env merge, and request metadata (run token, instance id).

There is no mandatory legacy standalone token/HMAC middleware chain in front of every request. Probe-style auth is the Bearer run token (or X-MCP-Token) and headers AgentRuntime sends; optional auth.mode in config.yaml is reserved for future templates and does not switch Control gating off.

Install

pip install agentruntime-mcp

Runtimes

Entry When to use HTTP
run(config_path) Decorator-only tool() modules; tools registered from config.yaml / build_schemas /mcp
run_with_registry(config_path, *names) Plugins registered with register_adapter; one process, one MCP server /mcp
run_with_router(config_path) Same registry, monolith routing (Go RunWithRouter / TS runWithRouter parity) /{adapter}/mcp plus optional webhook routes on the same ASGI app

Use register_adapter for anything that should share a process with other adapters. Keep plain run() for single-connector demos that only use decorators and YAML tools.

Webhooks: Implement register_webhook(self, mux: ServeMux) on the adapter. Paths are registered on the root Starlette app before adapter mounts (same dispatch order as Go/TS). Operators expose vendor callbacks as https://<host>:<port><path> (same host/port as MCP).

Minimal example

from pydantic import BaseModel, Field
from agentruntime.mcp.decorators import tool
from agentruntime.mcp.runtime import run
from fastmcp import Context

class In(BaseModel):
    a: float = Field(...)
    b: float = Field(...)

class Out(BaseModel):
    result: float
    expression: str

@tool(name="add", input_model=In, output_model=Out)
def add(a: float, b: float, ctx: Context) -> Out:
    region = ctx.config.region  # resolved config when schema + Control are used
    return Out(result=a + b, expression=f"{a} + {b}")

if __name__ == "__main__":
    run("config.yaml")

Config (config.yaml)

  • server: name, host, port, stateless_http
  • tracing: enable OpenTelemetry when dependencies are present
  • config: declarative schema for Control / GET /mcp/config/schema

Env overrides: HOST, PORT (see docs/mcp/mcp_env.md).

Example:

server:
  name: "MyConnector"
  host: "127.0.0.1"
  port: 8012
  stateless_http: true

tracing:
  enabled: false

config:
  apiKey:
    type: string
    displayName: API Key
    required: true

Control config resolution

When the adapter registers at least one config key:

  • Set MCP_CONTROL_SERVER_URL to your control-service base URL.
  • The SDK may call POST /mcp/config with the run token from the request and your schema.
  • Set MCP_CONFIG_FETCH_REQUIRED=false for local work without Control (when you still declare schema keys).

See docs/mcp/mcp_env.md for the full variable list.

Proxy (library)

from agentruntime.mcp.proxy import run_proxy
run_proxy(
    target_url="http://127.0.0.1:8000/mcp",
    overlay_file="tools.yaml",
    host="127.0.0.1",
    port=8010,
)

TypeScript sibling SDK

For Node deployments, use the monorepo package packages/agentruntime-mcp-ts (@agentruntime-labs/agentruntime-mcp): official @modelcontextprotocol/server, Zod 4, runWithRouter.

Examples in this repo

Releasing

See ../RELEASE.md (Python section): lightweight Git tags (v0.1.0, v0.1.1), bump version in pyproject.toml, do not commit __pycache__ / *.egg-info/.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

agentruntime_mcp-0.2.0.tar.gz (25.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

agentruntime_mcp-0.2.0-py3-none-any.whl (28.1 kB view details)

Uploaded Python 3

File details

Details for the file agentruntime_mcp-0.2.0.tar.gz.

File metadata

  • Download URL: agentruntime_mcp-0.2.0.tar.gz
  • Upload date:
  • Size: 25.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.1

File hashes

Hashes for agentruntime_mcp-0.2.0.tar.gz
Algorithm Hash digest
SHA256 d00ed27e79e0e096f25b321e87d7ecb98c3a8c96ce44e13e8e35850cf53f7a86
MD5 d47816c278bfbb32323b825129daa56b
BLAKE2b-256 7ddfb2510c6ad3f4a8a8d09a7bb002cbeb38756b26f78526c5704215b24799e0

See more details on using hashes here.

File details

Details for the file agentruntime_mcp-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for agentruntime_mcp-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2d17e5ca53656f98bf8f94f9b823bd5a4d5d0f90ddd4b9eb0007cc6e210a13e7
MD5 5ca5235ca9ba8a41afa807402998fbbc
BLAKE2b-256 e9f8ba5a407492bca7d0d017c84635f51d0bfa5e229563aaa2adc7e985b9b615

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page