Skip to main content
Glama
flyanima

Open Search MCP

by flyanima

jsonplaceholder_health_test

Test API connectivity and response times for JSONPlaceholder endpoints to verify service health and performance.

Instructions

Test API connectivity and response times using JSONPlaceholder

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
endpointsNoEndpoints to test: posts, users, comments, albums, photos, todos

Implementation Reference

  • The execute function implementing the tool's core logic: performs health checks on specified JSONPlaceholder endpoints by fetching limited data samples, calculating response times, tracking success/failure, and returning detailed test summary.
    execute: async (args: any) => { try { const endpoints = args.endpoints || ['posts', 'users', 'comments']; const testResults: any = { timestamp: new Date().toISOString(), endpoints_tested: endpoints, results: {}, summary: { total_tests: endpoints.length, successful: 0, failed: 0, average_response_time: 0 } }; let totalResponseTime = 0; for (const endpoint of endpoints) { const startTime = Date.now(); try { let data; switch (endpoint) { case 'posts': data = await client.getPosts(3); break; case 'users': data = await client.getUsers(3); break; case 'comments': data = await client.getComments(undefined, 3); break; case 'albums': data = await client.getAlbums(undefined, 3); break; case 'photos': data = await client.getPhotos(undefined, 3); break; case 'todos': data = await client.getTodos(undefined, 3); break; default: throw new Error(`Unknown endpoint: ${endpoint}`); } const responseTime = Date.now() - startTime; totalResponseTime += responseTime; testResults.results[endpoint] = { status: 'success', response_time: responseTime, data_count: Array.isArray(data) ? data.length : 1 }; testResults.summary.successful++; } catch (error) { const responseTime = Date.now() - startTime; testResults.results[endpoint] = { status: 'failed', response_time: responseTime, error: error instanceof Error ? error.message : 'Unknown error' }; testResults.summary.failed++; } } testResults.summary.average_response_time = Math.round(totalResponseTime / endpoints.length); return { success: true, data: { source: 'JSONPlaceholder API', health_test: testResults, timestamp: Date.now(), apiUsed: true } }; } catch (error) { return { success: false, error: error instanceof Error ? error.message : 'Failed to run health test' }; } }
  • Registers the 'jsonplaceholder_health_test' tool into the ToolRegistry within the registerJSONPlaceholderTools function.
    registry.registerTool({ name: 'jsonplaceholder_health_test', description: 'Test API connectivity and response times using JSONPlaceholder', category: 'testing', source: 'jsonplaceholder.typicode.com', inputSchema: { type: 'object', properties: { endpoints: { type: 'array', items: { type: 'string' }, description: 'Endpoints to test: posts, users, comments, albums, photos, todos', default: ['posts', 'users', 'comments'] } }, required: [] }, execute: async (args: any) => { try { const endpoints = args.endpoints || ['posts', 'users', 'comments']; const testResults: any = { timestamp: new Date().toISOString(), endpoints_tested: endpoints, results: {}, summary: { total_tests: endpoints.length, successful: 0, failed: 0, average_response_time: 0 } }; let totalResponseTime = 0; for (const endpoint of endpoints) { const startTime = Date.now(); try { let data; switch (endpoint) { case 'posts': data = await client.getPosts(3); break; case 'users': data = await client.getUsers(3); break; case 'comments': data = await client.getComments(undefined, 3); break; case 'albums': data = await client.getAlbums(undefined, 3); break; case 'photos': data = await client.getPhotos(undefined, 3); break; case 'todos': data = await client.getTodos(undefined, 3); break; default: throw new Error(`Unknown endpoint: ${endpoint}`); } const responseTime = Date.now() - startTime; totalResponseTime += responseTime; testResults.results[endpoint] = { status: 'success', response_time: responseTime, data_count: Array.isArray(data) ? data.length : 1 }; testResults.summary.successful++; } catch (error) { const responseTime = Date.now() - startTime; testResults.results[endpoint] = { status: 'failed', response_time: responseTime, error: error instanceof Error ? error.message : 'Unknown error' }; testResults.summary.failed++; } } testResults.summary.average_response_time = Math.round(totalResponseTime / endpoints.length); return { success: true, data: { source: 'JSONPlaceholder API', health_test: testResults, timestamp: Date.now(), apiUsed: true } }; } catch (error) { return { success: false, error: error instanceof Error ? error.message : 'Failed to run health test' }; } } });
  • Inline input schema defining the tool's expected parameters (optional endpoints array).
    inputSchema: { type: 'object', properties: { endpoints: { type: 'array', items: { type: 'string' }, description: 'Endpoints to test: posts, users, comments, albums, photos, todos', default: ['posts', 'users', 'comments'] } }, required: [] },
  • Zod schema in global input validator for validating and parsing tool inputs specifically for 'jsonplaceholder_health_test'.
    'jsonplaceholder_health_test': z.object({ endpoints: z.array(z.enum(['posts', 'users', 'comments', 'albums', 'photos', 'todos'])).optional() }),
  • Helper class instantiated and used by the handler to make actual API requests to JSONPlaceholder endpoints.
    class JSONPlaceholderAPIClient { private baseURL = 'https://jsonplaceholder.typicode.com'; async makeRequest(endpoint: string, params: Record<string, any> = {}) { try { const response = await axios.get(`${this.baseURL}${endpoint}`, { params, timeout: 10000 }); return response.data; } catch (error) {throw error; } } async getPosts(limit?: number) { const posts = await this.makeRequest('/posts'); return limit ? posts.slice(0, limit) : posts; } async getUsers(limit?: number) { const users = await this.makeRequest('/users'); return limit ? users.slice(0, limit) : users; } 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; } async getAlbums(userId?: number, limit?: number) { const endpoint = userId ? `/users/${userId}/albums` : '/albums'; const albums = await this.makeRequest(endpoint); return limit ? albums.slice(0, limit) : albums; } async getPhotos(albumId?: number, limit?: number) { const endpoint = albumId ? `/albums/${albumId}/photos` : '/photos'; const photos = await this.makeRequest(endpoint); return limit ? photos.slice(0, limit) : photos; } async getTodos(userId?: number, limit?: number) { const endpoint = userId ? `/users/${userId}/todos` : '/todos'; const todos = await this.makeRequest(endpoint); return limit ? todos.slice(0, limit) : todos; } }

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