X API FastMCP Server

X API FastMCP Server

A local MCP server that exposes the X API (formerly Twitter API) as tools, enabling operations like posting, searching, user management, and more via natural language commands.

Category
访问服务器

README

X API FastMCP Server

Run a local MCP server that exposes the X API OpenAPI spec as tools using FastMCP. Streaming and webhook endpoints are excluded.

Prerequisites

  • Python 3.9+
  • An X Developer Platform app (to get tokens)
  • Optional: an xAI API key if you want to run the Grok test client

Setup (local)

  1. Create a virtual environment and install dependencies:
    • python -m venv .venv
    • source .venv/bin/activate
    • pip install -r requirements.txt
  2. Create your local .env:
    • cp env.example .env
    • Required values (do not skip):
      • X_OAUTH_CONSUMER_KEY
      • X_OAUTH_CONSUMER_SECRET
      • X_BEARER_TOKEN (required for this setup; keep it set even if using OAuth1)
    • OAuth1 callback (defaults are fine):
      • X_OAUTH_CALLBACK_HOST (default 127.0.0.1)
      • X_OAUTH_CALLBACK_PORT (default 8976)
      • X_OAUTH_CALLBACK_PATH (default /oauth/callback)
      • X_OAUTH_CALLBACK_TIMEOUT (default 300)
    • Server settings (optional):
      • X_API_BASE_URL (default https://api.x.com)
      • X_API_TIMEOUT (default 30)
      • MCP_HOST (default 127.0.0.1)
      • MCP_PORT (default 8000)
      • X_API_DEBUG (default 1)
  • Tool filtering (optional, comma-separated):
    • X_API_TOOL_ALLOWLIST
  • Optional Grok test client:
    • XAI_API_KEY
    • XAI_MODEL (default grok-4-1-fast)
    • MCP_SERVER_URL (default http://127.0.0.1:8000/mcp)
  • Optional OAuth2 token generation:
    • CLIENT_ID
    • CLIENT_SECRET
    • X_OAUTH_ACCESS_TOKEN
- `X_OAUTH_ACCESS_TOKEN_SECRET` (optional)
  • Optional OAuth1 debug output:
    • X_OAUTH_PRINT_TOKENS
    • X_OAUTH_PRINT_AUTH_HEADER
  1. Register the callback URL in your X Developer App:
http://<X_OAUTH_CALLBACK_HOST>:<X_OAUTH_CALLBACK_PORT><X_OAUTH_CALLBACK_PATH>

Example (defaults):

http://127.0.0.1:8976/oauth/callback
  1. Start the server:
python server.py

The MCP endpoint is http://127.0.0.1:8000/mcp by default.

  1. Connect an MCP client:
  • Local client: point it to http://127.0.0.1:8000/mcp.
  • Remote client: tunnel your local server (e.g., ngrok) and use the public URL.

Whitelisting tools

Use X_API_TOOL_ALLOWLIST to load a small, explicit set of tools:

X_API_TOOL_ALLOWLIST=getUsersByUsername,createPosts,searchPostsRecent

Whitelisting is applied at startup when the OpenAPI spec is loaded, so restart the server after changes. See the full tool list below before building your allowlist.

OAuth1 flow (startup behavior)

On startup, the server opens a browser for OAuth1 consent and waits for the callback. Tokens are kept in memory only for the lifetime of the server process. Set X_OAUTH_PRINT_TOKENS=1 to print tokens, or X_OAUTH_PRINT_AUTH_HEADER=1 to print request headers.

Available tool calls (allowlist-ready)

Below is the full list of tool calls you can whitelist via X_API_TOOL_ALLOWLIST. Copy any of these into your .env allowlist.

  • addListsMember
  • addUserPublicKey
  • appendMediaUpload
  • blockUsersDms
  • createCommunityNotes
  • createComplianceJobs
  • createDirectMessagesByConversationId
  • createDirectMessagesByParticipantId
  • createDirectMessagesConversation
  • createLists
  • createMediaMetadata
  • createMediaSubtitles
  • createPosts
  • createUsersBookmark
  • deleteActivitySubscription
  • deleteAllConnections
  • deleteCommunityNotes
  • deleteConnectionsByEndpoint
  • deleteConnectionsByUuids
  • deleteDirectMessagesEvents
  • deleteLists
  • deleteMediaSubtitles
  • deletePosts
  • deleteUsersBookmark
  • evaluateCommunityNotes
  • finalizeMediaUpload
  • followList
  • followUser
  • getAccountActivitySubscriptionCount
  • getActivitySubscriptions
  • getChatConversation
  • getChatConversations
  • getCommunitiesById
  • getComplianceJobs
  • getComplianceJobsById
  • getConnectionHistory
  • getDirectMessagesEvents
  • getDirectMessagesEventsByConversationId
  • getDirectMessagesEventsById
  • getDirectMessagesEventsByParticipantId
  • getInsights28Hr
  • getInsightsHistorical
  • getListsById
  • getListsFollowers
  • getListsMembers
  • getListsPosts
  • getMarketplaceHandleAvailability
  • getMediaAnalytics
  • getMediaByMediaKey
  • getMediaByMediaKeys
  • getMediaUploadStatus
  • getNews
  • getOpenApiSpec
  • getPostsAnalytics
  • getPostsById
  • getPostsByIds
  • getPostsCountsAll
  • getPostsCountsRecent
  • getPostsLikingUsers
  • getPostsQuotedPosts
  • getPostsRepostedBy
  • getPostsReposts
  • getSpacesBuyers
  • getSpacesByCreatorIds
  • getSpacesById
  • getSpacesByIds
  • getSpacesPosts
  • getTrendsByWoeid
  • getTrendsPersonalizedTrends
  • getUsage
  • getUserPublicKeys
  • getUsersAffiliates
  • getUsersBlocking
  • getUsersBookmarkFolders
  • getUsersBookmarks
  • getUsersBookmarksByFolderId
  • getUsersById
  • getUsersByIds
  • getUsersByUsername
  • getUsersByUsernames
  • getUsersFollowedLists
  • getUsersFollowers
  • getUsersFollowing
  • getUsersLikedPosts
  • getUsersListMemberships
  • getUsersMe
  • getUsersMentions
  • getUsersMuting
  • getUsersOwnedLists
  • getUsersPinnedLists
  • getUsersPosts
  • getUsersRepostsOfMe
  • getUsersTimeline
  • hidePostsReply
  • initializeMediaUpload
  • likePost
  • mediaUpload
  • muteUser
  • pinList
  • removeListsMemberByUserId
  • repostPost
  • searchCommunities
  • searchCommunityNotesWritten
  • searchEligiblePosts
  • searchNews
  • searchPostsAll
  • searchPostsRecent
  • searchSpaces
  • searchUsers
  • sendChatMessage
  • unblockUsersDms
  • unfollowList
  • unfollowUser
  • unlikePost
  • unmuteUser
  • unpinList
  • unrepostPost
  • updateActivitySubscription
  • updateLists

Generate an OAuth2 user token (optional)

  1. Add CLIENT_ID and CLIENT_SECRET to your .env.
  2. Update redirect_uri in generate_authtoken.py to match your app settings.
  3. Run python generate_authtoken.py and follow the prompts.
  4. Copy the printed access token into .env as X_OAUTH_ACCESS_TOKEN. If your flow returns a secret, store it as X_OAUTH_ACCESS_TOKEN_SECRET.

Run the Grok MCP test client (optional)

  1. Set XAI_API_KEY in .env.
  2. Make sure your MCP server is running locally (or set MCP_SERVER_URL).
  3. If Grok is not running on your machine, use ngrok to expose your local MCP server and set MCP_SERVER_URL to the public HTTPS URL that ends with /mcp. Example flow: ngrok http 8000 then MCP_SERVER_URL=https://<id>.ngrok-free.dev/mcp.
  4. Run python test_grok_mcp.py.

Notes

  • Endpoints with /stream or /webhooks in the path are excluded.
  • Operations tagged Stream or Webhooks, or marked with x-twitter-streaming: true, are excluded.
  • The OpenAPI spec is fetched from https://api.twitter.com/2/openapi.json at startup.

推荐服务器

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 模型以安全和受控的方式获取实时的网络信息。

官方
精选