get_post_comments
Retrieve and organize comments from LinkedIn posts using HarvestAPI, with options to sort by relevance or date, paginate results, and save cleaned JSON data.
Instructions
Get comments on a LinkedIn post. Returns cleaned data in TOON format.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| post | Yes | LinkedIn post URL (required) | |
| sortBy | No | Sort by: relevance or date | |
| page | No | Page number | |
| paginationToken | No | Pagination token | |
| save_dir | No | Directory to save cleaned JSON data | |
| max_items | No | Maximum comments (default: 10) |
Implementation Reference
- src/index.ts:911-927 (handler)The handler function for the get_post_comments tool. It constructs API parameters from input args, calls the HarvestAPI endpoint '/post-comments', cleans the response data using DataCleaners.cleanComment, limits the number of items, and returns a formatted TOON-encoded response with optional saving to file and pagination info.private async getPostComments(args: Record<string, any>): Promise<CallToolResult> { const params: Record<string, any> = { post: args.post }; if (args.sortBy) params.sortBy = args.sortBy; if (args.page) params.page = args.page; if (args.paginationToken) params.paginationToken = args.paginationToken; const data = await this.makeRequest('/post-comments', params); const maxItems = args.max_items || 10; const cleaned = (data.elements || []).slice(0, maxItems).map(DataCleaners.cleanComment); return this.formatResponse(cleaned, { saveDir: args.save_dir, toolName: 'get_post_comments', pagination: data.pagination, }); }
- src/index.ts:457-468 (schema)The input schema for the get_post_comments tool, defining the expected parameters: required 'post' URL, optional sortBy, page, paginationToken, save_dir, and max_items.inputSchema: { type: 'object', properties: { post: { type: 'string', description: 'LinkedIn post URL (required)' }, sortBy: { type: 'string', description: 'Sort by: relevance or date', enum: ['relevance', 'date'] }, page: { type: 'integer', description: 'Page number', default: 1 }, paginationToken: { type: 'string', description: 'Pagination token' }, save_dir: { type: 'string', description: 'Directory to save cleaned JSON data' }, max_items: { type: 'integer', description: 'Maximum comments (default: 10)', default: 10 }, }, required: ['post'], },
- src/index.ts:454-469 (registration)Registration of the get_post_comments tool in the tools list returned by ListToolsRequestSchema handler.{ name: 'get_post_comments', description: 'Get comments on a LinkedIn post. Returns cleaned data in TOON format.', inputSchema: { type: 'object', properties: { post: { type: 'string', description: 'LinkedIn post URL (required)' }, sortBy: { type: 'string', description: 'Sort by: relevance or date', enum: ['relevance', 'date'] }, page: { type: 'integer', description: 'Page number', default: 1 }, paginationToken: { type: 'string', description: 'Pagination token' }, save_dir: { type: 'string', description: 'Directory to save cleaned JSON data' }, max_items: { type: 'integer', description: 'Maximum comments (default: 10)', default: 10 }, }, required: ['post'], }, } as Tool,
- src/index.ts:546-546 (registration)Dispatch case in the CallToolRequestSchema switch statement that maps the tool name to the getPostComments handler method.case 'get_post_comments': return await this.getPostComments(args as Record<string, any>);
- src/index.ts:168-177 (helper)Helper function in DataCleaners used by get_post_comments to clean individual comment data, extracting id, content, author, timestamp, and likes.cleanComment(raw: any): any { if (!raw) return null; return { id: raw.id, content: raw.content, authorName: raw.author?.name, postedAgo: raw.postedAt?.postedAgoText, likes: raw.engagement?.likes, }; },