Skip to content

Commit b5102c5

Browse files
committed
fix: tests
1 parent 5f4f1e8 commit b5102c5

3 files changed

Lines changed: 75 additions & 0 deletions

File tree

internal/config/capability.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55

66
sdkerrors "github.com/ethpandaops/codex-agent-sdk-go/internal/errors"
7+
"github.com/ethpandaops/codex-agent-sdk-go/internal/mcp"
78
)
89

910
// QueryBackend describes the built-in backend selected for one-shot Query.
@@ -187,6 +188,12 @@ func SelectQueryBackend(opts *Options) QueryBackend {
187188
return QueryBackendExec
188189
}
189190

191+
// SDK MCP servers require bidirectional callbacks and cannot be serialized
192+
// to exec CLI flags, so Query must run over app-server mode.
193+
if hasSDKMCPServers(opts.MCPServers) {
194+
return QueryBackendAppServer
195+
}
196+
190197
enabled := EnabledOptionFields(opts)
191198
for field := range enabled {
192199
capability, ok := optionCapabilityByField[field]
@@ -209,6 +216,14 @@ func ValidateOptionsForBackend(opts *Options, backend QueryBackend) error {
209216
return nil
210217
}
211218

219+
if backend == QueryBackendExec && hasSDKMCPServers(opts.MCPServers) {
220+
return fmt.Errorf(
221+
"%w: option MCPServers (WithMCPServers) with SDK server type is unsupported on %s backend",
222+
sdkerrors.ErrUnsupportedOption,
223+
backend,
224+
)
225+
}
226+
212227
enabled := EnabledOptionFields(opts)
213228
for field := range enabled {
214229
capability, ok := optionCapabilityByField[field]
@@ -257,3 +272,21 @@ func ValidateOptionsForBackend(opts *Options, backend QueryBackend) error {
257272

258273
return nil
259274
}
275+
276+
func hasSDKMCPServers(servers map[string]mcp.ServerConfig) bool {
277+
if len(servers) == 0 {
278+
return false
279+
}
280+
281+
for _, server := range servers {
282+
if server == nil {
283+
continue
284+
}
285+
286+
if server.GetType() == mcp.ServerTypeSDK {
287+
return true
288+
}
289+
}
290+
291+
return false
292+
}

internal/config/capability_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"testing"
66

77
"github.com/ethpandaops/codex-agent-sdk-go/internal/hook"
8+
"github.com/ethpandaops/codex-agent-sdk-go/internal/mcp"
89
"github.com/stretchr/testify/require"
910
)
1011

@@ -64,6 +65,24 @@ func TestSelectQueryBackend(t *testing.T) {
6465
},
6566
want: QueryBackendAppServer,
6667
},
68+
{
69+
name: "SDK MCP server requires app-server",
70+
options: &Options{
71+
MCPServers: map[string]mcp.ServerConfig{
72+
"sdk": &mcp.SdkServerConfig{Type: mcp.ServerTypeSDK, Name: "sdk"},
73+
},
74+
},
75+
want: QueryBackendAppServer,
76+
},
77+
{
78+
name: "non-SDK MCP server keeps exec",
79+
options: &Options{
80+
MCPServers: map[string]mcp.ServerConfig{
81+
"stdio": &mcp.StdioServerConfig{Command: "echo"},
82+
},
83+
},
84+
want: QueryBackendExec,
85+
},
6786
}
6887

6988
for _, tt := range tests {
@@ -129,4 +148,18 @@ func TestValidateOptionsForBackend(t *testing.T) {
129148
require.Error(t, err)
130149
require.ErrorContains(t, err, "only supports value \"stdio\"")
131150
})
151+
152+
t.Run("exec backend rejects SDK MCP servers", func(t *testing.T) {
153+
t.Parallel()
154+
155+
opts := &Options{
156+
MCPServers: map[string]mcp.ServerConfig{
157+
"sdk": &mcp.SdkServerConfig{Type: mcp.ServerTypeSDK, Name: "sdk"},
158+
},
159+
}
160+
161+
err := ValidateOptionsForBackend(opts, QueryBackendExec)
162+
require.Error(t, err)
163+
require.ErrorContains(t, err, "MCPServers")
164+
})
132165
}

query_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,15 @@ func TestRequiresAppServerQuery(t *testing.T) {
402402
{name: "fork requires app-server", options: &CodexAgentOptions{ForkSession: true}, want: true},
403403
{name: "continue requires app-server", options: &CodexAgentOptions{ContinueConversation: true}, want: true},
404404
{name: "output format requires app-server", options: &CodexAgentOptions{OutputFormat: map[string]any{"type": "json_schema"}}, want: true},
405+
{
406+
name: "sdk mcp server requires app-server",
407+
options: &CodexAgentOptions{
408+
MCPServers: map[string]MCPServerConfig{
409+
"sdk": &MCPSdkServerConfig{Type: MCPServerTypeSDK, Name: "sdk"},
410+
},
411+
},
412+
want: true,
413+
},
405414
}
406415

407416
for _, tt := range tests {

0 commit comments

Comments
 (0)