Skip to main content
Glama

get_comments

Retrieve comments from a specific BAND post to view community discussions and responses, using the post identifier and band key.

Instructions

Get comments from a specific post in BAND.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
band_keyYesband identifier
post_keyYespost identifier
sortNosort order for comments

Implementation Reference

  • The handler function that implements the core logic for the 'get_comments' tool: resolves band_key and post_key from inputs or URL, fetches comments from BAND API, optionally filters by comment_key, and returns JSON-formatted response.
    export async function handleToolCall(
      band_key: string | undefined,
      post_key: string | undefined,
      sort?: string,
      url?: string
    ) {
      let resolvedBandKey = band_key ? band_key.trim() : undefined;
      let resolvedPostKey = post_key ? post_key.trim() : undefined;
      let targetCommentKey: string | undefined;
    
      if (url) {
        const parsed = parseBandUrl(url);
        if (!resolvedBandKey) resolvedBandKey = parsed.bandKey;
        if (!resolvedPostKey) resolvedPostKey = parsed.postKey;
        targetCommentKey = parsed.commentKey;
      }
    
      if (!resolvedBandKey || !resolvedPostKey) {
        throw new Error(
          "band_key and post_key are required unless a valid BAND url is provided.",
        );
      }
    
      const params: Record<string, unknown> = { band_key: resolvedBandKey, post_key: resolvedPostKey };
      if (sort) params.sort = sort;
    
      const commentsData = await bandApiClient.get<CommentsResponse>(
        "/v2/band/post/comments",
        params
      );
      let payload = commentsData;
    
      if (targetCommentKey) {
        const matched = commentsData.items.filter(
          (item) => item.comment_key === targetCommentKey,
        );
    
        if (matched.length === 0) {
          throw new Error(
            `Comment ${targetCommentKey} was not found in the retrieved page. Try fetching the comments without filtering or adjust pagination.`,
          );
        }
    
        payload = {
          ...commentsData,
          items: matched,
        };
      }
      return {
        content: [
          {
            type: "text",
            text: JSON.stringify(payload, null, 2),
          },
        ],
      };
    }
  • The ToolDefinition object defining the name, description, inputSchema, and outputSchema for the 'get_comments' tool.
    export const ToolDefinition: Tool = {
      name: "get_comments",
      description: "Get comments from a specific post in BAND.",
      inputSchema: {
        type: "object",
        properties: {
          band_key: {
            type: "string",
            title: "Band Key",
            description: "band identifier",
          },
          post_key: {
            type: "string",
            title: "Post Key",
            description: "post identifier",
          },
          sort: {
            type: "string",
            title: "Sort",
            description: "sort order for comments",
          },
          url: {
            type: "string",
            title: "Comment URL",
            description:
              "Full BAND URL to the post or comment (e.g., https://band.us/band/{band_key}/post/{post_key}?commentId={comment_key}).",
          },
        },
        anyOf: [
          { required: ["band_key", "post_key"] },
          { required: ["url"] },
        ],
      },
      outputSchema: {
        type: "object",
        properties: {
          result_code: {
            type: "number",
            description: "Result code",
          },
          result_data: {
            type: "object",
            description: "Result data",
            properties: {
              paging: {
                type: "object",
                description: "Paging information",
              },
              items: {
                type: "array",
                description: "List of comments",
                items: {
                  type: "object",
                  properties: {
                    comment_key: {
                      type: "string",
                      description: "comment identifier",
                    },
                    content: {
                      type: "string",
                      description: "comment content",
                    },
                    created_at: {
                      type: "number",
                      description: "comment created time",
                    },
                    author: {
                      type: "object",
                      description: "comment author",
                      properties: {
                        name: {
                          type: "string",
                          description: "author name",
                        },
                        description: {
                          type: "string",
                          description: "author description",
                        },
                        profile_image_url: {
                          type: "string",
                          description: "author profile image url",
                        },
                      },
                    },
                  },
                },
              },
            },
          },
        },
        required: ["result_code", "result_data"],
      },
    };
  • src/tools.ts:15-28 (registration)
    Registration of the 'get_comments' tool (imported as comments.ToolDefinition) in the central bandTools array exported for MCP tool setup.
    export const bandTools: Tool[] = [
      profile.ToolDefinition,
      bands.ToolDefinition,
      posts.ToolDefinition,
      post.ToolDefinition,
      comments.ToolDefinition,
      permissions.ToolDefinition,
      albums.ToolDefinition,
      photos.ToolDefinition,
      writeComment.ToolDefinition,
      writePost.ToolDefinition,
      removePost.ToolDefinition,
      removeComment.ToolDefinition,
    ];
  • src/tools.ts:48-54 (registration)
    Switch case in the main handleToolCall dispatcher that routes calls to the 'get_comments' handler in the comments module.
    case "get_comments":
      return comments.handleToolCall(
        a.band_key as string | undefined,
        a.post_key as string | undefined,
        a.sort as string | undefined,
        a.url as string | undefined
      );

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/kanghouchao/band-mcp-server'

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