Skip to main content
Glama
jaacob

Perplexity MCP Server

by jaacob

search

Search the web using Perplexity AI to find information, answer questions, and retrieve relevant results through Claude's interface.

Instructions

Search the web using Perplexity AI

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesThe search query

Implementation Reference

  • MCP CallToolRequestSchema handler that implements the 'search' tool logic by validating arguments and calling Perplexity AI's chat completions API.
    this.server.setRequestHandler(CallToolRequestSchema, async (request) => { if (request.params.name !== 'search') { throw new McpError( ErrorCode.MethodNotFound, `Unknown tool: ${request.params.name}` ); } if (!isValidSearchArgs(request.params.arguments)) { throw new McpError( ErrorCode.InvalidParams, 'Invalid search arguments. Query must be a non-empty string.' ); } try { const response = await this.axiosInstance.post<SearchResponse>('/chat/completions', { model: MODEL, messages: [ { role: 'system', content: 'You are a helpful assistant that searches the web for accurate information.' }, { role: 'user', content: request.params.arguments.query } ] }); if (response.data.choices && response.data.choices.length > 0) { return { content: [ { type: 'text', text: response.data.choices[0].message.content, }, ], }; } else { throw new Error('No response content received'); } } catch (error) { if (axios.isAxiosError(error)) { const errorMessage = error.response?.data?.error?.message || error.response?.data?.detail || error.message; console.error('Full error:', JSON.stringify(error.response?.data, null, 2)); return { content: [ { type: 'text', text: `Perplexity API error: ${errorMessage}`, }, ], isError: true, }; } throw error; } });
  • src/index.ts:74-91 (registration)
    Registration of the 'search' tool in the ListToolsRequestSchema handler, providing name, description, and input schema.
    this.server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: [ { name: 'search', description: 'Search the web using Perplexity AI', inputSchema: { type: 'object', properties: { query: { type: 'string', description: 'The search query', }, }, required: ['query'], }, }, ], }));
  • TypeScript interface defining the expected response structure from Perplexity AI API.
    interface SearchResponse { choices: [{ message: { content: string; }; }]; }
  • Input schema definition for the 'search' tool.
    inputSchema: { type: 'object', properties: { query: { type: 'string', description: 'The search query', }, }, required: ['query'], },
  • Helper function to validate the arguments for the 'search' tool.
    const isValidSearchArgs = (args: any): args is { query: string } => typeof args === 'object' && args !== null && typeof args.query === 'string' && args.query.trim().length > 0;

Other Tools

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/jaacob/perplexity-mcp'

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