Skip to main content
Glama

get_linkedin_post_comments

Retrieve LinkedIn post comments by providing the post URN, with options to sort by relevance or recency and control the number of comments returned.

Instructions

Get LinkedIn comments for a post by URN

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
countYesMax comments to return
sortNoSort type (relevance or recent)relevance
timeoutNoTimeout in seconds
urnYesPost URN, only activity urn type is allowed (example: activity:7234173400267538433)

Implementation Reference

  • Full tool registration and inline handler implementation. Defines input schema with Zod, handles arguments, makes authenticated HTTPS POST request to AnySite API endpoint /api/linkedin/post/comments, returns JSON response or formatted error.
    server.tool(
      "get_linkedin_post_comments",
      "Get LinkedIn post comments",
      {
        urn: z.string().describe("Post URN"),
        count: z.number().default(10).describe("Max comments"),
        timeout: z.number().default(300).describe("Timeout in seconds"),
        sort: z.string().default("relevance").describe("Sort order")
      },
      async ({ urn, count, timeout, sort }) => {
        const requestData = { timeout, urn, sort, count };
        log(`Starting LinkedIn post comments lookup for: ${urn}`);
        try {
          const response = await makeRequest(API_CONFIG.ENDPOINTS.LINKEDIN_POST_COMMENTS, requestData);
          return {
            content: [{ type: "text", text: JSON.stringify(response, null, 2) }]
          };
        } catch (error) {
          log("LinkedIn post comments lookup error:", error);
          return {
            content: [{ type: "text", text: `LinkedIn post comments API error: ${formatError(error)}` }],
            isError: true
          };
        }
      }
    );
  • TypeScript interface defining expected input arguments for the tool, matching the inline Zod schema.
    export interface GetLinkedinPostCommentsArgs {
      urn: string;
      sort?: "relevance" | "recent";
      count?: number;
      timeout?: number;
    }
  • Type guard validation function for tool input arguments, checks urn contains 'activity:', valid sort options, numeric count/timeout.
    export function isValidGetLinkedinPostCommentsArgs(
      args: unknown
    ): args is GetLinkedinPostCommentsArgs {
      if (typeof args !== "object" || args === null) return false;
      const obj = args as Record<string, unknown>;
      if (typeof obj.urn !== "string" || !obj.urn.includes("activity:")) return false;
      if (obj.sort !== undefined && obj.sort !== "relevance" && obj.sort !== "recent") return false;
      if (obj.count !== undefined && typeof obj.count !== "number") return false;
      if (obj.timeout !== undefined && typeof obj.timeout !== "number") return false;
      return true;
    }
  • Shared helper function that performs all API calls to AnySite.io. Handles HTTPS POST requests with authentication (access-token, optional account-id), JSON parsing, and error handling.
    const makeRequest = (endpoint: string, data: any, method: string = "POST"): Promise<any> => {
      return new Promise((resolve, reject) => {
        const url = new URL(endpoint, API_CONFIG.BASE_URL);
        const postData = JSON.stringify(data);
    
        const options = {
          hostname: url.hostname,
          port: url.port || 443,
          path: url.pathname,
          method: method,
          headers: {
            "Content-Type": "application/json",
            "Content-Length": Buffer.byteLength(postData),
            "access-token": API_KEY,
            ...(ACCOUNT_ID && { "x-account-id": ACCOUNT_ID })
          }
        };
    
        const req = https.request(options, (res) => {
          let responseData = "";
          res.on("data", (chunk) => {
            responseData += chunk;
          });
    
          res.on("end", () => {
            try {
              const parsed = JSON.parse(responseData);
              if (res.statusCode && res.statusCode >= 200 && res.statusCode < 300) {
                resolve(parsed);
              } else {
                reject(new Error(`API error ${res.statusCode}: ${JSON.stringify(parsed)}`));
              }
            } catch (e) {
              reject(new Error(`Failed to parse response: ${responseData}`));
            }
          });
        });
    
        req.on("error", (error) => {
          reject(error);
        });
    
        req.write(postData);
        req.end();
      });
    };
  • API configuration object defining base URL and all endpoints. The tool uses API_CONFIG.ENDPOINTS.LINKEDIN_POST_COMMENTS.
    const API_CONFIG = {
      BASE_URL: "https://api.anysite.io",
      ENDPOINTS: {
        SEARCH_USERS: "/api/linkedin/search/users",
        USER_PROFILE: "/api/linkedin/user",
        LINKEDIN_EMAIL: "/api/linkedin/email/user",
        LINKEDIN_USER_POSTS: "/api/linkedin/user/posts",
        LINKEDIN_USER_REACTIONS: "/api/linkedin/user/reactions",
        LINKEDIN_USER_COMMENTS: "/api/linkedin/user/comments",
        LINKEDIN_SEARCH_POSTS: "/api/linkedin/search/posts",
        REDDIT_SEARCH_POSTS: "/api/reddit/search/posts",
        REDDIT_POSTS: "/api/reddit/posts",
        REDDIT_POST_COMMENTS: "/api/reddit/posts/comments",
        CHAT_MESSAGES: "/api/linkedin/management/chat/messages",
        CHAT_MESSAGE: "/api/linkedin/management/chat/message",
        USER_CONNECTION: "/api/linkedin/management/user/connection",
        POST_COMMENT: "/api/linkedin/management/post/comment",
        USER_CONNECTIONS: "/api/linkedin/management/user/connections",
        LINKEDIN_POST_REPOSTS: "/api/linkedin/post/reposts",
        LINKEDIN_POST_COMMENTS: "/api/linkedin/post/comments",
        LINKEDIN_POST_REACTIONS: "/api/linkedin/post/reactions",
        LINKEDIN_GOOGLE_COMPANY: "/api/linkedin/google/company",
        LINKEDIN_COMPANY: "/api/linkedin/company",
        LINKEDIN_COMPANY_EMPLOYEES: "/api/linkedin/company/employees",
        LINKEDIN_COMPANY_POSTS: "/api/linkedin/company/posts",
        LINKEDIN_POST: "/api/linkedin/management/post",
        LINKEDIN_SN_SEARCH_USERS: "/api/linkedin/sn_search/users",
        CONVERSATIONS: "/api/linkedin/management/conversations",
        GOOGLE_SEARCH: "/api/google/search",
        INSTAGRAM_USER: "/api/instagram/user",
        INSTAGRAM_USER_POSTS: "/api/instagram/user/posts",
        INSTAGRAM_POST_COMMENTS: "/api/instagram/post/comments",
        // New LinkedIn endpoints
        LINKEDIN_USER_ENDORSERS: "/api/linkedin/user/endorsers",
        LINKEDIN_USER_CERTIFICATES: "/api/linkedin/user/certificates",
        LINKEDIN_USER_EMAIL_DB: "/api/linkedin/user/email",
        LINKEDIN_MANAGEMENT_ME: "/api/linkedin/management/me",
        // New Instagram endpoints
        INSTAGRAM_POST: "/api/instagram/post",
        INSTAGRAM_POST_LIKES: "/api/instagram/post/likes",
        INSTAGRAM_USER_FRIENDSHIPS: "/api/instagram/user/friendships",
        INSTAGRAM_SEARCH_POSTS: "/api/instagram/search/posts",
        INSTAGRAM_USER_REELS: "/api/instagram/user/reels",
        // Twitter/X endpoints
        TWITTER_USER: "/api/twitter/user",
        TWITTER_SEARCH_USERS: "/api/twitter/search/users",
        TWITTER_USER_POSTS: "/api/twitter/user/posts",
        TWITTER_SEARCH_POSTS: "/api/twitter/search/posts",
        TWITTER_POST: "/api/twitter/post",
        // Web Parser endpoints
        WEBPARSER_PARSE: "/api/webparser/parse",
        WEBPARSER_SITEMAP: "/api/webparser/sitemap"
      }
    };

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/anysiteio/hdw-mcp-server'

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