add_entity_observation
Enhance entity records by appending observations in SourceSage MCP server. Input entity name and observation to dynamically update and store contextual data for efficient retrieval and analysis.
Instructions
Add an observation to an entity.
Args: entity_name: Name of the entity observation: Observation to add
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| entity_name | Yes | ||
| observation | Yes |
Implementation Reference
- sourcesage/mcp_server.py:186-211 (handler)The handler function decorated with @self.mcp.tool(), which registers and implements the add_entity_observation tool. It locates the entity by name and delegates to KnowledgeGraph.add_observation.def add_entity_observation(entity_name: str, observation: str) -> str: """Add an observation to an entity. Args: entity_name: Name of the entity observation: Observation to add """ # Find entity by name entities = self.knowledge.find_entity(entity_name) if not entities: return f"Error: Entity '{entity_name}' not found" # If multiple entities with the same name, use the first one entity_id = entities[0].entity_id success = self.knowledge.add_observation(entity_id, observation) if not success: return f"Error: Failed to add observation to entity '{entity_name}'" # Save knowledge if storage path is set if self.storage_path: self.knowledge.save_to_file(self.storage_path) return f"Observation added to entity '{entity_name}'"
- sourcesage/knowledge.py:201-221 (helper)Supporting method in KnowledgeGraph class that adds a unique observation to an entity's observations list and updates the timestamp.def add_observation(self, entity_id: str, observation: str) -> bool: """Add an observation to an entity. Args: entity_id: The ID of the entity observation: The observation to add Returns: True if successful, False otherwise """ if entity_id not in self.entities: return False entity = self.entities[entity_id] if observation not in entity.observations: entity.observations.append(observation) entity.updated_at = time.time() return True
- sourcesage/mcp_server.py:187-187 (schema)The function signature defines the input schema (entity_name: str, observation: str) and output (str) for the tool, used by MCP for validation."""Add an observation to an entity.
- sourcesage/mcp_server.py:186-186 (registration)The @self.mcp.tool() decorator registers the add_entity_observation function as an MCP tool.def add_entity_observation(entity_name: str, observation: str) -> str: