Skip to main content

Tavily搜索MCP服务智能体 - 为AI智能体提供强大的网络搜索能力

Project description

Tavily MCP Server

🚀 Tavily搜索MCP服务智能体 - 为AI智能体提供强大的网络搜索能力

📖 简介

Tavily MCP Server是一个基于FastAPI和FastMCP构建的智能搜索服务,集成了Tavily AI搜索引擎,为AI智能体提供高质量的网络搜索功能。支持综合搜索、答案生成和新闻搜索等多种搜索模式。

✨ 特性

  • 🔍 综合网络搜索 - 使用Tavily AI引擎进行全面的网络搜索
  • 🤖 智能答案生成 - 基于搜索结果生成直接答案
  • 📰 新闻搜索 - 专门的新闻内容搜索功能
  • 🎯 域名过滤 - 支持包含/排除特定域名
  • 📅 时间范围控制 - 可指定搜索的时间范围
  • 🌍 地区限制 - 支持按国家/地区进行搜索
  • 📊 多种输出格式 - 支持文本、JSON、Markdown格式输出
  • 🔐 API密钥验证 - 安全的API访问控制
  • 📝 完整日志记录 - 详细的操作日志

🚀 快速开始

安装

pip install tavily-mcp-server

环境配置

创建 .env 文件并配置必要的环境变量:

# Tavily API密钥 (必需)
TAVILY_API_KEY=your_tavily_api_key_here

# MCP API密钥 (必需)
MCP_API_KEY=your_mcp_api_key_here

启动服务

# 使用命令行工具启动
tavily-mcp

# 或者直接运行Python模块
python -m tavily_mcp_server.server

服务将在 http://localhost:8083 启动。

📚 API文档

启动服务后,可以访问以下地址查看API文档:

🔧 使用方法

1. 综合网络搜索

import requests

response = requests.post(
    "http://localhost:8083/tavily_web_search",
    headers={"X-API-Key": "your_mcp_api_key"},
    json={
        "query": "人工智能最新发展",
        "max_results": 5,
        "search_depth": "advanced",
        "format_type": "markdown"
    }
)

result = response.json()
print(result["text"])

2. 智能答案搜索

response = requests.post(
    "http://localhost:8083/tavily_answer_search",
    headers={"X-API-Key": "your_mcp_api_key"},
    json={
        "query": "什么是大语言模型?",
        "max_results": 3,
        "format_type": "text"
    }
)

result = response.json()
print(result["text"])

3. 新闻搜索

response = requests.post(
    "http://localhost:8083/tavily_news_search",
    headers={"X-API-Key": "your_mcp_api_key"},
    json={
        "query": "科技新闻",
        "max_results": 10,
        "days": 7,
        "format_type": "json"
    }
)

result = response.json()
print(result["data"])

🛠️ 高级配置

域名过滤

# 只搜索特定域名
response = requests.post(
    "http://localhost:8083/tavily_web_search",
    headers={"X-API-Key": "your_mcp_api_key"},
    json={
        "query": "Python教程",
        "include_domains": ["python.org", "docs.python.org"],
        "max_results": 5
    }
)

# 排除特定域名
response = requests.post(
    "http://localhost:8083/tavily_web_search",
    headers={"X-API-Key": "your_mcp_api_key"},
    json={
        "query": "编程学习",
        "exclude_domains": ["spam-site.com"],
        "max_results": 5
    }
)

地区和时间限制

response = requests.post(
    "http://localhost:8083/tavily_web_search",
    headers={"X-API-Key": "your_mcp_api_key"},
    json={
        "query": "本地新闻",
        "country": "CN",
        "days": 30,
        "max_results": 10
    }
)

🔐 安全性

  • 所有API端点都需要有效的API密钥验证
  • 支持CORS配置,可根据需要调整
  • 详细的错误处理和日志记录
  • 输入参数验证和清理

🧪 开发

本地开发环境设置

# 克隆项目
git clone https://github.com/mcp-team/tavily-mcp-server.git
cd tavily-mcp-server

# 安装开发依赖
pip install -e ".[dev]"

# 运行测试
pytest

# 代码格式化
black .

# 类型检查
mypy tavily_mcp_server

📄 许可证

本项目采用 MIT 许可证。详见 LICENSE 文件。

🤝 贡献

欢迎提交Issue和Pull Request!

📞 支持

如有问题或建议,请通过以下方式联系:

🔗 相关链接


让AI智能体拥有强大的搜索能力! 🚀

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tavily_mcp_server-1.0.7.tar.gz (11.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tavily_mcp_server-1.0.7-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

Details for the file tavily_mcp_server-1.0.7.tar.gz.

File metadata

  • Download URL: tavily_mcp_server-1.0.7.tar.gz
  • Upload date:
  • Size: 11.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.8

File hashes

Hashes for tavily_mcp_server-1.0.7.tar.gz
Algorithm Hash digest
SHA256 64ce61b89fe2e76614ad2f24cc4b073e86a1471d588011caedeb2a701a84a7d9
MD5 eb0a7d250db1b318b68c4f6b4f17c13f
BLAKE2b-256 5c6ecb15562e63af742920c5103174326651e54ce3c02e5437bc97cc5ce42ac1

See more details on using hashes here.

File details

Details for the file tavily_mcp_server-1.0.7-py3-none-any.whl.

File metadata

File hashes

Hashes for tavily_mcp_server-1.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 9aafb859a4e0e41aa15562d66edeb436f8235c8c8440b5eb296dcf38855d15f1
MD5 784ebfc0a5e5ee72f63e0d2e31f45bd2
BLAKE2b-256 2967e91e4a72e06a371b14d0d5a846c08e64e28096709ee48f05c51d3000024e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page