jsonplaceholder_posts
Retrieve test posts data from JSONPlaceholder for reliable API testing. Set a limit (1-100) to control the number of posts fetched, ensuring consistent results for development and debugging.
Instructions
Get test posts data from JSONPlaceholder (always works, good for testing)
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No | Maximum number of posts to return (1-100) |
Input Schema (JSON Schema)
{
"properties": {
"limit": {
"default": 10,
"description": "Maximum number of posts to return (1-100)",
"maximum": 100,
"minimum": 1,
"type": "number"
}
},
"required": [],
"type": "object"
}
Implementation Reference
- The execute handler function for the 'jsonplaceholder_posts' tool. Fetches posts from JSONPlaceholder API via client.getPosts() and formats the response.execute: async (args: any) => { try { const posts = await client.getPosts(args.limit || 10); return { success: true, data: { source: 'JSONPlaceholder API', type: 'posts', results: posts, count: posts.length, timestamp: Date.now(), apiUsed: true, note: 'This is test data from JSONPlaceholder - always reliable for testing' } }; } catch (error) { return { success: false, error: error instanceof Error ? error.message : 'Failed to get test posts' }; } }
- src/tools/testing/jsonplaceholder-tools.ts:189-230 (registration)Registration of the 'jsonplaceholder_posts' tool using registry.registerTool, including name, description, inputSchema, and inline execute handler.registry.registerTool({ name: 'jsonplaceholder_posts', description: 'Get test posts data from JSONPlaceholder (always works, good for testing)', category: 'testing', source: 'jsonplaceholder.typicode.com', inputSchema: { type: 'object', properties: { limit: { type: 'number', description: 'Maximum number of posts to return (1-100)', default: 10, minimum: 1, maximum: 100 } }, required: [] }, execute: async (args: any) => { try { const posts = await client.getPosts(args.limit || 10); return { success: true, data: { source: 'JSONPlaceholder API', type: 'posts', results: posts, count: posts.length, timestamp: Date.now(), apiUsed: true, note: 'This is test data from JSONPlaceholder - always reliable for testing' } }; } catch (error) { return { success: false, error: error instanceof Error ? error.message : 'Failed to get test posts' }; } } });
- Input schema defined in the tool registration for validating the optional 'limit' parameter.inputSchema: { type: 'object', properties: { limit: { type: 'number', description: 'Maximum number of posts to return (1-100)', default: 10, minimum: 1, maximum: 100 } }, required: [] },
- Helper method in JSONPlaceholderAPIClient class that fetches posts from the API endpoint and applies optional limit.async getPosts(limit?: number) { const posts = await this.makeRequest('/posts'); return limit ? posts.slice(0, limit) : posts; }
- src/utils/input-validator.ts:267-269 (schema)Additional Zod schema in input-validator.ts used for pre-execution input validation specific to 'jsonplaceholder_posts'.'jsonplaceholder_posts': z.object({ limit: z.number().int().min(1).max(100).optional().default(10) }),
- src/index.ts:245-245 (registration)Top-level registration call in main server initialization that invokes registerJSONPlaceholderTools, thereby registering 'jsonplaceholder_posts'.registerJSONPlaceholderTools(this.toolRegistry); // 2 tools: test_jsonplaceholder, test_httpbin