Skip to main content
Glama
wspotter

MCP Art Supply Store

by wspotter

post_to_social_media

Schedule and publish content to Facebook and Instagram with optional images and hashtags for social media marketing.

Instructions

Post content to Facebook and/or Instagram. Requires Meta API configuration. Can schedule posts for future publishing.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
hashtagsNoOptional: Comma-separated hashtags (without # symbol)
imageUrlNoOptional: URL to image (required for Instagram)
messageYesPost caption/message
platformsYesComma-separated platforms: facebook, instagram, or both
scheduleTimeNoOptional: Schedule for future (YYYY-MM-DD HH:MM format)

Implementation Reference

  • Handler function for 'post_to_social_media' tool. Checks configuration, parses input, calls appropriate platform posters (Facebook/Instagram), collects results, and returns formatted response with success/failure status.
    case 'post_to_social_media': {
      if (!socialMediaManager.isConfigured()) {
        return {
          content: [{
            type: 'text',
            text: `āš ļø Social media not configured yet!\n\nTo use this feature:\n1. Create a Facebook Business account\n2. Create a Facebook App\n3. Get your access tokens\n4. Add them to your .env file\n\nSee FACEBOOK_INSTAGRAM_SETUP.md for detailed instructions.`
          }]
        };
      }
    
      const platforms = String(args?.platforms || 'facebook').toLowerCase().split(',').map(p => p.trim());
      const message = String(args?.message || '');
      const imageUrl = args?.imageUrl ? String(args.imageUrl) : undefined;
      const hashtags = args?.hashtags ? String(args.hashtags).split(',').map(h => h.trim()) : undefined;
      const scheduleTime = args?.scheduleTime ? String(args.scheduleTime) : undefined;
    
      const results = [];
      
      for (const platform of platforms) {
        if (platform === 'facebook' || platform === 'both') {
          const result = await socialMediaManager.postToFacebook({
            platform: 'facebook',
            message,
            imageUrl,
            scheduledTime: scheduleTime
          });
          results.push(result);
        }
        
        if (platform === 'instagram' || platform === 'both') {
          const result = await socialMediaManager.postToInstagram({
            platform: 'instagram',
            message,
            imageUrl,
            hashtags
          });
          results.push(result);
        }
      }
    
      const successCount = results.filter(r => r.success).length;
      const failedResults = results.filter(r => !r.success);
    
      return {
        content: [{
          type: 'text',
          text: `šŸ“± Social Media Post Results\n\nāœ… ${successCount}/${results.length} successful\n\n${results.map(r =>
            r.success 
              ? `āœ“ ${r.platform}: Posted${r.scheduledTime ? ` (scheduled for ${r.scheduledTime})` : ''}\n  Post ID: ${r.postId}`
              : `āœ— ${r.platform}: Failed - ${r.error}`
          ).join('\n\n')}${failedResults.length > 0 ? '\n\nšŸ’” Tip: Check your API tokens and permissions if posts failed.' : ''}`
        }]
      };
    }
  • Tool schema definition including name, description, and inputSchema for validation in MCP server.
      name: 'post_to_social_media',
      description: 'Post content to Facebook and/or Instagram. Requires Meta API configuration. Can schedule posts for future publishing.',
      inputSchema: {
        type: 'object',
        properties: {
          platforms: { type: 'string', description: 'Comma-separated platforms: facebook, instagram, or both' },
          message: { type: 'string', description: 'Post caption/message' },
          imageUrl: { type: 'string', description: 'Optional: URL to image (required for Instagram)' },
          hashtags: { type: 'string', description: 'Optional: Comma-separated hashtags (without # symbol)' },
          scheduleTime: { type: 'string', description: 'Optional: Schedule for future (YYYY-MM-DD HH:MM format)' },
        },
        required: ['platforms', 'message'],
      },
    },
  • src/index.ts:516-518 (registration)
    Registration of tool list handler, which returns the full tools array including 'post_to_social_media'.
    server.setRequestHandler(ListToolsRequestSchema, async () => {
      return { tools };
    });
  • postToFacebook helper method: Posts to Facebook Graph API, handles scheduling, returns post result or error.
    async postToFacebook(post: SocialPost): Promise<PostResult> {
      if (!this.isConfigured()) {
        return {
          success: false,
          platform: 'facebook',
          error: 'Facebook API not configured. Please set FB_PAGE_TOKEN and FB_PAGE_ID environment variables.'
        };
      }
    
      try {
        const url = `https://graph.facebook.com/${this.apiVersion}/${this.fbPageId}/feed`;
        
        const body: any = {
          message: post.message,
          access_token: this.fbPageToken,
        };
    
        if (post.link) {
          body.link = post.link;
        }
    
        if (post.scheduledTime) {
          body.published = false;
          body.scheduled_publish_time = Math.floor(new Date(post.scheduledTime).getTime() / 1000);
        }
    
        const response = await fetch(url, {
          method: 'POST',
          headers: { 'Content-Type': 'application/json' },
          body: JSON.stringify(body)
        });
    
        const result = await response.json() as any;
    
        if (result.error) {
          return {
            success: false,
            platform: 'facebook',
            error: result.error.message
          };
        }
    
        return {
          success: true,
          postId: result.id,
          platform: 'facebook',
          scheduledTime: post.scheduledTime
        };
      } catch (error: any) {
        return {
          success: false,
          platform: 'facebook',
          error: error.message
        };
      }
    }
  • postToInstagram helper method: Creates media container then publishes via Instagram Graph API, handles hashtags and images, returns post result or error.
    async postToInstagram(post: SocialPost): Promise<PostResult> {
      if (!this.isConfigured() || !this.igAccountId) {
        return {
          success: false,
          platform: 'instagram',
          error: 'Instagram API not configured. Please set IG_ACCOUNT_ID environment variable.'
        };
      }
    
      if (!post.imageUrl) {
        return {
          success: false,
          platform: 'instagram',
          error: 'Instagram posts require an image. Please provide imageUrl.'
        };
      }
    
      try {
        // Step 1: Create media container
        const containerUrl = `https://graph.facebook.com/${this.apiVersion}/${this.igAccountId}/media`;
        
        let caption = post.message;
        if (post.hashtags && post.hashtags.length > 0) {
          caption += '\n\n' + post.hashtags.map(tag => tag.startsWith('#') ? tag : `#${tag}`).join(' ');
        }
    
        const containerBody: any = {
          image_url: post.imageUrl,
          caption: caption,
          access_token: this.fbPageToken
        };
    
        const containerResponse = await fetch(containerUrl, {
          method: 'POST',
          headers: { 'Content-Type': 'application/json' },
          body: JSON.stringify(containerBody)
        });
    
        const containerResult = await containerResponse.json() as any;
    
        if (containerResult.error) {
          return {
            success: false,
            platform: 'instagram',
            error: containerResult.error.message
          };
        }
    
        const containerId = containerResult.id;
    
        // Step 2: Publish container
        const publishUrl = `https://graph.facebook.com/${this.apiVersion}/${this.igAccountId}/media_publish`;
        
        const publishBody = {
          creation_id: containerId,
          access_token: this.fbPageToken
        };
    
        const publishResponse = await fetch(publishUrl, {
          method: 'POST',
          headers: { 'Content-Type': 'application/json' },
          body: JSON.stringify(publishBody)
        });
    
        const publishResult = await publishResponse.json() as any;
    
        if (publishResult.error) {
          return {
            success: false,
            platform: 'instagram',
            error: publishResult.error.message
          };
        }
    
        return {
          success: true,
          postId: publishResult.id,
          platform: 'instagram'
        };
      } catch (error: any) {
        return {
          success: false,
          platform: 'instagram',
          error: error.message
        };
      }
    }
