lithtrix_search
Search the web and obtain credibility-scored results. Each result includes a score from 0 to 1 indicating source authority, helping you quickly assess reliability.
Instructions
Search the web via Lithtrix and get credibility-scored results. Returns structured JSON with title, URL, snippet, source domain, and credibility_score (0–1) for each result. Higher credibility_score = more authoritative source (.gov=1.0, .edu=0.9, news=0.8, .org=0.7, other=0.5). Requires LITHTRIX_API_KEY environment variable.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| q | Yes | The search query (1–500 characters) | |
| num_results | No | Number of results to return (1–20, default 10) |
Implementation Reference
- tools/search.js:34-104 (handler)The async handler function that executes the lithtrix_search tool logic: validates API key, calls GET /v1/search on the Lithtrix API, and returns structured JSON results with error handling.
async ({ q, num_results = 10 }) => { const apiKey = process.env.LITHTRIX_API_KEY; if (!apiKey) { return { content: [ { type: "text", text: JSON.stringify({ error: "LITHTRIX_API_KEY environment variable is not set. " + "Register at https://lithtrix.ai to get an API key.", }), }, ], isError: true, }; } const url = new URL("/v1/search", LITHTRIX_API_URL); url.searchParams.set("q", q); url.searchParams.set("num_results", String(num_results)); let response; try { response = await fetch(url.toString(), { headers: { Authorization: `Bearer ${apiKey}`, "Content-Type": "application/json", }, }); } catch (err) { return { content: [ { type: "text", text: JSON.stringify({ error: `Network error contacting Lithtrix API: ${err.message}`, }), }, ], isError: true, }; } const body = await response.json(); if (!response.ok) { return { content: [ { type: "text", text: JSON.stringify({ error: body.message ?? `Lithtrix API error (HTTP ${response.status})`, error_code: body.error_code ?? "UNKNOWN", }), }, ], isError: true, }; } // Return the full structured response so agents can use results + usage info return { content: [ { type: "text", text: JSON.stringify(body, null, 2), }, ], }; } ); - tools/search.js:19-33 (schema)Input schema for lithtrix_search using Zod: requires 'q' (string, 1-500 chars) and optional 'num_results' (int 1-20, default 10).
{ q: z .string() .min(1) .max(500) .describe("The search query (1–500 characters)"), num_results: z .number() .int() .min(1) .max(20) .default(10) .optional() .describe("Number of results to return (1–20, default 10)"), }, - tools/search.js:12-105 (registration)The registerSearchTool function that registers the tool with the MCP server via server.tool('lithtrix_search', ...).
export function registerSearchTool(server) { server.tool( "lithtrix_search", "Search the web via Lithtrix and get credibility-scored results. " + "Returns structured JSON with title, URL, snippet, source domain, and credibility_score (0–1) " + "for each result. Higher credibility_score = more authoritative source (.gov=1.0, .edu=0.9, " + "news=0.8, .org=0.7, other=0.5). Requires LITHTRIX_API_KEY environment variable.", { q: z .string() .min(1) .max(500) .describe("The search query (1–500 characters)"), num_results: z .number() .int() .min(1) .max(20) .default(10) .optional() .describe("Number of results to return (1–20, default 10)"), }, async ({ q, num_results = 10 }) => { const apiKey = process.env.LITHTRIX_API_KEY; if (!apiKey) { return { content: [ { type: "text", text: JSON.stringify({ error: "LITHTRIX_API_KEY environment variable is not set. " + "Register at https://lithtrix.ai to get an API key.", }), }, ], isError: true, }; } const url = new URL("/v1/search", LITHTRIX_API_URL); url.searchParams.set("q", q); url.searchParams.set("num_results", String(num_results)); let response; try { response = await fetch(url.toString(), { headers: { Authorization: `Bearer ${apiKey}`, "Content-Type": "application/json", }, }); } catch (err) { return { content: [ { type: "text", text: JSON.stringify({ error: `Network error contacting Lithtrix API: ${err.message}`, }), }, ], isError: true, }; } const body = await response.json(); if (!response.ok) { return { content: [ { type: "text", text: JSON.stringify({ error: body.message ?? `Lithtrix API error (HTTP ${response.status})`, error_code: body.error_code ?? "UNKNOWN", }), }, ], isError: true, }; } // Return the full structured response so agents can use results + usage info return { content: [ { type: "text", text: JSON.stringify(body, null, 2), }, ], }; } ); } - index.js:31-45 (registration)Import of registerSearchTool from './tools/search.js' and call to register the tool: registerSearchTool(server).
import { registerSearchTool } from "./tools/search.js"; import { registerRegisterTool } from "./tools/register.js"; import { registerMemoryTools } from "./tools/memory.js"; import { registerBlobTools } from "./tools/blobs.js"; import { registerParseTools } from "./tools/parse.js"; import { registerFeedbackTool } from "./tools/feedback.js"; import { registerBrowseTool } from "./tools/browse.js"; import { registerCommonsTool } from "./tools/commons.js"; const server = new McpServer({ name: "lithtrix", version: "0.9.0", }); registerSearchTool(server);