get-text-record
Retrieve specific text records associated with an Ethereum Name Service (ENS) domain, such as email, URL, avatar, or social media details, by specifying the domain name and record key.
Instructions
Get a text record for an ENS name
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| key | Yes | The record key to look up (e.g., 'email', 'url', 'avatar', 'description', 'twitter', etc.) | |
| name | Yes | The ENS name to query |
Implementation Reference
- utils/index.ts:140-164 (handler)The handler function that executes the tool logic: normalizes the ENS name, fetches the text record via publicClient, handles no-value and error cases, returning a formatted ServerResponse.export async function getTextRecord( { name, key }: { name: string, key: string }): Promise<ServerResponse> { const normalizedName = normalizeName(name); try { const value = await publicClient.getTextRecord({ name:normalizedName, key }); if (!value) { return { content: [{ type: "text", text: `No '${key}' record found for ${normalizedName}` }], isError: false }; } return { content: [{ type: "text", text: `The '${key}' record for ${normalizedName} is: ${value}` }], isError: false }; } catch (error) { const errorMessage = handleEnsError(error, "getting records"); return { content: [{ type: "text", text: errorMessage }], isError: true }; } }
- index.ts:48-56 (registration)Registers the get-text-record tool with the MCP server, including input schema and handler invocation.server.tool( "get-text-record", "Get a text record for an ENS name", { name: z.string().describe("The ENS name to query"), key: z.string().describe("The record key to look up (e.g., 'email', 'url', 'avatar', 'description', 'twitter', etc.)"), }, async (params) => getTextRecord( params) );
- index.ts:51-54 (schema)Zod schema defining input parameters: name (ENS name) and key (text record key).{ name: z.string().describe("The ENS name to query"), key: z.string().describe("The record key to look up (e.g., 'email', 'url', 'avatar', 'description', 'twitter', etc.)"), },
- utils/index.ts:17-17 (helper)Helper function to normalize ENS names by appending '.eth' if missing.const normalizeName = (name: string) => name.endsWith('.eth') ? name : `${name}.eth`;
- utils/index.ts:19-54 (helper)Helper for standardized error handling in ENS operations, used in the handler.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)}`; }