Skip to main content
Glama

Create Knowledge Graph

create_graph

Create a new knowledge graph with a unique ID and title to organize structured data for AI agents using Mnemosyne MCP server.

Instructions

Creates a new knowledge graph with the given ID, title, and optional description. The graph_id should be a URL-safe identifier (e.g., 'my-project', 'research-notes').

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
graph_idYes
titleYes
descriptionNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The core handler function for the 'create_graph' tool. It validates inputs, submits a 'create_graph' job to the backend API, waits for completion using WebSocket or polling, and returns formatted JSON results.
    @server.tool(
        name="create_graph",
        title="Create Knowledge Graph",
        description=(
            "Creates a new knowledge graph with the given ID, title, and optional description. "
            "The graph_id should be a URL-safe identifier (e.g., 'my-project', 'research-notes')."
        ),
    )
    async def create_graph_tool(
        graph_id: str,
        title: str,
        description: Optional[str] = None,
        context: Context | None = None,
    ) -> str:
        """Create a new knowledge graph."""
        auth = MCPAuthContext.from_context(context)
        auth.require_auth()
    
        if not graph_id or not graph_id.strip():
            raise ValueError("graph_id is required and cannot be empty")
        if not title or not title.strip():
            raise ValueError("title is required and cannot be empty")
    
        payload = {
            "graph_id": graph_id.strip(),
            "title": title.strip(),
        }
        if description:
            payload["description"] = description.strip()
    
        metadata = await submit_job(
            base_url=backend_config.base_url,
            auth=auth,
            task_type="create_graph",
            payload=payload,
        )
    
        if context:
            await context.report_progress(10, 100)
    
        result = await _wait_for_job_result(
            job_stream, metadata, context, auth
        )
    
        return _render_json({
            "success": True,
            "graph_id": graph_id.strip(),
            "title": title.strip(),
            "description": description.strip() if description else None,
            "job_id": metadata.job_id,
            **result,
        })
  • Registration of graph operations tools, including 'create_graph', on the MCP server instance in the standalone server setup.
    register_basic_tools(mcp_server)
    register_graph_ops_tools(mcp_server)
    register_hocuspocus_tools(mcp_server)
  • Helper function used by create_graph_tool to wait for the job result using realtime streaming or polling.
    async def _wait_for_job_result(
        job_stream: Optional[RealtimeJobClient],
        metadata: JobSubmitMetadata,
        context: Optional[Context],
        auth: MCPAuthContext,
    ) -> JsonDict:
        """Wait for job completion via WebSocket or polling, return result info including detail."""
        events = None
        if job_stream and metadata.links.websocket:
            events = await stream_job(job_stream, metadata, timeout=STREAM_TIMEOUT_SECONDS)
    
        if events:
            if context:
                await context.report_progress(80, 100)
            # Check for completion status in events and extract result
            for event in reversed(events):
                event_type = event.get("type", "")
                if event_type in ("job_completed", "completed", "succeeded"):
                    if context:
                        await context.report_progress(100, 100)
                    # Extract result from event payload
                    result: JsonDict = {"status": "succeeded", "events": len(events)}
                    payload = event.get("payload", {})
                    if isinstance(payload, dict):
                        detail = payload.get("detail")
                        if detail:
                            result["detail"] = detail
                    return result
                if event_type in ("failed", "error"):
                    error = event.get("error", "Job failed")
                    return {"status": "failed", "error": error}
            return {"status": "unknown", "event_count": len(events)}
    
        # Fall back to polling
        status_payload = (
            await poll_job_until_terminal(metadata.links.status, auth)
            if metadata.links.status
            else None
        )
    
        if context:
            await context.report_progress(100, 100)
    
        if status_payload:
            status = status_payload.get("status", "unknown")
            detail = status_payload.get("detail")
            if status == "failed":
                error = status_payload.get("error") or (detail.get("error") if isinstance(detail, dict) else None)
                return {"status": "failed", "error": error}
            # Include full detail in result for successful jobs
            result: JsonDict = {"status": status}
            if detail:
                result["detail"] = detail
            return result
    
        return {"status": "unknown"}
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 mentions the tool creates something (implying mutation), it doesn't address important behavioral aspects like permissions required, whether the operation is idempotent, what happens on duplicate graph_id, rate limits, or what the output contains. The description provides minimal behavioral context beyond the basic operation.

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?

Two sentences with zero waste. The first sentence states the core purpose and parameters. The second provides crucial formatting guidance for graph_id. Every word earns its place, and the most important information (what it creates) comes first.

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

Completeness3/5

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

Given this is a mutation tool with no annotations but with an output schema (which handles return values), the description is moderately complete. It covers the parameters well but lacks behavioral context about permissions, idempotency, and error conditions. For a creation tool, more guidance on duplicate handling and success criteria would be beneficial.

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

Parameters4/5

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

With 0% schema description coverage, the description compensates well by explaining all 3 parameters: graph_id (URL-safe identifier with examples), title, and description (optional). It adds meaningful context about the graph_id format that isn't in the schema, though it doesn't elaborate on title constraints or description content guidelines.

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 'creates' and resource 'knowledge graph' with specific attributes (ID, title, optional description). It distinguishes from siblings like 'delete_graph' or 'list_graphs' by focusing on creation, but doesn't explicitly contrast with similar tools like 'create_folder' beyond the resource type.

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?

No guidance on when to use this tool versus alternatives is provided. The description doesn't mention prerequisites, when this operation is appropriate, or what happens if a graph with the same ID already exists. It simply states what the tool does without contextual usage information.

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/sophia-labs/mnemosyne-mcp'

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