Skip to main content
Glama

get_style_guide

Retrieve project-specific style guide rules and architectural patterns by querying documentation. Choose categories like naming, structure, patterns, or testing to get relevant rules for your codebase.

Instructions

Routes to the active/current project automatically when known. Query style guide rules and architectural patterns from project documentation.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryNoQuery for specific style guide rules (e.g., "component naming", "service patterns")
categoryNoFilter by category (naming, structure, patterns, testing)
projectNoOptional project selector for this call. Accepts a project root path, file path, file:// URI, or a relative subproject path under a configured root.
project_directoryNoDeprecated compatibility alias for older clients. Prefer project.

Implementation Reference

  • The main handler function that executes the 'get_style_guide' tool logic. It searches for style guide files (STYLE_GUIDE.md, CODING_STYLE.md, ARCHITECTURE.md, etc.) in the project root, splits content by sections, matches against a query/category filter, and returns relevant sections as JSON.
    export async function handle(
      args: Record<string, unknown>,
      ctx: ToolContext
    ): Promise<ToolResponse> {
      const { query, category } = args as {
        query?: string;
        category?: string;
      };
      const queryStr = typeof query === 'string' ? query.trim() : '';
      const queryLower = queryStr.toLowerCase();
      const queryTerms = queryLower.split(/\s+/).filter(Boolean);
      const categoryLower = typeof category === 'string' ? category.trim().toLowerCase() : '';
      const limitedMode = queryTerms.length === 0;
      const LIMITED_MAX_FILES = 3;
      const LIMITED_MAX_SECTIONS_PER_FILE = 2;
    
      const styleGuidePatterns = [
        'STYLE_GUIDE.md',
        'CODING_STYLE.md',
        'ARCHITECTURE.md',
        'CONTRIBUTING.md',
        'docs/style-guide.md',
        'docs/coding-style.md',
        'docs/ARCHITECTURE.md'
      ];
    
      const foundGuides: Array<{
        file: string;
        content: string;
        relevantSections: string[];
      }> = [];
    
      for (const pattern of styleGuidePatterns) {
        try {
          const files = await glob(pattern, {
            cwd: ctx.rootPath,
            absolute: true
          });
          for (const file of files) {
            try {
              // Normalize line endings to \n for consistent output
              const rawContent = await fs.readFile(file, 'utf-8');
              const content = rawContent.replace(/\r\n/g, '\n');
              const relativePath = path.relative(ctx.rootPath, file);
    
              // Find relevant sections based on query
              const sections = content.split(/^##\s+/m);
              const relevantSections: string[] = [];
              if (limitedMode) {
                const headings = (content.match(/^##\s+.+$/gm) || [])
                  .map((h) => h.trim())
                  .filter(Boolean)
                  .slice(0, LIMITED_MAX_SECTIONS_PER_FILE);
    
                if (headings.length > 0) {
                  relevantSections.push(...headings);
                } else {
                  const words = content.split(/\s+/).filter(Boolean);
                  if (words.length > 0) {
                    relevantSections.push(`Overview: ${words.slice(0, 80).join(' ')}...`);
                  }
                }
              } else {
                for (const section of sections) {
                  const sectionLower = section.toLowerCase();
                  const isRelevant = queryTerms.some((term) => sectionLower.includes(term));
                  if (isRelevant) {
                    // Limit section size to ~500 words
                    const words = section.split(/\s+/);
                    const truncated = words.slice(0, 500).join(' ');
                    relevantSections.push(
                      '## ' + (words.length > 500 ? truncated + '...' : section.trim())
                    );
                  }
                }
              }
    
              const categoryMatch =
                !categoryLower ||
                relativePath.toLowerCase().includes(categoryLower) ||
                relevantSections.some((section) => section.toLowerCase().includes(categoryLower));
              if (!categoryMatch) {
                continue;
              }
    
              if (relevantSections.length > 0) {
                foundGuides.push({
                  file: relativePath,
                  content: content.slice(0, 200) + '...',
                  relevantSections: relevantSections.slice(
                    0,
                    limitedMode ? LIMITED_MAX_SECTIONS_PER_FILE : 3
                  )
                });
              }
            } catch (_e) {
              // Skip unreadable files
            }
          }
        } catch (_e) {
          // Pattern didn't match, continue
        }
      }
    
      const results = limitedMode ? foundGuides.slice(0, LIMITED_MAX_FILES) : foundGuides;
    
      if (results.length === 0) {
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify(
                {
                  status: 'no_results',
                  message: limitedMode
                    ? 'No style guide files found in the default locations.'
                    : `No style guide content found matching: ${queryStr}`,
                  searchedPatterns: styleGuidePatterns,
                  hint: limitedMode
                    ? "Run get_style_guide with a query or category (e.g. category: 'testing') for targeted results."
                    : "Try broader terms like 'naming', 'patterns', 'testing', 'components'"
                },
                null,
                2
              )
            }
          ]
        };
      }
    
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify(
              {
                status: 'success',
                query: queryStr || undefined,
                category,
                limited: limitedMode,
                notice: limitedMode
                  ? 'No query provided. Results are capped. Provide query and/or category for targeted guidance.'
                  : undefined,
                resultLimits: limitedMode
                  ? {
                      maxFiles: LIMITED_MAX_FILES,
                      maxSectionsPerFile: LIMITED_MAX_SECTIONS_PER_FILE
                    }
                  : undefined,
                results,
                totalFiles: results.length,
                totalMatches: foundGuides.length
              },
              null,
              2
            )
          }
        ]
      };
    }
  • The Tool definition/schema for 'get_style_guide'. Declares name, description, and inputSchema with optional 'query' (string) and 'category' (string) properties.
    export const definition: Tool = {
      name: 'get_style_guide',
      description: 'Query style guide rules and architectural patterns from project documentation.',
      inputSchema: {
        type: 'object',
        properties: {
          query: {
            type: 'string',
            description:
              'Query for specific style guide rules (e.g., "component naming", "service patterns")'
          },
          category: {
            type: 'string',
            description: 'Filter by category (naming, structure, patterns, testing)'
          }
        }
      }
    };
  • src/tools/index.ts:9-9 (registration)
    Import of the definition (d5) and handle (h5) from get-style-guide.ts.
    import { definition as d5, handle as h5 } from './get-style-guide.js';
  • Registration of the 'get_style_guide' tool in the TOOLS array (as d5), wrapped with project selector.
    export const TOOLS: Tool[] = [d1, d2, d3, d4, d5, d6, d7, d8, d9, d10, d11].map(
      withProjectSelector
    );
  • Dispatch case in the switch statement that routes 'get_style_guide' to the h5 handler.
    case 'get_style_guide':
      return h5(args, ctx);
