get_subreddit_info
Retrieve subreddit details like description, subscriber count, and rules to analyze community data from Reddit's API.
Instructions
Get information about a subreddit
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| subreddit | Yes | Name of the subreddit (without r/ prefix) |
Implementation Reference
- src/reddit-client.ts:150-153 (handler)Core handler function that authenticates, makes API request to Reddit for subreddit info, and maps the response to a structured RedditSubreddit object.async getSubredditInfo(subreddit: string): Promise<RedditSubreddit> { const data = await this.makeRequest(`/r/${subreddit}/about`); return this.mapSubreddit(data.data); }
- src/index.ts:53-55 (schema)Zod schema for validating input parameters (subreddit name) to the get_subreddit_info tool.const GetSubredditInfoSchema = z.object({ subreddit: z.string().min(1, "Subreddit name is required"), });
- src/index.ts:150-163 (registration)Tool registration in the MCP server's listTools response, defining name, description, and input schema.{ name: 'get_subreddit_info', description: 'Get information about a subreddit', inputSchema: { type: 'object', properties: { subreddit: { type: 'string', description: 'Name of the subreddit (without r/ prefix)', }, }, required: ['subreddit'], }, },
- src/index.ts:335-346 (handler)MCP dispatch handler case that parses arguments using the schema, calls the RedditClient handler, and formats the JSON response.case 'get_subreddit_info': { const args = GetSubredditInfoSchema.parse(request.params.arguments); const subreddit = await redditClient.getSubredditInfo(args.subreddit); return { content: [ { type: 'text', text: JSON.stringify(subreddit, null, 2), }, ], }; }
- src/reddit-client.ts:31-40 (schema)TypeScript interface defining the output structure for subreddit information returned by the handler.export interface RedditSubreddit { display_name: string; title: string; description: string; subscribers: number; created_utc: number; public_description: string; url: string; over18: boolean; }