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,
    }
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 doesn't disclose behavioral traits like whether it requires authentication, has rate limits, returns paginated results, or what format the output is in. This is a significant gap 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, efficient sentence that directly states the tool's purpose without unnecessary words. It is appropriately sized and front-loaded, making it easy to parse quickly.

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 the complexity of retrieving 'all relationships and observations', no annotations, and no output schema, the description is incomplete. It doesn't explain what 'relationships' and 'observations' entail, the return format, or any constraints, leaving the agent with insufficient information for effective use.

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 input schema has 100% description coverage, with the single parameter 'entity_id' documented as 'Entity ID'. The description adds no additional meaning beyond this, such as explaining what constitutes an entity or how to obtain its ID. Baseline 3 is appropriate since the schema does the heavy lifting.

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 verb ('retrieve') and resource ('all relationships and observations for a specific entity'), making the purpose understandable. However, it doesn't differentiate from siblings like 'get_terraform_resource_info' or 'get_ansible_module_info', which also retrieve information but for different resources, so it lacks explicit sibling distinction.

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 doesn't mention prerequisites, exclusions, or compare to siblings such as 'get_entity' (if it existed) or other retrieval tools in the list, leaving the agent with minimal context for selection.

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

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/AgentWong/iac-memory-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server