Skip to main content
Glama
isagasi

CodeGuard MCP Server

by isagasi

get_security_instructions

Retrieve security rules for code generation by specifying language, context keywords, or file path to ensure adherence to best practices.

Instructions

Get security instructions for code generation. Returns applicable security rules based on language, context, or file path.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
languageNoProgramming language (python, javascript, typescript, java, c, etc.)
contextNoContext keywords (auth, crypto, database, api, password, hash, etc.)
filepathNoFile path for pattern matching (e.g., src/auth/login.ts)

Implementation Reference

  • The main handler function for the 'get_security_instructions' tool. It extracts language, context, and filepath from args, calls matchInstructions() to find matching security rules, formats them as markdown, and returns the result.
    function getSecurityInstructions(
      args: Record<string, unknown>,
      instructions: Instruction[]
    ) {
      const language = args.language as string | undefined;
      const context = args.context as string | undefined;
      const filepath = args.filepath as string | undefined;
      
      // Match instructions
      const result = matchInstructions(
        { language, context, filepath },
        instructions
      );
      
      // Format as markdown
      const content = result.instructions
        .map(i => {
          return `## ${i.frontmatter.description}\n\n${i.content}`;
        })
        .join('\n\n---\n\n');
      
      return {
        content: [
          {
            type: 'text',
            text: content || 'No specific security instructions matched. Follow general security best practices.',
          },
        ],
        isError: false,
      };
    }
  • Registration of the tool in the listTools() function, defining name 'get_security_instructions', description, and inputSchema with optional parameters: language, context, and filepath.
    {
      name: 'get_security_instructions',
      description: 'Get security instructions for code generation. Returns applicable security rules based on language, context, or file path.',
      inputSchema: {
        type: 'object',
        properties: {
          language: {
            type: 'string',
            description: 'Programming language (python, javascript, typescript, java, c, etc.)',
          },
          context: {
            type: 'string',
            description: 'Context keywords (auth, crypto, database, api, password, hash, etc.)',
          },
          filepath: {
            type: 'string',
            description: 'File path for pattern matching (e.g., src/auth/login.ts)',
          },
        },
      },
    },
  • Dispatch in callTool() that routes the 'get_security_instructions' tool name to the getSecurityInstructions handler function.
    if (name === 'get_security_instructions') {
      return getSecurityInstructions(args, instructions);
    }
  • src/index.ts:110-114 (registration)
    Server-level registration: the CallToolRequestSchema handler in the MCP server delegates to the callTool() function from handlers/tools.ts, which dispatches to getSecurityInstructions.
    // Call a tool
    server.setRequestHandler(CallToolRequestSchema, async (request) => {
      const { name, arguments: args = {} } = request.params;
      logToFile(`[MCP] CallTool: ${name} with args: ${JSON.stringify(args)}`);
      return callTool(name, args, instructions);
  • The matchInstructions() function called by the handler to score and select applicable security rules based on language, context, and filepath.
    export function matchInstructions(
      context: MatchContext,
      allInstructions: Instruction[]
    ): MatchResult {
      const scoredInstructions: ScoredInstruction[] = [];
      const matchedBy: MatchResult['metadata']['matchedBy'] = {};
      
      // Score all instructions
      for (const instruction of allInstructions) {
        const scored = scoreInstruction(instruction, context);
        if (scored.score > 0) {
          scoredInstructions.push(scored);
        }
      }
      
      // Sort by priority (high to low), then by score
      scoredInstructions.sort((a, b) => {
        if (a.priority !== b.priority) {
          return b.priority - a.priority;
        }
        return b.score - a.score;
      });
      
      // Count matches by type
      matchedBy.critical = scoredInstructions.filter(s => s.priority === Priority.CRITICAL).length;
      matchedBy.language = scoredInstructions.filter(s => s.matchReasons.includes('language')).length;
      matchedBy.filepath = scoredInstructions.filter(s => s.matchReasons.includes('filepath')).length;
      matchedBy.context = scoredInstructions.filter(s => s.matchReasons.includes('context')).length;
      
      // Priority breakdown
      const priorityBreakdown = {
        critical: scoredInstructions.filter(s => s.priority === Priority.CRITICAL).length,
        high: scoredInstructions.filter(s => s.priority === Priority.HIGH).length,
        medium: scoredInstructions.filter(s => s.priority === Priority.MEDIUM).length,
        low: scoredInstructions.filter(s => s.priority === Priority.LOW).length,
      };
      
      // Limit to top 15 rules to keep response size manageable
      const topInstructions = scoredInstructions.slice(0, 15);
      
      return {
        instructions: topInstructions.map(s => s.instruction),
        metadata: {
          totalMatched: scoredInstructions.length,
          matchedBy,
          priorityBreakdown,
        },
      };
    }

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv1.0.10

TDQS

A3.8/5.0
Behavior2/5

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

No annotations are provided, so the description carries the full burden for behavioral disclosure. It states that it 'Returns applicable security rules' but does not mention edge cases like empty results, error behavior, or any side effects. While the tool name suggests a read-only operation, this is not explicitly stated, leaving the agent with limited insight into its behavior.

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 two concise sentences, front-loaded with the primary action and followed by a clear summary of input logic. Every word contributes value, with no redundancy or filler.

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?

For a straightforward retrieval tool with no output schema and three optional parameters, the description covers the core purpose and input relationships. It is complete enough for an agent to select and invoke it, though a brief mention of the sibling tool would improve contextual completeness.

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?

The schema already provides 100% parameter descriptions, meeting the baseline. The description's mention of 'language, context, or file path' reinforces the schema but adds no new semantic detail about parameter interactions, precedence, or formatting. It neither enhances nor degrades the schema's clarity.

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's action ('Get security instructions') and its scope ('for code generation'), with specific input dimensions ('language, context, or file path'). This distinguishes it from the sibling tool 'validate_code_security', which focuses on validation rather than fetching instructions.

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

Usage Guidelines4/5

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

The description provides a clear use case ('for code generation'), implying when to use it. However, it does not explicitly mention alternatives or exclusions, such as when to prefer 'validate_code_security' instead. Thus it lacks the full alternative guidance seen in higher-scoring examples.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Deploy Server

Other Tools