Skip to content

Commit 62c5688

Browse files
committed
improve docs
1 parent 4b9203e commit 62c5688

File tree

4 files changed

+43
-10
lines changed

4 files changed

+43
-10
lines changed

README.md

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,33 @@
1-
# MCP Run Python
1+
<div align="center">
2+
<h1>MCP Run Python</h1>
3+
</div>
4+
<div align="center">
5+
<a href="https://github.com/pydantic/mcp-run-python/actions/workflows/ci.yml?query=branch%3Amain"><img src="https://github.com/pydantic/mcp-run-python/actions/workflows/ci.yml/badge.svg?event=push" alt="CI"></a>
6+
<a href="https://pypi.python.org/pypi/mcp-run-python"><img src="https://img.shields.io/pypi/v/mcp-run-python.svg" alt="PyPI"></a>
7+
<a href="https://github.com/pydantic/mcp-run-python"><img src="https://img.shields.io/pypi/pyversions/mcp-run-python.svg" alt="versions"></a>
8+
<a href="https://github.com/pydantic/mcp-run-python/blob/main/LICENSE"><img src="https://img.shields.io/github/license/pydantic/mcp-run-python.svg" alt="license"></a>
9+
<a href="https://logfire.pydantic.dev/docs/join-slack/"><img src="https://img.shields.io/badge/Slack-Join%20Slack-4A154B?logo=slack" alt="Join Slack" /></a>
10+
</div>
11+
<br/>
12+
<div align="center">
13+
MCP server to run Python code in a sandbox.
14+
</div>
15+
<br/>
16+
17+
Code is executed using [Pyodide](https://pyodide.org) in [Deno](https://deno.com/) and is therefore isolated from
18+
the rest of the operating system.
219

3-
[Model Context Protocol](https://modelcontextprotocol.io/) server to run Python code in a sandbox.
20+
## Features
421

5-
The code is executed using [Pyodide](https://pyodide.org) in [Deno](https://deno.com/) and is therefore isolated from
6-
the rest of the operating system.
22+
- **Secure Execution**: Run Python code in a sandboxed WebAssembly environment
23+
- **Package Management**: Automatically detects and installs required dependencies
24+
- **Complete Results**: Captures standard output, standard error, and return values
25+
- **Asynchronous Support**: Runs async code properly
26+
- **Error Handling**: Provides detailed error reports for debugging
727

8-
**See <https://ai.pydantic.dev/mcp/run-python/> for complete documentation.**
28+
## Usage
929

10-
To use this server, you must have both Python and [Deno](https://deno.com/) installed
30+
To use this server, you must have both Python and [Deno](https://deno.com/) installed.
1131

1232
The server can be run with `deno` installed using `uvx`:
1333

@@ -54,3 +74,11 @@ if __name__ == '__main__':
5474
import asyncio
5575
asyncio.run(main())
5676
```
77+
78+
## Logging
79+
80+
MCP Run Python supports emitting stdout and stderr from the python execution as [MCP logging messages](https://github.com/modelcontextprotocol/specification/blob/eb4abdf2bb91e0d5afd94510741eadd416982350/docs/specification/draft/server/utilities/logging.md?plain=1).
81+
82+
For logs to be emitted you must set the logging level when connecting to the server. By default, the log level is set to the highest level, `emergency`.
83+
84+
Currently, it's not possible to demonstrate this due to a bug in the Python MCP Client, see [modelcontextprotocol/python-sdk#201](https://github.com/modelcontextprotocol/python-sdk/issues/201#issuecomment-2727663121).

mcp_run_python/_cli.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,17 @@ def cli_logic(args_list: Sequence[str] | None = None) -> int:
2121
)
2222
parser.add_argument('--version', action='store_true', help='Show version and exit')
2323

24+
parser.add_argument('--port', type=int, help='Port to run the server on.')
2425
parser.add_argument(
2526
'mode',
26-
choices=['stdio', 'streamable-http', 'http', 'warmup'],
27-
help='Mode to run in ("http" is an alias for "streamable-http")',
27+
choices=['stdio', 'streamable-http', 'warmup'],
28+
help='Mode to run the server in.',
2829
)
2930

3031
args = parser.parse_args(args_list)
3132
if args.version:
3233
print(f'mcp-run-python {__version__}')
3334
return 0
3435
else:
35-
run_deno_server(args.mode.replace('-', '_'))
36+
run_deno_server(args.mode.replace('-', '_'), port=args.port)
3637
return 0

mcp_run_python/main.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,8 @@ def deno_args(mode: Mode, *, port: int | None = None) -> list[str]:
2626
mode,
2727
]
2828
if port is not None:
29-
args.append(f'--port={port}')
29+
if mode == 'streamable_http':
30+
args.append(f'--port={port}')
31+
else:
32+
raise ValueError('Port is only supported for `streamable_http` mode')
3033
return args

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ build-backend = "uv_build"
44

55
[project]
66
name = "mcp-run-python"
7+
description = "Model Context Protocol server to run Python code in a sandbox."
78
version = "0.0.1"
89
authors = [{ name = "Samuel Colvin", email = "samuel@pydantic.dev" }]
910
license = "MIT"

0 commit comments

Comments
 (0)