Skip to main content
Glama

Get Active Graph and Document

get_active_context

Retrieve the current graph and document IDs from a user's Mnemosyne session to identify what they are actively working on in the interface.

Instructions

Returns the currently active graph ID and document ID from the user's session. Use this to understand what the user is currently working on in the Mnemosyne UI. The user_id is automatically derived from authentication if not provided.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
user_idNo

Implementation Reference

  • The core handler function `get_active_context_tool` decorated with `@server.tool(name="get_active_context")`. This defines and registers the tool, implementing logic to fetch active graph/document from Hocuspocus Y.js session.
    @server.tool(
        name="get_active_context",
        title="Get Active Graph and Document",
        description=(
            "Returns the currently active graph ID and document ID from the user's session. "
            "Use this to understand what the user is currently working on in the Mnemosyne UI. "
            "The user_id is automatically derived from authentication if not provided."
        ),
    )
    async def get_active_context_tool(
        user_id: Optional[str] = None,
        context: Context | None = None,
    ) -> dict:
        """Get the active graph and document from session state."""
        auth = MCPAuthContext.from_context(context)
        token = auth.require_auth()
    
        # Auto-derive user_id if not provided
        if not user_id:
            # Try auth context first, then token
            user_id = auth.user_id or (get_user_id_from_token(token) if token else None)
            if not user_id:
                raise RuntimeError(
                    "Could not determine user ID. Either provide it explicitly or "
                    "ensure your token contains a 'sub' claim."
                )
    
        try:
            await hp_client.ensure_session_connected(user_id)
    
            active_graph = hp_client.get_active_graph_id()
            active_doc = hp_client.get_active_document_id()
            session_snapshot = hp_client.get_session_snapshot()
    
            result = {
                "active_graph_id": active_graph,
                "active_document_id": active_doc,
                "session": session_snapshot,
            }
            return result
    
        except Exception as e:
            logger.error(
                "Failed to get active context",
                extra_context={"error": str(e)},
            )
            raise RuntimeError(f"Failed to get active context: {e}")
  • Invocation of `register_hocuspocus_tools(mcp_server)` in `create_standalone_mcp_server()`, which executes the tool decorators to register `get_active_context` on the MCP server instance.
    register_hocuspocus_tools(mcp_server)
Behavior3/5

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

With no annotations provided, the description carries full burden. It discloses that user_id is 'automatically derived from authentication if not provided,' which is useful behavioral context about default behavior. However, it doesn't describe what happens if no active session exists, whether this is a read-only operation, or what the return format looks like.

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, front-loaded with core purpose, followed by usage guidance and parameter clarification. Every sentence earns its place with no wasted words or redundancy.

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?

For a simple read operation with 1 parameter and no output schema, the description covers purpose and usage well. However, without annotations or output schema, it should ideally mention that this is a read-only operation and hint at the return structure (e.g., returns IDs as strings). The current description is adequate but has gaps in behavioral disclosure.

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?

The description adds meaningful context about the single parameter: 'The user_id is automatically derived from authentication if not provided.' This explains the optional nature and default behavior beyond what the schema shows (just 'User Id' with null default). With 0% schema description coverage and only 1 parameter, this adequately compensates.

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

Purpose5/5

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

The description clearly states the specific action ('Returns'), resources ('currently active graph ID and document ID'), and context ('from the user's session'). It distinguishes from siblings like 'get_block' or 'get_workspace' by focusing on session-specific active context rather than retrieving arbitrary resources.

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

Usage Guidelines5/5

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

Explicitly states when to use this tool: 'Use this to understand what the user is currently working on in the Mnemosyne UI.' This provides clear context for application versus alternatives like 'list_graphs' for general listing or 'read_document' for document content.

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