post_to_x
Publish messages to X (formerly Twitter) using the social-media-mcp server. Create posts or add to existing threads with required content input.
Instructions
Post a message to X (formerly Twitter)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| content | Yes | Content of the post | |
| threadId | No | ID of the thread to post to |
Implementation Reference
- src/index.ts:168-205 (handler)The handler logic for 'post_to_x' tool that processes the request and interacts with the Twitter client.
if (request.params.name === "post_to_x") { if (!isValidPostArgs(request.params.arguments)) { throw new McpError( ErrorCode.InvalidParams, "Invalid post arguments" ); } const { content, threadId } = request.params.arguments; try { let tweet; if (threadId) { const lastPostInThread = this.socialMediaPosts.filter(post => post.threadId === threadId).sort((a,b) => new Date(b.timestamp).getTime() - new Date(a.timestamp).getTime())[0] if(lastPostInThread) { await sleep(2000) tweet = await twitterClient.v2.reply(content, lastPostInThread.tweetId ?? "0") } else { await sleep(2000) tweet = await twitterClient.v2.tweet(content) } } else { await sleep(2000) tweet = await twitterClient.v2.tweet(content) } const newPost: SocialMediaPost = { content, platform: "X", timestamp: new Date().toISOString(), threadId: threadId, tweetId: tweet.data.id }; this.socialMediaPosts.push(newPost); return { content: [ { type: "text", - src/index.ts:121-132 (schema)Tool definition including the name and input schema for 'post_to_x'.
{ name: "post_to_x", description: "Post a message to X (formerly Twitter)", inputSchema: { type: "object", properties: { content: { type: "string", description: "Content of the post" }, threadId: { type: "string", description: "ID of the thread to post to" }, }, required: ["content"], }, },