replyToTweet
Post a reply to a specific tweet on Twitter by providing the tweet ID and your response text using this Model Context Protocol tool.
Instructions
Reply to a tweet
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| text | Yes | The text of the reply | |
| tweetId | Yes | The ID of the tweet to reply to |
Implementation Reference
- src/handlers/tweet.handlers.ts:83-100 (handler)Core handler function implementing replyToTweet tool logic: checks for Twitter client, calls Twitter API v2.reply(text, tweetId), handles success/error responses.export async function handleReplyToTweet( client: TwitterClient | null, { tweetId, text }: { tweetId: string; text: string } ): Promise<HandlerResponse> { if (!client) { return createMissingTwitterApiKeyResponse('Reply to Tweet'); } try { const tweet = await client.v2.reply(text, tweetId); return createResponse(`Successfully replied to tweet: ${tweet.data.id}`); } catch (error) { if (error instanceof Error) { throw new Error(formatTwitterError(error, 'replying to tweet')); } throw new Error('Failed to reply to tweet: Unknown error occurred'); } }
- src/tools.ts:103-119 (schema)MCP tool definition and input schema for replyToTweet, used by the server to expose the tool with description and validation schema.replyToTweet: { description: 'Reply to a tweet', inputSchema: { type: 'object', properties: { tweetId: { type: 'string', description: 'The ID of the tweet to reply to' }, text: { type: 'string', description: 'The text of the reply' } }, required: ['tweetId', 'text'] } },
- src/index.ts:172-175 (registration)Tool registration in MCP server's CallToolRequestSchema handler: matches tool name and dispatches to handleReplyToTweet function.case 'replyToTweet': { const { tweetId, text } = request.params.arguments as { tweetId: string; text: string }; response = await handleReplyToTweet(client, { tweetId, text }); break;
- src/types.ts:19-22 (schema)TypeScript interface defining input arguments for replyToTweet handler.export interface ReplyToTweetArgs { tweetId: string; text: string; }
- src/types.ts:179-189 (schema)Runtime type assertion/validator for ReplyToTweetArgs ensuring tweetId and text are strings.export function assertReplyToTweetArgs(args: unknown): asserts args is ReplyToTweetArgs { if (typeof args !== 'object' || args === null) { throw new Error('Invalid arguments: expected object'); } if (!('tweetId' in args) || typeof (args as any).tweetId !== 'string') { throw new Error('Invalid arguments: expected tweetId string'); } if (!('text' in args) || typeof (args as any).text !== 'string') { throw new Error('Invalid arguments: expected text string'); } }