Skip to main content

memory_mcp_rs/
graph.rs

1use schemars::JsonSchema;
2use serde::{Deserialize, Serialize};
3
4/// Entity in the knowledge graph
5#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema, PartialEq)]
6pub struct Entity {
7    /// Unique name of the entity (serves as ID)
8    pub name: String,
9
10    /// Type of entity (person, organization, concept, etc.)
11    #[serde(rename = "entityType")]
12    pub entity_type: String,
13
14    /// Array of observations (facts) about the entity
15    pub observations: Vec<String>,
16}
17
18/// Relation between two entities
19#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema, PartialEq)]
20pub struct Relation {
21    /// Source entity name
22    pub from: String,
23
24    /// Target entity name
25    pub to: String,
26
27    /// Type of relation (works_at, knows, related_to, etc.)
28    #[serde(rename = "relationType")]
29    pub relation_type: String,
30}
31
32/// Complete knowledge graph
33#[derive(Debug, Clone, Serialize, Deserialize, Default)]
34pub struct KnowledgeGraph {
35    pub entities: Vec<Entity>,
36    pub relations: Vec<Relation>,
37}
38
39/// Input for adding observations to an entity
40#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
41pub struct ObservationInput {
42    #[serde(rename = "entityName")]
43    pub entity_name: String,
44    pub contents: Vec<String>,
45}
46
47/// Result of adding observations
48#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
49pub struct ObservationResult {
50    #[serde(rename = "entityName")]
51    pub entity_name: String,
52    #[serde(rename = "addedObservations")]
53    pub added_observations: Vec<String>,
54}
55
56/// Input for deleting observations from an entity
57#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
58pub struct ObservationDeletion {
59    #[serde(rename = "entityName")]
60    pub entity_name: String,
61    pub observations: Vec<String>,
62}