Skip to main content
Glama
wspotter

MCP Art Supply Store

by wspotter

get_social_analytics

Analyze Facebook and Instagram performance metrics including reach, engagement, and top-performing posts to measure social media effectiveness.

Instructions

Get performance analytics from Facebook and Instagram including reach, engagement, and top posts.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
periodNoNumber of days to analyze (default: 7)
platformYesPlatform: facebook or instagram

Implementation Reference

  • The primary handler logic for the 'get_social_analytics' tool. It checks configuration, parses input parameters (platform and period), calls socialMediaManager.getFacebookAnalytics for Facebook, and formats the response with metrics and top posts.
    case 'get_social_analytics': {
      if (!socialMediaManager.isConfigured()) {
        return {
          content: [{
            type: 'text',
            text: `āš ļø Social media not configured. See FACEBOOK_INSTAGRAM_SETUP.md for setup instructions.`
          }]
        };
      }
    
      const platform = String(args?.platform || 'facebook');
      const period = Number(args?.period || 7);
    
      try {
        if (platform.toLowerCase() === 'facebook') {
          const analytics = await socialMediaManager.getFacebookAnalytics(period);
          
          return {
            content: [{
              type: 'text',
              text: `šŸ“Š Facebook Analytics - ${analytics.period}\n\nšŸ“ˆ Performance Metrics:\n  šŸ‘„ Reach: ${analytics.metrics.reach.toLocaleString()}\n  šŸ‘ļø Impressions: ${analytics.metrics.impressions.toLocaleString()}\n  šŸ’¬ Engagement: ${analytics.metrics.engagement.toLocaleString()}\n  ⭐ Followers: ${analytics.metrics.followers.toLocaleString()}\n\nšŸ† Top Posts:\n${analytics.topPosts.map((post, i) =>
                `${i + 1}. ${post.content}\n   ā¤ļø ${post.likes} | šŸ’¬ ${post.comments} | šŸ”„ ${post.shares}`
              ).join('\n\n')}\n\nšŸ’” Insight: Post more content like your top performers to boost engagement!`
            }]
          };
        } else {
          return {
            content: [{
              type: 'text',
              text: `šŸ“Š Instagram Analytics coming soon! Currently only Facebook analytics are available.`
            }]
          };
        }
      } catch (error: any) {
        return {
          content: [{
            type: 'text',
            text: `āŒ Failed to fetch analytics: ${error.message}`
          }]
        };
      }
    }
  • The tool's input schema definition, specifying required 'platform' parameter and optional 'period' for the number of days.
    {
      name: 'get_social_analytics',
      description: 'Get performance analytics from Facebook and Instagram including reach, engagement, and top posts.',
      inputSchema: {
        type: 'object',
        properties: {
          platform: { type: 'string', description: 'Platform: facebook or instagram' },
          period: { type: 'number', description: 'Number of days to analyze (default: 7)' },
        },
        required: ['platform'],
      },
    },
  • Core helper function getFacebookAnalytics that fetches page insights and posts from Facebook Graph API, parses metrics like reach, impressions, engagement, followers, and top performing posts.
    async getFacebookAnalytics(days: number = 7): Promise<Analytics> {
      if (!this.isConfigured()) {
        throw new Error('Facebook API not configured');
      }
    
      try {
        // Get page insights
        const insightsUrl = `https://graph.facebook.com/${this.apiVersion}/${this.fbPageId}/insights`;
        const params = new URLSearchParams({
          metric: 'page_impressions,page_engaged_users,page_fans',
          period: 'day',
          since: Math.floor((Date.now() - (days * 24 * 60 * 60 * 1000)) / 1000).toString(),
          access_token: this.fbPageToken
        });
    
        const response = await fetch(`${insightsUrl}?${params}`);
        const result = await response.json() as any;
    
        // Get recent posts for top posts
        const postsUrl = `https://graph.facebook.com/${this.apiVersion}/${this.fbPageId}/posts`;
        const postsParams = new URLSearchParams({
          fields: 'message,likes.summary(true),comments.summary(true),shares',
          limit: '10',
          access_token: this.fbPageToken
        });
    
        const postsResponse = await fetch(`${postsUrl}?${postsParams}`);
        const postsResult = await postsResponse.json() as any;
    
        // Parse metrics
        let reach = 0;
        let engagement = 0;
        let followers = 0;
    
        if (result.data) {
          for (const metric of result.data) {
            if (metric.name === 'page_impressions' && metric.values.length > 0) {
              reach = metric.values.reduce((sum: number, v: any) => sum + (v.value || 0), 0);
            }
            if (metric.name === 'page_engaged_users' && metric.values.length > 0) {
              engagement = metric.values.reduce((sum: number, v: any) => sum + (v.value || 0), 0);
            }
            if (metric.name === 'page_fans' && metric.values.length > 0) {
              followers = metric.values[metric.values.length - 1].value || 0;
            }
          }
        }
    
        // Parse top posts
        const topPosts = [];
        if (postsResult.data) {
          for (const post of postsResult.data.slice(0, 5)) {
            topPosts.push({
              id: post.id,
              content: (post.message || '').substring(0, 100) + '...',
              likes: post.likes?.summary?.total_count || 0,
              comments: post.comments?.summary?.total_count || 0,
              shares: post.shares?.count || 0
            });
          }
        }
    
        return {
          platform: 'facebook',
          period: `last ${days} days`,
          metrics: {
            reach: reach,
            impressions: reach, // Simplified
            engagement: engagement,
            followers: followers,
            followerGrowth: 0 // Would need historical comparison
          },
          topPosts: topPosts
        };
      } catch (error: any) {
        throw new Error(`Failed to fetch analytics: ${error.message}`);
      }
    }
  • TypeScript interface defining the structure of the Analytics object returned by getFacebookAnalytics, used for output validation.
    interface Analytics {
      platform: string;
      period: string;
      metrics: {
        reach: number;
        impressions: number;
        engagement: number;
        followers: number;
        followerGrowth: number;
      };
      topPosts: Array<{
        id: string;
        content: string;
        likes: number;
        comments: number;
        shares: number;
      }>;
    }
  • src/index.ts:516-518 (registration)
    Registration of all tools including 'get_social_analytics' via the ListToolsRequestSchema handler that returns the tools array containing the tool definition.
    server.setRequestHandler(ListToolsRequestSchema, async () => {
      return { tools };
    });
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It mentions what data is retrieved (reach, engagement, top posts) but doesn't cover critical aspects like authentication requirements, rate limits, data freshness, error handling, or output format. For a data retrieval tool with zero annotation coverage, this leaves significant gaps in understanding how it behaves.

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?

