Skip to main content
Glama

azeth_get_weighted_reputation

Check an agent's on-chain reputation using USD-weighted ratings to assess trustworthiness before interactions. Returns weighted average based on rater payments.

Instructions

Get USD-weighted reputation for an agent from the on-chain ReputationModule.

Use this when: You want to check the reputation of an agent or service before interacting. Returns a weighted average where each rater's influence is proportional to their USD payment to the agent.

Returns: Weighted reputation with weightedValue (int256), totalWeight, and opinionCount.

Note: This is a read-only on-chain query. No private key or gas is required. Leave raters empty to aggregate across all raters who have submitted opinions.

Example: { "agentId": "1024" } or { "agentId": "1024", "raters": ["0x1234...abcd"] }

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
chainNoTarget chain. Defaults to AZETH_CHAIN env var or "baseSepolia". Accepts "base", "baseSepolia", "ethereumSepolia", "ethereum" (and aliases like "base-sepolia", "eth-sepolia", "sepolia", "eth", "mainnet").
agentIdYesTarget agent's ERC-8004 token ID (numeric string).
ratersNoSpecific rater addresses to include (optional). Empty = all raters.

Implementation Reference

  • The asynchronous handler function that executes the azeth_get_weighted_reputation tool, interacting with the ReputationModule contract via viem.
      async (args) => {
        const agentIdCheck = validateUint256(args.agentId, 'agentId');
        if (!agentIdCheck.valid) {
          return error('INVALID_INPUT', `${agentIdCheck.fieldName} exceeds maximum uint256 value`);
        }
    
        try {
          const { createPublicClient, http } = await import('viem');
    
          const resolved = resolveChain(args.chain);
          const chain = resolveViemChain(resolved);
          const rpcUrl = process.env[RPC_ENV_KEYS[resolved]] ?? SUPPORTED_CHAINS[resolved].rpcDefault;
    
          const publicClient = createPublicClient({
            chain,
            transport: http(rpcUrl),
          });
    
          const moduleAddress = AZETH_CONTRACTS[resolved].reputationModule;
          if (!moduleAddress || moduleAddress === ('' as `0x${string}`)) {
            return error('NETWORK_ERROR', `ReputationModule not deployed on ${resolved}.`, 'Deploy the ReputationModule first or switch to baseSepolia.');
          }
    
          // Check if the token ID exists on the trust registry before querying reputation
          const trustRegistryAddr = AZETH_CONTRACTS[resolved].trustRegistryModule;
          if (trustRegistryAddr && trustRegistryAddr !== ('' as `0x${string}`)) {
            try {
              const accountAddr = await publicClient.readContract({
                address: trustRegistryAddr,
                abi: TrustRegistryModuleAbi,
                functionName: 'getAccountByTokenId',
                args: [agentIdCheck.bigint],
              });
              if (accountAddr === '0x0000000000000000000000000000000000000000') {
                return success({
                  agentId: args.agentId,
                  weightedValue: '0',
                  totalWeight: '0',
                  opinionCount: '0',
                  warning: `No agent registered with token ID ${args.agentId}. The returned zeros indicate no registration, not a zero reputation.`,
                });
              }
            } catch {
              // getAccountByTokenId may not exist on older deployments — proceed with query
            }
          }
    
          const raterAddrs = args.raters
            .filter((a): a is `0x${string}` => /^0x[0-9a-fA-F]{40}$/.test(a));
    
          let result: readonly [bigint, bigint, bigint];
    
          if (raterAddrs.length > 0) {
            result = await publicClient.readContract({
              address: moduleAddress,
              abi: ReputationModuleAbi,
              functionName: 'getWeightedReputation',
              args: [agentIdCheck.bigint, raterAddrs],
            }) as readonly [bigint, bigint, bigint];
          } else {
            result = await publicClient.readContract({
              address: moduleAddress,
              abi: ReputationModuleAbi,
              functionName: 'getWeightedReputationAll',
              args: [agentIdCheck.bigint],
            }) as readonly [bigint, bigint, bigint];
          }
    
          const [weightedValue, totalWeight, opinionCount] = result;
    
          // Format weighted value: the contract returns values in the same decimal precision
          // as the submitted opinions. For the default MCP submission (valueDecimals=0), this
          // is an integer. For SDK submissions with 18 decimals, format accordingly.
          // Heuristic: if |value| > 10^15, it's likely 18-decimal; otherwise treat as integer.
          const absValue = weightedValue < 0n ? -weightedValue : weightedValue;
          const isHighPrecision = absValue > 10n ** 15n;
          const weightedValueFormatted = isHighPrecision
            ? formatTokenAmount(weightedValue, 18, 4)
            : weightedValue.toString();
    
          // totalWeight is a dampened dimensionless value: sum of pow2over3(netPaidUSD) across raters.
          // It is NOT USD — do not format as currency. Display as a plain number.
          const totalWeightFormatted = formatTokenAmount(totalWeight, 12, 2);
    
          return success({
            agentId: args.agentId,
            weightedValue: weightedValue.toString(),
            weightedValueFormatted,
            totalWeight: totalWeight.toString(),
            totalWeightFormatted,
            totalWeightDescription: 'Aggregate economic skin-in-the-game (higher = more payments behind opinions)',
            opinionCount: opinionCount.toString(),
            ratersFilter: raterAddrs.length > 0 ? raterAddrs : '(all raters)',
          });
        } catch (err) {
          return handleError(err);
        }
      },
    );
  • Input validation schema for azeth_get_weighted_reputation tool.
      inputSchema: z.object({
        chain: z.string().optional().describe('Target chain. Defaults to AZETH_CHAIN env var or "baseSepolia". Accepts "base", "baseSepolia", "ethereumSepolia", "ethereum" (and aliases like "base-sepolia", "eth-sepolia", "sepolia", "eth", "mainnet").'),
        agentId: z.string().regex(/^\d+$/, 'Must be a non-negative integer string').describe('Target agent\'s ERC-8004 token ID (numeric string).'),
        raters: z.preprocess(
          (val) => typeof val === 'string' ? JSON.parse(val) : val,
          z.array(
            z.string().regex(/^0x[0-9a-fA-F]{40}$/, 'Each rater must be a valid Ethereum address'),
          ).default([]),
        ).describe('Specific rater addresses to include (optional). Empty = all raters.'),
      }),
    },
  • Registration of the azeth_get_weighted_reputation tool with the server.
    server.registerTool(
      'azeth_get_weighted_reputation',
      {
        description: [
          'Get USD-weighted reputation for an agent from the on-chain ReputationModule.',
          '',
          'Use this when: You want to check the reputation of an agent or service before interacting.',
          'Returns a weighted average where each rater\'s influence is proportional to their USD payment to the agent.',
          '',
          'Returns: Weighted reputation with weightedValue (int256), totalWeight, and opinionCount.',
          '',
          'Note: This is a read-only on-chain query. No private key or gas is required.',
          'Leave raters empty to aggregate across all raters who have submitted opinions.',
          '',
          'Example: { "agentId": "1024" } or { "agentId": "1024", "raters": ["0x1234...abcd"] }',
        ].join('\n'),
        inputSchema: z.object({
          chain: z.string().optional().describe('Target chain. Defaults to AZETH_CHAIN env var or "baseSepolia". Accepts "base", "baseSepolia", "ethereumSepolia", "ethereum" (and aliases like "base-sepolia", "eth-sepolia", "sepolia", "eth", "mainnet").'),
          agentId: z.string().regex(/^\d+$/, 'Must be a non-negative integer string').describe('Target agent\'s ERC-8004 token ID (numeric string).'),
          raters: z.preprocess(
            (val) => typeof val === 'string' ? JSON.parse(val) : val,
            z.array(
              z.string().regex(/^0x[0-9a-fA-F]{40}$/, 'Each rater must be a valid Ethereum address'),
            ).default([]),
          ).describe('Specific rater addresses to include (optional). Empty = all raters.'),
        }),
      },
Behavior5/5

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

No annotations are provided, yet the description fully compensates by disclosing: (1) safety profile ('read-only', 'No private key or gas required'), (2) calculation methodology ('weighted average where each rater's influence is proportional to their USD payment'), (3) return value structure ('weightedValue (int256), totalWeight, and opinionCount'), and (4) filtering behavior for empty raters array.

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?

Well-structured with clear logical sections: purpose, usage trigger, return semantics, behavioral note, parameter guidance, and examples. Every sentence conveys unique information. Examples are appropriately placed at the end without cluttering the core description.

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?

Comprehensive for a read query tool. Since no output schema exists, the description commendably documents the return structure (int256 values, counts). It compensates for missing annotations with safety disclosures. Minor gap: it doesn't mention the chain parameter's default behavior (though the schema covers this thoroughly).

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

Parameters4/5

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

Schema coverage is 100%, establishing a baseline of 3. The description adds valuable semantic context beyond the schema: it explains the default behavior when raters is empty ('Leave raters empty to aggregate across all raters'), and provides concrete JSON examples showing both minimal and full parameter usage patterns. Slight deduction as it doesn't augment the chain parameter semantics beyond the schema.

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 opens with a precise action (Get) + specific resource (USD-weighted reputation) + source (on-chain ReputationModule). It clearly distinguishes this from sibling tools like azeth_get_active_opinion or azeth_get_net_paid by specifying the unique USD-weighted calculation methodology.

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

Usage Guidelines4/5

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

Provides explicit 'Use this when' guidance ('check the reputation of an agent or service before interacting'), which establishes clear intent. However, it lacks explicit 'when not to use' guidance or named alternatives (e.g., when to prefer azeth_get_active_opinion instead).

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/azeth-protocol/mcp-azeth'

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