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
| Name | Required | Description | Default |
|---|---|---|---|
| user_id | No |
Implementation Reference
- src/neem/mcp/tools/hocuspocus.py:48-95 (handler)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}")
- src/neem/mcp/server/standalone_server.py:317-317 (registration)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)