Skip to main content
Glama

query_patterns

Discover and analyze code patterns across programming languages within a knowledge graph. Filter results by language or pattern name to enhance code understanding and retrieval.

Instructions

Query code patterns in the knowledge graph.

Args: language: Filter by programming language pattern_name: Filter by pattern name

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
languageNo
pattern_nameNo

Implementation Reference

  • The handler function for the 'query_patterns' MCP tool. It queries the knowledge graph for patterns matching the given language and name filters, then formats and returns a detailed string summary of the matching patterns.
    @self.mcp.tool()
    def query_patterns(
        language: str | None = None, pattern_name: str | None = None
    ) -> str:
        """Query code patterns in the knowledge graph.
    
        Args:
            language: Filter by programming language
            pattern_name: Filter by pattern name
        """
        patterns = self.knowledge.find_patterns(
            name=pattern_name, language=language
        )
    
        if not patterns:
            return "No patterns found matching the query criteria"
    
        # Format results
        output = f"Found {len(patterns)} patterns:\n\n"
    
        for pattern in patterns:
            output += f"Name: {pattern.name}\n"
    
            if pattern.language:
                output += f"Language: {pattern.language}\n"
    
            output += f"Description: {pattern.description}\n"
    
            if pattern.example:
                output += "Example:\n"
                output += "```\n"
                output += pattern.example
                output += "\n```\n"
    
            output += "\n"
    
        return output
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. The description only states it's a query operation, but doesn't disclose important behavioral traits like whether this is a read-only operation, what permissions might be required, whether results are paginated, what format results return, or any rate limits. For a query tool with zero annotation coverage, this leaves significant gaps in understanding how the tool behaves.

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 appropriately concise with a clear main statement followed by parameter explanations. The two-sentence structure is efficient with no wasted words, though the parameter explanations could be more detailed given the schema coverage gap. The front-loaded purpose statement is effective.

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 the complexity of querying a knowledge graph with no annotations and no output schema, the description is incomplete. It doesn't explain what a 'code pattern' is in this context, what the query returns, how results are structured, or any limitations. For a tool that presumably returns complex pattern data from a knowledge graph, the description leaves too many questions unanswered.

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?

With 0% schema description coverage, the description adds some value by explaining that 'language' filters by programming language and 'pattern_name' filters by pattern name. However, it doesn't provide crucial details like what languages are supported, what pattern names exist, whether these are exact matches or partial matches, or what happens when both filters are null. The description compensates partially but not fully for the schema coverage gap.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose3/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description states 'Query code patterns in the knowledge graph' which provides a clear verb ('Query') and resource ('code patterns'), but it's somewhat vague about what 'code patterns' specifically means and doesn't distinguish this tool from sibling tools like 'query_entities' or 'query_style_conventions'. The purpose is understandable but lacks specificity about what distinguishes pattern queries from other query types.

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?

The description provides no guidance about when to use this tool versus alternatives. With sibling tools like 'query_entities' and 'query_style_conventions' available, there's no indication of what makes this tool appropriate for pattern queries specifically versus other query types. No context about prerequisites, typical use cases, or exclusions is provided.

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

Related 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/sarathsp06/sourcesage'

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