MCP服务器用于LLM代理集成服务
设计用于向大型语言模型(LLM)公开PagerDuty API功能的服务器。此服务器旨在用于程序化使用,具有结构化输入和输出功能。
概述
这 MCP服务器用于LLM代理集成服务 提供了一组用于与PagerDuty API交互的工具。这些实用程序是专门为LLM设计的,用于在PagerDuty资源(如事件、服务、团队和用户)上执行各种操作。
安装
来自PyPI
pip install mcp-server-for-llm-agent-integration-service源代码
# Clone the repository
git clone https://github.com/techtitan91/MCP-Server-For-LLM-Agent-Integration-Service
cd MCP-Server-For-LLM-Agent-Integration-Service
# Install dependencies
brew install uv
uv sync系统要求
- Python 3.13或更高版本
- PagerDuty API密钥
配置
这 MCP服务器用于LLM代理集成服务 需要在环境变量中定义PagerDuty API密钥:
PAGERDUTY_API_KEY=your_api_key_here使用说明
作为鹅的延伸
{
"type": "stdio",
"enabled": true,
"args": ["run", "python", "-m", "pagerduty_mcp_server"],
"commandInput": "uv run python -m pagerduty_mcp_server",
"timeout": 300,
"id": "mcp-server-for-llm-agent-integration-service",
"name": "MCP Server For LLM Agent Integration Service",
"description": "Server for PagerDuty API integration with LLMs",
"env_keys": ["PAGERDUTY_API_KEY"],
"cmd": "uv"
}作为独立服务器
uv run python -m pagerduty_mcp_server响应结构
所有API回复均遵循统一格式:
{
"metadata": {
"count": int, // Number of items in the result
"description": "" // A brief summary of the results
},
"resource_type": [ // Always pluralized for consistency, even if only one result is returned
{
},
],
"error": { // Present only if an error occurred
"message": "", // Human-readable error explanation
"code": "" // Machine-readable error identifier
}
}错误管理
当发生错误时,响应将包含一个错误对象和后续结构:
{
"metadata": {
"count": 0,
"description": "An error occurred while processing the request"
},
"error": {
"message": "Invalid user ID was provided",
"code": "INVALID_USER_ID"
}
}常见的错误情况包括:
- 无效的资源标识符(例如,user_id、team_id、service_id)
- 缺少必需参数
- 参数值无效
- API请求失败
- 响应处理过程中出错
参数验证
- 所有ID参数都必须是有效的PagerDuty资源标识符。
- 日期参数必须是有效的ISO8601时间戳。
- 列出参数(例如。,
statuses,team_ids)必须包含有效值。 - 列表参数中的无效值将被忽略。
- 所需参数不能为
None或空字符串。 - 对于
statuses在……里面list_incidents,仅triggered,acknowledged,以及resolved是可接受的值。 - 对于
urgency在事故中,仅high和low是可接受的值。 - 这
limit参数可用于限制列表操作返回的结果数量。
速率限制和分页
- 服务器遵守PagerDuty的API速率限制。
- 服务器会自动为您管理分页。
- 这
limit参数可用于控制列表操作返回的结果数量。 - 如果没有指定限制,服务器将返回最多
{pagerduty_mcp_server.utils.RESPONSE_LIMIT}默认结果。
示例用法(Python)
from pagerduty_mcp_server import incidents
from pagerduty_mcp_server.utils import RESPONSE_LIMIT
# List all incidents (including resolved ones) for the current user's teams
incidents_list = incidents.list_incidents()
# List only active incidents
active_incidents = incidents.list_incidents(statuses=['triggered', 'acknowledged'])
# List incidents for specific services
service_incidents = incidents.list_incidents(service_ids=['SERVICE-1', 'SERVICE-2'])
# List incidents for specific teams
team_incidents = incidents.list_incidents(team_ids=['TEAM-1', 'TEAM-2'])
# List incidents within a specified date range
date_range_incidents = incidents.list_incidents(
since='2024-03-01T00:00:00Z',
until='2024-03-14T23:59:59Z'
)
# List incidents with a custom limit on the number of results
limited_incidents = incidents.list_incidents(limit=10)
# List incidents with the default response limit
default_limit_incidents = incidents.list_incidents(limit=RESPONSE_LIMIT)用户上下文过滤
许多功能接受 current_user_context 参数(默认为 True),它根据此上下文自动过滤结果。当 current_user_context 是 True,某些过滤器参数不能使用,因为它们会与此自动过滤冲突:
- 对于所有资源类别:
- user_ids 不能在以下情况下使用 current_user_context=True.
- 对于事件:
- team_ids 和 service_ids 不能在以下情况下使用 current_user_context=True.
- 关于服务:
- team_ids 不能在以下情况下使用 current_user_context=True.
- 对于升级策略:
- team_ids 不能在以下情况下使用 current_user_context=True.
- 随叫随到:
- user_ids 不能在以下情况下使用 current_user_context=True. - schedule_ids 仍然可以用于按特定时间表进行过滤。 - 查询将显示与当前用户团队相关的所有升级策略的呼叫。 - 这有助于回答诸如“我的团队目前有谁在待命?”之类的问题 - 当前用户的ID不会作为过滤器应用,因此您将观察所有随叫随到的团队成员。
发展
执行测试
请注意,大多数测试都需要与PagerDuty API进行实时连接,因此您需要设置 PAGERDUTY_API_KEY 在运行完整的测试套件之前,请先在您的环境中进行测试。
uv run pytest只运行单元测试(即不需要 PAGERDUTY_API_KEY 待设置):
uv run pytest -m unit要仅运行集成测试,请执行以下操作:
uv run pytest -m integration要仅运行解析器测试,请执行以下操作:
uv run pytest -m parsers仅运行与特定子模块相关的测试:
uv run pytest -m 使用MCP检查器调试服务器
npx @modelcontextprotocol/inspector uv run python -m pagerduty_mcp_server贡献
发布过程
该项目坚持 常规承诺 自动发布。提交消息指示版本增量:
feat:→ 次要版本(例如1.0.0→ 1.1.0)fix:→ 补丁版本(例如1.0.0→ 1.0.1)BREAKING CHANGE:→ 主要版本(例如1.0.0→ 2.0.0)
这 CHANGELOG.md,GitHub版本和PyPI包会自动更新。
文档链接
工具文档 -有关可用工具的详细信息,包括参数、返回类型和示例查询。
编码约定
- 所有API响应都遵循标准格式,包括元数据、资源列表和可选的错误对象。
- 响应中的资源名称始终采用复数形式,以保持一致性。
- 所有返回单个项的函数仍然会生成一个包含一个元素的列表。
- 错误响应包括人类可读的消息和机器可读的代码。
- 所有时间戳均采用ISO8601格式。
- 测试用pytest标记来指示它们的类型(单元/集成)、它们所属的资源(事件、团队等)以及它们是否测试解析功能(使用“解析器”标记)。
