KYC MCP Server
Enables KYC (Know Your Customer) verification through API integration, supporting PAN card verification, PAN-Aadhaar link checking, and identity validation with advanced caching and rate limiting.
README
KYC MCP Server
A production-ready Model Context Protocol (MCP) server for KYC (Know Your Customer) API integration with advanced features including auto tool registry, caching, rate limiting, and comprehensive error handling.
Features
- ✅ Auto Tool Registry: Automatic tool discovery from metadata JSON files
- ✅ Advanced Caching: Redis-based caching with configurable TTL
- ✅ Rate Limiting: Per-tool rate limiting with token bucket algorithm
- ✅ JWT Authentication: Secure API authentication with token management
- ✅ Retry Logic: Exponential backoff for failed requests
- ✅ Structured Logging: Comprehensive logging with structlog
- ✅ Docker Ready: Full Docker and Docker Compose support
- ✅ Type Safety: Pydantic v2 for data validation
- ✅ Production Ready: Error handling, monitoring, and graceful shutdown
Implemented Tools
1. PAN Verification (verify_pan)
Verify PAN card details with name and date of birth matching.
Input:
pan: 10-character PAN number (e.g., "XXXPX1234A")name_as_per_pan: Full name as per PAN carddate_of_birth: Date of birth in DD/MM/YYYY formatconsent: User consent ('Y' or 'y')reason: Reason for verification
Output:
- PAN validation status
- Name and DOB match results
- Aadhaar seeding status
- PAN holder category
Cache TTL: 1 hour
2. PAN-Aadhaar Link Check (check_pan_aadhaar_link)
Check if PAN and Aadhaar are linked.
Input:
pan: Individual PAN number (4th character must be 'P')aadhaar_number: 12-digit Aadhaar numberconsent: User consent ('Y' or 'y')reason: Reason for checking
Output:
- Link status (linked/not linked)
- Descriptive message
Cache TTL: 2 hours
Architecture
kyc-mcp-server/
├── src/
│ ├── main.py # Application entry point
│ ├── server/
│ │ └── mcp_server.py # MCP server implementation
│ ├── tools/
│ │ ├── base_tool.py # Abstract base tool class
│ │ ├── pan_verification.py # PAN verification tool
│ │ └── pan_aadhaar_link.py # PAN-Aadhaar link tool
│ ├── registry/
│ │ └── tool_registry.py # Auto tool discovery & registration
│ ├── clients/
│ │ └── kyc_api_client.py # KYC API client with retry logic
│ ├── auth/
│ │ └── jwt_manager.py # JWT token management
│ ├── cache/
│ │ └── redis_cache.py # Redis caching layer
│ ├── models/
│ │ ├── requests.py # Request models
│ │ └── responses.py # Response models
│ └── utils/
│ ├── logger.py # Structured logging
│ └── rate_limiter.py # Rate limiting
├── config/
│ └── settings.py # Configuration management
├── metadata/
│ └── tools/ # Tool metadata JSON files
│ ├── pan_verification.json
│ └── pan_aadhaar_link.json
├── Dockerfile
├── docker-compose.yml
├── requirements.txt
└── .env.example
Installation
Prerequisites
- Python 3.11+
- Redis (for caching)
- KYC API credentials
Local Setup
- Clone the repository
git clone <repository-url>
cd kyc-mcp-server
- Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
- Install dependencies
pip install -r requirements.txt
- Configure environment
cp .env.example .env
# Edit .env with your credentials
- Start Redis
docker run -d -p 6379:6379 --name kyc-redis redis:7-alpine
- Run the server
python -m src.main
Docker Setup
- Configure environment
cp .env.example .env
# Edit .env with your credentials
- Build and run with Docker Compose
docker-compose up -d
- View logs
docker-compose logs -f kyc-mcp-server
- Stop the server
docker-compose down
Configuration
All configuration is managed through environment variables. See .env.example for all available options.
Key Configuration Options
| Variable | Description | Default |
|---|---|---|
KYC_API_BASE_URL |
KYC API base URL | Required |
KYC_API_KEY |
KYC API key | Required |
KYC_JWT_SECRET |
JWT secret for token generation | Required |
REDIS_HOST |
Redis host | localhost |
REDIS_PORT |
Redis port | 6379 |
CACHE_ENABLED |
Enable caching | true |
CACHE_DEFAULT_TTL |
Default cache TTL (seconds) | 3600 |
RATE_LIMIT_ENABLED |
Enable rate limiting | true |
RATE_LIMIT_PER_MINUTE |
Requests per minute | 60 |
RATE_LIMIT_PER_HOUR |
Requests per hour | 1000 |
LOG_LEVEL |
Logging level | INFO |
Usage
Using MCP Client
# Connect to the server
mcp-client connect stdio -- python -m src.main
# List available tools
mcp-client list-tools
# Call a tool
mcp-client call-tool verify_pan '{
"pan": "XXXPX1234A",
"name_as_per_pan": "John Doe",
"date_of_birth": "01/01/1990",
"consent": "Y",
"reason": "KYC verification"
}'
Example Tool Calls
PAN Verification
{
"tool": "verify_pan",
"arguments": {
"pan": "XXXPX1234A",
"name_as_per_pan": "John Doe",
"date_of_birth": "01/01/1990",
"consent": "Y",
"reason": "Customer onboarding"
}
}
Response:
{
"pan": "XXXPX1234A",
"category": "individual",
"status": "valid",
"remarks": null,
"name_match": true,
"dob_match": true,
"aadhaar_seeding_status": "y",
"verified_at": 1234567890,
"_cached": false
}
PAN-Aadhaar Link Check
{
"tool": "check_pan_aadhaar_link",
"arguments": {
"pan": "XXXPX1234A",
"aadhaar_number": "123456789012",
"consent": "Y",
"reason": "Link verification"
}
}
Response:
{
"linked": true,
"status": "y",
"message": "PAN and Aadhaar are linked",
"checked_at": 1234567890,
"_cached": false
}
Adding New Tools
The server uses an auto tool registry system. To add a new tool:
- Create tool class in
src/tools/
from src.tools.base_tool import BaseTool
class NewTool(BaseTool):
def get_name(self) -> str:
return "new_tool_name"
async def execute(self, params):
# Implementation
pass
- Create metadata file in
metadata/tools/
{
"name": "new_tool_name",
"description": "Tool description",
"input_schema": { ... },
"output_schema": { ... }
}
- Register tool in
src/main.py
new_tool = NewTool(api_client=self.api_client)
tool_registry.register_tool(new_tool)
- Restart server - Tool is automatically available!
Error Handling
The server provides comprehensive error handling:
- VALIDATION_ERROR: Invalid input parameters
- RATE_LIMIT_EXCEEDED: Rate limit exceeded
- TOOL_NOT_FOUND: Unknown tool requested
- EXECUTION_ERROR: Tool execution failed
- SERVICE_UNAVAILABLE: External API unavailable
All errors include descriptive messages and appropriate error codes.
Monitoring
Logs
Structured JSON logs are output to stdout:
{
"event": "tool_executed_successfully",
"tool": "verify_pan",
"timestamp": "2024-01-20T10:30:00Z",
"level": "info"
}
Metrics
The server exposes Prometheus-compatible metrics on port 9090 (configurable).
Performance
- Cache Hit Rate: >70% for repeated queries
- Response Time: <500ms (p95) for uncached requests
- Response Time: <10ms (p95) for cached requests
- Concurrent Requests: Supports 100+ concurrent requests
Security
- JWT-based authentication for API calls
- Input validation using Pydantic
- Rate limiting to prevent abuse
- Secure credential management via environment variables
- No sensitive data in logs
Troubleshooting
Redis Connection Failed
# Check if Redis is running
docker ps | grep redis
# Start Redis
docker run -d -p 6379:6379 redis:7-alpine
Rate Limit Exceeded
# Increase rate limits in .env
RATE_LIMIT_PER_MINUTE=120
RATE_LIMIT_PER_HOUR=2000
Tool Not Found
# Check metadata files exist
ls metadata/tools/
# Check tool registration in logs
docker-compose logs kyc-mcp-server | grep "tool_registered"
Development
Running Tests
# Install dev dependencies
pip install -r requirements-dev.txt
# Run tests
pytest tests/ -v
# Run with coverage
pytest tests/ --cov=src --cov-report=html
Code Quality
# Format code
black src/
# Lint code
ruff check src/
# Type checking
mypy src/
License
[Add your license here]
Support
For issues and questions:
- Create an issue in the repository
- Contact: [your-email@example.com]
Acknowledgments
Built with:
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。