-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathjsonrpc.go
More file actions
52 lines (44 loc) · 1.51 KB
/
Copy pathjsonrpc.go
File metadata and controls
52 lines (44 loc) · 1.51 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
package main
import "encoding/json"
// JSON-RPC message types for MCP protocol.
type jsonRPCMessage struct {
JSONRPC string `json:"jsonrpc"`
ID *json.RawMessage `json:"id,omitempty"`
Method string `json:"method,omitempty"`
Params json.RawMessage `json:"params,omitempty"`
Result json.RawMessage `json:"result,omitempty"`
Error json.RawMessage `json:"error,omitempty"`
}
type toolCallParams struct {
Name string `json:"name"`
Arguments json.RawMessage `json:"arguments,omitempty"`
ProgressToken json.RawMessage `json:"_meta,omitempty"`
}
type metaWithProgress struct {
ProgressToken json.RawMessage `json:"progressToken,omitempty"`
}
type progressNotification struct {
JSONRPC string `json:"jsonrpc"`
Method string `json:"method"`
Params progressParams `json:"params"`
}
type progressParams struct {
ProgressToken json.RawMessage `json:"progressToken"`
Progress int `json:"progress"`
Total int `json:"total,omitempty"`
Message string `json:"message,omitempty"`
}
// makeProgressNotification creates a JSON-RPC progress notification.
func makeProgressNotification(token json.RawMessage, progress, total int, message string) ([]byte, error) {
notif := progressNotification{
JSONRPC: "2.0",
Method: "notifications/progress",
Params: progressParams{
ProgressToken: token,
Progress: progress,
Total: total,
Message: message,
},
}
return json.Marshal(notif)
}