GEPA.Adapters.MCP (GEPA v0.3.0)

Copy Markdown View Source

MCP tool-use adapter.

The adapter optimizes tool descriptions/system prompts for tasks that require a model to choose and call MCP tools. It supports dependency-free testing via GEPA.Adapters.MCP.Client.Static, while the transport boundary is represented by GEPA.Adapters.MCP.Client.

Summary

Functions

Build the tool-use system prompt for a candidate and available tool schemas.

Extract a plain-text result from common MCP tool response shapes.

Generate reflective feedback for an MCP tool-use trajectory.

Types

t()

@type t() :: %GEPA.Adapters.MCP{
  answer_generator: term(),
  base_system_prompt: term(),
  client: term(),
  enable_two_pass: term(),
  failure_score: term(),
  metric_fn: term(),
  model: term(),
  remote_headers: term(),
  remote_transport: term(),
  remote_url: term(),
  scoring_fn: term(),
  server_params: term(),
  task_model: term(),
  tool_names: term(),
  tool_selector: term(),
  two_pass?: term()
}

Functions

build_system_prompt(adapter, candidate, tools)

@spec build_system_prompt(t(), map(), [map()]) :: String.t()

Build the tool-use system prompt for a candidate and available tool schemas.

extract_tool_response(result)

@spec extract_tool_response(term()) :: String.t()

Extract a plain-text result from common MCP tool response shapes.

generate_tool_feedback(trajectory, score)

@spec generate_tool_feedback(map() | GEPA.Adapters.MCP.Trajectory.t(), number()) ::
  String.t()

Generate reflective feedback for an MCP tool-use trajectory.

new(opts \\ [])

@spec new(keyword() | map()) :: t()