Skip to main content
Glama
rezashahnazar

Perplexity MCP Server

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.

TypeScript Node.js MCP

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.

Related MCP server: Perplexity Ask MCP Server

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

# Clone or navigate to the project directory
cd perplexity-mcp-server

# Install dependencies
pnpm install

# Build the project
pnpm build

Running the Server

For HTTP Transport:

# Build and start
pnpm build
pnpm start

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

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):

{
  "mcpServers": {
    "perplexity": {
      "command": "node",
      "args": ["/absolute/path/to/perplexity-mcp-server/dist/stdio.js"],
      "env": {
        "PERPLEXITY_API_KEY": "YOUR_PERPLEXITY_API_KEY"
      }
    }
  }
}

Note: Replace /absolute/path/to/perplexity-mcp-server with your actual project path.

Claude Desktop (Stdio)

Same configuration format:

{
  "mcpServers": {
    "perplexity": {
      "command": "node",
      "args": ["/absolute/path/to/perplexity-mcp-server/dist/stdio.js"],
      "env": {
        "PERPLEXITY_API_KEY": "YOUR_PERPLEXITY_API_KEY"
      }
    }
  }
}

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

pnpm build
pnpm start

Step 2: Configure Cursor

Create or edit ~/.cursor/mcp.json (global) or .cursor/mcp.json (project-specific):

{
  "mcpServers": {
    "perplexity": {
      "url": "http://127.0.0.1:3001/mcp",
      "headers": {
        "Authorization": "Bearer YOUR_PERPLEXITY_API_KEY"
      }
    }
  }
}

Step 3: Restart Cursor

The perplexity_search tool will now be available.

Claude Desktop (HTTP)

Same configuration format:

{
  "mcpServers": {
    "perplexity": {
      "url": "http://127.0.0.1:3001/mcp",
      "headers": {
        "Authorization": "Bearer YOUR_PERPLEXITY_API_KEY"
      }
    }
  }
}

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 header

  • Transport: StreamableHTTP (SSE-based)

Refer to your MCP client's documentation for specific configuration steps.

MCP SDK Integration

For direct SDK usage:

import { Client } from "@modelcontextprotocol/sdk/client/index.js";
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";

const client = new Client(
  {
    name: "my-client",
    version: "1.0.0",
  },
  {
    capabilities: {},
  }
);

const transport = new StreamableHTTPClientTransport(
  new URL("http://127.0.0.1:3001/mcp"),
  {
    headers: {
      Authorization: "Bearer YOUR_API_KEY",
    },
  }
);

await client.connect(transport);

const result = await client.callTool({
  name: "perplexity_search",
  arguments: {
    query: "What are the latest developments in quantum computing?",
  },
});

console.log(result);

Available Tools

Search and get AI-powered answers with real-time web data, citations, and images.

Parameters:

  • query (string, required): Your search query or question

Example:

{
  "query": "What are the latest developments in AI agents?"
}

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:

  1. Authorization Header (Recommended)

    • Format: Authorization: Bearer YOUR_API_KEY

    • Sent per-request via HTTP headers

    • More secure for multi-user scenarios

  2. Environment Variable (Fallback)

    • Set PERPLEXITY_API_KEY when starting the server

    • Shared across all requests

Usage Examples

With environment variable:

PERPLEXITY_API_KEY=pplx-abc123 PORT=8080 pnpm start

With header authentication:

pnpm start
# Client sends: Authorization: Bearer pplx-abc123

Development

Build

pnpm build

Development Mode (with auto-reload)

HTTP Server:

pnpm dev

Stdio Server:

pnpm dev:stdio

Watch TypeScript Compilation

pnpm watch

Test with MCP Inspector

HTTP Server:

pnpm inspector

Stdio Server:

pnpm inspector:stdio

Health Check

Verify the server is running:

curl http://127.0.0.1:3001/health

Expected response:

{ "status": "ok", "service": "perplexity-mcp-server" }

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

  1. Client sends HTTP POST to /mcp endpoint

  2. Express extracts Authorization header → API key

  3. Request forwarded to MCP transport

  4. Tool handler receives request with API key

  5. Server calls Perplexity API with streaming

  6. Response parsed and formatted with citations/images

  7. 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

  1. API Key Security

    • Use environment variables or secure vaults

    • Never commit API keys to version control

    • Rotate keys regularly

  2. Network Security

    • Server binds to 127.0.0.1 (localhost) by default

    • Use reverse proxy (nginx, Caddy) with SSL/TLS for production

    • Configure firewall rules appropriately

  3. Input Validation

    • All inputs validated with Zod schemas

    • Query length limits enforced

  4. Rate Limiting

    • Consider adding rate limiting middleware

    • Monitor Perplexity API usage

Reverse Proxy Example (nginx)

