Lists available resources from the MCP server
Reads a specific resource from the MCP server by its resource ID
Firebase Genkit MCP provides seamless integration between Genkit and the Model Context Protocol (MCP), an open standard for building servers that provide tools, resources, and prompts to clients. This plugin enables developers to both consume MCP tools as a client and expose Genkit functionality as an MCP server. With Genkit MCP, you can connect to existing MCP servers to access their tools and resources, or create your own MCP server that exposes your Genkit tools and prompts to other applications. The plugin supports multiple transport methods including stdio, SSE, and WebSocket connections.
Firebase Genkit MCP is an experimental plugin that bridges Genkit with the Model Context Protocol (MCP). This integration allows you to:
To get started with Genkit MCP, install both Genkit and the MCP plugin:
npm i genkit genkitx-mcp
The MCP client functionality allows you to connect to any MCP server and use its tools, prompts, and resources within your Genkit application.
import { genkit } from 'genkit';
import { mcpClient } from 'genkitx-mcp';
// Create an MCP client for a local server
const myMcpClient = mcpClient({
name: 'myserver', // This name will namespace all tools and prompts
serverProcess: {
command: 'npx',
args: ['-y', '@some/mcp-server', '--option', 'value'],
},
});
// Add the client to your Genkit instance
const ai = genkit({
plugins: [
myMcpClient,
// other plugins...
],
});
You can connect to MCP servers in several ways:
Local Process (stdio) - Launch a server as a subprocess:
mcpClient({
name: 'local',
serverProcess: {
command: 'npx',
args: ['-y', '@some/package'],
env: { KEY: 'value' }, // Optional environment variables
},
});
Remote Server (SSE) - Connect to a remote server via Server-Sent Events:
mcpClient({
name: 'remote',
serverUrl: 'https://example.com/mcp',
});
WebSocket Connection - Connect via WebSocket:
mcpClient({
name: 'websocket',
serverWebsocketUrl: 'wss://example.com/mcp',
});
Once connected, all MCP server tools and prompts are automatically registered with Genkit and namespaced under the client name you provided:
// Using an MCP tool
const result = await ai.tools.myserver.some_tool({ param1: 'value' });
// Using an MCP prompt
const response = await ai.generate({
prompt: ai.prompts.myserver.some_prompt({ input: 'value' }),
model: 'your-model',
});
MCP resources are accessible through special tools that are automatically registered:
// List available resources
const resources = await ai.tools.myserver.list_resources();
// Read a specific resource
const content = await ai.tools.myserver.read_resource({
resource_id: 'some-resource-id'
});
You can expose your Genkit instance as an MCP server, making all your tools and prompts available to other applications.
import { genkit, z } from 'genkit';
import { mcpServer } from 'genkitx-mcp';
// Create a Genkit instance
const ai = genkit({});
// Define tools and prompts
ai.defineTool(
{
name: 'calculate',
description: 'Perform a calculation',
inputSchema: z.object({
expression: z.string()
}),
outputSchema: z.number(),
},
async ({ expression }) => {
return eval(expression);
}
);
// Start the MCP server
mcpServer(ai, {
name: 'my_calculation_server',
version: '1.0.0'
}).start();
By default, the server uses the stdio transport, which is suitable for local subprocess communication. You can specify a different transport when starting the server.
When working with Genkit MCP, be aware of these limitations:
user
and model
message types are supported in prompts; system
messages are not supportedYou can test your MCP server using the official MCP inspector:
npx @modelcontextprotocol/inspector path/to/your/server.js
The inspector provides a UI to explore and test your server's tools and prompts.