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
createMcpHost
orcreateMcpClient
. - Provide Genkit tools and prompts as an MCP server using
createMcpServer
.
Installation
To get started, you'll need Genkit and the MCP plugin:
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.
- Parameters for launching a local server process using the stdio MCP transport.
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 thecreateMcpHost
options 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 themcpServers
configuration (e.g.,localFs/read_file
). - For
createMcpClient
, the namespace is thename
you 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
user
andmodel
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:
Once you start the inspector, you can list prompts and actions and test them out manually.
hybrid server
The server is able to function both locally and remotely, depending on the configuration or use case.
Provides integration between Genkit and the Model Context Protocol (MCP).
Related Resources
Related MCP Servers
- AsecurityAlicenseAqualityA powerful Model Context Protocol (MCP) tool for exploring and managing different types of databases including PostgreSQL, MySQL, and Firestore.Last updated -95MIT License
- -securityFlicense-qualityProvides integration with Github through the Model Context Protocol (MCP), allowing Large Language Models to interact with Github's repositories, issues, pull requests and search functionality.Last updated -5492
- AsecurityAlicenseAqualityGitLabとの連携機能を提供するModel Context Protocol (MCP) サーバーです。GitLabの特定のプロジェクトからパイプラインの失敗情報やマージリクエストへの指摘事項を取得し、AIアシスタントに提供します。Last updated -33MIT License
- -securityAlicense-qualityThe Model Context Protocol (MCP) Jenkins integration is an open-source implementation that bridges Jenkins with AI language models following Anthropic's MCP specification. This project enables secure, contextual AI interactions with Jenkins tools while maintaining data privacy and security.Last updated -38MIT License