by KWDB
Implements the Model Context Protocol to enable query execution, metadata retrieval, and prompt delivery for KWDB databases, delivering a uniform JSON API for read, write, and DDL operations.
Provides a Go‑based MCP server that parses MCP StdIO or HTTP requests, routes them to appropriate tools (read‑query, write‑query), automatically limits result sets, and returns consistent JSON responses. It also exposes MCP resources (product info, database metadata, table schema) and a collection of embedded prompts for common database tasks.
make deps && make build
./bin/kwdb-mcp-server "postgresql://user:pass@host:port/dbname?sslmode=disable"
CONNECTION_STRING="postgresql://..." PORT=8080 make run-http
make run-sse
./mcp
for HTTP) using the appropriate tool names (read-query
, write-query
) or resource URIs (kwdb://table/tablename
).LIMIT 20
to SELECT statements lacking a limit.isError
).mcp-go
framework and PostgreSQL driver lib/pq
.Q: Do I need to modify SQL queries manually to add a limit?
A: No. The server automatically appends LIMIT 20
to SELECT statements that lack a LIMIT clause.
Q: Can I run the server on Windows? A: Yes, as long as Go 1.23+ and the PostgreSQL driver are installed; the binary is OS‑agnostic.
Q: How are authentication credentials provided? A: Via the PostgreSQL connection string passed as the first argument when starting the server.
Q: Is SSE still supported? A: It works but is deprecated; HTTP mode is recommended.
Q: How do I add a new MCP prompt?
A: Add a Markdown file under pkg/prompts/docs/
, register it in pkg/prompts/prompts.go
, and rebuild the binary.
The KWDB MCP Server is a server implementation based on the MCP (Model Context Protocol) protocol, which provides a set of tools and resources for interacting with the KWDB database and providing business intelligence functionality through the MCP protocol. The KWDB MCP Server supports reading, writing, querying, modifying data, and performing DDL operations.
The core process of the KWDB MCP Server consists of the following components:
LIMIT 20
clause for SQL queries without a LIMIT
clause.SELECT
, SHOW
, EXPLAIN
, and other read-only queries.INSERT
, UPDATE
, DELETE
, and CREATE
, DROP
, ALTER
DDL operations.isError
flag.{
"content": [{"type": "text", "text": "Query error: error details"}],
"isError": true
}
{
"jsonrpc": "2.0",
"id": 1,
"error": {
"code": -32002, // RESOURCE_NOT_FOUND: resource does not exist
"message": "handler not found for resource URI 'kwdb://table/nonexistent': resource not found"
}
}
Or internal processing errors:
{
"jsonrpc": "2.0",
"id": 1,
"error": {
"code": -32603, // INTERNAL_ERROR: internal resource processing error
"message": "failed to get table schema for 'tablename': database connection error"
}
}
LIMIT 20
clause to SELECT
queries without a LIMIT
clause.The KWDB MCP Server provides the following security measures:
MCP Resources allow the KWDB MCP Server to expose data and content that can be read by MCP clients and used as context for LLM interactions. The KWDB MCP Server provides the following MCP Resources:
Resources | URI Format | Description | Example |
---|---|---|---|
Product information | kwdb://product_info |
Product information, including the version and supported features | kwdb://product_info/ |
Database metadata | kwdb://db_info/{database_name} |
Information about a specific database, including the engine type, comments, and tables | kwdb://db_info/db_shig |
Table schema | kwdb://table/{table_name} |
Schema of a specific table, including columns and example queries | kwdb://table/user_profile |
The MCP Tools enable the KWDB MCP Server to expose executable functionality to MCP clients. Through MCP Tools, LLMs can interact with external systems. The KWDB MCP Server provides the following MCP Tools.
The KWDB MCP Server executes the SELECT
, SHOW
, EXPLAIN
statements, and other read-only queries to read data from the database. The read_query
function returns the query results in a format of array for your SQL statement. In addition, the KWDB MCP Server will automatically add the LIMIT 20
clause to SELECT
queries without a LIMIT
clause to prevent large result sets.
Examples:
-- Query table data.
SELECT * FROM users LIMIT 10;
-- List all created tables.
SHOW TABLES;
-- Execute a SQL query and generate details about the SQL query.
EXPLAIN ANALYZE SELECT * FROM orders WHERE user_id = 1;
The KWDB MCP Server executes data modification queries, including DML and DDL operations.
Examples:
-- Insert data into the table.
INSERT INTO users (name, email) VALUES ('John Doe', 'john@example.com');
-- Update data in the table.
UPDATE users SET email = 'new-email@example.com' WHERE id = 1;
-- Remove data from the table.
DELETE FROM users WHERE id = 1;
-- Create a table.
CREATE TABLE products (id SERIAL PRIMARY KEY, name TEXT, price DECIMAL);
-- Add a column to a table.
ALTER TABLE products ADD COLUMN description TEXT;
-- Remove a table.
DROP TABLE products;
MCP Prompts enable the KWDB MCP Server to define reusable prompt templates and workflows that MCP clients can easily surface to users and LLMs. They provide a powerful way to standardize and share common LLM interactions. The KWDB MCP Server provides the following MCP Prompts:
Type | Prompt Name | Description |
---|---|---|
Database description | db_description |
A comprehensive description of KWDB database, including core functions, supported features, and use cases. |
Syntax guide | syntax_guide |
A comprehensive syntax guide for KWDB, including examples of common queries and best practices. |
Cluster management | cluster_management |
A comprehensive guide for managing KWDB clusters, including node management, load balancing, and monitoring. |
Data migration | data_migration |
A guide for migrating data to and from KWDB, including import/export methods and best practices. |
Installation | installation |
A step-by-step guide for installing and deploying KWDB in various environments. |
Performance tunning | performance_tuning |
A guide for optimizing KWDB performance, including query optimization, indexing strategies, and system-level tuning. |
Troubleshooting | troubleshooting |
A guide for diagnosing and resolving common KWDB issues and errors. |
Backup and restore | backup_restore |
A comprehensive guide for backing up and restoring KWDB databases, including strategies, tools, and best practices. |
DBA templates | dba_template |
Templates and guidelines for MCP Prompts writing. |
The MCP Prompts are Markdown files stored in the pkg/prompts/docs/
directory. These files are embedded into the binary when compiling the KWDB MCP Server using Go's embed
package. Currently, the KWDB MCP Server provides the following Prompts files:
pkg/prompts/docs/ReadExamples.md
: contain read query examples (using the SELECT
statement).pkg/prompts/docs/WriteExamples.md
: contain write query examples (using the INSERT
, UPDATE
, DELETE
, CREATE
, ALTER
statements).pkg/prompts/docs/DBDescription.md
: contain the database description.pkg/prompts/docs/SyntaxGuide.md
: contain the SQL syntax guide.pkg/prompts/docs/ClusterManagementGuide.md
: contain the cluster management guide.pkg/prompts/docs/DataMigrationGuide.md
: contain the data migration guide.pkg/prompts/docs/InstallationGuide.md
: contain the installation guide.pkg/prompts/docs/PerformanceTuningGuide.md
: contain the performance tuning guide.pkg/prompts/docs/TroubleShootingGuide.md
: contain the troubleshooting guide.pkg/prompts/docs/BackupRestoreGuide.md
: contain the backup and restore guide.pkg/prompts/docs/DBATemplate.md
: contain the database administration template.To add MCP Prompts, follow these steps:
pkg/prompts/docs/
directory, such as new_usecase.md
.pkg/prompts/prompts.go
file.registerUseCasePrompts()
in the pkg/prompts/prompts.go
file.README
file.For details about how to add MCP Prompts, see comments in the pkg/prompts/prompts.go
file.
To modify MCP Prompts, follow these steps:
pkg/prompts/docs/
directory.make build
command to rebuild the application. The updated MCP Prompts will be embedded in the binary.lib/pq
.Clone the repository.
git clone https://gitee.com/kwdb/kwdb-mcp-server
cd kwdb-mcp-server
Install dependencies.
make deps
Build the application.
make build
If you succeed, the application adopts the following structure.
kwdb-mcp-server/
├── bin/
│ └── kwdb-mcp-server # Binary executable file
├── cmd/
│ └── kwdb-mcp-server/
│ └── main.go # The main application
├── pkg/
│ ├── db/
│ │ └── db.go # Database operations
│ ├── prompts/
│ │ ├── prompts.go # MCP Prompts
│ │ └── docs/ # MCP Prompts files
│ │ ├── ReadExamples.md # Read query examples
│ │ ├── WriteExamples.md # Write query examples
│ │ ├── DBDescription.md # Database descriptions
│ │ ├── SyntaxGuide.md # SQL Syntax guide
│ │ ├── ClusterManagementGuide.md # Cluster management guide
│ │ ├── DataMigrationGuide.md # Data migration guide
│ │ ├── InstallationGuide.md # Installation guide
│ │ ├── PerformanceTuningGuide.md # Performance tunning
│ │ ├── TroubleShootingGuide.md # Troubleshooting guide
│ │ ├── BackupRestoreGuide.md # Backup and restore guide
│ │ └── DBATemplate.md # DBA templates
│ ├── resources/
│ │ └── resources.go # MCP Resources
│ ├── server/
│ │ └── server.go # KWDB MCP Server configurations
│ ├── tools/
│ │ └── tools.go # MCP Tools
│ └── version/
│ └── version.go # Version information
├── Makefile # Commands for building and running the KWDB MCP Server
└── README.md # README file
The KWDB MCP Server supports three transport modes:
Run the KWDB MCP Server with a PostgreSQL connection string:
./bin/kwdb-mcp-server "postgresql://<username>:<password>@<hostname>:<port>/<database_name>?sslmode=disable"
Run the KWDB MCP Server using the Makefile:
CONNECTION_STRING="postgresql://<username>:<password>@<hostname>:<port>/<database_name>?sslmode=disable" make run
Parameters:
username
: Username for connecting to the KWDB database.password
: Password for authentication.hostname
: IP address of the KWDB database.port
: Port for connecting to the KWDB database.database_name
: Name of the KWDB database to access.sslmode
: SSL mode. Supported values: disable
, allow
, prefer
, require
, verify-ca
, verify-full
. For details, see SSL Mode Parameters.Run the KWDB MCP Server in HTTP mode:
CONNECTION_STRING="postgresql://<username>:<password>@<hostname>:<port>/<database_name>?sslmode=disable" PORT=8080 make run-http
The HTTP service listens on 0.0.0.0:<port>
by default, and the MCP endpoint is http://<host>:<port>/mcp
.
Parameters:
-t
or --transport
: Transport type, supports stdio
, sse
, http
.
stdio
: Standard input/output modesse
: SSE mode (deprecated)http
: HTTP mode (recommended)-p
or --port
: Listening port for KWDB MCP Server, default is 8080
.username
: Username for connecting to the KWDB database.password
: Password for authentication.hostname
: IP address of the KWDB database.port
: Port for connecting to the KWDB database.database_name
: Name of the KWDB database to access.sslmode
: SSL mode. Supported values: disable
, allow
, prefer
, require
, verify-ca
, verify-full
. For details, see SSL Mode Parameters.Note
SSE mode is deprecated and will be removed in future releases. Please use HTTP mode if possible.
Run the KWDB MCP Server in SSE mode:
CONNECTION_STRING="postgresql://<username>:<password>@<hostname>:<port>/<database_name>?sslmode=disable" PORT=8080 make run-sse
Parameters:
-t
or --transport
: Transport type, supports stdio
, sse
, http
.
stdio
: Standard input/output modesse
: SSE mode (deprecated)http
: HTTP mode (recommended)-p
or --port
: Listening port for KWDB MCP Server, default is 8080
.username
: Username for connecting to the KWDB database.password
: Password for authentication.hostname
: IP address of the KWDB database.port
: Port for connecting to the KWDB database.database_name
: Name of the KWDB database to access.sslmode
: SSL mode. Supported values: disable
, allow
, prefer
, require
, verify-ca
, verify-full
. For details, see SSL Mode Parameters.For details about how the KWDB MCP Server integerates with LLM Agents, see Integrate with LLM Agents.
For details about how to troubleshoot the KWDB MCP Server, see Troubleshooting.
For documentation about the KWDB MCP Server, see the KWDB Documentation Website.
Contributions are welcome! Please feel free to submit issues and pull requests.
This project is licensed under the MIT License.
kwdb-mcp-server is indexed and certified by MCP Review
Please log in to share your review and rating for this MCP.
Explore related MCPs that share similar capabilities and solve comparable challenges
by googleapis
An MCP server that streamlines database tool development by handling connection pooling, authentication, observability, and secure access, allowing agents to interact with databases via natural language.
by bytebase
Provides a universal gateway that lets MCP‑compatible clients explore and query MySQL, PostgreSQL, SQL Server, MariaDB, and SQLite databases through a single standardized interface.
by designcomputer
Enables secure interaction with MySQL databases via the Model Context Protocol, allowing AI applications to list tables, read contents, and execute queries safely.
by benborla
Provides read‑only access to MySQL databases for large language models, allowing schema inspection and safe execution of SQL queries.
by ClickHouse
Enables AI assistants to run read‑only ClickHouse queries, list databases and tables, and execute embedded chDB queries through an MCP interface.
by chroma-core
Offers an MCP server exposing Chroma's vector database capabilities for LLM applications, supporting collection and document management, multiple embedding functions, and flexible client types such as in‑memory, persistent, HTTP, and cloud.
by kiliczsh
Enables LLMs to interact with MongoDB databases via a standardized interface, offering schema inspection, query execution, aggregation, and write capabilities, with optional read‑only mode and smart ObjectId handling.
by domdomegg
Provides read and write access to Airtable bases for AI systems, enabling inspection of schemas and manipulation of records.
by XGenerationLab
A Model Context Protocol (MCP) server that enables natural language queries to databases