get_threads_posts
Retrieve posts from a Threads user by providing their username. This tool extracts social media content for analysis or monitoring purposes.
Instructions
Get posts from a Threads user
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| handle | Yes | Threads username |
Implementation Reference
- src/index.ts:466-485 (handler)Handler logic for the 'get_threads_posts' tool. Makes an API call to Sociavault to fetch Threads user posts, extracts the data using extractThreadsPosts, and returns formatted JSON response.if (name === "get_threads_posts") { const { handle } = args as { handle: string }; const response = await axios.get(`${BASE_URL}/threads/user/posts`, { headers: { "X-API-Key": API_KEY }, params: { handle }, }); const extracted = extractThreadsPosts(response.data, 10); return { content: [ { type: "text", text: JSON.stringify( { handle, posts: extracted, total_returned: extracted.length }, null, 2 ), }, ], }; }
- src/index.ts:289-299 (registration)Tool registration entry in the tools array, including name, description, and input schema. Used by ListToolsRequestHandler.{ name: "get_threads_posts", description: "Get posts from a Threads user", inputSchema: { type: "object", properties: { handle: { type: "string", description: "Threads username" }, }, required: ["handle"], }, },
- src/index.ts:292-299 (schema)Input schema definition for the 'get_threads_posts' tool, specifying the required 'handle' parameter.inputSchema: { type: "object", properties: { handle: { type: "string", description: "Threads username" }, }, required: ["handle"], }, },
- src/index.ts:138-151 (helper)Helper function to extract and format Threads posts data from the API response, limiting to 10 posts.function extractThreadsPosts(data: any, limit = 10) { const posts = data?.data?.threads || data?.threads || data?.data || []; const postsArray = Array.isArray(posts) ? posts : []; return postsArray.slice(0, limit).map((post: any) => { return { id: post.id || post.pk, text: post.caption?.text || post.text || "", likes: post.like_count || post.likes || 0, replies: post.replies_count || post.replies || 0, reposts: post.repost_count || 0, timestamp: post.taken_at || post.created_at, }; }); }