UNPKG

mcp-newsapi

Version:

MCP Server for accessing News API endpoints.

31 lines (30 loc) 1.18 kB
// Import individual tool definitions import { everythingTool } from './everything.js'; import { topHeadlinesTool } from './topHeadlines.js'; // Define the list of tools const newsApiToolDefinitions = [ everythingTool, topHeadlinesTool, ]; /** * Registers all News API tools with the MCP server. * @param server The McpServer instance. */ export const registerNewsApiTools = (server) => { newsApiToolDefinitions.forEach((toolDef) => { try { // Pass the raw shape to the inputSchema parameter, assuming SDK handles z.object() server.tool(toolDef.name, toolDef.description, toolDef.inputSchemaShape, async (input) => { const result = await toolDef.handler(input); // Assuming the handler returns the data directly, wrap it in the MCP content format return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }], }; }); console.log(`Registered News API tool: ${toolDef.name}`); } catch (error) { console.error(`Failed to register tool ${toolDef.name}:`, error); } }); };