MCP数据库工具箱
    
   
MCP Toolbox for Databases是一个开源的模型上下文协议(MCP)服务器,它将您的AI代理、IDE和应用程序直接连接到您的企业数据库。
它服务于 双重用途:
- 即用型MCP服务器(构建时): 使用我们的 *预构建的通用工具*。无需编写样板,即可与数据对话、探索模式并生成代码。
- 自定义工具框架(运行时): 一个强大的框架,为您的生产代理构建专业、高度安全的人工智能工具。安全轻松地定义结构化查询、语义搜索和NL2SQL功能。
此README提供了一个简要概述。有关详细信息,请参阅 全部文件.
\[!重要\]\ 存储库名称更新: 这genai-toolbox存储库已正式重命名为mcp-toolbox。为确保您的本地环境反映新名称,您可以更新您的远程:git remote set-url origin https://github.com/googleapis/mcp-toolbox.git
\[!注意\] 该解决方案最初名为“数据库的Gen AI工具箱”(github.com/googleapis/genai工具箱),因为其最初的开发早于MCP,但为了与MCP兼容而重命名。
目录
______________________________________________________________________
为什么选择MCP工具箱?
- 开箱即用的数据库访问: 用于即时数据探索的预构建通用工具(例如。,
list_tables,execute_sql)直接从IDE或CLI。 - 自定义工具框架: 使用您自己的预定义逻辑构建生产就绪工具,通过受限访问、结构化查询和语义搜索确保安全。
- 简化开发: 用不到10行代码将工具集成到您的代理开发工具包(ADK)、LangChain、LlamaIdex或自定义代理中。
- 更好的性能: 开箱即用地处理连接池、集成身份验证(IAM)和端到端可观察性(OpenTetry)。
- 增强安全性:集成身份验证,可更安全地访问您的数据。
- 端到端可观察性:开箱即用的指标和跟踪,内置对OpenTetry的支持。
______________________________________________________________________
快速入门:预构建工具
停止上下文切换,让你的AI助手成为真正的共同开发者。通过使用MCP Toolbox将IDE连接到数据库,您可以用简单的英语查询数据,自动化模式发现和管理,并生成支持数据库的代码。
通过配置MCP服务器,您可以在任何兼容MCP的IDE或客户端(例如Gemini CLI、Google Antigravity、Claude Code、Codex等)中使用工具箱。
预构建的工具也可以通过以下方式方便地获得 谷歌反重力MCP商店 只需简单的点击安装体验。
- 将以下内容添加到客户端的MCP配置文件中(通常
mcp.json或claude_desktop_config.json):
{
"mcpServers": {
"toolbox-postgres": {
"command": "npx",
"args": [
"-y",
"@toolbox-sdk/server",
"--prebuilt=postgres",
"--stdio"
]
}
}
}- 设置要连接的适当环境变量,请参阅 预构建工具参考.
当您使用以下命令运行工具箱时 --prebuilt= 标记后,您可以立即访问标准工具与该数据库进行交互。
目前支持的数据库包括:
- 谷歌云: AlloyDB、BigQuery、云SQL(PostgreSQL、MySQL、SQL Server)、Spanner、Firestore、知识目录(以前称为Dataplex)。
- 其他数据库: PostgreSQL、MySQL、SQL Server、Oracle、MongoDB、Redis、Elasticsearch、CockroachDB、ClickHouse、Couchbase、Neo4j、Snowflake、Trino等。
有关所有受支持数据库中可用工具及其功能的完整列表,请参阅 预构建工具参考.
*看 安装并运行工具箱服务器 部分介绍了不同的执行方法,如Docker或二进制文件。*
\[!提示\] 对于寻求托管解决方案的用户, 谷歌云MCP服务器 使用预构建的工具提供管理MCP体验;你可以 在此处了解更多差异.
______________________________________________________________________
快速入门:自定义工具
工具箱也可以用作定制工具的框架。 配置工具箱的主要方法是通过 tools.yaml 文件。如果你 如果有多个文件,您可以告诉工具箱用哪个文件加载 --config tools.yaml 旗帜。
您可以在 资源.
来源
这 sources 你的部分 tools.yaml 定义您的数据源 工具箱应该可以访问。大多数工具至少有一个源 执行反对。
kind: source
name: my-pg-source
type: postgres
host: 127.0.0.1
port: 5432
database: toolbox_db
user: toolbox_user
password: my-password有关配置不同类型源的更多详细信息,请参阅 来源.
工具
这 tools a部分 tools.yaml 定义代理可以采取的操作:什么 它是什么类型的工具,它影响哪个来源,它使用什么参数等。
kind: tool
name: search-hotels-by-name
type: 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 || '%';有关配置不同类型工具的更多详细信息,请参阅 工具.
工具集
这 toolsets 你的部分 tools.yaml 允许您定义工具组 你希望能够一起装载。这可用于定义 基于代理或应用程序的不同组。
kind: toolset
name: my_first_toolset
tools:
- my_first_tool
- my_second_tool
---
kind: toolset
name: my_second_toolset
tools:
- my_second_tool
- my_third_tool提示
这 prompts a部分 tools.yaml 定义可用于以下操作的提示 与LLM的互动。
kind: prompt
name: code_review
description: "Asks the LLM to analyze code quality and suggest improvements."
messages:
- content: >
Please review the following code for quality, correctness,
and potential improvements: \n\n{{.code}}
arguments:
- name: "code"
description: "The code to review"有关配置提示的更多详细信息,请参阅 提示.
______________________________________________________________________
安装并运行工具箱服务器
您可以直接使用 配置文件:
npx @toolbox-sdk/server --config tools.yaml这将使用您的配置文件运行最新版本的工具箱服务器。
\[!注意\] 这种方法是为了方便而不是为了性能而优化的。 为了更标准、更可靠的安装,请使用二进制 或容器图像,如所述 安装并运行工具箱服务器.
安装工具箱
有关最新版本,请查看 发布页面 并使用 按照操作系统和CPU架构的说明进行操作。
Binary
要将工具箱安装为二进制文件,请执行以下操作:
Linux (AMD64) 要在Linux(AMD64)上将工具箱作为二进制文件安装: ``sh # see releases page for other versions export VERSION=1.2.0 curl -L -o toolbox https://storage.googleapis.com/mcp-toolbox-for-databases/v$VERSION/linux/amd64/toolbox chmod +x toolbox`macOS (Apple Silicon) 要在macOS(Apple Silicon)上将Toolbox作为二进制文件安装:`sh # see releases page for other versions export VERSION=1.2.0 curl -L -o toolbox https://storage.googleapis.com/mcp-toolbox-for-databases/v$VERSION/darwin/arm64/toolbox chmod +x toolbox`macOS (Intel) 要在macOS(英特尔)上将工具箱作为二进制文件安装:`sh # see releases page for other versions export VERSION=1.2.0 curl -L -o toolbox https://storage.googleapis.com/mcp-toolbox-for-databases/v$VERSION/darwin/amd64/toolbox chmod +x toolbox`Windows (Command Prompt) 要在Windows上将工具箱作为二进制文件安装(命令提示符):`cmd :: see releases page for other versions set VERSION=1.2.0 curl -o toolbox.exe "https://storage.googleapis.com/mcp-toolbox-for-databases/v%VERSION%/windows/amd64/toolbox.exe"`Windows (PowerShell) 要在Windows(PowerShell)上将工具箱作为二进制文件安装,请执行以下操作:`powershell # see releases page for other versions $VERSION = "1.2.0" curl.exe -o toolbox.exe "https://storage.googleapis.com/mcp-toolbox-for-databases/v$VERSION/windows/amd64/toolbox.exe"``
Container image You can also install Toolbox as a container:
# see releases page for other versions
export VERSION=1.2.0
docker pull us-central1-docker.pkg.dev/database-toolbox/toolbox/toolbox:$VERSIONHomebrew
要在macOS或Linux上使用Homebrew安装工具箱:
brew install mcp-toolboxCompile from source
要从源代码安装,请确保您拥有最新版本的 去安装,然后运行以下命令:
go install github.com/googleapis/mcp-toolbox@v1.2.0Gemini CLI Check out the Gemini CLI extensions to install prebuilt tools for specific databases like AlloyDB, BigQuery, and Cloud SQL directly into Gemini CLI.
# Install Gemini CLI
npm install -g @google/gemini-cli
# Install the extension
gemini extensions install https://github.com/gemini-cli-extensions/cloud-sql-postgres
# Run Gemini CLI
gemini通过Gemini CLI使用自然语言与您的自定义工具进行交互。
# Install the extension
gemini extensions install https://github.com/gemini-cli-extensions/mcp-toolbox运行工具箱
配置 一 tools.yaml 定义你的工具,然后 执行 toolbox 要启动服务器,请执行以下操作:
Binary
要从二进制文件运行工具箱,请执行以下操作:
./toolbox --config "tools.yaml"ⓘ Note\ 默认情况下,工具箱启用动态重新加载。要禁用,请使用 --disable-reload 旗帜。Container image
在拉取后运行服务器 集装箱图像:
export VERSION=0.24.0 # Use the version you pulled
docker run -p 5000:5000 \
-v $(pwd)/tools.yaml:/app/tools.yaml \
us-central1-docker.pkg.dev/database-toolbox/toolbox/toolbox:$VERSION \
--config "/app/tools.yaml"ⓘ Note\ 这-v旗帜挂在当地tools.yaml放入容器中,以及-p地图 集装箱港口5000到主机的端口5000.
Source
要直接从源代码运行服务器,请导航到项目根目录 并运行:
go run .ⓘ Note\ 此命令从源代码运行项目,更适合开发 以及测试。确实如此 不 将二进制文件编译到您的 $GOPATH如果你愿意的话 要编译二进制文件,请参考 开发者 文档.Homebrew
如果使用安装工具箱 家酿,the toolbox 二进制文件在您的系统路径中可用。您可以使用相同的命令启动服务器 命令:
toolbox --config "tools.yaml"NPM
要直接运行Toolbox而不手动下载二进制文件(需要Node.js):
npx @toolbox-sdk/server --config tools.yamlGemini CLI After installing a Gemini CLI extensions, the prebuilt tools will be available during use.
# Run Gemini CLI
gemini
# List extensions
/extensions list
# List MCP servers
/mcp list你可以使用 toolbox help 查看完整的旗帜列表!要停止服务器,请发送 终止信号(ctrl+c 在大多数平台上)。
有关部署到不同环境的更多详细文档,请查看 出资源在 部署工具箱 部分
______________________________________________________________________
连接到工具箱
工具箱服务器启动并运行后,您可以将工具加载到MCP兼容客户端或 应用程序。
MCP客户端
将以下配置添加到MCP客户端配置中:
{
"mcpServers": {
"toolbox": {
"type": "http",
"url": "http://127.0.0.1:5000/mcp",
}
}
}如果你想连接到特定的工具集,请将url替换为“http://127.0.0.1:5000/mcp/{toolset_name}“。
工具箱SDK:与您的应用程序集成
Toolbox Client SDK提供易于使用的构建块和高级功能,用于将自定义应用程序连接到MCP Toolbox服务器。请参阅下面使用各种框架的客户端SDK列表:
Python (Github)
Core
- 安装 工具箱核心SDK:
pip install toolbox-core- 加载工具:
from toolbox_core import ToolboxClient
# update the url to point to your server
async with ToolboxClient("http://127.0.0.1:5000") as client:
# these tools can be passed to your application!
tools = await client.load_toolset("toolset_name")有关使用Toolbox Core SDK的更多详细说明,请参阅 项目的README.
LangChain / LangGraph
- 安装 工具箱LangChain SDK:
pip install toolbox-langchain- 加载工具:
from toolbox_langchain import ToolboxClient
# update the url to point to your server
async with ToolboxClient("http://127.0.0.1:5000") as client:
# these tools can be passed to your application!
tools = client.load_toolset()有关使用Toolbox LangChain SDK的更多详细说明,请参阅 项目的README.
LlamaIndex
pip install toolbox-llamaindex- 加载工具:
from toolbox_llamaindex import ToolboxClient
# update the url to point to your server
async with ToolboxClient("http://127.0.0.1:5000") as client:
# these tools can be passed to your application!
tools = client.load_toolset()有关使用Toolbox Llamanidex SDK的更多详细说明,请参阅 项目的README.
Javascript/Typescript (Github)
Core
- 安装 工具箱核心SDK:
npm install @toolbox-sdk/core- 加载工具:
import { ToolboxClient } from '@toolbox-sdk/core';
// update the url to point to your server
const URL = 'http://127.0.0.1:5000';
let client = new ToolboxClient(URL);
// these tools can be passed to your application!
const tools = await client.loadToolset('toolsetName');有关使用Toolbox Core SDK的更多详细说明,请参阅 项目的README.
LangChain / LangGraph
- 安装 工具箱核心SDK:
npm install @toolbox-sdk/core- 加载工具:
import { ToolboxClient } from '@toolbox-sdk/core';
// update the url to point to your server
const URL = 'http://127.0.0.1:5000';
let client = new ToolboxClient(URL);
// these tools can be passed to your application!
const toolboxTools = await client.loadToolset('toolsetName');
// Define the basics of the tool: name, description, schema and core logic
const getTool = (toolboxTool) => tool(currTool, {
name: toolboxTool.getName(),
description: toolboxTool.getDescription(),
schema: toolboxTool.getParamSchema()
});
// Use these tools in your Langchain/Langraph applications
const tools = toolboxTools.map(getTool);Genkit
- 安装 工具箱核心SDK:
npm install @toolbox-sdk/core- 加载工具:
import { ToolboxClient } from '@toolbox-sdk/core';
import { genkit } from 'genkit';
// Initialise genkit
const ai = genkit({
plugins: [
googleAI({
apiKey: process.env.GEMINI_API_KEY || process.env.GOOGLE_API_KEY
})
],
model: googleAI.model('gemini-2.0-flash'),
});
// update the url to point to your server
const URL = 'http://127.0.0.1:5000';
let client = new ToolboxClient(URL);
// these tools can be passed to your application!
const toolboxTools = await client.loadToolset('toolsetName');
// Define the basics of the tool: name, description, schema and core logic
const getTool = (toolboxTool) => ai.defineTool({
name: toolboxTool.getName(),
description: toolboxTool.getDescription(),
schema: toolboxTool.getParamSchema()
}, toolboxTool)
// Use these tools in your Genkit applications
const tools = toolboxTools.map(getTool);ADK
- 安装 工具箱ADK SDK:
npm install @toolbox-sdk/adk- 加载工具:
import { ToolboxClient } from '@toolbox-sdk/adk';
// update the url to point to your server
const URL = 'http://127.0.0.1:5000';
let client = new ToolboxClient(URL);
// these tools can be passed to your application!
const tools = await client.loadToolset('toolsetName');有关使用Toolbox ADK SDK的更多详细说明,请参阅 项目的README.
Go (Github)
Core
- 安装 工具箱Go SDK:
go get github.com/googleapis/mcp-toolbox-sdk-go- 加载工具:
package main
import (
"github.com/googleapis/mcp-toolbox-sdk-go/core"
"context"
)
func main() {
// Make sure to add the error checks
// update the url to point to your server
URL := "http://127.0.0.1:5000";
ctx := context.Background()
client, err := core.NewToolboxClient(URL)
// Framework agnostic tools
tools, err := client.LoadToolset("toolsetName", ctx)
}有关使用Toolbox Go SDK的更多详细说明,请参阅 项目的README.
LangChain Go
- 安装 工具箱Go SDK:
go get github.com/googleapis/mcp-toolbox-sdk-go- 加载工具:
package main
import (
"context"
"encoding/json"
"github.com/googleapis/mcp-toolbox-sdk-go/core"
"github.com/tmc/langchaingo/llms"
)
func main() {
// Make sure to add the error checks
// update the url to point to your server
URL := "http://127.0.0.1:5000"
ctx := context.Background()
client, err := core.NewToolboxClient(URL)
// Framework agnostic tool
tool, err := client.LoadTool("toolName", ctx)
// Fetch the tool's input schema
inputschema, err := tool.InputSchema()
var paramsSchema map[string]any
_ = json.Unmarshal(inputschema, ¶msSchema)
// Use this tool with LangChainGo
langChainTool := llms.Tool{
Type: "function",
Function: &llms.FunctionDefinition{
Name: tool.Name(),
Description: tool.Description(),
Parameters: paramsSchema,
},
}
}
Genkit
- 安装 工具箱Go SDK:
go get github.com/googleapis/mcp-toolbox-sdk-go- 加载工具:
package main
import (
"context"
"log"
"github.com/firebase/genkit/go/genkit"
"github.com/googleapis/mcp-toolbox-sdk-go/core"
"github.com/googleapis/mcp-toolbox-sdk-go/tbgenkit"
)
func main() {
// Make sure to add the error checks
// Update the url to point to your server
URL := "http://127.0.0.1:5000"
ctx := context.Background()
g := genkit.Init(ctx)
client, err := core.NewToolboxClient(URL)
// Framework agnostic tool
tool, err := client.LoadTool("toolName", ctx)
// Convert the tool using the tbgenkit package
// Use this tool with Genkit Go
genkitTool, err := tbgenkit.ToGenkitTool(tool, g)
if err != nil {
log.Fatalf("Failed to convert tool: %v\n", err)
}
log.Printf("Successfully converted tool: %s", genkitTool.Name())
}Go GenAI
- 安装 工具箱Go SDK:
go get github.com/googleapis/mcp-toolbox-sdk-go- 加载工具:
package main
import (
"context"
"encoding/json"
"github.com/googleapis/mcp-toolbox-sdk-go/core"
"google.golang.org/genai"
)
func main() {
// Make sure to add the error checks
// Update the url to point to your server
URL := "http://127.0.0.1:5000"
ctx := context.Background()
client, err := core.NewToolboxClient(URL)
// Framework agnostic tool
tool, err := client.LoadTool("toolName", ctx)
// Fetch the tool's input schema
inputschema, err := tool.InputSchema()
var schema *genai.Schema
_ = json.Unmarshal(inputschema, &schema)
funcDeclaration := &genai.FunctionDeclaration{
Name: tool.Name(),
Description: tool.Description(),
Parameters: schema,
}
// Use this tool with Go GenAI
genAITool := &genai.Tool{
FunctionDeclarations: []*genai.FunctionDeclaration{funcDeclaration},
}
}OpenAI Go
- 安装 工具箱Go SDK:
go get github.com/googleapis/mcp-toolbox-sdk-go- 加载工具:
package main
import (
"context"
"encoding/json"
"github.com/googleapis/mcp-toolbox-sdk-go/core"
openai "github.com/openai/openai-go"
)
func main() {
// Make sure to add the error checks
// Update the url to point to your server
URL := "http://127.0.0.1:5000"
ctx := context.Background()
client, err := core.NewToolboxClient(URL)
// Framework agnostic tool
tool, err := client.LoadTool("toolName", ctx)
// Fetch the tool's input schema
inputschema, err := tool.InputSchema()
var paramsSchema openai.FunctionParameters
_ = json.Unmarshal(inputschema, ¶msSchema)
// Use this tool with OpenAI Go
openAITool := openai.ChatCompletionToolParam{
Function: openai.FunctionDefinitionParam{
Name: tool.Name(),
Description: openai.String(tool.Description()),
Parameters: paramsSchema,
},
}
}ADK Go
- 安装 工具箱Go SDK:
go get github.com/googleapis/mcp-toolbox-sdk-go- 加载工具:
package main
import (
"github.com/googleapis/mcp-toolbox-sdk-go/tbadk"
"context"
)
func main() {
// Make sure to add the error checks
// Update the url to point to your server
URL := "http://127.0.0.1:5000"
ctx := context.Background()
client, err := tbadk.NewToolboxClient(URL)
if err != nil {
return fmt.Sprintln("Could not start Toolbox Client", err)
}
// Use this tool with ADK Go
tool, err := client.LoadTool("toolName", ctx)
if err != nil {
return fmt.Sprintln("Could not load Toolbox Tool", err)
}
}有关使用Toolbox Go SDK的更多详细说明,请参阅 项目的README.
______________________________________________________________________
附加功能
带有工具箱UI的测试工具
要启动工具箱的交互式UI,请使用 --ui 旗帜。这允许您进行测试 具有授权参数等功能的工具和工具集。要了解更多, 访问 工具箱UI.
./toolbox --ui遥测
工具箱通过OpenTetry发出跟踪和指标。使用 --telemetry-otlp= 导出到任何与OTLP兼容的后端,如谷歌云监控、Agnost AI或 其他人。看 遥测文档 了解详情。
生成代理技能
这 skills-generate 命令允许您转换 工具集 进入A 代理技能 与兼容 代理技能规范这对于将工具作为便携式技能包分发非常有用。
toolbox --config tools.yaml skills-generate \
--name "my-skill" \
--toolset "my_toolset" \
--description "A skill containing multiple tools"生成后,您可以将该技能安装到Gemini CLI中:
gemini skills install ./skills/my-skill有关更多详细信息,请参阅 生成代理技能指南.
______________________________________________________________________
版本控制
MCP数据库工具箱如下 语义化版本.
公共API包括工具箱服务器(CLI、配置清单和预构建工具集)和客户端SDK。
- 主要版本 对于破坏性更改(如不兼容的CLI或清单更改),会递增。
- 次要版本 对于新功能,包括对预构建工具集或测试版功能的修改,都会递增。
- 补丁版本 为向后兼容的错误修复而递增。
有关更多详细信息,请参阅我们的 完整版本控制策略.
______________________________________________________________________
贡献
欢迎捐款。请看 贡献 入门指南。
有关在Toolbox上设置开发环境的技术详细信息,请参阅 开发者 导游。
请注意,此项目发布时附带了《贡献者行为准则》。参与此项目即表示您同意遵守其条款。看 贡献者行为准则 了解更多信息。
______________________________________________________________________
社区
加入我们 不和谐社区 与我们的开发人员联系!
