publish_post
Publish a social media post instantly to X, Instagram, or Threads with text content and optional media attachments.
Instructions
Publish a social media post immediately
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| platform | Yes | Social media platform | |
| content | Yes | Post content/text | |
| mediaUrls | No | Optional media URLs to attach |
Implementation Reference
- src/index.ts:33-55 (registration)Tool name 'publish_post' is registered in the ListToolsRequestSchema handler with its inputSchema defining required parameters (platform, content) and optional mediaUrls.
name: 'publish_post', description: 'Publish a social media post immediately', inputSchema: { type: 'object', properties: { platform: { type: 'string', enum: ['X', 'INSTAGRAM', 'THREADS'], description: 'Social media platform', }, content: { type: 'string', description: 'Post content/text', }, mediaUrls: { type: 'array', items: { type: 'string' }, description: 'Optional media URLs to attach', }, }, required: ['platform', 'content'], }, }, - src/index.ts:225-248 (handler)The publishPost method executes the tool logic: fetches accounts, finds the matching platform account, and POSTs to /posts API endpoint to publish the post.
private async publishPost(args: any) { const { accounts } = await this.apiRequest('GET', '/accounts'); const account = accounts.find((a: any) => a.provider === args.platform); if (!account) { throw new Error(`No ${args.platform} account connected. Available accounts: ${accounts.map((a: any) => a.provider).join(', ')}`); } const result = await this.apiRequest('POST', '/posts', { accountId: account.id, platform: args.platform, content: args.content, mediaUrls: args.mediaUrls || [], }); return { content: [ { type: 'text', text: `✅ Post published to ${args.platform}!\nStatus: ${result.post.status}\nPost ID: ${result.post.id}`, }, ], }; } - src/index.ts:138-139 (handler)The CallToolRequestSchema handler routes the 'publish_post' tool name to the publishPost method.
case 'publish_post': return await this.publishPost(args); - src/index.ts:35-54 (schema)Input schema for publish_post defines three properties: platform (enum: X, INSTAGRAM, THREADS), content (string), and mediaUrls (optional array of strings). platform and content are required.
inputSchema: { type: 'object', properties: { platform: { type: 'string', enum: ['X', 'INSTAGRAM', 'THREADS'], description: 'Social media platform', }, content: { type: 'string', description: 'Post content/text', }, mediaUrls: { type: 'array', items: { type: 'string' }, description: 'Optional media URLs to attach', }, }, required: ['platform', 'content'], }, - src/index.ts:170-195 (helper)The apiRequest helper is used by publishPost to make authenticated HTTP requests to the Sociona API.
private async apiRequest(method: string, endpoint: string, body?: any) { const url = `${API_BASE}${endpoint}`; console.error(`Making ${method} request to ${url}`); const response = await fetch(url, { method, headers: { 'Authorization': `Bearer ${SOCIONA_API_KEY}`, 'Content-Type': 'application/json', }, body: body ? JSON.stringify(body) : undefined, }); if (!response.ok) { let errorMessage = `API request failed with status ${response.status}`; try { const errorData = await response.json(); errorMessage = errorData.message || errorMessage; } catch (e) { // Ignore JSON parse errors } throw new Error(errorMessage); } return response.json(); }