Skip to main content
Glama
florinel-chis

Magento 2 GraphQL Documentation MCP Server

search_examples

Search for Magento 2 GraphQL code examples by topic and filter by language—GraphQL, JSON, JavaScript, PHP, or bash—to find relevant snippets quickly.

Instructions

Search for code examples by topic and language

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesSearch term for code examples
languageNoFilter by language: graphql, json, javascript, php, bash

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The main handler function for the search_examples tool. Accepts query (required) and language (optional) parameters. Queries the code_blocks table with a LIKE search on code and context columns, optionally filtered by language, limited to 10 results. Returns formatted Markdown with title, file path, language, context, and code preview.
    @mcp.tool(
        name="search_examples",
        description="Search for code examples by topic and language"
    )
    def search_examples(
        query: Annotated[str, Field(description="Search term for code examples")],
        language: Annotated[
            Optional[str],
            Field(description="Filter by language: graphql, json, javascript, php, bash")
        ] = None
    ) -> str:
        """Search code blocks"""
        db = Database(DB_PATH)
    
        # Search in code and context
        sql = """
            SELECT cb.*, d.title, d.file_path
            FROM code_blocks cb
            JOIN documents d ON cb.document_id = d.id
            WHERE (cb.code LIKE ? OR cb.context LIKE ?)
        """
        params = [f"%{query}%", f"%{query}%"]
    
        if language:
            sql += " AND cb.language = ?"
            params.append(language)
    
        sql += " LIMIT 10"
    
        results = list(db.query(sql, params))
    
        if not results:
            return f"No code examples found matching: {query}"
    
        # Format results
        formatted = []
        for block in results:
            context_str = f"**Context:** {block['context']}\n" if block.get('context') else ""
    
            formatted.append(
                f"### {block['title']}\n"
                f"**File:** {block['file_path']}\n"
                f"**Language:** {block['language']}\n"
                f"{context_str}"
                f"\n```{block['language']}\n"
                f"{block['code'][:MAX_CODE_PREVIEW_LENGTH]}\n"  # Limit code length for readability
                f"```\n"
            )
    
        return "\n---\n\n".join(formatted)
  • Input schema for search_examples: a required 'query' string and optional 'language' string filter (graphql, json, javascript, php, bash).
    query: Annotated[str, Field(description="Search term for code examples")],
    language: Annotated[
        Optional[str],
        Field(description="Filter by language: graphql, json, javascript, php, bash")
    ] = None
  • Registration decorator that registers the function as an MCP tool named 'search_examples' with the FastMCP server instance.
    @mcp.tool(
        name="search_examples",
        description="Search for code examples by topic and language"
  • Configuration constant limiting code preview length (default 400 characters), used in the handler to truncate displayed code.
    MAX_CODE_PREVIEW_LENGTH = int(os.environ.get("MAGENTO_GRAPHQL_DOCS_CODE_PREVIEW", "400"))
  • Database path configuration used by the handler to open the sqlite-utils Database connection.
    DB_PATH = get_db_path()
Behavior2/5

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

No annotations provided, so description carries burden. It only paraphrases the schema (search by topic and language) and adds no behavioral traits (e.g., result format, pagination, authentication needs). The output schema exists but is not referenced.

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?

Single sentence with no unnecessary words. It is appropriately short for a simple search tool, though additional structure (e.g., bullet points) could improve readability.

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?

With only 2 parameters and an output schema, the description is minimally adequate. It does not explain query syntax, language filter values (though schema has enum), or result handling, leaving gaps for a search tool.

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 descriptions for both parameters. The description adds 'by topic and language' but does not elaborate beyond schema, meeting baseline expectation for high coverage.

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?

Description clearly states the tool searches for code examples by topic and language. It distinguishes from sibling tools like search_documentation by specifying 'code examples', though not explicitly contrasting them.

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 on when to use this tool versus alternative search tools (search_documentation, search_graphql_elements). The description implies usage context but does not provide when-to-use or when-not-to-use criteria.

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