Model Context Protocol (MCP) server for database operations
CoreMCP by CoreBaseHQ provides a secure, extensible bridge between AI assistants (like Claude Desktop) and your databases through the Model Context Protocol.
- π Multiple Database Support: MSSQL, Firebird (coming soon), and extensible adapter system
- π§ Automatic Schema Discovery: CoreMCP automatically scans your database tables, columns, foreign keys, and descriptions to provide AI context
- π Column Comments Support: Extracts and presents database column comments/descriptions to the AI for better query understanding
- π οΈ Dynamic Tool Generation: Built-in tools for common operations (list tables, describe schema) plus custom tool support
- π― Custom Query Tools: Define reusable SQL queries as MCP tools in your config file
- π‘οΈ Secure: Read-only mode support, connection string isolation
- π― MCP Native: Built specifically for Model Context Protocol
- π§ Easy Configuration: Simple YAML-based setup
- π¦ Lightweight: Single binary, no runtime dependencies
- Go 1.23 or higher (for building from source)
- Database drivers are embedded in the binary
git clone https://github.com/corebasehq/coremcp.git
cd coremcp
go build -o coremcp ./cmd/coremcpDownload the latest release from the Releases page.
Create a coremcp.yaml file in your working directory:
server:
name: "coremcp-agent"
version: "0.1.0"
transport: "stdio"
port: 8080
logging:
level: "info"
format: "json"
sources:
- name: "my_database"
type: "mssql"
dsn: "sqlserver://username:password@localhost:1433?database=mydb&encrypt=disable"
readonly: trueSee coremcp.example.yaml for more examples.
Microsoft SQL Server:
sqlserver://username:password@host:port?database=dbname&encrypt=disable
Dummy (for testing):
dummy://test
CoreMCP includes enterprise-grade security features:
security:
# Maximum rows to return (prevents DB overload)
max_row_limit: 1000
# Enable PII masking
enable_pii_masking: true
# PII patterns to mask
pii_patterns:
- name: "credit_card"
pattern: '\b\d{4}[\s-]?\d{4}[\s-]?\d{4}[\s-]?\d{4}\b'
replacement: "****-****-****-****"
enabled: true
- name: "email"
pattern: '\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b'
replacement: "***@***.***"
enabled: true
- name: "turkish_id"
pattern: '\b[1-9]\d{10}\b'
replacement: "***********"
enabled: trueSecurity Features:
- AST-Based Query Validation: Uses sqlparser to analyze SQL queries and block dangerous operations (DROP, ALTER, UPDATE, DELETE, TRUNCATE, EXEC, etc.)
- Automatic Row Limiting: Adds LIMIT clause to prevent accidentally returning millions of rows
- PII Data Masking: Automatically masks sensitive data like credit cards, emails, SSNs, Turkish IDs, IBANs
- Configurable Patterns: Define custom regex patterns for your specific PII requirements
CoreMCP has two operation modes:
Start the MCP Server locally:
coremcp serve --config coremcp.yamlOr use stdio transport (default):
coremcp serve -t stdioAdd to your Claude Desktop config (claude_desktop_config.json):
{
"mcpServers": {
"coremcp": {
"command": "/path/to/coremcp",
"args": ["serve", "-c", "/path/to/coremcp.yaml"],
"env": {}
}
}
}Connect to CoreBase Cloud Platform for remote management:
coremcp connect --server="wss://api.corebase.com/ws/agent" --token="sk_fabrika_123"Perfect for:
- π Factory Deployments: No need to open inbound ports
- π Remote Management: Control databases from anywhere
- π Secure: Agent initiates connection from inside your network
- π Auto-Reconnect: Automatic reconnection on network failures
- βοΈ Remote Config: Update database connections without redeployment
Flags:
-s, --server string CoreBase Cloud WebSocket URL (required)
-t, --token string Authentication token (required)
-a, --agent-id string Agent ID (optional, auto-generated if not provided)
-r, --max-reconnect int Maximum reconnection attempts (default: 10, 0 for infinite)
-d, --reconnect-delay duration Delay between reconnection attempts (default: 5s)# Factory IT admin runs this command
./coremcp connect \
--server="wss://api.corebasehq.com/ws/agent" \
--token="sk_fabrika_xyz" \
--agent-id="factory-istanbul-001" \
--max-reconnect=0 # Infinite reconnectionHow it works:
- π Agent connects to CoreBase Cloud via WebSocket (outbound only)
- π Authenticates with your API token
- π‘ Receives commands from your CoreBase dashboard
- π― Executes SQL queries on local databases
- π€ Sends results back through the secure tunnel
- π Auto-reconnects on connection loss
Remote Commands Supported:
run_sql: Execute SQL queries remotelyget_schema: Retrieve database schemalist_sources: List connected databaseshealth_check: Check agent statusconfig_sync: Update database configurations remotely
No Port Forwarding Required! π
coremcp/
βββ cmd/coremcp/ # CLI application entry point
β βββ main.go # Main entry
β βββ root.go # Root command
β βββ serve.go # Serve command (stdio mode for Claude Desktop)
β βββ connect.go # Connect command (WebSocket mode for Cloud)
βββ pkg/
β βββ adapter/ # Database adapters
β β βββ factory.go # Adapter factory pattern
β β βββ dummy/ # Dummy adapter (for testing)
β β βββ mssql/ # MSSQL adapter
β βββ config/ # Configuration management
β βββ core/ # Core type definitions
β βββ security/ # Security features (PII masking, query validation)
β βββ server/ # MCP server implementation
βββ coremcp.yaml # Configuration file
Executes arbitrary SQL queries on configured database sources.
Parameters:
source_name(required): Name of the database source from configquery(required): SQL query to execute
Example:
SELECT * FROM users WHERE id = 1Lists all tables in a database with summary information.
Parameters:
source_name(required): Name of the database source
Returns: List of tables with column counts, primary keys, and foreign key counts.
Shows detailed schema information for a specific table.
Parameters:
source_name(required): Name of the database sourcetable_name(required): Name of the table to describe
Returns: Complete table schema including:
- Column names and data types
- Nullable information
- Primary keys
- Foreign key relationships
- Column descriptions/comments
You can define reusable SQL queries as custom MCP tools in your coremcp.yaml:
custom_tools:
- name: "get_daily_sales"
description: "Retrieves daily sales summary for a specific date"
source: "production_db"
query: "SELECT * FROM orders WHERE DATE(created_at) = '{{date}}'"
parameters:
- name: "date"
description: "Date in YYYY-MM-DD format"
required: true
- name: "get_top_customers"
description: "Lists top N customers by order count"
source: "production_db"
query: "SELECT user_id, COUNT(*) as order_count FROM orders GROUP BY user_id ORDER BY order_count DESC LIMIT {{limit}}"
parameters:
- name: "limit"
description: "Number of customers to return"
required: true
default: "10"Benefits:
- Encapsulate complex queries
- Provide simple interfaces for common operations
- Parameters are automatically validated
- AI can discover and use these tools automatically
Automatically provides complete database schema context to the AI, including:
- Table names
- Column names with data types
- Primary keys
- Foreign key relationships
- Column descriptions/comments from the database
When CoreMCP starts, it automatically:
- Connects to all configured databases
- Scans the schema (tables, columns, keys, relationships)
- Extracts column comments/descriptions (e.g.,
MS_Descriptionin MSSQL) - Creates a comprehensive context prompt for the AI
This allows Claude to understand your database structure and write accurate queries without you having to explain the schema manually.
Example:
When you ask Claude "Show me all sales", Claude can see that you have a TBLSATIS table with specific columns and automatically write the correct query.
- Create a new package in
pkg/adapter/yourdb/ - Implement the
core.Sourceinterface - Register in
pkg/adapter/factory.go
See pkg/adapter/dummy/dummy.go for a simple example.
Contributions are welcome! Please read CONTRIBUTING.md for details.
For security concerns, please see SECURITY.md.
Apache License 2.0 - see LICENSE for details.
- Automatic Schema Discovery - Load database structure on startup
- Column Comments/Descriptions - Extract and display database metadata
- Dynamic Tool Generation - list_tables, describe_table tools
- Custom Query Tools - Define reusable queries in config
- AST-Based Query Sanitization - Block dangerous SQL operations
- PII Data Masking - Mask sensitive information in results
- Automatic Row Limiting - Prevent database overload
- WebSocket Connect Mode - Remote management via CoreBase Cloud π
- Auto-Reconnection Logic - Resilient agent connections
- Remote Configuration Sync - Update database configs remotely
- PostgreSQL adapter
- MySQL adapter
- Firebird adapter (in progress)
- Query result caching
- HTTP transport support
- Write operation support (with strict safety guards)
- Audit logging
- Multi-tenant agent management
- Real-time monitoring dashboard
- π Report a bug
- π‘ Request a feature
- π§ Email: support@corebasehq.com
Made with β€οΈ by CoreBaseHQ