Skip to main content

mcp-worker-protocol

Protocol foundation for the MCP Worker platform — shared Pydantic models, standardized error codes, and an async/sync Hub HTTP client.

Python License Tests

mcp-worker-protocol is the protocol base layer shared by MCP worker runtimes and host agents. It owns the cross-service contract — data models, errors, headers, and Hub communication — so the layers above it can stay focused on business behavior.


Installation

pip install mcp-worker-protocol

Import name uses an underscore: mcp_worker_protocol.


Quickstart

from mcp_worker_protocol import (
    ToolSchema,
    ParametersSchema,
    PropertyDefinition,
    HubClient,
)

tool = ToolSchema(
    tool_id="my_hello",
    title="Hello World",
    description="Return a greeting",
    parameters_schema=ParametersSchema(
        properties={"name": PropertyDefinition(type="string", default="World")},
        required=[],
    ),
)

client = HubClient("https://hub.example.com", api_key="mcp_sk_xxx")
client.register_tools([tool], jwt_token="<jwt>")

Five lines to a serializable, validated MCP tool definition and a working Hub client.


What's inside

Module Responsibility
models Pydantic models: ToolSchema, ParametersSchema, PropertyDefinition, Heartbeat, TaskReport, ErrorInfo, and more
errors Eight standard error codes, HubError hierarchy, and HTTP-status mapping
utils schema_from_signature — derive a JSON Schema from Python type hints
hub_client HubClient (sync) and AsyncHubClient (async) with retry + error mapping

Generate schemas from type hints

from mcp_worker_protocol import schema_from_signature

def search(collection: str, top_k: int = 5):
    """Semantic search
    :param collection: Collection name
    :param top_k: Number of results
    """

schema = schema_from_signature(search)
# schema.required == ["collection"]
# schema.properties["top_k"].default == 5

Handle errors by contract

from mcp_worker_protocol import HubError, NetworkError

try:
    client.send_heartbeat(heartbeat)
except HubError as exc:
    print(exc.code, exc.http_status, exc.detail)
except NetworkError:
    # transport-level failure
    ...

Error codes

Code HTTP Meaning
INVALID_PARAMS 422 Invalid parameters
NOT_FOUND 404 Tool or resource not found
TIMEOUT 504 Execution timeout
PERMISSION_DENIED 403 Not authorized
WORKER_OFFLINE 503 Worker offline
WORKER_ERROR 502 Worker internal error
INTERNAL_ERROR 500 Hub internal error
RATE_LIMITED 429 Rate limited

Compatibility

  • Python 3.10+
  • Runtime dependencies: pydantic>=2.0, httpx>=0.24 — nothing else.
  • New model fields are backward-compatible (defaulted), and serialization omits None values via exclude_none=True.

Development

pip install -e ".[dev]"
pytest

License

Apache License 2.0

Metadata

Release files for mcp-worker-protocol 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mcp-worker-protocol 1.1.0
File Size Uploaded Provenance
mcp_worker_protocol-1.1.0.tar.gz 16.4 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for mcp-worker-protocol 1.1.0
File Interpreter ABI Platform
mcp_worker_protocol-1.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 33.7 kB

Release files / mcp_worker_protocol-1.1.0.tar.gz

Download URL mcp_worker_protocol-1.1.0.tar.gz
Size 16.4 kB
Tags Source
SHA-256 checksum
How to use checksums
5d8bf264db2f5c422facf2d07652c399dc6b69bcb99c53aec3c140484e00aaf4
BLAKE2b-256 checksum
How to use checksums
a56b667984b26436086de64ce380ce0b4d050562900ca47361eb48545747ca48
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.20

Release files / mcp_worker_protocol-1.1.0-py3-none-any.whl

Download URL mcp_worker_protocol-1.1.0-py3-none-any.whl
Size 17.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c21ea2c57b337963f55ef1c4f188231e3cef9ad7b21ee3723eca32601c189d10
BLAKE2b-256 checksum
How to use checksums
480423b52245d7010fb4bc5e14fef53cd2a83268002393567552677100b620a4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.20

Security for mcp-worker-protocol 1.1.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.

Release history Release notifications | RSS feed

This release

1.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page