Skip to main content
Glama

log_decision

Record and document decisions in a structured format, including title, context, alternatives, and consequences, for centralized knowledge management on the MCP server.

Instructions

Log a decision in the decision log

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
alternativesNoAlternatives considered
consequencesNoConsequences of the decision
contextYesDecision context
decisionYesThe decision made
titleYesDecision title

Implementation Reference

  • The main handler function for the 'log_decision' tool. It calls ProgressTracker.logDecision to log the decision and also tracks progress.
    export async function handleLogDecision(
      progressTracker: ProgressTracker,
      decision: {
        title: string;
        context: string;
        decision: string;
        alternatives?: string[] | string;
        consequences?: string[] | string;
      }
    ) {
      try {
        await progressTracker.logDecision(decision);
    
        // Also track this as progress
        await progressTracker.trackProgress('Decision Made', {
          description: decision.title,
        });
    
        return {
          content: [
            {
              type: 'text',
              text: `Decision logged: ${decision.title}`,
            },
          ],
        };
      } catch (error) {
        return {
          content: [
            {
              type: 'text',
              text: `Error logging decision: ${error}`,
            },
          ],
          isError: true,
        };
      }
    }
  • Core helper method in ProgressTracker that implements the logic to append a formatted decision entry to 'decision-log.md'.
      async logDecision(decision: Decision): Promise<void> {
        const decisionLogPath = path.join(this.memoryBankDir, 'decision-log.md');
        
        try {
          let decisionLogContent = await FileUtils.readFile(decisionLogPath);
          
          const timestamp = new Date().toISOString().split('T')[0];
          const time = new Date().toLocaleTimeString();
          const userId = decision.userId || this.userId;
          const formattedUserId = this.formatUserId(userId);
          
          // Format alternatives and consequences
          const alternatives = Array.isArray(decision.alternatives) 
            ? decision.alternatives.map(alt => `  - ${alt}`).join('\n') 
            : decision.alternatives || 'None';
            
          const consequences = Array.isArray(decision.consequences) 
            ? decision.consequences.map(cons => `  - ${cons}`).join('\n') 
            : decision.consequences || 'None';
          
          const newDecision = `
    ## ${decision.title}
    - **Date:** ${timestamp} ${time}
    - **Author:** ${formattedUserId}
    - **Context:** ${decision.context}
    - **Decision:** ${decision.decision}
    - **Alternatives Considered:** 
    ${Array.isArray(decision.alternatives) ? alternatives : `  - ${alternatives}`}
    - **Consequences:** 
    ${Array.isArray(decision.consequences) ? consequences : `  - ${consequences}`}
    `;
          
          // Add the new decision to the end of the file
          decisionLogContent += newDecision;
          
          await FileUtils.writeFile(decisionLogPath, decisionLogContent);
        } catch (error) {
          console.error(`Error logging decision: ${error}`);
          throw new Error(`Failed to log decision: ${error}`);
        }
      }
  • Input schema for the log_decision tool defining the expected parameters.
    inputSchema: {
      type: 'object',
      properties: {
        title: {
          type: 'string',
          description: 'Decision title',
        },
        context: {
          type: 'string',
          description: 'Decision context',
        },
        decision: {
          type: 'string',
          description: 'The decision made',
        },
        alternatives: {
          type: 'array',
          items: {
            type: 'string',
          },
          description: 'Alternatives considered',
        },
        consequences: {
          type: 'array',
          items: {
            type: 'string',
          },
          description: 'Consequences of the decision',
        },
      },
      required: ['title', 'context', 'decision'],
    },
  • Registration of the log_decision tool with name, description, and schema reference.
    export const decisionTools = [
      {
        name: 'log_decision',
        description: 'Log a decision in the decision log',
        inputSchema: {
          type: 'object',
          properties: {
            title: {
              type: 'string',
              description: 'Decision title',
            },
            context: {
              type: 'string',
              description: 'Decision context',
            },
            decision: {
              type: 'string',
              description: 'The decision made',
            },
            alternatives: {
              type: 'array',
              items: {
                type: 'string',
              },
              description: 'Alternatives considered',
            },
            consequences: {
              type: 'array',
              items: {
                type: 'string',
              },
              description: 'Consequences of the decision',
            },
          },
          required: ['title', 'context', 'decision'],
        },
      },
    ];
  • Registration of all tools including decisionTools in the MCP server's ListToolsRequestHandler.
    server.setRequestHandler(ListToolsRequestSchema, async () => ({
      tools: [
        ...coreTools,
        ...progressTools,
        ...contextTools,
        ...decisionTools,
        ...modeTools,
      ],
    }));
  • Dispatch handler in the main tool call switch statement that validates arguments and calls handleLogDecision.
    case 'log_decision': {
      const progressTracker = getProgressTracker();
      if (!progressTracker) {
        return {
          content: [
            {
              type: 'text',
              text: 'Memory Bank not found. Use initialize_memory_bank to create one.',
            },
          ],
          isError: true,
        };
      }
    
      const { title, context, decision, alternatives, consequences } = request.params.arguments as {
        title: string;
        context: string;
        decision: string;
        alternatives?: string[] | string;
        consequences?: string[] | string;
      };
      if (!title || !context || !decision) {
        throw new McpError(
          ErrorCode.InvalidParams,
          'Title, context, and decision are required'
        );
      }
      return handleLogDecision(progressTracker, {
        title,
        context,
        decision,
        alternatives,
        consequences,
      });
    }

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/aakarsh-sasi/memory-bank-mcp'

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