TwitterAPI MCP Server

TwitterAPI MCP Server

An MCP server that provides access to Twitter data and write actions through TwitterAPI.io, bypassing the need for a standard Twitter developer account. It enables users to search tweets, retrieve profiles, and post content with support for pagination and enterprise proxy configurations.

Category
访问服务器

README

TwitterAPI MCP Server

A Model Context Protocol (MCP) server that provides access to Twitter data through the TwitterAPI.io service. This server enables Claude and other MCP clients to interact with Twitter's ecosystem without requiring Twitter developer account approval.

Attribution: This project is a fork of kinhunt/twitterapi-mcp with bug fixes and improvements to match the official TwitterAPI.io documentation.

Features

  • User Information: Get detailed user profiles, followers, and following lists
  • Tweet Operations: Search tweets, get tweet details, replies, and user timelines
  • Search Capabilities: Advanced search for both tweets and users
  • Write Actions: Post tweets and interact with content (requires login)
  • Pagination Support: All list endpoints support cursor-based pagination
  • Enterprise Ready: Proxy support and robust error handling
  • No Twitter Auth: Uses TwitterAPI.io which doesn't require Twitter developer approval

Installation

Quick Start with npx (Recommended)

npx twitterapi-mcp-server

Global Installation

npm install -g twitterapi-mcp-server

Local Installation

npm install twitterapi-mcp-server

Configuration

Getting an API Key

  1. Visit TwitterAPI.io
  2. Create an account and log in
  3. Get your API key from the dashboard
  4. The API key format looks like: new1_xxxxxxxxxxxxxxxxxxxxx

Environment Variables

Variable Required Description
TWITTERAPI_API_KEY Yes Your TwitterAPI.io API key
PROXY_URL No Proxy URL for enterprise environments
HTTP_PROXY No Alternative proxy configuration
HTTPS_PROXY No Alternative proxy configuration

MCP Client Configuration

Claude Desktop

Add this to your Claude Desktop configuration file:

macOS: ~/Library/Application Support/Claude/claude_desktop_config.json

Windows: %APPDATA%\Claude\claude_desktop_config.json

{
  "mcpServers": {
    "twitterapi": {
      "command": "npx",
      "args": ["-y", "twitterapi-mcp-server"],
      "env": {
        "TWITTERAPI_API_KEY": "your_api_key_here"
      }
    }
  }
}

Claude Desktop with Proxy

{
  "mcpServers": {
    "twitterapi": {
      "command": "npx",
      "args": ["-y", "twitterapi-mcp-server"],
      "env": {
        "TWITTERAPI_API_KEY": "your_api_key_here",
        "PROXY_URL": "http://proxy.company.com:8080"
      }
    }
  }
}

Cursor IDE

Add to your Cursor MCP settings (.cursor/mcp.json):

{
  "mcpServers": {
    "twitterapi": {
      "command": "npx",
      "args": ["-y", "twitterapi-mcp-server"],
      "env": {
        "TWITTERAPI_API_KEY": "your_api_key_here"
      }
    }
  }
}

Claude Code

Add to your Claude Code MCP settings (~/.claude/settings.json):

{
  "mcpServers": {
    "twitterapi": {
      "command": "npx",
      "args": ["-y", "twitterapi-mcp-server"],
      "env": {
        "TWITTERAPI_API_KEY": "your_api_key_here"
      }
    }
  }
}

Using with Node directly

If you prefer to run with Node directly instead of npx:

{
  "mcpServers": {
    "twitterapi": {
      "command": "node",
      "args": ["/path/to/twitterapi-mcp-server/build/index.js"],
      "env": {
        "TWITTERAPI_API_KEY": "your_api_key_here"
      }
    }
  }
}

Available Tools

User Information

Tool Description Required Params Optional Params
get_user_by_username Get user details by username username -
get_user_by_id Get user details by user ID user_id -
get_user_followers Get user's followers (200/page) username cursor, pageSize
get_user_following Get users someone follows (200/page) username cursor, pageSize
search_users Search for users by keyword query cursor

Tweet Operations

Tool Description Required Params Optional Params
get_user_tweets Get tweets from a user (20/page) username or userId cursor, includeReplies
search_tweets Search tweets by keywords query queryType (Latest/Top), cursor
get_tweet_by_id Get tweets by IDs tweet_ids (array) -
get_tweet_replies Get replies to a tweet (20/page) tweetId cursor, sinceTime, untilTime

Write Actions (Requires Login)

Tool Description Required Params Optional Params
login_user Login to Twitter account user_name, email, password, proxy totp_secret
create_tweet Post new tweets tweet_text, proxy reply_to_tweet_id, attachment_url, media_ids

