HR策略MCP服务器

提供策略资源并维护策略记录供AI代理使用,同时提供简单的数学工具,并通过官方`modelcontextprotocol/python-sdk`将所有MCP服务器整合到一个受身份验证保护的MCP端点。

  • by abneetwats24
  • Python
  • 本地部署
  • 2 星标
  • 更新于
在 GitHub 查看 abneetwats24/hr-policy-mcp

使用说明

人力资源策略MCP服务器

此服务器提供策略资源并维护策略记录,供AI代理使用。

它还公开了简单的数学工具,并将两个MCP服务器组合在一个单独的 使用官方身份验证保护的MCP端点 modelcontextprotocol/python-sdk.

应用程序设计流程

flowchart LR
subgraph ControlPlane[Control Plane]
subgraph Registry[Agent Registry]
AgentASG[Agent A-JSON]
AgentBSG[Agent B-JSON]
AgentCSG[Agent C-JSON]
end
LGRrouterN[Router/Agent Selector]
end

subgraph OrgServices[Integration/Knowledge]
ServiceA[Service A]
ServiceB[Service B]
ServiceC[Service C]
ServiceD[Service D]
end


Broker[(Message Fabric)]
Observability[(Tracing & Metrics)]


AgentA[Agent A]
AgentB[Agent B]
AgentC[Agent C]

McpA[MCP A]
McpB[MCP B]
McpC[MCP C]

User[User]

User -->|API / WS / Event| Client  
Client --> LGRrouterN
LGRrouterN -->|A2A Message| Registry
AgentA -->|A2A Message| Broker
Broker -->|Deliver| AgentB
Broker -->|Deliver| AgentC


AgentA -->|Response/Heartbeat| AgentASG
AgentB -->|Response/Heartbeat| AgentBSG
AgentC -->|Response/Heartbeat| AgentCSG


AgentASG <-->|Discovery API| AgentA
AgentBSG <-->|Discovery API| AgentB
AgentCSG <-->|Discovery API| AgentC



AgentA --> Observability
AgentB --> Observability
AgentC --> Observability

AgentA <--> McpA
AgentB <--> McpB
AgentC <--> McpC

McpA <--> ServiceA
McpB <--> ServiceB
McpC <--> ServiceD
McpB <--> ServiceC

目录结构

src/
  main.py                 # Composite MCP server (HR + math) with auth
  hr_policy_mcp/
    __init__.py           # Exposes hr_policy_mcp and registers resources
    server.py             # HR FastMCP instance + PolicyService wiring
    services/
      policy_service.py   # Loads PDF policies from static/dev/policy_files
    resources/
      policies.py         # Registers one MCP resource per policy
  math_mcp/
    __init__.py           # Exposes math_mcp and registers tools
    server.py             # Math FastMCP instance
    tools/
      basic.py            # add / subtract tools
  middleware/
    __init__.py
    token_verifier.py     # OAuth2 token introspection (Keycloak)

static/
  dev/
    policy_files/         # PDF HR policy documents

认证

主MCP服务器的配置类似于 simple-auth 示例中 python SDK。它使用:

  • Keycloak领域发现地点: http://192.168.10.7:5555/realms/openspace/.well-known/openid-configuration
  • 令牌自检端点: http://192.168.10.7:5555/realms/openspace/protocol/openid-connect/token/introspect
  • 所需范围: mcp:tools (可通过env配置)。

客户端凭据是通过环境变量提供的(请参见 .env.example).

使用紫外线(本地)运行

uv run src/main.py

复合MCP服务器将监听 http://127.0.0.1:3000/mcp 使用 streamable-http 运输。

码头工人

直接使用Docker构建和运行:

docker build -t hr-policy-mcp .
docker run --rm -p 3000:3000 --env-file .env hr-policy-mcp

或者使用docker compose:

docker compose up --build

MCP端点将在以下位置可用:

http://127.0.0.1:3000/mcp

日志记录

服务器发出两种日志:

  • 标准Python日志

    • 配置于 src/main.py 通过 setup_logging().
    • 输出到stdout/stderr和 logs/server.log.
    • 由以下组件使用 PolicyService 报告加载/解析错误。
  • MCP上下文日志记录

    • 工具和资源接受 ctx: Context[ServerSession, None] 争论。
    • 通过以下方式读取人力资源策略资源日志和失败 ctx.info(...) / ctx.error(...).
    • 数学工具通过以下方式记录操作 ctx.debug(...).
    • 这些日志作为通知发送回兼容的MCP客户端。

Keycloak身份验证服务器配置

跟随 钥匙斗篷配置

MCP认证广为人知

要查看众所周知的详细信息:http://127.0.0.1:3000/math/.well-已知/oauth保护的资源 应该输出如下内容:

{"resource":"http://127.0.0.1:3000/","authorization_servers":["http://192.168.10.7:5555/realms/openspace"],"scopes_supported":["mcp:tools"],"bearer_methods_supported":["header"]}