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

Download files

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

Source Distribution

mcp_worker_protocol-1.0.0.tar.gz (16.3 kB view details)

Uploaded Source

Built Distribution

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

mcp_worker_protocol-1.0.0-py3-none-any.whl (17.2 kB view details)

Uploaded Python 3

File details

Details for the file mcp_worker_protocol-1.0.0.tar.gz.

File metadata

  • Download URL: mcp_worker_protocol-1.0.0.tar.gz
  • Upload date:
  • Size: 16.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.10.20

File hashes

Hashes for mcp_worker_protocol-1.0.0.tar.gz
Algorithm Hash digest
SHA256 2af14418dcf595d05efece96e26b7513f053dd3d66deb45c1e1f11c869a86da0
MD5 a40f7002df4cef3a1d66d35e98a6a5cf
BLAKE2b-256 802ad629a2896ec2401e1e76bf3f99e34f88b5466950db0ea15c8ecb9a59f61f

See more details on using hashes here.

File details

Details for the file mcp_worker_protocol-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for mcp_worker_protocol-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 541fc5fd7bfc33f059517a9449a659f4ea8b5df69ccf5152feaf7f869f6fdd60
MD5 bc65c00d53bd448cace5a205c5932802
BLAKE2b-256 1a477073fefcae4b145e2963f3a8b42d9112790aabb9cc2da5318e8418a04249

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 Sentry Error logging StatusPage Status page