postTweet
Publish tweets to Twitter using the Model Context Protocol. This tool enables automated posting of text content to the social media platform.
Instructions
Post a tweet to Twitter
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| text | Yes | The text of the tweet |
Implementation Reference
- src/handlers/tweet.handlers.ts:15-32 (handler)Core handler function that executes the postTweet tool by calling the Twitter v2 API to post the tweet.
export async function handlePostTweet( client: TwitterClient | null, { text }: { text: string } ): Promise<HandlerResponse> { if (!client) { return createMissingTwitterApiKeyResponse('Post Tweet'); } try { const tweet = await client.v2.tweet(text); return createResponse(`Successfully posted tweet: ${tweet.data.id}`); } catch (error) { if (error instanceof Error) { throw new Error(formatTwitterError(error, 'posting tweet')); } throw new Error('Failed to post tweet: Unknown error occurred'); } } - src/tools.ts:5-13 (schema)MCP tool schema definition for postTweet, including input schema and description.
postTweet: { description: 'Post a tweet to Twitter', inputSchema: { type: 'object', properties: { text: { type: 'string', description: 'The text of the tweet' }, }, required: ['text'], }, - src/index.ts:152-155 (registration)Registration and dispatch logic in the main MCP server handler that calls the postTweet handler.
case 'postTweet': { const { text } = request.params.arguments as { text: string }; response = await handlePostTweet(client, { text }); break; - src/types.ts:1-2 (schema)TypeScript interface defining the input arguments for postTweet.
export interface PostTweetArgs { text: string;