Class McpAgent

java.lang.Object
dev.langchain4j.agentic.mcp.McpAgent

public class McpAgent extends Object
Provides type-safe factory methods to create MCP client agent builders.

An MCP client agent wraps a single MCP tool as a non-AI agent, allowing it to be composed with other agents in sequences, loops, supervisors, and other workflow patterns.

UntypedAgent agent = McpAgentBuilder
        .mcpBuilder(mcpClient)
        .toolName("my_tool")
        .inputKeys("arg1", "arg2")
        .outputKey("result")
        .build();
  • Method Details

    • builder

      public static McpClientBuilder<UntypedAgent> builder(McpClient mcpClient)
      Creates a builder for an untyped MCP client agent.
      Parameters:
      mcpClient - the MCP client instance used to discover and execute the tool
      Returns:
      a new McpClientBuilder instance
    • builder

      public static <T> McpClientBuilder<T> builder(McpClient mcpClient, Class<T> agentServiceClass)
      Creates a builder for a typed MCP client agent implementing the given agent service interface.
      Parameters:
      mcpClient - the MCP client instance used to discover and execute the tool
      agentServiceClass - the class of the agent service interface
      Returns:
      a new McpClientBuilder instance