Behavior3/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It adds valuable context beyond the schema by mentioning authentication requirements ('Requires Meta API configuration') and scheduling capability ('Can schedule posts for future publishing'), but does not disclose other important traits like rate limits, error handling, whether posts are editable after creation, or what happens if scheduling fails. This is adequate but has clear gaps for a mutation tool.

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 extremely concise (two sentences) and front-loaded with the core purpose. Every sentence earns its place: the first states the action and platforms, the second adds crucial behavioral context (authentication and scheduling). There is zero waste or redundancy.

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 this is a mutation tool with no annotations and no output schema, the description is moderately complete. It covers the purpose, prerequisites, and scheduling behavior, but lacks details on return values, error conditions, or platform-specific constraints (e.g., Instagram requiring images). For a 5-parameter tool that creates social media posts, more context would be beneficial.

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%, so the schema already documents all 5 parameters thoroughly. The description does not add any parameter-specific semantics beyond what the schema provides (e.g., it doesn't explain format details for 'platforms' or constraints for 'scheduleTime'). The baseline score of 3 is appropriate when the schema does the heavy lifting.

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?

The description clearly states the specific action ('Post content') and target resources ('Facebook and/or Instagram'), distinguishing it from sibling tools like 'schedule_weekly_posts' (which implies recurring scheduling) and 'generate_post_ideas' (which is idea generation rather than posting). The verb 'post' is precise and the platforms are explicitly named.

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?

The description provides clear context for when to use this tool ('Post content to Facebook and/or Instagram') and mentions prerequisites ('Requires Meta API configuration'), but does not explicitly state when not to use it or name specific alternatives among siblings (e.g., 'schedule_weekly_posts' for recurring posts). The guidance is helpful but lacks explicit exclusions.

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