-
Notifications
You must be signed in to change notification settings - Fork 3.5k
feat: add MCP server for Perplexica integration #1044
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
willtwilson
wants to merge
2
commits into
ItzCrazyKns:master
Choose a base branch
from
willtwilson:feat/mcp-server
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| PORT=8940 | ||
| PERPLEXICA_URL=http://localhost:3000 | ||
|
|
||
| # Chat model provider (check GET /api/providers for available providers) | ||
| PERPLEXICA_CHAT_PROVIDER= | ||
| PERPLEXICA_CHAT_MODEL=gpt-4o-mini | ||
|
|
||
| # Embedding model provider | ||
| PERPLEXICA_EMBED_PROVIDER= | ||
| PERPLEXICA_EMBED_MODEL=text-embedding-3-large |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| FROM node:22-slim AS builder | ||
| WORKDIR /app | ||
| COPY package.json package-lock.json tsconfig.json ./ | ||
| RUN npm ci | ||
| COPY src/ src/ | ||
| RUN npx tsc | ||
|
|
||
| FROM node:22-slim | ||
| RUN groupadd -r appuser && useradd -r -g appuser -d /app appuser | ||
| WORKDIR /app | ||
| COPY package.json package-lock.json ./ | ||
| RUN npm ci --omit=dev | ||
| COPY --from=builder /app/dist dist/ | ||
| USER appuser | ||
| EXPOSE 8940 | ||
| CMD ["node", "dist/server.js"] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| # Perplexica MCP Server | ||
|
|
||
| Use [Perplexica](https://github.com/ItzCrazyKns/Perplexica) as a tool in any [MCP](https://modelcontextprotocol.io)-compatible AI client — Claude Desktop, LibreChat, Continue, and more. | ||
|
|
||
| ## What This Does | ||
|
|
||
| Exposes Perplexica's web search as an MCP tool (`perplexica_search`) over SSE transport. AI agents can call this tool to get cited, synthesised answers from web sources. | ||
|
|
||
| ## Quick Start | ||
|
|
||
| ### Docker | ||
|
|
||
| ```bash | ||
| cd integrations/mcp-server | ||
| docker build -t perplexica-mcp . | ||
| docker run -p 8940:8940 \ | ||
| -e PERPLEXICA_URL=http://host.docker.internal:3000 \ | ||
| -e PERPLEXICA_CHAT_PROVIDER=your-provider-uuid \ | ||
| -e PERPLEXICA_CHAT_MODEL=gpt-4o-mini \ | ||
| -e PERPLEXICA_EMBED_PROVIDER=your-embed-provider-uuid \ | ||
| -e PERPLEXICA_EMBED_MODEL=text-embedding-3-large \ | ||
| perplexica-mcp | ||
| ``` | ||
|
|
||
| ### Manual | ||
|
|
||
| ```bash | ||
| cd integrations/mcp-server | ||
| npm install | ||
| cp .env.example .env # edit with your settings | ||
| npm run dev | ||
| ``` | ||
|
|
||
| ### Finding Your Provider IDs | ||
|
|
||
| The MCP server needs provider UUIDs from your Perplexica instance: | ||
|
|
||
| ```bash | ||
| curl http://localhost:3000/api/providers | ||
| ``` | ||
|
|
||
| Use the `id` field from the response as `PERPLEXICA_CHAT_PROVIDER` / `PERPLEXICA_EMBED_PROVIDER`, and the model `key` as `PERPLEXICA_CHAT_MODEL` / `PERPLEXICA_EMBED_MODEL`. | ||
|
|
||
| ## Client Configuration | ||
|
|
||
| ### LibreChat (librechat.yaml) | ||
|
|
||
| ```yaml | ||
| mcpServers: | ||
| perplexica: | ||
| type: sse | ||
| url: http://perplexica-mcp:8940/sse | ||
| ``` | ||
|
|
||
| ### Claude Desktop (claude_desktop_config.json) | ||
|
|
||
| ```json | ||
| { | ||
| "mcpServers": { | ||
| "perplexica": { | ||
| "url": "http://localhost:8940/sse" | ||
| } | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ## Environment Variables | ||
|
|
||
| | Variable | Required | Default | Description | | ||
| |----------|----------|---------|-------------| | ||
| | `PORT` | No | `8940` | Server port | | ||
| | `PERPLEXICA_URL` | No | `http://localhost:3000` | Perplexica backend URL | | ||
| | `PERPLEXICA_CHAT_PROVIDER` | Yes | — | Chat model provider UUID (from `/api/providers`) | | ||
| | `PERPLEXICA_CHAT_MODEL` | Yes | — | Chat model key | | ||
| | `PERPLEXICA_EMBED_PROVIDER` | Yes | — | Embedding provider UUID (from `/api/providers`) | | ||
| | `PERPLEXICA_EMBED_MODEL` | Yes | — | Embedding model key | | ||
|
|
||
| ## Tool Reference | ||
|
|
||
| ### `perplexica_search` | ||
|
|
||
| | Parameter | Type | Required | Description | | ||
| |-----------|------|----------|-------------| | ||
| | `query` | string | Yes | Search query | | ||
| | `sources` | string[] | No | Sources to search. Default: `["web"]`. Options: `"web"`, `"academic"`, `"discussions"` | | ||
|
|
||
| Returns the synthesised answer text with source citations. | ||
|
|
||
| ## How It Works | ||
|
|
||
| 1. MCP client connects via SSE to `/sse` | ||
| 2. Client calls the `perplexica_search` tool with a query | ||
| 3. Server forwards the query to Perplexica's `POST /api/search` endpoint | ||
| 4. Server returns the synthesised answer with source citations to the MCP client | ||
|
|
||
| ## Important Notes | ||
|
|
||
| - **No `express.json()` middleware** — the MCP SDK reads the raw request stream internally. Adding body-parsing middleware breaks the SSE transport handshake. | ||
| - Uses the documented `/api/search` endpoint with `sources: ["web"]` (v1.12.1+ API). | ||
| - Source citations are appended as markdown links to the response text. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.