search_threads
Find course discussion threads by searching titles, content, or categories to locate relevant academic conversations and resources.
Instructions
Search threads in a course by title, content, or category
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| course_id | Yes | Course ID | |
| query | Yes | Search query (matches title, content, and category) | |
| category | No | Filter by category name (exact match) | |
| limit | No | Max threads to fetch before filtering |
Implementation Reference
- src/index.ts:170-210 (handler)The `search_threads` tool is registered and implemented in `src/index.ts`. It fetches threads using `api.listThreads` and then filters them client-side based on the title, category, subcategory, and content.
server.tool( "search_threads", "Search threads in a course by title, content, or category", { course_id: z.number().describe("Course ID"), query: z.string().describe("Search query (matches title, content, and category)"), category: z.string().optional().describe("Filter by category name (exact match)"), limit: z.number().min(1).max(100).default(50).describe("Max threads to fetch before filtering"), }, async ({ course_id, query, category, limit }) => { try { const threads = await api.listThreads(course_id, { limit, sort: "new" }); const q = query.toLowerCase(); const matches = threads.filter((t) => { if (category && t.category.toLowerCase() !== category.toLowerCase()) { return false; } return ( t.title.toLowerCase().includes(q) || t.category.toLowerCase().includes(q) || t.subcategory.toLowerCase().includes(q) || edXmlToPlainText(t.document ?? "").toLowerCase().includes(q) ); }); const summary = matches.map((t) => ({ id: t.id, number: t.number, type: t.type, title: t.title, category: t.category, subcategory: t.subcategory, reply_count: t.reply_count, is_answered: t.is_answered, created_at: t.created_at, })); return ok(summary); } catch (err) { return fail(err); } } );