Perplexica搜索代理服务

MCP Perplexica是一个为Perplexica搜索API提供代理服务的工具,允许LLMs通过模型上下文协议(MCP)执行网页搜索,支持多种搜索模式和传输方式。

  • by Kaiohz
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 Kaiohz/mcp-perplexica

使用说明

MCP困惑

MCP服务器代理 困惑 搜索API。

该服务器允许LLM使用模型上下文协议(MCP)通过Perplexica执行网络搜索。

特性

  • 🔍 通过Perplexica进行网络搜索
  • 📚 多种聚焦模式(网络、学术、YouTube、Reddit等)
  • ⚡ 可配置的优化模式(速度、平衡、质量)
  • 🔧 可定制的模型配置
  • 📖 答复中的来源引用
  • 🚀 多种传输模式(stdio、SSE、流式HTTP)

先决条件

安装

  1. 克隆存储库:
git clone https://github.com/Kaiohz/mcp-perplexica.git
cd mcp-perplexica
  1. 使用UV安装依赖项:
uv sync
  1. 创建环境文件:
cp .env.example .env
  1. 编辑 .env 根据您的配置:
# Perplexica API
PERPLEXICA_URL=http://localhost:3000

# Transport: stdio (default), sse, or streamable-http
TRANSPORT=stdio
HOST=127.0.0.1
PORT=8000

# Model configuration
DEFAULT_CHAT_MODEL_PROVIDER_ID=your-provider-id
DEFAULT_CHAT_MODEL_KEY=anthropic/claude-sonnet-4.5
DEFAULT_EMBEDDING_MODEL_PROVIDER_ID=your-provider-id
DEFAULT_EMBEDDING_MODEL_KEY=openai/text-embedding-3-small

用法

运输方式

服务器支持三种传输模式:

运输 描述 用例
stdio 标准输入/输出 CLI工具,Claude Desktop
sse 服务器通过HTTP发送事件 Web客户端
streamable-http 流式HTTP(建议用于生产) 生产部署

使用Docker Compose运行

同时运行Perplexica和MCP Perplexiica的最简单方法:

# Copy and configure environment files
cp .env.example .env
cp .env.perplexica.example .env.perplexica

# Edit .env with your MCP Perplexica settings
# Edit .env.perplexica with your Perplexica settings

# Start services
docker compose up -d

这将开始:

  • 困惑 上 http://localhost:3000
  • MCP困惑 连接到Perplexica

运行MCP服务器(无Docker)

标准模式(默认)

uv run python src/main.py

SSE模式

TRANSPORT=sse PORT=8000 uv run python src/main.py

流式HTTP模式

TRANSPORT=streamable-http PORT=8000 uv run python src/main.py

Claude桌面配置

添加到您的Claude Desktop配置(~/Library/Application Support/Claude/claude_desktop_config.json 在macOS上):

{
  "mcpServers": {
    "perplexica": {
      "command": "uv",
      "args": ["run", "--directory", "/path/to/mcp-perplexica", "python", "-m", "main"],
      "env": {
        "PERPLEXICA_URL": "http://localhost:3000",
        "TRANSPORT": "stdio",
        "DEFAULT_CHAT_MODEL_PROVIDER_ID": "your-provider-id",
        "DEFAULT_CHAT_MODEL_KEY": "anthropic/claude-sonnet-4.5",
        "DEFAULT_EMBEDDING_MODEL_PROVIDER_ID": "your-provider-id",
        "DEFAULT_EMBEDDING_MODEL_KEY": "openai/text-embedding-3-small"
      }
    }
  }
}

Claude代码配置

对于基于HTTP的传输,您可以将服务器添加到Claude Code中:

# Start the server with streamable-http transport
TRANSPORT=streamable-http PORT=8000 uv run python -m main

# Add to Claude Code
claude mcp add --transport http perplexica http://localhost:8000/mcp

可用工具

search

使用Perplexica进行网络搜索。

参数:

参数 类型 必填 说明
query string 是 搜索查询
focus_mode string 否 搜索焦点: webSearch, academicSearch, writingAssistant, wolframAlphaSearch, youtubeSearch, redditSearch
optimization_mode string 否 优化: speed, balanced, quality
system_instructions string 否 AI响应的自定义指令
chat_model_provider_id string 否 覆盖默认聊天模型提供程序
chat_model_key string 否 覆盖默认聊天模式
embedding_model_provider_id string 否 覆盖默认嵌入提供程序
embedding_model_key string 否 覆盖默认嵌入模型

例子:

Search for "latest developments in AI" using academic focus

发展

安装开发依赖项

uv sync --dev

运行测试

uv run pytest

运行门楣

uv run ruff check .
uv run ruff format .
uv run black src/

建筑

该项目采用六边形建筑:

src/
├── main.py              # MCP server entry point
├── config.py            # Pydantic Settings
├── dependencies.py      # Dependency injection
├── domain/              # Business core (pure Python)
│   ├── entities.py      # Dataclasses
│   └── ports.py         # ABC interfaces
├── application/         # Use cases
│   ├── requests.py      # Pydantic DTOs
│   └── use_cases.py     # Business logic
└── infrastructure/      # External adapters
    └── perplexica/
        └── adapter.py   # HTTP client

许可证

麻省理工学院