Skip to main content
Glama

Get Workspace Structure

get_workspace

Retrieve the folder and file structure of a graph's workspace to understand document organization.

Instructions

Returns the folder and file structure of a graph's workspace. Use this to understand the organization of documents in a graph.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
graph_idYes

Implementation Reference

  • The core asynchronous handler function `get_workspace_tool` for the "get_workspace" tool. It authenticates the request, ensures connection to the workspace channel via `hp_client.connect_workspace(graph_id)`, fetches the workspace snapshot using `hp_client.get_workspace_snapshot(graph_id)`, and returns a dictionary containing the graph_id and workspace data.
    @server.tool(
        name="get_workspace",
        title="Get Workspace Structure",
        description=(
            "Returns the folder and file structure of a graph's workspace. "
            "Use this to understand the organization of documents in a graph."
        ),
    )
    async def get_workspace_tool(
        graph_id: str,
        context: Context | None = None,
    ) -> dict:
        """Get workspace folder structure."""
        auth = MCPAuthContext.from_context(context)
        auth.require_auth()
    
        try:
            # Connect to the workspace channel
            await hp_client.connect_workspace(graph_id)
    
            # Get workspace snapshot
            snapshot = hp_client.get_workspace_snapshot(graph_id)
    
            result = {
                "graph_id": graph_id,
                "workspace": snapshot,
            }
            return result
    
        except Exception as e:
            logger.error(
                "Failed to get workspace",
                extra_context={
                    "graph_id": graph_id,
                    "error": str(e),
                },
            )
            raise RuntimeError(f"Failed to get workspace: {e}")
  • Explicit registration of the hocuspocus tools (including "get_workspace") on the MCP server instance by calling `register_hocuspocus_tools(mcp_server)`.
    register_hocuspocus_tools(mcp_server)
  • Supporting method `get_workspace_snapshot` in HocuspocusClient class that retrieves the current state of the workspace Y.js document for a given graph_id, extracting and serializing the folders, artifacts, documents, and ui maps into a plain dictionary.
    def get_workspace_snapshot(self, graph_id: str) -> Dict[str, Any]:
        """Get a snapshot of the workspace state for a graph."""
        channel = self._workspace_channels.get(graph_id)
        if channel is None:
            return {}
    
        doc = channel.doc
    
        def ymap_to_dict(ymap: pycrdt.Map) -> Dict[str, Any]:
            result = {}
            for key in ymap.keys():
                value = ymap.get(key)
                if isinstance(value, pycrdt.Map):
                    result[key] = ymap_to_dict(value)
                elif isinstance(value, pycrdt.Array):
                    result[key] = list(value)
                else:
                    result[key] = value
            return result
    
        # Workspace uses four separate YMaps: folders, artifacts, documents, ui
        folders_map: pycrdt.Map = doc.get("folders", type=pycrdt.Map)
        artifacts_map: pycrdt.Map = doc.get("artifacts", type=pycrdt.Map)
        documents_map: pycrdt.Map = doc.get("documents", type=pycrdt.Map)
        ui_map: pycrdt.Map = doc.get("ui", type=pycrdt.Map)
    
        return {
            "folders": ymap_to_dict(folders_map),
            "artifacts": ymap_to_dict(artifacts_map),
            "documents": ymap_to_dict(documents_map),
            "ui": ymap_to_dict(ui_map),
        }
  • Supporting method `connect_workspace` that establishes the WebSocket connection to the Hocuspocus workspace channel for the given graph_id if not already connected and synced.
    async def connect_workspace(self, graph_id: str) -> None:
        """Connect to a workspace channel for the given graph.
    
        Args:
            graph_id: The graph ID
        """
        if graph_id in self._workspace_channels:
            channel = self._workspace_channels[graph_id]
            if channel.ws and not channel.ws.closed and channel.synced.is_set():
                return  # Already connected and synced
    
        channel = ChannelState()
        self._workspace_channels[graph_id] = channel
    
        async with channel.lock:
            await self._connect_channel(
                channel,
                f"/hocuspocus/workspace/{graph_id}",
                f"workspace:{graph_id}",
            )
  • The `register_hocuspocus_tools` function definition that sets up the HocuspocusClient on the server and registers all hocuspocus tools including "get_workspace" using the `@server.tool` decorator.
    def register_hocuspocus_tools(server: FastMCP) -> None:
Behavior2/5

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

No annotations are provided, so the description carries full burden. It states it 'Returns' data, implying a read-only operation, but does not disclose behavioral traits such as permissions required, rate limits, pagination, or response format. For a tool with zero annotation coverage, this leaves significant gaps in understanding how it behaves.

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 two sentences, front-loaded with the core purpose and followed by usage context. Every sentence adds value without redundancy, making it efficient and well-structured for quick comprehension.

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 1 parameter with 0% schema coverage, no annotations, and no output schema, the description is incomplete. It covers the basic purpose but lacks details on parameters, behavioral traits, or return values, which are essential for a tool that retrieves structural data in a graph-based system.

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

Parameters2/5

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

Schema description coverage is 0%, so the description must compensate. It mentions 'graph's workspace' but does not explain the 'graph_id' parameter beyond what the schema title ('Graph Id') provides. No details on format, sourcing, or constraints are added, failing to adequately clarify parameter meaning.

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 ('Returns') and resource ('folder and file structure of a graph's workspace'), specifying it provides organizational understanding. It distinguishes from siblings like 'list_graphs' (which lists graphs) or 'get_block' (which retrieves individual blocks), but could be more explicit about the distinction.

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

Usage Guidelines3/5

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

The description implies usage ('Use this to understand the organization of documents in a graph') for exploring workspace structure, but lacks explicit guidance on when to choose this over alternatives like 'list_graphs' for high-level overview or 'query_blocks' for detailed content. No exclusions or prerequisites are mentioned.

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