python-session-mcp
python-session-mcp
유지되는 세션에서 Python을 실행하고 이를 Model Context Protocol을 통해 LLM 클라이언트에 노출합니다.
저자: Dr Merwan Roudane
차별점
세션이 유지됩니다. 한 호출에서 로드된 DataFrame은 다음 호출에도 그대로 남아 있으므로 분석을 매번 전체를 다시 보내는 대신 단계적으로 구축할 수 있습니다.
서버의 인터프리터가 아니라 사용자의 인터프리터입니다. 서버는 pandas가 없는 기본 Python 환경에 설치되어 있을 수 있습니다. 사용자 코드를 실행하는 인터프리터는 별도로 선택됩니다: conda 또는 Anaconda 설치가 있으면 우선 사용되며, PYTHON_MCP_INTERPRETER가 이를 재정의합니다.
충돌은 프로세스 하나의 비용만 발생합니다. 코드는 서버가 아닌 워커에서 실행됩니다. 메모리를 소진하거나, sys.exit를 호출하거나, C 확장을 충돌시켜도 워커가 교체되고 서버는 계속 실행됩니다. 또한 사용자 코드는 서버의 stdin에서 분리되는데, MCP에서 이 stdin은 JSON-RPC 스트림 자체입니다.
Related MCP server: mcp-python-repl
설치
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를 한 번에 |
| ADF 또는 KPSS, 정상성이 될 때까지 차분 |
차트
도구 | 용도 |
| line, scatter, hist, box 또는 bar — 선택적으로 파일로 직접 저장 |
| 열려 있는 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 deployed
Maintenance
Related MCP Connectors
Multiple MCP tools, persistent graph memory, token-saving data pointers, and more.
MCP server for building and testing AI agents with multi-model experimentation and insights.
Persistent memory and cross-session learning for AI coding assistants (hosted remote MCP).
MCP server for your apps' tools and custom tools, plus hosted AI agents and approval-gated workflows
Related MCP Servers
- 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.1235 PyPI1MIT
- 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
- AlicenseNot gradedqualityBmaintenanceEnables LLM agents to run persistent Python code in a workspace-scoped shared kernel, with tools for execution, background tasks, file operations, and external MCP integrations.AGPL 3.0