Package com.google.genkit.plugins.mcp
Class MCPServer
java.lang.Object
com.google.genkit.plugins.mcp.MCPServer
MCP Server that exposes Genkit tools, prompts, and flows as MCP endpoints.
This server allows external MCP clients (like Claude Desktop, or other AI agents) to discover and invoke Genkit tools.
Example usage:
// Create Genkit and define some tools
Genkit genkit = Genkit.builder().build();
genkit.defineTool("calculator", "Performs basic math",
Map.of("type", "object", ...),
Map.class,
(ctx, input) -> {
// Tool implementation
return result;
});
// Create and start MCP server
MCPServer mcpServer = new MCPServer(genkit.getRegistry(),
MCPServerOptions.builder()
.name("my-tools-server")
.version("1.0.0")
.build());
// Start with STDIO transport (for use with Claude Desktop, etc.)
mcpServer.start();
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new MCP server with default options.MCPServer(Registry registry, MCPServerOptions options) Creates a new MCP server. -
Method Summary
Modifier and TypeMethodDescriptionGets the server options.booleanChecks if the server is running.voidstart()Starts the MCP server with STDIO transport.voidstart(io.modelcontextprotocol.spec.McpServerTransportProvider transportProvider) Starts the MCP server with a custom transport provider.voidstop()Stops the MCP server.
-
Constructor Details
-
MCPServer
Creates a new MCP server.- Parameters:
registry- the Genkit registry containing tools to exposeoptions- the server options
-
MCPServer
Creates a new MCP server with default options.- Parameters:
registry- the Genkit registry containing tools to expose
-
-
Method Details
-
start
Starts the MCP server with STDIO transport.This is the standard transport for use with Claude Desktop and other MCP clients that launch the server as a subprocess.
- Throws:
GenkitException- if the server fails to start
-
start
public void start(io.modelcontextprotocol.spec.McpServerTransportProvider transportProvider) throws GenkitException Starts the MCP server with a custom transport provider.- Parameters:
transportProvider- the transport provider to use- Throws:
GenkitException- if the server fails to start
-
stop
public void stop()Stops the MCP server. -
isRunning
public boolean isRunning()Checks if the server is running.- Returns:
- true if running
-
getOptions
Gets the server options.- Returns:
- the options
-