Behavior3/5

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

With no annotations, the description reveals the automatic project routing behavior and the query nature, suggesting a read-only operation. However, it does not explicitly state that it is non-destructive, what happens if no project is active, or any error conditions, leaving some behavioral ambiguity.

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 only two sentences, front-loading the key automatic routing feature and then the main query purpose. Every sentence is necessary and without fluff, achieving maximum conciseness.

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?

No output schema exists, so the description should explain what the tool returns. It does not describe the return format, error handling, or behavior when no results are found. The deprecated 'project_directory' parameter is not addressed. This leaves significant gaps for an agent to use the tool correctly.

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

Parameters4/5

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

Parameter descriptions in schema cover 100% of parameters, already defining each parameter's purpose. The description adds value by explaining the automatic routing behavior for the optional 'project' parameter, clarifying that omitting it uses the active project, which goes beyond the schema's description.

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 tool queries style guide rules and architectural patterns from project documentation, using the verb 'Query' and resource 'style guide rules and architectural patterns'. It distinguishes itself from siblings like search_codebase (which is broader) and get_team_patterns (which is team-specific) by focusing specifically on style guide documentation.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage for querying style guide rules in the current project due to automatic routing, but does not explicitly state when to use it over alternatives (e.g., search_codebase for general search, get_team_patterns for team patterns). No when-not or explicit alternative guidance 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

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/PatrickSys/codebase-context'

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