Skip to main content
Glama

get_comments_by_submission

Retrieve comments from a Reddit submission by providing the submission ID to access discussion threads and user responses.

Instructions

Accéder aux commentaires d'une soumission

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
limitNoNombre de commentaires à récupérer
submission_idYesL'ID de la soumission

Implementation Reference

  • The main tool handler function that takes params, fetches comments using the Reddit client, formats them, and returns a structured text response.
    export async function getCommentsBySubmission(params: { submission_id: string; limit?: number; }) { const { submission_id, limit = 20 } = params; const client = getRedditClient(); if (!client) { throw new McpError( ErrorCode.InternalError, "Reddit client not initialized" ); } try { console.log(`[Tool] Getting comments for submission ${submission_id}`); const comments = await client.getCommentsBySubmission(submission_id, limit); const formattedComments = comments.map(formatCommentInfo); const commentSummaries = formattedComments .map( (comment, index) => ` ### ${index + 1}. u/${comment.author} - Score: ${comment.stats.score} - Posté: ${comment.metadata.posted} - Contenu: ${comment.content.substring(0, 200)}${comment.content.length > 200 ? "..." : ""} ` ) .join("\n"); return { content: [ { type: "text", text: ` # Commentaires pour la soumission ${submission_id} ${commentSummaries} `, }, ], }; } catch (error) { console.error(`[Error] Error getting comments by submission: ${error}`); throw new McpError( ErrorCode.InternalError, `Failed to fetch comments: ${error}` ); } }
  • Tool schema definition including name, description, and input schema for validation.
    { name: "get_comments_by_submission", description: "Accéder aux commentaires d'une soumission", inputSchema: { type: "object", properties: { submission_id: { type: "string", description: "L'ID de la soumission", }, limit: { type: "integer", description: "Nombre de commentaires à récupérer", default: 20, }, }, required: ["submission_id"], }, },
  • src/index.ts:478-481 (registration)
    Registration in the tool dispatcher switch case that calls the handler function.
    case "get_comments_by_submission": return await tools.getCommentsBySubmission( toolParams as { submission_id: string; limit?: number } );
  • Helper method in RedditClient that performs the actual API call to fetch comments by submission ID.
    async getCommentsBySubmission(submissionId: string, limit: number = 20): Promise<RedditComment[]> { await this.authenticate(); try { const response = await this.api.get(`/comments/${submissionId}.json`, { params: { limit } }); if (!response.data || response.data.length < 2) { throw new Error(`Submission with ID ${submissionId} not found or has no comments`); } const comments = response.data[1].data.children; return comments.map((child: any) => { const comment = child.data; return { id: comment.id, author: comment.author, body: comment.body, score: comment.score, controversiality: comment.controversiality, subreddit: comment.subreddit, submissionTitle: response.data[0].data.children[0].data.title, createdUtc: comment.created_utc, edited: !!comment.edited, isSubmitter: comment.is_submitter, permalink: comment.permalink, }; }); } catch (error) { console.error(`[Error] Failed to get comments for submission ${submissionId}:`, error); throw new Error(`Failed to get comments for submission ${submissionId}`); } }

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/samy-clivolt/reddit-mcp-server'

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