Skip to content

Commit 8550c79

Browse files
committed
Generate Go unions from required fields
1 parent 08c67ac commit 8550c79

8 files changed

Lines changed: 584 additions & 129 deletions

File tree

go/generated_session_events.go

Lines changed: 24 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

go/internal/e2e/rpc_mcp_config_e2e_test.go

Lines changed: 48 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,12 @@ func TestRpcMcpConfigE2E(t *testing.T) {
2121

2222
serverName := fmt.Sprintf("sdk-test-%s", randomHex(t))
2323

24-
nodeCmd := "node"
25-
baseConfig := rpc.McpServerConfig{
26-
Command: &nodeCmd,
24+
baseConfig := &rpc.McpServerConfigLocal{
25+
Command: "node",
2726
Args: []string{"-v"},
2827
}
29-
updatedConfig := rpc.McpServerConfig{
30-
Command: &nodeCmd,
28+
updatedConfig := &rpc.McpServerConfigLocal{
29+
Command: "node",
3130
Args: []string{"--version"},
3231
}
3332

@@ -74,11 +73,15 @@ func TestRpcMcpConfigE2E(t *testing.T) {
7473
if !present {
7574
t.Fatalf("Expected %q to still be present after Update", serverName)
7675
}
77-
if updated.Command == nil || *updated.Command != "node" {
78-
t.Errorf("Expected command='node', got %v", updated.Command)
76+
updatedLocal, ok := updated.(*rpc.McpServerConfigLocal)
77+
if !ok {
78+
t.Fatalf("Expected local MCP config, got %T", updated)
7979
}
80-
if len(updated.Args) == 0 || updated.Args[0] != "--version" {
81-
t.Errorf("Expected args[0]='--version', got %v", updated.Args)
80+
if updatedLocal.Command != "node" {
81+
t.Errorf("Expected command='node', got %q", updatedLocal.Command)
82+
}
83+
if len(updatedLocal.Args) == 0 || updatedLocal.Args[0] != "--version" {
84+
t.Errorf("Expected args[0]='--version', got %v", updatedLocal.Args)
8285
}
8386

8487
if _, err := client.RPC.Mcp.Config().Disable(t.Context(), &rpc.McpConfigDisableRequest{Names: []string{serverName}}); err != nil {
@@ -111,7 +114,7 @@ func TestRpcMcpConfigE2E(t *testing.T) {
111114

112115
serverName := fmt.Sprintf("sdk-http-oauth-%s", randomHex(t))
113116

114-
httpType := rpc.McpServerConfigTypeHTTP
117+
httpType := rpc.McpServerConfigHTTPTypeHTTP
115118
urlBase := "https://example.com/mcp"
116119
urlUpdated := "https://example.com/updated-mcp"
117120
clientID := "client-id"
@@ -123,19 +126,19 @@ func TestRpcMcpConfigE2E(t *testing.T) {
123126
var timeoutBase int64 = 3000
124127
var timeoutUpdated int64 = 4000
125128

126-
baseConfig := rpc.McpServerConfig{
129+
baseConfig := &rpc.McpServerConfigHTTP{
127130
Type: &httpType,
128-
URL: &urlBase,
131+
URL: urlBase,
129132
Headers: map[string]string{"Authorization": "Bearer token"},
130133
OauthClientID: &clientID,
131134
OauthPublicClient: &publicFalse,
132135
OauthGrantType: &grantClientCreds,
133136
Tools: []string{"*"},
134137
Timeout: &timeoutBase,
135138
}
136-
updatedConfig := rpc.McpServerConfig{
139+
updatedConfig := &rpc.McpServerConfigHTTP{
137140
Type: &httpType,
138-
URL: &urlUpdated,
141+
URL: urlUpdated,
139142
OauthClientID: &clientIDUpdated,
140143
OauthPublicClient: &publicTrue,
141144
OauthGrantType: &grantAuthCode,
@@ -162,23 +165,27 @@ func TestRpcMcpConfigE2E(t *testing.T) {
162165
if !present {
163166
t.Fatalf("Expected %q to be present after Add", serverName)
164167
}
165-
if added.Type == nil || *added.Type != "http" {
166-
t.Errorf("Expected type='http', got %v", added.Type)
168+
addedHTTP, ok := added.(*rpc.McpServerConfigHTTP)
169+
if !ok {
170+
t.Fatalf("Expected HTTP MCP config, got %T", added)
171+
}
172+
if addedHTTP.Type == nil || *addedHTTP.Type != "http" {
173+
t.Errorf("Expected type='http', got %v", addedHTTP.Type)
167174
}
168-
if added.URL == nil || *added.URL != "https://example.com/mcp" {
169-
t.Errorf("Expected url='https://example.com/mcp', got %v", added.URL)
175+
if addedHTTP.URL != "https://example.com/mcp" {
176+
t.Errorf("Expected url='https://example.com/mcp', got %q", addedHTTP.URL)
170177
}
171-
if got := added.Headers["Authorization"]; got != "Bearer token" {
178+
if got := addedHTTP.Headers["Authorization"]; got != "Bearer token" {
172179
t.Errorf("Expected Authorization='Bearer token', got %q", got)
173180
}
174-
if added.OauthClientID == nil || *added.OauthClientID != "client-id" {
175-
t.Errorf("Expected oauthClientId='client-id', got %v", added.OauthClientID)
181+
if addedHTTP.OauthClientID == nil || *addedHTTP.OauthClientID != "client-id" {
182+
t.Errorf("Expected oauthClientId='client-id', got %v", addedHTTP.OauthClientID)
176183
}
177-
if added.OauthPublicClient == nil || *added.OauthPublicClient {
178-
t.Errorf("Expected oauthPublicClient=false, got %v", added.OauthPublicClient)
184+
if addedHTTP.OauthPublicClient == nil || *addedHTTP.OauthPublicClient {
185+
t.Errorf("Expected oauthPublicClient=false, got %v", addedHTTP.OauthPublicClient)
179186
}
180-
if added.OauthGrantType == nil || *added.OauthGrantType != "client_credentials" {
181-
t.Errorf("Expected oauthGrantType='client_credentials', got %v", added.OauthGrantType)
187+
if addedHTTP.OauthGrantType == nil || *addedHTTP.OauthGrantType != "client_credentials" {
188+
t.Errorf("Expected oauthGrantType='client_credentials', got %v", addedHTTP.OauthGrantType)
182189
}
183190

184191
if _, err := client.RPC.Mcp.Config().Update(t.Context(), &rpc.McpConfigUpdateRequest{
@@ -195,23 +202,27 @@ func TestRpcMcpConfigE2E(t *testing.T) {
195202
if !present {
196203
t.Fatalf("Expected %q to still be present after Update", serverName)
197204
}
198-
if updated.URL == nil || *updated.URL != "https://example.com/updated-mcp" {
199-
t.Errorf("Expected url='https://example.com/updated-mcp', got %v", updated.URL)
205+
updatedHTTP, ok := updated.(*rpc.McpServerConfigHTTP)
206+
if !ok {
207+
t.Fatalf("Expected HTTP MCP config, got %T", updated)
208+
}
209+
if updatedHTTP.URL != "https://example.com/updated-mcp" {
210+
t.Errorf("Expected url='https://example.com/updated-mcp', got %q", updatedHTTP.URL)
200211
}
201-
if updated.OauthClientID == nil || *updated.OauthClientID != "updated-client-id" {
202-
t.Errorf("Expected oauthClientId='updated-client-id', got %v", updated.OauthClientID)
212+
if updatedHTTP.OauthClientID == nil || *updatedHTTP.OauthClientID != "updated-client-id" {
213+
t.Errorf("Expected oauthClientId='updated-client-id', got %v", updatedHTTP.OauthClientID)
203214
}
204-
if updated.OauthPublicClient == nil || !*updated.OauthPublicClient {
205-
t.Errorf("Expected oauthPublicClient=true, got %v", updated.OauthPublicClient)
215+
if updatedHTTP.OauthPublicClient == nil || !*updatedHTTP.OauthPublicClient {
216+
t.Errorf("Expected oauthPublicClient=true, got %v", updatedHTTP.OauthPublicClient)
206217
}
207-
if updated.OauthGrantType == nil || *updated.OauthGrantType != "authorization_code" {
208-
t.Errorf("Expected oauthGrantType='authorization_code', got %v", updated.OauthGrantType)
218+
if updatedHTTP.OauthGrantType == nil || *updatedHTTP.OauthGrantType != "authorization_code" {
219+
t.Errorf("Expected oauthGrantType='authorization_code', got %v", updatedHTTP.OauthGrantType)
209220
}
210-
if len(updated.Tools) == 0 || updated.Tools[0] != "updated-tool" {
211-
t.Errorf("Expected tools[0]='updated-tool', got %v", updated.Tools)
221+
if len(updatedHTTP.Tools) == 0 || updatedHTTP.Tools[0] != "updated-tool" {
222+
t.Errorf("Expected tools[0]='updated-tool', got %v", updatedHTTP.Tools)
212223
}
213-
if updated.Timeout == nil || *updated.Timeout != 4000 {
214-
t.Errorf("Expected timeout=4000, got %v", updated.Timeout)
224+
if updatedHTTP.Timeout == nil || *updatedHTTP.Timeout != 4000 {
225+
t.Errorf("Expected timeout=4000, got %v", updatedHTTP.Timeout)
215226
}
216227

217228
if _, err := client.RPC.Mcp.Config().Remove(t.Context(), &rpc.McpConfigRemoveRequest{Name: serverName}); err != nil {

go/rpc/generated_rpc.go

Lines changed: 37 additions & 48 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

go/rpc/generated_rpc_api_shape_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ var (
1616
_ ExternalToolResult = (*ExternalToolTextResultForLlm)(nil)
1717
_ FilterMapping = FilterMappingEnumMap{}
1818
_ FilterMapping = FilterMappingStringMarkdown
19+
_ McpServerConfig = (*McpServerConfigHTTP)(nil)
20+
_ McpServerConfig = (*McpServerConfigLocal)(nil)
1921
_ UIElicitationFieldValue = UIElicitationStringValue("")
2022
_ UIElicitationFieldValue = UIElicitationStringArrayValue(nil)
2123
_ UIElicitationFieldValue = UIElicitationBooleanValue(false)
@@ -31,7 +33,11 @@ func TestGeneratedRPCAPIShape(t *testing.T) {
3133

3234
assertInterfaceType(t, file, "FilterMapping")
3335
assertTypeExpr(t, fileSet, findTypeSpec(t, file, "FilterMappingEnumMap").Type, "map[string]FilterMappingValue")
34-
assertStructFieldType(t, file, fileSet, "McpServerConfig", "FilterMapping", "FilterMapping")
36+
37+
assertInterfaceType(t, file, "McpServerConfig")
38+
assertStructFieldType(t, file, fileSet, "McpConfigAddRequest", "Config", "McpServerConfig")
39+
assertStructFieldType(t, file, fileSet, "McpConfigList", "Servers", "map[string]McpServerConfig")
40+
assertStructFieldType(t, file, fileSet, "McpConfigUpdateRequest", "Config", "McpServerConfig")
3541
assertStructFieldType(t, file, fileSet, "McpServerConfigHTTP", "FilterMapping", "FilterMapping")
3642
assertStructFieldType(t, file, fileSet, "McpServerConfigLocal", "FilterMapping", "FilterMapping")
3743

0 commit comments

Comments
 (0)