threads_get_posts
Retrieve published Threads posts with options to filter by date, limit results, and paginate through content.
Instructions
Get a list of published Threads posts.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No | Number of results (default 25) | |
| since | No | Start date (ISO 8601 or Unix timestamp) | |
| until | No | End date (ISO 8601 or Unix timestamp) | |
| after | No | Pagination cursor | |
| before | No | Pagination cursor |
Implementation Reference
- src/tools/threads/media.ts:17-32 (handler)The handler for threads_get_posts, which fetches published Threads posts using the MetaClient.
async ({ limit, since, until, after, before }) => { try { const params: Record<string, unknown> = { fields: "id,media_product_type,media_type,media_url,permalink,text,timestamp,shortcode,is_quote_post,has_replies,reply_audience,topic_tag,link_attachment_url,poll_attachment,gif_attachment,alt_text", }; if (limit) params.limit = limit; if (since) params.since = since; if (until) params.until = until; if (after) params.after = after; if (before) params.before = before; const { data, rateLimit } = await client.threads("GET", `/${client.threadsUserId}/threads`, params); return { content: [{ type: "text", text: JSON.stringify({ ...data as object, _rateLimit: rateLimit }, null, 2) }] }; } catch (error) { return { content: [{ type: "text", text: `Get posts failed: ${error instanceof Error ? error.message : String(error)}` }], isError: true }; } } - src/tools/threads/media.ts:10-16 (schema)The input schema for threads_get_posts using Zod.
{ limit: z.number().optional().describe("Number of results (default 25)"), since: z.string().optional().describe("Start date (ISO 8601 or Unix timestamp)"), until: z.string().optional().describe("End date (ISO 8601 or Unix timestamp)"), after: z.string().optional().describe("Pagination cursor"), before: z.string().optional().describe("Pagination cursor"), }, - src/tools/threads/media.ts:7-33 (registration)Registration of the threads_get_posts tool within the McpServer.
server.tool( "threads_get_posts", "Get a list of published Threads posts.", { limit: z.number().optional().describe("Number of results (default 25)"), since: z.string().optional().describe("Start date (ISO 8601 or Unix timestamp)"), until: z.string().optional().describe("End date (ISO 8601 or Unix timestamp)"), after: z.string().optional().describe("Pagination cursor"), before: z.string().optional().describe("Pagination cursor"), }, async ({ limit, since, until, after, before }) => { try { const params: Record<string, unknown> = { fields: "id,media_product_type,media_type,media_url,permalink,text,timestamp,shortcode,is_quote_post,has_replies,reply_audience,topic_tag,link_attachment_url,poll_attachment,gif_attachment,alt_text", }; if (limit) params.limit = limit; if (since) params.since = since; if (until) params.until = until; if (after) params.after = after; if (before) params.before = before; const { data, rateLimit } = await client.threads("GET", `/${client.threadsUserId}/threads`, params); return { content: [{ type: "text", text: JSON.stringify({ ...data as object, _rateLimit: rateLimit }, null, 2) }] }; } catch (error) { return { content: [{ type: "text", text: `Get posts failed: ${error instanceof Error ? error.message : String(error)}` }], isError: true }; } } );