Skip to main content
Glama

reddit-mcp-server

search-tools.ts1.78 kB
import { getRedditClient } from "../client/reddit-client" import { formatPost } from "../utils/formatters" import { UserError } from "fastmcp" export async function searchReddit(params: { query: string subreddit?: string sort?: string time_filter?: string limit?: number type?: string }) { const { query, subreddit, sort = "relevance", time_filter = "all", limit = 10, type = "link" } = params const client = getRedditClient() if (!client) { throw new UserError("Reddit client not initialized") } if (!query || query.trim().length === 0) { throw new UserError("Search query cannot be empty") } try { const posts = await client.searchReddit(query, { subreddit, sort, timeFilter: time_filter, limit, type, }) return { content: [ { type: "text", text: `# Reddit Search Results for: "${query}"${subreddit ? ` in r/${subreddit}` : ""} ## Search Parameters - Sort: ${sort} - Time Filter: ${time_filter} - Type: ${type} - Results: ${posts.length} ${posts .map((post, index) => { const formatted = formatPost(post) return `### ${index + 1}. ${formatted.title} - Author: u/${formatted.author} - Subreddit: r/${formatted.subreddit} - Score: ${formatted.score} (${formatted.upvoteRatio}% upvoted) - Comments: ${formatted.numComments} - Posted: ${formatted.createdAt} ${formatted.selftext ? `\n${formatted.selftext.substring(0, 200)}${formatted.selftext.length > 200 ? "..." : ""}\n` : ""} - Link: https://reddit.com${formatted.permalink} ${formatted.nsfw ? "- **NSFW**" : ""} ${formatted.spoiler ? "- **Spoiler**" : ""} ` }) .join("\n")}`, }, ], } } catch (error) { throw new UserError(`Failed to search Reddit: ${String(error)}`) } }

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/jordanburke/reddit-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server