网络搜索API服务

Ollama WebSearch MCP Server提供网络搜索和网页内容抓取API服务,适用于需要集成网络搜索功能的开发场景。

  • by akopper
  • Python
  • 本地部署
  • 1 星标
  • 更新于
在 GitHub 查看 akopper/ollama-websearch-mcp

使用说明

Ollama WebSearch MCP服务器

用于Ollama网络搜索和网络获取API的MCP服务器。

概述

此MCP服务器公开了两个与Ollama的web服务交互的工具:

  • 网络搜索:使用Ollama的托管搜索API执行网络搜索
  • web_fetch:获取网页内容

需求

  • Python 3.10+
  • Ollama帐户(用于云API访问)

安装

克隆

git clone https://github.com/akopper/ollama-websearch-mcp.git
cd ollama-websearch-mcp

来源

pip install -e .

使用uvx

uvx默认以stdio模式运行服务器(适用于Claude Desktop/Cursor):

uvx --from https://github.com/akopper/ollama-websearch-mcp ollama-websearch-mcp

对于带有uvx的HTTP模式:

uvx --from https://github.com/akopper/ollama-websearch-mcp ollama-websearch-mcp -- --http

码头工人

Docker镜像默认为HTTP模式。

# HTTP mode (default) - for remote usage
docker run -d -p 8000:8000 -e OLLAMA_API_KEY=your-api-key ghcr.io/akopper/ollama-websearch-mcp

# stdio mode - for Claude Desktop/Cursor
docker run -it --rm -e OLLAMA_API_KEY=your-api-key ghcr.io/akopper/ollama-websearch-mcp --stdio

Docker Compose

cp .env.example .env
# Edit .env with your API key
docker-compose up -d

配置

环境变量

变量 描述 默认值
OLLAMA_API_KEY Ollama云服务的API密钥 无
OLLAMA_HOST Ollama的主机URL https://ollama.com

获取API密钥

  1. 首选 ollama.com
  2. 登录您的账户
  3. 导航到API设置
  4. 生成API密钥

用法

运行服务器

stdio模式(默认,适用于克劳德桌面/光标)

# Using the installed command
ollama-websearch-mcp

# Or directly with Python
python -m ollama_websearch_mcp.server

HTTP模式(用于远程使用)

python -m ollama_websearch_mcp.server --http

服务器将于启动 http://localhost:8000/mcp 默认情况下。

Claude桌面集成

将以下内容添加到您的Claude Desktop配置中:

macOS: ~/Library/Application Support/Claude/claude_desktop_config.json

视窗: %APPDATA%/Claude/claude_desktop_config.json

{
  "mcpServers": {
    "ollama-websearch": {
      "command": "ollama-websearch-mcp",
      "env": {
        "OLLAMA_API_KEY": "your-api-key-here"
      }
    }
  }
}

或者使用自定义Python环境:

{
  "mcpServers": {
    "ollama-websearch": {
      "command": "/path/to/venv/bin/python",
      "args": ["-m", "ollama_websearch_mcp.server"],
      "env": {
        "OLLAMA_API_KEY": "your-api-key-here"
      }
    }
  }
}

光标集成

添加到光标设置(或 .cursor/mcp.json 在项目中):

{
  "mcpServers": {
    "ollama-websearch": {
      "command": "ollama-websearch-mcp",
      "env": {
        "OLLAMA_API_KEY": "your-api-key-here"
      }
    }
  }
}

MCPorter集成

MCPorter可以发现并使用此MCP服务器。创建配置文件:

// config/mcporter.json
{
  "mcpServers": {
    "ollama-websearch": {
      "description": "Ollama web search and web fetch MCP server",
      "command": "ollama-websearch-mcp",
      "env": {
        "OLLAMA_API_KEY": "$env:OLLAMA_API_KEY"
      }
    }
  }
}

或者运行ad-hoc:

# List tools
npx mcporter list ollama-websearch

# Call a tool
npx mcporter call ollama-websearch.web_search query:python max_results:10

可用工具

网络搜索

使用Ollama的托管搜索API执行网络搜索。

参数:

  • query (必填):搜索查询字符串
  • max_results (可选):返回的最大结果数(默认值:10)

退货: 包含带有标题、url和代码段的搜索结果的词典。

web_fetch

获取网页的内容。

参数:

  • url (必填):要获取的绝对URL

退货: 包含提取内容的字典,包括html、文本和元数据。

发展

设置

# Create virtual environment
python -m venv .venv
source .venv/bin/activate

# Install with dev dependencies
pip install -e ".[dev]"

运行测试

# Run all tests
pytest

# Run a single test
pytest tests/test_server.py::TestWebSearch::test_web_search_returns_dict

# Run with verbose output
pytest -v

# Run with coverage
pytest --cov=src --cov-report=html

代码检查

# Check code style
ruff check src/ tests/

# Auto-fix issues
ruff check src/ tests/ --fix

运行服务器进行开发

# stdio mode with mcp dev
mcp dev src/ollama_websearch_mcp/server.py

# Or run directly
python -m ollama_websearch_mcp.server

许可证

麻省理工学院