--- title: PyMCP emoji: 🔥 colorFrom: pink colorTo: yellow sdk: docker pinned: true license: mit short_description: A powerful MCP server for AI agents to run Python code. tags: - building-mcp-track-enterprise - building-mcp-track-consumer - building-mcp-track-creative ---
|
PyMCP
A powerful MCP server for AI agents that uses Docker sandboxing to
securely run Python code. |
### 5.2. Image Preprocessing & Augmentation
# 6. Quickstart
You can get started instantly by using the deployed version of PyMCP:
> [!IMPORTANT]
> Use the following endpoints based on your use case:
>
> - Web Interface: `https://huggingface.co/spaces/MCP-1st-Birthday/PyMCP`
> - Streamable HTTP (MCP): `https://mcp-1st-birthday-pymcp.hf.space/gradio_api/mcp`
> - SSE (MCP): `https://mcp-1st-birthday-pymcp.hf.space/gradio_api/mcp/sse`
### 6.1. Claude Desktop (Requires npx)
Add/update your `claude_desktop_config.json`:
```json
{
"mcpServers": {
"py-mcp": {
"command": "npx",
"args": [
"-y",
"mcp-remote",
"https://mcp-1st-birthday-pymcp.hf.space/gradio_api/mcp"
]
}
}
}
```
### 6.2. LangChain
The example below also demonstrates PyMCP's built-in system prompt.
```bash
pip install langchain langchain-mcp-adapters langchain-openai
```
```python
import asyncio
from langchain.agents import create_agent
from langchain_mcp_adapters.client import MultiServerMCPClient
async def main() -> None:
client = MultiServerMCPClient(
{
"py-mcp": {
"transport": "streamable_http",
"url": "https://mcp-1st-birthday-pymcp.hf.space/gradio_api/mcp",
},
}
)
system_prompt = (await client.get_prompt("py-mcp", "system_prompt"))[0].content
tools = await client.get_tools()
agent = create_agent(
model="openai:gpt-5.1",
system_prompt=system_prompt,
tools=tools,
)
query = "Create a simple bar chart using matplotlib."
response = await agent.ainvoke({"messages": query})
print(response["messages"][-1].content)
if __name__ == "__main__":
asyncio.run(main())
```
> [!IMPORTANT]
> When running inside a Jupyter notebook, use `await main()` instead of `asyncio.run(main())` since an event loop is already running.
# 7. Build & Run
### Prerequisites
- Docker
- Git
### 7.1. Clone and Build
```bash
git clone https://github.com/aniketppanchal/py-mcp.git
cd py-mcp
docker build -t py-mcp .
```
### 7.2. Run the Container
Choose one of the modes below:
#### 7.2.1. Local Mode
```bash
docker run --rm --name py-mcp-server -p 7860:7860 py-mcp
```
> [!IMPORTANT]
> Use the following endpoints based on your use case:
>
> - Web Interface: `http://localhost:7860`
> - Streamable HTTP (MCP): `http://localhost:7860/gradio_api/mcp`
> - SSE (MCP): `http://localhost:7860/gradio_api/mcp/sse`
>
> **Note:** It is not recommended to change the host port from `7860` to another value, as you would need to update the port in all endpoints above, including all the downloadable URLs provided by your agent.
#### 7.2.2. Online Mode
```bash
docker run --rm --name py-mcp-server -e SHARE_ONLINE=true py-mcp
```
> [!IMPORTANT]
> When running in online mode, Gradio will print a unique public URL, for example:
> `https://xxxx.gradio.live`
>
> Use the following endpoints based on your use case:
>
> - Web Interface: `https://xxxx.gradio.live`
> - Streamable HTTP (MCP): `https://xxxx.gradio.live/gradio_api/mcp`
> - SSE (MCP): `https://xxxx.gradio.live/gradio_api/mcp/sse`
### 7.2.3. Configuration Options
You can customize sandbox behavior using the following environment variables:
| Environment Variable | Type | Description | Default |
| -------------------------------- | ---------------- | -------------------------------------------------------------------------- | ------- |
| SHARE_ONLINE | `true` / `false` | Controls whether exported file URLs are publicly accessible or local-only. | `false` |
| PACKAGE_INSTALLATION_TIMEOUT_SEC | Number (seconds) | Maximum duration allowed for installing Python packages. | `600` |
| CODE_EXECUTION_TIMEOUT_SEC | Number (seconds) | Maximum duration allowed for Python code execution. | `600` |
| COMMAND_EXECUTION_TIMEOUT_SEC | Number (seconds) | Maximum duration allowed for shell command execution. | `600` |