想要在Agent中操作数据库怎么办?一个个的对接不同的数据库工具、处理各种业务要求吗,显然这样十分繁琐,不然也不会出来Spring jbdc template这样模版库。
近日,Google瞄准AI应用集成数据库这一痛点,开源一个新项目genai-toolbox,它是一个专为数据库设计的MCP服务器,让开发者能够用不到10行代码就将数据库工具集成到AI应用中。

传统方式需要处理连接池管理、身份验证、可观测性等复杂问题,而Toolbox将这些统一封装,提供了简化开发、性能优化、安全增强三大核心价值。该项目最大的创新在于其动态工具注册机制。每个工具包都能自动注册到中央注册表,服务器配置代码通过注册表动态解码和初始化工具。这种设计大大简化了新工具的添加过程,实现了服务器配置与具体工具实现的解耦。
项目支持PostgreSQL、MySQL、BigQuery、Redis等主流数据库,通过统一的YAML配置文件即可定义数据源、工具和工具集。开发者只需配置tools.yaml文件,然后运行./toolbox –tools-file “tools.yaml”即可启动服务器。
tools.yaml:
sources:
my-pg-source:
kind: postgres
host: 127.0.0.1
port: 5432
database: toolbox_db
user: ${USER_NAME}
password: ${PASSWORD}
tools:
search-hotels-by-name:
kind: postgres-sql
source: my-pg-source
description: Search for hotels based on name.
parameters:
- name: name
type: string
description: The name of the hotel.
statement: SELECT * FROM hotels WHERE name ILIKE '%' || $1 || '%';
search-hotels-by-location:
kind: postgres-sql
source: my-pg-source
description: Search for hotels based on location.
parameters:
- name: location
type: string
description: The location of the hotel.
statement: SELECT * FROM hotels WHERE location ILIKE '%' || $1 || '%';
book-hotel:
kind: postgres-sql
source: my-pg-source
description: >-
Book a hotel by its ID. If the hotel is successfully booked, returns a NULL, raises an error if not.
parameters:
- name: hotel_id
type: string
description: The ID of the hotel to book.
statement: UPDATE hotels SET booked = B'1' WHERE id = $1;
toolsets:
my-toolset:
- search-hotels-by-name
- search-hotels-by-location
- book-hotel
然后在Python应用中轻松调用:
from toolbox_core import ToolboxClient
async with ToolboxClient("http://127.0.0.1:5000") as client:
tools = await client.load_toolset("my-toolset")
同时,支持Python和JavaScript两套完整SDK,覆盖LangChain、LlamaIndex、Genkit等主流AI框架。Python开发者可通过pip install toolbox-core快速集成,JavaScript开发者则使用npm install @toolbox-sdk/core。
想要客户端连接,也很方便,以下是MCP配置:
{
"mcpServers": {
"toolbox": {
"type": "sse",
"url": "http://127.0.0.1:5000/mcp/sse",
}
}
}
项目还提供了容器化部署和二进制安装两种方式,支持Linux/ARM64多平台架构,满足不同部署需求。
同时,项目在企业级特性保障上,MCP Toolbox内置了连接池管理、OpenTelemetry可观测性、企业级安全认证等生产环境必需特性。
项目地址:https://github.com/googleapis/genai-toolbox
公众号回复“进群”入群讨论。
(文:AI工程化)