Content-Length: 1053076 | pFad | https://github.com/mark3labs/mcp-go/commit/f8badd69d08f609cbbd7a218c3b2b8de05987277

92 chore: replace `interface{}` with `any` (#261) · mark3labs/mcp-go@f8badd6 · GitHub
Skip to content

Commit f8badd6

Browse files
authored
chore: replace interface{} with any (#261)
1 parent 3442d32 commit f8badd6

File tree

23 files changed

+280
-280
lines changed

23 files changed

+280
-280
lines changed

client/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ func (c *Client) OnNotification(
9494
func (c *Client) sendRequest(
9595
ctx context.Context,
9696
method string,
97-
params interface{},
97+
params any,
9898
) (*json.RawMessage, error) {
9999
if !c.initialized && method != "initialize" {
100100
return nil, fmt.Errorf("client not initialized")

client/inprocess_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ func TestInProcessMCPClient(t *testing.T) {
196196

197197
request := mcp.CallToolRequest{}
198198
request.Params.Name = "test-tool"
199-
request.Params.Arguments = map[string]interface{}{
199+
request.Params.Arguments = map[string]any{
200200
"parameter-1": "value1",
201201
}
202202

client/sse_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ func TestSSEMCPClient(t *testing.T) {
238238

239239
request := mcp.CallToolRequest{}
240240
request.Params.Name = "test-tool"
241-
request.Params.Arguments = map[string]interface{}{
241+
request.Params.Arguments = map[string]any{
242242
"parameter-1": "value1",
243243
}
244244

client/stdio_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ func TestStdioMCPClient(t *testing.T) {
232232

233233
request := mcp.CallToolRequest{}
234234
request.Params.Name = "test-tool"
235-
request.Params.Arguments = map[string]interface{}{
235+
request.Params.Arguments = map[string]any{
236236
"param1": "value1",
237237
}
238238

client/transport/sse_test.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,15 @@ func startMockSSEEchoServer() (string, func()) {
6464
}
6565

6666
// Parse incoming JSON-RPC request
67-
var request map[string]interface{}
67+
var request map[string]any
6868
decoder := json.NewDecoder(r.Body)
6969
if err := decoder.Decode(&request); err != nil {
7070
http.Error(w, fmt.Sprintf("Invalid JSON: %v", err), http.StatusBadRequest)
7171
return
7272
}
7373

7474
// Echo back the request as the response result
75-
response := map[string]interface{}{
75+
response := map[string]any{
7676
"jsonrpc": "2.0",
7777
"id": request["id"],
7878
"result": request,
@@ -96,7 +96,7 @@ func startMockSSEEchoServer() (string, func()) {
9696
mu.Unlock()
9797
case "debug/echo_error_string":
9898
data, _ := json.Marshal(request)
99-
response["error"] = map[string]interface{}{
99+
response["error"] = map[string]any{
100100
"code": -1,
101101
"message": string(data),
102102
}
@@ -153,9 +153,9 @@ func TestSSE(t *testing.T) {
153153
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
154154
defer cancel()
155155

156-
params := map[string]interface{}{
156+
params := map[string]any{
157157
"string": "hello world",
158-
"array": []interface{}{1, 2, 3},
158+
"array": []any{1, 2, 3},
159159
}
160160

161161
request := JSONRPCRequest{
@@ -173,10 +173,10 @@ func TestSSE(t *testing.T) {
173173

174174
// Parse the result to verify echo
175175
var result struct {
176-
JSONRPC string `json:"jsonrpc"`
177-
ID int64 `json:"id"`
178-
Method string `json:"method"`
179-
Params map[string]interface{} `json:"params"`
176+
JSONRPC string `json:"jsonrpc"`
177+
ID int64 `json:"id"`
178+
Method string `json:"method"`
179+
Params map[string]any `json:"params"`
180180
}
181181

182182
if err := json.Unmarshal(response.Result, &result); err != nil {
@@ -198,7 +198,7 @@ func TestSSE(t *testing.T) {
198198
t.Errorf("Expected string 'hello world', got %v", result.Params["string"])
199199
}
200200

201-
if arr, ok := result.Params["array"].([]interface{}); !ok || len(arr) != 3 {
201+
if arr, ok := result.Params["array"].([]any); !ok || len(arr) != 3 {
202202
t.Errorf("Expected array with 3 items, got %v", result.Params["array"])
203203
}
204204
})
@@ -244,7 +244,7 @@ func TestSSE(t *testing.T) {
244244
Notification: mcp.Notification{
245245
Method: "debug/echo_notification",
246246
Params: mcp.NotificationParams{
247-
AdditionalFields: map[string]interface{}{"test": "value"},
247+
AdditionalFields: map[string]any{"test": "value"},
248248
},
249249
},
250250
}
@@ -294,7 +294,7 @@ func TestSSE(t *testing.T) {
294294
JSONRPC: "2.0",
295295
ID: int64(100 + idx),
296296
Method: "debug/echo",
297-
Params: map[string]interface{}{
297+
Params: map[string]any{
298298
"requestIndex": idx,
299299
"timestamp": time.Now().UnixNano(),
300300
},
@@ -324,10 +324,10 @@ func TestSSE(t *testing.T) {
324324

325325
// Parse the result to verify echo
326326
var result struct {
327-
JSONRPC string `json:"jsonrpc"`
328-
ID int64 `json:"id"`
329-
Method string `json:"method"`
330-
Params map[string]interface{} `json:"params"`
327+
JSONRPC string `json:"jsonrpc"`
328+
ID int64 `json:"id"`
329+
Method string `json:"method"`
330+
Params map[string]any `json:"params"`
331331
}
332332

333333
if err := json.Unmarshal(responses[i].Result, &result); err != nil {

client/transport/stdio_test.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ func TestStdio(t *testing.T) {
7373
ctx, cancel := context.WithTimeout(context.Background(), 5000000000*time.Second)
7474
defer cancel()
7575

76-
params := map[string]interface{}{
76+
params := map[string]any{
7777
"string": "hello world",
78-
"array": []interface{}{1, 2, 3},
78+
"array": []any{1, 2, 3},
7979
}
8080

8181
request := JSONRPCRequest{
@@ -93,10 +93,10 @@ func TestStdio(t *testing.T) {
9393

9494
// Parse the result to verify echo
9595
var result struct {
96-
JSONRPC string `json:"jsonrpc"`
97-
ID int64 `json:"id"`
98-
Method string `json:"method"`
99-
Params map[string]interface{} `json:"params"`
96+
JSONRPC string `json:"jsonrpc"`
97+
ID int64 `json:"id"`
98+
Method string `json:"method"`
99+
Params map[string]any `json:"params"`
100100
}
101101

102102
if err := json.Unmarshal(response.Result, &result); err != nil {
@@ -118,7 +118,7 @@ func TestStdio(t *testing.T) {
118118
t.Errorf("Expected string 'hello world', got %v", result.Params["string"])
119119
}
120120

121-
if arr, ok := result.Params["array"].([]interface{}); !ok || len(arr) != 3 {
121+
if arr, ok := result.Params["array"].([]any); !ok || len(arr) != 3 {
122122
t.Errorf("Expected array with 3 items, got %v", result.Params["array"])
123123
}
124124
})
@@ -164,7 +164,7 @@ func TestStdio(t *testing.T) {
164164
Notification: mcp.Notification{
165165
Method: "debug/echo_notification",
166166
Params: mcp.NotificationParams{
167-
AdditionalFields: map[string]interface{}{"test": "value"},
167+
AdditionalFields: map[string]any{"test": "value"},
168168
},
169169
},
170170
}
@@ -213,7 +213,7 @@ func TestStdio(t *testing.T) {
213213
JSONRPC: "2.0",
214214
ID: int64(100 + idx),
215215
Method: "debug/echo",
216-
Params: map[string]interface{}{
216+
Params: map[string]any{
217217
"requestIndex": idx,
218218
"timestamp": time.Now().UnixNano(),
219219
},
@@ -243,10 +243,10 @@ func TestStdio(t *testing.T) {
243243

244244
// Parse the result to verify echo
245245
var result struct {
246-
JSONRPC string `json:"jsonrpc"`
247-
ID int64 `json:"id"`
248-
Method string `json:"method"`
249-
Params map[string]interface{} `json:"params"`
246+
JSONRPC string `json:"jsonrpc"`
247+
ID int64 `json:"id"`
248+
Method string `json:"method"`
249+
Params map[string]any `json:"params"`
250250
}
251251

252252
if err := json.Unmarshal(responses[i].Result, &result); err != nil {

client/transport/streamable_http_test.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func startMockStreamableHTTPServer() (string, func()) {
4646
w.Header().Set("Mcp-Session-Id", sessionID)
4747
w.Header().Set("Content-Type", "application/json")
4848
w.WriteHeader(http.StatusAccepted)
49-
json.NewEncoder(w).Encode(map[string]interface{}{
49+
json.NewEncoder(w).Encode(map[string]any{
5050
"jsonrpc": "2.0",
5151
"id": request["id"],
5252
"result": "initialized",
@@ -62,7 +62,7 @@ func startMockStreamableHTTPServer() (string, func()) {
6262
// Echo back the request as the response result
6363
w.Header().Set("Content-Type", "application/json")
6464
w.WriteHeader(http.StatusOK)
65-
json.NewEncoder(w).Encode(map[string]interface{}{
65+
json.NewEncoder(w).Encode(map[string]any{
6666
"jsonrpc": "2.0",
6767
"id": request["id"],
6868
"result": request,
@@ -104,10 +104,10 @@ func startMockStreamableHTTPServer() (string, func()) {
104104
w.Header().Set("Content-Type", "application/json")
105105
w.WriteHeader(http.StatusOK)
106106
data, _ := json.Marshal(request)
107-
json.NewEncoder(w).Encode(map[string]interface{}{
107+
json.NewEncoder(w).Encode(map[string]any{
108108
"jsonrpc": "2.0",
109109
"id": request["id"],
110-
"error": map[string]interface{}{
110+
"error": map[string]any{
111111
"code": -1,
112112
"message": string(data),
113113
},
@@ -152,9 +152,9 @@ func TestStreamableHTTP(t *testing.T) {
152152
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
153153
defer cancel()
154154

155-
params := map[string]interface{}{
155+
params := map[string]any{
156156
"string": "hello world",
157-
"array": []interface{}{1, 2, 3},
157+
"array": []any{1, 2, 3},
158158
}
159159

160160
request := JSONRPCRequest{
@@ -172,10 +172,10 @@ func TestStreamableHTTP(t *testing.T) {
172172

173173
// Parse the result to verify echo
174174
var result struct {
175-
JSONRPC string `json:"jsonrpc"`
176-
ID int64 `json:"id"`
177-
Method string `json:"method"`
178-
Params map[string]interface{} `json:"params"`
175+
JSONRPC string `json:"jsonrpc"`
176+
ID int64 `json:"id"`
177+
Method string `json:"method"`
178+
Params map[string]any `json:"params"`
179179
}
180180

181181
if err := json.Unmarshal(response.Result, &result); err != nil {
@@ -197,7 +197,7 @@ func TestStreamableHTTP(t *testing.T) {
197197
t.Errorf("Expected string 'hello world', got %v", result.Params["string"])
198198
}
199199

200-
if arr, ok := result.Params["array"].([]interface{}); !ok || len(arr) != 3 {
200+
if arr, ok := result.Params["array"].([]any); !ok || len(arr) != 3 {
201201
t.Errorf("Expected array with 3 items, got %v", result.Params["array"])
202202
}
203203
})
@@ -295,7 +295,7 @@ func TestStreamableHTTP(t *testing.T) {
295295
JSONRPC: "2.0",
296296
ID: int64(100 + idx),
297297
Method: "debug/echo",
298-
Params: map[string]interface{}{
298+
Params: map[string]any{
299299
"requestIndex": idx,
300300
"timestamp": time.Now().UnixNano(),
301301
},
@@ -325,10 +325,10 @@ func TestStreamableHTTP(t *testing.T) {
325325

326326
// Parse the result to verify echo
327327
var result struct {
328-
JSONRPC string `json:"jsonrpc"`
329-
ID int64 `json:"id"`
330-
Method string `json:"method"`
331-
Params map[string]interface{} `json:"params"`
328+
JSONRPC string `json:"jsonrpc"`
329+
ID int64 `json:"id"`
330+
Method string `json:"method"`
331+
Params map[string]any `json:"params"`
332332
}
333333

334334
if err := json.Unmarshal(responses[i].Result, &result); err != nil {

examples/custom_context/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ func tokenFromContext(ctx context.Context) (string, error) {
4444
}
4545

4646
type response struct {
47-
Args map[string]interface{} `json:"args"`
48-
Headers map[string]string `json:"headers"`
47+
Args map[string]any `json:"args"`
48+
Headers map[string]string `json:"headers"`
4949
}
5050

5151
// makeRequest makes a request to httpbin.org including the auth token in the request

examples/everything/main.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -137,12 +137,12 @@ func NewMCPServer() *server.MCPServer {
137137
// Description: "Samples from an LLM using MCP's sampling feature",
138138
// InputSchema: mcp.ToolInputSchema{
139139
// Type: "object",
140-
// Properties: map[string]interface{}{
141-
// "prompt": map[string]interface{}{
140+
// Properties: map[string]any{
141+
// "prompt": map[string]any{
142142
// "type": "string",
143143
// "description": "The prompt to send to the LLM",
144144
// },
145-
// "maxTokens": map[string]interface{}{
145+
// "maxTokens": map[string]any{
146146
// "type": "number",
147147
// "description": "Maximum number of tokens to generate",
148148
// "default": 100,
@@ -190,9 +190,9 @@ func runUpdateInterval() {
190190
// Notification: mcp.Notification{
191191
// Method: "resources/updated",
192192
// Params: struct {
193-
// Meta map[string]interface{} `json:"_meta,omitempty"`
193+
// Meta map[string]any `json:"_meta,omitempty"`
194194
// }{
195-
// Meta: map[string]interface{}{"uri": uri},
195+
// Meta: map[string]any{"uri": uri},
196196
// },
197197
// },
198198
// },
@@ -333,7 +333,7 @@ func handleSendNotification(
333333
err := server.SendNotificationToClient(
334334
ctx,
335335
"notifications/progress",
336-
map[string]interface{}{
336+
map[string]any{
337337
"progress": 10,
338338
"total": 10,
339339
"progressToken": 0,
@@ -370,7 +370,7 @@ func handleLongRunningOperationTool(
370370
server.SendNotificationToClient(
371371
ctx,
372372
"notifications/progress",
373-
map[string]interface{}{
373+
map[string]any{
374374
"progress": i,
375375
"total": int(steps),
376376
"progressToken": progressToken,
@@ -394,7 +394,7 @@ func handleLongRunningOperationTool(
394394
}, nil
395395
}
396396

397-
// func (s *MCPServer) handleSampleLLMTool(arguments map[string]interface{}) (*mcp.CallToolResult, error) {
397+
// func (s *MCPServer) handleSampleLLMTool(arguments map[string]any) (*mcp.CallToolResult, error) {
398398
// prompt, _ := arguments["prompt"].(string)
399399
// maxTokens, _ := arguments["maxTokens"].(float64)
400400

@@ -406,7 +406,7 @@ func handleLongRunningOperationTool(
406406
// )
407407

408408
// return &mcp.CallToolResult{
409-
// Content: []interface{}{
409+
// Content: []any{
410410
// mcp.TextContent{
411411
// Type: "text",
412412
// Text: fmt.Sprintf("LLM sampling result: %s", result),

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://github.com/mark3labs/mcp-go/commit/f8badd69d08f609cbbd7a218c3b2b8de05987277

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy