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

Function TestFileFormatting

examples/server/memory/kb_test.go:379–427  ·  view source on GitHub ↗

TestFileFormatting verifies the JSON storage format structure.

(t *testing.T)

Source from the content-addressed store, hash-verified

377
378// TestFileFormatting verifies the JSON storage format structure.
379func TestFileFormatting(t *testing.T) {
380 for name, newStore := range stores() {
381 t.Run(name, func(t *testing.T) {
382 s := newStore(t)
383 kb := knowledgeBase{s: s}
384
385 // Setup test entity
386 testEntities := []Entity{
387 {
388 Name: "FileTest",
389 EntityType: "TestEntity",
390 Observations: []string{"Test observation"},
391 },
392 }
393
394 _, err := kb.createEntities(testEntities)
395 if err != nil {
396 t.Fatalf("failed to create test entity: %v", err)
397 }
398
399 // Extract raw storage data
400 data, err := s.Read()
401 if err != nil {
402 t.Fatalf("failed to read from store: %v", err)
403 }
404
405 // Validate JSON format
406 var items []kbItem
407 err = json.Unmarshal(data, &items)
408 if err != nil {
409 t.Fatalf("failed to parse store data JSON: %v", err)
410 }
411
412 // Check data structure
413 if len(items) != 1 {
414 t.Fatalf("expected 1 item in memory file, got %d", len(items))
415 }
416
417 item := items[0]
418 if item.Type != "entity" ||
419 item.Name != "FileTest" ||
420 item.EntityType != "TestEntity" ||
421 len(item.Observations) != 1 ||
422 item.Observations[0] != "Test observation" {
423 t.Errorf("store item format incorrect: %+v", item)
424 }
425 })
426 }
427}
428
429// TestMCPServerIntegration tests the knowledge base through MCP server layer.
430func TestMCPServerIntegration(t *testing.T) {

Callers

nothing calls this directly

Calls 4

createEntitiesMethod · 0.95
storesFunction · 0.85
RunMethod · 0.80
ReadMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…