The Perplexity MCP Server integrates Perplexity AI's real-time web search and advanced language models into MCP-compatible applications. It enables you to:
Access Real-Time Information: Query current web data for up-to-date answers on news, events, and trending topics
AI-Powered Responses: Generate intelligent, contextual answers using Perplexity's Sonar Pro model
Research and Fact-Checking: Retrieve verified information from recent or authoritative web sources
Technical Lookups: Access current technical documentation and resources
Clean Responses: Receive concise answers without citations or references for straightforward use
Streaming Architecture: Efficiently streams responses server-side while delivering complete results to MCP clients
Simple Integration: Easy configuration and setup with MCP-compatible applications like Cursor IDE and Claude Desktop
Provides access to Perplexity AI's chat API with real-time web search capabilities, enabling AI-powered question answering with up-to-date information and citations using the sonar-pro model.
Perplexity MCP Server
A production-ready Model Context Protocol (MCP) server that integrates Perplexity AI's powerful search capabilities. Get real-time AI-powered answers with web sources and citations through the StreamableHTTP transport.
Overview
This MCP server provides seamless integration with Perplexity AI's chat API, enabling AI applications to access current web information through the Model Context Protocol. Built with TypeScript, Express, and the MCP SDK StreamableHTTP transport for efficient, scalable communication.
Features
✅ Dual Transport Support - Both Stdio (auto-start) and HTTP (standalone) transports
✅ Real-time Web Search - Powered by Perplexity's Sonar Pro model
✅ Rich Responses - AI-generated answers with citations and related images
✅ Flexible Authentication - Supports Authorization header and environment variables
✅ Smart Port Management - Automatic port conflict detection with helpful error messages
✅ Production Ready - Express-based with proper error handling and session management
✅ Universal Compatibility - Works with any MCP client supporting StreamableHTTP or Stdio
Quick Start
Prerequisites
Node.js 18+
pnpm package manager
Perplexity API Key from perplexity.ai
Installation
Running the Server
For HTTP Transport:
The server will start on http://127.0.0.1:3001/mcp
For Stdio Transport:
No manual start needed - the MCP client launches it automatically. Just configure your client and restart it.
Get Your API Key
Sign up and get your Perplexity API key from https://www.perplexity.ai/
Client Configuration
This server provides two transport options:
Transport | Use Case | Pros | When to Use |
Stdio | Development, Single Client | ✅ Auto-starts ✅ No port conflicts ✅ Simple setup | Cursor IDE, Claude Desktop (single user) |
HTTP | Production, Multiple Clients | ✅ Serves multiple clients ✅ Stays running ✅ Better for servers | Production deployments, shared environments |
Option 1: Stdio Transport (Auto-Start) ⭐ Recommended
The client launches the server automatically. No manual server start required.
Best for: Cursor IDE, Claude Desktop, single-user development
Cursor IDE (Stdio)
Create or edit ~/.cursor/mcp.json
(global) or .cursor/mcp.json
(project-specific):
Note: Replace /absolute/path/to/perplexity-mcp-server
with your actual project path.
Claude Desktop (Stdio)
Same configuration format:
Option 2: HTTP Transport (Standalone Server) 🚀 Production
Server runs independently and can serve multiple clients.
Best for: Production deployments, shared environments, multiple concurrent clients
Step 1: Start the server
Step 2: Configure Cursor
Create or edit ~/.cursor/mcp.json
(global) or .cursor/mcp.json
(project-specific):
Step 3: Restart Cursor
The perplexity_search
tool will now be available.
Claude Desktop (HTTP)
Same configuration format:
Note: The server must be running before connecting.
Other MCP Clients
Any MCP client supporting StreamableHTTP can connect using:
Server URL:
http://127.0.0.1:3001/mcp
Authentication:
Authorization: Bearer YOUR_PERPLEXITY_API_KEY
headerTransport: StreamableHTTP (SSE-based)
Refer to your MCP client's documentation for specific configuration steps.
MCP SDK Integration
For direct SDK usage:
Available Tools
perplexity_search
Search and get AI-powered answers with real-time web data, citations, and images.
Parameters:
query
(string, required): Your search query or question
Example:
Response includes:
AI-generated answer based on current web data
Sources: Citations with URLs
Related Images: Relevant images with titles and URLs
Model Configuration:
Model:
sonar-pro
(Perplexity's premier advanced search model)Search Recency:
month
(configurable)Streaming: Enabled (from Perplexity API, processed server-side)
Citations: Included
Images: Included when relevant
Configuration
Environment Variables
PERPLEXITY_API_KEY
: Your Perplexity API key (optional if using Authorization header)PORT
: Server port (default: 3001)
API Key Priority
The server accepts API keys from two sources with the following priority:
Authorization Header (Recommended)
Format:
Authorization: Bearer YOUR_API_KEY
Sent per-request via HTTP headers
More secure for multi-user scenarios
Environment Variable (Fallback)
Set
PERPLEXITY_API_KEY
when starting the serverShared across all requests
Usage Examples
With environment variable:
With header authentication:
Development
Build
Development Mode (with auto-reload)
HTTP Server:
Stdio Server:
Watch TypeScript Compilation
Test with MCP Inspector
HTTP Server:
Stdio Server:
Health Check
Verify the server is running:
Expected response:
Architecture
StreamableHTTP Transport
This server uses the MCP StreamableHTTP transport providing:
HTTP/HTTPS - Standard protocols for web communication
Server-Sent Events (SSE) - Real-time server-to-client messages
Session Management - Stateful sessions with UUID-based IDs
Scalability - Multiple concurrent connections
Infrastructure Compatibility - Works with proxies, load balancers, and CDNs
Request Flow
Client sends HTTP POST to
/mcp
endpointExpress extracts Authorization header → API key
Request forwarded to MCP transport
Tool handler receives request with API key
Server calls Perplexity API with streaming
Response parsed and formatted with citations/images
Complete response returned via MCP protocol
Technology Stack
Runtime: Node.js 18+
Language: TypeScript 5.3+
Framework: Express 5
MCP SDK: @modelcontextprotocol/sdk
HTTP Client: node-fetch 3
Validation: Zod 3
Production Deployment
Security Best Practices
API Key Security
Use environment variables or secure vaults
Never commit API keys to version control
Rotate keys regularly
Network Security
Server binds to
127.0.0.1
(localhost) by defaultUse reverse proxy (nginx, Caddy) with SSL/TLS for production
Configure firewall rules appropriately
Input Validation
All inputs validated with Zod schemas
Query length limits enforced
Rate Limiting
Consider adding rate limiting middleware
Monitor Perplexity API usage
Reverse Proxy Example (nginx)
Process Management (PM2)
Docker Deployment
Troubleshooting
Common Issues
Error: "PERPLEXITY_API_KEY is required"
Ensure API key is provided via Authorization header or environment variable
Check header format:
Authorization: Bearer YOUR_KEY
Verify the server receives the header (check logs)
Connection Refused
Verify server is running:
curl http://127.0.0.1:3001/health
Check port matches configuration
Ensure no firewall is blocking the port
Citations or Images showing as "Untitled" or broken links
This should be fixed in the latest version
Rebuild:
pnpm build && pnpm start
Verify you're running the latest code
Error: "Port 3001 is already in use"
The server automatically detects port conflicts and provides helpful solutions:
Cursor IDE not finding server (HTTP)
Ensure server is running before starting Cursor:
pnpm start
Check
~/.cursor/mcp.json
syntax is valid JSONFully restart Cursor (Cmd+Q / Ctrl+Q, then relaunch)
Verify server is running:
curl http://127.0.0.1:3001/health
Check Cursor's MCP panel for connection status
Cursor IDE - Stdio vs HTTP
Stdio (Recommended): Auto-starts, no manual server needed
HTTP: Requires
pnpm start
running in a separate terminalIf HTTP not connecting, try Stdio instead for simplicity
API Reference
Perplexity API
Documentation: https://docs.perplexity.ai/
API Reference: https://docs.perplexity.ai/api-reference/chat-completions
Model Cards: https://docs.perplexity.ai/guides/model-cards
Model Context Protocol
MCP Docs: https://modelcontextprotocol.io/
Specification: https://spec.modelcontextprotocol.io/
TypeScript SDK: https://github.com/modelcontextprotocol/typescript-sdk
Project Structure
Contributing
Contributions are welcome! Please feel free to submit issues or pull requests.
License
MIT
Acknowledgments
Built with:
Model Context Protocol by Anthropic
Made with ❤️ using the Model Context Protocol
Support
🌟 Star this repo if you find it useful!
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.
Integrates Perplexity AI's chat capabilities with real-time web search, enabling users to ask questions and receive AI-powered answers with up-to-date information and citations from verified web sources.