下一代DBA必备技能
相信很多DBA都有私人珍藏例如各种常用SQL, 以下是我的一些珍藏,都在github里需要随时可取:
《PostgreSQL (慢SQL|数据库整体变慢|性能抖动) 数据库性能分析与优化方法 - 珍藏级,建议收藏》 《PostgreSQL AB表切换最佳实践 - 提高切换成功率,杜绝雪崩 - 珍藏级》 《PostgreSQL 锁等待排查实践 - 珍藏级 - process xxx1 acquired RowExclusiveLock on relation xxx2 of database xxx3 after xxx4 ms at xxx》 《PostgreSQL 实时健康监控 大屏 - 高频指标 - 珍藏级》 《PostgreSQL 10 postgresql.conf 参数模板 - 珍藏级》 《PostgreSQL 锁等待监控 珍藏级SQL - 谁堵塞了谁》 《PostgreSQL 如何查找TOP SQL (例如IO消耗最高的SQL) (包含SQL优化内容) - 珍藏级 - 数据库慢、卡死、连接爆增、慢查询多、OOM、crash、in recovery、崩溃等怎么办?怎么优化?怎么诊断?》
前面一篇文章介绍了 深入浅出 MCP 与 ACP:AI 时代的「连接器」与「协作网」 , 这些协议就像AI和其他应用的粘合剂, 核心目的是加速AI化进程, 让AI应用可以安全可靠的调用外部工具, 与其他应用进行协作. 另外还有一篇:
为什么DBA会消失? 我的建议是什么? 我觉得在彻底消失之前, 可以再挣扎一下, 那就是如题所示自我革命: “下一代DBA必备技能: 开发MCP Server”.
甚至于, 开发MCP Server应该是数据库产品厂商自己的责任, 那就真没DBA啥事了. 就像openAPI一样, openMCP可能也会成为数据库产品的标配.
为了推进DBA AI化, 我们需要构建数据库的mcp server, 把过去的经验抽象成"function", 当然你也可以非常非常偷懒的进行抽象(开放所有SQL执行权限). 这样的话mcp client就可以通过mcp server开放的接口来接管数据库. 如果mcp server是高度抽象的,那么定制化任务剧本就更能体现DBA老手的能力了,剧本杀玩法参考:《留给DBA的时间不多了,PG智能体开源》
放眼望去:似乎各个行业都在打造人工岗位的AI替身。似乎各个应用都在开发mcp server,生怕被AI agent抛弃。
mcp 联通AI agent和应用则像bytebase dbhub (mcp server)提供的这张图, 非常形象:
+------------------+ +--------------+ +------------------+
| | | | | |
| | | | | |
| Claude Desktop +--->+ +--->+ PostgreSQL |
| | | | | |
| Cursor +--->+ DBHub +--->+ SQL Server |
| | | | | |
| Other MCP +--->+ +--->+ SQLite |
| Clients | | | | |
| | | +--->+ MySQL |
| | | | | |
| | | +--->+ Other Databases |
| | | | | |
+------------------+ +--------------+ +------------------+
MCP Clients MCP Server Databases复制
例如将open WebUI或数据库管理软件等类AI前端连接到某数据库mcp server,可实现在前端AI应用与数据库的结合:
https://mcp.so/server/open-webui-mcp-connector
mcp server 例子1 DBHub
https://github.com/modelcontextprotocol/servers 这个开源项目里展示了很多产品的mcp server, 包括数据库的.
bytebase DBHub是其中之一, 天舟老哥果然是非常赶潮流的存在, 下面是这个项目的readme, 关注Supported Matrix.

DBHub is a universal database gateway implementing the Model Context Protocol (MCP) server interface. This gateway allows MCP-compatible clients to connect to and explore different databases.
+------------------+ +--------------+ +------------------+
| | | | | |
| | | | | |
| Claude Desktop +--->+ +--->+ PostgreSQL |
| | | | | |
| Cursor +--->+ DBHub +--->+ SQL Server |
| | | | | |
| Other MCP +--->+ +--->+ SQLite |
| Clients | | | | |
| | | +--->+ MySQL |
| | | | | |
| | | +--->+ Other Databases |
| | | | | |
+------------------+ +--------------+ +------------------+
MCP Clients MCP Server Databases复制
Demo SSE Endpoint
https://demo.dbhub.ai/sse connects a sample employee database. You can point Cursor or MCP Inspector to it to see it in action.

