Skip to main content
Glama

build_injection

Creates injection payloads with contexts and instincts for specific tool-input combinations to automate rule and preference application.

Instructions

Build a complete injection payload (contexts + instincts) for a tool/input combination

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
toolYesTool name or pattern
inputYesInput text to match instincts against

Implementation Reference

  • The core business logic that builds the injection payload by combining context matches and instinct matches.
    buildInjection(tool: string, input: string): InjectionPayload {
      // 1. Match contexts (always full confidence)
      const contextMatches = this.matchContexts({ tool });
      const context_rules: InjectionRule[] = contextMatches.map((m) => ({
        source: 'context' as const,
        id: m.context.tool_category,
        content: JSON.stringify(m.context),
        confidence: 1.0,
        matched_by: m.matched_pattern,
      }));
    
      // 2. Match instincts (confidence-scored)
      const instinctMatches = this.matchInstincts({ input });
      const instinct_rules: InjectionRule[] = instinctMatches.map((m) => ({
        source: 'instinct' as const,
        id: m.instinct.id,
        content: m.instinct.rule,
        confidence: m.instinct.confidence,
        matched_by: m.matched_pattern,
      }));
    
      // 3. Estimate tokens
      const estimateTokens = (text: string) =>
        text.split(/\s+/).filter(Boolean).length;
      const estimated_tokens =
        context_rules.reduce((sum, r) => sum + estimateTokens(r.content), 0) +
        instinct_rules.reduce((sum, r) => sum + estimateTokens(r.content), 0);
  • MCP tool handler registration and request dispatching for build_injection.
    case 'build_injection': {
      const tool = String(args?.['tool'] ?? '*');
      const input = String(args?.['input'] ?? '');
      const payload = engine.buildInjection(tool, input);
      return { content: [{ type: 'text', text: JSON.stringify(payload, null, 2) }] };
    }
  • MCP schema definition for the build_injection tool.
    {
      name: 'build_injection',
      description:
        'Build a complete injection payload (contexts + instincts) for a tool/input combination',
      inputSchema: {
        type: 'object' as const,
        properties: {
          tool: { type: 'string', description: 'Tool name or pattern' },
          input: {
            type: 'string',
            description: 'Input text to match instincts against',
          },
        },
        required: ['tool', 'input'],
      },
    },

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/doobidoo/MCP-Context-Provider'

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