Skip to main content
Glama
AgentWong

IAC Memory MCP Server

by AgentWong

view_relationships

Retrieve all relationships and observations for a specific entity in Infrastructure-as-Code data to understand dependencies and configurations.

Instructions

Retrieve all relationships and observations for a specific entity

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
entity_idYesEntity ID

Implementation Reference

  • MCP handler function for the view_relationships tool. Logs the operation, calls the core execute_view_relationships function, and handles any errors by raising McpError.
    async def handle_view_relationships(
        db: Any, arguments: Dict[str, Any], operation_id: str
    ) -> list[types.TextContent | types.ImageContent | types.EmbeddedResource]:
        """Handle view_relationships tool."""
        try:
            logger.info(
                "Viewing entity relationships",
                extra={
                    "entity_id": arguments.get("entity_id"),
                    "operation_id": operation_id,
                },
            )
    
            # Execute relationship view
            return execute_view_relationships(db, arguments)
    
        except Exception as e:
            error_msg = f"Failed to view relationships: {str(e)}"
            logger.error(error_msg, extra={"operation_id": operation_id})
            raise McpError(
                types.ErrorData(
                    code=types.INTERNAL_ERROR,
                    message=error_msg,
                    data={
                        "tool": "view_relationships",
                        "operation_id": operation_id,
                    },
                )
            )
  • Core database query function that retrieves entity details, observations, and relationships, then formats them into a TextContent response.
    def execute_view_relationships(
        db: DatabaseManager, arguments: Dict[str, Any]
    ) -> List[TextContent]:
        """Execute view relationships operation."""
        logger.info("Viewing relationships", extra={"relationship_args": arguments})
    
        entity_id = arguments["entity_id"]
        with db.get_connection() as conn:
            cursor = conn.execute(
                """SELECT
                    e.id, e.name, e.type, e.created_at, e.updated_at,
                    o.content as observation,
                    r.relationship_type,
                    e2.id as related_id,
                    e2.name as related_name,
                    e2.type as related_type,
                    e2.created_at as related_created_at,
                    e2.updated_at as related_updated_at
                FROM entities e
                LEFT JOIN observations o ON e.id = o.entity_id
                LEFT JOIN entity_relationships r ON e.id = r.source_id
                LEFT JOIN entities e2 ON r.target_id = e2.id
                WHERE e.id = ?""",
                (entity_id,),
            )
            entity = cursor.fetchone()
            if not entity:
                raise DatabaseError(f"Entity not found: {entity_id}")
    
            result = [
                f"Entity {entity_id}:",
                f"Name: {entity['name']}",
                f"Type: {entity['type']}",
                f"Created: {entity['created_at']}",
                f"Updated: {entity['updated_at']}",
            ]
    
            if entity["observation"]:
                result.extend(
                    [
                        "",  # Empty line for readability
                        f"Observation: {entity['observation']}",
                    ]
                )
    
            if entity["related_name"]:
                result.extend(
                    [
                        "",  # Empty line for readability
                        "Related Entity:",
                        f"  ID: {entity['related_id']}",
                        f"  Name: {entity['related_name']}",
                        f"  Type: {entity['related_type']}",
                        f"  Created: {entity['related_created_at']}",
                        f"  Updated: {entity['related_updated_at']}",
                        f"  Relationship Type: {entity['relationship_type']}",
                    ]
                )
    
            return [TextContent(type="text", text="\n".join(result))]
  • JSON schema defining the input parameters for the view_relationships tool, requiring 'entity_id'.
    "view_relationships": {
        "type": "object",
        "description": "Retrieve all relationships and observations for a specific entity",
        "required": ["entity_id"],
        "properties": {"entity_id": {"type": "string", "description": "Entity ID"}},
    },
  • Dictionary mapping the tool name 'view_relationships' to its handler function, used for registering the tool with the MCP server.
    entity_tool_handlers = {
        "create_entity": handle_create_entity,
        "update_entity": handle_update_entity,
        "delete_entity": handle_delete_entity,
        "view_relationships": handle_view_relationships,
    }

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observed

TDQS

C2.9/5.0
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden. It states 'Retrieve', implying a read-only operation, but does not disclose behavioral traits like permissions needed, rate limits, pagination, or what 'observations' entail. This is inadequate for a tool with no annotation coverage.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, clear sentence that directly states the tool's function without unnecessary words. It is front-loaded and efficient, earning its place by conveying the core purpose concisely.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given no annotations, no output schema, and a single parameter with full schema coverage, the description is incomplete. It lacks details on return values, error handling, or behavioral context, making it insufficient for an agent to fully understand the tool's operation and outcomes.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The schema description coverage is 100%, with the parameter 'entity_id' documented as 'Entity ID'. The description adds no additional meaning beyond this, such as format examples or constraints. With high schema coverage, the baseline is 3, as the schema handles the parameter documentation.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Retrieve') and the target ('all relationships and observations for a specific entity'), making the purpose understandable. However, it does not differentiate this tool from potential siblings like 'get_entity' or 'list_relationships', which might offer similar functionality, preventing a score of 5.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It does not mention prerequisites, exclusions, or compare it to sibling tools such as 'get_entity' or 'list_relationships', leaving the agent without context for selection.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.