Skip to main content
Glama

chain_of_reasoning

Read-onlyIdempotent

Reconstructs the complete chain of reasoning for any governed session, agent, or time range, returning causally ordered links with hash-chain verification. Supports summary, full, DAG, or EU AI Act compliance export.

Instructions

Reconstruct the complete Chain of Reasoning for a governed session, agent, or time range. Returns every link — AI Brain state, deliberation steps, precedent cited, gate decisions, knowledge packs, merit assessments — in causal order with hash-chain verification. Use "summary" format for a quick overview, "full" for all links, "dag" for the causal graph, or "export" for an EU AI Act compliance artifact.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
scopeYesWhat to query: "session" for a specific committee session, "agent" for an agent over time, "time_range" for all activity in a period.
session_idNoCommittee session ID (required when scope = "session"). Format: cs-{uuid}
agent_idNoAgent ID (required when scope = "agent"). Can be a user ID or model name.
startNoStart of time range (ISO 8601). Default: 7 days ago.
endNoEnd of time range (ISO 8601). Default: now.
formatNoResponse format: "summary" = stats only, "full" = all links, "dag" = causal graph with edges, "export" = EU AI Act compliance artifact.summary
limitNoMaximum number of links to return (default: 100, max: 500). Only applies to "full" format.

Implementation Reference

  • The handler function executed when the chain_of_reasoning tool is called. It constructs API URLs based on scope (session/agent/time_range) and format (summary/full/dag/export), fetches data from the Chain of Reasoning backend API, and returns the results with error handling.
      async (input) => {
        const apiBase = process.env.GIA_API_URL || 'http://localhost:3001';
        // GIA_INTERNAL_API_KEY = server-side name; GIA_API_KEY = MCP container name (same value)
        const apiKey = process.env.GIA_INTERNAL_API_KEY || process.env.GIA_API_KEY || '';
    
        try {
          let url: string;
          const params = new URLSearchParams();
    
          if (input.scope === 'session') {
            if (!input.session_id) {
              return { content: [{ type: 'text' as const, text: JSON.stringify({ error: 'session_id required when scope = "session"' }) }] };
            }
    
            if (input.format === 'dag') {
              url = `${apiBase}/api/chain-of-reasoning/session/${input.session_id}/dag`;
            } else if (input.format === 'export') {
              url = `${apiBase}/api/chain-of-reasoning/session/${input.session_id}/export`;
            } else {
              url = `${apiBase}/api/chain-of-reasoning/session/${input.session_id}`;
            }
          } else if (input.scope === 'agent') {
            if (!input.agent_id) {
              return { content: [{ type: 'text' as const, text: JSON.stringify({ error: 'agent_id required when scope = "agent"' }) }] };
            }
            url = `${apiBase}/api/chain-of-reasoning/agent/${encodeURIComponent(input.agent_id)}`;
            if (input.start) params.set('start', input.start);
            if (input.end) params.set('end', input.end);
            if (input.limit) params.set('limit', String(input.limit));
          } else {
            url = `${apiBase}/api/chain-of-reasoning/time-range`;
            if (input.start) params.set('start', input.start);
            if (input.end) params.set('end', input.end);
            if (input.limit) params.set('limit', String(input.limit));
          }
    
          const queryString = params.toString();
          const fullUrl = queryString ? `${url}?${queryString}` : url;
    
          const resp = await fetch(fullUrl, {
            headers: {
              'Authorization': `Bearer ${apiKey}`,
              'Content-Type': 'application/json',
            },
          });
    
          if (!resp.ok) {
            const body = await resp.text();
            return {
              content: [{ type: 'text' as const, text: JSON.stringify({
                error: `Chain of Reasoning query failed (HTTP ${resp.status})`,
                detail: body,
              }) }],
            };
          }
    
          const data = await resp.json() as Record<string, unknown>;
    
          // For summary format, strip the full links array to reduce token usage
          if (input.format === 'summary' && data.links) {
            const links = data.links as Array<Record<string, unknown>>;
            data.linksPreview = links.slice(0, 5).map(l => ({
              operation: l.operation,
              timestamp: l.timestamp,
              actor: l.actor,
              maiLevel: l.maiLevel,
            }));
            delete data.links;
          }
    
          return {
            content: [{ type: 'text' as const, text: JSON.stringify(data, null, 2) }],
          };
        } catch (err: unknown) {
          return {
            content: [{ type: 'text' as const, text: JSON.stringify({
              error: 'Chain of Reasoning query failed',
              detail: (err as Error).message,
            }) }],
          };
        }
      },
    );
  • Zod schema defining the tool's input parameters: scope (session/agent/time_range), session_id, agent_id, start, end, format (summary/full/dag/export), and limit. Also includes metadata hints (readOnly, idempotent).
    {
      scope: z.enum(['session', 'agent', 'time_range']).describe(
        'What to query: "session" for a specific committee session, "agent" for an agent over time, "time_range" for all activity in a period.'
      ),
      session_id: z.string().optional().describe(
        'Committee session ID (required when scope = "session"). Format: cs-{uuid}'
      ),
      agent_id: z.string().optional().describe(
        'Agent ID (required when scope = "agent"). Can be a user ID or model name.'
      ),
      start: z.string().optional().describe(
        'Start of time range (ISO 8601). Default: 7 days ago.'
      ),
      end: z.string().optional().describe(
        'End of time range (ISO 8601). Default: now.'
      ),
      format: z.enum(['summary', 'full', 'dag', 'export']).default('summary').describe(
        'Response format: "summary" = stats only, "full" = all links, "dag" = causal graph with edges, "export" = EU AI Act compliance artifact.'
      ),
      limit: z.number().int().min(1).max(500).optional().describe(
        'Maximum number of links to return (default: 100, max: 500). Only applies to "full" format.'
      ),
    },
  • The registerChainOfReasoningTools function that registers the tool with the MCP server via server.tool('chain_of_reasoning', ...).
    export function registerChainOfReasoningTools(server: McpServer, _engine: GovernanceEngine): void {
      server.tool(
        'chain_of_reasoning',
  • Registration entry in the TOOL_REGISTRY array that maps chain_of_reasoning to the 'tenant' visibility tier, meaning it's accessible to paying customers but not public.
    { tier: 'tenant', register: registerChainOfReasoningTools, description: 'chain_of_reasoning (Governed Cognition provenance trail)' },
Behavior4/5

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

Annotations already declare readOnlyHint=true, destructiveHint=false, and idempotentHint=true, so the agent knows it's a safe read operation. The description adds that results are returned in causal order with hash-chain verification, providing valuable behavioral context beyond annotations.

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 sentences long with no redundant information. The first sentence states the main purpose and outputs, the second details format options. Every word contributes to understanding, making it concise and well-structured.

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?

Given no output schema, the description partially covers the output by mentioning 'every link' and the specific elements returned. It could be more complete by describing the response structure or pagination (though limit parameter addresses the latter). Overall, it provides sufficient context for an intelligent agent.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100%, and the description adds significant value to parameters, especially the 'format' enum by explaining each option: 'summary' for overview, 'full' for all links, 'dag' for causal graph, 'export' for EU AI Act compliance artifact. This enriches the schema definitions with real-world use cases.

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 reconstructs the complete Chain of Reasoning for a session, agent, or time range. It lists the exact elements returned and format options, making its purpose unambiguous. It distinguishes itself from sibling tools like audit_pipeline or export_ledger by focusing on causal order and hash-chain verification.

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 explains how to use different formats ('summary', 'full', 'dag', 'export') but does not explicitly guide when to choose this tool over siblings. It lacks explicit when-to-use or when-not-to-use guidance, leaving the agent to infer based on the tool's purpose.

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/knowledgepa3/gia-mcp-server'

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