Skip to content

Commit 4b9203e

Browse files
committed
fix readme, add docs
1 parent cc2259a commit 4b9203e

File tree

7 files changed

+249
-27
lines changed

7 files changed

+249
-27
lines changed

.github/worflows/ci.yml

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
name: CI
2+
on:
3+
push:
4+
branches:
5+
- main
6+
tags:
7+
- "**"
8+
pull_request: {}
9+
10+
env:
11+
COLUMNS: 150
12+
UV_PYTHON: 3.13
13+
UV_FROZEN: "1"
14+
15+
jobs:
16+
lint:
17+
runs-on: ubuntu-latest
18+
steps:
19+
- uses: actions/checkout@v4
20+
21+
- uses: astral-sh/setup-uv@v6
22+
with:
23+
enable-cache: true
24+
- run: uv sync
25+
26+
- uses: denoland/setup-deno@v2
27+
with:
28+
deno-version: v2.x
29+
30+
- uses: actions/cache@v4
31+
with:
32+
path: ~/.cache/pre-commit
33+
key: pre-commit|${{ env.UV_PYTHON }}|${{ hashFiles('.pre-commit-config.yaml') }}
34+
35+
- run: uvx pre-commit run --color=always --all-files --verbose
36+
env:
37+
SKIP: no-commit-to-branch
38+
39+
test:
40+
name: test py${{ matrix.python-version }}
41+
strategy:
42+
fail-fast: false
43+
matrix:
44+
python-version: ["3.10", "3.11", "3.12", "3.13"]
45+
env:
46+
UV_PYTHON: ${{ matrix.python-version }}
47+
runs-on: ubuntu-latest
48+
steps:
49+
- uses: actions/checkout@v4
50+
- uses: astral-sh/setup-uv@v6
51+
with:
52+
enable-cache: true
53+
- run: uv sync
54+
- run: make test
55+
env:
56+
COVERAGE_FILE: coverage/.coverage.py${{ matrix.python-version }}
57+
- name: store coverage files
58+
uses: actions/upload-artifact@v4
59+
with:
60+
name: coverage-${{ matrix.python-version }}
61+
path: coverage
62+
include-hidden-files: true
63+
64+
coverage:
65+
runs-on: ubuntu-latest
66+
needs: [test]
67+
steps:
68+
- name: get coverage files
69+
uses: actions/download-artifact@v4
70+
with:
71+
merge-multiple: true
72+
path: coverage
73+
- uses: astral-sh/setup-uv@v6
74+
with:
75+
enable-cache: true
76+
- run: uvx coverage combine coverage
77+
- run: uvx coverage report --fail-under 90
78+
79+
check:
80+
if: always()
81+
needs: [lint, test, coverage]
82+
runs-on: ubuntu-latest
83+
steps:
84+
- uses: re-actors/alls-green@release/v1
85+
with:
86+
jobs: ${{ toJSON(needs) }}
87+
88+
release:
89+
needs: [check]
90+
if: success() && startsWith(github.ref, 'refs/tags/')
91+
runs-on: ubuntu-latest
92+
environment:
93+
name: release
94+
url: https://pypi.org/project/mcp-run-python/${{ steps.check-package-version.outputs.VERSION }}
95+
permissions:
96+
id-token: write
97+
outputs:
98+
package-version: ${{ steps.check-python-version.outputs.VERSION }}
99+
steps:
100+
- uses: actions/checkout@v4
101+
102+
- uses: astral-sh/setup-uv@v6
103+
with:
104+
enable-cache: true
105+
106+
- id: check-package-version
107+
uses: samuelcolvin/check-python-version@v5
108+
with:
109+
version_file_path: packages/python/pyproject.toml
110+
111+
- run: uv build
112+
113+
- run: uv publish --trusted-publishing always

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,9 @@ typecheck-py: ## Typecheck the code
5757
typecheck: typecheck-ts typecheck-py ## Typecheck all code
5858

5959
.PHONY: test
60-
test: ## Run tests
60+
test: ## Run tests and collect coverage data
6161
uv run coverage run -m pytest
62+
@uv run coverage report
6263

6364
.PHONY: all
6465
all: format typecheck test ## run format, typecheck and test

README.md

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,57 +7,40 @@ the rest of the operating system.
77

88
**See <https://ai.pydantic.dev/mcp/run-python/> for complete documentation.**
99

