Skip to main content

TwitterAPI.io MCP Server for AI assistant access to Twitter data

Project description

TwitterAPI.io MCP Server

Model Context Protocol Python Version License

A Model Context Protocol (MCP) server that provides LLM applications with access to Twitter data through the TwitterAPI.io service. This server enables AI assistants like Claude to retrieve and analyze tweets, user profiles, and other Twitter data in a structured way.

๐Ÿš€ Features

Resources

  • Tweet data by ID (tweet://{tweet_id})
  • Tweet replies (tweet://{tweet_id}/replies)
  • Tweet retweeters (tweet://{tweet_id}/retweeters)
  • User profiles (user://{username})
  • User tweets (user://{username}/tweets)
  • User followers (user://{username}/followers)
  • User following (user://{username}/following)

Tools

  • Basic Twitter operations (get tweet, get user profile, search tweets)

๐Ÿ“‹ Requirements

  • Python 3.8 or higher
  • TwitterAPI.io API key

๐Ÿ”ง Installation

Option 1: Direct Installation from PyPI (Recommended)

# Install with pip
pip install twitterapi-mcp

# or with uv for better performance
uv pip install twitterapi-mcp

Option 2: Use with MCP in Claude Desktop (No Installation)

You can use the server directly through uv run by adding to your .mcp.json file:

"twitterapi-mcp": {
  "command": "uv",
  "args": [
    "run",
    "twitterapi-mcp"
  ],
  "env": {
    "TWITTER_API_KEY": "your_api_key_here"
  }
}

Option 3: From Source

  1. Clone this repository:
git clone https://github.com/DevRico003/twitterapi.io-mcp.git
cd twitterapi.io-mcp
  1. Install as development package:
pip install -e .
  1. Configure your TwitterAPI.io API key using environment variables or a .env file:
TWITTER_API_KEY=your_api_key_here
LOG_LEVEL=INFO
CACHE_TTL=3600
MAX_TWEETS=100

๐Ÿš€ Usage

Running the Server

Run directly with Python:

# Run the server package as a module
python -m twitterapi_server

Or use the MCP development mode:

mcp dev twitterapi_server

Install in Claude Desktop

# If you have the package installed:
mcp install -m twitterapi-mcp --name "Twitter API"

# Or directly from the code:
mcp install twitterapi_server --name "Twitter API"

โš™๏ธ Configuration

The server supports the following environment variables:

  • TWITTER_API_KEY (required): Your TwitterAPI.io API key
  • LOG_LEVEL (optional): Logging level (default: INFO)
  • CACHE_TTL (optional): Cache timeout in seconds (default: 3600/1 hour)
  • MAX_TWEETS (optional): Maximum tweets per request (default: 100)

๐Ÿ“ Project Structure

.
โ”œโ”€โ”€ .gitignore
โ”œโ”€โ”€ LICENSE
โ”œโ”€โ”€ MANIFEST.in
โ”œโ”€โ”€ README.md              # This file
โ”œโ”€โ”€ pyproject.toml         # Project configuration and dependencies
โ”œโ”€โ”€ requirements.txt       # Dependencies (alternative format)
โ”œโ”€โ”€ setup.py               # Build script (legacy compatibility)
โ”œโ”€โ”€ twitterapi/            # Main package source code
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”œโ”€โ”€ api_client.py
โ”‚   โ”œโ”€โ”€ config.py
โ”‚   โ”œโ”€โ”€ mcp_server.py
โ”‚   โ”œโ”€โ”€ utils.py
โ”‚   โ”œโ”€โ”€ resources/
โ”‚   โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”‚   โ”œโ”€โ”€ tweet_resources.py
โ”‚   โ”‚   โ””โ”€โ”€ user_resources.py
โ”‚   โ””โ”€โ”€ tools/
โ”‚       โ”œโ”€โ”€ __init__.py
โ”‚       โ””โ”€โ”€ basic_tools.py
โ””โ”€โ”€ twitterapi_server/     # Server entry point package
    โ””โ”€โ”€ __init__.py        # Contains main() function

๐Ÿงช Testing

Run the tests with pytest:

## ๐Ÿ“ฆ Publishing to PyPI (Developer Notes)

To publish a new version of this package to PyPI:

1.  **Increment Version:** Update the `version` number in `pyproject.toml`.
2.  **Install Tools:** Make sure you have the necessary tools installed:
    ```bash
    pip install --upgrade build twine
    ```
3.  **Configure Credentials:** Ensure you have a `.pypirc` file in your home directory (`~/.pypirc`) configured with your PyPI API token or username/password. Example:
    ```ini
    [pypi]
      username = __token__
      password = pypi-your-api-token-here
    ```
4.  **Build the Package:** Generate the distribution archives:
    ```bash
    python -m build
    ```
    This will create `sdist` (.tar.gz) and `wheel` (.whl) files in the `dist/` directory.
5.  **Upload to PyPI:** Upload the generated files using twine:
    ```bash
    # Replace X.Y.Z with the new version number
    python -m twine upload dist/twitterapi_mcp-X.Y.Z*

    # Or upload all files in dist/ (be careful if old versions exist)
    # python -m twine upload dist/*
    ```
python -m pytest

You can run specific test modules:

python -m pytest tests/test_utils.py
python -m pytest tests/test_api_client.py

๐Ÿ“Š API Cost Considerations

TwitterAPI.io charges approximately $0.15 per 1,000 tweets retrieved. This server implements caching with a configurable TTL to reduce API costs while maintaining fresh data. The cache is particularly effective for frequently monitored influencers and popular searches.

๐Ÿ“„ License

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

twitterapi_mcp-0.1.4.tar.gz (17.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

twitterapi_mcp-0.1.4-py3-none-any.whl (15.5 kB view details)

Uploaded Python 3

File details

Details for the file twitterapi_mcp-0.1.4.tar.gz.

File metadata

  • Download URL: twitterapi_mcp-0.1.4.tar.gz
  • Upload date:
  • Size: 17.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.0

File hashes

Hashes for twitterapi_mcp-0.1.4.tar.gz
Algorithm Hash digest
SHA256 62d528bf572c431a5ff0cbdbbb2b1663946666ac6c4a52421b3c1903d2a0580a
MD5 fc279507a9dbc7b7df1dd4423e78986e
BLAKE2b-256 9cfed5e95d6487d76a4b18a5f2389256c041b5399312870330b5f336613d55f4

See more details on using hashes here.

File details

Details for the file twitterapi_mcp-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: twitterapi_mcp-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 15.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.0

File hashes

Hashes for twitterapi_mcp-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 11d0998caba4484f9e8b0e84c492d882da21ea5302fb971ffc28d4aabea29c7d
MD5 d262f473bc7bb000133d51cbd47c48ff
BLAKE2b-256 dce5bae0f993433df0c931b9319d0c087fbfa4df41cb9f641345b946d95dd344

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page