jsonplaceholder_comments
Retrieve test comments data for specific posts via JSONPlaceholder API. Use post ID to fetch targeted comments or set a limit to control the number of results. Ideal for testing and development purposes.
Instructions
Get test comments data from JSONPlaceholder
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No | Maximum number of comments to return (1-100) | |
| postId | No | Post ID to get comments for (1-100, optional) |
Input Schema (JSON Schema)
{
"properties": {
"limit": {
"default": 10,
"description": "Maximum number of comments to return (1-100)",
"maximum": 100,
"minimum": 1,
"type": "number"
},
"postId": {
"description": "Post ID to get comments for (1-100, optional)",
"type": "number"
}
},
"required": [],
"type": "object"
}
Implementation Reference
- The execute handler function that implements the core logic of the jsonplaceholder_comments tool by fetching comments from the JSONPlaceholder API using the client instance.execute: async (args: any) => { try { const comments = await client.getComments(args.postId, args.limit || 10); return { success: true, data: { source: 'JSONPlaceholder API', type: 'comments', postId: args.postId, results: comments, count: comments.length, timestamp: Date.now(), apiUsed: true } }; } catch (error) { return { success: false, error: error instanceof Error ? error.message : 'Failed to get test comments' }; } }
- src/tools/testing/jsonplaceholder-tools.ts:276-321 (registration)The registration of the jsonplaceholder_comments tool in the ToolRegistry, including name, description, inputSchema, and reference to the execute handler.registry.registerTool({ name: 'jsonplaceholder_comments', description: 'Get test comments data from JSONPlaceholder', category: 'testing', source: 'jsonplaceholder.typicode.com', inputSchema: { type: 'object', properties: { postId: { type: 'number', description: 'Post ID to get comments for (1-100, optional)' }, limit: { type: 'number', description: 'Maximum number of comments to return (1-100)', default: 10, minimum: 1, maximum: 100 } }, required: [] }, execute: async (args: any) => { try { const comments = await client.getComments(args.postId, args.limit || 10); return { success: true, data: { source: 'JSONPlaceholder API', type: 'comments', postId: args.postId, results: comments, count: comments.length, timestamp: Date.now(), apiUsed: true } }; } catch (error) { return { success: false, error: error instanceof Error ? error.message : 'Failed to get test comments' }; } } });
- src/utils/input-validator.ts:273-276 (schema)Zod schema used for input validation of the jsonplaceholder_comments tool parameters (postId and limit).'jsonplaceholder_comments': z.object({ postId: z.number().int().min(1).max(100).optional(), limit: z.number().int().min(1).max(100).optional().default(10) }),
- Helper method in JSONPlaceholderAPIClient class that constructs the API endpoint for comments and fetches/slices the data.async getComments(postId?: number, limit?: number) { const endpoint = postId ? `/posts/${postId}/comments` : '/comments'; const comments = await this.makeRequest(endpoint); return limit ? comments.slice(0, limit) : comments; }