genkit_mcp library

MCP (Model Context Protocol) integration for Genkit Dart.

Use this library to connect Genkit to MCP servers as a client or host, or to expose Genkit tools, prompts, and resources as an MCP server.

Classes

GenkitMcpClient
A client connection to a single MCP server.
GenkitMcpHost
Manages connections to multiple MCP servers and aggregates their tools, prompts, and resources.
GenkitMcpServer
An MCP server that exposes Genkit tools, prompts, and resources over the Model Context Protocol.
McpClientOptions
Options for a GenkitMcpClient instance.
McpClientOptionsWithCache
McpClientOptions with an additional cacheTtlMillis for the registry plugin created by defineMcpClient.
McpClientPlugin
A GenkitPlugin that exposes a single GenkitMcpClient's tools, prompts, and resources through the Genkit registry.
McpHostOptions
Options for a GenkitMcpHost instance.
McpHostOptionsWithCache
McpHostOptions with an additional cacheTtlMillis for the registry plugin created by defineMcpHost.
McpHostPlugin
McpRoot
An MCP root entry advertised to the server via roots/list.
McpServerConfig
Configuration for connecting to a single MCP server.
McpServerOptions
Configuration for a GenkitMcpServer.
McpServerTransport
Base class for MCP server transports.
StreamableHttpClientTransport
StreamableHttpServerTransport
Streamable HTTP transport for MCP servers.

Functions

createMcpClient(McpClientOptions options) GenkitMcpClient
Creates an MCP client that connects to a single MCP server.
createMcpHost(McpHostOptions options) GenkitMcpHost
Creates an MCP host that manages connections to multiple MCP servers.
createMcpServer(Genkit ai, McpServerOptions options) GenkitMcpServer
Creates an MCP server that exposes all tools, prompts, and resources registered in ai over the Model Context Protocol.
defineMcpClient(Genkit ai, McpClientOptionsWithCache options) GenkitMcpClient
Creates an MCP client and registers it as a GenkitPlugin so that tools, prompts, and resources are discoverable through ai's registry.
defineMcpHost(Genkit ai, McpHostOptionsWithCache options) GenkitMcpHost
Creates an MCP host and registers it as a GenkitPlugin so that tools, prompts, and resources from all connected servers are discoverable through ai's registry.

Typedefs

McpElicitationHandler = Future<Map<String, dynamic>> Function(Map<String, dynamic> params)
Handler for server-initiated elicitation/create requests.
McpNotificationHandler = void Function(String method, Map<String, dynamic> params)
Handler for server notifications (e.g. notifications/tools/list_changed).
McpSamplingHandler = Future<Map<String, dynamic>> Function(Map<String, dynamic> params)
Handler for server-initiated sampling/createMessage requests.