人力资源数据服务

基于FastMCP构建的HR数据服务,通过基于权限范围的方式提供员工目录、个人资料、薪资和PII数据的访问。

  • by anevjes
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 anevjes/demo-hr-mcp-hack

使用说明

HR MCP服务器

构建的HR MCP服务器 FastMCP 通过基于范围的授权公开员工目录、个人资料、工资和PII数据。

范围

范围 描述
reader 访问非PII员工数据(姓名、部门、职位、办公室等)
writer 更新员工记录
restricted 访问个人身份信息/敏感数据(工资、地址、税务信息、银行详细信息等)

范围映射到工具

工具 所需范围
list_employees reader
get_employee_profile reader
search_employee_directory reader
get_org_chart reader
get_employee_pii restricted
get_employee_salary restricted
get_employee_full_record restricted
get_department_salary_summary restricted
update_employee_profile writer
update_employee_salary writer + restricted
update_employee_contact writer + restricted
whoami (任何经过身份验证的用户)

设置

pip install fastmcp

跑步

# STDIO mode (for MCP clients)
python server.py

# Or via FastMCP CLI
fastmcp run server.py

模拟数据

该服务器附带了7名跨部门(工程、数据科学、人力资源、财务、运营、高管)的模拟员工。所有数据都通过以下方式存储在内存中 hr_data.py.

部署到Azure容器应用程序

先决条件

  • Azure命令行界面(az)已安装并登录
  • Docker已安装
  • 现有的Azure容器注册表(ACR)
  • 现有的容器应用程序环境

1.构建并推送Docker镜像

.\build-and-push.ps1 -AcrName <your-acr-name>

这将构建图像并将其推送为 <your-acr-name>.azurecr.io/hr-mcp-server:latest.

2.部署容器应用程序

az deployment group create `
  --resource-group <your-rg> `
  --template-file infra/container-app.bicep `
  --parameters `
    environmentId="/subscriptions/<sub-id>/resourceGroups/<rg>/providers/Microsoft.App/managedEnvironments/<env-name>" `
    acrLoginServer="<your-acr-name>.azurecr.io" `
    appInsightsConnectionString="<optional-connection-string>"

二头肌模板(infra/container-app.bicep)使用以下命令创建容器应用程序:

  • 端口8000的外部入口
  • 系统为ACR拉取分配了托管身份
  • Application Insights遥测(可选)

3.授予ACR拉取权限

部署后,分配 AcrPull 容器应用程序的托管身份的角色:

# Get the principal ID from the deployment output
$principalId = (az containerapp show --name hr-mcp-server --resource-group <your-rg> --query identity.principalId -o tsv)

az role assignment create `
  --assignee $principalId `
  --role AcrPull `
  --scope /subscriptions/<sub-id>/resourceGroups/<rg>/providers/Microsoft.ContainerRegistry/registries/<your-acr-name>

4.重新启动容器应用程序

角色分配传播后,重新启动以拉取具有托管标识的映像:

az containerapp revision restart --name hr-mcp-server --resource-group <your-rg>