python-session-mcp
python-session-mcp
Python を存続し続けるセッション内で実行し、Model Context Protocol 経由で LLM クライアントに公開します。
著者: Dr Merwan Roudane
他と違う点
セッションは維持される。 ある呼び出しで読み込んだ DataFrame は次の呼び出しでもそのまま残るため、分析は毎回全体を送り直すのではなく、段階的に構築されます。
あなたのインタープリターであり、サーバーのものではない。 サーバーは、pandas が入っていない素の Python 環境にインストールされているかもしれません。コードを実行するインタープリターは別途選択されます。conda または Anaconda のインストールがあればそれが優先され、PYTHON_MCP_INTERPRETER で上書きできます。
クラッシュしても失われるのは1プロセスだけ。 コードはサーバーではなくワーカーで実行されます。メモリを使い果たしても、sys.exit を呼んでも、C 拡張がクラッシュしても、ワーカーは置き換えられ、サーバーは処理を続けます。また、ユーザーコードをサーバーの標準入力から遠ざけます。MCP では、その標準入力は JSON-RPC ストリームそのものです。
Related MCP server: LLM Python Code Sandbox
インストール
pip install python-session-mcpライブラリとしての利用
from python_mcp import PythonRunner
with PythonRunner() as py:
py.run("import pandas as pd, statsmodels.api as sm")
py.run("df = pd.read_csv('macro.csv')")
print(py.run("df.describe()"))
py.run("m = sm.OLS(df['y'], sm.add_constant(df[['x','z']])).fit()")
print(py.run("m.summary()"))
print(py.value("m.params.to_dict()")) # a real Python dict最後の式は REPL と同じように表示されるため、df.head() だけでも print() なしでフレームが表示されます。
MCP サーバーとしての利用
{
"mcpServers": {
"python": {
"command": "python-session-mcp",
"env": { "PYTHON_MCP_INTERPRETER": "C:\\Users\\you\\anaconda3\\python.exe" }
}
}
}ツール
セッション
ツール | 目的 |
| どのインタープリターか、そして実際にどのパッケージが入っているか |
| すべてを忘れさせる。オプションでインタープリターを再起動 |
コードの実行
ツール | 目的 |
| メインのツール。 永続セッションでコードを実行する |
| 現在定義されているもの |
| 型、形状、dtypes、およびオブジェクトの中身を覗き見 |
| JSON で表現可能な値を取得する |
データ
ツール | 目的 |
|
|
| DataFrame を書き出し、存在しないフォルダーを作成する |
| 形状、dtypes、欠損数、先頭行 |
| 歪度と尖度を含む記述統計 |
| Pearson、Spearman、または Kendall |
推定
ツール | 目的 |
| OLS。オプションで HC または HAC 標準誤差 |
| Breusch-Godfrey、White、Jarque-Bera を1回の呼び出しで |
| ADF または KPSS。定常になるまで差分を取る |
チャート
ツール | 目的 |
| 折れ線、散布、ヒストグラム、箱ひげ図、または棒グラフ — オプションでファイルに直接出力 |
| 開いている matplotlib の図をファイルに書き出す |
エラー
失敗時には、例外と あなたの コードの行が示され、セッションはそのまま維持されます:
Python error: NameError on line 2: name 'undefined_name' is not defined失敗前に出力されたものは、その失敗と一緒に報告されます。その出力が失敗の原因を説明していることが多いからです。
図
プロットはテキストとして返すことはできません。描画してから保存してください:
py.run("import matplotlib; matplotlib.use('Agg')")
py.run("import matplotlib.pyplot as plt; plt.plot(df['x'], df['y'], 'o')")
py.save_figure("figures/scatter.png") # missing folders are created知っておくべきこと
インタープリターはサーバーのものとは別です。 パッケージが存在することを前提にする前に
python_statusで確認してください。状態は便利であると同時に危険です。 名前は残り続けるため、前のステップの古い変数が、いつの間にか後のステップに使われることがあります。新しいことを始めるときは
reset_namespaceを使いましょう。run_pythonは与えられたものを何でも実行します。あなたの環境で、あなたのファイルアクセス権限で。それがこのツールの目的であり、意図的に使う価値があります。最後の式はエコーされます。 長い DataFrame は、スライスしない限り全体が表示されます。
テスト
python tests/test_live.py # 41 testsテストは、永続性、行番号付きのエラー報告、JSON ラウンドトリップ、図の書き出し、ユーザーコードがワーカーを完全に停止させた後の復旧、そして既知の係数を持つ生成データに対するすべてのデータ・推定ツールをカバーしています。
同じデータで EViews と照合したところ、回帰結果は表示されたすべての桁で一致しました。係数、R-squared、Durbin-Watson、そして Breusch-Godfrey と Jarque-Bera の統計量も同様です。
ライセンス
MIT. Copyright (c) 2026 Merwan Roudane.
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceProvides persistent IPython shell sessions per conversation with DataFrame-centric architecture, enabling stateful data analysis, CLI tool execution, and integration of external MCP servers within the same workspace context.23Apache 2.0
- FlicenseNot gradedqualityDmaintenanceEnables LLMs to execute Python code in isolated sandboxes with file operations and MCP integration, supporting multi-round execution and plot capture.1
- AlicenseAqualityDmaintenanceA production-grade MCP server providing a persistent Python REPL with multi-session support, sandboxing, and timeout protection, enabling LLM agents to execute Python code across multiple turns with variables that persist between calls.121MIT
- AlicenseNot gradedqualityDmaintenanceMCP server for secure, session-based Python code execution in Docker containers, enabling LLM applications to run code, manage state, and access files.9MIT
Related MCP Connectors
Persistent memory and cross-session learning for AI coding assistants (hosted remote MCP).
MCP server providing access to the Scorecard API to evaluate and optimize LLM systems.
MCP server exposing the Backtest360 engine API as tools for AI agents.
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/merwanroudane/mcp_python'
If you have feedback or need assistance with the MCP directory API, please join our Discord server