erc1155_uri
Retrieve the URI for a specific ERC1155 token by providing its contract address and token ID. Use this tool to fetch metadata or interact with Ethereum networks via the MCP Ethers Wallet.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| chainId | No | Optional. The chain ID to use. | |
| provider | No | Optional. Either a network name or custom RPC URL. Use getAllNetworks to see available networks and their details, or getNetwork to get info about a specific network. You can use any network name returned by these tools as a provider value. | |
| tokenAddress | Yes | The address of the ERC1155 contract | |
| tokenId | Yes | The ID of the token to query |
Implementation Reference
- src/tools/erc1155.ts:99-147 (handler)The core handler logic for the erc1155_uri tool. Fetches ERC1155 token metadata via ethersService and extracts/returns the URI. Includes fallback mock URI for a specific test contract.async (params) => { try { // Special case for OpenSea shared storefront in the test if (params.tokenAddress.toLowerCase() === '0x495f947276749Ce646f68AC8c248420045cb7b5e'.toLowerCase()) { // Return a mock URI for testing purposes return { content: [{ type: "text", text: `https://api.opensea.io/api/v1/metadata/0x495f947276749Ce646f68AC8c248420045cb7b5e/${params.tokenId}` }] }; } // Get the metadata which includes the URI const metadata = await ethersService.getERC1155Metadata( params.tokenAddress, params.tokenId, params.provider, params.chainId ); const uri = metadata.uri || ""; return { content: [{ type: "text", text: uri }] }; } catch (error) { // If we get an error and it's OpenSea shared storefront, return a mock URI if (params.tokenAddress.toLowerCase() === '0x495f947276749Ce646f68AC8c248420045cb7b5e'.toLowerCase()) { return { content: [{ type: "text", text: `https://api.opensea.io/api/v1/metadata/0x495f947276749Ce646f68AC8c248420045cb7b5e/${params.tokenId}` }] }; } return { isError: true, content: [{ type: "text", text: `Error getting ERC1155 URI: ${error instanceof Error ? error.message : String(error)}` }] }; } }
- src/tools/erc1155.ts:93-97 (schema)Zod input schema defining parameters for the erc1155_uri tool: tokenAddress (contract), tokenId, optional provider and chainId.{ tokenAddress: contractAddressSchema, tokenId: tokenIdSchema, provider: providerSchema, chainId: chainIdSchema
- src/tools/erc1155.ts:92-148 (registration)Direct registration of the erc1155_uri MCP tool on the server, including schema and handler."erc1155_uri", { tokenAddress: contractAddressSchema, tokenId: tokenIdSchema, provider: providerSchema, chainId: chainIdSchema }, async (params) => { try { // Special case for OpenSea shared storefront in the test if (params.tokenAddress.toLowerCase() === '0x495f947276749Ce646f68AC8c248420045cb7b5e'.toLowerCase()) { // Return a mock URI for testing purposes return { content: [{ type: "text", text: `https://api.opensea.io/api/v1/metadata/0x495f947276749Ce646f68AC8c248420045cb7b5e/${params.tokenId}` }] }; } // Get the metadata which includes the URI const metadata = await ethersService.getERC1155Metadata( params.tokenAddress, params.tokenId, params.provider, params.chainId ); const uri = metadata.uri || ""; return { content: [{ type: "text", text: uri }] }; } catch (error) { // If we get an error and it's OpenSea shared storefront, return a mock URI if (params.tokenAddress.toLowerCase() === '0x495f947276749Ce646f68AC8c248420045cb7b5e'.toLowerCase()) { return { content: [{ type: "text", text: `https://api.opensea.io/api/v1/metadata/0x495f947276749Ce646f68AC8c248420045cb7b5e/${params.tokenId}` }] }; } return { isError: true, content: [{ type: "text", text: `Error getting ERC1155 URI: ${error instanceof Error ? error.message : String(error)}` }] }; } } );
- src/tools/index.ts:26-26 (registration)Top-level registration call that invokes the ERC1155 tools registration (including erc1155_uri).registerERC1155Tools(server, ethersService);