Skip to main content
Glama

getNFTTokenURI

Retrieve the token URI for an ERC721 NFT by providing the contract address and token ID. This tool enables access to NFT metadata stored on-chain through the MCP Ethers Wallet server.

Input Schema

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

Implementation Reference

  • The core handler logic for the 'getNFTTokenURI' tool. It uses the EthersService to fetch ERC721 metadata for the given contract and token ID, extracts the token URI, and returns it in the MCP response format. Handles errors gracefully.
    async (params) => { try { // Get the metadata which includes the token URI const metadata = await ethersService.getERC721Metadata( params.contractAddress, params.tokenId, params.provider, params.chainId ); const uri = metadata.uri || ""; return { content: [{ type: "text", text: `Token URI for token ${params.tokenId} is ${uri}` }] }; } catch (error) { return { isError: true, content: [{ type: "text", text: `Error getting NFT token URI: ${error instanceof Error ? error.message : String(error)}` }] }; } }
  • TypeScript type definition for the input parameters of the getNFTTokenURI tool.
    type GetNFTTokenURIParams = { contractAddress: string; tokenId: string | number; provider?: string; chainId?: number; };
  • Zod-based input schema for validating parameters in the getNFTTokenURI tool registration.
    { contractAddress: contractAddressSchema.describe("The address of the ERC721 contract"), tokenId: tokenIdSchema.describe("The ID of the token to get the URI for"), 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.") },
  • Direct registration of the getNFTTokenURI tool with the MCP server via server.tool(), including schema and handler.
    server.tool( "getNFTTokenURI", { contractAddress: contractAddressSchema.describe("The address of the ERC721 contract"), tokenId: tokenIdSchema.describe("The ID of the token to get the URI for"), 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 { // Get the metadata which includes the token URI const metadata = await ethersService.getERC721Metadata( params.contractAddress, params.tokenId, params.provider, params.chainId ); const uri = metadata.uri || ""; return { content: [{ type: "text", text: `Token URI for token ${params.tokenId} is ${uri}` }] }; } catch (error) { return { isError: true, content: [{ type: "text", text: `Error getting NFT token URI: ${error instanceof Error ? error.message : String(error)}` }] }; } } );
  • Invocation of registerERC721Tools in the main tools index, which registers the getNFTTokenURI tool among other ERC721 tools.
    registerERC721Tools(server, ethersService);

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