threads_search_posts
Search public Threads posts by keyword or topic tag. Filter results by media type, author username, and date range. Paginate to access more results.
Instructions
Search for public Threads posts by keyword or topic tag. Results can be filtered by media type and author.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| q | Yes | Search keyword or query | |
| search_type | No | Search by keyword or topic tag (default: keyword) | |
| media_type | No | Filter results by media type | |
| author_username | No | Filter results by author username | |
| since | No | Start date (Unix timestamp) | |
| until | No | End date (Unix timestamp) | |
| limit | No | Number of results | |
| after | No | Pagination cursor |
Implementation Reference
- src/tools/threads/media.ts:54-87 (handler)Handler function for the threads_search_posts tool. It calls the Meta Graph API endpoint `/{threadsUserId}/threads_search` with query parameters (q, search_type, media_type, author_username, since, until, limit, after) and returns JSON results.
// ─── threads_search_posts ──────────────────────────────────── server.tool( "threads_search_posts", "Search for public Threads posts by keyword or topic tag. Results can be filtered by media type and author.", { q: z.string().describe("Search keyword or query"), search_type: z.enum(["keyword", "tag"]).optional().describe("Search by keyword or topic tag (default: keyword)"), media_type: z.enum(["TEXT", "IMAGE", "VIDEO", "CAROUSEL"]).optional().describe("Filter results by media type"), author_username: z.string().optional().describe("Filter results by author username"), since: z.string().optional().describe("Start date (Unix timestamp)"), until: z.string().optional().describe("End date (Unix timestamp)"), limit: z.number().optional().describe("Number of results"), after: z.string().optional().describe("Pagination cursor"), }, async ({ q, search_type, media_type, author_username, since, until, limit, after }) => { try { const params: Record<string, unknown> = { q, fields: "id,text,username,permalink,timestamp,media_type,media_url,topic_tag", }; if (search_type) params.search_type = search_type; if (media_type) params.media_type = media_type; if (author_username) params.author_username = author_username; if (since) params.since = since; if (until) params.until = until; if (limit) params.limit = limit; if (after) params.after = after; const { data, rateLimit } = await client.threads("GET", `/${client.threadsUserId}/threads_search`, params); return { content: [{ type: "text", text: JSON.stringify({ ...data as object, _rateLimit: rateLimit }, null, 2) }] }; } catch (error) { return { content: [{ type: "text", text: `Search posts failed: ${error instanceof Error ? error.message : String(error)}` }], isError: true }; } } ); - src/tools/threads/media.ts:58-67 (schema)Zod schema defining the input parameters for threads_search_posts. Requires 'q' (keyword/query), with optional: search_type, media_type, author_username, since, until, limit, after.
{ q: z.string().describe("Search keyword or query"), search_type: z.enum(["keyword", "tag"]).optional().describe("Search by keyword or topic tag (default: keyword)"), media_type: z.enum(["TEXT", "IMAGE", "VIDEO", "CAROUSEL"]).optional().describe("Filter results by media type"), author_username: z.string().optional().describe("Filter results by author username"), since: z.string().optional().describe("Start date (Unix timestamp)"), until: z.string().optional().describe("End date (Unix timestamp)"), limit: z.number().optional().describe("Number of results"), after: z.string().optional().describe("Pagination cursor"), }, - src/index.ts:50-88 (registration)Registration of the threads_search_posts tool via registerThreadsMediaTools in the main server entry point.
registerThreadsMediaTools(server, client); registerThreadsReplyTools(server, client); registerThreadsProfileTools(server, client); registerThreadsInsightTools(server, client); // Register resources registerInstagramResources(server, client); registerThreadsResources(server, client); // Register prompts registerPrompts(server); async function main() { const transport = new StdioServerTransport(); await server.connect(transport); } main().catch((err) => { console.error("Fatal error:", err); process.exit(1); }); // ── Smithery Sandbox ── export function createSandboxServer() { const sandbox = new McpServer({ name: "meta-mcp", version: "2.0.0", }); const mockConfig: MetaConfig = { appId: "", appSecret: "", instagramAccessToken: "", instagramUserId: "", threadsAccessToken: "", threadsUserId: "", }; const mockClient = new MetaClient(mockConfig);