Skip to main content
Glama
florinel-chis

Magento 2 GraphQL Documentation MCP Server

search_graphql_elements

Search for GraphQL queries, mutations, types, or interfaces in Magento 2 documentation. Filter by element type to locate specific API references quickly.

Instructions

Search for GraphQL queries, mutations, types, or interfaces

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesSearch term, e.g., 'products', 'cart', 'customer'
element_typeNoFilter by element type: query, mutation, type, interface, union

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • Tool registration using FastMCP decorator. Registers 'search_graphql_elements' as an MCP tool with metadata description.
    @mcp.tool(
        name="search_graphql_elements",
        description="Search for GraphQL queries, mutations, types, or interfaces"
    )
  • Handler function that performs FTS search on the graphql_elements table, optionally filters by element_type, fetches the source document title/path, and formats results with element details.
    def search_graphql_elements(
        query: Annotated[str, Field(description="Search term, e.g., 'products', 'cart', 'customer'")],
        element_type: Annotated[
            Optional[str],
            Field(description="Filter by element type: query, mutation, type, interface, union")
        ] = None
    ) -> str:
        """Search GraphQL schema elements"""
        db = Database(DB_PATH)
    
        # FTS search
        results = list(db["graphql_elements"].search(query, limit=10))
    
        # Apply filter
        if element_type:
            results = [r for r in results if r['element_type'] == element_type]
    
        if not results:
            return f"No GraphQL elements found matching: {query}"
    
        # Format results
        formatted_results = []
        for elem in results:
            # Get source document
            try:
                doc = dict(db.query(
                    "SELECT title, file_path FROM documents WHERE id = ?",
                    [elem['document_id']]
                ).__next__())
                source = f"{doc['title']} ({doc['file_path']})"
            except StopIteration:
                source = "Unknown"
    
            fields = json.loads(elem.get('fields_json', '[]'))
            params = json.loads(elem.get('parameters_json', '[]'))
    
            formatted_results.append(
                f"### `{elem['element_type']}` **{elem['name']}**\n"
                f"**Source:** {source}\n"
                f"**Fields:** {', '.join(fields[:10]) if fields else 'None'}\n"
                f"**Parameters:** {', '.join(params) if params else 'None'}\n"
            )
    
        return "\n---\n\n".join(formatted_results)
  • Input schema using Pydantic Field annotations: 'query' (required str) and optional 'element_type' (str filter for query/mutation/type/interface/union). Returns str.
    def search_graphql_elements(
        query: Annotated[str, Field(description="Search term, e.g., 'products', 'cart', 'customer'")],
        element_type: Annotated[
            Optional[str],
            Field(description="Filter by element type: query, mutation, type, interface, union")
        ] = None
    ) -> str:
  • Database schema initialization for the graphql_elements table and its FTS5 full-text search index (trigram tokenizer), created during ingestion.
    if "graphql_elements" not in db.table_names():
        db["graphql_elements"].create({
            "id": int,
            "document_id": str,
            "element_type": str,
            "name": str,
            "fields_json": str,
            "parameters_json": str,
            "return_type": str,
            "description": str,
            "searchable_text": str,
        }, pk="id")
        db["graphql_elements"].create_index(["document_id"])
        db["graphql_elements"].create_index(["element_type"])
        db["graphql_elements"].create_index(["name"])
    
    # Create FTS5 indexes
    if "documents_fts" not in db.table_names():
        db["documents"].enable_fts(
            ["searchable_text"],
            create_triggers=True,
            tokenize="trigram"
        )
        logger.info("Created FTS index for documents")
    
    if "graphql_elements_fts" not in db.table_names():
        db["graphql_elements"].enable_fts(
            ["searchable_text"],
            create_triggers=True,
            tokenize="trigram"
        )
        logger.info("Created FTS index for graphql_elements")
  • Data ingestion logic that populates the graphql_elements table from parsed documentation data during the ingest process.
    # Insert GraphQL elements
    logger.info(f"Inserting {len(graphql_elements)} GraphQL elements...")
    element_records = []
    for element in graphql_elements:
        element_records.append({
            "document_id": element.document_id,
            "element_type": element.element_type,
            "name": element.name,
            "fields_json": json.dumps(element.fields),
            "parameters_json": json.dumps(element.parameters),
            "return_type": element.return_type,  # Allow NULL for missing return type
            "description": element.description,  # Allow NULL for missing description
            "searchable_text": element.searchable_text,
        })
    
    if element_records:
        db["graphql_elements"].insert_all(element_records)
        logger.info(f"Inserted {len(element_records)} GraphQL elements")
Behavior2/5

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

With no annotations, the description must disclose behavioral traits, but it only states the search action. It omits details like read-only behavior, result limits, error handling, or required permissions.

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 a single clear sentence with no redundant wording, making it very concise and easy to parse.

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 search tool with a full input schema and an output schema, the description is adequate but minimal. It does not cover edge cases or further behavior, leaving some gaps.

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 description coverage is 100%, so the schema already documents both parameters. The tool description adds no extra semantic value beyond the schema, meeting the baseline of 3.

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 verb 'Search' and the specific resource 'GraphQL queries, mutations, types, or interfaces'. This differentiates it from sibling tools like search_documentation and search_examples.

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?

No guidance is provided on when to use this tool over alternatives. It does not mention scenarios where it is appropriate or inappropriate, nor does it reference sibling tools.

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