Skip to main content
Glama
flyanima

Open Search MCP

by flyanima

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
NameRequiredDescriptionDefault
endpointNoJSONPlaceholder endpoint to testposts
idNoSpecific 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: [] },
  • 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

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/flyanima/open-search-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server