端口MCP服务器
模型上下文协议(MCP)服务器,用于与端口的软件目录API交互。这使GitHub Copilot和其他MCP客户端能够查询您的端口实体并与之交互。
特性
此MCP服务器提供以下工具:
1. get_entity
通过蓝图和实体标识符从Port获取特定实体。
使用案例: 检索有关特定服务、产品或任何其他实体的详细信息。
参数:
blueprint_identifier(必填):蓝图类型(例如“服务”、“产品”)entity_identifier(必填):实体的唯一标识符exclude_calculated_properties(可选):从响应中排除计算属性
2. search_entities
使用Port强大的查询规则搜索实体。
使用案例: 根据特定条件、属性或关系查找实体。
参数:
rules(必需):包含属性、运算符和值的搜索规则数组combinator(可选):如何组合规则-“和”或“或”(默认值:“和”)exclude_calculated_properties(可选):从响应中排除计算属性
示例规则:
[
{
"property": "$blueprint",
"operator": "=",
"value": "service"
},
{
"property": "environment",
"operator": "=",
"value": "production"
}
]3. find_product_for_service
帮助工具,用于查找服务所属的产品实体。
使用案例: 当你有一项服务并想知道它是什么产品的一部分时。
参数:
service_identifier(必填):服务实体的标识符
退货: 服务实体及其相关产品实体。
4. find_services_for_product
帮助工具,用于查找属于特定产品的所有服务实体。
使用案例: 当您想查看组成产品的所有服务/应用程序时。
参数:
product_identifier(必填):产品实体的标识符
退货: 与产品相关的所有服务实体。
设置
1.安装依赖项
pip install -r requirements.txt2.设置环境变量
您需要端口API凭据才能使用此服务器。从您的端口组织设置中获取它们。
export PORT_CLIENT_ID="your-client-id"
export PORT_CLIENT_SECRET="your-client-secret"3.在GitHub Copilot中配置MCP
将此服务器添加到MCP配置文件中。位置取决于您的设置:
对于VS代码: 编辑 ~/Library/Application Support/Code/User/mcp.json (macOS)或您操作系统上的同等版本。
添加以下配置:
{
"mcpServers": {
"port": {
"command": "python3",
"args": [
"/path/to/port-er/port_mcp_server.py"
],
"env": {
"PORT_CLIENT_ID": "your-client-id",
"PORT_CLIENT_SECRET": "your-client-secret"
}
}
}
}对于Claude Desktop: 编辑 ~/Library/Application Support/Claude/claude_desktop_config.json (macOS):
{
"mcpServers": {
"port": {
"command": "python3",
"args": [
"/path/to/port-er/port_mcp_server.py"
],
"env": {
"PORT_CLIENT_ID": "your-client-id",
"PORT_CLIENT_SECRET": "your-client-secret"
}
}
}
}4.使脚本可执行(可选)
chmod +x port_mcp_server.py5.测试服务器
您可以直接测试服务器:
export PORT_CLIENT_ID="your-client-id"
export PORT_CLIENT_SECRET="your-client-secret"
python3 port_mcp_server.py然后通过stdin发送JSON-RPC请求:
{"jsonrpc": "2.0", "id": 1, "method": "tools/list"}使用示例
配置后,您可以在GitHub Copilot中使用自然语言:
示例1:为服务查找产品
"What product does the service 'auth-service' belong to?"助理将使用 find_product_for_service 随着 service_identifier: "auth-service".
示例2:列出产品中的所有服务
"Show me all services that are part of the 'payments-platform' product"助理将使用 find_services_for_product 随着 product_identifier: "payments-platform".
示例3:获取服务详细信息
"Get the details of the service 'user-api'"助理将使用 get_entity 随着 blueprint_identifier: "service" 和 entity_identifier: "user-api".
示例4:搜索生产服务
"Find all services running in production environment"助理将使用 search_entities 有适当的规则。
常见用例
1.查找服务所有权
获取服务实体以查看其所有者、团队和存储库信息:
"Who owns the 'checkout-service'?"2.产品发现
查找服务所属的产品并获取产品级别信息:
"What product is 'payment-gateway' part of, and who are the product stakeholders?"3.服务库存
列出产品的所有服务,以了解其架构:
"List all microservices in the 'e-commerce' product"4.存储库映射
查找与服务关联的GitHub存储库:
"What's the repository URL for 'notification-service'?"定制
调整关系名称
辅助工具(find_product_for_service 和 find_services_for_product)假定某些关系属性名称。您可能需要根据端口配置调整这些参数:
在 port_mcp_server.py,查找:
for rel_key in ["product", "parentProduct", "belongsToProduct"]:更新此列表以匹配您的实际关系属性名称。
添加更多辅助工具
您可以按照以下模式添加其他辅助工具:
- 创建一个处理函数(例如。,
handle_your_tool) - 将其添加到中的工具列表
tools/list响应 - 在中添加一个案例
tools/call处理器
故障排除
身份验证问题
- 验证您的
PORT_CLIENT_ID和PORT_CLIENT_SECRET是正确的 - 检查您的端口凭据是否具有必要的权限
未找到实体
- 验证蓝图标识符是否与您的端口配置匹配
- 检查实体标识符是否存在于端口目录中
未找到关系属性
- 端口设置中的关系属性名称可能不同
- 检查端口蓝图配置中的实际关系属性名称
api参考
使用的端口API端点
POST /v1/auth/access_token-身份验证GET /v1/blueprints/{blueprint}/entities/{entity}-获取实体POST /v1/entities/search-搜索实体
有关更多详细信息,请参阅:
许可证
麻省理工学院
