Skip to main content

MCP (Model Context Protocol) Server for py4agent - Provides code execution capabilities through Jupyter kernels

Project description

py4agent-mcp

MCP (Model Context Protocol) Server for py4agent - Provides code execution capabilities through Jupyter kernels.

Features

  • Isolated Python Runtimes: Create and manage independent Python execution environments
  • MCP Protocol Integration: Seamless integration with Model Context Protocol
  • Jupyter Kernel Backend: Powered by Jupyter Server's kernel management
  • Multi-modal Output: Support for text, tables, plots, and images
  • Background Execution: Async code execution for long-running operations
  • Runtime Persistence: Automatic save/restore of runtime configurations

Installation

This project is part of a monorepo. Install dependencies:

# Install py4agent (required dependency)
pip install py4agent

# Install py4agent-mcp
cd py4agent-mcp
pip install -e .

For development setup, see INSTALL.md.

Usage

Start the MCP Server

# Start with default settings (127.0.0.1:8889)
py4agent-mcp

# Custom host and port
py4agent-mcp --host 0.0.0.0 --port 9000

# Enable debug logging
py4agent-mcp --debug

# Save logs to file
py4agent-mcp --log-dir ./logs

Command Line Options

  • --host: Host to bind (default: 127.0.0.1)
  • --port: Port to bind (default: 8889)
  • --debug: Enable debug logging
  • --workers: Number of worker processes (must be 1 for MCP)
  • --log-dir: Directory to store logs (optional)

Python API

from py4agent_mcp import create_app, create_mcp_app, main
from py4agent_mcp.mcp_server import JupyterKernelManager

# Create FastAPI app with MCP mounted
app = create_app()

# Create MCP server app
mcp_app = create_mcp_app()

# Run the server
main()

MCP Tools

The server exposes the following MCP tools:

  1. create_runtime: Create a new isolated Python runtime
  2. list_runtimes: List all active runtimes
  3. delete_runtime: Delete a runtime and free resources
  4. restart_runtime: Restart a runtime (clears state)
  5. interrupt_runtime: Interrupt running code (Ctrl+C)
  6. get_runtime_status: Get runtime status information
  7. execute_code: Execute Python code in a runtime

Project Structure

py4agent-mcp/
├── py4agent_mcp/           # Package directory
│   ├── __init__.py         # Package exports
│   └── mcp_server.py       # Main MCP server implementation
├── pyproject.toml          # Project configuration
├── README.md
├── INSTALL.md
├── CHANGES.md
└── test_install.sh

Architecture

  • Built on FastAPI and FastMCP
  • Uses Jupyter Server's AsyncMappingKernelManager
  • Runtime configurations persist across server restarts
  • Single-worker mode required for MCP SSE (Server-Sent Events)
  • Depends on py4agent for code execution parsing
  • Organized as a proper Python package for clean imports

Requirements

  • Python >= 3.9
  • py4agent >= 0.0.3
  • FastAPI
  • FastMCP
  • Jupyter Server >= 2.0.0
  • Jupyter Client >= 8.0.0

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

py4agent_mcp-0.1.1.tar.gz (11.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

py4agent_mcp-0.1.1-py3-none-any.whl (11.2 kB view details)

Uploaded Python 3

File details

Details for the file py4agent_mcp-0.1.1.tar.gz.

File metadata

  • Download URL: py4agent_mcp-0.1.1.tar.gz
  • Upload date:
  • Size: 11.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.11.5 Darwin/25.2.0

File hashes

Hashes for py4agent_mcp-0.1.1.tar.gz
Algorithm Hash digest
SHA256 4d680e69d0d022f86084a04922a8d7b40ed0abef2f9a4793275e5c0c2e8fb5a4
MD5 318a4d9d8f21a2b7b03b7431b9d32231
BLAKE2b-256 f7b2f0ca76739f020f394dd7a1168c1f514531c7c5a773eda4d1d618dd988a37

See more details on using hashes here.

File details

Details for the file py4agent_mcp-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: py4agent_mcp-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 11.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.11.5 Darwin/25.2.0

File hashes

Hashes for py4agent_mcp-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5305e3b0eed08836083b17225b104f5dad03fbd6250eb3be425891f81e4cdabe
MD5 eeb191fd7da0b272d81d61f8fbe900cd
BLAKE2b-256 0ad599f896d6f3ca7c49e15301a7db778852da910ecebde6e8a33737079295c0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page