Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ The server will be accessible at `http://localhost:8080/mcp`
## Available Tools

### **perplexity_search**

Search results include publication and last-updated dates when available. Missing or null dates are omitted from the formatted output.

Direct web search using the Perplexity Search API. Returns ranked search results with metadata, perfect for finding current information. Supports recency filters (`search_recency_filter`), domain restrictions (`search_domain_filter`), and [Fast Search](https://docs.perplexity.ai/docs/search/fast-search) (`search_type: "fast"`) for lower latency and cost.

### **perplexity_ask**
Expand Down
41 changes: 41 additions & 0 deletions src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,47 @@ describe("Perplexity MCP Server", () => {
});

describe("performSearch", () => {
it("should accept nullable dates and preserve last_updated through parsing", async () => {
global.fetch = vi.fn().mockResolvedValue({
ok: true,
json: async () => ({
id: "search_dates",
results: [
{ title: "Updated", url: "https://example.com/updated", snippet: "text",
date: null, last_updated: "2026-10-12" },
{ title: "Published", url: "https://example.com/published", snippet: "text",
date: "2026-10-11", last_updated: null },
{ title: "Undated", url: "https://example.com/undated", snippet: "text" },
{ title: "Unknown", url: "https://example.com/unknown", snippet: "text",
date: null, last_updated: null },
],
}),
} as Response);

const result = await performSearch("test dates");

expect(result).toContain("Found 4 search results");
expect(result).toContain("Last updated: 2026-10-12");
expect(result).toContain("Date: 2026-10-11");
expect(result.match(/Date:/g)).toHaveLength(1);
expect(result.match(/Last updated:/g)).toHaveLength(1);
expect(result).not.toContain("null");
expect(result).not.toContain("undefined");
});

it.each(["date", "last_updated"])("should reject non-string %s values", async (field) => {
global.fetch = vi.fn().mockResolvedValue({
ok: true,
json: async () => ({
results: [{ title: "Invalid", url: "https://example.com", snippet: "text", [field]: 123 }],
}),
} as Response);

await expect(performSearch("invalid dates")).rejects.toThrow(
"Failed to parse JSON response from Perplexity Search API"
);
});

it("should successfully perform search", async () => {
const mockResponse = {
results: [
Expand Down
3 changes: 3 additions & 0 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,9 @@ export function formatSearchResults(data: SearchResponse): string {
if (result.date) {
formattedResults += ` Date: ${result.date}\n`;
}
if (result.last_updated) {
formattedResults += ` Last updated: ${result.last_updated}\n`;
}
formattedResults += `\n`;
});

Expand Down
3 changes: 2 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ export interface SearchResult {
title: string;
url: string;
snippet?: string;
date?: string;
date?: string | null;
last_updated?: string | null;
score?: number;
}

Expand Down
3 changes: 2 additions & 1 deletion src/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ export const SearchResultSchema = z.object({
title: z.string(),
url: z.string(),
snippet: z.string().optional(),
date: z.string().optional(),
date: z.string().nullish(),
last_updated: z.string().nullish(),
score: z.number().optional(),
});

Expand Down
Loading