get-name-history
Retrieve the full history of an Ethereum Name Service (ENS) domain, including ownership changes and record updates, by querying the ENS system.
Instructions
Get the history of an ENS name
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | The ENS name to check history for |
Implementation Reference
- utils/index.ts:305-375 (handler)Implements the core logic of the 'get-name-history' tool by fetching and formatting the ENS name's history events using publicClient.getNameHistory.export async function getNameHistory( { name }: { name: string }): Promise<ServerResponse> { const normalizedName = normalizeName(name); try { const history = await publicClient.getNameHistory({ name: normalizedName }); if (!history) { return { content: [{ type: "text", text: `No history found for ${name}` }], isError: false }; } let output = `History for ${name}:\n\n`; if (history.domainEvents.length > 0) { output += "Domain Events:\n"; for (const event of history.domainEvents) { output += `- ${event.type} at block ${event.blockNumber}\n`; if (event.type === 'Transfer' || event.type === 'NewOwner') { output += ` New owner: ${event.owner}\n`; } else if (event.type === 'NewResolver') { output += ` New resolver: ${event.resolver}\n`; } } } if (history.registrationEvents && history.registrationEvents.length > 0) { output += "\nRegistration Events:\n"; for (const event of history.registrationEvents) { output += `- ${event.type} at block ${event.blockNumber}\n`; if (event.type === 'NameRegistered') { output += ` Registrant: ${event.registrant}\n`; output += ` Expiry Date: ${new Date(Number(event.expiryDate) * 1000).toLocaleString()}\n`; } else if (event.type === 'NameRenewed') { output += ` New Expiry Date: ${new Date(Number(event.expiryDate) * 1000).toLocaleString()}\n`; } } } if (history.resolverEvents && history.resolverEvents.length > 0) { output += "\nResolver Events:\n"; for (const event of history.resolverEvents) { output += `- ${event.type} at block ${event.blockNumber}\n`; if (event.type === 'AddrChanged') { output += ` New address: ${event.addr}\n`; } else if (event.type === 'TextChanged') { output += ` Key: ${event.key}\n`; if (event.value) output += ` Value: ${event.value}\n`; } } } return { content: [{ type: "text", text: output }], isError: false }; } catch (error) { const errorMessage = handleEnsError(error, "get name history"); return { content: [{ type: "text", text: errorMessage }], isError: true }; } }
- index.ts:89-96 (registration)Registers the 'get-name-history' MCP tool with input schema and delegates to the getNameHistory handler.server.tool( "get-name-history", "Get the history of an ENS name", { name: z.string().describe("The ENS name to check history for"), }, async (params) => getNameHistory( params) );
- utils/index.ts:10-15 (schema)Defines the output schema structure used by the getNameHistory handler and other tools.interface ServerResponse { content: TextContent[]; isError: boolean; _meta?: { [key: string]: unknown }; [x: string]: unknown; }
- utils/index.ts:17-17 (helper)Helper function to normalize ENS names by appending '.eth' if missing, used in getNameHistory.const normalizeName = (name: string) => name.endsWith('.eth') ? name : `${name}.eth`;
- utils/index.ts:19-54 (helper)Helper function for error handling in ENS operations, used in getNameHistory.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)}`; }