Skip to main content

Twitter API的MCP服务,基于twitterapi.io,使用studio模式进行通信

Project description

Twitter API MCP服务

这是一个基于Model Context Protocol (MCP)的Twitter API客户端,使用twitterapi.io的API服务来获取Twitter数据。该服务允许AI助手(如Claude)查询Twitter数据,包括用户信息、推文、趋势等。

功能

  • 获取用户信息和用户关系数据(粉丝、关注)
  • 搜索和获取推文,包括用户时间线、列表推文
  • 获取推文详情、回复、引用和转发信息
  • 高级推文搜索功能

环境要求

  • Python 3.12或更高版本
  • mcp库 >= 1.6.0
  • httpx >= 0.28.1
  • python-dotenv >= 1.0.0 (可选,用于加载环境变量)

安装

  1. 确保你已安装必要的依赖:

    pip install "mcp>=1.6.0" "httpx>=0.28.1" "python-dotenv>=1.0.0"
    

    或者使用uv:

    uv pip install "mcp>=1.6.0" "httpx>=0.28.1" "python-dotenv>=1.0.0"
    
  2. 设置Twitter API密钥:

    export TWITTER_API_KEY="your_api_key_here"
    

    或者创建一个.env文件:

    TWITTER_API_KEY=your_api_key_here
    

使用方法

使用MCP CLI运行服务

mcp dev main.py

这将使用MCP Inspector启动服务,可通过本地网页界面测试其功能。

安装到Claude Desktop

要在Claude Desktop中使用此服务:

mcp install main.py --name "Twitter API"

直接执行

python main.py

可用的工具

用户相关工具

  1. get_user_info_by_username - 根据用户名获取Twitter用户信息
  2. batch_get_users_by_ids - 批量获取用户信息
  3. get_user_last_tweets - 获取用户最新的推文
  4. get_user_followers - 获取用户的粉丝列表
  5. get_user_followings - 获取用户的关注列表
  6. get_user_mentions - 获取用户被提及的推文

推文相关工具

  1. get_tweets_by_ids - 通过推文ID获取推文
  2. get_tweet_replies - 获取推文的回复
  3. get_tweet_quotations - 获取引用推文的推文
  4. get_tweet_retweeters - 获取转发推文的用户
  5. get_list_tweets - 获取列表中的推文
  6. advanced_search_tweets - 高级搜索推文

示例使用场景

使用Claude与此MCP服务的交互示例:

  1. 获取用户信息: "请获取Twitter用户'elonmusk'的个人资料信息。"

  2. 搜索推文: "请通过高级搜索找到关于'人工智能'的最新推文,限制结果为5条。"

  3. 查看用户推文: "显示用户'elonmusk'的最新3条推文。"

  4. 获取推文回复: "获取ID为'1234567890'的推文的所有回复。"

  5. 了解推文引用: "查看有哪些用户引用了ID为'1234567890'的推文。"

注意事项

  • 你需要一个有效的twitterapi.io API密钥才能使用此服务
  • 某些API调用可能受到twitterapi.io的速率限制
  • 确保遵守Twitter的服务条款和API使用政策

开发与测试

项目包含examples目录中的客户端示例代码,可用于了解如何从Python程序中调用此MCP服务。 tests目录包含基本的单元测试,可确保服务核心功能正常工作。

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

mcp_twitterio-0.1.0.tar.gz (5.7 kB view details)

Uploaded Source

Built Distribution

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

mcp_twitterio-0.1.0-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

Details for the file mcp_twitterio-0.1.0.tar.gz.

File metadata

  • Download URL: mcp_twitterio-0.1.0.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.12

File hashes

Hashes for mcp_twitterio-0.1.0.tar.gz
Algorithm Hash digest
SHA256 65eb0bc51487a51ebc0fa24d7d8cae3680d8f894dd6555db56fac71f53a30578
MD5 6e732615f4bbf5994547e6b1cdf8ce3c
BLAKE2b-256 df1b9e5e0e501f5e857a761c036076e00261c6f3de7463390ccee3a851d5491a

See more details on using hashes here.

File details

Details for the file mcp_twitterio-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: mcp_twitterio-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.12

File hashes

Hashes for mcp_twitterio-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7f266231698f5d0a3eb1562c1c798c25790ac7f62e160374435b31c8d4a5d835
MD5 3837240a47eee0bc76e9ff4c0b2cefda
BLAKE2b-256 11af45d71d5d3f07d63ecea4bc25a45a5f1210cf4266f19c463e7c2958a25ea1

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