Leave MCP Server
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@Leave MCP Server Apply for annual leave from June 10 to 12"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
请假流程 MCP 服务
将 Dify 请假流程封装为 Model Context Protocol (MCP) 服务,让 LLM 客户端(Claude Desktop、Trae 等)通过标准 MCP 协议调用工具完成请假申请。
功能特性
6 个业务流程层工具:覆盖请假全流程(初始化、选岗、计算天数、附件检查、上传、提交)
环境切换:通过
API_ENV环境变量一键切换 UAT/PRD 环境,所有接口统一域名业务校验内置:年假/调休假余额校验、丧假 ≤3 天限制、7 类附件要求
附件上传:支持 base64 编码和本地文件路径两种方式
无状态设计:MCP 服务无状态,状态由 LLM 上下文保存,确认后再执行
流程引导 Prompt:内置
leave_flow_guide提示词,指导 LLM 按序调用工具
Related MCP server: HR Leave Management MCP Server
安装
# 克隆项目后安装(包含开发依赖)
pip install -e ".[dev]"环境变量配置
复制 .env.example 为 .env 并按需修改:
copy .env.example .env变量 | 说明 | 默认值 |
| 环境切换: |
|
| UAT 域名 |
|
| PRD 域名 |
|
切换生产环境只需设置 API_ENV=prd,所有接口自动指向 PRD 域名。
使用方式
1. MCP Inspector(开发调试)
mcp dev src/leave_mcp/server.py浏览器打开 Inspector 界面,可手动触发每个工具并查看返回结构。
2. Claude Desktop 配置
在 Claude Desktop 配置文件(claude_desktop_config.json)中添加:
{
"mcpServers": {
"leave-service": {
"command": "python",
"args": ["-m", "leave_mcp.server"],
"cwd": "D:\\子公司AI大赛PPT\\003",
"env": {
"PYTHONPATH": "D:\\子公司AI大赛PPT\\003\\src",
"API_ENV": "uat"
}
}
}
}
API_ENV设为uat或prd,不设置默认uat。切换到生产环境改为"prd"即可。
3. 直接运行
python -m leave_mcp.server工具列表
# | 工具名 | 功能 | 封装接口 |
1 |
| 初始化流程:获取用户信息、检查未销假、获取请假类型和余额 | 接口 1+4+2+3 |
2 |
| 从岗位列表中选择指定岗位(边界校验) | 无 |
3 |
| 计算实际休假天数 + 年假/调休假余额校验 | 接口 5 |
4 |
| 根据请假类型检查附件要求(7 类规则 + 丧假 ≤3 天) | 无 |
5 |
| 批量上传附件(支持 base64 编码或文件路径) | 接口 7 |
6 |
| 提交请假申请,返回申请单号 | 接口 8 |
Prompt
leave_flow_guide:请假流程引导,指导 LLM 按init → select → calculate → check_attachment → (upload) → submit顺序调用工具。
工具调用流程
用户发起请假请求
│
▼
init_leave_flow(user_token)
│
├── has_pending_leave=true → 提示用户先销假,结束
│
▼
select_organization(user_orgs, selected_index) [多岗位时]
│
▼
calculate_leave_days(...)
│
├── balance_sufficient=false → 提示余额不足
│
▼
check_attachment_requirement(leave_type, leave_days, has_attachment)
│
├── action=reject → 提示拒绝原因(如丧假超3天)
├── action=upload → upload_attachment(...) → submit_leave_application(...)
└── action=submit → submit_leave_application(...)附件要求速查
请假类型 | 所需附件 |
病假 | 诊断证明或病假条(二选一) |
产假 | 产检证明 |
工伤假 | 工伤情况证明 |
婚假 | 结婚证 |
丧假 | 死亡证明(且时长 ≤ 3 天) |
流产假 | 诊断证明或病假条(二选一) |
年休假 | 无需附件(但需校验余额) |
调休假 | 无需附件(但需校验余额) |
测试
# 运行所有测试
pytest tests/ -v
# 运行特定测试类
pytest tests/test_tools.py::TestCalculateLeaveDays -v测试覆盖:
test_client.py:8 个 REST 接口封装(respx mock httpx)test_tools.py:6 个工具的正常/异常分支(未销假拦截、余额不足、丧假超限、7 类附件规则、base64 解码)
项目结构
├── pyproject.toml # 项目配置 + 依赖
├── .env.example # 环境变量示例
├── src/leave_mcp/
│ ├── server.py # FastMCP 实例 + 6 个工具 + prompt
│ ├── config.py # 环境切换配置(API_ENV 控制 uat/prd)
│ ├── models.py # Pydantic 输入输出模型
│ ├── client.py # httpx 异步客户端,8 接口封装
│ ├── exceptions.py # 自定义异常
│ └── prompts.py # 流程引导提示词
└── tests/
├── conftest.py # pytest fixtures
├── test_client.py # 接口封装测试
└── test_tools.py # 工具逻辑测试关键设计决策
环境切换:通过
API_ENV变量控制(uat/prd),所有 8 个接口统一域名,UAT 用zhgr-mp-uat.huanhuigroup.cn,PRD 用zhgr-mp.huanhuigroup.cn。错误分层:业务可恢复结果(余额不足等)返回
{success: false, message}不中断对话;系统异常抛错。无状态:MCP 服务不保存会话状态,所需状态(如
selected_org、leave_types)由 LLM 在上下文中保存并作为参数传入。Token 传参:
user_token通过工具参数传入,不在服务端存储。Prompts 替代编排:Dify 的 22 节点状态机靠
leave_flow_guideprompt 指导 LLM 按序调用。附件双模式上传:支持
file_base64(跨客户端通用)和file_path(本地直读),优先file_path。
技术栈
Python ≥ 3.10
MCP Python SDK v1.0+
httpx(异步 HTTP 客户端)
Pydantic v2.0+(数据验证)
Available Tools
6 toolscalculate_leave_daysA
计算实际休假天数并校验假期余额。
调用接口 5 计算实际休假天数,然后根据请假类型校验余额:
年休假:校验年假余额是否充足
调休假:校验调休假余额是否充足
其他类型:不校验余额
Args: user_token: 用户认证 Token。 leave_type_code: 请假类型编码(来自 init_leave_flow 的 leave_types)。 start_date: 开始日期,格式 yyyy-MM-dd。 end_date: 结束日期,格式 yyyy-MM-dd。 user_code: 用户编码。 leave_type: 请假类型名称(如 "年休假"、"调休假"),用于余额校验。 avlb_annl_leave: 年假剩余天数(来自 init_leave_flow)。 avlb_ot_leave: 调休假剩余天数(来自 init_leave_flow)。 start_time_code: 开始时间编码,AM 或 PM,默认 AM。 end_time_code: 结束时间编码,AM 或 PM,默认 AM。
Returns: CalcDaysResult: 包含休假天数和余额校验结果。
Inputs: end_date (required), user_code (required), leave_type (required), start_date (required), +6 more. Returns: calculate_leave_days 工具返回结果。
check_attachment_requirementA
根据请假类型检查附件要求。
7 类请假类型的附件规则:
病假:诊断证明或病假条
产假:产检证明
工伤假:工伤证明
婚假:结婚证
丧假:死亡证明,且时长 ≤ 3 天(超出则拒绝)
流产假:诊断证明或病假条
年休假/调休假:无需附件
如果用户已上传附件(has_attachment=true),则 action=submit; 否则需上传时 action=upload。
Args: leave_type: 请假类型名称(如 "病假"、"婚假")。 leave_days: 实际休假天数(字符串,来自 calculate_leave_days)。 has_attachment: 用户是否已上传附件。
Returns: AttachmentCheckResult: 包含 action(upload/submit/reject)和提示信息。
Inputs: leave_days (required), leave_type (required), has_attachment (required). Returns: check_attachment_requirement 工具返回结果。
init_leave_flowA
初始化请假流程。
依次执行:获取用户信息(接口1)→ 检查未销假(接口4)→ 获取请假类型(接口2)→ 查询剩余假期(接口3)。 如果存在未销假记录,返回 has_pending_leave=true,LLM 应提示用户先销假。
两种调用方式:
提供 user_token:直接使用 Token 调用接口。
提供 user_code:自动通过 /auth/sso/getZhhhToken/{userCode} 获取 Token。 如果 Token 为空,返回提示"用户未登录,请先登录"。
Args: user_token: 用户认证 Token(可选,优先使用)。 user_code: 用户编码(可选,user_token 为空时通过此编码自动获取 Token)。
Returns: InitFlowResult: 包含用户信息、岗位列表、请假类型、剩余假期、Token。
Inputs: user_code, user_token. Returns: init_leave_flow 工具返回结果。
select_organizationA
根据用户选择的序号返回岗位信息。
用于用户有多个岗位时,从 init_leave_flow 返回的 user_orgs 中选择一个。 索引从 0 开始(与 Python 列表一致)。如果用户输入的是从 1 开始的序号, LLM 应在调用前转换为从 0 开始的索引。
Args: user_orgs: 岗位列表,来自 init_leave_flow 的返回值。 selected_index: 选中的岗位索引(从 0 开始)。
Returns: SelectOrgResult: 包含选中的岗位信息。
Inputs: user_orgs (required), selected_index (required). Returns: select_organization 工具返回结果。
submit_leave_applicationA
提交请假申请。
调用接口 8 提交请假流程,返回申请单号。需要汇总所有信息: 用户信息、岗位信息、请假类型、日期、天数、原因、附件等。
Args: user_token: 用户认证 Token。 user_name: 申请人姓名(来自 init_leave_flow)。 user_code: 申请人编码(来自 init_leave_flow)。 selected_org: 选中的岗位信息(来自 select_organization)。 avlb_annl_leave: 年假剩余天数(来自 init_leave_flow)。 avlb_ot_leave: 调休假剩余天数(来自 init_leave_flow)。 leave_type_code: 请假类型编码。 leave_type_value: 请假类型名称。 start_date: 开始日期,格式 yyyy-MM-dd。 end_date: 结束日期,格式 yyyy-MM-dd。 leave_days: 实际休假天数(来自 calculate_leave_days)。 lv_reason: 请假原因。 start_time_code: 开始时间编码,AM 或 PM,默认 AM。 end_time_code: 结束时间编码,AM 或 PM,默认 AM。 file_ids: 附件 ID 列表(来自 upload_attachment,无附件时为 None)。 file_names: 附件名列表(来自 upload_attachment,无附件时为 None)。
Returns: SubmitResult: 包含申请单号。
Inputs: end_date (required), lv_reason (required), user_code (required), user_name (required), +12 more. Returns: submit_leave_application 工具返回结果。
upload_attachmentA
批量上传附件文件。
将 base64 编码的文件内容解码后调用接口 7 上传。支持同时上传多个附件。 单文件大小上限由 MAX_ATTACHMENT_SIZE_MB 控制(默认 10MB)。
Args: user_token: 用户认证 Token。 files: 附件列表,每个元素包含 file_name、mime_type、file_base64。
Returns: UploadResult: 包含上传后的文件 ID 和文件名列表。
Inputs: files (required), user_token (required). Returns: upload_attachment 工具返回结果。
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 6 tools
Each tool has a clear, distinct purpose: initialization, leave calculation, attachment check, organization selection, upload, and submission. No overlapping functionality.
All tools follow a consistent verb_noun pattern in snake_case, e.g., calculate_leave_days, upload_attachment. No deviations.
With 6 tools, the server covers the essential steps of a leave application process without unnecessary bloat or missing critical operations.
The tool set covers the full leave application workflow: init, calculate, check, select, upload, submit. Minor gaps like viewing or canceling existing leave are absent but not critical for the core flow.
Maintenance
Related MCP Connectors
Malaysian SME accounting, e-Invoice and payroll for your AI. 77 tools; writes are approved drafts.
CharlieHR MCP server for ChatGPT, Claude and any AI agent: list team members, list time off requests, approve time off request, deny time off request, book time off, record sick day, adjust time off allowance and cancel time off booking in your own CharlieHR account. Cotlet works in the account through your Cloud Browser, a real Chrome where you sign in to CharlieHR yourself; Cotlet does not store your password and you need no CharlieHR API key. About the official CharlieHR API: CharlieHR has an API, but a narrow one, and no official MCP server (checked 20 Oct 2026). A Super Admin creates a Client ID and Client Secret under Company > Integrations > API Access; the API covers team members, leave, offices and teams. Setup and FAQ: https://cotlet.dev/integrations/charliehr-api-mcp-server
Employee leave and PTO: requests, approvals, balances, who is out, and conflict checks.
Read Breathe HR employees, absences, sickness and leave; create and review leave requests.
Related MCP Servers
- FlicenseNot gradedqualityDmaintenanceProvides tools for managing human resources tasks such as applying for leave, checking leave balances, and viewing holiday schedules. It enables natural language interaction for employee information and leave history tracking via the Model Context Protocol.-
- FlicenseBqualityDmaintenanceEnables managing employee leave requests (apply, view, list leaves) through Claude desktop using natural language.6-
- FlicenseBqualityDmaintenanceEnables HR teams to query and manage employee leave through natural language using Claude Desktop, with tools for checking balances, applying leave, and viewing history.3-
- FlicenseBqualityDmaintenanceEnables LLMs to manage employee leave by checking balances, applying for leave, and viewing history.3-