mcp-run-python

Official

hybrid server

The server is able to function both locally and remotely, depending on the configuration or use case.

Integrations

  • Provides the ability to execute Python code in a sandboxed environment using pyodide, allowing safe Python code execution isolated from the operating system.

MCP Python 実行

サンドボックス内で Python コードを実行するためのモデル コンテキスト プロトコルサーバー。

コードはDeno内でPyodideを使用して実行されるため、オペレーティング システムの残りの部分から分離されます。

完全なドキュメントについては、 https://ai.pydantic.dev/mcp/run-python/を参照してください。

denoをインストールした状態でサーバーを実行するには、次のコマンドを使用します。

deno run \ -N -R=node_modules -W=node_modules --node-modules-dir=auto \ jsr:@pydantic/mcp-run-python [stdio|sse|warmup]

どこ:

  • -N -R=node_modules -W=node_modules--allow-net --allow-read=node_modules --allow-write=node_modulesのエイリアス)は、 ./node_modulesへのネットワークアクセスと読み取り/書き込みアクセスを許可します。これらは、pyodide が Python 標準ライブラリとパッケージをダウンロードしてキャッシュするために必要です。
  • --node-modules-dir=auto deno にローカルのnode_modulesディレクトリを使用するように指示します。
  • stdioStdio MCPトランスポートを使用してサーバーを実行します。プロセスをローカルでサブプロセスとして実行するのに適しています。
  • sseSSE MCPトランスポートを使用してサーバーを実行します。サーバーをHTTPサーバーとして実行し、ローカルまたはリモートで接続します。
  • warmup 、Python標準ライブラリをダウンロードしてキャッシュするための最小限のPythonスクリプトを実行します。これは、サーバーが正しく動作しているかどうかを確認するのにも役立ちます。

PydanticAI で@pydantic/mcp-run-python使用する例を次に示します。

from pydantic_ai import Agent from pydantic_ai.mcp import MCPServerStdio import logfire logfire.configure() logfire.instrument_mcp() logfire.instrument_pydantic_ai() server = MCPServerStdio('deno', args=[ 'run', '-N', '-R=node_modules', '-W=node_modules', '--node-modules-dir=auto', 'jsr:@pydantic/mcp-run-python', 'stdio', ]) agent = Agent('claude-3-5-haiku-latest', mcp_servers=[server]) async def main(): async with agent.run_mcp_servers(): result = await agent.run('How many days between 2000-01-01 and 2025-03-18?') print(result.output) #> There are 9,208 days between January 1, 2000, and March 18, 2025.w if __name__ == '__main__': import asyncio asyncio.run(main())
-
security - not tested
A
license - permissive license
-
quality - not tested

サンドボックス内で Python コードを実行するためのモデル コンテキスト プロトコル サーバー。

ID: 2nc0ejepw0