Skip to content

Commit 4c14832

Browse files
authored
test(source/alloydbainl): create MCP integration tests (googleapis#2921)
This PR adds the mapped integration tests for AlloyDB AINL tools using the native MCP harness.
1 parent 6ed9700 commit 4c14832

File tree

5 files changed

+388
-97
lines changed

5 files changed

+388
-97
lines changed

tests/alloydb/alloydb_mcp_test.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,25 @@ func TestAlloyDBListTools(t *testing.T) {
3737
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
3838
defer cancel()
3939

40-
toolsFile := getAlloyDBToolsConfig()
40+
toolsFile := map[string]any{
41+
"sources": map[string]any{
42+
"alloydb-admin-source": map[string]any{
43+
"type": "alloydb-admin",
44+
},
45+
},
46+
"tools": map[string]any{
47+
"alloydb-list-clusters": map[string]any{
48+
"type": "alloydb-list-clusters",
49+
"source": "alloydb-admin-source",
50+
"description": "Lists all AlloyDB clusters in a given project and location.",
51+
},
52+
"alloydb-list-users": map[string]any{
53+
"type": "alloydb-list-users",
54+
"source": "alloydb-admin-source",
55+
"description": "Lists all AlloyDB users within a specific cluster.",
56+
},
57+
},
58+
}
4159

4260
// Start the toolbox server
4361
cmd, cleanup, err := tests.StartCmd(ctx, toolsFile)

tests/alloydbainl/alloydb_ai_nl_integration_test.go

Lines changed: 0 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"encoding/json"
2121
"io"
2222
"net/http"
23-
"os"
2423
"reflect"
2524
"regexp"
2625
"strings"
@@ -32,47 +31,6 @@ import (
3231
"github.com/googleapis/mcp-toolbox/tests"
3332
)
3433

35-
var (
36-
AlloyDBAINLSourceType = "alloydb-postgres"
37-
AlloyDBAINLToolType = "alloydb-ai-nl"
38-
AlloyDBAINLProject = os.Getenv("ALLOYDB_AI_NL_PROJECT")
39-
AlloyDBAINLRegion = os.Getenv("ALLOYDB_AI_NL_REGION")
40-
AlloyDBAINLCluster = os.Getenv("ALLOYDB_AI_NL_CLUSTER")
41-
AlloyDBAINLInstance = os.Getenv("ALLOYDB_AI_NL_INSTANCE")
42-
AlloyDBAINLDatabase = os.Getenv("ALLOYDB_AI_NL_DATABASE")
43-
AlloyDBAINLUser = os.Getenv("ALLOYDB_AI_NL_USER")
44-
AlloyDBAINLPass = os.Getenv("ALLOYDB_AI_NL_PASS")
45-
)
46-
47-
func getAlloyDBAINLVars(t *testing.T) map[string]any {
48-
switch "" {
49-
case AlloyDBAINLProject:
50-
t.Fatal("'ALLOYDB_AI_NL_PROJECT' not set")
51-
case AlloyDBAINLRegion:
52-
t.Fatal("'ALLOYDB_AI_NL_REGION' not set")
53-
case AlloyDBAINLCluster:
54-
t.Fatal("'ALLOYDB_AI_NL_CLUSTER' not set")
55-
case AlloyDBAINLInstance:
56-
t.Fatal("'ALLOYDB_AI_NL_INSTANCE' not set")
57-
case AlloyDBAINLDatabase:
58-
t.Fatal("'ALLOYDB_AI_NL_DATABASE' not set")
59-
case AlloyDBAINLUser:
60-
t.Fatal("'ALLOYDB_AI_NL_USER' not set")
61-
case AlloyDBAINLPass:
62-
t.Fatal("'ALLOYDB_AI_NL_PASS' not set")
63-
}
64-
return map[string]any{
65-
"type": AlloyDBAINLSourceType,
66-
"project": AlloyDBAINLProject,
67-
"cluster": AlloyDBAINLCluster,
68-
"instance": AlloyDBAINLInstance,
69-
"region": AlloyDBAINLRegion,
70-
"database": AlloyDBAINLDatabase,
71-
"user": AlloyDBAINLUser,
72-
"password": AlloyDBAINLPass,
73-
}
74-
}
75-
7634
func TestAlloyDBAINLToolEndpoints(t *testing.T) {
7735
sourceConfig := getAlloyDBAINLVars(t)
7836
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
@@ -277,59 +235,6 @@ func runAINLToolInvokeTest(t *testing.T) {
277235

278236
}
279237

280-
func getAINLToolsConfig(sourceConfig map[string]any) map[string]any {
281-
// Write config into a file and pass it to command
282-
toolsFile := map[string]any{
283-
"sources": map[string]any{
284-
"my-instance": sourceConfig,
285-
},
286-
"authServices": map[string]any{
287-
"my-google-auth": map[string]any{
288-
"type": "google",
289-
"clientId": tests.ClientId,
290-
},
291-
},
292-
"tools": map[string]any{
293-
"my-simple-tool": map[string]any{
294-
"type": AlloyDBAINLToolType,
295-
"source": "my-instance",
296-
"description": "Simple tool to test end to end functionality.",
297-
"nlConfig": "my_nl_config",
298-
},
299-
"my-auth-tool": map[string]any{
300-
"type": AlloyDBAINLToolType,
301-
"source": "my-instance",
302-
"description": "Tool to test authenticated parameters.",
303-
"nlConfig": "my_nl_config",
304-
"nlConfigParameters": []map[string]any{
305-
{
306-
"name": "email",
307-
"type": "string",
308-
"description": "user email",
309-
"authServices": []map[string]string{
310-
{
311-
"name": "my-google-auth",
312-
"field": "email",
313-
},
314-
},
315-
},
316-
},
317-
},
318-
"my-auth-required-tool": map[string]any{
319-
"type": AlloyDBAINLToolType,
320-
"source": "my-instance",
321-
"description": "Tool to test auth required invocation.",
322-
"nlConfig": "my_nl_config",
323-
"authRequired": []string{
324-
"my-google-auth",
325-
},
326-
},
327-
},
328-
}
329-
330-
return toolsFile
331-
}
332-
333238
func runAINLMCPToolCallMethod(t *testing.T) {
334239
sessionId := tests.RunInitialize(t, "2024-11-05")
335240
header := map[string]string{}

0 commit comments

Comments
 (0)