Skip to main content
Glama

read_document

Retrieve formatted document content from Mnemosyne knowledge graphs as structured TipTap XML for processing and analysis.

Instructions

Reads document content as TipTap XML with full formatting.

Blocks: paragraph, heading (level="1-3"), bulletList, orderedList, blockquote, codeBlock (language="..."), taskList (taskItem checked="true"), horizontalRule Marks (nestable): strong, em, strike, code, mark (highlight), a (href="..."), footnote (data-footnote-content="..."), commentMark (data-comment-id="...") Lists: item

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
graph_idYes
document_idYes

Implementation Reference

  • The handler function that executes the read_document tool: authenticates, connects to Hocuspocus document channel, reads TipTap XML content and comments using DocumentReader, returns structured result.
    async def read_document_tool(
        graph_id: str,
        document_id: str,
        context: Context | None = None,
    ) -> dict:
        """Read document content as TipTap XML."""
        auth = MCPAuthContext.from_context(context)
        auth.require_auth()
    
        try:
            # Connect to the document channel
            await hp_client.connect_document(graph_id, document_id)
    
            # Get the channel and read content
            channel = hp_client.get_document_channel(graph_id, document_id)
            if channel is None:
                raise RuntimeError(f"Document channel not found: {graph_id}/{document_id}")
    
            reader = DocumentReader(channel.doc)
            xml_content = reader.to_xml()
            comments = reader.get_all_comments()
    
            result = {
                "graph_id": graph_id,
                "document_id": document_id,
                "content": xml_content,
                "comments": comments,
            }
            return result
    
        except Exception as e:
            logger.error(
                "Failed to read document",
                extra_context={
                    "graph_id": graph_id,
                    "document_id": document_id,
                    "error": str(e),
                },
            )
            raise RuntimeError(f"Failed to read document: {e}")
  • The @server.tool decorator that registers the read_document tool, defines its name, title, description (schema metadata), and parameter types via function signature.
        @server.tool(
            name="read_document",
            title="Read Document Content",
            description="""Reads document content as TipTap XML with full formatting.
    
    Blocks: paragraph, heading (level="1-3"), bulletList, orderedList, blockquote, codeBlock (language="..."), taskList (taskItem checked="true"), horizontalRule
    Marks (nestable): strong, em, strike, code, mark (highlight), a (href="..."), footnote (data-footnote-content="..."), commentMark (data-comment-id="...")
    Lists: <bulletList><listItem><paragraph>item</paragraph></listItem></bulletList>""",
        )
  • Call to register_hocuspocus_tools which defines and registers the read_document tool (among others) to the FastMCP server instance.
    register_hocuspocus_tools(mcp_server)

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