Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit87e0133

Browse files
authored
MCP server to run Python code in a sandbox (pydantic#1140)
1 parent80d5c07 commit87e0133

22 files changed

+3668
-6
lines changed

‎.github/workflows/ci.yml

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ jobs:
2929
-name:Install dependencies
3030
run:uv sync --all-extras --all-packages --group lint
3131

32+
-uses:actions/setup-node@v4
33+
34+
-run:npm install
35+
working-directory:mcp-run-python
36+
3237
-uses:pre-commit/action@v3.0.0
3338
with:
3439
extra_args:--all-files --verbose
@@ -215,10 +220,39 @@ jobs:
215220
-run:uv run coverage report --fail-under 95
216221
-run:uv run diff-cover coverage.xml --fail-under 100
217222

223+
test-mcp-run-python:
224+
runs-on:ubuntu-latest
225+
timeout-minutes:5
226+
env:
227+
UV_PYTHON:"3.12"
228+
steps:
229+
-uses:actions/checkout@v4
230+
231+
-uses:astral-sh/setup-uv@v5
232+
with:
233+
enable-cache:true
234+
235+
-uses:actions/setup-node@v4
236+
237+
-run:npm install
238+
working-directory:mcp-run-python
239+
240+
-run:npm run lint
241+
working-directory:mcp-run-python
242+
243+
-run:npm run prepare
244+
working-directory:mcp-run-python
245+
246+
-run:uv run --package mcp-run-python pytest mcp-run-python -v
247+
248+
# check npx works
249+
-run:npx . warmup
250+
working-directory:mcp-run-python
251+
218252
# https://github.com/marketplace/actions/alls-green#why used for branch protection checks
219253
check:
220254
if:always()
221-
needs:[lint, mypy, docs, test-live, test, coverage]
255+
needs:[lint, mypy, docs, test-live, test, coverage, test-mcp-run-python]
222256
runs-on:ubuntu-latest
223257

224258
steps:

‎.pre-commit-config.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ repos:
3232
types:[python]
3333
language:system
3434
pass_filenames:false
35+
-id:lint-js
36+
name:Lint JS
37+
entry:make
38+
args:[lint-js]
39+
language:system
40+
types_or:[javascript, ts, json]
41+
files:'^mcp-run-python/'
42+
pass_filenames:false
3543
-id:typecheck
3644
name:Typecheck
3745
entry:make

‎Makefile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ lint: ## Lint the code
2727
uv run ruff format --check
2828
uv run ruff check
2929

30+
.PHONY: lint-js
31+
lint-js:## Lint JS and TS code
32+
cd mcp-run-python&& npm run lint
33+
3034
.PHONY: typecheck-pyright
3135
typecheck-pyright:
3236
@# PYRIGHT_PYTHON_IGNORE_WARNINGS avoids the overhead of making a request to github on every invocation
@@ -62,6 +66,11 @@ testcov: test ## Run tests and generate a coverage report
6266
@echo"building coverage html"
6367
@uv run coverage html
6468

69+
.PHONY: test-mrp
70+
test-mrp:## Build and tests of mcp-run-python
71+
cd mcp-run-python&& npm run prepare
72+
uv run --package mcp-run-python pytest mcp-run-python -v
73+
6574
.PHONY: update-examples
6675
update-examples:## Update documentation examples
6776
uv run -m pytest --update-examples tests/test_examples.py

‎mcp-run-python/.prettierignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules/
2+
dist/

‎mcp-run-python/README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#MCP Run Python
2+
3+
[Model Context Protocol](https://modelcontextprotocol.io/) server to run Python code in a sandbox.
4+
5+
The code is executed using[pyodide](https://pyodide.org) in node and is therefore isolated from
6+
the rest of the operating system.
7+
8+
The server can be run with just npx thus:
9+
10+
```bash
11+
npx @pydantic/mcp-run-python [stdio|sse]
12+
```
13+
14+
where:
15+
16+
-`stdio` runs the server with the[Stdio MCP transport](https://modelcontextprotocol.io/docs/concepts/transports#standard-input%2Foutput-stdio) — suitable for running the process as a subprocess locally
17+
- and`sse` runs the server with the[SSE MCP transport](https://modelcontextprotocol.io/docs/concepts/transports#server-sent-events-sse) — running the server as an HTTP server to connect locally or remotely

‎mcp-run-python/cli.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env node
2+
3+
const{ main}=require('./dist/index.js')
4+
5+
main()

‎mcp-run-python/eslint.config.mjs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
importeslintfrom'@eslint/js'
2+
importtseslintfrom'typescript-eslint'
3+
4+
exportdefaulttseslint.config(eslint.configs.recommended,tseslint.configs.recommended)

‎mcp-run-python/inline_python.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// build dist/prepareEnvCode.js from src/prepare_env.py
2+
constfs=require('fs')
3+
constpath=require('path')
4+
5+
constsrc=path.resolve(__dirname,'src/prepare_env.py')
6+
constdst=path.resolve(__dirname,'dist/prepareEnvCode.js')
7+
8+
constpythonCode=fs.readFileSync(src,'utf8').replace(/\\n/g,'\\\\n')
9+
constjsCode=`// DO NOT EDIT THIS FILE DIRECTLY, INSTEAD RUN "npm run build"
10+
"use strict";
11+
Object.defineProperty(exports, "__esModule", { value: true });
12+
exports.preparePythonCode = \`${pythonCode}\`
13+
`
14+
15+
fs.writeFileSync(dst,jsCode,'utf8')

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp