reddit_subreddit
Extract and automatically parse Reddit subreddit posts by providing the subreddit URL.
Instructions
Scrape Reddit subreddit results with automatic parsing
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| url | Yes | URL to subreddit |
Implementation Reference
- The handler function that executes the tool logic: takes scraping params with a 'url', calls the ScraperAPI client with target REDDIT_SUBREDDIT, transforms the response by removing high-char-count fields like 'preview' and 'media_metadata', and returns the result as text content.
async (scrapingParams: ScrapingMCPParams, extra: ProgressExtra) => { const params = { ...scrapingParams, target: SCRAPER_API_TARGETS.REDDIT_SUBREDDIT, } satisfies ScraperAPIParams; const { data } = await sapiClient.scrape<object>({ auth, scrapingParams: params, extra }); const { data: text } = this.transformResponse({ data }); return { content: [ { type: 'text', text, }, ], }; } ); }; - The transformResponse method that strips 'preview' and 'media_metadata' fields from the scraped data (to reduce payload size) and stringifies the result.
transformResponse = ({ data }: { data: object }) => { for (const fieldToRemove of RedditSubredditTool.FIELDS_WITH_HIGH_CHAR_COUNT) { data = removeKeyFromNestedObject({ obj: data, keyToRemove: fieldToRemove }); } return { data: JSON.stringify(data) }; }; - Input schema for the tool: requires a single 'url' string parameter describing the subreddit URL.
inputSchema: { url: z.string().describe('URL to subreddit'), }, - src/tools/reddit-subreddit/reddit-subreddit-tool.ts:20-52 (registration)The register method that registers the tool named 'reddit_subreddit' with the MCP server, including input schema, annotations (readOnlyHint, openWorldHint), and the handler callback.
register = ({ server, sapiClient, auth }: ToolRegistrationArgs) => { server.registerTool( 'reddit_subreddit', { description: 'Scrape Reddit subreddit results with automatic parsing', inputSchema: { url: z.string().describe('URL to subreddit'), }, annotations: { readOnlyHint: true, openWorldHint: true, }, }, async (scrapingParams: ScrapingMCPParams, extra: ProgressExtra) => { const params = { ...scrapingParams, target: SCRAPER_API_TARGETS.REDDIT_SUBREDDIT, } satisfies ScraperAPIParams; const { data } = await sapiClient.scrape<object>({ auth, scrapingParams: params, extra }); const { data: text } = this.transformResponse({ data }); return { content: [ { type: 'text', text, }, ], }; } ); - src/server/sapi-base-server.ts:92-93 (registration)Instantiation of RedditSubredditTool in the allTools array of the base server, which is later registered via registerTools/registerAllTools.
new RedditSubredditTool(), new RedditUserTool(),