This server provides several utility and demonstration actions:
Echo: Returns back a provided message
Add: Performs addition of two numbers
PrintEnv: Displays environment variables for debugging
LongRunningOperation: Simulates a long-running task with progress updates
SampleLLM: Samples from an LLM using a provided prompt with optional token limit
GetTinyImage: Retrieves the MCP_TINY_IMAGE
Allows integration with the filesystem server through MCP, enabling reading files from allowed directories
Genkit MCP
This plugin provides integration between Genkit and the Model Context Protocol (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:
Consume MCP tools, prompts, and resources as a client using
createMcpHostorcreateMcpClient.Provide Genkit tools and prompts as an MCP server using
createMcpServer.
Installation
To get started, you'll need Genkit and the MCP plugin:
Related MCP server: Github MCP Server
MCP Host
To connect to one or more MCP servers, you use the createMcpHost function. This function returns a GenkitMcpHost instance that manages connections to the configured MCP servers.
The createMcpHost function initializes a GenkitMcpHost instance, which handles the lifecycle and communication with the defined MCP servers.
createMcpHost() Options
name: (optional, string) A name for the MCP host plugin itself. Defaults to 'genkitx-mcp'.version: (optional, string) The version of the MCP host plugin. Defaults to "1.0.0".rawToolResponses: (optional, boolean) Whentrue, tool responses are returned in their raw MCP format; otherwise, they are processed for Genkit compatibility. Defaults tofalse.mcpServers: (required, object) An object where each key is a client-side name (namespace) for an MCP server, and the value is the configuration for that server.Each server configuration object can include:
disabled: (optional, boolean) Iftrue, this server connection will not be attempted. Defaults tofalse.One of the following server connection configurations:
Parameters for launching a local server process using the stdio MCP transport.
command: (required, string) Shell command path for launching the MCP server (e.g.,npx,python).args: (optional, string[]) Array of string arguments to pass to the command.env: (optional, Record<string, string>) Key-value object of environment variables.
url: (string) The URL of a remote server to connect to using the Streamable HTTP MCP transport.transport: An existing MCP transport object for connecting to the server.
MCP Client (Single Server)
For scenarios where you only need to connect to a single MCP server, or prefer to manage client instances individually, you can use createMcpClient.
createMcpClient() Options
The createMcpClient function takes an McpClientOptions object:
name: (required, string) A unique name for this client instance. This name will be used as the namespace for its tools and prompts.version: (optional, string) Version for this client instance. Defaults to "1.0.0".Additionally, it supports all options from
McpServerConfig(e.g.,disabled,rawToolResponses, and transport configurations), as detailed in thecreateMcpHostoptions section.
Using MCP Actions (Tools, Prompts)
Both GenkitMcpHost (via getActiveTools()) and GenkitMcpClient (via getActiveTools()) discover available tools from their connected and enabled MCP server(s). These tools are standard Genkit ToolAction instances and can be provided to Genkit models.
MCP prompts can be fetched using McpHost.getPrompt(serverName, promptName) or mcpClient.getPrompt(promptName). These return an ExecutablePrompt.
All MCP actions (tools, prompts, resources) are namespaced.
For
createMcpHost, the namespace is the key you provide for that server in themcpServersconfiguration (e.g.,localFs/read_file).For
createMcpClient, the namespace is thenameyou provide in its options (e.g.,myFileSystemClient/list_resources).
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:
If the content is text and valid JSON, it is parsed and returned as a JSON object.
If the content is text but not valid JSON, the raw text is returned.
If the content contains a single non-text part (e.g., an image), that part is returned directly.
If the content contains multiple or mixed parts (e.g., text and an image), the full content response array is returned.
MCP Server
You can also expose all of the tools and prompts from a Genkit instance as an MCP server using the createMcpServer function.
The createMcpServer function returns a GenkitMcpServer instance. The start() method on this instance will start an MCP server (using the stdio transport by default) that exposes all registered Genkit tools and prompts. To start the server with a different MCP transport, you can pass the transport instance to the start() method (e.g., server.start(customMcpTransport)).
createMcpServer() Options
name: (required, string) The name you want to give your server for MCP inspection.version: (optional, string) The version your server will advertise to clients. Defaults to "1.0.0".
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
userandmodelmessages.systemmessages 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:
Once you start the inspector, you can list prompts and actions and test them out manually.