这是一个提供标准化工具和资源以与PI仪表板API交互的模型上下文协议(MCP)服务器。此实现使Claude和其他兼容MCP的AI助手能够安全地访问和管理PI仪表板资源,包括类别和图表。
以下演示了在设置完成后使用此MCP服务器的典型场景。
初始认证:
确保PI API MCP服务器正在运行
将API URL设置为http://localhost:8224/pi/api/v2
使用认证工具进行认证指导
检查连接状态以验证一切正常
列出仪表板上的两个图表
图表分析:
从图表ID 450中检索元数据
从ID 450提取图表JSON数据
识别与声明关联的图表ID
获取已识别图表的JSON数据
分析数据以生成可操作见解
示例输出:

要通过Smithery自动安装Claude Desktop的pi-api-mcp-server:
npx -y @smithery/cli install @mingzilla/pi-api-mcp-server --client claude
{
"mcpServers": {
"pi-api": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"-e",
"API_URL=http://localhost:8224/pi/api/v2",
"-e",
"PI_API_KEY=XXXXXXXX",
"mingzilla/pi-api-mcp-server"
],
"disabled": false,
"autoApprove": [
"keep-session-alive",
"check-connection",
"authenticate",
"list-categories",
"get-category",
"list-charts",
"get-chart",
"export-chart",
"get-filterable-attributes",
"export-chart"
]
}
}
}
重要说明:如果初始化时未提供--api-url参数,服务器将在执行任何操作之前要求您使用set-api-url工具配置API URL。这种设计允许在启动时URL不确定的环境中灵活配置。
访问您的Claude for Desktop应用程序配置:
~/Library/Application Support/Claude/claude_desktop_config.json%APPDATA%\Claude\claude_desktop_config.json获取图表实体的可过滤属性
将API URL设置为http://localhost:8224/pi/api/v2
这里是一些连接服务器后可以与Claude一起使用的示例查询:
请使用set-api-url工具将PI API URL设置为http://localhost:8224/pi/api/v2
请帮我认证到PI API。
我有一个令牌。请使用keep-session-alive工具和我的令牌:[YOUR_TOKEN_HERE]
请检查我与PI API的连接是否正常工作。
列出仪表板中的所有类别。
获取ID为123的类别的详细信息。
列出仪表板中可用的所有图表。
将ID为456的图表导出为PDF。
获取图表实体的可过滤属性,以了解我可以过滤哪些字段。
使用过滤选项列出描述中包含“收入”的图表。
分析仪表板中的类别。
比较图表123和456之间的数据。
展示如何有效地使用此API的过滤器。
start.sh来运行开发服务器。# 克隆仓库(SSH或HTTPS选项)
git clone git@github.com:mingzilla/pi-api-mcp-server.git
cd pi-api-mcp-server
# 安装依赖
npm install
./dependencies.sh # 安装全局依赖以启用通过"@mingzilla/pi-api-mcp-server"连接MCP客户端
# 构建项目
npm run build
# 执行服务器
npm start
# 全局安装
npm install -g @mingzilla/pi-api-mcp-server
# 通过npx直接执行
npx @mingzilla/pi-api-mcp-server --api-url "http://localhost:8224/pi/api/v2" --auth-token "XXXXXXXX"
与Claude for Desktop集成:
./dependencies.sh以安装所需依赖{
"mcpServers": {
"pi-api": {
"command": "npx",
"args": [
"-y",
"@mingzilla/pi-api-mcp-server",
"--api-url",
"http://localhost:8224/pi/api/v2",
"--auth-token",
"XXXXXXXX"
],
"autoApprove": [
"keep-session-alive",
"check-connection",
"authenticate",
"list-categories",
"get-category",
"list-charts",
"get-chart",
"export-chart",
"get-filterable-attributes",
"export-chart"
]
}
}
}
./start.sh运行服务器build/index.js文件路径设置配置./start.sh
{
"mcpServers": {
"pi-api": {
"command": "node",
"args": [
"/home/mingzilla/dev/tool-mcp-pi-api-server/build/index.js",
"--api-url",
"http://localhost:8224/pi/api/v2",
"--auth-token",
"XXXXXXXX"
],
"autoApprove": [
"keep-session-alive",
"check-connection",
"authenticate",
"list-categories",
"get-category",
"list-charts",
"get-chart",
"export-chart",
"get-filterable-attributes",
"export-chart"
]
}
}
}
MIT许可证
黄明(mingzilla)