内容
mcp-plotting-server
一款 [FastMCP](httpsofastmcp.com/) 服务器,能够将 JSON 数据转换为 Plotly 图表,可作为独立服务部署在 [Modal](https://modal.com/)数据以 JSON 形式输入;则是经过验证的 Plotly 图表(JSON)或独立的 HTML 文档上下文协议(Model)返回。
## 为什么需要绘图服务器
绘图代码在该服务器进程中运行,部署为其自身的服务。调用这些工具的应用程序服务器从不执行绘图代码,只接收完成的图表或图像。M是隔离边界,这正是架构意义。
## 工具列表
工具 | 输入 | 输出 | 使用| --- | --- | --- | --- |
| `quick_plot` | 表格数据(记录列表)表类型 | Plotly 图表 JSON | 拥有整洁数据并标准图表 |
| `create_figure` | 完整的 Plotly规格(`data` +`) | Plotly 图表 完全控制图表轨迹和布局 |
| `render_` | Plotly 图表规格 | 独立 HTML 文档 | 需要、可查看的产物(默认从 CDN 加载 plotly.js) |
| `describe_plot` | 表格数据 + 自然语言描述 | Plotly 图表 JSON | 让 AI 代理为您创建图表 |
前三个工具返回 `fig.to_json()` 的输出,前端直接使用 [plotly.js](https://plotly.com/javascript/) 进行渲染 是稳定的跨语言契约render_figure_html` 将图表封装在自包含的 HTML 页面中,以便创建可共享的文件。
`` 是创作层:它内运行 opencode(使用针对您的数据编写 Plotly 脚本,使用 `uv run` 执行结果,并以与其他工具相同的格式 JSON。它比其他工具慢运行完整的代码生成循环),需要 `GEMINI_API_KEY` Modal附加到 Web 函数。因为它很慢,所以调用者必须允许较 工具超时(例如, 的 `experimental.mcp_timeout` 提高到约 240000。
## 先决条件
- Python 3.11+
- Modal 账户和已登录的 CLI(`pip install modal && modal token new`)
- 用于创建 GitHub 仓库的 `gh` CLI(可选)
## 本地开发
通过 stdio(默认的 MCP 传输,用于本地客户端)运行:
```bash
uvx --from . mcp-plotting-server
```
或直接运行服务器:
```bash
python -m mcp_plotting.server在本地开发期间使用 HTTP 服务器,调用 `mcp.run(transport="http", port=800,然后连接到 `http://8000/mcp`。
Modal 上部署
开发环境(实时重载,临时 URL):
```modal serve deploy.py
```
生产环境(永久 URL):bash
modal deploy deploy.pyModal 打印一个 Web URL
```
https://<workspace>--mcp-plotting-server-serve.modal.run
```
MCP 端点是该 URL 加上 `/m检查位于 `/health## 从 MCP 客户端连接任何 MCP 客户端(opClaude Desktop 等)指向已部署的端点:
```{
"mcpServers": {
"plotting": {
"url": "https://<workspace>--mcp-plotting-server-serve.modalcp"
}
}
```
## 工具调用`quick_plot` 带有:
```json
{
data": [
{"month": "Jan", "sales":},
{"month": " "sales": 150 {"month": "Mar", " 180}
],
kind": "bar",
": "month",
"y": "sales",
"title": "Quarterly sales"
}
```
的 Plotly 图表 `data` 和 `layout` 直接交给 plotly.js,或将给 `render_figure_html`独立的可查看的 HTML 页面。
## 布局
```
mcp_plotting/server.py Fast 服务器和工具
deploy.py 部署(ASGI 流式 HTTP)
```
## 许可证