Tavily MCP Server

remote-capable server

The server can be hosted and run remotely because it primarily relies on remote services or has no dependency on the local environment.

Integrations

  • Required runtime environment for the server, supporting the execution of JavaScript code needed for the MCP server functionality.

  • Package manager used for installing dependencies and running scripts for the MCP server.

  • Used for development of the MCP server, providing type safety and modern JavaScript features.

Tavily MCP 服务器

模型上下文协议 (MCP) 服务器,使用 Tavily API 提供 AI 驱动的搜索功能。该服务器使 AI 助手能够执行全面的网络搜索并检索相关的最新信息。

特征

  • 人工智能搜索功能
  • 支持基本和高级搜索深度
  • 丰富的搜索结果,包括标题、URL 和内容片段
  • 人工智能生成的搜索结果摘要
  • 结果评分和响应时间跟踪
  • 具有缓存功能的全面搜索历史记录存储
  • 用于灵活数据访问的 MCP 资源

先决条件

  • Node.js(v16 或更高版本)
  • npm(Node 包管理器)
  • Tavily API 密钥(在Tavily 的网站上获取)
  • MCP 客户端(例如 Cline、Claude Desktop 或您自己的实现)

安装

  1. 克隆存储库:
git clone https://github.com/it-beard/tavily-server.git cd tavily-mcp-server
  1. 安装依赖项:
npm install
  1. 构建项目:
npm run build

配置

此服务器可与任何 MCP 客户端配合使用。以下是一些常用客户端的配置说明:

克莱恩配置

如果您使用的是 Cline(Claude 的 VSCode 扩展),请在以下位置创建或修改 MCP 设置文件:

  • macOS: ~/Library/Application Support/Cursor/User/globalStorage/saoudrizwan.claude-dev/settings/cline_mcp_settings.json
  • Windows: %APPDATA%\Cursor\User\globalStorage\saoudrizwan.claude-dev\settings\cline_mcp_settings.json
  • Linux: ~/.config/Cursor/User/globalStorage/saoudrizwan.claude-dev\settings\cline_mcp_settings.json

添加以下配置(用您自己的替换路径和 API 密钥):

{ "mcpServers": { "tavily": { "command": "node", "args": ["/path/to/tavily-server/build/index.js"], "env": { "TAVILY_API_KEY": "your-api-key-here" } } } }

Claude桌面配置

如果您使用的是 Claude Desktop 应用程序,请修改以下配置文件:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json
  • Linux: ~/.config/Claude/claude_desktop_config.json

使用与上面相同的配置格式。

其他 MCP 客户端

对于其他 MCP 客户端,请参阅其文档以了解正确的配置文件位置和格式。服务器配置应包括:

  1. 运行服务器的命令(通常是node
  2. 已编译服务器文件的路径
  3. 包括 Tavily API 密钥在内的环境变量

用法

工具

服务器提供了一个名为search的工具,其参数如下:

必需参数

  • query (字符串):要执行的搜索查询

可选参数

  • search_depth (字符串):“基本”(更快)或“高级”(更全面)

示例用法

// Example using the MCP SDK const result = await mcpClient.callTool("tavily", "search", { query: "latest developments in artificial intelligence", search_depth: "basic" });

资源

服务器提供静态和动态资源以实现灵活的数据访问:

静态资源

  • tavily://last-search/result :返回最近搜索查询的结果
    • 持久保存到数据目录中的磁盘
    • 经受服务器重启
    • 如果尚未进行搜索,则返回“尚未进行搜索”错误

动态资源(资源模板)

  • tavily://search/{query} :访问任何查询的搜索结果
    • 将 {query} 替换为您的 URL 编码的搜索词
    • 例如: tavily://search/artificial intelligence
    • 如果之前进行了查询,则返回缓存的结果
    • 如果之前没有搜索过查询,则执行并存储新的搜索
    • 返回与搜索工具相同的格式,但通过资源接口

与工具相比,MCP 中的资源提供了一种访问数据的替代方法:

  • 工具用于执行操作(例如执行新搜索)
  • 资源用于访问数据(例如检索现有搜索结果)
  • 资源 URI 可以存储并稍后访问
  • 资源支持静态(固定)和动态(模板化)访问模式

响应格式

interface SearchResponse { query: string; answer: string; results: Array<{ title: string; url: string; content: string; score: number; }>; response_time: number; }

持久存储

服务器对搜索结果实现了全面的持久化存储:

存储位置

  • 数据存储在data目录中
  • data/searches.json包含所有历史搜索结果
  • 服务器重启后数据仍然存在
  • 存储在服务器启动时自动初始化

存储功能

  • 存储完整的搜索历史记录
  • 缓存所有搜索结果以便快速检索
  • 自动保存新的搜索结果
  • 基于磁盘的持久性
  • JSON 格式,方便调试
  • 存储操作的错误处理
  • 自动目录创建

缓存行为

  • 所有搜索结果都会自动缓存
  • 同一查询的后续请求将返回缓存的结果
  • 缓存可提高响应时间并减少 API 调用
  • 缓存在服务器重启后仍然存在
  • 跟踪上次搜索以便快速访问

发展

项目结构

tavily-server/ ├── src/ │ └── index.ts # Main server implementation ├── data/ # Persistent storage directory │ └── searches.json # Search history and cache storage ├── build/ # Compiled JavaScript files ├── package.json # Project dependencies and scripts └── tsconfig.json # TypeScript configuration

可用脚本

  • npm run build :编译 TypeScript 并使输出可执行
  • npm run start :启动 MCP 服务器(构建后)
  • npm run dev :以开发模式运行服务器

错误处理

服务器提供了常见问题的详细错误消息:

  • API 密钥无效
  • 网络错误
  • 搜索参数无效
  • API 速率限制
  • 未找到资源
  • 无效的资源 URI
  • 存储读/写错误

贡献

  1. 分叉存储库
  2. 创建你的功能分支( git checkout -b feature/amazing-feature
  3. 提交您的更改( git commit -m 'Add some amazing feature'
  4. 推送到分支( git push origin feature/amazing-feature
  5. 打开拉取请求

执照

该项目根据 MIT 许可证获得许可 - 有关详细信息,请参阅LICENSE文件。

致谢

-
security - not tested
A
license - permissive license
-
quality - not tested

使 AI 助手能够通过 Tavily API 执行最新的网络搜索,并通过 AI 生成的摘要提供全面的搜索结果。

  1. Features
    1. Prerequisites
      1. Installation
        1. Configuration
          1. Cline Configuration
          2. Claude Desktop Configuration
          3. Other MCP Clients
        2. Usage
          1. Tools
          2. Resources
          3. Persistent Storage
        3. Development
          1. Project Structure
          2. Available Scripts
        4. Error Handling
          1. Contributing
            1. License
              1. Acknowledgments
                ID: fzs8u6odo2