GEPA Adapter Changes¶
This page explains the GEPA Code Mode adapter changes used by this project.
What Code Mode Means Here¶
In this project, "Code Mode" means a code-first MCP tool orchestration pattern where the model uses a small tool surface (typically discovery + execution) and generates code to drive multi-step work.
Background:
- Cloudflare blog (Code Mode + MCP context):
https://blog.cloudflare.com/code-mode-mcp/ - UTCP Code Mode implementation:
https://github.com/universal-tool-calling-protocol/code-mode
What Changed¶
The adapter keeps optimization logic in GEPA and keeps runtime execution in runner classes.
The runtime side now supports three patterns:
MCPStdioCodeModeRunner- local MCP servers over stdio
-
good for UTCP and local development
-
MCPStreamableHTTPCodeModeRunner - direct MCP over streamable HTTP
-
works with Cloudflare MCP endpoint
https://mcp.cloudflare.com/mcp -
HTTPCodeModeRunner - JSON bridge endpoint
- useful if your platform exposes non MCP HTTP contract
Why This Matters¶
Teams can optimize prompt and tool policy text once, while changing runtime transport without rewriting GEPA logic.
This makes contributions back to GEPA small:
- adapter core stays simple
- transport logic stays in runners
- examples show local and Cloudflare paths
What GEPA Optimizes¶
GEPA optimizes candidate text fields:
system_promptcodemode_descriptiontool_alias_map(optional JSON string)tool_description_overrides(optional JSON string)
GEPA does not mutate your server code.
How Execution Works¶
For each dataset row:
- GEPA sends candidate text to the runner.
- Runner calls MCP or HTTP runtime tools.
- Runner returns:
final_answergenerated_codeselected_tooltool_callslogserror- Metric scores result.
- GEPA updates candidate text in optimization mode.
Cloudflare MCP Flow¶
Use direct MCP transport:
mcp-http defaults to https://mcp.cloudflare.com/mcp.
You can still override with --endpoint.
Cloudflare response note for this demo:
- case 1 may return structured JSON from
search(tool paths, counts) - case 2 should return
{"result": 42}fromexecute - average score may be
0.5with current string-match metric
Treat tool selection and response structure as the primary integration signal for this demo.
Local MCP Flow¶
Use stdio transport:
GEPA Example Scripts¶
If you are validating GEPA adapter behavior directly, use:
code_mode_mcp_cloudflare_example.pyfor Cloudflare MCPcode_mode_mcp_local_stdio_example.pyfor local stdio MCP
These are real transport examples, not static mocks.