Skip to main content
Glama
florinel-chis

Magento 2 GraphQL Documentation MCP Server

get_related_documents

Find related documents by providing a source file path from Magento 2 GraphQL documentation.

Instructions

Find documents related to the specified document

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
file_pathYesFile path of source document

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The handler function that implements the 'get_related_documents' tool logic. It queries the SQLite database for documents related by category/subcategory and by keyword matching, then returns formatted results.
    @mcp.tool(
        name="get_related_documents",
        description="Find documents related to the specified document"
    )
    def get_related_documents(
        file_path: Annotated[str, Field(description="File path of source document")]
    ) -> str:
        """Find related docs"""
        db = Database(DB_PATH)
    
        # Get source document
        try:
            source_doc = dict(db.query(
                "SELECT * FROM documents WHERE file_path = ?",
                [file_path]
            ).__next__())
        except StopIteration:
            return f"Document not found: {file_path}"
    
        # Find related documents
        # 1. Same category and subcategory
        related_by_category = list(db.query(
            "SELECT * FROM documents WHERE category = ? AND subcategory = ? AND file_path != ? LIMIT 5",
            [source_doc['category'], source_doc['subcategory'], file_path]
        ))
    
        # 2. Similar keywords
        source_keywords = set(json.loads(source_doc.get('keywords_json', '[]')))
        related_by_keywords = []
    
        if source_keywords:
            for keyword in list(source_keywords)[:3]:
                matches = list(db.query(
                    "SELECT * FROM documents WHERE keywords_json LIKE ? AND file_path != ? LIMIT 3",
                    [f"%{keyword}%", file_path]
                ))
                related_by_keywords.extend(matches)
    
        # Combine and deduplicate
        seen = set()
        all_related = []
    
        for doc in related_by_category + related_by_keywords:
            if doc['file_path'] not in seen:
                seen.add(doc['file_path'])
                all_related.append(doc)
    
        all_related = all_related[:5]
    
        if not all_related:
            return f"No related documents found for: {file_path}"
    
        # Format results
        lines = [f"# Related Documents for: {source_doc['title']}", ""]
    
        for doc in all_related:
            relationship = "Same category" if doc['category'] == source_doc['category'] else "Similar content"
    
            lines.append(f"### {doc['title']}")
            lines.append(f"**Path:** {doc['file_path']}")
            lines.append(f"**Relationship:** {relationship}")
            lines.append(f"**Category:** {doc['category']}/{doc.get('subcategory', 'N/A')}")
    
            if doc.get('description'):
                lines.append(f"**Description:** {doc['description'][:150]}...")
    
            lines.append("")
    
        return "\n".join(lines)
  • Input schema for the tool: requires a single 'file_path' string parameter.
    def get_related_documents(
        file_path: Annotated[str, Field(description="File path of source document")]
  • Registration of the tool using FastMCP's @mcp.tool decorator with the name 'get_related_documents'.
    @mcp.tool(
        name="get_related_documents",
        description="Find documents related to the specified document"
    )
  • The DB_PATH configuration constant used by the handler to connect to the SQLite database.
    DB_PATH = get_db_path()
    DOCS_PATH = get_docs_path()
Behavior2/5

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

With no annotations provided, the description fails to disclose any behavioral traits. It does not indicate whether the operation is read-only, whether there are side effects, or any rate limits. The output schema exists but is not referenced in the description.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single sentence that directly states the tool's function. It is front-loaded and concise, with no wasted words. However, it could be slightly expanded to include more context without losing conciseness.

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

Completeness4/5

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

Given the tool's simplicity (one parameter, output schema present), the description is mostly complete. It explains the purpose and the parameter sufficiently. The existence of an output schema compensates for the lack of return value detail in the description.

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

Parameters3/5

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

Schema coverage is 100% with the parameter file_path having a clear description. The description adds no additional meaning beyond the schema. Baseline 3 is appropriate.

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 tool's purpose: finding documents related to a given document. It uses a specific verb ('Find') and resource ('documents related to the specified document'). However, it lacks differentiation from sibling tools like get_document or search_documentation, leaving the concept of 'related' somewhat ambiguous.

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?

There is no guidance on when to use this tool versus alternatives such as get_document (for a single document) or search_documentation (for keyword-based search). No prerequisites or conditions 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/florinel-chis/magento-graphql-docs-mcp'

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