Social Media MCP Server
by tayler-id
import { createComponentLogger } from './build/utils/logger.js';
import linkedinClient from './build/platforms/linkedin/client.js';
import mastodonClient from './build/platforms/mastodon/client.js';
import { SocialPlatform } from './build/types/index.js';
import historyManager from './build/history/manager.js';
import fs from 'fs';
const logger = createComponentLogger('NewMCPPost');
/**
* Main function to post new MCP content
*/
async function postNewMCPContent() {
console.log('Starting to post new MCP content...');
logger.info('Starting new MCP content posting...');
try {
// Read the content file
logger.info('Reading new MCP content...');
const contentRaw = fs.readFileSync('./new-mcp-content.json', 'utf-8');
const content = JSON.parse(contentRaw);
// Create content objects
const mastodonContent = {
text: content.mastodon.post,
platform: SocialPlatform.MASTODON
};
const linkedinContent = {
text: content.linkedin.post,
platform: SocialPlatform.LINKEDIN
};
// Post to Mastodon
console.log('Posting to Mastodon...');
logger.info('Posting to Mastodon...', { content: mastodonContent.text.substring(0, 30) + '...' });
let mastodonResult = false;
if ('postStatus' in mastodonClient) {
const postResult = await mastodonClient.postStatus(mastodonContent);
if (postResult.success) {
logger.info('Mastodon post successful', {
id: postResult.postId,
url: postResult.url,
isMock: postResult.isMock
});
console.log('\nMastodon post successful!');
console.log(`URL: ${postResult.url}`);
if (postResult.isMock) {
console.log('Note: This was a mock post. To post for real, check Mastodon credentials.');
}
mastodonResult = true;
} else {
logger.error('Mastodon post failed', { error: postResult.error });
console.log('\nMastodon post failed:', postResult.error);
}
} else {
logger.error('Mastodon client does not have a postStatus method');
console.log('\nError: Mastodon client does not have a postStatus method');
}
// Post to LinkedIn
console.log('\nPosting to LinkedIn...');
logger.info('Posting to LinkedIn...', { content: linkedinContent.text.substring(0, 30) + '...' });
let linkedinResult = false;
const postResult = await linkedinClient.postShare(linkedinContent);
if (postResult.success) {
logger.info('LinkedIn post successful', {
id: postResult.postId,
url: postResult.url,
isMock: postResult.isMock
});
console.log('\nLinkedIn post successful!');
console.log(`URL: ${postResult.url}`);
if (postResult.isMock) {
console.log('Note: This was a mock post. To post for real, check LinkedIn credentials.');
}
linkedinResult = true;
} else {
logger.error('LinkedIn post failed', { error: postResult.error });
console.log('\nLinkedIn post failed:', postResult.error);
}
// Add to history
let historyId = '';
if (mastodonResult || linkedinResult) {
console.log('\nAdding to history...');
logger.info('Adding to history...');
// Create history entry
const topic = 'Social Media MCP Server Update';
const instruction = 'Post update about Social Media MCP Server improvements';
const platforms = [];
if (mastodonResult) platforms.push(SocialPlatform.MASTODON);
if (linkedinResult) platforms.push(SocialPlatform.LINKEDIN);
// Create a dummy Twitter content to satisfy the type requirements
const twitterContent = {
text: "This content was not posted to Twitter",
platform: SocialPlatform.TWITTER
};
const contentMap = {
[SocialPlatform.TWITTER]: twitterContent,
[SocialPlatform.MASTODON]: mastodonContent,
[SocialPlatform.LINKEDIN]: linkedinContent,
};
const keywords = ['MCP', 'SocialMedia', 'AIIntegration', 'DevOps', 'TechInnovation'];
// Add to history
historyId = historyManager.addToHistory(topic, instruction, platforms, contentMap, keywords);
logger.info('Added to history', { id: historyId });
console.log('Content added to history with ID:', historyId);
}
// Log overall results
logger.info('New MCP content posting completed', {
mastodon: mastodonResult ? 'Success' : 'Failed',
linkedin: linkedinResult ? 'Success' : 'Failed',
historyId
});
console.log('\n===== POSTING SUMMARY =====');
console.log(`Mastodon: ${mastodonResult ? 'SUCCESS' : 'FAILED'}`);
console.log(`LinkedIn: ${linkedinResult ? 'SUCCESS' : 'FAILED'}`);
console.log(`History ID: ${historyId || 'Not added'}`);
return {
mastodon: mastodonResult,
linkedin: linkedinResult,
historyId
};
} catch (error) {
logger.error('Error posting new MCP content', {
error: error instanceof Error ? error.message : String(error)
});
console.log('\nError posting new MCP content:', error instanceof Error ? error.message : String(error));
return {
mastodon: false,
linkedin: false,
historyId: ''
};
}
}
// Run the main function
postNewMCPContent().catch(error => {
logger.error('Unhandled error in new MCP content posting', {
error: error instanceof Error ? error.message : String(error)
});
console.error('Unhandled error:', error);
});