list_threads
Retrieve discussion threads from an Ed Discussion course with configurable sorting, pagination, and limits for efficient content management.
Instructions
List discussion threads in a course
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| course_id | Yes | Course ID | |
| limit | No | Max threads to return (1-100) | |
| offset | No | Pagination offset | |
| sort | No | Sort order | new |
Implementation Reference
- src/index.ts:103-137 (handler)Registration and handler logic for the "list_threads" MCP tool. It parses input using zod, calls the API client's `listThreads` method, and formats the result.
server.tool( "list_threads", "List discussion threads in a course", { course_id: z.number().describe("Course ID"), limit: z.number().min(1).max(100).default(30).describe("Max threads to return (1-100)"), offset: z.number().min(0).default(0).describe("Pagination offset"), sort: z .enum(["new", "top", "active", "unanswered"]) .default("new") .describe("Sort order"), }, async ({ course_id, limit, offset, sort }) => { try { const threads = await api.listThreads(course_id, { limit, offset, sort }); const summary = threads.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, is_pinned: t.is_pinned, is_private: t.is_private, created_at: t.created_at, user: t.user, })); return ok(summary); } catch (err) { return fail(err); } } ); - src/api.ts:112-128 (helper)API client method that performs the network request to fetch discussion threads.
async listThreads( courseId: number, opts: { limit?: number; offset?: number; sort?: string } = {} ): Promise<EdThread[]> { const params: Record<string, string | number> = {}; if (opts.limit !== undefined) params.limit = opts.limit; if (opts.offset !== undefined) params.offset = opts.offset; if (opts.sort) params.sort = opts.sort; const res = await this.request<EdListThreadsResponse>( "GET", `courses/${courseId}/threads`, undefined, params ); return res.threads; }