Skip to content

Commit 7f8220e

Browse files
committed
Run modernize
1 parent 0505dc8 commit 7f8220e

35 files changed

+360
-378
lines changed

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ doc:
33

44
format:
55
go fmt ./...
6+
# go run golang.org/x/tools/gopls/internal/analysis/modernize/cmd/modernize@latest -fix -test ./...
7+
modernize -fix -test ./...
68
cd docs-site && npm run format
79

810
lint:

cmd/mcp-front/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ func main() {
151151
os.Exit(1)
152152
}
153153

154-
log.LogInfoWithFields("main", "Starting mcp-front", map[string]interface{}{
154+
log.LogInfoWithFields("main", "Starting mcp-front", map[string]any{
155155
"version": BuildVersion,
156156
"config": *conf,
157157
})

integration/inline_test.go

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ func TestInlineMCPServer(t *testing.T) {
3636

3737
// Test 1: Basic echo tool (static args)
3838
t.Run("echo tool", func(t *testing.T) {
39-
params := map[string]interface{}{
39+
params := map[string]any{
4040
"name": "echo",
41-
"arguments": map[string]interface{}{
41+
"arguments": map[string]any{
4242
"message": "Hello, inline MCP!",
4343
},
4444
}
@@ -47,18 +47,18 @@ func TestInlineMCPServer(t *testing.T) {
4747
require.NoError(t, err, "Failed to call echo tool")
4848

4949
// Check for error in response
50-
errorMap, hasError := result["error"].(map[string]interface{})
50+
errorMap, hasError := result["error"].(map[string]any)
5151
assert.False(t, hasError, "Echo tool returned error: %v", errorMap)
5252

5353
// Verify result
54-
resultMap, ok := result["result"].(map[string]interface{})
54+
resultMap, ok := result["result"].(map[string]any)
5555
require.True(t, ok, "Expected result in response")
5656

57-
content, ok := resultMap["content"].([]interface{})
57+
content, ok := resultMap["content"].([]any)
5858
require.True(t, ok, "Expected content in result")
5959
require.NotEmpty(t, content, "Expected content array")
6060

61-
firstContent, ok := content[0].(map[string]interface{})
61+
firstContent, ok := content[0].(map[string]any)
6262
require.True(t, ok, "Expected content item to be map")
6363

6464
text, ok := firstContent["text"].(string)
@@ -69,18 +69,18 @@ func TestInlineMCPServer(t *testing.T) {
6969

7070
// Test 2: Environment variables
7171
t.Run("environment variables", func(t *testing.T) {
72-
params := map[string]interface{}{
72+
params := map[string]any{
7373
"name": "env_test",
74-
"arguments": map[string]interface{}{},
74+
"arguments": map[string]any{},
7575
}
7676

7777
result, err := client.SendMCPRequest("tools/call", params)
7878
require.NoError(t, err, "Failed to call env_test tool")
7979

8080
// Check result
81-
resultMap, _ := result["result"].(map[string]interface{})
82-
content, _ := resultMap["content"].([]interface{})
83-
firstContent, _ := content[0].(map[string]interface{})
81+
resultMap, _ := result["result"].(map[string]any)
82+
content, _ := resultMap["content"].([]any)
83+
firstContent, _ := content[0].(map[string]any)
8484
text, _ := firstContent["text"].(string)
8585

8686
// printenv outputs all environment variables
@@ -90,28 +90,28 @@ func TestInlineMCPServer(t *testing.T) {
9090

9191
// Test 3: Static output test
9292
t.Run("static output", func(t *testing.T) {
93-
params := map[string]interface{}{
93+
params := map[string]any{
9494
"name": "static_test",
95-
"arguments": map[string]interface{}{},
95+
"arguments": map[string]any{},
9696
}
9797

9898
result, err := client.SendMCPRequest("tools/call", params)
9999
require.NoError(t, err, "Failed to call static_test tool")
100100

101101
// Check result
102-
resultMap, _ := result["result"].(map[string]interface{})
103-
content, _ := resultMap["content"].([]interface{})
104-
firstContent, _ := content[0].(map[string]interface{})
102+
resultMap, _ := result["result"].(map[string]any)
103+
content, _ := resultMap["content"].([]any)
104+
firstContent, _ := content[0].(map[string]any)
105105
text, _ := firstContent["text"].(string)
106106

107107
assert.Contains(t, text, "Static output: test")
108108
})
109109

110110
// Test 4: JSON output parsing
111111
t.Run("JSON output", func(t *testing.T) {
112-
params := map[string]interface{}{
112+
params := map[string]any{
113113
"name": "json_output",
114-
"arguments": map[string]interface{}{
114+
"arguments": map[string]any{
115115
"value": "test-input",
116116
},
117117
}
@@ -120,9 +120,9 @@ func TestInlineMCPServer(t *testing.T) {
120120
require.NoError(t, err, "Failed to call json_output tool")
121121

122122
// For JSON output, the content should be parsed as JSON
123-
resultMap, _ := result["result"].(map[string]interface{})
124-
content, _ := resultMap["content"].([]interface{})
125-
firstContent, _ := content[0].(map[string]interface{})
123+
resultMap, _ := result["result"].(map[string]any)
124+
content, _ := resultMap["content"].([]any)
125+
firstContent, _ := content[0].(map[string]any)
126126

127127
// The JSON output should be in the text field as a string
128128
text, ok := firstContent["text"].(string)
@@ -135,16 +135,16 @@ func TestInlineMCPServer(t *testing.T) {
135135

136136
// Test 6: Error handling
137137
t.Run("failing tool", func(t *testing.T) {
138-
params := map[string]interface{}{
138+
params := map[string]any{
139139
"name": "failing_tool",
140-
"arguments": map[string]interface{}{},
140+
"arguments": map[string]any{},
141141
}
142142

143143
result, err := client.SendMCPRequest("tools/call", params)
144144
require.NoError(t, err, "Request should succeed even if tool fails")
145145

146146
// Check for error in response
147-
errorMap, hasError := result["error"].(map[string]interface{})
147+
errorMap, hasError := result["error"].(map[string]any)
148148
assert.True(t, hasError, "Expected error for failing tool")
149149

150150
if hasError {
@@ -158,21 +158,21 @@ func TestInlineMCPServer(t *testing.T) {
158158

159159
// Test 7: List tools
160160
t.Run("list tools", func(t *testing.T) {
161-
result, err := client.SendMCPRequest("tools/list", map[string]interface{}{})
161+
result, err := client.SendMCPRequest("tools/list", map[string]any{})
162162
require.NoError(t, err, "Failed to list tools")
163163

164164
// Check result
165-
resultMap, ok := result["result"].(map[string]interface{})
165+
resultMap, ok := result["result"].(map[string]any)
166166
require.True(t, ok, "Expected result in response")
167167

168-
tools, ok := resultMap["tools"].([]interface{})
168+
tools, ok := resultMap["tools"].([]any)
169169
require.True(t, ok, "Expected tools array")
170170
assert.Len(t, tools, 6, "Expected 6 tools")
171171

172172
// Verify tool names
173173
toolNames := make([]string, 0)
174174
for _, tool := range tools {
175-
toolMap, _ := tool.(map[string]interface{})
175+
toolMap, _ := tool.(map[string]any)
176176
name, _ := toolMap["name"].(string)
177177
toolNames = append(toolNames, name)
178178
}

integration/integration_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ func TestIntegration(t *testing.T) {
4040

4141
t.Log("Connected to MCP server with session")
4242

43-
queryParams := map[string]interface{}{
43+
queryParams := map[string]any{
4444
"name": "query",
45-
"arguments": map[string]interface{}{
45+
"arguments": map[string]any{
4646
"sql": "SELECT COUNT(*) as user_count FROM users",
4747
},
4848
}
@@ -55,33 +55,33 @@ func TestIntegration(t *testing.T) {
5555
require.NotNil(t, result, "Expected some response from MCP server")
5656

5757
// Check for error in response
58-
errorMap, hasError := result["error"].(map[string]interface{})
58+
errorMap, hasError := result["error"].(map[string]any)
5959
assert.False(t, hasError, "Query returned error: %v", errorMap)
6060

6161
// Verify we got result content
62-
resultMap, ok := result["result"].(map[string]interface{})
62+
resultMap, ok := result["result"].(map[string]any)
6363
require.True(t, ok, "Expected result in response")
6464

65-
content, ok := resultMap["content"].([]interface{})
65+
content, ok := resultMap["content"].([]any)
6666
require.True(t, ok, "Expected content in result")
6767
assert.NotEmpty(t, content, "Query result missing content")
6868
t.Log("Query executed successfully")
6969

7070
// Test resources list
71-
resourcesResult, err := client.SendMCPRequest("resources/list", map[string]interface{}{})
71+
resourcesResult, err := client.SendMCPRequest("resources/list", map[string]any{})
7272
require.NoError(t, err, "Failed to list resources")
7373

7474
t.Logf("Resources response: %+v", resourcesResult)
7575

7676
// Check for error in resources response
77-
errorMap, hasError = resourcesResult["error"].(map[string]interface{})
77+
errorMap, hasError = resourcesResult["error"].(map[string]any)
7878
assert.False(t, hasError, "Resources list returned error: %v", errorMap)
7979

8080
// Verify we got resources
81-
resultMap, ok = resourcesResult["result"].(map[string]interface{})
81+
resultMap, ok = resourcesResult["result"].(map[string]any)
8282
require.True(t, ok, "Expected result in resources response")
8383

84-
resources, ok := resultMap["resources"].([]interface{})
84+
resources, ok := resultMap["resources"].([]any)
8585
require.True(t, ok, "Expected resources array in result")
8686
assert.NotEmpty(t, resources, "Expected at least one resource")
8787
t.Logf("Found %d resources", len(resources))

integration/isolation_test.go

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package integration
22

33
import (
4+
"slices"
45
"testing"
56
"time"
67

@@ -53,11 +54,8 @@ func TestMultiUserSessionIsolation(t *testing.T) {
5354
var client1Container string
5455
for _, container := range containersAfterClient1 {
5556
isNew := true
56-
for _, initial := range initialContainers {
57-
if container == initial {
58-
isNew = false
59-
break
60-
}
57+
if slices.Contains(initialContainers, container) {
58+
isNew = false
6159
}
6260
if isNew {
6361
client1Container = container
@@ -70,9 +68,9 @@ func TestMultiUserSessionIsolation(t *testing.T) {
7068
t.Error("No new container created for client1")
7169
}
7270

73-
query1Result, err := client1.SendMCPRequest("tools/call", map[string]interface{}{
71+
query1Result, err := client1.SendMCPRequest("tools/call", map[string]any{
7472
"name": "query",
75-
"arguments": map[string]interface{}{
73+
"arguments": map[string]any{
7674
"sql": "SELECT 'user1-query1' as test_id, COUNT(*) as count FROM users",
7775
},
7876
})
@@ -101,11 +99,8 @@ func TestMultiUserSessionIsolation(t *testing.T) {
10199
var client2Container string
102100
for _, container := range containersAfterClient2 {
103101
isNew := true
104-
for _, existing := range containersAfterClient1 {
105-
if container == existing {
106-
isNew = false
107-
break
108-
}
102+
if slices.Contains(containersAfterClient1, container) {
103+
isNew = false
109104
}
110105
if isNew {
111106
client2Container = container
@@ -126,9 +121,9 @@ func TestMultiUserSessionIsolation(t *testing.T) {
126121
t.Logf("Confirmed different stdio processes: User1 container=%s, User2 container=%s", client1Container, client2Container)
127122
}
128123

129-
query2Result, err := client2.SendMCPRequest("tools/call", map[string]interface{}{
124+
query2Result, err := client2.SendMCPRequest("tools/call", map[string]any{
130125
"name": "query",
131-
"arguments": map[string]interface{}{
126+
"arguments": map[string]any{
132127
"sql": "SELECT 'user2-query1' as test_id, COUNT(*) as count FROM orders",
133128
},
134129
})
@@ -139,9 +134,9 @@ func TestMultiUserSessionIsolation(t *testing.T) {
139134

140135
// Step 3: First user sends another query
141136
t.Log("\nStep 3: First user sends another query")
142-
query3Result, err := client1.SendMCPRequest("tools/call", map[string]interface{}{
137+
query3Result, err := client1.SendMCPRequest("tools/call", map[string]any{
143138
"name": "query",
144-
"arguments": map[string]interface{}{
139+
"arguments": map[string]any{
145140
"sql": "SELECT 'user1-query2' as test_id, current_timestamp as ts",
146141
},
147142
})
@@ -152,9 +147,9 @@ func TestMultiUserSessionIsolation(t *testing.T) {
152147

153148
// Step 4: First user sends another query
154149
t.Log("\nStep 4: First user sends another query")
155-
query4Result, err := client1.SendMCPRequest("tools/call", map[string]interface{}{
150+
query4Result, err := client1.SendMCPRequest("tools/call", map[string]any{
156151
"name": "query",
157-
"arguments": map[string]interface{}{
152+
"arguments": map[string]any{
158153
"sql": "SELECT 'user1-query3' as test_id, version() as db_version",
159154
},
160155
})
@@ -165,9 +160,9 @@ func TestMultiUserSessionIsolation(t *testing.T) {
165160

166161
// Step 5: Second user sends a query
167162
t.Log("\nStep 5: Second user sends a query")
168-
query5Result, err := client2.SendMCPRequest("tools/call", map[string]interface{}{
163+
query5Result, err := client2.SendMCPRequest("tools/call", map[string]any{
169164
"name": "query",
170-
"arguments": map[string]interface{}{
165+
"arguments": map[string]any{
171166
"sql": "SELECT 'user2-query2' as test_id, current_database() as db_name",
172167
},
173168
})
@@ -241,9 +236,9 @@ func TestSessionCleanupAfterTimeout(t *testing.T) {
241236
assert.Greater(t, len(containersAfterConnect), len(initialContainers), "No new container created for client")
242237

243238
// Send a query to ensure session is active
244-
_, err = client.SendMCPRequest("tools/call", map[string]interface{}{
239+
_, err = client.SendMCPRequest("tools/call", map[string]any{
245240
"name": "query",
246-
"arguments": map[string]interface{}{
241+
"arguments": map[string]any{
247242
"sql": "SELECT 'test' as test_id",
248243
},
249244
})
@@ -310,11 +305,11 @@ func TestSessionTimerReset(t *testing.T) {
310305

311306
// Keep session alive by sending queries every 5 seconds
312307
// With 8s timeout, this should keep it alive
313-
for i := 0; i < 3; i++ {
308+
for i := range 3 {
314309
t.Logf("Sending keepalive query %d/3...", i+1)
315-
_, err := client.SendMCPRequest("tools/call", map[string]interface{}{
310+
_, err := client.SendMCPRequest("tools/call", map[string]any{
316311
"name": "query",
317-
"arguments": map[string]interface{}{
312+
"arguments": map[string]any{
318313
"sql": "SELECT 'keepalive' as status, NOW() as timestamp",
319314
},
320315
})
@@ -413,11 +408,11 @@ func TestMultiUserTimerIndependence(t *testing.T) {
413408
go func() {
414409
defer close(done)
415410
// Run 4 queries - the last one AFTER client1 should be cleaned up
416-
for i := 0; i < 4; i++ {
411+
for i := range 4 {
417412
time.Sleep(4 * time.Second)
418-
_, err := client2.SendMCPRequest("tools/call", map[string]interface{}{
413+
_, err := client2.SendMCPRequest("tools/call", map[string]any{
419414
"name": "query",
420-
"arguments": map[string]interface{}{
415+
"arguments": map[string]any{
421416
"sql": "SELECT 'client2-keepalive' as status",
422417
},
423418
})

integration/main_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func TestMain(m *testing.M) {
6767

6868
// Wait for database to be ready
6969
fmt.Println("Waiting for database to be ready...")
70-
for i := 0; i < 30; i++ { // Wait up to 30 seconds
70+
for i := range 30 { // Wait up to 30 seconds
7171
checkCmd := exec.Command("docker", "compose", "exec", "-T", "test-postgres", "pg_isready", "-U", "testuser", "-d", "testdb")
7272
if err := checkCmd.Run(); err == nil {
7373
fmt.Println("Database is ready!")
@@ -83,7 +83,7 @@ func TestMain(m *testing.M) {
8383

8484
// Wait for SSE server to be ready
8585
fmt.Println("Waiting for SSE server to be ready...")
86-
for i := 0; i < 30; i++ { // Wait up to 30 seconds
86+
for i := range 30 { // Wait up to 30 seconds
8787
resp, err := http.Get("http://localhost:3001")
8888
if err == nil {
8989
resp.Body.Close()
@@ -102,7 +102,7 @@ func TestMain(m *testing.M) {
102102

103103
// Wait for Streamable server to be ready
104104
fmt.Println("Waiting for Streamable server to be ready...")
105-
for i := 0; i < 30; i++ { // Wait up to 30 seconds
105+
for i := range 30 { // Wait up to 30 seconds
106106
resp, err := http.Get("http://localhost:3002")
107107
if err == nil {
108108
resp.Body.Close()

0 commit comments

Comments
 (0)