test_jsonplaceholder
Validate JSON data by testing JSONPlaceholder API endpoints like posts, users, and comments to ensure proper data structure and API functionality.
Instructions
Test JSONPlaceholder API for JSON data validation
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| endpoint | No | JSONPlaceholder endpoint to test | posts |
| id | No | Specific resource ID to fetch (optional) |
Implementation Reference
- The execute handler function for the 'test_jsonplaceholder' tool. It simulates JSONPlaceholder API calls using mock data based on the provided endpoint ('posts', 'users', 'comments') and optional id, returning structured success/error responses.execute: async (args: ToolInput): Promise<ToolOutput> => { try { const { endpoint = 'posts', id } = args; const baseUrl = 'https://jsonplaceholder.typicode.com'; const url = id ? `${baseUrl}/${endpoint}/${id}` : `${baseUrl}/${endpoint}`; // Simulate API response const mockData = { posts: [{ id: 1, title: 'Test Post', body: 'Test content', userId: 1 }], users: [{ id: 1, name: 'Test User', email: 'test@example.com' }], comments: [{ id: 1, postId: 1, name: 'Test Comment', email: 'test@example.com', body: 'Test comment body' }] }; return { success: true, data: { endpoint, url, response: mockData[endpoint as keyof typeof mockData] || [], status: 'success' }, metadata: { tool: 'test_jsonplaceholder', timestamp: new Date().toISOString() } }; } catch (error) { return { success: false, error: `JSONPlaceholder test failed: ${error instanceof Error ? error.message : String(error)}`, data: null }; } }
- Input schema definition for the 'test_jsonplaceholder' tool, specifying optional 'endpoint' (enum of JSONPlaceholder endpoints) and 'id' parameters.inputSchema: { type: 'object', properties: { endpoint: { type: 'string', enum: ['posts', 'users', 'comments', 'albums', 'photos', 'todos'], description: 'JSONPlaceholder endpoint to test', default: 'posts' }, id: { type: 'number', description: 'Specific resource ID to fetch (optional)' } }, required: [] },
- src/tools/testing/jsonplaceholder-tools.ts:68-123 (registration)Tool registration block within registerJSONPlaceholderTools function, defining name, description, schema, and handler for 'test_jsonplaceholder'.registry.registerTool({ name: 'test_jsonplaceholder', description: 'Test JSONPlaceholder API for JSON data validation', category: 'testing', source: 'JSONPlaceholder', inputSchema: { type: 'object', properties: { endpoint: { type: 'string', enum: ['posts', 'users', 'comments', 'albums', 'photos', 'todos'], description: 'JSONPlaceholder endpoint to test', default: 'posts' }, id: { type: 'number', description: 'Specific resource ID to fetch (optional)' } }, required: [] }, execute: async (args: ToolInput): Promise<ToolOutput> => { try { const { endpoint = 'posts', id } = args; const baseUrl = 'https://jsonplaceholder.typicode.com'; const url = id ? `${baseUrl}/${endpoint}/${id}` : `${baseUrl}/${endpoint}`; // Simulate API response const mockData = { posts: [{ id: 1, title: 'Test Post', body: 'Test content', userId: 1 }], users: [{ id: 1, name: 'Test User', email: 'test@example.com' }], comments: [{ id: 1, postId: 1, name: 'Test Comment', email: 'test@example.com', body: 'Test comment body' }] }; return { success: true, data: { endpoint, url, response: mockData[endpoint as keyof typeof mockData] || [], status: 'success' }, metadata: { tool: 'test_jsonplaceholder', timestamp: new Date().toISOString() } }; } catch (error) { return { success: false, error: `JSONPlaceholder test failed: ${error instanceof Error ? error.message : String(error)}`, data: null }; } } });
- src/index.ts:245-245 (registration)Main server registration call in OpenSearchMCPServer.registerAllTools() that invokes the registration of 'test_jsonplaceholder' (and test_httpbin).registerJSONPlaceholderTools(this.toolRegistry); // 2 tools: test_jsonplaceholder, test_httpbin