MCP 谷歌自定义搜索服务器基于模型上下文协议(MCP)构建,借助谷歌的自定义搜索 API 为语言学习模型(LLMs)提供网络搜索功能。通过标准化接口,LLMs 能轻松执行网络搜索。
git clone https://github.com/yourusername/mcp-google-custom-search-server.git
cd mcp-google-custom-search-server
npm install
GOOGLE_API_KEY=你的API密钥
GOOGLE_SEARCH_ENGINE_ID=你的搜索引擎ID
npm run build
npm start
在开始之前,请确保完成以下准备工作:
变量名称 | 描述 | 是否必填 |
---|---|---|
GOOGLE_API_KEY | 你的谷歌自定义搜索 API 密钥 | 是 |
GOOGLE_SEARCH_ENGINE_ID | 你的自定义搜索引擎 ID | 是 |
在 Claude Desktop 配置文件(通常位于~/Library/Application Support/Claude/claude_desktop_config.json
)中添加以下内容:
{
"servers": {
"custom_search": {
"type": "mcp",
"host": "localhost",
"port": "3000"
}
}
}
query
:要搜索的关键词或短语。num_results
:返回的结果数量(默认为 10)。{
"results": [
{
"title": "结果标题",
"link": "链接地址",
"description": "结果描述"
}
]
}
mcp-google-custom-search-server/
├── index.js # 主应用程序文件
├── config.js # 配置文件
└── package.json # 依赖项和脚本
npm run build
:构建服务器。npm start
:启动服务器。使用MCP Inspector测试服务器功能。在终端运行以下命令:
npm install -g mcp-inspector
mcp-inspector
输入以下内容进行搜索:
{
"command": "search",
"query": "MCP协议"
}