Skip to main content
Glama
AgentWong
by AgentWong

create_entity

Add new Infrastructure-as-Code components to persistent memory storage for version tracking and relationship mapping in Terraform and Ansible environments.

Instructions

Create a new entity in the knowledge graph with optional initial observations

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
nameYesEntity name
typeYesEntity type
observationNoInitial observation

Implementation Reference

  • The primary MCP handler function for the 'create_entity' tool. Validates inputs, logs the operation, calls the execution helper, and handles errors appropriately.
    async def handle_create_entity(db: Any, arguments: Dict[str, Any], operation_id: str) -> list[types.TextContent | types.ImageContent | types.EmbeddedResource]:
        """Handle create_entity tool."""
        # Validate required arguments
        if not arguments.get("name") or not arguments.get("type"):
            raise ValidationError("Missing required arguments: name and type are required")
    
        logger.info(
            "Creating entity",
            extra={
                "entity_type": arguments.get("type"),
                "operation_id": operation_id,
            },
        )
    
        try:
            # Execute creation
            return await execute_create_entity(db, arguments)
    
        except Exception as e:
            error_msg = f"Failed to create entity: {str(e)}"
            logger.error(error_msg, extra={"operation_id": operation_id})
            raise McpError(
                types.ErrorData(
                    code=types.INTERNAL_ERROR,
                    message=error_msg,
                    data={
                        "tool": "create_entity",
                        "operation_id": operation_id,
                    },
                )
            )
  • Core database execution logic for creating an entity and optional observation. Performs transaction-safe INSERT operations and returns a formatted success message.
    async def execute_create_entity(
        db: DatabaseManager, arguments: Dict[str, Any]
    ) -> List[TextContent]:
        """Execute create entity operation.
    
        Args:
            db: Database manager instance
            arguments: Tool arguments
        """
        logger.info("Creating new entity", extra={"tool_arguments": arguments})
    
        with db.get_connection() as conn:
            conn.execute("PRAGMA busy_timeout = 5000")  # 5s timeout
            conn.execute("BEGIN IMMEDIATE")
            try:
                # Create entity
                cursor = conn.execute(
                    """INSERT INTO entities (name, type)
                    VALUES (?, ?)""",
                    (arguments["name"], arguments["type"]),
                )
                entity_id = cursor.lastrowid
    
                # Add observation if provided
                if "observation" in arguments:
                    conn.execute(
                        "INSERT INTO observations (entity_id, content) VALUES (?, ?)",
                        (entity_id, arguments["observation"]),
                    )
    
                conn.commit()
                return [
                    TextContent(
                        type="text",
                        text=f"Created entity '{arguments['name']}' (ID: {entity_id})",
                    )
                ]
            except Exception as e:
                conn.rollback()
                logger.error(f"Failed to create entity: {str(e)}")
                raise DatabaseError(f"Failed to create entity: {str(e)}")
  • JSON schema defining the input parameters, requirements, and descriptions for the 'create_entity' tool.
    "create_entity": {
        "type": "object",
        "description": "Create a new entity in the knowledge graph with optional initial observations",
        "required": ["name", "type"],
        "properties": {
            "name": {"type": "string", "description": "Entity name"},
            "type": {"type": "string", "description": "Entity type"},
            "observation": {"type": "string", "description": "Initial observation"},
        },
    },
  • Local registration mapping the 'create_entity' tool name to its handler function, which is later merged into the global tool_handlers dictionary.
    entity_tool_handlers = {
        "create_entity": handle_create_entity,
        "update_entity": handle_update_entity,
        "delete_entity": handle_delete_entity,
        "view_relationships": handle_view_relationships,
    }
  • Top-level MCP server registration of the call_tool and list_tools methods, which dispatch to handlers including 'create_entity' via the merged tool_handlers dictionary.
    def register_tools(server: Server) -> None:
        """Register all tool handlers with the server."""
    
        @server.call_tool()
        async def call_tool(
            name: str, arguments: Dict[str, Any], ctx: RequestContext | None = None
        ):
            return await handle_call_tool(name, arguments, ctx)
    
        @server.list_tools()
        async def list_tools(ctx: RequestContext = None):
            return await handle_list_tools(ctx)
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. While it indicates this is a creation operation, it doesn't address important behavioral aspects like whether this requires specific permissions, what happens if an entity with the same name already exists, whether the operation is idempotent, or what the response looks like. For a mutation tool with zero annotation coverage, this is inadequate.

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 communicates the core functionality without any wasted words. It's appropriately sized for a tool with 3 parameters and gets straight to the point with no unnecessary elaboration.

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?

For a mutation tool with no annotations and no output schema, the description is insufficiently complete. It doesn't explain what happens after creation, what errors might occur, how the entity integrates with the knowledge graph system, or what the tool returns. Given the complexity of entity creation in a knowledge graph context, more contextual information is needed.

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%, so all parameters are documented in the schema. The description adds minimal value beyond the schema by mentioning 'optional initial observations' which corresponds to the 'observation' parameter. However, it doesn't provide additional context about parameter relationships or usage patterns beyond what's already in the structured schema.

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 ('create') and resource ('entity in the knowledge graph'), making the purpose immediately understandable. However, it doesn't differentiate this tool from its sibling 'update_entity' or explain how it relates to other entity management tools like 'delete_entity' and 'view_relationships', which prevents a perfect score.

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 like 'update_entity' or 'delete_entity'. It mentions 'optional initial observations' but doesn't explain when this feature is appropriate or what prerequisites might be needed for creating entities.

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-project'

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