From cc0946092194294ec38028ce8e29e0b1b449eb2f Mon Sep 17 00:00:00 2001 From: Michael Bleigh Date: Wed, 27 Nov 2024 12:15:54 -0800 Subject: [PATCH] feat(js/plugins/mpc): adds new MCP plugin (#1415) --- js/plugins/langchain/src/evaluators.ts | 1 + js/plugins/mcp/LICENSE | 203 +++++++++++++++ js/plugins/mcp/README.md | 112 ++++++++ js/plugins/mcp/examples/client/index.js | 36 +++ js/plugins/mcp/examples/client/package.json | 25 ++ js/plugins/mcp/examples/server/index.js | 46 ++++ js/plugins/mcp/examples/server/package.json | 18 ++ .../examples/server/prompts/port_code.prompt | 13 + js/plugins/mcp/package.json | 58 +++++ js/plugins/mcp/src/client/message.ts | 46 ++++ js/plugins/mcp/src/client/prompts.ts | 84 ++++++ js/plugins/mcp/src/client/resources.ts | 100 +++++++ js/plugins/mcp/src/client/tools.ts | 96 +++++++ js/plugins/mcp/src/index.ts | 92 +++++++ js/plugins/mcp/src/server.ts | 246 ++++++++++++++++++ js/plugins/mcp/tsconfig.json | 4 + js/plugins/mcp/tsup.config.ts | 22 ++ js/pnpm-lock.yaml | 174 ++++++++++++- 18 files changed, 1365 insertions(+), 11 deletions(-) create mode 100644 js/plugins/mcp/LICENSE create mode 100644 js/plugins/mcp/README.md create mode 100644 js/plugins/mcp/examples/client/index.js create mode 100644 js/plugins/mcp/examples/client/package.json create mode 100644 js/plugins/mcp/examples/server/index.js create mode 100644 js/plugins/mcp/examples/server/package.json create mode 100644 js/plugins/mcp/examples/server/prompts/port_code.prompt create mode 100644 js/plugins/mcp/package.json create mode 100644 js/plugins/mcp/src/client/message.ts create mode 100644 js/plugins/mcp/src/client/prompts.ts create mode 100644 js/plugins/mcp/src/client/resources.ts create mode 100644 js/plugins/mcp/src/client/tools.ts create mode 100644 js/plugins/mcp/src/index.ts create mode 100644 js/plugins/mcp/src/server.ts create mode 100644 js/plugins/mcp/tsconfig.json create mode 100644 js/plugins/mcp/tsup.config.ts diff --git a/js/plugins/langchain/src/evaluators.ts b/js/plugins/langchain/src/evaluators.ts index 9edb12d44..f793c1e4d 100644 --- a/js/plugins/langchain/src/evaluators.ts +++ b/js/plugins/langchain/src/evaluators.ts @@ -42,6 +42,7 @@ export function langchainEvaluator( type as 'labeled_criteria' | 'criteria', { criteria, + // TODO: Figure out why this breaks with TypeScript 5.3 llm: genkitModel(ai, judgeLlm, judgeConfig), chainOptions: { callbacks: [new GenkitTracer()], diff --git a/js/plugins/mcp/LICENSE b/js/plugins/mcp/LICENSE new file mode 100644 index 000000000..26a870243 --- /dev/null +++ b/js/plugins/mcp/LICENSE @@ -0,0 +1,203 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + \ No newline at end of file diff --git a/js/plugins/mcp/README.md b/js/plugins/mcp/README.md new file mode 100644 index 000000000..676e52f90 --- /dev/null +++ b/js/plugins/mcp/README.md @@ -0,0 +1,112 @@ +# Genkit MCP + +This plugin provides integration between Genkit and the [Model Context Protocol](https://modelcontextprotocol.io) (MCP). MCP is an open standard allowing developers to build "servers" which provide tools, resources, and prompts to clients. Genkit MCP allows Genkit developers to both consume MCP tools, prompts, and resources as a client and provide tools and prompts as a server. + +## MCP Client + +To create an MCP client, you call the `mcpClient` function to generate a Genkit plugin for an MCP server. For example, to use MCP's example [filesystem server](https://github.com/modelcontextprotocol/servers/tree/main/src/filesystem): + +```ts +import { genkit } from 'genkit'; +import { mcpClient } from '@genkit-ai/mcp'; + +// the filesystem server requires one or more allowed directories +const ALLOWED_DIRS = ['/Users/yourusername/Desktop']; + +const filesystemClient = mcpClient({ + name: 'filesystem', + serverProcess: { + command: 'npx', + args: ['-y', '@modelcontextprotocol/server-everything', ...ALLOWED_DIRS], + }, +}); + +const ai = genkit({ + plugins: [ + filesystemClient /* ... other plugins such as model providers ...*/, + ], +}); +``` + +Most MCP servers are built to run as spawned processes on the same machine using the `stdio` transport. When you supply the `serverProcess` option, you are specifying the command, arguments, and environment variables for spawning the server as a subprocess. + +### mcpClient() Options + +- **`name`**: (required) The name for this client, which namespaces its tools and prompts. +- **`version`**: (optional) The client's version number. Defaults to "1.0.0". +- You must supply one of: + - **`serverProcess`**: Parameters for launching a local server process using the stdio MCP transport. + - **`command`**: Shell command path for launching the MCP server. Can be e.g. `npx` or `uvx` to download and run the server from a package manager. + - **`args`**: (optional) Array of string arguments to pass to the command. + - **`env`**: (optional) Key value object of environment variables to pass to the command. + - **`serverUrl`**: The URL of a remote server to connect to using the SSE MCP transport. + - **`transport`**: An existing MCP transport object for connecting to the server. +- **`rawToolResponses`**: (optional) A boolean flag. If `true`, tool responses are returned in their raw MCP format; otherwise, they are processed for Genkit compatibility. + +### Using MCP Actions + +The Genkit MCP client automatically discovers available tools and prompts and registers them with Genkit making them available anywhere other tools and prompts can be used. To access resources, special `list_resources` and `read_resource` tools are registered that will access resources for the server. + +All MCP actions are namespaced under the name you supply, so a client called `filesystem` will register tools such as `filesystem/read_file`. + +### Tool Responses + +MCP tools return a `content` array as opposed to a structured response like most Genkit tools. The Genkit MCP plugin attempts to parse and coerce returned content: + +1. If content is text and valid JSON, the JSON is parsed and returned. +2. If content is text and not valid JSON, the text is returned. +3. If content has a single non-text part, it is returned. +4. If content has multiple/mixed parts, the full content response is returned. + +## MCP Server + +You can also expose all of the tools and prompts from a Genkit instance as an MCP server: + +```ts +import { genkit, z } from 'genkit'; +import { mcpServer } from '@genkit-ai/mcp'; + +const ai = genkit({}); + +ai.defineTool( + { + name: 'add', + description: 'add two numbers together', + inputSchema: z.object({ a: z.number(), b: z.number() }), + outputSchema: z.number(), + }, + async ({ a, b }) => { + return a + b; + } +); + +ai.definePrompt( + { + name: 'happy', + description: 'everybody together now', + input: { + schema: z.object({ action: z.string().optional() }), + default: { action: 'clap your hands' }, + }, + }, + `If you're happy and you know it, {{action}}.` +); + +mcpServer(ai, { name: 'example_server', version: '0.0.1' }).start(); +``` + +The above will start up an MCP server with the stdio transport that exposes a tool called `add` and a prompt called `happy`. To start the server with a different transport, use `mcpServer(...).start(otherTransport)`. + +### Known Limitations + +- MCP prompts are only able to take string parameters, so inputs to schemas must be objects with only string property values. +- MCP prompts only support `user` and `model` messages. `system` messages are not supported. +- MCP prompts only support a single "type" within a message so you can't mix media and text in the same message. + +### Testing your MCP server + +You can test your MCP server using the official inspector. For example, if your server code compiled into `dist/index.js`, you could run: + + npx @modelcontextprotocol/inspector dist/index.js + +Once you start the inspector, you can list prompts and actions and test them out manually. diff --git a/js/plugins/mcp/examples/client/index.js b/js/plugins/mcp/examples/client/index.js new file mode 100644 index 000000000..ea6f02f25 --- /dev/null +++ b/js/plugins/mcp/examples/client/index.js @@ -0,0 +1,36 @@ +/** + * Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { gemini15Pro, googleAI } from '@genkit-ai/googleai'; +import { genkit } from 'genkit'; +import { logger } from 'genkit/logging'; +import { mcpClient } from 'genkitx-mcp'; + +logger.setLogLevel('debug'); + +const everythingClient = mcpClient({ + name: 'everything', + version: '1.0.0', + serverProcess: { + command: 'npx', + args: ['@modelcontextprotocol/server-everything'], + }, +}); + +const ai = genkit({ + plugins: [googleAI(), everythingClient], + model: gemini15Pro, +}); diff --git a/js/plugins/mcp/examples/client/package.json b/js/plugins/mcp/examples/client/package.json new file mode 100644 index 000000000..9acf429c8 --- /dev/null +++ b/js/plugins/mcp/examples/client/package.json @@ -0,0 +1,25 @@ +{ + "name": "@genkit-ai/mcp-examples-client-stdio", + "version": "1.0.0", + "description": "", + "main": "index.js", + "type": "module", + "scripts": { + "start": "genkit start -- tsx --watch index.ts", + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [], + "author": "", + "license": "ISC", + "dependencies": { + "@genkit-ai/googleai": "file:../../../googleai", + "@modelcontextprotocol/server-filesystem": "^0.5.1", + "@modelcontextprotocol/server-github": "^0.5.1", + "genkit": "file:../../../../genkit", + "genkitx-mcp": "file:../../" + }, + "devDependencies": { + "@modelcontextprotocol/server-puppeteer": "^0.5.1", + "tsx": "^4.19.2" + } +} diff --git a/js/plugins/mcp/examples/server/index.js b/js/plugins/mcp/examples/server/index.js new file mode 100644 index 000000000..b9ecc7c5d --- /dev/null +++ b/js/plugins/mcp/examples/server/index.js @@ -0,0 +1,46 @@ +/** + * Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { genkit, z } from 'genkit'; +import { mcpServer } from 'genkitx-mcp'; + +const ai = genkit({}); + +ai.defineTool( + { + name: 'add', + description: 'add two numbers together', + inputSchema: z.object({ a: z.number(), b: z.number() }), + outputSchema: z.number(), + }, + async ({ a, b }) => { + return a + b; + } +); + +ai.definePrompt( + { + name: 'happy', + description: 'everybody together now', + input: { + schema: z.object({ action: z.string().optional() }), + default: { action: 'clap your hands' }, + }, + }, + `If you're happy and you know it, {{action}}.` +); + +mcpServer(ai, { name: 'example_server', version: '0.0.1' }).start(); diff --git a/js/plugins/mcp/examples/server/package.json b/js/plugins/mcp/examples/server/package.json new file mode 100644 index 000000000..6983b3fb8 --- /dev/null +++ b/js/plugins/mcp/examples/server/package.json @@ -0,0 +1,18 @@ +{ + "name": "@genkit-ai/mcp-examples-server", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "start": "node index.js", + "inspect": "npx @modelcontextprotocol/inspector index.js" + }, + "keywords": [], + "author": "", + "license": "ISC", + "dependencies": { + "genkit": "file:../../../../genkit", + "genkitx-mcp": "file:../.." + }, + "type": "module" +} diff --git a/js/plugins/mcp/examples/server/prompts/port_code.prompt b/js/plugins/mcp/examples/server/prompts/port_code.prompt new file mode 100644 index 000000000..65b9f631c --- /dev/null +++ b/js/plugins/mcp/examples/server/prompts/port_code.prompt @@ -0,0 +1,13 @@ +--- +input: + schema: + code: string, the source code to port from one language to another + fromLang?: string, the original language of the source code (e.g. js, python) + toLang: string, the destination language of the source code (e.g. python, js) +--- + +You are assisting the user in translating code between two programming languages. Given the code below, translate it into {{toLang}}. + +```{{#if fromLang}}{{fromLang}}{{/if}} +{{code}} +``` \ No newline at end of file diff --git a/js/plugins/mcp/package.json b/js/plugins/mcp/package.json new file mode 100644 index 000000000..70a1f0ef4 --- /dev/null +++ b/js/plugins/mcp/package.json @@ -0,0 +1,58 @@ +{ + "name": "genkitx-mpc", + "keywords": [ + "genkit", + "genkit-plugin", + "mcp", + "model-context-protocol", + "ai", + "genai", + "generative-ai" + ], + "version": "0.9.5", + "description": "A Genkit plugin that provides interoperability between Genkit and Model Context Protocol (MCP). Both client and server use cases are supported.", + "main": "dist/index.js", + "types": "./lib/index.d.ts", + "exports": { + ".": { + "require": "./lib/index.js", + "import": "./lib/index.mjs", + "types": "./lib/index.d.ts", + "default": "./lib/index.js" + } + }, + "type": "commonjs", + "scripts": { + "check": "tsc", + "compile": "tsup-node", + "build:clean": "rimraf ./lib", + "build": "npm-run-all build:clean check compile", + "build:watch": "tsup-node --watch", + "test": "tsx --test ./tests/*_test.ts" + }, + "repository": { + "type": "git", + "url": "https://github.com/firebase/genkit.git", + "directory": "js/plugins/mpc" + }, + "author": "genkit", + "license": "Apache-2.0", + "peerDependencies": { + "genkit": "workspace:*", + "@genkit-ai/core": "workspace:*" + }, + "devDependencies": { + "@jest/globals": "^29.7.0", + "@types/node": "^20.11.16", + "jest": "^29.7.0", + "npm-run-all": "^4.1.5", + "rimraf": "^6.0.1", + "ts-jest": "^29.1.2", + "tsup": "^8.3.5", + "tsx": "^4.19.2", + "typescript": "^5.3.0" + }, + "dependencies": { + "@modelcontextprotocol/sdk": "1.0.0" + } +} diff --git a/js/plugins/mcp/src/client/message.ts b/js/plugins/mcp/src/client/message.ts new file mode 100644 index 000000000..ab5f30626 --- /dev/null +++ b/js/plugins/mcp/src/client/message.ts @@ -0,0 +1,46 @@ +/** + * Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import type { PromptMessage } from '@modelcontextprotocol/sdk/types.js' with { 'resolution-mode': 'import' }; +import { MessageData, Part } from 'genkit'; + +const ROLE_MAP = { + user: 'user', + assistant: 'model', +} as const; + +export function fromMcpPromptMessage(message: PromptMessage): MessageData { + return { + role: ROLE_MAP[message.role], + content: [fromMcpPart(message.content)], + }; +} + +export function fromMcpPart(part: PromptMessage['content']): Part { + switch (part.type) { + case 'text': + return { text: part.text }; + case 'image': + return { + media: { + contentType: part.mimeType, + url: `data:${part.mimeType};base64,${part.data}`, + }, + }; + case 'resource': + return {}; + } +} diff --git a/js/plugins/mcp/src/client/prompts.ts b/js/plugins/mcp/src/client/prompts.ts new file mode 100644 index 000000000..f322473d6 --- /dev/null +++ b/js/plugins/mcp/src/client/prompts.ts @@ -0,0 +1,84 @@ +/** + * Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import type { Client } from '@modelcontextprotocol/sdk/client/index.js' with { 'resolution-mode': 'import' }; +import type { Prompt } from '@modelcontextprotocol/sdk/types.js' with { 'resolution-mode': 'import' }; +import { Genkit, JSONSchema } from 'genkit'; +import { logger } from 'genkit/logging'; +import type { McpClientOptions } from '../index.js'; +import { fromMcpPromptMessage } from './message.js'; + +function toSchema(args: Prompt['arguments']) { + if (!args) return {}; + const schema: JSONSchema = { type: 'object', properties: {}, required: [] }; + for (const arg of args) { + schema.properties[arg.name] = { + type: 'string', + description: arg.description, + }; + if (arg.required) schema.required.push(arg.name); + } + return schema; +} + +function registerPrompt( + ai: Genkit, + client: Client, + prompt: Prompt, + params: McpClientOptions +) { + logger.debug( + `[@genkit-ai/mcp] Registering MCP prompt ${params.name}/${prompt.name}` + ); + ai.definePrompt( + { + name: prompt.name, + description: prompt.description || '', + input: { jsonSchema: toSchema(prompt.arguments) }, + output: { format: 'text' }, + }, + async (args) => { + logger.debug( + `[@genkit-ai/mcp] Calling MCP prompt ${params.name}/${prompt.name} with arguments`, + JSON.stringify(args) + ); + const result = await client.getPrompt({ + name: prompt.name, + arguments: args, + }); + return { + messages: result.messages.map(fromMcpPromptMessage), + }; + } + ); +} + +/** + * Lookup all tools available in the server and register each as a Genkit tool. + */ +export async function registerAllPrompts( + ai: Genkit, + client: Client, + params: McpClientOptions +): Promise { + let cursor: string | undefined; + while (true) { + const { nextCursor, prompts } = await client.listPrompts({ cursor }); + prompts.forEach((p) => registerPrompt(ai, client, p, params)); + cursor = nextCursor; + if (!cursor) break; + } +} diff --git a/js/plugins/mcp/src/client/resources.ts b/js/plugins/mcp/src/client/resources.ts new file mode 100644 index 000000000..2801c2aa2 --- /dev/null +++ b/js/plugins/mcp/src/client/resources.ts @@ -0,0 +1,100 @@ +/** + * Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import type { Client } from '@modelcontextprotocol/sdk/client/index.js' with { 'resolution-mode': 'import' }; +import type { + Resource, + ResourceTemplate, +} from '@modelcontextprotocol/sdk/types.js' with { 'resolution-mode': 'import' }; +import { Genkit, z } from 'genkit'; +import type { McpClientOptions } from '../index.js'; + +export function registerResourceTools( + ai: Genkit, + client: Client, + params: McpClientOptions +) { + 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(), + }), + }, + async ({ cursor, all }) => { + if (!all) { + return client.listResources(); + } + + let currentCursor: string | undefined; + const resources: Resource[] = []; + while (true) { + const { nextCursor, resources: newResources } = + await client.listResources({ cursor }); + 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(), + }), + }, + async ({ cursor, all }) => { + if (!all) { + return client.listResourceTemplates(); + } + + let currentCursor: string | undefined; + const resourceTemplates: ResourceTemplate[] = []; + while (true) { + const { nextCursor, resourceTemplates: newResourceTemplates } = + await client.listResourceTemplates({ cursor }); + 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'), + }), + }, + async ({ uri }) => { + return client.readResource({ uri }); + } + ); +} diff --git a/js/plugins/mcp/src/client/tools.ts b/js/plugins/mcp/src/client/tools.ts new file mode 100644 index 000000000..433f5c135 --- /dev/null +++ b/js/plugins/mcp/src/client/tools.ts @@ -0,0 +1,96 @@ +/** + * Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import type { Client } from '@modelcontextprotocol/sdk/client/index.js' with { 'resolution-mode': 'import' }; +import type { + CallToolResult, + Tool, +} from '@modelcontextprotocol/sdk/types.js' with { 'resolution-mode': 'import' }; +import { Genkit, z } from 'genkit'; +import { logger } from 'genkit/logging'; +import type { McpClientOptions } from '../index.js'; + +const toText = (c: CallToolResult['content']) => + c.map((p) => p.text || '').join(''); + +function processResult(result: CallToolResult) { + if (result.isError) return { error: toText(result.content) }; + if (result.content.every((c) => !!c.text)) { + const text = toText(result.content); + if (text.trim().startsWith('{') || text.trim().startsWith('[')) { + try { + return JSON.parse(text); + } catch (e) { + return text; + } + } + return text; + } + if (result.content.length === 1) return result.content[0]; + return result; +} + +function registerTool( + ai: Genkit, + client: Client, + tool: Tool, + params: McpClientOptions +) { + logger.debug( + `[@genkit-ai/mcp] Registering MCP tool ${params.name}/${tool.name}` + ); + ai.defineTool( + { + name: `${params.name}/${tool.name}`, + description: tool.description || '', + inputJsonSchema: tool.inputSchema, + outputSchema: z.any(), + }, + async (args) => { + logger.debug( + `[@genkit-ai/mcp] Calling MCP tool ${params.name}/${tool.name} with arguments`, + JSON.stringify(args) + ); + const result = await client.callTool({ + name: tool.name, + arguments: args, + }); + logger.debug( + `MCP tool ${tool.name} result:`, + JSON.stringify(result, null, 2) + ); + if (params.rawToolResponses) return result; + return processResult(result as CallToolResult); + } + ); +} + +/** + * Lookup all tools available in the server and register each as a Genkit tool. + */ +export async function registerAllTools( + ai: Genkit, + client: Client, + params: McpClientOptions +): Promise { + let cursor: string | undefined; + while (true) { + const { nextCursor, tools } = await client.listTools({ cursor }); + tools.forEach((t) => registerTool(ai, client, t, params)); + cursor = nextCursor; + if (!cursor) break; + } +} diff --git a/js/plugins/mcp/src/index.ts b/js/plugins/mcp/src/index.ts new file mode 100644 index 000000000..6d09e0ba4 --- /dev/null +++ b/js/plugins/mcp/src/index.ts @@ -0,0 +1,92 @@ +/** + * Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import type { StdioServerParameters } from '@modelcontextprotocol/sdk/client/stdio.js' with { 'resolution-mode': 'import' }; +import type { Transport } from '@modelcontextprotocol/sdk/shared/transport.js' with { 'resolution-mode': 'import' }; +import { Genkit, GenkitError } from 'genkit'; +import { genkitPlugin } from 'genkit/plugin'; +import { registerAllPrompts } from './client/prompts.js'; +import { registerResourceTools } from './client/resources.js'; +import { registerAllTools } from './client/tools.js'; +import { GenkitMcpServer } from './server.js'; + +export interface McpClientOptions { + /** Provide a name for this client which will be its namespace for all tools and prompts. */ + name: string; + /** Provide a version number for this client (defaults to 1.0.0). */ + version?: string; + /** If you already have an MCP transport you'd like to use, pass it here to connect to the server. */ + transport?: Transport; + /** Start a local server process using the stdio MCP transport. */ + serverProcess?: StdioServerParameters; + /** Connect to a remote server process using the SSE MCP transport. */ + serverUrl?: string; + /** Return tool responses in raw MCP form instead of processing them for Genkit compatibility. */ + rawToolResponses?: boolean; +} + +async function transportFrom(params: McpClientOptions): Promise { + if (params.transport) return params.transport; + if (params.serverUrl) { + const { SSEClientTransport } = await import( + '@modelcontextprotocol/sdk/client/sse.js' + ); + return new SSEClientTransport(URL.parse(params.serverUrl)!); + } + if (params.serverProcess) { + const { StdioClientTransport } = await import( + '@modelcontextprotocol/sdk/client/stdio.js' + ); + return new StdioClientTransport(params.serverProcess); + } + throw new GenkitError({ + status: 'INVALID_ARGUMENT', + message: + 'Unable to create a server connection with supplied options. Must provide transport, stdio, or sseUrl.', + }); +} + +export function mcpClient(params: McpClientOptions) { + return genkitPlugin(params.name, async (ai: Genkit) => { + const { Client } = await import( + '@modelcontextprotocol/sdk/client/index.js' + ); + + const transport = await transportFrom(params); + ai.options.model; + const client = new Client( + { name: params.name, version: params.version || '1.0.0' }, + { capabilities: {} } + ); + await client.connect(transport); + await Promise.all([ + registerAllTools(ai, client, params), + registerAllPrompts(ai, client, params), + registerResourceTools(ai, client, params), + ]); + }); +} + +export interface McpServerOptions { + /** The name you want to give your server for MCP inspection. */ + name: string; + /** The version you want the server to advertise to clients. Defaults to 1.0.0. */ + version?: string; +} + +export function mcpServer(ai: Genkit, options: McpServerOptions) { + return new GenkitMcpServer(ai, options); +} diff --git a/js/plugins/mcp/src/server.ts b/js/plugins/mcp/src/server.ts new file mode 100644 index 000000000..5acb0c451 --- /dev/null +++ b/js/plugins/mcp/src/server.ts @@ -0,0 +1,246 @@ +/** + * Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { + Genkit, + GenkitError, + Message, + MessageData, + PromptAction, +} from 'genkit'; +import type { McpServerOptions } from './index.js'; + +import { toJsonSchema } from '@genkit-ai/core/schema'; +import type { Server } from '@modelcontextprotocol/sdk/server/index.js' with { 'resolution-mode': 'import' }; +import type { Transport } from '@modelcontextprotocol/sdk/shared/transport.js' with { 'resolution-mode': 'import' }; +import type { + CallToolRequest, + CallToolResult, + GetPromptRequest, + GetPromptResult, + ListPromptsRequest, + ListPromptsResult, + ListToolsRequest, + ListToolsResult, + Prompt, + PromptMessage, + Tool, +} from '@modelcontextprotocol/sdk/types.js' with { 'resolution-mode': 'import' }; +import { logger } from 'genkit/logging'; +import { ToolAction, toToolDefinition } from 'genkit/tool'; +export class GenkitMcpServer { + ai: Genkit; + options: McpServerOptions; + server?: Server; + actionsResolved: boolean = false; + toolActions: ToolAction[] = []; + promptActions: PromptAction[] = []; + + constructor(ai: Genkit, options: McpServerOptions) { + this.ai = ai; + this.options = options; + this.setup(); + } + + async setup(): Promise { + if (this.actionsResolved) return; + const { Server } = await import( + '@modelcontextprotocol/sdk/server/index.js' + ); + + this.server = new Server( + { name: this.options.name, version: this.options.version || '1.0.0' }, + { + capabilities: { + prompts: {}, + tools: {}, + }, + } + ); + + const { + CallToolRequestSchema, + GetPromptRequestSchema, + ListPromptsRequestSchema, + ListToolsRequestSchema, + } = await import('@modelcontextprotocol/sdk/types.js'); + + this.server.setRequestHandler( + ListToolsRequestSchema, + this.listTools.bind(this) + ); + this.server.setRequestHandler( + CallToolRequestSchema, + this.callTool.bind(this) + ); + this.server.setRequestHandler( + ListPromptsRequestSchema, + this.listPrompts.bind(this) + ); + this.server.setRequestHandler( + GetPromptRequestSchema, + this.getPrompt.bind(this) + ); + + const allActions = await this.ai.registry.listActions(); + const toolList: ToolAction[] = []; + const promptList: PromptAction[] = []; + for (const k in allActions) { + console.log('action:', k); + if (k.startsWith('/tool/')) { + toolList.push(allActions[k] as ToolAction); + } else if (k.startsWith('/prompt/')) { + promptList.push(allActions[k] as PromptAction); + } + } + this.toolActions = toolList; + this.promptActions = promptList; + this.actionsResolved = true; + } + + async listTools(req: ListToolsRequest): Promise { + await this.setup(); + return { + tools: this.toolActions.map((t): Tool => { + const def = toToolDefinition(t); + return { + name: def.name, + inputSchema: (def.inputSchema as any) || { type: 'object' }, + description: def.description, + }; + }), + }; + } + + async callTool(req: CallToolRequest): Promise { + await this.setup(); + const tool = this.toolActions.find( + (t) => t.__action.name === req.params.name + ); + if (!tool) + throw new GenkitError({ + status: 'NOT_FOUND', + message: `Tried to call tool '${req.params.name}' but it could not be found.`, + }); + const result = await tool(req.params.arguments); + return { content: [{ type: 'text', text: JSON.stringify(result) }] }; + } + + async listPrompts(req: ListPromptsRequest): Promise { + await this.setup(); + return { + prompts: this.promptActions.map((p): Prompt => { + return { + name: p.__action.name, + description: p.__action.description, + arguments: toMcpPromptArguments(p), + }; + }), + }; + } + + async getPrompt(req: GetPromptRequest): Promise { + await this.setup(); + const prompt = this.promptActions.find( + (p) => p.__action.name === req.params.name + ); + if (!prompt) + throw new GenkitError({ + status: 'NOT_FOUND', + message: `[@genkit-ai/mcp] Tried to call prompt '${req.params.name}' but it could not be found.`, + }); + const result = await prompt(req.params.arguments); + return { + description: prompt.__action.description, + messages: result.messages.map(toMcpPromptMessage), + }; + } + + async start(transport?: Transport) { + if (!transport) { + const { StdioServerTransport } = await import( + '@modelcontextprotocol/sdk/server/stdio.js' + ); + transport = new StdioServerTransport(); + } + await this.setup(); + await this.server!.connect(transport); + logger.info( + `[@genkit-ai/mcp] MCP server '${this.options.name}' started successfully.` + ); + } +} + +function toMcpPromptArguments(p: PromptAction): Prompt['arguments'] { + const jsonSchema = toJsonSchema({ + schema: p.__action.inputSchema, + jsonSchema: p.__action.inputJsonSchema, + }); + + if (!jsonSchema) return undefined; + if (!jsonSchema.properties) + throw new GenkitError({ + status: 'FAILED_PRECONDITION', + message: + '[@genkit-ai/mcp] MCP prompts must take objects as input schema.', + }); + + const args: Prompt['arguments'] = []; + for (const k in jsonSchema.properties) { + const { type, description } = jsonSchema.properties[k]; + if ( + type !== 'string' && + (!Array.isArray(type) || !type.includes('string')) + ) { + throw new GenkitError({ + status: 'FAILED_PRECONDITION', + message: `[@genkit-ai/mcp] MCP prompts may only take string arguments, but ${p.__action.name} has property '${k}' of type '${type}'.`, + }); + } + args.push({ + name: k, + description, + required: jsonSchema.required?.includes(k), + }); + } +} + +const ROLE_MAP = { model: 'assistant', user: 'user' } as const; + +function toMcpPromptMessage(messageData: MessageData): PromptMessage { + if (messageData.role !== 'model' && messageData.role !== 'user') { + throw new GenkitError({ + status: 'UNIMPLEMENTED', + message: `[@genkit-ai/mcp] MCP prompt messages do not support role '${messageData.role}'. Only 'user' and 'model' messages are supported.`, + }); + } + const message = new Message(messageData); + const common = { role: ROLE_MAP[messageData.role] }; + if (message.media) { + const { url, contentType } = message.media; + if (!url.startsWith('data:')) + throw new GenkitError({ + status: 'UNIMPLEMENTED', + message: `[@genkit-ai/mcp] MCP prompt messages only support base64 data images.`, + }); + const mimeType = + contentType || url.substring(url.indexOf(':')! + 1, url.indexOf(';')); + const data = url.substring(url.indexOf(',') + 1); + return { ...common, content: { type: 'image', mimeType, data } }; + } else { + return { ...common, content: { type: 'text', text: message.text } }; + } +} diff --git a/js/plugins/mcp/tsconfig.json b/js/plugins/mcp/tsconfig.json new file mode 100644 index 000000000..596e2cf72 --- /dev/null +++ b/js/plugins/mcp/tsconfig.json @@ -0,0 +1,4 @@ +{ + "extends": "../../tsconfig.json", + "include": ["src"] +} diff --git a/js/plugins/mcp/tsup.config.ts b/js/plugins/mcp/tsup.config.ts new file mode 100644 index 000000000..01dce0a6b --- /dev/null +++ b/js/plugins/mcp/tsup.config.ts @@ -0,0 +1,22 @@ +/** + * Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { defineConfig, Options } from 'tsup'; +import { defaultOptions } from '../../tsup.common'; + +export default defineConfig({ + ...(defaultOptions as Options), +}); diff --git a/js/pnpm-lock.yaml b/js/pnpm-lock.yaml index aecef0b9b..16bdcc101 100644 --- a/js/pnpm-lock.yaml +++ b/js/pnpm-lock.yaml @@ -604,6 +604,46 @@ importers: specifier: ^4.9.0 version: 4.9.5 + plugins/mcp: + dependencies: + '@genkit-ai/core': + specifier: workspace:* + version: link:../../core + '@modelcontextprotocol/sdk': + specifier: 1.0.0 + version: 1.0.0 + genkit: + specifier: workspace:* + version: link:../../genkit + devDependencies: + '@jest/globals': + specifier: ^29.7.0 + version: 29.7.0 + '@types/node': + specifier: ^20.11.16 + version: 20.16.9 + jest: + specifier: ^29.7.0 + version: 29.7.0(@types/node@20.16.9) + npm-run-all: + specifier: ^4.1.5 + version: 4.1.5 + rimraf: + specifier: ^6.0.1 + version: 6.0.1 + ts-jest: + specifier: ^29.1.2 + version: 29.2.5(@babel/core@7.25.7)(@jest/transform@29.7.0)(@jest/types@29.6.3)(babel-jest@29.7.0(@babel/core@7.25.7))(jest@29.7.0(@types/node@20.16.9))(typescript@5.6.3) + tsup: + specifier: ^8.3.5 + version: 8.3.5(postcss@8.4.47)(tsx@4.19.2)(typescript@5.6.3)(yaml@2.6.1) + tsx: + specifier: ^4.19.2 + version: 4.19.2 + typescript: + specifier: ^5.3.0 + version: 5.6.3 + plugins/ollama: dependencies: genkit: @@ -1227,7 +1267,7 @@ importers: version: link:../../plugins/ollama genkitx-openai: specifier: ^0.10.1 - version: 0.10.1(@genkit-ai/ai@0.9.3)(@genkit-ai/core@0.9.3) + version: 0.10.1(@genkit-ai/ai@0.9.5)(@genkit-ai/core@0.9.5) devDependencies: rimraf: specifier: ^6.0.1 @@ -2016,11 +2056,11 @@ packages: '@firebase/util@1.9.5': resolution: {integrity: sha512-PP4pAFISDxsf70l3pEy34Mf3GkkUcVQ3MdKp6aSVb7tcpfUQxnsdV7twDd8EkfB6zZylH6wpUAoangQDmCUMqw==} - '@genkit-ai/ai@0.9.3': - resolution: {integrity: sha512-5u64IcC5GCDmFmYZOGaL6e36pVsy1DyccFhrExFFlNU4tcBnqM76OIIFG1Fu6KGt/fvGFhllWatvBrKdqKESfw==} + '@genkit-ai/ai@0.9.5': + resolution: {integrity: sha512-C1YzQILR3t1U7ZQSsliv8bC5zhufSw7S1rAb8OJN83m4pu2dUQLgUk0KoT1Iu+61Vtg48U+7MFLvVkhwUHM5Xg==} - '@genkit-ai/core@0.9.3': - resolution: {integrity: sha512-D9fVQjIOAY172X1U/98W+4wc3U1QWsilHc4gmLBANdG+Dok9rZpup8N2xac6W8Iy1P7SsL9YE4mUCKikxLSqLQ==} + '@genkit-ai/core@0.9.5': + resolution: {integrity: sha512-iP7uF/try5RBzn5tS+UOEz0IdkAenE5FoWUl+j4lPVqij8PePjXQROGaTAjA+nIyRCrjHq2hLPjZ4kO9mmtZ7w==} '@google-cloud/aiplatform@3.25.0': resolution: {integrity: sha512-qKnJgbyCENjed8e1G5zZGFTxxNKhhaKQN414W2KIVHrLxMFmlMuG+3QkXPOWwXBnT5zZ7aMxypt5og0jCirpHg==} @@ -2526,6 +2566,9 @@ packages: '@material/material-color-utilities@0.2.7': resolution: {integrity: sha512-0FCeqG6WvK4/Cc06F/xXMd/pv4FeisI0c1tUpBbfhA2n9Y8eZEv4Karjbmf2ZqQCPUWMrGp8A571tCjizxoTiQ==} + '@modelcontextprotocol/sdk@1.0.0': + resolution: {integrity: sha512-mbe0otw8vTtZoL5pVucXAmx6oEC7YjdXBgVeFkJXASu4OAnLkrIeNw9zwzU5CwEp19M54bjOUGcna90Dl/H5Bw==} + '@opentelemetry/api-logs@0.52.1': resolution: {integrity: sha512-qnSqB2DQ9TPP96dl8cDubDvrUyWc0/sK81xHTK8eSUspzDM3bsewX903qclQFvVhgStjRWdC5bLb3kQqMkfV5A==} engines: {node: '>=14'} @@ -5552,6 +5595,10 @@ packages: resolution: {integrity: sha512-8zGqypfENjCIqGhgXToC8aB2r7YrBX+AQAfIPs/Mlk+BtPTztOvTS01NRW/3Eh60J+a48lt8qsCzirQ6loCVfA==} engines: {node: '>= 0.8'} + raw-body@3.0.0: + resolution: {integrity: sha512-RmkhL8CAyCRPXCE28MMH0z2PNWQBNk2Q09ZdxM9IOOXwxwZbN+qbWaatPkdkWIKL2ZVDImrN/pK5HTRz2PcS4g==} + engines: {node: '>= 0.8'} + rc@1.2.8: resolution: {integrity: sha512-y3bGgqKj3QBdxLbLkomlohkvsA8gdAiUQlSBJnBhfn+BPxg4bc62d8TcBW15wavDfgexCgccckhcZvywyQYPOw==} hasBin: true @@ -6758,9 +6805,9 @@ snapshots: dependencies: tslib: 2.6.2 - '@genkit-ai/ai@0.9.3': + '@genkit-ai/ai@0.9.5': dependencies: - '@genkit-ai/core': 0.9.3 + '@genkit-ai/core': 0.9.5 '@opentelemetry/api': 1.9.0 '@types/node': 20.16.9 colorette: 2.0.20 @@ -6771,7 +6818,7 @@ snapshots: transitivePeerDependencies: - supports-color - '@genkit-ai/core@0.9.3': + '@genkit-ai/core@0.9.5': dependencies: '@opentelemetry/api': 1.9.0 '@opentelemetry/context-async-hooks': 1.25.1(@opentelemetry/api@1.9.0) @@ -7246,6 +7293,12 @@ snapshots: '@material/material-color-utilities@0.2.7': {} + '@modelcontextprotocol/sdk@1.0.0': + dependencies: + content-type: 1.0.5 + raw-body: 3.0.0 + zod: 3.23.8 + '@opentelemetry/api-logs@0.52.1': dependencies: '@opentelemetry/api': 1.9.0 @@ -8634,6 +8687,21 @@ snapshots: - supports-color - ts-node + create-jest@29.7.0(@types/node@20.16.9): + dependencies: + '@jest/types': 29.6.3 + chalk: 4.1.2 + exit: 0.1.2 + graceful-fs: 4.2.11 + jest-config: 29.7.0(@types/node@20.16.9) + jest-util: 29.7.0 + prompts: 2.4.2 + transitivePeerDependencies: + - '@types/node' + - babel-plugin-macros + - supports-color + - ts-node + cross-env@7.0.3: dependencies: cross-spawn: 7.0.6 @@ -9211,10 +9279,10 @@ snapshots: - encoding - supports-color - genkitx-openai@0.10.1(@genkit-ai/ai@0.9.3)(@genkit-ai/core@0.9.3): + genkitx-openai@0.10.1(@genkit-ai/ai@0.9.5)(@genkit-ai/core@0.9.5): dependencies: - '@genkit-ai/ai': 0.9.3 - '@genkit-ai/core': 0.9.3 + '@genkit-ai/ai': 0.9.5 + '@genkit-ai/core': 0.9.5 openai: 4.53.0(encoding@0.1.13) zod: 3.23.8 transitivePeerDependencies: @@ -9774,6 +9842,25 @@ snapshots: - supports-color - ts-node + jest-cli@29.7.0(@types/node@20.16.9): + dependencies: + '@jest/core': 29.7.0 + '@jest/test-result': 29.7.0 + '@jest/types': 29.6.3 + chalk: 4.1.2 + create-jest: 29.7.0(@types/node@20.16.9) + exit: 0.1.2 + import-local: 3.2.0 + jest-config: 29.7.0(@types/node@20.16.9) + jest-util: 29.7.0 + jest-validate: 29.7.0 + yargs: 17.7.2 + transitivePeerDependencies: + - '@types/node' + - babel-plugin-macros + - supports-color + - ts-node + jest-config@29.7.0(@types/node@20.11.30): dependencies: '@babel/core': 7.25.7 @@ -10061,6 +10148,18 @@ snapshots: - supports-color - ts-node + jest@29.7.0(@types/node@20.16.9): + dependencies: + '@jest/core': 29.7.0 + '@jest/types': 29.6.3 + import-local: 3.2.0 + jest-cli: 29.7.0(@types/node@20.16.9) + transitivePeerDependencies: + - '@types/node' + - babel-plugin-macros + - supports-color + - ts-node + jose@4.15.5: {} joycon@3.1.1: {} @@ -10906,6 +11005,13 @@ snapshots: iconv-lite: 0.4.24 unpipe: 1.0.0 + raw-body@3.0.0: + dependencies: + bytes: 3.1.2 + http-errors: 2.0.0 + iconv-lite: 0.6.3 + unpipe: 1.0.0 + rc@1.2.8: dependencies: deep-extend: 0.6.0 @@ -11388,6 +11494,25 @@ snapshots: '@jest/types': 29.6.3 babel-jest: 29.7.0(@babel/core@7.25.7) + ts-jest@29.2.5(@babel/core@7.25.7)(@jest/transform@29.7.0)(@jest/types@29.6.3)(babel-jest@29.7.0(@babel/core@7.25.7))(jest@29.7.0(@types/node@20.16.9))(typescript@5.6.3): + dependencies: + bs-logger: 0.2.6 + ejs: 3.1.10 + fast-json-stable-stringify: 2.1.0 + jest: 29.7.0(@types/node@20.16.9) + jest-util: 29.7.0 + json5: 2.2.3 + lodash.memoize: 4.1.2 + make-error: 1.3.6 + semver: 7.6.3 + typescript: 5.6.3 + yargs-parser: 21.1.1 + optionalDependencies: + '@babel/core': 7.25.7 + '@jest/transform': 29.7.0 + '@jest/types': 29.6.3 + babel-jest: 29.7.0(@babel/core@7.25.7) + ts-md5@1.3.1: {} tslib@2.6.2: {} @@ -11446,6 +11571,33 @@ snapshots: - tsx - yaml + tsup@8.3.5(postcss@8.4.47)(tsx@4.19.2)(typescript@5.6.3)(yaml@2.6.1): + dependencies: + bundle-require: 5.0.0(esbuild@0.24.0) + cac: 6.7.14 + chokidar: 4.0.1 + consola: 3.2.3 + debug: 4.3.7 + esbuild: 0.24.0 + joycon: 3.1.1 + picocolors: 1.1.1 + postcss-load-config: 6.0.1(postcss@8.4.47)(tsx@4.19.2)(yaml@2.6.1) + resolve-from: 5.0.0 + rollup: 4.25.0 + source-map: 0.8.0-beta.0 + sucrase: 3.35.0 + tinyexec: 0.3.1 + tinyglobby: 0.2.10 + tree-kill: 1.2.2 + optionalDependencies: + postcss: 8.4.47 + typescript: 5.6.3 + transitivePeerDependencies: + - jiti + - supports-color + - tsx + - yaml + tsx@4.19.1: dependencies: esbuild: 0.23.1