Skip to main content
Glama

get_comment

Retrieve a specific Reddit comment using its unique ID to access detailed discussion content and context.

Instructions

Accéder à un commentaire spécifique

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
comment_idYesL'ID du commentaire à récupérer

Implementation Reference

  • Main handler function for the 'get_comment' tool. It takes comment_id parameter, fetches the comment using RedditClient.getComment, formats it, and returns MCP-formatted content.
    export async function getComment(params: { comment_id: string }) { const { comment_id } = params; const client = getRedditClient(); if (!client) { throw new McpError( ErrorCode.InternalError, "Reddit client not initialized" ); } try { console.log(`[Tool] Getting comment ${comment_id}`); const comment = await client.getComment(comment_id); const formattedComment = formatCommentInfo(comment); return { content: [ { type: "text", text: ` # Commentaire Reddit ## Détails du commentaire - Auteur: u/${formattedComment.author} - Score: ${formattedComment.stats.score} - Controverse: ${formattedComment.stats.controversiality} ## Contenu ${formattedComment.content} ## Contexte - Subreddit: r/${formattedComment.context.subreddit} - Thread: ${formattedComment.context.thread} ## Métadonnées - Posté: ${formattedComment.metadata.posted} - Drapeaux: ${formattedComment.metadata.flags.length ? formattedComment.metadata.flags.join(", ") : "Aucun"} ## Lien ${formattedComment.link} ## Analyse du commentaire ${formattedComment.commentAnalysis} `, }, ], }; } catch (error) { console.error(`[Error] Error getting comment: ${error}`); throw new McpError( ErrorCode.InternalError, `Failed to fetch comment: ${error}` ); } }
  • src/index.ts:231-242 (registration)
    Registration of the 'get_comment' tool in the MCP server's tool list, including name, description, and input schema.
    name: "get_comment", description: "Accéder à un commentaire spécifique", inputSchema: { type: "object", properties: { comment_id: { type: "string", description: "L'ID du commentaire à récupérer", }, }, required: ["comment_id"], },
  • Dispatch handler in the main tool call switch statement that routes 'get_comment' calls to tools.getComment.
    case "get_comment": return await tools.getComment( toolParams as { comment_id: string } );
  • RedditClient method that performs the actual API call to fetch a specific comment by ID from Reddit's API.
    async getComment(commentId: string): Promise<RedditComment> { await this.authenticate(); try { const response = await this.api.get(`/api/info.json?id=t1_${commentId}`); if (!response.data.data.children.length) { throw new Error(`Comment with ID ${commentId} not found`); } const comment = response.data.data.children[0].data; return { id: comment.id, author: comment.author, body: comment.body, score: comment.score, controversiality: comment.controversiality, subreddit: comment.subreddit, submissionTitle: comment.link_title || "", createdUtc: comment.created_utc, edited: !!comment.edited, isSubmitter: comment.is_submitter, permalink: comment.permalink, }; } catch (error) { console.error(`[Error] Failed to get comment with ID ${commentId}:`, error); throw new Error(`Failed to get comment with ID ${commentId}`); } }

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