Skip to main content
Glama
manimohans

Farcaster MCP Server

by manimohans

get-channel-casts

Fetch casts from a specific Farcaster channel by specifying the channel name or URL and limit the number of results for targeted content retrieval.

Instructions

Get casts from a specific Farcaster channel

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
channelYesChannel name (e.g., 'aichannel') or URL
limitNoMaximum number of casts to return (default: 10)

Implementation Reference

  • The core handler function for the 'get-channel-casts' tool. It computes a channel hash if needed, fetches casts from the Hubble API using /castsByParent with parent_url, handles empty results, formats the casts using formatCasts helper, and returns formatted text response or error.
    }, function (_a) { return __awaiter(_this, [_a], void 0, function (_b) { var channelHash, response, castsText, error_8; var channel = _b.channel, _c = _b.limit, limit = _c === void 0 ? 10 : _c; return __generator(this, function (_d) { switch (_d.label) { case 0: _d.trys.push([0, 3, , 4]); channelHash = channel.startsWith("0x") ? channel : "0x".concat(buffer_1.Buffer.from(channel).toString("hex")); return [4 /*yield*/, fetchFromHubble("/castsByParent", { parent_url: channelHash, pageSize: limit, reverse: 1 // Get newest first })]; case 1: response = _d.sent(); if (!response.messages || response.messages.length === 0) { return [2 /*return*/, { content: [ { type: "text", text: "No casts found for channel \"".concat(channel, "\"") } ] }]; } return [4 /*yield*/, formatCasts(response.messages, limit)]; case 2: castsText = _d.sent(); return [2 /*return*/, { content: [ { type: "text", text: "# Recent Casts in Channel \"".concat(channel, "\"\n\n").concat(castsText) } ] }]; case 3: error_8 = _d.sent(); console.error("Error in get-channel-casts:", error_8); return [2 /*return*/, { content: [ { type: "text", text: "Error fetching channel casts: ".concat(error_8 instanceof Error ? error_8.message : String(error_8)) } ], isError: true }]; case 4: return [2 /*return*/]; } }); }); });
  • Zod schema defining input parameters for the get-channel-casts tool: channel (string) and optional limit (number).
    channel: zod_1.z.string().describe("Channel name or parent URL"), limit: zod_1.z.number().optional().describe("Maximum number of casts to return (default: 10)")
  • src/index.js:340-340 (registration)
    Registration of the 'get-channel-casts' tool with the MCP server, specifying name, description, input schema, and handler.
    server.tool("get-channel-casts", "Get casts from a specific Farcaster channel", {
  • The core handler function for the 'get-channel-casts' tool in TypeScript source. Resolves channel name to URL using getChannelUrl helper (with Warpcast API fallback), fetches casts via /castsByParent using 'url' param, formats with formatCasts, returns response or error. More robust channel resolution than JS version.
    async ({ channel, limit = 10 }: { channel: string; limit?: number }) => { try { // First, determine the channel URL let channelUrl: string | null = null; // If it's already a URL format, use it directly if (channel.startsWith('https://') || channel.startsWith('chain://') || channel.startsWith('0x')) { channelUrl = channel; console.error(`Using provided URL: ${channelUrl}`); } else { // Otherwise, get the URL for the channel name channelUrl = await getChannelUrl(channel); if (!channelUrl) { return { content: [ { type: "text", text: `Failed to create URL for channel "${channel}".` } ], isError: true }; } console.error(`Using URL for channel "${channel}": ${channelUrl}`); } // Set up parameters for the API call const params: Record<string, any> = { pageSize: limit, reverse: 1 // Get newest first }; // Use url parameter for the API call as shown in the example params.url = channelUrl; console.error(`Fetching casts with params:`, params); let response: FarcasterCastsResponse; try { response = await fetchFromHubble(`/castsByParent`, params) as FarcasterCastsResponse; } catch (error) { // If the first attempt fails and we're using a Warpcast URL, try the API lookup approach if (channelUrl.includes('warpcast.com') && !channel.startsWith('https://')) { console.error(`First attempt failed, trying to get hash URL from Warpcast API`); // Try to fetch channel info from Warpcast API try { const apiResponse = await axios.get('https://api.warpcast.com/v2/all-channels'); if (apiResponse.data && apiResponse.data.result && apiResponse.data.result.channels) { // Look for channel by ID or name (case insensitive) const channelNameLower = channel.toLowerCase(); const channelInfo = apiResponse.data.result.channels.find((c: any) => c.id.toLowerCase() === channelNameLower || c.name.toLowerCase() === channelNameLower ); if (channelInfo && channelInfo.url) { console.error(`Found channel in API: ${channelInfo.name} (${channelInfo.id}) with URL: ${channelInfo.url}`); // Try again with the hash URL params.url = channelInfo.url; console.error(`Retrying with hash URL: ${channelInfo.url}`); response = await fetchFromHubble(`/castsByParent`, params) as FarcasterCastsResponse; } else { throw new Error(`Channel "${channel}" not found in Warpcast API`); } } else { throw error; // Re-throw the original error if API response is invalid } } catch (apiError) { console.error(`Error fetching from Warpcast API: ${apiError instanceof Error ? apiError.message : String(apiError)}`); throw error; // Re-throw the original error if API call fails } } else { throw error; // Re-throw the error if it's not a Warpcast URL or if it's already a full URL } } if (!response.messages || response.messages.length === 0) { return { content: [ { type: "text", text: `No casts found for channel "${channel}"` } ] }; } const castsText = await formatCasts(response.messages, limit); return { content: [ { type: "text", text: `# Recent Casts in Channel "${channel}"\n\n${castsText}` } ] }; } catch (error) { console.error("Error in get-channel-casts:", error); return { content: [ { type: "text", text: `Error fetching channel casts: ${error instanceof Error ? error.message : String(error)}` } ], isError: true }; } }
  • src/index.ts:469-469 (registration)
    Registration of the 'get-channel-casts' tool in the TypeScript source file.
    server.tool(

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/manimohans/farcaster-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server