news
Search for recent news articles to gather current information and data using web search capabilities.
Instructions
Search for recent news articles using SearchClaw. Costs 1 credit.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| q | Yes | News search query |
Implementation Reference
- src/index.ts:90-90 (handler)Handler function for 'news' tool - takes query parameter 'q' and makes POST request to /search/news endpoint, returning JSON-formatted results
async ({ q }) => jsonResult(await apiPost("/search/news", { q })) - src/index.ts:89-89 (schema)Input schema for 'news' tool using Zod - defines single required string parameter 'q' (news search query)
{ q: z.string().describe("News search query") }, - src/index.ts:86-91 (registration)Registration of 'news' tool with McpServer - defines tool name, description, input schema, and handler function
server.tool( "news", "Search for recent news articles using SearchClaw. Costs 1 credit.", { q: z.string().describe("News search query") }, async ({ q }) => jsonResult(await apiPost("/search/news", { q })) ); - src/index.ts:61-63 (helper)jsonResult helper function - formats API response data into MCP content format with JSON stringification
function jsonResult(data: unknown) { return { content: [{ type: "text" as const, text: JSON.stringify(data, null, 2) }] }; } - src/index.ts:41-59 (helper)apiPost helper function - makes POST requests to SearchClaw API with 30s timeout, API key authentication, and error handling
async function apiPost(path: string, body: Record<string, unknown>) { const controller = new AbortController(); const timeout = setTimeout(() => controller.abort(), 30000); try { const response = await fetch(`${API_BASE}${path}`, { method: "POST", headers: { ...headers, "Content-Type": "application/json" }, body: JSON.stringify(body), signal: controller.signal, }); if (!response.ok) { const text = await response.text(); throw new Error(`SearchClaw API error ${response.status}: ${text}`); } return response.json(); } finally { clearTimeout(timeout); } }