query-mon-nft
Retrieve detailed NFT information from the Monad testnet by providing the contract address and token ID, enabling seamless integration with AI models for blockchain interactions.
Instructions
Query NFT information on Monad testnet
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| contractAddress | Yes | NFT contract address | |
| tokenId | Yes | Token ID of the NFT |
Input Schema (JSON Schema)
{
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"contractAddress": {
"description": "NFT contract address",
"type": "string"
},
"tokenId": {
"description": "Token ID of the NFT",
"type": "string"
}
},
"required": [
"contractAddress",
"tokenId"
],
"type": "object"
}
Implementation Reference
- src/tools/nft/query.ts:27-67 (handler)Core execution logic of the 'query-mon-nft' tool. Queries ERC721 ownerOf and tokenURI using viem publicClient on Monad testnet, returns formatted text response or error.async ({ contractAddress, tokenId }) => { try { // Create contract instance const contract = { address: contractAddress as `0x${string}`, abi: ERC721_ABI, }; // Get owner and token URI const [owner, tokenUri] = await Promise.all([ publicClient.readContract({ ...contract, functionName: 'ownerOf', args: [BigInt(tokenId)], }), publicClient.readContract({ ...contract, functionName: 'tokenURI', args: [BigInt(tokenId)], }), ]); return { content: [ { type: "text", text: `NFT Information:\nContract: ${contractAddress}\nToken ID: ${tokenId}\nOwner: ${owner}\nToken URI: ${tokenUri}`, }, ], }; } catch (error) { return { content: [ { type: "text", text: `Failed to query NFT information. Error: ${error instanceof Error ? error.message : String(error)}`, }, ], }; } }
- src/tools/nft/query.ts:23-26 (schema)Zod-based input schema for the tool parameters: contractAddress and tokenId.{ contractAddress: z.string().describe("NFT contract address"), tokenId: z.string().describe("Token ID of the NFT"), },
- src/tools/nft/query.ts:19-69 (registration)Registers the 'query-mon-nft' tool with the MCP server, specifying name, description, input schema, and handler function.export function nftQueryProvider(server: McpServer) { server.tool( "query-mon-nft", "Query NFT information on Monad testnet", { contractAddress: z.string().describe("NFT contract address"), tokenId: z.string().describe("Token ID of the NFT"), }, async ({ contractAddress, tokenId }) => { try { // Create contract instance const contract = { address: contractAddress as `0x${string}`, abi: ERC721_ABI, }; // Get owner and token URI const [owner, tokenUri] = await Promise.all([ publicClient.readContract({ ...contract, functionName: 'ownerOf', args: [BigInt(tokenId)], }), publicClient.readContract({ ...contract, functionName: 'tokenURI', args: [BigInt(tokenId)], }), ]); return { content: [ { type: "text", text: `NFT Information:\nContract: ${contractAddress}\nToken ID: ${tokenId}\nOwner: ${owner}\nToken URI: ${tokenUri}`, }, ], }; } catch (error) { return { content: [ { type: "text", text: `Failed to query NFT information. Error: ${error instanceof Error ? error.message : String(error)}`, }, ], }; } } ); }
- src/tools/nft/query.ts:11-14 (helper)ERC721 ABI fragments required for the contract read operations in the handler.const ERC721_ABI = parseAbi([ 'function ownerOf(uint256 tokenId) external view returns (address)', 'function tokenURI(uint256 tokenId) external view returns (string)', ]);
- src/tools/nft/index.ts:4-7 (registration)Wrapper provider function for NFT tools that calls the specific query provider to register the tool.export function nftProvider(server: McpServer) { nftQueryProvider(server); }