Leave Management MCP Server
Provides leave-management functionality backed by PostgreSQL, including checking employee leave balances, submitting and reviewing leave requests, retrieving employee leave dates, checking date availability, and listing leave requests.
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 Management MCP Server Check leave balance for employee E1042"
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.
Leave Management MCP Server
A Python-based Model Context Protocol (MCP) server for managing employee leave requests using PostgreSQL. It exposes leave-management functionality as MCP tools and resources so an MCP-compatible client can interact with employee records, leave balances, leave requests, and leave calendars.
Features
MCP tools
Tool Description
check_leave_balance Retrieves an employee's available
balance for each leave type.
submit_leave_request Submits a leave request, calculates
working days (Monday--Friday), and
stores the request and its
individual leave dates.
review_leave_request Approves or rejects a pending
request. Approval deducts the
requested days from the employee's
leave balance.
get_employee_leave_dates Retrieves an employee's leave
dates, with optional status and
month filters.
check_date_availability Lists employees who have approved
leave on a specified date.
Related MCP server: Leave Management MCP Server
list_leave_requests Lists leave requests, optionally
filtered by status and employee.
MCP resources
Resource URI Description
policy://company/leave Returns the company's leave policy.
balances://{employee_id} Returns leave balances for the
specified employee.
Technology stack
Python
MCP Python SDK (
mcp[cli])PostgreSQL
Psycopg 3 (
psycopg[binary])python-dotenvuvfor Python project and dependency management
Project structure
leave-management-mcp-server/
├── .env # Local database configuration (not committed)
├── .env.example # Example environment configuration
├── .gitignore
├── pyproject.toml
├── uv.lock # Generated by uv, if committed
└── src/
└── my_first_mcp_server/
└── __init__.py # MCP server, tools, resources, and database logicThe GitHub repository can be named
leave-management-mcp-serverwhile the Python package directory remainsmy_first_mcp_server.
Prerequisites
Python version compatible with the
requires-pythonsetting inpyproject.toml.PostgreSQL, with a database created for the application.
An MCP-compatible client or MCP Inspector for testing.
Setup
1. Clone the repository
git clone https://github.com/YOUR_USERNAME/leave-management-mcp-server.git
cd leave-management-mcp-serverReplace YOUR_USERNAME with your GitHub username.
2. Install dependencies
uv syncThe dependencies used by this project can be added with:
uv add "mcp[cli]"
uv add "psycopg[binary]"
uv add python-dotenvuv add adds a dependency to pyproject.toml and updates the lock
file. uv sync installs the dependencies declared by the project.
3. Create the PostgreSQL database
For example, create a database named leave_management:
CREATE DATABASE leave_management;Connect to that database before running the table creation statements below.
4. Configure environment variables
Create a .env file in the project root:
DATABASE_URL=postgresql://postgres:YOUR_PASSWORD@localhost:5432/leave_managementReplace YOUR_PASSWORD with your PostgreSQL password.
The application loads this value using python-dotenv. Keep .env
private and do not commit it to Git.
Create a .env.example file for other developers, containing
placeholders only:
DATABASE_URL=postgresql://postgres:YOUR_PASSWORD@localhost:5432/leave_management5. Create the database tables
Run the following SQL while connected to the leave_management
database.
Employees
Stores employee details. employee_id is the primary key.
CREATE TABLE employees (
employee_id VARCHAR(20) PRIMARY KEY,
name VARCHAR(100) NOT NULL,
department VARCHAR(100) NOT NULL
);Leave balances
Stores the available number of days for each employee and leave type. Each employee can have one balance row per leave type.
CREATE TABLE leave_balances (
id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
employee_id VARCHAR(20) NOT NULL,
leave_type VARCHAR(20) NOT NULL,
available_days INTEGER NOT NULL DEFAULT 0,
CONSTRAINT fk_balance_employee
FOREIGN KEY (employee_id)
REFERENCES employees(employee_id),
CONSTRAINT uk_employee_leave
UNIQUE (employee_id, leave_type),
CONSTRAINT ck_leave_type
CHECK (leave_type IN ('VACATION', 'SICK', 'PERSONAL')),
CONSTRAINT ck_available_days
CHECK (available_days >= 0)
);Leave requests
Stores the overall request, including its date range, number of requested working days, reason, status, and reviewer remarks.
CREATE TABLE leave_requests (
request_id VARCHAR(20) PRIMARY KEY,
employee_id VARCHAR(20) NOT NULL,
leave_type VARCHAR(20) NOT NULL,
start_date DATE NOT NULL,
end_date DATE NOT NULL,
days_requested INTEGER NOT NULL,
reason VARCHAR(500),
status VARCHAR(20) NOT NULL DEFAULT 'PENDING',
remarks VARCHAR(500),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT fk_request_employee
FOREIGN KEY (employee_id)
REFERENCES employees(employee_id),
CONSTRAINT ck_request_leave_type
CHECK (leave_type IN ('VACATION', 'SICK', 'PERSONAL')),
CONSTRAINT ck_request_status
CHECK (status IN ('PENDING', 'APPROVED', 'REJECTED')),
CONSTRAINT ck_request_dates
CHECK (end_date >= start_date),
CONSTRAINT ck_request_days
CHECK (days_requested > 0)
);Individual leave dates
Stores each working date associated with a request. This supports overlap checks and date-based availability queries. Deleting a request also deletes its associated date rows.
CREATE TABLE leave_request_dates (
id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
request_id VARCHAR(20) NOT NULL,
leave_date DATE NOT NULL,
CONSTRAINT fk_leave_request
FOREIGN KEY (request_id)
REFERENCES leave_requests(request_id)
ON DELETE CASCADE,
CONSTRAINT uk_request_date
UNIQUE (request_id, leave_date)
);6. Optional sample data
Insert sample employees:
INSERT INTO employees (employee_id, name, department)
VALUES
('EMP001', 'Alice Johnson', 'Engineering'),
('EMP002', 'Bob Smith', 'Product');Insert their leave balances:
INSERT INTO leave_balances (employee_id, leave_type, available_days)
VALUES
('EMP001', 'VACATION', 15),
('EMP001', 'SICK', 8),
('EMP001', 'PERSONAL', 4),
('EMP002', 'VACATION', 10),
('EMP002', 'SICK', 10),
('EMP002', 'PERSONAL', 2);Run these inserts only once for the sample database. Running them again may cause primary-key or unique-constraint violations.
Run the MCP server with MCP Inspector
Start the MCP development inspector from the repository root:
uv run mcp dev src/my_first_mcp_server/__init__.pyThe command launches the MCP development environment and MCP Inspector.
Open the Inspector URL printed in the terminal (commonly
http://127.0.0.1:6274).
Keep the terminal process running while using Inspector. Stop it with
Ctrl+C.
Use Inspector to connect to the server, view its resources and tools, and invoke the tools with test arguments.
Example tool inputs
The exact arguments are validated against the Python tool function signatures.
Check leave balance
{
"employee_id": "EMP001"
}Submit a leave request
{
"employee_id": "EMP001",
"leave_type": "SICK",
"start_date": "2026-11-06",
"end_date": "2026-11-09",
"reason": "Sick leave"
}The working-day calculation counts Monday through Friday, inclusive. In this example, Friday 6 November and Monday 9 November are two working days.
Review a leave request
{
"request_id": "REQ-XXXXXXXX",
"action": "APPROVE",
"remarks": "Approved"
}Use the actual request ID returned by submit_leave_request. Supported
actions are APPROVE and REJECT.
Get employee leave dates
{
"employee_id": "EMP001",
"status": "APPROVED",
"month_prefix": "2026-11"
}Check date availability
{
"target_date": "2026-11-06"
}List leave requests
{
"status": "ALL",
"employee_id": "EMP001"
}Leave request lifecycle
An employee submits a request.
The server validates the employee, leave type, date range, balance, and overlapping pending or approved leave.
The server inserts the request into
leave_requestsand its working dates intoleave_request_dates.The request starts with
PENDINGstatus.An authorized reviewer approves or rejects the request.
On approval, the server deducts the requested days from
leave_balancesand updates the request status.On rejection, the status changes to
REJECTED; the balance is not deducted.
Pending requests do not deduct or reserve leave balance in the current business logic. Public holidays are not excluded by the current Monday--Friday working-day calculation.
Database relationships
employees
│
├──< leave_balances
│
└──< leave_requests
│
└──< leave_request_datesOne employee can have multiple leave-balance rows, one per leave type.
One employee can submit multiple leave requests.
One leave request can contain multiple individual working dates.
leave_request_dates.request_idreferencesleave_requests.request_idwithON DELETE CASCADE.
Troubleshooting
DATABASE_URL is missing
Confirm that
.envexists in the repository root.Confirm that it contains
DATABASE_URL=....Verify the database name, username, password, host, and port.
Ensure the application loads the root
.envfile.
PostgreSQL connection error
Confirm PostgreSQL is running.
Confirm the
leave_managementdatabase exists.Verify the credentials in
DATABASE_URL.Confirm that the tables were created in the correct database.
MCP tool execution error
Check the terminal running
mcp devfor the Python traceback.Verify that the MCP tool arguments match the function signatures.
Verify that the database contains the expected employee and balance records.
Check that the request ID and leave type satisfy the database constraints.
AttributeError: 'Connection' object has no attribute 'executemany'
With Psycopg 3, call executemany() on a cursor, not on the connection:
with conn.cursor() as cur:
cur.executemany(
"""
INSERT INTO leave_request_dates (request_id, leave_date)
VALUES (%s, %s)
""",
rows
)Development commands
# Add the MCP SDK
uv add "mcp[cli]"
# Add PostgreSQL driver
uv add "psycopg[binary]"
# Add .env support
uv add python-dotenv
# Install/synchronize dependencies
uv sync
# Start MCP Inspector
uv run mcp dev src/my_first_mcp_server/__init__.pySecurity notes
Never commit
.env, database passwords, API keys, or access tokens.Keep
.envin.gitignore.Use
.env.examplewith placeholder values for documentation.Use a restricted PostgreSQL user for application access rather than a database superuser.
Do not expose raw database exception details to end users in production; log diagnostic details securely.
Future enhancements
Possible next improvements include:
Company holiday calendar and holiday-aware working-day calculations.
Role-based authorization for reviewers and employees.
Reserving leave days for pending requests, if required by company policy.
Audit history for approval/rejection and balance changes.
Notifications for request submission and review decisions.
Automated tests for validation, overlapping requests, transactions, and concurrent submissions.
License
This project is licensed under the MIT License.
See the LICENSE file for details.
Available Tools
6 toolscheck_date_availabilityC
Check employees on approved leave on a specific date.
Inputs: target_date (required). Returns: result
check_leave_balanceC
Check remaining leave days for an employee.
Inputs: employee_id (required). Returns: result
get_employee_leave_datesC
Retrieve leave dates for an employee.
Inputs: employee_id (required), status, month_prefix. Returns: result
list_leave_requestsC
List leave requests with optional status and employee filters.
Inputs: status, employee_id. Returns: result
review_leave_requestC
Approve or reject a submitted leave request.
Inputs: action (required), request_id (required), remarks. Returns: result
submit_leave_requestC
Apply for a new leave request.
Inputs: reason (required), end_date (required), leave_type (required), start_date (required), +1 more. Returns: result
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 6 tools
Most tools target clearly distinct operations (balance check, submit, review, list, date availability). However, get_employee_leave_dates overlaps somewhat with list_leave_requests filtered by employee, and check_date_availability vs. get_employee_leave_dates differ mainly in query axis, which could confuse an agent at the edges.
All six tools follow a consistent snake_case verb_noun pattern (check_, submit_, review_, get_, list_). The verb prefixes are intuitive and predictable across the set.
Six tools is well-scoped for a leave management server, with each tool covering a distinct part of the workflow. No bloat and no obviously redundant tools.
The core lifecycle is covered: check balance, submit, review, list, and query dates/availability. Minor gaps remain, such as withdrawing/canceling a request or updating a pending one, which agents would have to work around.
Maintenance
Related MCP Connectors
Employee leave and PTO: requests, approvals, balances, who is out, and conflict checks.
Track and manage employee time off with quick balance lookups and streamlined applications. Find t…
MCP server exposing klokin time-tracking operations (employees, time entries, stores) to AI clients.
MCP server for Talenta — read employee, attendance, leave, payroll and recruitment data.
Related MCP Servers
- FlicenseNot gradedqualityDmaintenanceEnables natural-language-based employee leave management including leave balance checks, leave applications, approvals, and history retrieval through an MCP-compatible client.-
- FlicenseCqualityDmaintenanceEnables natural language leave management, allowing users to check leave balances, apply for leave, and retrieve leave history via MCP tools.3-
- FlicenseNot gradedqualityDmaintenanceExposes leave management APIs through MCP, enabling users to manage employee leave requests, approvals, and balances via natural language. It bridges Claude Desktop to a Flask backend with PostgreSQL persistence.-
- AlicenseBqualityDmaintenanceMCP server for managing employee leave requests, balances, and types with natural language, using a dummy in-memory database.6ISC