Skip to main content

mcpd Python SDK

Project description

mcpd-sdk-python

mcpd-sdk-python is a lightweight Python SDK for interacting with the mcpd application.

A daemon that exposes MCP server tools via a simple HTTP API.

This SDK provides high-level and dynamic access to those tools, making it easy to integrate with scripts, applications, or agentic frameworks.

Features

  • Discover and list available mcpd hosted MCP servers
  • Retrieve tool definitions and schemas for one or all servers
  • Dynamically invoke any tool using a clean, attribute-based syntax
  • Generate self-contained, deepcopy-safe tool functions for frameworks like any-agent
  • Minimal dependencies (requests only)

Installation

Assuming you are using uv, include it in your pyproject.toml:

[tool.uv.sources]
mcpd = { path = "../mcpd", editable = true }

[project]
dependencies = [
  "mcpd"
]

Then run:

uv venv
source .venv/bin/activate
uv sync

Dev Setup

Use the Makefile target to ensure uv is installed, and your virtual environment is active and sync'd.

make setup

Testing

Ensure you have the correct dependencies installed for testing:

uv sync --group tests

Then to run all tests:

uv run pytest tests

... or via Makefile:

make test

Quick Start

from mcpd import McpdClient, McpdError

client = McpdClient(endpoint="http://localhost:8090")

# List available servers
print(client.servers())
# Example: ['time', 'fetch', 'git']

# List tool definitions (schemas) for a specific server
print(client.tools(server_name="time"))

# Dynamically call a tool
try:
    result = client.call.time.get_current_time(timezone="UTC")
    print(result)
except McpdError as e:
    print(f"Error: {e}")

Agentic Usage

Generate dynamic functions suitable for AI agents:

from any_agent import AnyAgent, AgentConfig
from mcpd import McpdClient

# Assumes the mcpd daemon is running
client = McpdClient(endpoint="http://localhost:8090")

agent_config = AgentConfig(
    tools=client.agent_tools(),
    model_id="gpt-4.1-nano",  # Requires OPENAI_API_KEY to be set
    instructions="Use the tools to answer the user's question."
)
agent = AnyAgent.create("mcpd-agent", agent_config)

response = agent.run("What is the current time in Tokyo?")
print(response)

Examples

A working SDK examples are available in the examples/ folder, please refer to the relevant example for execution details.

Method Docs
AnyAgent README.md
Manual README.md
Pydantic AI README.md

API

Initialization

from mcpd import McpdClient

# Initialize the client with your mcpd API endpoint.
# api_key is optional and sends an 'MCPD-API-KEY' header.
client = McpdClient(api_endpoint="http://localhost:8090", api_key="optional-key")

Core Methods

  • client.servers() -> list[str] - Returns a list of all configured server names.

  • client.tools() -> dict[str, list[dict]] - Returns a dictionary mapping each server name to a list of its tool schema definitions.

  • client.tools(server_name: str) -> list[dict] - Returns the tool schema definitions for only the specified server.

  • client.agent_tools() -> list[Callable] - Returns a list of self-contained, callable functions suitable for agentic frameworks.

  • client.clear_agent_tools_cache() - Clears cached generated callable functions that are created when calling agent_tools().

  • client.has_tool(server_name: str, tool_name: str) -> bool - Checks if a specific tool exists on a given server.

  • client.call.<server_name>.<tool_name>(**kwargs) - The primary way to dynamically call any tool using keyword arguments.

Error Handling

All SDK-level errors, including HTTP and connection errors, will raise a McpdError exception. The original exception is chained for full context.

License

Apache-2.0

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

mcpd-0.0.1.tar.gz (394.9 kB view details)

Uploaded Source

Built Distribution

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

mcpd-0.0.1-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

Details for the file mcpd-0.0.1.tar.gz.

File metadata

  • Download URL: mcpd-0.0.1.tar.gz
  • Upload date:
  • Size: 394.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for mcpd-0.0.1.tar.gz
Algorithm Hash digest
SHA256 cac56c00f8ff8d98d17e4354b8d0d94a5279a595e706989a8ff558af86805307
MD5 3ff6692620a00432bca2a39c5c426814
BLAKE2b-256 af21db164a29880534a8629e4b2aca9e0b22d418d909d287c68ac4b14ba086ec

See more details on using hashes here.

Provenance

The following attestation bundles were made for mcpd-0.0.1.tar.gz:

Publisher: release.yaml on mozilla-ai/mcpd-sdk-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mcpd-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: mcpd-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 8.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for mcpd-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ab5b281a47d34590988847050a0d9e9e6ae41c48e5a4c3cfe6f067f9c9491994
MD5 acdc3b7fd0d72e791cb77aa546ecbb03
BLAKE2b-256 1fd0b8db412968b17f6f946a5384cc910e477a7adfa811a8b9242ac2d3483731

See more details on using hashes here.

Provenance

The following attestation bundles were made for mcpd-0.0.1-py3-none-any.whl:

Publisher: release.yaml on mozilla-ai/mcpd-sdk-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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