runServerTest runs the server conformance test. It must be executed in a synctest bubble.
(t *testing.T, test *conformanceTest)
| 153 | // runServerTest runs the server conformance test. |
| 154 | // It must be executed in a synctest bubble. |
| 155 | func runServerTest(t *testing.T, test *conformanceTest) { |
| 156 | ctx := t.Context() |
| 157 | // Construct the server based on features listed in the test. |
| 158 | impl := &Implementation{Name: "testServer", Version: "v1.0.0"} |
| 159 | |
| 160 | if test.name == "spec-sep-973-additional-metadata.txtar" { |
| 161 | impl.Icons = []Icon{iconObj} |
| 162 | impl.WebsiteURL = "https://github.com/modelcontextprotocol/go-sdk" |
| 163 | } |
| 164 | |
| 165 | s := NewServer(impl, nil) |
| 166 | for _, tn := range test.tools { |
| 167 | switch tn { |
| 168 | case "greet": |
| 169 | AddTool(s, &Tool{ |
| 170 | Name: "greet", |
| 171 | Description: "say hi", |
| 172 | }, sayHi) |
| 173 | case "greetWithIcon": |
| 174 | AddTool(s, &Tool{ |
| 175 | Name: "greetWithIcon", |
| 176 | Description: "say hi", |
| 177 | Icons: []Icon{iconObj}, |
| 178 | }, sayHi) |
| 179 | case "structured": |
| 180 | AddTool(s, &Tool{Name: "structured"}, structuredTool) |
| 181 | case "tomorrow": |
| 182 | AddTool(s, &Tool{Name: "tomorrow"}, tomorrowTool) |
| 183 | case "inc": |
| 184 | inSchema, err := jsonschema.For[incInput](nil) |
| 185 | if err != nil { |
| 186 | t.Fatal(err) |
| 187 | } |
| 188 | inSchema.Properties["x"].Default = json.RawMessage(`6`) |
| 189 | AddTool(s, &Tool{Name: "inc", InputSchema: inSchema}, incTool) |
| 190 | case "contentTool": |
| 191 | AddTool(s, &Tool{ |
| 192 | Name: "contentTool", |
| 193 | Title: "contentTool", |
| 194 | Description: "return resourceLink content with Icon", |
| 195 | }, contentTool) |
| 196 | default: |
| 197 | t.Fatalf("unknown tool %q", tn) |
| 198 | } |
| 199 | } |
| 200 | for _, pn := range test.prompts { |
| 201 | switch pn { |
| 202 | case "code_review": |
| 203 | s.AddPrompt(codeReviewPrompt, codReviewPromptHandler) |
| 204 | case "code_reviewWithIcon": |
| 205 | s.AddPrompt(&Prompt{ |
| 206 | Name: "code_review", |
| 207 | Description: "do a code review", |
| 208 | Arguments: []*PromptArgument{{Name: "Code", Required: true}}, |
| 209 | Icons: []Icon{iconObj}, |
| 210 | }, codReviewPromptHandler) |
| 211 | default: |
| 212 | t.Fatalf("unknown prompt %q", pn) |
no test coverage detected
searching dependent graphs…