get-username-casts
Retrieve recent casts from a Farcaster user by specifying their username. Use this tool to fetch and analyze content posted by specific accounts on the Farcaster network.
Instructions
Get casts from a specific Farcaster username
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| username | Yes | Farcaster username | |
| limit | No | Maximum number of casts to return (default: 10) |
Implementation Reference
- src/index.ts:602-671 (handler)The handler function that executes the get-username-casts tool. It resolves the Farcaster username to a FID, fetches user display name, retrieves recent casts using the Hubble API, formats them, and returns a formatted text response or error.async ({ username, limit = 10 }: { username: string; limit?: number }) => { try { console.error(`Looking up casts for username: ${username}`); // First, we need to get the FID for the username const fid = await getFidByUsername(username); if (!fid) { return { content: [ { type: "text", text: `User "${username}" not found.` } ], isError: true }; } console.error(`Found FID ${fid} for username ${username}, fetching user data`); // Get user data to ensure we have the display name const userData = await getUserData(fid); // Use the display name if available, otherwise use the FID const displayName = userData.displayName || `FID: ${fid}`; console.error(`User data: displayName=${displayName}`); // Now get the casts for this FID const response = await fetchFromHubble(`/castsByFid`, { fid, pageSize: limit, reverse: 1 // Get newest first }) as FarcasterCastsResponse; if (!response.messages || response.messages.length === 0) { return { content: [ { type: "text", text: `No casts found for ${displayName} (FID: ${fid})` } ] }; } const castsText = await formatCasts(response.messages, limit); return { content: [ { type: "text", text: `# Casts from ${displayName}\n\n${castsText}` } ] }; } catch (error) { console.error("Error in get-username-casts:", error); return { content: [ { type: "text", text: `Error fetching casts by username: ${error instanceof Error ? error.message : String(error)}` } ], isError: true }; } }
- src/index.ts:598-601 (schema)Zod schema defining the input parameters: required 'username' string and optional 'limit' number.{ username: z.string().describe("Farcaster username"), limit: z.number().optional().describe("Maximum number of casts to return (default: 10)") },
- src/index.ts:595-672 (registration)Registration of the 'get-username-casts' tool on the MCP server using server.tool(), including description, schema, and inline handler function.server.tool( "get-username-casts", "Get casts from a specific Farcaster username", { username: z.string().describe("Farcaster username"), limit: z.number().optional().describe("Maximum number of casts to return (default: 10)") }, async ({ username, limit = 10 }: { username: string; limit?: number }) => { try { console.error(`Looking up casts for username: ${username}`); // First, we need to get the FID for the username const fid = await getFidByUsername(username); if (!fid) { return { content: [ { type: "text", text: `User "${username}" not found.` } ], isError: true }; } console.error(`Found FID ${fid} for username ${username}, fetching user data`); // Get user data to ensure we have the display name const userData = await getUserData(fid); // Use the display name if available, otherwise use the FID const displayName = userData.displayName || `FID: ${fid}`; console.error(`User data: displayName=${displayName}`); // Now get the casts for this FID const response = await fetchFromHubble(`/castsByFid`, { fid, pageSize: limit, reverse: 1 // Get newest first }) as FarcasterCastsResponse; if (!response.messages || response.messages.length === 0) { return { content: [ { type: "text", text: `No casts found for ${displayName} (FID: ${fid})` } ] }; } const castsText = await formatCasts(response.messages, limit); return { content: [ { type: "text", text: `# Casts from ${displayName}\n\n${castsText}` } ] }; } catch (error) { console.error("Error in get-username-casts:", error); return { content: [ { type: "text", text: `Error fetching casts by username: ${error instanceof Error ? error.message : String(error)}` } ], isError: true }; } } );