1package proto
2
3import "fmt"
4
5// MCPState represents the current state of an MCP client.
6type MCPState int
7
8const (
9 MCPStateDisabled MCPState = iota
10 MCPStateStarting
11 MCPStateConnected
12 MCPStateError
13)
14
15// MarshalText implements the [encoding.TextMarshaler] interface.
16func (s MCPState) MarshalText() ([]byte, error) {
17 return []byte(s.String()), nil
18}
19
20// UnmarshalText implements the [encoding.TextUnmarshaler] interface.
21func (s *MCPState) UnmarshalText(data []byte) error {
22 switch string(data) {
23 case "disabled":
24 *s = MCPStateDisabled
25 case "starting":
26 *s = MCPStateStarting
27 case "connected":
28 *s = MCPStateConnected
29 case "error":
30 *s = MCPStateError
31 default:
32 return fmt.Errorf("unknown mcp state: %s", data)
33 }
34 return nil
35}
36
37// String returns the string representation of the MCPState.
38func (s MCPState) String() string {
39 switch s {
40 case MCPStateDisabled:
41 return "disabled"
42 case MCPStateStarting:
43 return "starting"
44 case MCPStateConnected:
45 return "connected"
46 case MCPStateError:
47 return "error"
48 default:
49 return "unknown"
50 }
51}
52
53// MCPEventType represents the type of MCP event.
54type MCPEventType string
55
56const (
57 MCPEventStateChanged MCPEventType = "state_changed"
58)
59
60// MarshalText implements the [encoding.TextMarshaler] interface.
61func (t MCPEventType) MarshalText() ([]byte, error) {
62 return []byte(t), nil
63}
64
65// UnmarshalText implements the [encoding.TextUnmarshaler] interface.
66func (t *MCPEventType) UnmarshalText(data []byte) error {
67 *t = MCPEventType(data)
68 return nil
69}
70
71// MCPEvent represents an event in the MCP system.
72type MCPEvent struct {
73 Type MCPEventType `json:"type"`
74 Name string `json:"name"`
75 State MCPState `json:"state"`
76 Error error `json:"error,omitempty"`
77 ToolCount int `json:"tool_count,omitempty"`
78}