Skip to main content
Glama

Open Search MCP

by flyanima

jsonplaceholder_comments

Retrieve test comments data for specific posts via JSONPlaceholder API. Use post ID to fetch targeted comments or set a limit to control the number of results. Ideal for testing and development purposes.

Instructions

Get test comments data from JSONPlaceholder

Input Schema

NameRequiredDescriptionDefault
limitNoMaximum number of comments to return (1-100)
postIdNoPost ID to get comments for (1-100, optional)

Input Schema (JSON Schema)

{ "properties": { "limit": { "default": 10, "description": "Maximum number of comments to return (1-100)", "maximum": 100, "minimum": 1, "type": "number" }, "postId": { "description": "Post ID to get comments for (1-100, optional)", "type": "number" } }, "required": [], "type": "object" }

Implementation Reference

  • The execute handler function that implements the core logic of the jsonplaceholder_comments tool by fetching comments from the JSONPlaceholder API using the client instance.
    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' }; } }
  • The registration of the jsonplaceholder_comments tool in the ToolRegistry, including name, description, inputSchema, and reference to 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' }; } } });
  • Zod schema used for input validation of the jsonplaceholder_comments tool parameters (postId and limit).
    '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.
    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; }

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