The Model Context Protocol (MCP) is revolutionizing how AI assistants interact with external systems and data sources. Instead of being limited to their training data, AI models can now access real-time information and perform actions through MCP servers. In this guide, we'll build a MCP server for employee management that integrates with data sources like a PostgreSQL database.
MCP is an open protocol that enables AI assistants like Claude to connect to external data sources and tools. Think of it as a bridge between AI and your applications - allowing the AI to read databases, call APIs, and perform complex operations on your behalf.
Key Benefits:
Our employee management MCP server will provide these powerful tools:
Before we start, make sure you have:
Create the MCP server using the official TypeScript template:
npx @modelcontextprotocol/create-server employee-server
cd employee-server
npm install pg @types/pg dotenv
This creates a well-structured project with all the necessary MCP server boilerplate and PostgreSQL dependencies.
If you have Docker, start a PostgreSQL container:
docker run --name postgres -e POSTGRES_PASSWORD=postgres -p 5432:5432 -d postgres
Create the database and tables:
docker exec -it postgres psql -U postgres -c "CREATE DATABASE employee_management;"
docker exec -i postgres psql -U postgres -d employee_management < database/setup.sql
The setup script creates 4 tables (employees, leave_types, leave_balances, leave_applications) and inserts sample data including 8 employees across different departments.
Create a .env
file with your database credentials:
cp .env.example .env
Update the .env
file with your database connection details:
DB_HOST=localhost
DB_PORT=5432
DB_NAME=employee_management
DB_USER=postgres
DB_PASSWORD=postgres
The project structure includes:
Build the TypeScript project:
npm run build
Test the server connection:
node build/index.js
You should see: "Database connection successful" and "Employee Management MCP server running on stdio"
Configure Claude Desktop to use your MCP server. Edit the configuration file:
macOS:
code ~/Library/Application\ Support/Claude/claude_desktop_config.json
Note: If you select yes to Would you like to add this server to Claude Desktop
option, you can skip above step.
Windows:
code %AppData%\Claude\claude_desktop_config.json
Add your server configuration:
{
"mcpServers": {
"employee-server": {
"command": "node",
"args": ["/absolute/path/to/employee-server/build/index.js"],
"env": {
"DB_HOST": "localhost",
"DB_PORT": "5432",
"DB_NAME": "employee_management",
"DB_USER": "postgres",
"DB_PASSWORD": "postgres"
}
}
}
}
Important: Use the absolute path to your project directory.
Restart Claude Desktop completely. You should now see the MCP tools available in the interface.
Test with these commands:
Server not appearing in Claude Desktop:
# Check Claude Desktop logs
tail -f ~/Library/Logs/Claude/mcp*.log
Database connection issues:
# Test PostgreSQL connection
psql -h localhost -p 5432 -U postgres -d employee_management -c "SELECT COUNT(*) FROM employees;"
Build errors:
# Clean and rebuild
rm -rf build/
npm run build
Building an MCP server opens up powerful possibilities, So do keep this in mind when you are building your next application
MCP servers have the following advantages: