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
61
62
63
64
65
66
67
68
69
70
71
72
|
package main
import "encoding/json"
// JSON-RPC 2.0 request
type JSONRPCRequest struct {
JSONRPC string `json:"jsonrpc"` // must be "2.0"
ID *int64 `json:"id,omitempty"` // nil for notifications, non-nil for requests
Method string `json:"method"`
Params json.RawMessage `json:"params,omitempty"`
}
// JSON-RPC 2.0 response
type JSONRPCResponse struct {
JSONRPC string `json:"jsonrpc"` // always "2.0"
ID int64 `json:"id"` // echo request ID
Result any `json:"result,omitempty"`
Error *RPCError `json:"error,omitempty"`
}
// JSON-RPC error object
type RPCError struct {
Code int `json:"code"`
Message string `json:"message"`
Data any `json:"data,omitempty"`
}
// Standard JSON-RPC error codes
const (
ErrCodeParseError = -32700
ErrCodeInvalidRequest = -32600
ErrCodeMethodNotFound = -32601
ErrCodeInvalidParams = -32602
ErrCodeInternal = -32603
)
// MCP tool definition
type Tool struct {
Name string `json:"name"`
Description string `json:"description,omitempty"`
InputSchema json.RawMessage `json:"inputSchema"`
VarlinkMethod string `json:"-"` // Original Varlink method name (not serialized to JSON)
}
// MCP initialize result
type InitializeResult struct {
ProtocolVersion string `json:"protocolVersion"`
Capabilities map[string]any `json:"capabilities"`
ServerInfo map[string]any `json:"serverInfo,omitempty"`
}
// MCP tools/list result
type ToolsListResult struct {
Tools []Tool `json:"tools"`
}
// MCP tools/call params
type ToolsCallParams struct {
Name string `json:"name"`
Arguments map[string]any `json:"arguments,omitempty"`
}
// MCP tools/call result
type ToolsCallResult struct {
Content []ContentItem `json:"content"`
}
// MCP content item
type ContentItem struct {
Type string `json:"type"` // "text"
Text string `json:"text"` // Content text
}
|