resolve-name
Convert ENS names to Ethereum addresses with the ENS MCP Server, enabling accurate and direct resolution of blockchain identities for decentralized applications and transactions.
Instructions
Resolve an ENS name to an Ethereum address
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | The ENS name to resolve (e.g., 'vitalik.eth') |
Implementation Reference
- utils/index.ts:71-100 (handler)The core handler function that resolves an ENS name to an Ethereum address using publicClient.getAddressRecord({name, coin: 'ETH'}), normalizes the name, handles errors with handleEnsError, and returns a formatted ServerResponse.export async function resolveName( { name }: { name: string } ): Promise<ServerResponse> { const normalizedName = normalizeName(name); try { const result = await publicClient.getAddressRecord({ name:normalizedName, coin: 'ETH' }); if (!result) { return { content: [{ type: "text", text: `Could not resolve ${normalizedName} to an address.` }], isError: false }; } return { content: [{ type: "text", text: `The address for ${normalizedName} is ${result.value}` }], isError: false }; } catch (error) { const errorMessage = handleEnsError(error, "name resolution"); return { content: [{ type: "text", text: errorMessage }], isError: true }; } }
- index.ts:26-35 (registration)Registers the 'resolve-name' tool on the MCP server, providing description, input schema (name: string), and handler that calls resolveName.server.tool( "resolve-name", "Resolve an ENS name to an Ethereum address", { name: z.string().describe("The ENS name to resolve (e.g., 'vitalik.eth')"), }, async (params) => { return await resolveName(params); } );
- index.ts:29-31 (schema)Zod schema for the tool input: a string parameter 'name' for the ENS name.{ name: z.string().describe("The ENS name to resolve (e.g., 'vitalik.eth')"), },
- utils/index.ts:17-17 (helper)Helper function to normalize ENS name by appending '.eth' if missing, used in resolveName.const normalizeName = (name: string) => name.endsWith('.eth') ? name : `${name}.eth`;
- utils/index.ts:19-54 (helper)Helper function to handle and format ENS-related errors, used in the catch block of resolveName.export function handleEnsError(error: unknown, operation: string): string { console.error(`Error during ENS ${operation}:`, error); let errorMessage = ""; if (error instanceof Error) { errorMessage = error.message; if ( errorMessage.includes("fetch failed") || errorMessage.includes("timeout") || errorMessage.includes("network") || errorMessage.includes("HTTP request failed") ) { return `Network error while accessing Ethereum providers. Please check your internet connection or try again later. Technical details: ${errorMessage}`; } if (errorMessage.includes("ENS")) { return `ENS error: ${errorMessage}`; } if ( errorMessage.includes("invalid") || errorMessage.includes("parameter") ) { return `Invalid input: ${errorMessage}`; } } return `Error during ${operation}: ${errorMessage || String(error)}`; }