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.

117 lines 4.29 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var __async = (__this, __arguments, generator) => { return new Promise((resolve, reject) => { var fulfilled = (value) => { try { step(generator.next(value)); } catch (e) { reject(e); } }; var rejected = (value) => { try { step(generator.throw(value)); } catch (e) { reject(e); } }; var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected); step((generator = generator.apply(__this, __arguments)).next()); }); }; var resources_exports = {}; __export(resources_exports, { registerResourceTools: () => registerResourceTools }); module.exports = __toCommonJS(resources_exports); var import_genkit = require("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: import_genkit.z.object({ /** Provide a cursor for accessing additional paginated results. */ cursor: import_genkit.z.string().optional(), /** When specified, automatically paginate and fetch all resources. */ all: import_genkit.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: import_genkit.z.object({ /** Provide a cursor for accessing additional paginated results. */ cursor: import_genkit.z.string().optional(), /** When specified, automatically paginate and fetch all resources. */ all: import_genkit.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: import_genkit.z.object({ uri: import_genkit.z.string().describe("the URI of the resource to retrieve") }) }, (_0) => __async(this, [_0], function* ({ uri }) { return client.readResource({ uri }); }) ); }); } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { registerResourceTools }); //# sourceMappingURL=resources.js.map