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
| Name | Required | Description | Default |
|---|---|---|---|
| tool | Yes | Tool name or pattern | |
| input | Yes | Input text to match instincts against |
Implementation Reference
- src/engine/engine.ts:168-195 (handler)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); - src/server/index.ts:294-299 (registration)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) }] }; } - src/server/index.ts:117-132 (schema)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'], }, },