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, orsse - 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) -> Clientcommand:list[str](recommended) orstr- defaults to running the subprocess with the repo root as
cwd(more reliable in notebooks)
connect_http(rpc_url, *, headers=None) -> Clientconnect_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 | Noneresources(timeout_s=30) -> list[ResourceItem]read_resource(uri, timeout_s=60) -> Anyprompts(timeout_s=30) -> list[PromptItem]get_prompt(name, arguments=None, timeout_s=60) -> Any
-
Call
call(name, arguments=None, timeout_s=60) -> CallResultlast() -> CallResult | None
-
Rendering (notebook-friendly)
show(obj, mode='auto'|'json'|'text'|'markdown', compact=True, max_depth=5, max_items=60) -> Nonedumps(obj, compact=True, max_depth=5, max_items=60) -> str
-
Cases (input-only: tool + args)
save_case(tool, arguments, note=None, root=None) -> Pathcases(root=None) -> list[Path]load_case(path) -> CallCasereplay_case(case, timeout_s=60) -> CallResultreplay_case_path(path, timeout_s=60) -> CallResult
-
Exports
export_logs(root=None) -> Pathexport_history(root=None) -> Pathexport_last(root=None) -> Path
Models (data types)
The following types are also exported for type hints and inspection:
ToolItem,ResourceItem,PromptItemCallCase(stores tool + args + metadata)CallResult(includesok/result/error/stderr_tail/ts)LogEvent
Files & Folders
examples/notebooks/: example notebooks (script-first)examples/servers/: example MCP serversdocs/: detailed documentation (start atdocs/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.
- For the FastMCP example, run the server with
- Notebook working directories are often not the repo root; this library defaults stdio subprocess
cwdto 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a43a89a749965d46ea35c87bc3f43e43b8dbc049ee48ebd088f1d0350897d7d5
|
|
| MD5 |
2e3063d24ae66f95a3bf0d852537b49c
|
|
| BLAKE2b-256 |
0fc467c49341970b3300c70607fe5a8e5747c2abff2425b84a88ec88fea4b32f
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2e45b8e1b413401c59f448761fdaa5d8ae56c13369b84661e6e98769357c314f
|
|
| MD5 |
c8d5d8064e5c66b54c8deeb45d5e1230
|
|
| BLAKE2b-256 |
3b0ec73fd91780b8b60f304473343901cc2050b149432f6501bae9b8172aef6c
|