The description is a single, efficient sentence that front-loads the core purpose with no wasted words. It directly states what the tool does and includes key details (platforms and metrics) without unnecessary elaboration.

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

Completeness3/5

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

Given no annotations and no output schema, the description is moderately complete for a simple retrieval tool. It covers the what (analytics) and scope (platforms/metrics), but lacks behavioral context and output details. For a tool with 2 parameters and 100% schema coverage, it's adequate but could better address missing annotation information.

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

Parameters3/5

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

Schema description coverage is 100%, with both parameters ('period' and 'platform') well-documented in the schema. The description adds no additional parameter semantics beyond implying analytics are for Facebook/Instagram, which the schema already specifies. This meets the baseline of 3 since the schema does the heavy lifting.

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

Purpose4/5

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

The description clearly states the tool's purpose: 'Get performance analytics from Facebook and Instagram including reach, engagement, and top posts.' It specifies the action (get), resource (performance analytics), and scope (Facebook/Instagram with specific metrics). However, it doesn't explicitly differentiate from sibling tools like 'get_sales_report' or 'track_competitor_activity' that might also involve analytics.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites, compare to siblings like 'analyze_post_performance' or 'get_instagram_story_ideas', or specify scenarios where this tool is preferred. The agent must infer usage from the purpose alone.

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/wspotter/mcpart'

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