Skip to main content
Glama

aga_measure_subject

Measure digital content against sealed cryptographic references to verify integrity and generate signed receipts for tamper-evident logging.

Instructions

Measure subject state, compare to sealed reference. Generates signed receipt. (Claims 1e-1g)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
subject_contentNoRaw content to measure
subject_bytes_hashNoPre-computed SHA-256 bytes hash (64 hex)
subject_metadata_hashNoPre-computed SHA-256 metadata hash (64 hex)
subject_metadataNo

Implementation Reference

  • The handleMeasureSubject function processes subject measurement requests, performs drift detection, updates portal state, generates cryptographic receipts, and interacts with the continuity chain.
    export async function handleMeasureSubject(args: MeasureSubjectArgs, ctx: ServerContext) {
      if (!ctx.portal.artifact) return ctx.error('No artifact loaded. Call aga_create_artifact first.');
      if (ctx.portal.state === 'TERMINATED') return ctx.error('Portal is terminated. Re-attest required.');
      if (ctx.portal.state === 'SAFE_STATE') return ctx.error('Portal is in safe state. Re-attest required.');
    
      let currentBytesHash: string;
      let currentMetaHash: string;
      let match: boolean;
    
      if (args.subject_bytes_hash) {
        // Pre-computed hash mode
        currentBytesHash = args.subject_bytes_hash;
        currentMetaHash = args.subject_metadata_hash ?? ctx.portal.artifact.subject_identifier.metadata_hash;
        match = currentBytesHash === ctx.portal.artifact.subject_identifier.bytes_hash &&
                currentMetaHash === ctx.portal.artifact.subject_identifier.metadata_hash;
        if (!match && ctx.portal.state === 'ACTIVE_MONITORING') {
          (ctx.portal as any).state = 'DRIFT_DETECTED';
        }
      } else if (args.subject_content) {
        // Content mode - use portal.measure()
        const result = ctx.portal.measure(
          new TextEncoder().encode(args.subject_content),
          args.subject_metadata ?? {},
        );
        currentBytesHash = result.currentBytesHash;
        currentMetaHash = result.currentMetaHash;
        match = result.match;
        if (!result.ttl_ok) {
          ctx.measurementCount++;
          const receipt = generateReceipt({
            subjectId: ctx.portal.artifact.subject_identifier, artifactRef: hashArtifact(ctx.portal.artifact),
            currentHash: 'UNAVAILABLE', sealedHash: `${result.expectedBytesHash}||${result.expectedMetaHash}`,
            driftDetected: true, driftDescription: 'TTL expired - fail-closed termination', action: 'TERMINATE',
            measurementType: ctx.portal.artifact.enforcement_parameters.measurement_types.join(','),
            seq: ctx.portal.sequenceCounter + 1, prevLeaf: ctx.portal.lastLeafHash, portalKP: ctx.portalKP,
          });
          await ctx.storage.storeReceipt(receipt);
          await ctx.appendToChain('INTERACTION_RECEIPT', { receipt_id: receipt.receipt_id, drift_detected: true, enforcement_action: 'TERMINATE' });
          return ctx.json({ success: true, match: false, drift_detected: true, ttl_ok: false, revoked: false, enforcement_action: 'TERMINATE', portal_state: ctx.portal.state, receipt_id: receipt.receipt_id, measurement_count: ctx.measurementCount });
        }
        if (result.revoked) {
          ctx.measurementCount++;
          const receipt = generateReceipt({
            subjectId: ctx.portal.artifact.subject_identifier, artifactRef: hashArtifact(ctx.portal.artifact),
            currentHash: 'UNAVAILABLE', sealedHash: `${result.expectedBytesHash}||${result.expectedMetaHash}`,
            driftDetected: true, driftDescription: 'Artifact revoked - fail-closed termination', action: 'TERMINATE',
            measurementType: ctx.portal.artifact.enforcement_parameters.measurement_types.join(','),
            seq: ctx.portal.sequenceCounter + 1, prevLeaf: ctx.portal.lastLeafHash, portalKP: ctx.portalKP,
          });
          await ctx.storage.storeReceipt(receipt);
          await ctx.appendToChain('INTERACTION_RECEIPT', { receipt_id: receipt.receipt_id, drift_detected: true, enforcement_action: 'TERMINATE' });
          return ctx.json({ success: true, match: false, drift_detected: true, ttl_ok: true, revoked: true, enforcement_action: 'TERMINATE', portal_state: ctx.portal.state, receipt_id: receipt.receipt_id, measurement_count: ctx.measurementCount });
        }
      } else {
        return ctx.error('Provide either subject_content or subject_bytes_hash');
      }
    
      const artRef = hashArtifact(ctx.portal.artifact);
      const currentStr = `${currentBytesHash}||${currentMetaHash}`;
      const sealedStr = `${ctx.portal.artifact.subject_identifier.bytes_hash}||${ctx.portal.artifact.subject_identifier.metadata_hash}`;
    
      let action: EnforcementAction | null = null;
      let driftDesc: string | null = null;
    
      if (!match) {
        driftDesc = 'Subject modified - hash mismatch';
        action = ctx.portal.artifact.enforcement_parameters.enforcement_triggers[0] ?? 'ALERT_ONLY';
        if (ctx.portal.state === 'DRIFT_DETECTED') {
          ctx.portal.enforce(action);
        }
        if (action === 'QUARANTINE') ctx.quarantine = initQuarantine();
      }
    
      ctx.measurementCount++;
    
      const receipt = generateReceipt({
        subjectId: ctx.portal.artifact.subject_identifier,
        artifactRef: artRef,
        currentHash: currentStr,
        sealedHash: sealedStr,
        driftDetected: !match,
        driftDescription: driftDesc,
        action,
        measurementType: ctx.portal.artifact.enforcement_parameters.measurement_types.join(','),
        seq: ctx.portal.sequenceCounter + 1,
        prevLeaf: ctx.portal.lastLeafHash,
        portalKP: ctx.portalKP,
      });
      await ctx.storage.storeReceipt(receipt);
      await ctx.appendToChain('INTERACTION_RECEIPT', {
        receipt_id: receipt.receipt_id,
        drift_detected: !match,
        enforcement_action: action,
      });
    
      return ctx.json({
        success: true,
        match,
        drift_detected: !match,
        ttl_ok: true,
        revoked: false,
        enforcement_action: action,
        portal_state: ctx.portal.state,
        receipt_id: receipt.receipt_id,
        measurement_count: ctx.measurementCount,
      });
    }
  • The MeasureSubjectArgs interface defines the expected input schema for the aga_measure_subject tool.
    export interface MeasureSubjectArgs {
      subject_content?: string;
      subject_bytes_hash?: string;
      subject_metadata_hash?: string;
      subject_metadata?: SubjectMetadata;
    }
  • src/server.ts:122-137 (registration)
    Registration of the aga_measure_subject tool in the MCP server using governedTool middleware.
    // 4. aga_measure_subject (governed)
    governedTool('aga_measure_subject',
      'Measure subject state, compare to sealed reference. Generates signed receipt. (Claims 1e-1g)',
      {
        subject_content: z.string().optional().describe('Raw content to measure'),
        subject_bytes_hash: z.string().optional().describe('Pre-computed SHA-256 bytes hash (64 hex)'),
        subject_metadata_hash: z.string().optional().describe('Pre-computed SHA-256 metadata hash (64 hex)'),
        subject_metadata: z.object({
          filename: z.string().optional(),
          version: z.string().optional(),
          author: z.string().optional(),
          content_type: z.string().optional(),
        }).optional(),
      },
      async (args) => handleMeasureSubject({ ...args, subject_metadata: args.subject_metadata ?? {} }, ctx),
    );
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions generating a 'signed receipt' and references 'Claims 1e-1g', hinting at cryptographic or legal aspects, but lacks details on permissions, side effects, rate limits, or what the receipt contains. This is inadequate for a tool that appears to involve measurement and signing operations.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is concise and front-loaded with the core purpose in the first sentence. The second part ('Claims 1e-1g') is cryptic but brief. No wasted words, though it could be more informative given the tool's complexity.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's apparent complexity (involving measurement, comparison, and signed receipts), no annotations, no output schema, and incomplete parameter guidance, the description is insufficient. It doesn't explain what the 'sealed reference' is, how comparison works, what the receipt contains, or error conditions, leaving critical gaps for an AI agent to use it effectively.

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?

Schema description coverage is 75%, with clear descriptions for three parameters but minimal for 'subject_metadata' properties. The description adds no parameter-specific semantics beyond implying that inputs relate to a 'subject' for measurement. It doesn't clarify relationships between parameters (e.g., if 'subject_content' or hashes are required) or the purpose of metadata, leaving gaps despite decent schema coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Measure subject state, compare to sealed reference. Generates signed receipt.' It specifies the verb ('measure', 'compare', 'generates') and resource ('subject state'), but doesn't explicitly differentiate from siblings like 'aga_measure_behavior' or 'aga_trigger_measurement'. The mention of 'Claims 1e-1g' adds specificity but is cryptic without context.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance is provided on when to use this tool versus alternatives. The description mentions comparing to a 'sealed reference' and generating a 'signed receipt', which implies use for verification or attestation, but it doesn't specify prerequisites, exclusions, or direct alternatives among siblings like 'aga_verify_artifact' or 'aga_measure_behavior'.

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/attestedintelligence/aga-mcp-server'

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