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 这将构建图像并将其推送为 .azurecr.io/hr-mcp-server:latest.
2.部署容器应用程序
az deployment group create `
--resource-group `
--template-file infra/container-app.bicep `
--parameters `
environmentId="/subscriptions//resourceGroups//providers/Microsoft.App/managedEnvironments/" `
acrLoginServer=".azurecr.io" `
appInsightsConnectionString=""二头肌模板(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 --query identity.principalId -o tsv)
az role assignment create `
--assignee $principalId `
--role AcrPull `
--scope /subscriptions//resourceGroups//providers/Microsoft.ContainerRegistry/registries/4.重新启动容器应用程序
角色分配传播后,重新启动以拉取具有托管标识的映像:
az containerapp revision restart --name hr-mcp-server --resource-group 