使用说明
图API MCP服务器
一个通过模型上下文协议(MCP)提供Microsoft Graph API文档访问的FastMCP服务器。该服务器在Docker中运行,并通过可流式传输的HTTP MCP接口公开Graph API文档。
特点/特性
- FastMCP 服务器使用FastMCP并结合Streamable-HTTP传输实现MCP协议
- 离线文档从本地读取
graph_docs.jsonl文件以便快速、离线访问 - 搜索工具提供多种工具用于查询Graph API文档
- Docker 支持容器化部署,便于设置和移植
- 文档导入器用于解析和提取Microsoft Graph文档中元数据的脚本
MCP 工具
服务器通过MCP提供以下工具:
1. searchDocs
跨标题、路径和内容按关键词搜索文档。
参数:
query(字符串):搜索查询字符串max_results(int, 可选):最大结果数量(默认:10)
示例:
{
"query": "user",
"max_results": 5
}
2. getDocByPath
获取特定文件路径的完整文档。
参数:
path(字符串):文档的文件路径
示例:
{
"path": "api-reference/v1.0/api/user-get.md"
}
3. getApiSchema
获取特定API端点的JSON模式。
参数:
endpointAPI终端路径(例如,“/users”或“users”)
示例:
{
"endpoint": "/users"
}
4. getExamples
获取特定主题或API的代码示例。
参数:
topic主题或API以获取示例language(字符串,可选):按编程语言过滤
示例:
{
"topic": "users",
"language": "javascript"
}
设置
先决条件
- Docker 和 Docker Compose
- Python 3.11+(用于本地运行,无需Docker)
使用Docker快速入门
-
克隆仓库:
git clone https://github.com/jacklatrobe/GRAPH_API_MCP.git cd GRAPH_API_MCP -
使用 Docker Compose 构建并运行:
docker-compose up --build -
服务器将在以下地址可用:
http://localhost:8000
本地开发
-
安装依赖项:
pip install -r requirements.txt -
运行服务器:
python server.py
进口文件
从 Microsoft Graph 文档存储库导入文档:
-
克隆 Microsoft Graph 文档:
git clone https://github.com/microsoftgraph/microsoft-graph-docs-contrib.git -
运行导入脚本:
python import_graph_docs.py microsoft-graph-docs-contrib graph_docs.jsonl -
该脚本将:
- 解析仓库中的所有Markdown文件
- 提取元数据(标题、版本、HTTP方法、示例、权限、模式)
- 输出一个标准化的JSONL文件
数据格式
这个(或:该) graph_docs.jsonl 文件中的每一行包含一个JSON对象,结构如下:
{
"path": "api-reference/v1.0/api/user-get.md",
"title": "Get user",
"version": "v1.0",
"http_methods": [
{"method": "GET", "path": "/users/{id}"}
],
"examples": [
{"language": "http", "code": "GET https://graph.microsoft.com/v1.0/users/{id}"}
],
"permissions": ["User.Read", "User.ReadBasic.All"],
"schema": {"@odata.type": "microsoft.graph.user", "id": "string"},
"content": "First 5000 characters of markdown content..."
}
建筑学
┌─────────────────────┐
│ MCP Client │
│ (LLM Agent) │
└──────────┬──────────┘
│ MCP Protocol
│ (Streamable-HTTP)
▼
┌─────────────────────┐
│ FastMCP Server │
│ (server.py) │
├─────────────────────┤
│ - searchDocs │
│ - getDocByPath │
│ - getApiSchema │
│ - getExamples │
└──────────┬──────────┘
│ Read
▼
┌─────────────────────┐
│ graph_docs.jsonl │
│ (Documentation DB) │
└─────────────────────┘
发展
项目结构
GRAPH_API_MCP/
├── server.py # FastMCP server implementation
├── import_graph_docs.py # Documentation importer script
├── graph_docs.jsonl # Sample documentation data
├── requirements.txt # Python dependencies
├── Dockerfile # Docker image definition
├── docker-compose.yml # Docker Compose configuration
└── README.md # This file
运行测试
服务器中包含示例数据 graph_docs.jsonl你可以通过以下方式测试这些工具:
- 启动服务器
- 与MCP客户端建立连接
- 调用可用工具
许可证
MIT 许可证 - 请参阅 许可证 文件中包含详细信息
致谢
- 使用……构建 FastMCP
- 来自……的文件/资料 Microsoft Graph API
