reddit_user
Scrape a Reddit user's profile, posts, and comments by providing their user profile URL.
Instructions
Scrape a Reddit user profile and their posts/comments
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| url | Yes | Reddit user profile URL (eg. https://www.reddit.com/user/IWasRightOnce/) |
Implementation Reference
- The async handler function executed when the 'reddit_user' tool is called. It receives scraping params, calls the ScraperApiClient with the REDDIT_USER target, transforms the response by removing high-character-count fields, and returns the data as text content.
async (scrapingParams: ScrapingMCPParams, extra: ProgressExtra) => { const params = { ...scrapingParams, target: SCRAPER_API_TARGETS.REDDIT_USER, } satisfies ScraperAPIParams; const { data } = await sapiClient.scrape<object>({ auth, scrapingParams: params, extra }); const { data: text } = this.transformResponse({ data }); return { content: [ { type: 'text', text, }, ], }; } - Input schema defined via Zod: requires a 'url' string (the Reddit user profile URL) and includes annotations (readOnlyHint, openWorldHint).
inputSchema: { url: z .string() .describe('Reddit user profile URL (eg. https://www.reddit.com/user/IWasRightOnce/)'), }, - src/tools/reddit-user/reddit-user-tool.ts:24-59 (registration)The 'register' method that calls server.registerTool with the name 'reddit_user', description, input schema, and the handler function.
register = ({ server, sapiClient, auth }: ToolRegistrationArgs) => { server.registerTool( 'reddit_user', { description: 'Scrape a Reddit user profile and their posts/comments', inputSchema: { url: z .string() .describe('Reddit user profile URL (eg. https://www.reddit.com/user/IWasRightOnce/)'), }, annotations: { readOnlyHint: true, openWorldHint: true, }, }, async (scrapingParams: ScrapingMCPParams, extra: ProgressExtra) => { const params = { ...scrapingParams, target: SCRAPER_API_TARGETS.REDDIT_USER, } 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:93-97 (registration)Instantiation of RedditUserTool in the allTools array, which is later iterated to register all tools on the server.
new RedditUserTool(), new BingSearchTool(), new ChatGPTTool(), new PerplexityTool(), ]; - The transformResponse method that removes high-character-count fields (author_flair_richtext, preview, media_metadata) from the scraped data to reduce payload size.
transformResponse = ({ data }: { data: object }) => { for (const fieldToRemove of RedditUserTool.FIELDS_WITH_HIGH_CHAR_COUNT) { data = removeKeyFromNestedObject({ obj: data, keyToRemove: fieldToRemove }); } return { data: JSON.stringify(data) }; };