10-
The server can be run with `deno` installed using:
10+
To use this server, you must have both Python and [Deno](https://deno.com/) installed
11+
12+
The server can be run with `deno` installed using `uvx`:
1113

1214
```bash
13-
deno run \
14-
-N -R=node_modules -W=node_modules --node-modules-dir=auto \
15-
jsr:@pydantic/mcp-run-python [stdio|streamable_http|sse|warmup]
15+
uvx mcp-run-python [stdio|streamable-http|warmup]
1616
```
1717

1818
where:
1919

20-
- `-N -R=node_modules -W=node_modules` (alias of `--allow-net --allow-read=node_modules --allow-write=node_modules`)
21-
allows network access and read+write access to `./node_modules`. These are required so pyodide can download and cache
22-
the Python standard library and packages
23-
- `--node-modules-dir=auto` tells deno to use a local `node_modules` directory
2420
- `stdio` runs the server with the
2521
[Stdio MCP transport](https://modelcontextprotocol.io/specification/2025-06-18/basic/transports#stdio) — suitable for
2622
running the process as a subprocess locally
27-
- `streamable_http` runs the server with the
23+
- `streamable-http` runs the server with the
2824
[Streamable HTTP MCP transport](https://modelcontextprotocol.io/specification/2025-06-18/basic/transports#streamable-http) -
2925
suitable for running the server as an HTTP server to connect locally or remotely. This supports stateful requests, but
3026
does not require the client to hold a stateful connection like SSE
31-
- `sse` runs the server with the
32-
[SSE MCP transport](https://modelcontextprotocol.io/specification/2024-11-05/basic/transports#http-with-sse)
33-
suitable for running the server as an HTTP server to connect locally or remotely. Note that the SSE transport has been
34-
[deprecated in newer MCP protocol versions](https://modelcontextprotocol.io/specification/2025-06-18/basic/transports#backwards-compatibility)
35-
and is there to maintain backwards compatibility.
3627
- `warmup` will run a minimal Python script to download and cache the Python standard library. This is also useful to
3728
check the server is running correctly.
3829

39-
Here's an example of using `@pydantic/mcp-run-python` with Pydantic AI:
30+
Here's an example of using `mcp-run-python` with Pydantic AI:
4031

4132
```python
4233
from pydantic_ai import Agent
4334
from pydantic_ai.mcp import MCPServerStdio
35+
from mcp_run_python import deno_args
4436

4537
import logfire
4638

4739
logfire.configure()
4840
logfire.instrument_mcp()
4941
logfire.instrument_pydantic_ai()
5042

51-
server = MCPServerStdio('deno',
52-
args=[
53-
'run',
54-
'-N',
55-
'-R=node_modules',
56-
'-W=node_modules',
57-
'--node-modules-dir=auto',
58-
'jsr:@pydantic/mcp-run-python',
59-
'stdio',
60-
])
43+
server = MCPServerStdio('deno', args=deno_args('stdio'))
6144
agent = Agent('claude-3-5-haiku-latest', toolsets=[server])
6245

6346

mcp_run_python/py.typed

Whitespace-only changes.

pydantic_ai_example.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# /// script
2+
# requires-python = ">=3.13"
3+
# dependencies = [
4+
# "logfire",
5+
# "mcp-run-python",
6+
# "pydantic-ai-slim[mcp,anthropic]",
7+
# ]
8+
#
9+
# [tool.uv.sources]
10+
# mcp-run-python = { path = "." }
11+
# ///
12+
import logfire
13+
from pydantic_ai import Agent
14+
from pydantic_ai.mcp import MCPServerStdio
15+
16+
from mcp_run_python import deno_args
17+
18+
logfire.configure()
19+
logfire.instrument_mcp()
20+
logfire.instrument_pydantic_ai()
21+
22+
server = MCPServerStdio('deno', args=deno_args('stdio'))
23+
agent_with_python = Agent('claude-3-5-haiku-latest', toolsets=[server])
24+
25+
26+
async def main():
27+
async with agent_with_python:
28+
result = await agent_with_python.run('How many days between 2000-01-01 and 2025-03-18?')
29+
print(result.output)
30+
# > There are 9,208 days between January 1, 2000, and March 18, 2025.w
31+
32+
33+
if __name__ == '__main__':
34+
import asyncio
35+
36+
asyncio.run(main())

pyproject.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ Changelog = "https://github.com/pydantic/mcp-run-python/releases"
3838
[tool.uv.build-backend]
3939
module-name = "mcp_run_python"
4040
module-root = ""
41-
41+
source-exclude = ["node_modules"]
42+
wheel-exclude = ["node_modules"]
4243

4344
[dependency-groups]
4445
dev = [
@@ -51,6 +52,7 @@ dev = [
5152
"pytest>=8.3.3",
5253
"pytest-pretty>=1.2.0",
5354
"ruff>=0.12.11",
55+
"coverage>=7.10.6",
5456
]
5557

5658
[project.scripts]

0 commit comments

Comments
 (0)