-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmcp_client.go
More file actions
60 lines (53 loc) · 1.58 KB
/
Copy pathmcp_client.go
File metadata and controls
60 lines (53 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package reference
import (
"encoding/json"
"fmt"
)
// MCPRequest represents a JSON-RPC 2.0 request payload to an MCP server.
type MCPRequest struct {
JSONRPC string `json:"jsonrpc"`
ID int64 `json:"id"`
Method string `json:"method"`
Params interface{} `json:"params,omitempty"`
}
// MCPResponse represents a JSON-RPC 2.0 response payload from an MCP server.
type MCPResponse struct {
JSONRPC string `json:"jsonrpc"`
ID int64 `json:"id"`
Result json.RawMessage `json:"result,omitempty"`
Error *MCPError `json:"error,omitempty"`
}
// MCPError represents a JSON-RPC error payload.
type MCPError struct {
Code int `json:"code"`
Message string `json:"message"`
}
// ToolDescription represents a discovered MCP tool.
type ToolDescription struct {
Name string `json:"name"`
Description string `json:"description"`
InputSchema map[string]interface{} `json:"inputSchema"`
}
// FormatMCPToolListRequest creates a JSON-RPC request for listing MCP tools.
func FormatMCPToolListRequest(id int64) ([]byte, error) {
req := MCPRequest{
JSONRPC: "2.0",
ID: id,
Method: "tools/list",
}
return json.Marshal(req)
}
// FormatMCPToolCallRequest creates a JSON-RPC request for executing an MCP tool.
func FormatMCPToolCallRequest(id int64, name string, args map[string]interface{}) ([]byte, error) {
params := map[string]interface{}{
"name": name,
"arguments": args,
}
req := MCPRequest{
JSONRPC: "2.0",
ID: id,
Method: "tools/call",
Params: params,
}
return json.Marshal(req)
}