get_subreddit
Access a subreddit by name to retrieve its content and information for analysis or interaction.
Instructions
Accéder à un subreddit par nom
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| subreddit_name | Yes | Le nom du subreddit |
Implementation Reference
- src/tools/search-tools.ts:177-236 (handler)The primary handler function for the 'get_subreddit' MCP tool. It retrieves subreddit data using the Reddit client, formats it with formatSubredditInfo, and returns a formatted text response with details like stats, description, metadata, links, analysis, and engagement tips.export async function getSubreddit(params: { subreddit_name: string }) { const { subreddit_name } = params; const client = getRedditClient(); if (!client) { throw new McpError( ErrorCode.InternalError, "Reddit client not initialized" ); } try { console.log(`[Tool] Getting subreddit r/${subreddit_name}`); const subreddit = await client.getSubreddit(subreddit_name); const formattedSubreddit = formatSubredditInfo(subreddit); return { content: [ { type: "text", text: ` # r/${formattedSubreddit.name} ## Informations générales - Titre: ${formattedSubreddit.title} - Abonnés: ${formattedSubreddit.stats.subscribers.toLocaleString()} - Utilisateurs actifs: ${formattedSubreddit.stats.activeUsers} ## Description ### Description courte ${formattedSubreddit.description.short} ### Description complète ${formattedSubreddit.description.full} ## Métadonnées - Créé: ${formattedSubreddit.metadata.created} - Drapeaux: ${formattedSubreddit.metadata.flags.length ? formattedSubreddit.metadata.flags.join(", ") : "Aucun"} ## Liens - Subreddit: ${formattedSubreddit.links.subreddit} - Wiki: ${formattedSubreddit.links.wiki} ## Analyse de la communauté ${formattedSubreddit.communityAnalysis} ## Conseils d'engagement ${formattedSubreddit.engagementTips} `, }, ], }; } catch (error) { console.error(`[Error] Error getting subreddit: ${error}`); throw new McpError( ErrorCode.InternalError, `Failed to fetch subreddit: ${error}` ); } }
- src/index.ts:277-290 (registration)Registration of the 'get_subreddit' tool in the ListToolsRequestHandler, including the tool name, description, and input schema definition.{ name: "get_subreddit", description: "Accéder à un subreddit par nom", inputSchema: { type: "object", properties: { subreddit_name: { type: "string", description: "Le nom du subreddit", }, }, required: ["subreddit_name"], }, },
- src/index.ts:488-491 (registration)Dispatch logic in the CallToolRequestHandler switch statement that routes calls to the 'get_subreddit' tool to the imported tools.getSubreddit handler function.case "get_subreddit": return await tools.getSubreddit( toolParams as { subreddit_name: string } );
- src/tools/index.ts:4-5 (helper)Re-export of functions from search-tools.ts (including getSubreddit) in the tools index module, allowing centralized import as 'tools.getSubreddit' from src/index.ts.export * from "./search-tools";
- src/index.ts:280-289 (schema)Input schema definition for the 'get_subreddit' tool, specifying the required 'subreddit_name' parameter.inputSchema: { type: "object", properties: { subreddit_name: { type: "string", description: "Le nom du subreddit", }, }, required: ["subreddit_name"], },