Skip to main content
Glama

assess_risk

Analyze DeFi transaction safety by scanning contracts, simulating outcomes, and checking tokens to provide go/no-go recommendations before interactions.

Instructions

Comprehensive risk assessment combining contract scanning, transaction simulation, and token checks. This is the recommended all-in-one safety check before any DeFi interaction. Returns a go/no-go recommendation.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
actionYesType of action being assessed
targetContractYesThe contract being interacted with
chainIdNoChain ID
fromYesThe agent's wallet address
transactionDataNoCalldata for the transaction (hex)
valueNoETH value (in wei)0
tokenAddressNoToken address if this involves a token swap

Implementation Reference

  • The handler function for the `assess_risk` tool. It orchestrates contract scanning, transaction simulation, and token safety checks to generate a final risk assessment and attestation.
    server.tool(
      "assess_risk",
      "Comprehensive risk assessment combining contract scanning, transaction simulation, and token checks. This is the recommended all-in-one safety check before any DeFi interaction. Returns a go/no-go recommendation.",
      {
        action: z.enum(["swap", "approve", "transfer", "interact"]).describe("Type of action being assessed"),
        targetContract: z.string().describe("The contract being interacted with"),
        chainId: z.number().default(1).describe("Chain ID"),
        from: z.string().describe("The agent's wallet address"),
        transactionData: z.string().optional().describe("Calldata for the transaction (hex)"),
        value: z.string().default("0").describe("ETH value (in wei)"),
        tokenAddress: z.string().optional().describe("Token address if this involves a token swap"),
      },
      async ({ action, targetContract, chainId, from, transactionData, value, tokenAddress }) => {
        const checks: Record<string, any> = {};
    
        // 1. Scan the contract
        const fetched = await fetchContractSource(targetContract, chainId);
        if (fetched.source) {
          checks.contractScan = scanContractSource(fetched.source);
        } else if (fetched.bytecode) {
          checks.contractScan = scanBytecode(fetched.bytecode);
        }
    
        // 2. Simulate the transaction if we have calldata
        if (transactionData) {
          checks.simulation = await simulateTransaction({
            chainId,
            from: from as Address,
            to: targetContract as Address,
            data: transactionData as Hex,
            value: BigInt(value),
          });
          // Convert bigint for JSON serialization
          if (checks.simulation) {
            checks.simulation.gasUsed = checks.simulation.gasUsed.toString();
          }
        }
    
        // 3. Check token safety if relevant
        if (tokenAddress) {
          checks.tokenSafety = await checkTokenSellability(
            chainId,
            tokenAddress as Address,
            from as Address,
          );
        }
    
        // 4. Compute overall risk
        let overallRisk = 0;
        const risks: string[] = [];
    
        if (checks.contractScan) {
          overallRisk = Math.max(overallRisk, checks.contractScan.riskScore);
          if (checks.contractScan.riskScore >= 70) risks.push("contract_high_risk");
        }
    
        if (checks.simulation && !checks.simulation.success) {
          overallRisk = Math.max(overallRisk, 80);
          risks.push("transaction_reverts");
        }
    
        if (checks.simulation?.gasAnomaly) {
          overallRisk = Math.max(overallRisk, 60);
          risks.push("gas_anomaly");
        }
    
        if (checks.tokenSafety && !checks.tokenSafety.canSell) {
          overallRisk = Math.max(overallRisk, 90);
          risks.push("cannot_sell_token");
        }
    
        const decision = overallRisk >= 70 ? "BLOCK" : overallRisk >= 40 ? "WARN" : "ALLOW";
    
        // If not blocked, sign an attestation for on-chain verification
        let attestation: Record<string, string> | undefined;
        if (decision !== "BLOCK") {
          try {
            const selector = transactionData ? transactionData.slice(0, 10) as Hex : "0x00000000" as Hex;
            const att = await signAttestation({
              agent: from as Address,
              target: targetContract as Address,
              selector,
              riskScore: overallRisk,
            });
            attestation = {
              attestationId: att.attestationId,
              agent: att.agent,
              target: att.target,
              selector: att.selector,
              riskScore: att.riskScore.toString(),
              expiresAt: att.expiresAt.toString(),
              signature: att.signature,
            };
          } catch {
            // Attester key not configured - attestation unavailable
            // MCP-only mode still works (agent gets the risk assessment)
          }
        }
    
        return {
          content: [{
            type: "text" as const,
            text: JSON.stringify({
              decision,
              overallRiskScore: overallRisk,
              riskFactors: risks,
              action,
              checks,
              attestation,
              recommendation: decision === "BLOCK"
                ? "DO NOT proceed with this transaction. High risk of fund loss."
                : decision === "WARN"
                ? "Proceed with caution. Some risk indicators detected."
                : "Transaction appears safe. Proceed normally.",
            }, null, 2),
          }],
        };
      },
    );
Behavior3/5

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

With no annotations provided, the description carries full burden. It discloses the tool's comprehensive nature and returns a 'go/no-go recommendation', but lacks details on permissions, rate limits, or potential side effects. It adequately describes the core behavior but misses deeper operational context.

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 front-loaded with the core purpose in the first sentence, uses two efficient sentences total with zero wasted words, and clearly communicates the tool's value proposition and recommendation status without redundancy.

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?

For a complex 7-parameter tool with no annotations and no output schema, the description is reasonably complete. It explains the tool's integrative nature, when to use it, and the output type ('go/no-go recommendation'), though it could elaborate more on behavioral risks or error handling.

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 100%, so the baseline is 3. The description adds no specific parameter details beyond what the schema provides, but it contextualizes the inputs as part of a 'comprehensive risk assessment' for DeFi safety checks, which slightly enhances understanding.

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's purpose with specific verbs ('combining contract scanning, transaction simulation, and token checks') and resources ('DeFi interaction'), and distinguishes it from sibling tools by positioning it as the 'recommended all-in-one safety check' that integrates their functions.

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

Usage Guidelines5/5

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

The description explicitly states when to use this tool ('before any DeFi interaction') and implies alternatives by naming sibling tools (check_token, scan_contract, simulate_transaction) as components it combines, making it the comprehensive choice over piecemeal approaches.

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/StanleytheGoat/aegis'

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