Class MCPServerConfig

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

public class MCPServerConfig extends Object
Configuration for connecting to an MCP server.

Supports two transport types:

  • STDIO: Launches a local process and communicates via standard I/O
  • HTTP: Connects to a remote MCP server via HTTP/SSE

Example usage:


 // STDIO transport - launch a local MCP server
 MCPServerConfig filesystemServer = MCPServerConfig.stdio("npx", "-y", "@modelcontextprotocol/server-filesystem",
 		"/tmp");

 // HTTP transport - connect to remote server
 MCPServerConfig remoteServer = MCPServerConfig.http("http://localhost:3001/mcp");

 // With environment variables
 MCPServerConfig serverWithEnv = MCPServerConfig.builder().command("npx")
 		.args("-y", "@modelcontextprotocol/server-github").env("GITHUB_TOKEN", System.getenv("GITHUB_TOKEN"))
 		.build();
 
  • Method Details

    • stdio

      public static MCPServerConfig stdio(String command, String... args)
      Creates a STDIO server configuration.
      Parameters:
      command - the command to execute
      args - arguments for the command
      Returns:
      the server configuration
    • http

      public static MCPServerConfig http(String url)
      Creates an HTTP server configuration.
      Parameters:
      url - the server URL
      Returns:
      the server configuration
    • streamableHttp

      public static MCPServerConfig streamableHttp(String url)
      Creates a Streamable HTTP server configuration.
      Parameters:
      url - the server URL
      Returns:
      the server configuration
    • builder

      public static MCPServerConfig.Builder builder()
      Creates a new builder.
      Returns:
      a new builder
    • getTransportType

      public MCPServerConfig.TransportType getTransportType()
      Gets the transport type.
      Returns:
      the transport type
    • getCommand

      public String getCommand()
      Gets the command for STDIO transport.
      Returns:
      the command, or null for HTTP transport
    • getArgs

      public List<String> getArgs()
      Gets the command arguments.
      Returns:
      the arguments
    • getEnv

      public Map<String,String> getEnv()
      Gets the environment variables.
      Returns:
      the environment variables
    • getUrl

      public String getUrl()
      Gets the URL for HTTP transport.
      Returns:
      the URL, or null for STDIO transport
    • isDisabled

      public boolean isDisabled()
      Whether this server is disabled.
      Returns:
      true if disabled