Skip to main content

No project description provided

Project description

mcp-tuning

A script-first MCP debugging/testing library for Jupyter notebooks and plain Python scripts.

It is designed to help you iterate on MCP servers (implemented in any language) by providing a small, synchronous client API:

  • Connect via stdio (subprocess), http, or sse
  • Explore: tools / resources / prompts
  • Call tools with JSON arguments
  • Save/replay input-only cases (tool + args)
  • Export logs / history / last result as JSON for repeatable debugging

Start with examples/notebooks/01_mcp_inspector_demo.ipynb.

Requirements

  • Python 3.12+
  • uv

Install (uv)

uv sync
uv sync --extra notebook --extra test

Run (Jupyter)

uv run jupyter lab

Quickstart (stdio)

Prefer argv lists for stdio servers (avoids shell quoting issues) and make sure the server runs in an environment that has its dependencies installed.

from mcp_tuning import connect_stdio

# Example 1: connect to the built-in mock server (minimal dependencies)
import sys
c = connect_stdio([sys.executable, "src/mcp_tuning/_mock_server.py"])

print(c.server_info())
print([t.name for t in c.tools()])
print(c.call("add", {"a": 1, "b": 2}).result)
c.close()

Connect to the FastMCP example server (requires mcp installed in the interpreter that runs the server):

from mcp_tuning import connect_stdio

c = connect_stdio([".venv/Scripts/python.exe", "examples/servers/simple_stdio_server.py"])
print([t.name for t in c.tools()])
print(c.call("add", {"a": 1, "b": 2}).result)
c.close()

Public API Reference

The public API is intentionally small and exported at the top-level mcp_tuning package.

Connect functions

  • connect_stdio(command, *, cwd=None, env=None) -> Client
    • command: list[str] (recommended) or str
    • defaults to running the subprocess with the repo root as cwd (more reliable in notebooks)
  • connect_http(rpc_url, *, headers=None) -> Client
  • connect_sse(*, sse_url, rpc_url, headers=None) -> Client

Client

Client (alias: MCPClient) is the main entry point for notebooks and scripts.

  • Lifecycle

    • close()
    • server_info() -> dict | None
  • Explore

    • tools(timeout_s=30) -> list[ToolItem]
    • tool(name, timeout_s=30) -> ToolItem | None
    • resources(timeout_s=30) -> list[ResourceItem]
    • read_resource(uri, timeout_s=60) -> Any
    • prompts(timeout_s=30) -> list[PromptItem]
    • get_prompt(name, arguments=None, timeout_s=60) -> Any
  • Call

    • call(name, arguments=None, timeout_s=60) -> CallResult
    • last() -> CallResult | None
  • Rendering (notebook-friendly)

    • show(obj, mode='auto'|'json'|'text'|'markdown', compact=True, max_depth=5, max_items=60) -> None
    • dumps(obj, compact=True, max_depth=5, max_items=60) -> str
  • Cases (input-only: tool + args)

    • save_case(tool, arguments, note=None, root=None) -> Path
    • cases(root=None) -> list[Path]
    • load_case(path) -> CallCase
    • replay_case(case, timeout_s=60) -> CallResult
    • replay_case_path(path, timeout_s=60) -> CallResult
  • Exports

    • export_logs(root=None) -> Path
    • export_history(root=None) -> Path
    • export_last(root=None) -> Path

Models (data types)

The following types are also exported for type hints and inspection:

  • ToolItem, ResourceItem, PromptItem
  • CallCase (stores tool + args + metadata)
  • CallResult (includes ok/result/error/stderr_tail/ts)
  • LogEvent

Files & Folders

  • examples/notebooks/: example notebooks (script-first)
  • examples/servers/: example MCP servers
  • docs/: detailed documentation (start at docs/index.md)
  • cases/: saved cases (*.json)
  • exports/: exported logs/history/results (*.json)

Troubleshooting

  • Timeouts usually mean the server did not start correctly (missing deps, wrong executable, wrong paths).
    • For the FastMCP example, run the server with .venv/Scripts/python.exe.
  • Notebook working directories are often not the repo root; this library defaults stdio subprocess cwd to the repo root.
  • On timeouts, the error message includes a stderr tail (stdio) to help you debug server startup failures.

Tests

python -m pytest

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

mcp_tuning-0.1.0.tar.gz (108.1 kB view details)

Uploaded Source

Built Distribution

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

mcp_tuning-0.1.0-py3-none-any.whl (26.9 kB view details)

Uploaded Python 3

File details

Details for the file mcp_tuning-0.1.0.tar.gz.

File metadata

  • Download URL: mcp_tuning-0.1.0.tar.gz
  • Upload date:
  • Size: 108.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.13 {"installer":{"name":"uv","version":"0.9.13"},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for mcp_tuning-0.1.0.tar.gz
Algorithm Hash digest
SHA256 a43a89a749965d46ea35c87bc3f43e43b8dbc049ee48ebd088f1d0350897d7d5
MD5 2e3063d24ae66f95a3bf0d852537b49c
BLAKE2b-256 0fc467c49341970b3300c70607fe5a8e5747c2abff2425b84a88ec88fea4b32f

See more details on using hashes here.

File details

Details for the file mcp_tuning-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: mcp_tuning-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 26.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.13 {"installer":{"name":"uv","version":"0.9.13"},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for mcp_tuning-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2e45b8e1b413401c59f448761fdaa5d8ae56c13369b84661e6e98769357c314f
MD5 c8d5d8064e5c66b54c8deeb45d5e1230
BLAKE2b-256 3b0ec73fd91780b8b60f304473343901cc2050b149432f6501bae9b8172aef6c

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