UNPKG

dataforseo-mcp-server

Version:

CLI and MCP server for DataForSEO API — browse documentation and make authenticated API requests

27 lines • 991 B
import { z } from "zod"; import { clientUserAgentFromExtra, runWithClientUserAgent, } from "../core/api/user-agent.js"; export function toMcpResponse(result) { return { content: result.content, ...(result.isError ? { isError: true } : {}), }; } export function buildToolDefinition(tool) { if (!(tool.schema instanceof z.ZodObject)) { throw new Error(`Tool "${tool.name}" must use a ZodObject schema for MCP registration`); } return { title: tool.title, description: tool.description, params: tool.schema.shape, annotations: tool.getAnnotations(), handler: (params, extra) => runWithClientUserAgent(clientUserAgentFromExtra(extra), async () => toMcpResponse(await tool.invoke(params))), }; } export function buildToolsRecord(tools) { return tools.reduce((acc, tool) => { acc[tool.name] = buildToolDefinition(tool); return acc; }, {}); } //# sourceMappingURL=tool-definition.js.map