python-session-mcp
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@python-session-mcpLoad macro.csv, run OLS of y on x and z, and show the summary."
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
python-session-mcp
Run Python in a session that stays alive, and expose it to LLM clients over the Model Context Protocol.
Author: Dr Merwan Roudane
What makes it different
The session persists. A DataFrame loaded in one call is still there in the next, so an analysis is built up in steps rather than resent whole each time.
Your interpreter, not the server's. The server may well be installed under
a bare Python with no pandas in it. The interpreter that runs your code is
chosen separately: a conda or Anaconda installation is preferred when one is
present, and PYTHON_MCP_INTERPRETER overrides that.
A crash costs one process. Code runs in a worker, not in the server. Exhaust
memory, call sys.exit, crash a C extension — the worker is replaced and the
server carries on. It also keeps user code away from the server's stdin, which
under MCP is the JSON-RPC stream itself.
Related MCP server: LLM Python Code Sandbox
Install
pip install python-session-mcpLibrary use
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 dictA final expression is shown the way a REPL would, so df.head() on its own
displays the frame without print().
MCP server use
{
"mcpServers": {
"python": {
"command": "python-session-mcp",
"env": { "PYTHON_MCP_INTERPRETER": "C:\\Users\\you\\anaconda3\\python.exe" }
}
}
}Tools
Session
Tool | Purpose |
| Which interpreter, and which packages it actually has |
| Forget everything, optionally restarting the interpreter |
Running code
Tool | Purpose |
| Main tool. Run code in the persistent session |
| What is currently defined |
| Type, shape, dtypes and a peek at one object |
| Bring a JSON-representable value back |
Data
Tool | Purpose |
| Read |
| Write a DataFrame out, creating missing folders |
| Shape, dtypes, missing counts and the first rows |
| Descriptives with skew and kurtosis |
| Pearson, Spearman or Kendall |
Estimation
Tool | Purpose |
| OLS, optionally with HC or HAC standard errors |
| Breusch-Godfrey, White and Jarque-Bera in one call |
| ADF or KPSS, differencing until stationary |
Charts
Tool | Purpose |
| line, scatter, hist, box or bar — optionally straight to a file |
| Write the open matplotlib figure to a file |
Errors
Failures name the exception and the line of your code, and leave the session intact:
Python error: NameError on line 2: name 'undefined_name' is not definedAnything printed before the failure is reported with it, since that output is often what explains the failure.
Figures
A plot cannot come back as text. Draw it, then save it:
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 createdWorth knowing
The interpreter is separate from the server's. Check
python_statusbefore relying on a package being there.State is a convenience and a hazard. Names persist, so a stale variable from an earlier step can quietly feed a later one.
reset_namespacewhen starting something new.run_pythonexecutes whatever it is given, in your environment, with your file access. That is the point of it, and worth being deliberate about.The final expression is echoed. A long DataFrame will print in full unless you slice it.
Tests
python tests/test_live.py # 41 testsThey cover persistence, error reporting with line numbers, JSON round trips, figure writing, recovery after user code kills the worker outright, and every data and estimation tool against generated data with known coefficients.
Checked against EViews on the same data, the regression agrees to every printed digit -- coefficients, R-squared, Durbin-Watson, and the Breusch-Godfrey and Jarque-Bera statistics alike.
Licence
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