server {
    listen 443 ssl http2;
    server_name mcp.yourdomain.com;

    ssl_certificate /path/to/cert.pem;
    ssl_certificate_key /path/to/key.pem;

    location /mcp {
        proxy_pass http://127.0.0.1:3001;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}

Process Management (PM2)

# Install PM2
npm install -g pm2

# Start server
pm2 start dist/server.js --name perplexity-mcp

# With environment variables
pm2 start dist/server.js --name perplexity-mcp \
  --env PERPLEXITY_API_KEY=your-key \
  --env PORT=3001

# Save process list
pm2 save

# Setup startup script
pm2 startup

Docker Deployment

FROM node:18-alpine

WORKDIR /app

COPY package.json pnpm-lock.yaml ./
RUN npm install -g pnpm && pnpm install --frozen-lockfile

COPY . .
RUN pnpm build

EXPOSE 3001

CMD ["node", "dist/server.js"]

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:

❌ ERROR: Port 3001 is already in use!
   Process: PID 12345: node dist/server.js

💡 To fix this, you can:
   1. Stop the existing server (Ctrl+C in its terminal)
   2. Use a different port: PORT=3002 pnpm start
   3. Kill the process: kill -9 $(lsof -ti:3001)
   4. Find and stop it: lsof -ti:3001 | xargs ps -p

Cursor IDE not finding server (HTTP)

  • Ensure server is running before starting Cursor: pnpm start

  • Check ~/.cursor/mcp.json syntax is valid JSON

  • Fully 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 terminal

  • If HTTP not connecting, try Stdio instead for simplicity

API Reference

Perplexity API

Model Context Protocol

Project Structure

perplexity-mcp-server/
├── src/
│   ├── server.ts          # HTTP transport server (StreamableHTTP)
│   └── stdio.ts           # Stdio transport server (auto-start)
├── dist/                  # Compiled JavaScript output
│   ├── server.js          # HTTP server executable
│   └── stdio.js           # Stdio server executable
├── package.json          # Dependencies and scripts
├── tsconfig.json         # TypeScript configuration
├── mcp.json.example     # Example MCP client config
└── README.md            # This file

Contributing

Contributions are welcome! Please feel free to submit issues or pull requests.

License

MIT

Acknowledgments

Built with:


Made with ❤️ using the Model Context Protocol

Support

Available Tools

1 tool
perplexity_search_chatA

Ask questions and get AI-powered answers with real-time web search from Perplexity AI. Use this when you need current information, facts, research, news, or any query that benefits from up-to-date web sources. Responses include citations to original sources. Best for: current events, research questions, factual queries, technical documentation lookups, and any information that requires recent or authoritative web sources.

ParametersJSON Schema
NameRequiredDescriptionDefault
contentYesThe user message/query to send to Perplexity AI

TDQS

A4.4/5.0
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It effectively describes key traits: the tool performs searches with real-time web access, includes citations to sources, and is optimized for current or authoritative information. However, it lacks details on rate limits, authentication needs, or error handling, which are minor gaps.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is appropriately sized and front-loaded, starting with the core functionality and followed by usage guidelines. Every sentence adds value without redundancy, making it efficient and easy to parse for an AI agent.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (search with AI and web integration) and lack of annotations or output schema, the description is mostly complete. It covers purpose, usage, and behavioral aspects well, but could benefit from mentioning response format or potential limitations to fully compensate for the missing structured data.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The schema description coverage is 100%, so the input schema already documents the 'content' parameter as a string for the user query. The description does not add any additional meaning or context about parameters beyond what the schema provides, such as formatting examples or constraints, resulting in a baseline score.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose with specific verbs ('Ask questions', 'get AI-powered answers') and resources ('Perplexity AI', 'real-time web search'). It explicitly distinguishes what the tool does by mentioning its unique features like citations and web-sourced information, even without siblings for comparison.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides explicit guidance on when to use this tool, listing specific scenarios such as 'current information, facts, research, news' and 'any query that benefits from up-to-date web sources'. It includes a 'Best for' section with detailed examples like current events and technical documentation lookups, offering clear context for usage.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections. Dates show when Glama detected each change.

  1. 1 tool updatev1.0.0
    • First observedperplexity_search_chat

TDQS

A4.2/5.0
Disambiguation5/5

With only one tool, there is no possibility of ambiguity or overlap between tools. The tool's purpose is clearly defined as performing AI-powered web searches with citations, leaving no room for confusion or misselection.

Naming Consistency5/5

The single tool name 'perplexity_search_chat' follows a clear and consistent pattern. Since there is only one tool, naming consistency is inherently perfect with no deviations or mixed conventions to evaluate.

Tool Count2/5

A single tool is too few for most server purposes, as it limits functionality and flexibility. While this tool covers web search comprehensively, the server's scope feels thin, lacking complementary operations like filtering, saving searches, or managing history that would enhance its utility.

Completeness3/5

The tool provides a robust search function with real-time web access and citations, covering the core need for up-to-date information. However, there are notable gaps: no ability to refine searches, save results, or interact with search history, which are common features in search-oriented interfaces, limiting agent workflows.

Maintenance

ActivityInactive
ResponsivenessNo issues

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Connectors

Related MCP Servers

  • A
    license
    Not graded
    quality
    D
    maintenance
    Provides AI-powered search, research, and reasoning capabilities through integration with Perplexity.ai, offering three specialized tools: general conversational AI, deep research with citations, and advanced reasoning.
    13
    2
    MIT
  • A
    license
    Not graded
    quality
    D
    maintenance
    Integrates the Sonar API to provide Claude with real-time web-wide research capabilities. Enables conversational web searches through Perplexity's AI-powered search engine for up-to-date information retrieval.
    1,826
    MIT
  • A
    license
    A
    quality
    B
    maintenance
    Provides AI assistants with real-time web search, reasoning, and research capabilities through Perplexity's Sonar models and Search API. Supports quick searches, deep research, advanced reasoning, and direct web search with ranked results.
    4
    44,116
    2,507
    MIT

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/rezashahnazar/perplexity-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server