AI Integration (MCP Server)
Digital ID includes a Model Context Protocol (MCP) server that allows AI assistants like Cursor or Claude Desktop to interact with your Digital ID system directly.
Organisation-Wide Access Only
The MCP server only supports organisation-wide access for security. You must configure ORGANISATION_ID in your environment, and the server will automatically restrict all queries to that organisation only.
This ensures:
- Each MCP server instance can only access one organisation's data
- No risk of cross-organisation data access
- Safe for multi-tenant deployments
- Organisation-level security by design
Access Control: The MCP server requires database credentials and a configured ORGANISATION_ID. Once configured, it can only access data from the specified organisation. This makes it suitable for trusted administrators who need to query their organisation's data.
What is MCP?
The Model Context Protocol (MCP) is a standard protocol that allows AI assistants to access external data and perform actions through secure, standardised interfaces. The Digital ID MCP server provides AI assistants with tools to query employee data, verify ID cards, view verification logs, and perform administrative tasks.
Overview
The MCP server acts as a bridge between AI assistants and your Digital ID database, allowing natural language queries and automated tasks:
- Employee Lookups: Find employee information by ID, email, or reference number
- ID Card Verification: Verify ID cards using QR codes or NFC tokens
- Log Analysis: Query verification logs with filtering options
- Employee Management: List employees, view pending photo approvals, and manage ID cards
- Organisation Data: Access organisation information and structure
How It Works
The MCP server is a TypeScript/Node.js application that:
- Connects to Your Database: Uses MySQL connection to access Digital ID data securely
- Exposes Tools: Provides standardised tools that AI assistants can call (like functions)
- Communicates via JSON-RPC: Uses the Model Context Protocol standard over stdio (standard input/output)
- Returns Structured Data: Formats database results as JSON for AI assistants to process
Available Tools
The MCP server provides the following tools that AI assistants can use:
Employee Management
| Tool | Description | Parameters |
|---|---|---|
get_employee |
Get employee information | employee_id, email, employee_reference, organisation_id |
list_employees |
List employees with filters | organisation_id, is_active, has_photo, limit |
get_pending_photos |
Get employees with pending photo approvals | organisation_id |
Verification
| Tool | Description | Parameters |
|---|---|---|
verify_id_card |
Verify an ID card token | token, verification_type (qr/nfc/ble) |
get_verification_logs |
Get verification logs with filters | employee_id, organisation_id, verification_type, result, start_date, end_date, limit |
revoke_id_card |
Revoke an employee's ID card | employee_id, reason |
Organisation
| Tool | Description | Parameters |
|---|---|---|
get_organisation |
Get organisation information | organisation_id, domain |
Available Resources
In addition to tools, the MCP server provides resources that AI assistants can read:
digital-id://employees: List of all employees (limited to 1000 records)digital-id://organisations: List of all organisations
Setting Up the MCP Server
To use the MCP server with an AI assistant like Cursor or Claude Desktop, follow these steps:
Prerequisites
- Node.js 18+ installed on your system
- Access to the Digital ID database
- Database credentials (host, database name, username, password)
- An AI assistant that supports MCP (Cursor, Claude Desktop, etc.)
Step 1: Install Dependencies
- Navigate to the MCP server directory:
cd mcp-server - Install Node.js dependencies:
npm install
Step 2: Configure Environment
- Create a
.envfile in themcp-serverdirectory - Add your database credentials and organisation ID:
DB_HOST=localhost DB_NAME=digital_ids DB_USER=your_db_user DB_PASS=your_db_password ORGANISATION_ID=1 - Replace the values with your actual database credentials
- Required: Set
ORGANISATION_IDto the ID of the organisation whose data you want to access. The MCP server only supports organisation-wide access for security - all queries will be automatically filtered to this organisation.
Organisation-Wide Access Required
The MCP server requires ORGANISATION_ID to be set in your environment configuration. This ensures the server can only access data from that specific organisation, providing essential security for multi-tenant deployments.
When ORGANISATION_ID is configured:
- All employee queries are automatically filtered to the specified organisation
- Verification logs only show data from that organisation
- Only employees from that organisation can be revoked
- Resources (employees, organisations) only show data from that organisation
- The server will fail to start if
ORGANISATION_IDis not set
Example: If you set ORGANISATION_ID=5, the MCP server will only be able to access data from organisation ID 5, even if the database contains data from multiple organisations.
Multi-Organisation Deployments: If you need to access data from multiple organisations, you must set up separate MCP server instances, each with its own ORGANISATION_ID configuration.
Security Warning
Never commit the .env file to version control. It contains sensitive database credentials. The .gitignore file is already configured to exclude it.
Step 3: Build the Server
- Compile the TypeScript code:
npm run build - Verify the build succeeded - you should see a
dist/index.jsfile
Step 4: Test the Server
- Run the server to verify it works:
npm start - You should see "Digital ID MCP Server running on stdio"
- Press Ctrl+C to stop the server
Step 5: Configure Your AI Assistant
The configuration depends on which AI assistant you're using:
For Cursor
- Open Cursor settings
- Navigate to MCP settings (usually in Settings → Features → MCP)
- Add the following configuration to your MCP settings file:
{ "mcpServers": { "digital-id": { "command": "node", "args": ["/absolute/path/to/digital-id/mcp-server/dist/index.js"], "env": { "DB_HOST": "localhost", "DB_NAME": "digital_ids", "DB_USER": "your_db_user", "DB_PASS": "your_db_password", "ORGANISATION_ID": "1" } } } } - Important: Replace
/absolute/path/to/digital-idwith the actual absolute path to your project directory - Replace database credentials with your actual values
- Required: Add
"ORGANISATION_ID": "1"with your organisation ID (replace 1 with your actual organisation ID). The MCP server requires this to be set. - Restart Cursor for changes to take effect
For Claude Desktop
- Open Claude Desktop settings
- Navigate to MCP settings (usually in Settings → Developer → MCP)
- Add the same configuration as shown for Cursor above
- Use the absolute path to
dist/index.js - Restart Claude Desktop
Finding Your Path
On macOS/Linux, you can find the absolute path by running pwd in the terminal while in your project directory. On Windows, use the full path including the drive letter (e.g., C:\Users\YourName\digital-id\mcp-server\dist\index.js).
Using the MCP Server
Once configured, you can interact with your Digital ID system using natural language in your AI assistant:
Example Queries
- "Get employee information for john.doe@example.com"
- "Show me verification logs for organisation ID 1 from last month"
- "List all employees with pending photo approvals"
- "Verify this ID card token: abc123..."
- "How many active employees are in organisation 2?"
- "Show me all failed verifications from yesterday"
- "Revoke the ID card for employee ID 5, reason: employee left"
Architecture
Understanding how the MCP server works helps with troubleshooting and customisation:
Communication Flow
- AI Assistant: Receives user query in natural language
- AI Assistant: Decides which MCP tool to call based on the query
- MCP Server: Receives tool call request via JSON-RPC over stdio
- MCP Server: Executes database query using provided parameters
- MCP Server: Formats results as JSON
- AI Assistant: Receives structured data and presents it to the user
Database Connection
The server maintains a single MySQL connection that is reused for all requests. The connection is created on first use and persists for the lifetime of the server process.
Error Handling
All errors are caught and returned in a standardised format that AI assistants can understand. Database errors, validation errors, and missing data are all handled gracefully.
Development Mode
For development, you can use watch mode to automatically rebuild when code changes:
npm run dev
This runs TypeScript compiler in watch mode, automatically recompiling when you save changes to src/index.ts.
Adding New Tools
To add custom functionality to the MCP server:
-
Add Tool Definition: Add a new tool object to the
ListToolsRequestSchemahandler insrc/index.ts- Define the tool name, description, and input schema
- Specify required and optional parameters
-
Implement Tool Handler: Add a case in the
CallToolRequestSchemahandler switch statement- Extract parameters from the request
- Execute database queries
- Return formatted JSON results
-
Rebuild: Run
npm run buildto compile changes - Restart: Restart your AI assistant to load the updated MCP server
Code Structure
The MCP server code is well-organised in src/index.ts. Tool definitions are at the top in the ListToolsRequestSchema handler, and implementations are in the CallToolRequestSchema handler. Follow the existing patterns for consistency.
Troubleshooting
Server Won't Start
- Check that Node.js 18+ is installed:
node --version - Verify database credentials in
.envfile - Ensure the database server is running and accessible
- Check network connectivity if using a remote database
"Cannot Find Module" Errors
- Run
npm installagain to ensure dependencies are installed - Verify you're in the
mcp-serverdirectory - Check that
dist/index.jsexists after building - Ensure
node_modulesdirectory exists
Database Connection Errors
- Verify database credentials are correct
- Check that the database server is running
- Ensure network access to the database (if remote)
- Verify database name, username, and password
- Check firewall settings if connecting remotely
Tools Not Appearing in AI Assistant
- Restart your AI assistant application completely
- Check the MCP configuration syntax is valid JSON
- Verify the path to
dist/index.jsis correct and absolute - Check AI assistant logs for MCP connection errors
- Ensure the MCP server starts without errors when tested manually
Tools Return Errors
- Check database schema matches what the code expects
- Verify table names and column names are correct
- Check database user has necessary permissions
- Review error messages in AI assistant output for details
Security Considerations
Organisation-Level Security
The MCP server enforces organisation-level access control. When configured with ORGANISATION_ID, the server automatically restricts all queries to that organisation only, ensuring:
- Single organisation access - Can only access the configured organisation's data
- No cross-organisation access - Cannot view other organisations' data
- Automatic filtering - All queries are filtered by organisation ID
- Safe for multi-tenant - Each organisation can have its own MCP server instance
Security Model: The MCP server requires database credentials and a configured ORGANISATION_ID. Once configured, it can only access data from the specified organisation. This provides organisation-level isolation for multi-tenant deployments.
Security Best Practices
To secure the MCP server, follow these recommendations:
-
Configure Organisation ID (Required): Set
ORGANISATION_IDin your environment - this is mandatory- The MCP server requires
ORGANISATION_IDto be set - it will not start without it - Automatically filters all queries to the specified organisation
- Prevents access to other organisations' data
- Essential for multi-tenant deployments
- Example: Add
ORGANISATION_ID=1to your.envfile
- The MCP server requires
-
Use Read-Only Database Users: For production, create a read-only database user that can only SELECT data, not modify it
- This prevents users from modifying data via the MCP server
- They can still query all data, but cannot revoke cards or make changes
- Example MySQL:
GRANT SELECT ON digital_ids.* TO 'mcp_readonly'@'localhost';
-
Restrict Database Access: Only provide database credentials to trusted administrators
- The MCP server is designed for administrators who already have database access
- Do not share database credentials with end users
- Use separate credentials for MCP server if possible
-
Protect Credentials: Never commit
.envfiles or database credentials to version control- The
.gitignorefile excludes.envfiles - Use secure methods to share credentials (password managers, secure channels)
- The
-
Network Security: The server runs locally via stdio (not HTTP), but still ensure network security
- MCP servers communicate via stdio, so they're not directly accessible over the network
- However, if database is remote, secure the database connection
- Use SSH tunnels or VPNs for remote database access
-
Audit Access: Monitor who has access to database credentials
- Keep records of who has database credentials
- Review database access logs regularly
- Rotate credentials periodically
-
Multi-Tenant Deployments: The MCP server is designed for organisation-wide access
ORGANISATION_IDis required - the server will not start without it- Each organisation must have its own MCP server instance with its own
ORGANISATION_ID - This ensures complete isolation between organisations
- No risk of cross-organisation data access
Organisation-Wide Access Enforced
The MCP server enforces organisation-wide access by requiring ORGANISATION_ID to be set. This ensures all queries are automatically filtered to the specified organisation, providing essential security for multi-tenant deployments. This feature is described in detail in the setup instructions above.
Future Improvements
Potential security enhancements for future versions could include:
- User-based authentication (require login credentials)
- Role-based access control (restrict certain tools based on user role)
- API keys for authentication
- Rate limiting to prevent abuse
Benefits of MCP Integration
- Natural Language Queries: Ask questions about your Digital ID system in plain English
- Quick Data Access: Instantly retrieve employee information without navigating the web interface
- Automated Tasks: Perform routine administrative tasks through AI assistants
- Data Analysis: Query verification logs and analyse patterns using natural language
- Integration: Connect Digital ID data with other tools and workflows
Use Cases
The MCP server is particularly useful for:
- Administrators who want to quickly look up employee information
- Analysing verification patterns and security events
- Integrating Digital ID data into automated workflows
- Building custom reports and dashboards
- Auditing and compliance reviews