Class MCPServer

java.lang.Object
com.google.genkit.plugins.mcp.MCPServer

public class MCPServer extends Object
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 Details

    • MCPServer

      public MCPServer(Registry registry, MCPServerOptions options)
      Creates a new MCP server.
      Parameters:
      registry - the Genkit registry containing tools to expose
      options - the server options
    • MCPServer

      public MCPServer(Registry registry)
      Creates a new MCP server with default options.
      Parameters:
      registry - the Genkit registry containing tools to expose
  • Method Details

    • start

      public void start() throws GenkitException
      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

      public MCPServerOptions getOptions()
      Gets the server options.
      Returns:
      the options