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

Function TestMCPErrorHandling

examples/server/memory/kb_test.go:587–614  ·  view source on GitHub ↗

TestMCPErrorHandling tests error scenarios through MCP layer.

(t *testing.T)

Source from the content-addressed store, hash-verified

585
586// TestMCPErrorHandling tests error scenarios through MCP layer.
587func TestMCPErrorHandling(t *testing.T) {
588 for name, newStore := range stores() {
589 t.Run(name, func(t *testing.T) {
590 s := newStore(t)
591 kb := knowledgeBase{s: s}
592
593 ctx := context.Background()
594
595 _, _, err := kb.AddObservations(ctx, nil, AddObservationsArgs{
596 Observations: []Observation{
597 {
598 EntityName: "NonExistentEntity",
599 Contents: []string{"This should fail"},
600 },
601 },
602 })
603 if err == nil {
604 t.Errorf("expected MCP AddObservations to return error for non-existent entity")
605 } else {
606 // Verify the error message contains expected text
607 want := "entity with name NonExistentEntity not found"
608 if !strings.Contains(err.Error(), want) {
609 t.Errorf("expected error message to contain '%s', got: %v", want, err)
610 }
611 }
612 })
613 }
614}
615
616// TestMCPResponseFormat verifies MCP response format consistency.
617func TestMCPResponseFormat(t *testing.T) {

Callers

nothing calls this directly

Calls 4

AddObservationsMethod · 0.95
storesFunction · 0.85
RunMethod · 0.80
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…