MCPcopy Index your code
hub / github.com/github/github-mcp-server / TestBuildInitializeRequest

Function TestBuildInitializeRequest

cmd/mcpcurl/main_test.go:108–154  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

106}
107
108func TestBuildInitializeRequest(t *testing.T) {
109 t.Parallel()
110 got, err := buildInitializeRequest()
111 if err != nil {
112 t.Fatalf("unexpected error: %v", err)
113 }
114
115 var msg map[string]json.RawMessage
116 if err := json.Unmarshal([]byte(got), &msg); err != nil {
117 t.Fatalf("result is not valid JSON: %v", err)
118 }
119
120 // Verify required fields
121 for _, field := range []string{"jsonrpc", "id", "method", "params"} {
122 if _, ok := msg[field]; !ok {
123 t.Errorf("missing required field %q", field)
124 }
125 }
126
127 // Verify method
128 var method string
129 if err := json.Unmarshal(msg["method"], &method); err != nil {
130 t.Fatalf("failed to parse method: %v", err)
131 }
132 if method != "initialize" {
133 t.Errorf("expected method 'initialize', got %q", method)
134 }
135
136 // Verify params contain protocolVersion and clientInfo
137 var params map[string]json.RawMessage
138 if err := json.Unmarshal(msg["params"], &params); err != nil {
139 t.Fatalf("failed to parse params: %v", err)
140 }
141 for _, field := range []string{"protocolVersion", "capabilities", "clientInfo"} {
142 if _, ok := params[field]; !ok {
143 t.Errorf("missing params field %q", field)
144 }
145 }
146
147 var version string
148 if err := json.Unmarshal(params["protocolVersion"], &version); err != nil {
149 t.Fatalf("failed to parse protocolVersion: %v", err)
150 }
151 if version != "2024-11-05" {
152 t.Errorf("expected protocolVersion '2024-11-05', got %q", version)
153 }
154}
155
156func TestBuildInitializedNotification(t *testing.T) {
157 t.Parallel()

Callers

nothing calls this directly

Calls 1

buildInitializeRequestFunction · 0.85

Tested by

no test coverage detected