genkitx-mcp
Version:
A Genkit plugin that provides interoperability between Genkit and Model Context Protocol (MCP). Both client and server use cases are supported.
95 lines • 3.48 kB
JavaScript
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 resources_exports = {};
__export(resources_exports, {
registerResourceTools: () => registerResourceTools
});
module.exports = __toCommonJS(resources_exports);
var import_genkit = require("genkit");
async function registerResourceTools(ai, client, params) {
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()
})
},
async ({ cursor, all }) => {
if (!all) {
return client.listResources();
}
let currentCursor = cursor;
const resources = [];
while (true) {
const { nextCursor, resources: newResources } = await 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()
})
},
async ({ cursor, all }) => {
if (!all) {
return client.listResourceTemplates();
}
let currentCursor = cursor;
const resourceTemplates = [];
while (true) {
const { nextCursor, resourceTemplates: newResourceTemplates } = await 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")
})
},
async ({ uri }) => {
return client.readResource({ uri });
}
);
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
registerResourceTools
});
//# sourceMappingURL=resources.js.map
;