MCPcopy Create free account
hub / github.com/modelcontextprotocol/go-sdk / runServerTest

Function runServerTest

mcp/conformance_test.go:155–380  ·  view source on GitHub ↗

runServerTest runs the server conformance test. It must be executed in a synctest bubble.

(t *testing.T, test *conformanceTest)

Source from the content-addressed store, hash-verified

153// runServerTest runs the server conformance test.
154// It must be executed in a synctest bubble.
155func 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)

Callers 1

TestServerConformanceFunction · 0.85

Calls 15

AddPromptMethod · 0.95
AddResourceMethod · 0.95
ConnectMethod · 0.95
EncodeIndentFunction · 0.92
NewServerFunction · 0.85
AddToolFunction · 0.85
NewInMemoryTransportsFunction · 0.85
IsMethod · 0.80
IsCallMethod · 0.80
BytesMethod · 0.80
ConnectMethod · 0.65
WriteMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…