UNPKG

genkitx-mcp

Version:

A Genkit plugin that provides interoperability between Genkit and Model Context Protocol (MCP). Both client and server use cases are supported.

76 lines 2.63 kB
import { __async } from "../chunk-E3LOUS7X.mjs"; import { z } from "genkit"; function registerResourceTools(ai, client, params) { return __async(this, null, function* () { ai.defineTool( { name: `${params.name}/list_resources`, description: `list all available resources for '${params.name}'`, inputSchema: z.object({ /** Provide a cursor for accessing additional paginated results. */ cursor: z.string().optional(), /** When specified, automatically paginate and fetch all resources. */ all: z.boolean().optional() }) }, (_0) => __async(this, [_0], function* ({ cursor, all }) { if (!all) { return client.listResources(); } let currentCursor = cursor; const resources = []; while (true) { const { nextCursor, resources: newResources } = yield client.listResources({ cursor: currentCursor }); resources.push(...newResources); currentCursor = nextCursor; if (!currentCursor) break; } return { resources }; }) ); ai.defineTool( { name: `${params.name}/list_resource_templates`, description: `list all available resource templates for '${params.name}'`, inputSchema: z.object({ /** Provide a cursor for accessing additional paginated results. */ cursor: z.string().optional(), /** When specified, automatically paginate and fetch all resources. */ all: z.boolean().optional() }) }, (_0) => __async(this, [_0], function* ({ cursor, all }) { if (!all) { return client.listResourceTemplates(); } let currentCursor = cursor; const resourceTemplates = []; while (true) { const { nextCursor, resourceTemplates: newResourceTemplates } = yield client.listResourceTemplates({ cursor: currentCursor }); resourceTemplates.push(...newResourceTemplates); currentCursor = nextCursor; if (!currentCursor) break; } return { resourceTemplates }; }) ); ai.defineTool( { name: `${params.name}/read_resource`, description: `this tool can read resources from '${params.name}'`, inputSchema: z.object({ uri: z.string().describe("the URI of the resource to retrieve") }) }, (_0) => __async(this, [_0], function* ({ uri }) { return client.readResource({ uri }); }) ); }); } export { registerResourceTools }; //# sourceMappingURL=resources.mjs.map