Examples

Get User Information

// Get user by username
await get_user_by_username({ username: "elonmusk" })

// Get user followers with pagination
await get_user_followers({
  username: "elonmusk",
  pageSize: 100
})

// Get next page using cursor
await get_user_followers({
  username: "elonmusk",
  cursor: "next_cursor_from_previous_response"
})

Search and Retrieve Tweets

// Search latest tweets
await search_tweets({
  query: "artificial intelligence",
  queryType: "Latest"
})

// Search top/popular tweets
await search_tweets({
  query: "OpenAI",
  queryType: "Top"
})

// Advanced search with operators
await search_tweets({
  query: "AI from:elonmusk since:2024-01-01"
})

// Get user's recent tweets
await get_user_tweets({ username: "openai" })

// Get user's tweets including replies
await get_user_tweets({
  username: "openai",
  includeReplies: true
})

// Get specific tweets by IDs
await get_tweet_by_id({
  tweet_ids: ["1234567890123456789", "9876543210987654321"]
})

// Get replies to a tweet
await get_tweet_replies({
  tweetId: "1234567890123456789"
})

Create Content (Requires Login)

// Login first (requires residential proxy)
await login_user({
  user_name: "your_username",
  email: "your_email@example.com",
  password: "your_password",
  proxy: "http://user:pass@proxy:port"
})

// Post a tweet
await create_tweet({
  tweet_text: "Hello from MCP!",
  proxy: "http://user:pass@proxy:port"
})

// Reply to a tweet
await create_tweet({
  tweet_text: "Great point!",
  reply_to_tweet_id: "1234567890123456789",
  proxy: "http://user:pass@proxy:port"
})

Pagination

All list endpoints return paginated results with cursor-based navigation:

{
  "data": [...],
  "has_next_page": true,
  "next_cursor": "cursor_string_for_next_page"
}

To get the next page, pass the next_cursor value as the cursor parameter in your next request.

API Pricing

TwitterAPI.io offers pay-as-you-go pricing:

Operation Price
Tweets $0.15 per 1,000
User profiles $0.18 per 1,000
Followers/Following $0.15 per 1,000
Login $0.003 per call
Create tweet $0.003 per call
  • Minimum charge: $0.00015 per request
  • No monthly fees
  • Free trial credits available
  • Discounted rates for students and research institutions

Development

Building from Source

git clone https://github.com/Jing-yilin/twitterapi-mcp-server.git
cd twitterapi-mcp-server
npm install
npm run build

Running Tests

# Using bun
bun test

# Or with npm (requires bun installed)
npm test

Testing the Server Manually

# Set your API key
export TWITTERAPI_API_KEY="your_api_key"

# Test tools list
echo '{"jsonrpc": "2.0", "id": 1, "method": "tools/list", "params": {}}' | node build/index.js

# Test a tool call
echo '{"jsonrpc": "2.0", "id": 1, "method": "tools/call", "params": {"name": "get_user_by_username", "arguments": {"username": "elonmusk"}}}' | node build/index.js

Project Structure

twitterapi-mcp-server/
├── src/
│   ├── index.ts           # Main server implementation
│   ├── index.test.ts      # Unit tests
│   └── integration.test.ts # Integration tests
├── build/                  # Compiled JavaScript
├── package.json
├── tsconfig.json
└── README.md

Error Handling

The server handles common errors:

Error Cause Solution
401 Unauthorized Invalid API key Check your TWITTERAPI_API_KEY
402 Payment Required Insufficient credits Add credits at TwitterAPI.io dashboard
429 Rate Limited Too many requests Wait and retry, or reduce request rate
400 Bad Request Invalid parameters Check parameter names and formats

Security Considerations

  • Store API keys as environment variables, never in code
  • Login credentials are used only for authentication, not stored persistently
  • All API requests use HTTPS
  • Proxy support available for enterprise security requirements
  • The login_cookie from login is stored in memory only for the session

Troubleshooting

"Unauthorized" error

  • Verify your API key is correct
  • Check that TWITTERAPI_API_KEY environment variable is set

"Credits not enough" error

  • Add credits to your TwitterAPI.io account
  • Check your usage at the dashboard

Server not starting

  • Ensure Node.js >= 18.0.0 is installed
  • Run npm run build to compile TypeScript
  • Check for error messages in stderr

Proxy issues

  • Verify proxy URL format: http://user:pass@host:port
  • Test proxy connectivity independently
  • For HTTPS proxies, use HTTPS_PROXY variable

Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Support

Acknowledgments


Note: This is an unofficial MCP server for TwitterAPI.io. Make sure to comply with Twitter's Terms of Service when using this tool.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选