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

Method createEntities

examples/server/memory/kb.go:186–205  ·  view source on GitHub ↗

createEntities adds new entities to the graph, skipping duplicates by name. It returns the new entities that were actually added.

(entities []Entity)

Source from the content-addressed store, hash-verified

184// createEntities adds new entities to the graph, skipping duplicates by name.
185// It returns the new entities that were actually added.
186func (k knowledgeBase) createEntities(entities []Entity) ([]Entity, error) {
187 graph, err := k.loadGraph()
188 if err != nil {
189 return nil, err
190 }
191
192 var newEntities []Entity
193 for _, entity := range entities {
194 if !slices.ContainsFunc(graph.Entities, func(e Entity) bool { return e.Name == entity.Name }) {
195 newEntities = append(newEntities, entity)
196 graph.Entities = append(graph.Entities, entity)
197 }
198 }
199
200 if err := k.saveGraph(graph); err != nil {
201 return nil, err
202 }
203
204 return newEntities, nil
205}
206
207// createRelations adds new relations to the graph, skipping exact duplicates.
208// It returns the new relations that were actually added.

Callers 5

TestErrorHandlingFunction · 0.95
TestFileFormattingFunction · 0.95
CreateEntitiesMethod · 0.95

Calls 2

loadGraphMethod · 0.95
saveGraphMethod · 0.95

Tested by 4

TestErrorHandlingFunction · 0.76
TestFileFormattingFunction · 0.76