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.

65 lines (60 loc) 2.98 kB
import * as genkit_plugin from 'genkit/plugin'; import { StdioServerParameters } from '@modelcontextprotocol/sdk/client/stdio.js'; import { Transport } from '@modelcontextprotocol/sdk/shared/transport.js'; import { Genkit, PromptAction } from 'genkit'; import { Server } from '@modelcontextprotocol/sdk/server/index.js'; import { ListToolsRequest, ListToolsResult, CallToolRequest, CallToolResult, ListPromptsRequest, ListPromptsResult, GetPromptRequest, GetPromptResult } from '@modelcontextprotocol/sdk/types.js'; import { ToolAction } from 'genkit/tool'; /** * 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. */ declare class GenkitMcpServer { ai: Genkit; options: McpServerOptions; server?: Server; actionsResolved: boolean; toolActions: ToolAction[]; promptActions: PromptAction[]; constructor(ai: Genkit, options: McpServerOptions); setup(): Promise<void>; listTools(req: ListToolsRequest): Promise<ListToolsResult>; callTool(req: CallToolRequest): Promise<CallToolResult>; listPrompts(req: ListPromptsRequest): Promise<ListPromptsResult>; getPrompt(req: GetPromptRequest): Promise<GetPromptResult>; start(transport?: Transport): Promise<void>; } 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; } declare function mcpClient(params: McpClientOptions): genkit_plugin.GenkitPlugin; 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; } declare function mcpServer(ai: Genkit, options: McpServerOptions): GenkitMcpServer; export { GenkitMcpServer as G, type McpClientOptions as M, type McpServerOptions as a, mcpServer as b, mcpClient as m };