postTweet
Publish tweets to Twitter using a structured input format. Enables integration with the Twitter MCP Server for streamlined social media interaction.
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: checks for Twitter client, posts the tweet via Twitter API v2, handles success response with tweet ID and formats errors.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 definition and input schema for postTweet, specifying the required 'text' parameter.postTweet: { description: 'Post a tweet to Twitter', inputSchema: { type: 'object', properties: { text: { type: 'string', description: 'The text of the tweet' }, }, required: ['text'], },
- src/types.ts:1-2 (schema)TypeScript interface defining the input arguments for postTweet.export interface PostTweetArgs { text: string;
- src/index.ts:152-155 (registration)Tool dispatch registration in the MCP server: maps 'postTweet' tool call to handlePostTweet handler.case 'postTweet': { const { text } = request.params.arguments as { text: string }; response = await handlePostTweet(client, { text }); break;
- src/index.ts:17-17 (registration)Import of the postTweet handler function.handlePostTweet,