jsonplaceholder_comments
Retrieve test comments data from JSONPlaceholder for development and testing purposes, with optional filtering by post ID and configurable result limits.
Instructions
Get test comments data from JSONPlaceholder
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| postId | No | Post ID to get comments for (1-100, optional) | |
| limit | No | Maximum number of comments to return (1-100) |
Implementation Reference
- The main handler function that executes the tool logic. It fetches comments from the JSONPlaceholder API using the client instance and formats the response with success status, data, and error handling.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)Registers the 'jsonplaceholder_comments' tool with the ToolRegistry, including name, description, input schema, and 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 definition used for input validation specific to the jsonplaceholder_comments tool in the global input validator.'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, used by the tool handler.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; }