Skip to main content
Glama

Get Discussions

get_discussions

Retrieve discussion board content for a course, including forums, topics, and posts. Use courseId to list all forums, or add forumId and topicId to drill into specific topics and posts.

Instructions

Fetch discussion board content for a course including forums, topics, and posts. Use this when the user asks about discussion boards, forum posts, class discussions, or wants to see what's been posted. Provide just courseId to list all forums and their topics. Add forumId to get topics and posts for a specific forum. Add both forumId and topicId to get all posts in a specific discussion topic.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
courseIdYesCourse ID to get discussion boards for.
forumIdNoSpecific forum ID to get topics and posts for. If omitted, returns all forums.
topicIdNoSpecific topic ID to get posts for. Requires forumId.

Implementation Reference

  • The main handler registration function (registerGetDiscussions) and all helper functions (getForumsOverview, getForumDetail, getTopicPosts, formatPosts) that execute the get_discussions tool logic. It fetches discussion board data from Brightspace D2L API — forums, topics, and posts — with three levels of detail based on provided parameters.
    export function registerGetDiscussions(
      server: McpServer,
      apiClient: D2LApiClient
    ): void {
      server.registerTool(
        "get_discussions",
        {
          title: "Get Discussions",
          description:
            "Fetch discussion board content for a course including forums, topics, and posts. Use this when the user asks about discussion boards, forum posts, class discussions, or wants to see what's been posted. Provide just courseId to list all forums and their topics. Add forumId to get topics and posts for a specific forum. Add both forumId and topicId to get all posts in a specific discussion topic.",
          inputSchema: GetDiscussionsSchema,
        },
        async (args: any) => {
          try {
            log("DEBUG", "get_discussions tool called", { args });
    
            const { courseId, forumId, topicId } = GetDiscussionsSchema.parse(args);
    
            // topicId requires forumId
            if (topicId !== undefined && forumId === undefined) {
              return errorResponse(
                "topicId requires forumId. Provide both forumId and topicId to get posts for a specific topic."
              );
            }
    
            // Specific topic — get posts
            if (forumId !== undefined && topicId !== undefined) {
              return await getTopicPosts(apiClient, courseId, forumId, topicId);
            }
    
            // Specific forum — get its topics + posts
            if (forumId !== undefined) {
              return await getForumDetail(apiClient, courseId, forumId);
            }
    
            // All forums overview
            return await getForumsOverview(apiClient, courseId);
          } catch (error) {
            return sanitizeError(error);
          }
        }
      );
    }
    
    /**
     * Get all forums for a course with their topics (no posts).
     */
    async function getForumsOverview(
      apiClient: D2LApiClient,
      courseId: number
    ): Promise<any> {
      const forumsPath = apiClient.le(courseId, "/discussions/forums/");
      const forums = await apiClient.get<D2LForum[]>(forumsPath, {
        ttl: DEFAULT_CACHE_TTLS.courseContent,
      });
    
      const result = [];
    
      for (const forum of forums) {
        // Fetch topics for each forum
        let topics: D2LTopic[] = [];
        try {
          const topicsPath = apiClient.le(
            courseId,
            `/discussions/forums/${forum.ForumId}/topics/`
          );
          topics = await apiClient.get<D2LTopic[]>(topicsPath, {
            ttl: DEFAULT_CACHE_TTLS.courseContent,
          });
        } catch (error: any) {
          if (error?.status === 403) {
            log("DEBUG", `No access to topics for forum ${forum.ForumId}, skipping`);
          } else {
            log("DEBUG", `Failed to fetch topics for forum ${forum.ForumId}`, error);
          }
        }
    
        result.push({
          forumId: forum.ForumId,
          name: forum.Name,
          description: forum.Description?.Text ?? null,
          isLocked: forum.IsLocked,
          isHidden: forum.IsHidden,
          topics: topics.map((t) => ({
            topicId: t.TopicId,
            forumId: t.ForumId,
            name: t.Name,
            description: t.Description?.Text ?? null,
            dueDate: t.DueDate,
            isLocked: t.IsLocked,
            isHidden: t.IsHidden,
            mustPostToParticipate: t.MustPostToParticipate,
            scoreOutOf: t.ScoreOutOf,
          })),
        });
      }
    
      log(
        "INFO",
        `get_discussions: Retrieved ${forums.length} forums for course ${courseId}`
      );
    
      return toolResponse({
        courseId,
        forumCount: result.length,
        forums: result,
      });
    }
    
    /**
     * Get a specific forum with its topics and posts.
     */
    async function getForumDetail(
      apiClient: D2LApiClient,
      courseId: number,
      forumId: number
    ): Promise<any> {
      // Fetch forum info
      const forumPath = apiClient.le(
        courseId,
        `/discussions/forums/${forumId}`
      );
      const forum = await apiClient.get<D2LForum>(forumPath, {
        ttl: DEFAULT_CACHE_TTLS.courseContent,
      });
    
      // Fetch topics
      const topicsPath = apiClient.le(
        courseId,
        `/discussions/forums/${forumId}/topics/`
      );
      const topics = await apiClient.get<D2LTopic[]>(topicsPath, {
        ttl: DEFAULT_CACHE_TTLS.courseContent,
      });
    
      // Fetch posts for each topic
      const topicsWithPosts = [];
      for (const topic of topics) {
        let posts: D2LPost[] = [];
        try {
          const postsPath = apiClient.le(
            courseId,
            `/discussions/forums/${forumId}/topics/${topic.TopicId}/posts/`
          );
          posts = await apiClient.get<D2LPost[]>(postsPath, {
            ttl: DEFAULT_CACHE_TTLS.announcements,
          });
        } catch (error: any) {
          if (error?.status === 403) {
            log("DEBUG", `No access to posts for topic ${topic.TopicId}, skipping`);
          } else {
            log("DEBUG", `Failed to fetch posts for topic ${topic.TopicId}`, error);
          }
        }
    
        topicsWithPosts.push({
          topicId: topic.TopicId,
          name: topic.Name,
          description: topic.Description?.Html
            ? convertHtmlToMarkdown(topic.Description.Html).markdown
            : topic.Description?.Text ?? null,
          dueDate: topic.DueDate,
          isLocked: topic.IsLocked,
          mustPostToParticipate: topic.MustPostToParticipate,
          scoreOutOf: topic.ScoreOutOf,
          postCount: posts.length,
          posts: formatPosts(posts),
        });
      }
    
      log(
        "INFO",
        `get_discussions: Retrieved forum ${forumId} with ${topics.length} topics for course ${courseId}`
      );
    
      return toolResponse({
        courseId,
        forum: {
          forumId: forum.ForumId,
          name: forum.Name,
          description: forum.Description?.Text ?? null,
          isLocked: forum.IsLocked,
          isHidden: forum.IsHidden,
        },
        topicCount: topicsWithPosts.length,
        topics: topicsWithPosts,
      });
    }
    
    /**
     * Get all posts for a specific topic.
     */
    async function getTopicPosts(
      apiClient: D2LApiClient,
      courseId: number,
      forumId: number,
      topicId: number
    ): Promise<any> {
      // Fetch topic info
      const topicPath = apiClient.le(
        courseId,
        `/discussions/forums/${forumId}/topics/${topicId}`
      );
      const topic = await apiClient.get<D2LTopic>(topicPath, {
        ttl: DEFAULT_CACHE_TTLS.courseContent,
      });
    
      // Fetch posts
      const postsPath = apiClient.le(
        courseId,
        `/discussions/forums/${forumId}/topics/${topicId}/posts/`
      );
      const posts = await apiClient.get<D2LPost[]>(postsPath, {
        ttl: DEFAULT_CACHE_TTLS.announcements,
      });
    
      log(
        "INFO",
        `get_discussions: Retrieved ${posts.length} posts for topic ${topicId} in forum ${forumId}`
      );
    
      return toolResponse({
        courseId,
        forumId,
        topic: {
          topicId: topic.TopicId,
          name: topic.Name,
          description: topic.Description?.Html
            ? convertHtmlToMarkdown(topic.Description.Html).markdown
            : topic.Description?.Text ?? null,
          dueDate: topic.DueDate,
          isLocked: topic.IsLocked,
          mustPostToParticipate: topic.MustPostToParticipate,
          scoreOutOf: topic.ScoreOutOf,
        },
        postCount: posts.length,
        posts: formatPosts(posts),
      });
    }
    
    /**
     * Format posts into a clean thread structure.
     */
    function formatPosts(posts: D2LPost[]): any[] {
      return posts
        .filter((p) => !p.IsDeleted)
        .map((p) => ({
          postId: p.PostId,
          threadId: p.ThreadId,
          parentPostId: p.ParentPostId,
          subject: p.Subject,
          message: p.Message?.Html
            ? convertHtmlToMarkdown(p.Message.Html).markdown
            : p.Message?.Text ?? "",
          author: p.IsAnonymous ? "Anonymous" : p.PostingUserDisplayName,
          datePosted: p.DatePosted,
          lastEditedDate: p.LastEditedDate,
          replyCount: p.ReplyPostIds?.length ?? 0,
          wordCount: p.WordCount,
          attachmentCount: p.AttachmentCount,
          isRead: p.IsRead,
        }))
        .sort(
          (a, b) =>
            new Date(a.datePosted).getTime() - new Date(b.datePosted).getTime()
        );
    }
  • Zod schema (GetDiscussionsSchema) defining input validation: courseId (required), forumId (optional), topicId (optional, requires forumId).
    export const GetDiscussionsSchema = z.object({
      courseId: z.coerce.number().int().positive()
        .describe("Course ID to get discussion boards for."),
      forumId: z.coerce.number().int().positive().optional()
        .describe("Specific forum ID to get topics and posts for. If omitted, returns all forums."),
      topicId: z.coerce.number().int().positive().optional()
        .describe("Specific topic ID to get posts for. Requires forumId."),
    });
  • src/index.ts:31-32 (registration)
    Import of registerGetDiscussions from tools/index.ts.
      registerGetDiscussions,
    } from "./tools/index.js";
  • src/index.ts:189-189 (registration)
    Registration call: registerGetDiscussions(server, apiClient) invoked during server startup.
    registerGetDiscussions(server, apiClient);
  • Barrel re-export of registerGetDiscussions from the tools module.
    export { registerGetDiscussions } from "./get-discussions.js";
    
    // Re-export shared helpers and schemas for convenience
    export { toolResponse, errorResponse, sanitizeError } from "./tool-helpers.js";
    export * from "./schemas.js";
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations provided. Description focuses on functionality without mentioning behavioral traits like read-only nature, authentication needs, or side effects. For a fetch operation, this is adequate but could be more transparent.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Three sentences. Front-loaded with purpose. No redundant information. Efficiently conveys parameter combinations and usage guidance.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given 100% schema coverage, no output schema, and no annotations, the description is complete for a simple fetch tool. It covers all parameter scenarios. Lacks mention of return format or whether it's read-only, but these are not critical for this tool.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema already covers all parameters with descriptions. Description adds significant value by explaining how parameters interact hierarchically (e.g., just courseId lists forums, add forumId for topics, add topicId for posts). This clarifies usage beyond individual field descriptions.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

Description clearly states the verb 'Fetch' and resource 'discussion board content for a course including forums, topics, and posts'. It distinguishes from sibling tools like get_announcements and get_assignments which cover different content.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Explicitly states when to use: 'when the user asks about discussion boards, forum posts, class discussions, or wants to see what's been posted.' Provides parameter usage patterns but does not mention when not to use.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

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/RohanMuppa/brightspace-mcp-server'

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