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,
        },
      };
    }
Behavior2/5

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

With no annotations, the description should fully disclose behavioral traits. It indicates the tool returns applicable security rules but does not mention side effects, data source, rate limits, or that it is a read-only operation. Basic transparency is lacking.

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 concise with two sentences, front-loading the core action and purpose. No redundant or extraneous information is present.

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?

Given no output schema, the description hints at 'applicable security rules' but does not specify the return format or structure. For a simple lookup tool, this is adequate but could be more informative about the output.

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?

All three parameters have descriptions in the input schema (100% coverage), so the baseline is 3. The description only lists parameter names without adding new meaning beyond what the schema already provides.

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 'Get', the resource 'security instructions', and context 'for code generation'. It further specifies the criteria (language, context, file path), making the tool's purpose unambiguous and distinct from the sibling tool.

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 the tool provides instructions based on inputs, but does not explicitly differentiate from the sibling 'validate_code_security' or state when to use this tool versus alternatives. No when-not or 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/isagasi/codeguard-mcp-server'

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