Skip to main content
Glama

scan_contract

Analyze smart contracts for security vulnerabilities, exploit patterns, and rug-pull signals to assess risks before interacting with unfamiliar contracts.

Instructions

Analyze a smart contract's source code or bytecode for known exploit patterns, honeypot mechanics, rug-pull signals, and security vulnerabilities. Returns a risk score (0-100) and detailed findings. Use this BEFORE interacting with any unfamiliar contract.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sourceNoSolidity source code of the contract to analyze
bytecodeNoContract bytecode (hex) to analyze if source is unavailable
contractAddressNoContract address - if provided, will attempt to fetch source from block explorer
chainIdNoChain ID (1=Ethereum, 8453=Base, 84532=Base Sepolia)

Implementation Reference

  • Tool registration and handler definition for 'scan_contract'. It accepts source, bytecode, or a contract address, and calls the scanner engine.
    server.tool(
      "scan_contract",
      "Analyze a smart contract's source code or bytecode for known exploit patterns, honeypot mechanics, rug-pull signals, and security vulnerabilities. Returns a risk score (0-100) and detailed findings. Use this BEFORE interacting with any unfamiliar contract.",
      {
        source: z.string().optional().describe("Solidity source code of the contract to analyze"),
        bytecode: z.string().optional().describe("Contract bytecode (hex) to analyze if source is unavailable"),
        contractAddress: z.string().optional().describe("Contract address - if provided, will attempt to fetch source from block explorer"),
        chainId: z.number().default(1).describe("Chain ID (1=Ethereum, 8453=Base, 84532=Base Sepolia)"),
      },
      async ({ source, bytecode, contractAddress, chainId }) => {
        if (!source && !bytecode && !contractAddress) {
          return {
            content: [{
              type: "text" as const,
              text: JSON.stringify({
                error: "Provide at least one of: source, bytecode, or contractAddress",
              }),
            }],
          };
        }
    
        // If we have a contract address but no source/bytecode, try to fetch it
        if (contractAddress && !source && !bytecode) {
          const fetched = await fetchContractSource(contractAddress, chainId);
          if (fetched.source) source = fetched.source;
          if (fetched.bytecode) bytecode = fetched.bytecode;
        }
    
        let result;
        if (source) {
          result = scanContractSource(source);
        } else if (bytecode) {
          result = scanBytecode(bytecode);
        } else {
          return {
            content: [{
              type: "text" as const,
              text: JSON.stringify({
                error: "Could not fetch contract source or bytecode. Provide them directly.",
              }),
            }],
          };
        }
    
        return {
          content: [{
            type: "text" as const,
            text: JSON.stringify(result, null, 2),
          }],
        };
      },
    );
  • The core logic for scanning contract source code against exploit patterns.
    export function scanContractSource(source: string): ScanResult {
      const findings: ScanFinding[] = [];
    
      for (const pattern of EXPLOIT_PATTERNS) {
        if (!pattern.sourcePatterns) continue;
    
        for (const regex of pattern.sourcePatterns) {
          const match = source.match(regex);
          if (match) {
            // Avoid duplicate findings for the same pattern
            if (findings.some((f) => f.patternId === pattern.id)) continue;
    
            findings.push({
              patternId: pattern.id,
              patternName: pattern.name,
              severity: pattern.severity,
              description: pattern.description,
              riskWeight: pattern.riskWeight,
              matchedSnippet: match[0].slice(0, 100),
            });
            break; // One match per pattern is enough
          }
        }
      }
    
      return buildResult(findings);
    }
Behavior4/5

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

With no annotations provided, the description carries the full burden and does well by disclosing key behaviors: it analyzes for specific exploit patterns, returns a risk score and findings, and has a precautionary use case. However, it lacks details on rate limits, authentication needs, or error handling.

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, followed by usage guidance, all in two efficient sentences with zero wasted words, making it easy to parse quickly.

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 the tool's complexity (security analysis with 4 parameters) and no output schema, the description is mostly complete, covering purpose, usage, and output types. However, it could benefit from more details on behavioral aspects like performance or limitations to fully compensate for the lack of annotations and output schema.

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 schema already documents all parameters well. The description adds no additional parameter semantics beyond implying analysis can be done on source, bytecode, or via address, which is already covered in the schema. Baseline 3 is appropriate.

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 ('analyze', 'returns') and resources ('smart contract's source code or bytecode'), distinguishing it from siblings like 'assess_risk' or 'check_token' by focusing on contract analysis for security patterns.

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?

It explicitly states when to use this tool ('BEFORE interacting with any unfamiliar contract'), providing clear context and distinguishing it from alternatives like 'simulate_transaction' by focusing on pre-interaction analysis rather than simulation.

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