Skip to main content
Glama

getNFTInfo

Retrieve basic details about an ERC721 NFT collection, including name, symbol, and total supply, by providing the contract address.

Instructions

Get information about an ERC721 NFT collection including its name, symbol, and total supply. Provides basic details about the NFT contract.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
contractAddressYesThe address of the ERC721 contract
providerNoOptional. The provider to use. If not provided, the default provider is used.
chainIdNoOptional. The chain ID to use.

Implementation Reference

  • The MCP tool handler function that executes the getNFTInfo tool logic. Fetches NFT collection information using ethersService and returns a formatted text response or error.
        async (params) => {
          try {
            const info = await ethersService.getERC721CollectionInfo(
              params.contractAddress,
              params.provider,
              params.chainId
            );
            
            return {
              content: [{ 
                type: "text", 
                text: `NFT Information:
    Name: ${info.name}
    Symbol: ${info.symbol}
    Total Supply: ${info.totalSupply}`
              }]
            };
          } catch (error) {
            return {
              isError: true,
              content: [{ 
                type: "text", 
                text: `Error getting NFT information: ${error instanceof Error ? error.message : String(error)}`
              }]
            };
          }
        }
  • Registration of the getNFTInfo tool with the MCP server inside registerERC721Tools function, including name, description, input schema, and handler reference.
      server.tool(
        "getNFTInfo",
        "Get information about an ERC721 NFT collection including its name, symbol, and total supply. Provides basic details about the NFT contract.",
        {
          contractAddress: contractAddressSchema.describe("The address of the ERC721 contract"),
          provider: providerSchema.describe("Optional. The provider to use. If not provided, the default provider is used."),
          chainId: chainIdSchema.describe("Optional. The chain ID to use.")
        },
        async (params) => {
          try {
            const info = await ethersService.getERC721CollectionInfo(
              params.contractAddress,
              params.provider,
              params.chainId
            );
            
            return {
              content: [{ 
                type: "text", 
                text: `NFT Information:
    Name: ${info.name}
    Symbol: ${info.symbol}
    Total Supply: ${info.totalSupply}`
              }]
            };
          } catch (error) {
            return {
              isError: true,
              content: [{ 
                type: "text", 
                text: `Error getting NFT information: ${error instanceof Error ? error.message : String(error)}`
              }]
            };
          }
        }
      );
  • Input schema for the getNFTInfo tool using Zod schemas for contractAddress, provider, and chainId.
    {
      contractAddress: contractAddressSchema.describe("The address of the ERC721 contract"),
      provider: providerSchema.describe("Optional. The provider to use. If not provided, the default provider is used."),
      chainId: chainIdSchema.describe("Optional. The chain ID to use.")
    },
  • Supporting helper function getNFTInfo that retrieves basic ERC721 collection information (name, symbol, totalSupply) with rate limiting, caching, error handling, and metrics. Used internally by ethersService.getERC721CollectionInfo.
    export async function getNFTInfo(
      ethersService: EthersService,
      contractAddress: string,
      provider?: string,
      chainId?: number
    ): Promise<ERC721Info> {
      metrics.incrementCounter('erc721.getNFTInfo');
      
      return timeAsync('erc721.getNFTInfo', async () => {
        try {
          // Check rate limiting
          const identity = `${contractAddress}:${provider || 'default'}`;
          if (!rateLimiter.consume('token', identity)) {
            throw new ERC721Error('Rate limit exceeded for NFT operations');
          }
          
          // Create cache key
          const cacheKey = createTokenCacheKey(
            CACHE_KEYS.ERC721_INFO,
            contractAddress,
            chainId
          );
          
          // Check cache first
          const cachedInfo = contractCache.get(cacheKey);
          if (cachedInfo) {
            return cachedInfo as ERC721Info;
          }
          
          // Get provider from ethers service
          const ethersProvider = ethersService['getProvider'](provider, chainId);
          
          // Check if address is contract
          const code = await ethersProvider.getCode(contractAddress);
          if (code === '0x' || code === '0x0') {
            throw new TokenNotFoundError(contractAddress);
          }
          
          // Create contract instance
          const contract = new ethers.Contract(contractAddress, ERC721_ABI, ethersProvider);
          
          // Fetch NFT information - some contracts might not implement all methods
          let name = '';
          let symbol = '';
          let totalSupply: string | undefined = undefined;
          
          try {
            name = await contract.name();
          } catch (error) {
            logger.debug('Error getting NFT name', { contractAddress, error });
            name = 'Unknown Collection';
          }
          
          try {
            symbol = await contract.symbol();
          } catch (error) {
            logger.debug('Error getting NFT symbol', { contractAddress, error });
            symbol = 'NFT';
          }
          
          try {
            // totalSupply is optional in ERC721
            const supplyBigInt = await contract.totalSupply();
            totalSupply = supplyBigInt.toString();
          } catch (error) {
            // totalSupply function is not required in ERC721, so ignore errors
            logger.debug('NFT contract does not implement totalSupply', { contractAddress });
          }
          
          // Format data
          const nftInfo: ERC721Info = {
            name,
            symbol,
            totalSupply
          };
          
          // Cache result for future use (1 hour TTL)
          contractCache.set(cacheKey, nftInfo, { ttl: 3600000 });
          
          return nftInfo;
        } catch (error) {
          logger.debug('Error getting ERC721 NFT info', { contractAddress, error });
          
          if (error instanceof TokenNotFoundError) {
            throw error;
          }
          
          throw handleTokenError(error, 'Failed to get NFT collection information');
        }
      });
    }
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. While it states this is a read operation ('Get information'), it doesn't mention important behavioral aspects like whether this requires network access, potential rate limits, error conditions, or what format the returned information takes. For a tool that presumably queries blockchain data, this lack of behavioral context is significant.

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 appropriately concise with two sentences that efficiently convey the core functionality. The first sentence states the purpose and key data returned, while the second provides additional context about the type of contract. There's no unnecessary verbiage, though it could be slightly more structured to separate purpose from behavioral context.

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 complexity (blockchain data retrieval), lack of annotations, and absence of an output schema, the description is insufficiently complete. It doesn't explain what specific information is returned beyond mentioning 'name, symbol, and total supply,' nor does it address error handling, network requirements, or how the optional parameters affect behavior. For a tool with no structured output definition, more descriptive completeness is needed.

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?

The description adds no parameter-specific information beyond what's already in the schema. With 100% schema description coverage, all three parameters (contractAddress, provider, chainId) are already documented in the input schema. The description doesn't provide additional context about parameter usage, relationships between parameters, or examples of valid values beyond what the schema provides.

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: 'Get information about an ERC721 NFT collection including its name, symbol, and total supply.' It specifies the verb ('Get'), resource ('ERC721 NFT collection'), and key data fields. However, it doesn't explicitly distinguish this tool from similar siblings like 'getNFTMetadata' or 'getERC20TokenInfo', which reduces clarity about when to choose this specific tool.

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?

The description provides no guidance on when to use this tool versus alternatives. With siblings like 'getNFTMetadata', 'getNFTOwner', and 'getNFTTokenURI' available, there's no indication of what makes this tool unique or when it should be preferred over those other NFT-related tools. The description only states what it does, not when to use it.

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/crazyrabbitLTC/mcp-ethers-server'

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