UNPKG

@coinbase/agentkit-model-context-protocol

Version:

Model Context Protocol Extension of Coinbase Agentkit

43 lines (42 loc) 1.44 kB
"use strict"; /** * Main exports for the AgentKit Model Context Protocol (MCP) Extension package */ Object.defineProperty(exports, "__esModule", { value: true }); exports.getMcpTools = getMcpTools; const zod_to_json_schema_1 = require("zod-to-json-schema"); /** * Get Model Context Protocol (MCP) tools from an AgentKit instance * * @param agentKit - The AgentKit instance * @returns An array of tools and a tool handler */ async function getMcpTools(agentKit) { const actions = agentKit.getActions(); return { tools: actions.map(action => { return { name: action.name, description: action.description, // eslint-disable-next-line @typescript-eslint/no-explicit-any inputSchema: (0, zod_to_json_schema_1.zodToJsonSchema)(action.schema), }; }), toolHandler: async (name, args) => { const action = actions.find(action => action.name === name); if (!action) { throw new Error(`Tool ${name} not found`); } const parsedArgs = action.schema.parse(args); const result = await action.invoke(parsedArgs); return { content: [ { type: "text", text: JSON.stringify(result), }, ], }; }, }; }