Supported Matrix
Database Resources
db://schemas | |||||
db://schemas/{schemaName}/tables | |||||
db://schemas/{schemaName}/tables/{tableName} | |||||
db://schemas/{schemaName}/tables/{tableName}/indexes |
Database Tools
run_query | |||||
list_connectors |
Prompt Capabilities
generate_sql | |||||
explain_db |
Installation
Docker
# PostgreSQL example
docker run --rm --init \
--name dbhub \
--publish 8080:8080 \
bytebase/dbhub \
--transport sse \
--port 8080 \
--dsn "postgres://user:password@localhost:5432/dbname?sslmode=disable"复制
# Demo mode with sample employee database
docker run --rm --init \
--name dbhub \
--publish 8080:8080 \
bytebase/dbhub \
--transport sse \
--port 8080 \
--demo复制
NPM
# PostgreSQL example
npx @bytebase/dbhub --transport sse --port 8080 --dsn "postgres://user:password@localhost:5432/dbname"复制
# Demo mode with sample employee database
npx @bytebase/dbhub --transport sse --port 8080 --demo复制
Note: The demo mode includes a bundled SQLite sample "employee" database with tables for employees, departments, salaries, and more.
Claude Desktop

Claude Desktop only supports stdio
transport https://github.com/orgs/modelcontextprotocol/discussions/16
// claude_desktop_config.json
{
"mcpServers": {
"dbhub-postgres-docker": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"bytebase/dbhub",
"--transport",
"stdio",
"--dsn",
// Use host.docker.internal as the host if connecting to the local db
"postgres://user:password@host.docker.internal:5432/dbname?sslmode=disable"
]
},
"dbhub-postgres-npx": {
"command": "npx",
"args": [
"-y",
"@bytebase/dbhub",
"--transport",
"stdio",
"--dsn",
"postgres://user:password@localhost:5432/dbname?sslmode=disable"
]
},
"dbhub-demo": {
"command": "npx",
"args": ["-y", "@bytebase/dbhub", "--transport", "stdio", "--demo"]
}
}
}复制
Cursor

