Python notebook mcp
Python notebook mcp
README
<div align="center"> <h1>Python Notebook MCP</h1> <p>MCP server enabling AI assistants to interact with Jupyter notebooks through the Model Context Protocol.</p> <p> <a href="LICENSE"><img src="https://img.shields.io/badge/License-MIT-blue.svg" alt="MIT License"/></a> <img src="https://img.shields.io/badge/Python-3.10+-blue.svg" alt="Python 3.10+"/> <img src="https://img.shields.io/badge/MCP-Compatible-orange.svg" alt="MCP Compatible"/> </p> </div>
This server allows compatible AI assistants (like Cursor or Claude Desktop) to interact with Jupyter Notebook files (.ipynb) on your local machine.
📋 Prerequisites
Before you begin, ensure you have the following installed:
- Python: Version 3.10 or higher.
uv: The fast Python package installer and virtual environment manager from Astral. If you don't have it, install it:# On macOS / Linux curl -LsSf https://astral.sh/uv/install.sh | sh # On Windows (PowerShell) powershell -c "irm https://astral.sh/uv/install.ps1 | iex" # IMPORTANT: Add uv to your PATH if prompted by the installer # For macOS/Linux (bash/zsh), add to your ~/.zshrc or ~/.bashrc: # export PATH="$HOME/.local/bin:$PATH" # Then restart your shell or run `source ~/.zshrc` (or equivalent)fastmcpCLI (Optional, for Claude Desktopfastmcp install): If you plan to use thefastmcp installmethod for Claude Desktop, you need thefastmcpcommand available.# Using uv uv pip install fastmcp # Or using pipx (recommended for CLI tools) pipx install fastmcp
🔧 Setup
-
Clone the Repository:
git clone https://github.com/UsamaK98/python-notebook-mcp.git # Or your fork/local path cd python-notebook-mcp -
Choose Setup Method:
-
Option A: Automated Setup (Recommended) Run the appropriate script for your OS from the project's root directory (where you just
cd-ed into).- macOS / Linux:
# Make script executable (if needed) chmod +x ./install_unix.sh # Run the script bash ./install_unix.sh - Windows (PowerShell):
# You might need to adjust PowerShell execution policy first # Set-ExecutionPolicy RemoteSigned -Scope CurrentUser .\install_windows.ps1
These scripts will create the
.venv, install dependencies, and output the exact paths needed for your MCP client configuration. - macOS / Linux:
-
Option B: Manual Setup Follow these steps if you prefer manual control or encounter issues with the scripts.
- Create & Activate Virtual Environment:
(You should see# Create the environment (e.g., named .venv) uv venv # Activate the environment # On macOS/Linux (bash/zsh): source .venv/bin/activate # On Windows (Command Prompt): # .venv\Scripts\activate.bat # On Windows (PowerShell): # .venv\Scripts\Activate.ps1(.venv)or similar at the start of your shell prompt) - Install Dependencies:
# Make sure your venv is active uv pip install -r requirements.txt
- Create & Activate Virtual Environment:
-
▶️ Running the Server
Make sure your virtual environment (.venv) is activated if you used manual setup.
Method 1: Direct Execution (Recommended for Cursor, General Use)
This method uses uv run to execute the server script directly using your current Python environment (which should now have the dependencies installed).
-
Run the Server:
# From the python-notebook-mcp directory uv run python server.pyThe server will start and print status messages, including the (uninitialized) workspace directory.
-
Client Configuration (
mcp.json): Configure your MCP client (e.g., Cursor) to connect. Create or edit the client's MCP configuration file (e.g.,.cursor/mcp.jsonin your workspace).Template (Recommended):
{ "mcpServers": { "jupyter": { // Use the absolute path to the Python executable inside your .venv "command": "/full/absolute/path/to/python-notebook-mcp/.venv/bin/python", // macOS/Linux // "command": "C:\\full\\absolute\\path\\to\\python-notebook-mcp\\.venv\\Scripts\\python.exe", // Windows "args": [ // Absolute path to the server script "/full/absolute/path/to/python-notebook-mcp/server.py" ], "autoApprove": ["initialize_workspace"] // Optional: Auto-approve certain safe tools } } }❓ Why the full path to Python? GUI applications like Cursor might not inherit the same
PATHenvironment as your terminal. Specifying the exact path to the Python interpreter inside your.venvensures the server runs with the correct environment and dependencies. ⚠️ IMPORTANT: Replace the placeholder paths with the actual absolute paths on your system.
Method 2: Claude Desktop Integration (fastmcp install)
This method uses the fastmcp tool to create a dedicated, isolated environment for the server and register it with Claude Desktop. You generally don't need to activate the .venv manually for this method, as fastmcp install handles environment creation.
- Install the Server for Claude:
# From the python-notebook-mcp directory fastmcp install server.py --name "Jupyter Notebook MCP"fastmcp installusesuvbehind the scenes to create the environment and install dependencies fromrequirements.txt.- The server will now appear in the Claude Desktop developer settings and can be enabled there. You generally don't need to manually edit
claude_desktop_config.jsonwhen usingfastmcp install.
📘 Usage
Key Concept: Workspace Initialization
Regardless of how you run the server, the first action you must take from your AI assistant is to initialize the workspace. This tells the server where your project files and notebooks are located.
# Example tool call from the client (syntax may vary)
initialize_workspace(directory="/full/absolute/path/to/your/project_folder")
⚠️ You must provide the full absolute path to the directory containing your notebooks. Relative paths or paths like
.are not accepted. The server will confirm the path and list any existing notebooks found.
Core Operations
Once the workspace is initialized, you can use the available tools:
# List notebooks
list_notebooks()
# Create a new notebook
create_notebook(filepath="analysis/new_analysis.ipynb", title="My New Analysis")
# Add a code cell to the notebook
add_cell(filepath="analysis/new_analysis.ipynb", content="import pandas as pd\ndf = pd.DataFrame({'col1': [1, 2], 'col2': [3, 4]})\ndf.head()", cell_type="code")
# Read the first cell (index 0)
read_cell(filepath="analysis/new_analysis.ipynb", cell_index=0)
# Edit the second cell (index 1)
edit_cell(filepath="analysis/new_analysis.ipynb", cell_index=1, content="# This is updated markdown")
# Read the output of the second cell (index 1) after execution (if any)
read_cell_output(filepath="analysis/new_analysis.ipynb", cell_index=1)
# Read the entire notebook structure
read_notebook(filepath="analysis/new_analysis.ipynb")
🛠️ Available Tools
| Tool | Description |
|---|---|
initialize_workspace |
REQUIRED FIRST STEP. Sets the absolute path for the workspace. |
list_notebooks |
Lists all .ipynb files found within the workspace directory. |
create_notebook |
Creates a new, empty Jupyter notebook if it doesn't exist. |
read_notebook |
Reads the entire structure and content of a notebook. |
read_cell |
Reads the content and metadata of a specific cell by index. |
edit_cell |
Modifies the source content of an existing cell by index. |
add_cell |
Adds a new code or markdown cell at a specific index or the end. |
read_notebook_outputs |
Reads all outputs from all code cells in a notebook. |
read_cell_output |
Reads the output(s) of a specific code cell by index. |
🧪 Development & Debugging
If you need to debug the server itself:
- Run Directly: Use
uv run python server.pyand observe the terminal output for errors or print statements. - FastMCP Dev Mode: For interactive testing with the MCP Inspector:
# Make sure fastmcp is installed in your environment # uv pip install fastmcp uv run fastmcp dev server.py
📄 License
This project is licensed under the MIT License - see the LICENSE file for details.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。