Cursor supports both stdio
andsse
.Follow Cursor MCP guide and make sure to use Agent mode.
Usage
Configure your database connection
You can use DBHub in demo mode with a sample employee database for testing:
pnpm dev --demo
复制
For real databases, a Database Source Name (DSN) is required. You can provide this in several ways:
Command line argument (highest priority):
pnpm dev --dsn "postgres://user:password@localhost:5432/dbname?sslmode=disable"
复制Environment variable (second priority):
export DSN="postgres://user:password@localhost:5432/dbname?sslmode=disable"
pnpm dev复制Environment file (third priority):
DSN=postgres://user:password@localhost:5432/dbname?sslmode=disable
复制For development: Create .env.local
with your DSNFor production: Create .env
with your DSN
DBHub supports the following database connection string formats:
postgres://[user]:[password]@[host]:[port]/[database] | postgres://user:password@localhost:5432/dbname?sslmode=disable | |
sqlite:///[path/to/file] sqlite::memory: | sqlite:///path/to/database.db sqlite::memory: | |
sqlserver://[user]:[password]@[host]:[port]/[database] | sqlserver://user:password@localhost:1433/dbname | |
mysql://[user]:[password]@[host]:[port]/[database] | mysql://user:password@localhost:3306/dbname |
Transport
stdio (default) - for direct integration with tools like Claude Desktop:
npx @bytebase/dbhub --transport stdio --dsn "postgres://user:password@localhost:5432/dbname?sslmode=disable"
复制sse - for browser and network clients:
npx @bytebase/dbhub --transport sse --port 5678 --dsn "postgres://user:password@localhost:5432/dbname?sslmode=disable"
复制
Command line options
false | ||
stdio or sse | stdio | |
--transport=sse ) | 8080 |
The demo mode uses an in-memory SQLite database loaded with the sample employee database that includes tables for employees, departments, titles, salaries, department employees, and department managers. The sample database includes SQL scripts for table creation, data loading, and testing.
Development
Install dependencies:
pnpm install
复制Run in development mode:
pnpm dev
复制Build for production:
pnpm build
pnpm start --transport stdio --dsn "postgres://user:password@localhost:5432/dbname?sslmode=disable"复制
Debug with MCP Inspector
stdio
# PostgreSQL example
TRANSPORT=stdio DSN="postgres://user:password@localhost:5432/dbname?sslmode=disable" npx @modelcontextprotocol/inspector node path/to/dbhub/dist/index.js复制
SSE
# Start DBHub with SSE transport
pnpm dev --transport=sse --port=8080
# Start the MCP Inspector in another terminal
npx @modelcontextprotocol/inspector复制
Connect to the DBHub server /sse
endpoint
mcp server 例子2 mcp_server_milvus
milvus的 mcp server非常值得学习, 如果你想自己开发mcp server, 建议可以学习一下, 以下是这个项目的readme
MCP Server for Milvus
The Model Context Protocol (MCP) is an open protocol that enables seamless integration between LLM applications and external data sources and tools. Whether you're building an AI-powered IDE, enhancing a chat interface, or creating custom AI workflows, MCP provides a standardized way to connect LLMs with the context they need.
This repository contains a MCP server that provides access to Milvus vector database functionality.
Prerequisites
Before using this MCP server, ensure you have:
Python 3.10 or higher A running Milvus instance (local or remote) uv installed (recommended for running the server)
Usage
The recommended way to use this MCP server is to run it directly with uv
without installation. This is how both Claude Desktop and Cursor are configured to use it in the examples below.
If you want to clone the repository:
git clone https://github.com/zilliztech/mcp-server-milvus.git
cd mcp-server-milvus复制
Then you can run the server directly:
uv run src/mcp_server_milvus/server.py --milvus-uri http://localhost:19530
复制
Supported Applications
This MCP server can be used with various LLM applications that support the Model Context Protocol:
Claude Desktop: Anthropic's desktop application for Claude Cursor: AI-powered code editor with MCP support in its Composer feature Custom MCP clients: Any application implementing the MCP client specification
Usage with Claude Desktop
Install Claude Desktop from https://claude.ai/download
Open your Claude Desktop configuration:
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Add the following configuration:
{
"mcpServers": {
"milvus": {
"command": "/PATH/TO/uv",
"args": [
"--directory",
"/path/to/mcp-server-milvus/src/mcp_server_milvus",
"run",
"server.py",
"--milvus-uri",
"http://localhost:19530"
]
}
}
}复制
Restart Claude Desktop
Usage with Cursor
Cursor also supports MCP tools through its Agent feature in Composer. You can add the Milvus MCP server to Cursor in two ways:
Option 1: Using Cursor Settings UI
Go to
Cursor Settings
>Features
>MCP
Click on the
+ Add New MCP Server
buttonFill out the form:
⚠️ Note: Use
127.0.0.1
instead oflocalhost
to avoid potential DNS resolution issues.Type: Select stdio
(since you're running a command)Name: milvus
Command: /PATH/TO/uv --directory path/to/mcp-server-milvus/src/mcp_server_milvus run server.py --milvus-uri http://127.0.0.1:19530
Option 2: Using Project-specific Configuration (Recommended)
Create a .cursor/mcp.json
file in your project root:
Create the
.cursor
directory in your project root:mkdir -p path/to/your/project/.cursor
复制Create a
mcp.json
file with the following content:{
"mcpServers": {
"milvus": {
"command": "/PATH/TO/uv",
"args": [
"--directory",
"/path/to/mcp-server-milvus/src/mcp_server_milvus",
"run",
"server.py",
"--milvus-uri",
"http://127.0.0.1:19530"
]
}
}
}复制Restart Cursor or reload the window
After adding the server, you may need to press the refresh button in the MCP settings to populate the tool list. The Composer Agent will automatically use the Milvus tools when relevant to your queries.
Verifying the Integration
To verify that Cursor has successfully integrated with your Milvus MCP server:
Open Cursor Settings > Features > MCP Check that "Milvus" appears in the list of MCP servers Verify that the tools are listed (e.g., milvus_list_collections, milvus_vector_search, etc.) If the server is enabled but shows an error, check the Troubleshooting section below
Available Tools
The server provides the following tools:
Search and Query Operations
milvus_text_search
: Search for documents using full text searchcollection_name
: Name of collection to searchquery_text
: Text to search forlimit
: Maximum results (default: 5)output_fields
: Fields to include in resultsdrop_ratio
: Proportion of low-frequency terms to ignore (0.0-1.0)Parameters: milvus_vector_search
: Perform vector similarity search on a collectioncollection_name
: Name of collection to searchvector
: Query vectorvector_field
: Field containing vectors to search (default: "vector")limit
: Maximum results (default: 5)output_fields
: Fields to include in resultsmetric_type
: Distance metric (COSINE, L2, IP) (default: "COSINE")Parameters: milvus_query
: Query collection using filter expressionscollection_name
: Name of collection to queryfilter_expr
: Filter expression (e.g. 'age > 20')output_fields
: Fields to include in resultslimit
: Maximum results (default: 10)Parameters:
Collection Management
milvus_list_collections
: List all collections in the databasemilvus_create_collection
: Create a new collection with specified schemacollection_name
: Name for the new collectioncollection_schema
: Collection schema definitionindex_params
: Optional index parametersParameters: milvus_load_collection
: Load a collection into memory for search and querycollection_name
: Name of collection to loadreplica_number
: Number of replicas (default: 1)Parameters: milvus_release_collection
: Release a collection from memorycollection_name
: Name of collection to releaseParameters:
Data Operations
milvus_insert_data
: Insert data into a collectioncollection_name
: Name of collectiondata
: Dictionary mapping field names to lists of valuesParameters: milvus_delete_entities
: Delete entities from a collection based on filter expressioncollection_name
: Name of collectionfilter_expr
: Filter expression to select entities to deleteParameters:
Environment Variables
MILVUS_URI
: Milvus server URI (can be set instead of --milvus-uri)MILVUS_TOKEN
: Optional authentication tokenMILVUS_DB
: Database name (defaults to "default")
Development
To run the server directly:
uv run server.py --milvus-uri http://localhost:19530
复制
Examples
Using Claude Desktop
Example 1: Listing Collections
What are the collections I have in my Milvus DB?
复制
Claude will then use MCP to check this information on your Milvus DB.
I'll check what collections are available in your Milvus database.
Here are the collections in your Milvus database:
1. rag_demo
2. test
3. chat_messages
4. text_collection
5. image_collection
6. customized_setup
7. streaming_rag_demo复制
Example 2: Searching for Documents
Find documents in my text_collection that mention "machine learning"
复制
Claude will use the full-text search capabilities of Milvus to find relevant documents:
I'll search for documents about machine learning in your text_collection.
> View result from milvus-text-search from milvus (local)
Here are the documents I found that mention machine learning:
[Results will appear here based on your actual data]复制
Using Cursor
Example: Creating a Collection
In Cursor's Composer, you can ask:
Create a new collection called 'articles' in Milvus with fields for title (string), content (string), and a vector field (128 dimensions)
复制
Cursor will use the MCP server to execute this operation:
I'll create a new collection called 'articles' with the specified fields.
Collection 'articles' has been created successfully with the following schema:
- title: string
- content: string
- vector: float vector[128]复制
Troubleshooting
Common Issues
Connection Errors
If you see errors like "Failed to connect to Milvus server":
Verify your Milvus instance is running: docker ps
(if using Docker)Check the URI is correct in your configuration Ensure there are no firewall rules blocking the connection Try using 127.0.0.1
instead oflocalhost
in the URI
Authentication Issues
If you see authentication errors:
Verify your MILVUS_TOKEN
is correctCheck if your Milvus instance requires authentication Ensure you have the correct permissions for the operations you're trying to perform
Tool Not Found
If the MCP tools don't appear in Claude Desktop or Cursor:
Restart the application Check the server logs for any errors Verify the MCP server is running correctly Press the refresh button in the MCP settings (for Cursor)
Getting Help
If you continue to experience issues:
Check the GitHub Issues for similar problems Join the Zilliz Community Discord for support File a new issue with detailed information about your problem
参考
如果你对function call, tools call没什么概念, 可以看一下mistral下面这个文档:
https://docs.mistral.ai/capabilities/function_calling/
https://github.com/zilliztech/mcp-server-milvus/blob/main/src/mcp_server_milvus/server.py
https://github.com/modelcontextprotocol/servers/tree/main/src/postgres
https://mcp.so/server/postgres
https://github.com/bytebase/dbhub/
https://github.com/nahmanmate/postgresql-mcp-server