x-mcp-server
X MCP Server
适用于官方 X API 的 TypeScript Model Context Protocol (MCP) 服务器。
该项目允许兼容 MCP 的代理(包括 ChatGPT 代理)通过运行在您自己计算机上的本地服务器,安全地读取 X 账户并向其发布内容。
该服务器支持:
读取已认证的 X 账户。
按用户名查找 X 用户。
按 ID 读取帖子。
列出用户的最新帖子。
使用 X 搜索语法搜索最新帖子。
在显式启用写入模式时创建帖子和回复。
为每台本地计算机安装选择不同的 X 账户。
通过
stdio为本地 MCP 主机运行。通过 OpenAI Secure MCP Tunnels 为 ChatGPT 在本地 Streamable HTTP 上运行。
项目状态
这是一个功能完善的 MVP。
已实现:
基于
stdio的 MCP 服务器。基于 Streamable HTTP 的 MCP 服务器。
官方 X API 客户端。
本地多账户配置。
默认安全的
read-only模式。显式的
read-write模式,用于发布和回复。用于 X 账户重新授权的本地 OAuth 2.0 Authorization Code + PKCE 辅助工具。
使用 Vitest 的单元测试。
通过 OpenAI Secure MCP Tunnels 连接 ChatGPT 的指南。
Windows 上手动和自动启动的本地服务器生命周期指南。
Related MCP server: X API FastMCP Server
工作原理
对于本地 MCP 主机:
MCP host
-> stdio
-> x-mcp-server
-> official X API对于 ChatGPT 代理:
ChatGPT agent
-> custom MCP app
-> OpenAI Secure MCP Tunnel
-> tunnel-client on your computer
-> http://127.0.0.1:3001/mcp
-> x-mcp-server
-> official X APIX 凭据保留在本地。ChatGPT 通过隧道连接到本地 MCP 服务器;它不会收到您的 X 访问令牌。
可用的 MCP 工具
工具 | 类型 | 描述 |
| 读取 | 返回选定的本地配置文件、已配置的账户、模式以及已认证的 X 用户。 |
| 读取 | 返回已认证的 X 用户。 |
| 读取 | 按用户名查找 X 用户。 |
| 读取 | 按 ID 读取帖子。 |
| 读取 | 列出由用户 ID 撰写的最新帖子。 |
| 读取 | 使用官方 X 查询语法搜索最新帖子。 |
| 写入 | 发布新帖子。需要 |
| 写入 | 回复帖子。需要 |
除非设置了 X_MCP_MODE=read-write,否则写入工具会被阻止。
要求
Node.js 20 或更高版本。
一个 X Developer 账户。
一个启用了 OAuth 2.0 的 X Developer App。
X 读取范围:
tweet.read users.read。用于发布和回复的 X 写入范围:
tweet.write。推荐的 X 刷新范围:
offline.access。对于 ChatGPT:已启用开发者模式。
对于 ChatGPT 本地连接:一个 OpenAI Secure MCP Tunnel 和
tunnel-client。
分步安装
1. 克隆仓库
git clone https://github.com/lluisfont/x-mcp-server.git
cd x-mcp-server如果您已经有该仓库:
cd C:\Repos\x-mcp-server
git pull2. 安装依赖
npm install3. 创建本地环境文件
Copy-Item .env.example .env在本地编辑 .env。
不要提交 .env。它可能包含访问令牌、刷新令牌、客户端密钥和私有 API 密钥。
4. 配置活动的 X 账户
对于命名本地账户:
X_MCP_ACCOUNT=fcbnews2026
X_MCP_MODE=read-only
X_API_BASE_URL=https://api.x.com
X_ACCOUNT_FCBNEWS2026_USER_ACCESS_TOKEN=
X_ACCOUNT_FCBNEWS2026_REFRESH_TOKEN=对于同一台计算机上的多个账户:
X_MCP_ACCOUNT=fcbnews2026
X_MCP_MODE=read-only
X_ACCOUNT_FCBNEWS2026_USER_ACCESS_TOKEN=
X_ACCOUNT_FCBNEWS2026_REFRESH_TOKEN=
X_ACCOUNT_LLUISFONT_USER_ACCESS_TOKEN=
X_ACCOUNT_LLUISFONT_REFRESH_TOKEN=X_MCP_ACCOUNT 选择此安装使用的本地配置文件。不同计算机可以选择不同账户,而无需更改代码。
同时支持传统的单账户模式:
X_MCP_ACCOUNT=default
X_USER_ACCESS_TOKEN=新安装应优先使用命名账户。
5. 选择传输方式
对于直接启动进程的本地 MCP 主机:
X_MCP_TRANSPORT=stdio对于通过本地隧道的 ChatGPT:
X_MCP_TRANSPORT=http
X_MCP_HTTP_PORT=3001
X_MCP_HTTP_PATH=/mcp6. 运行类型检查和测试
npm run typecheck
npm test
npm run build7. 启动 MCP 服务器
对于 stdio:
npm run dev对于本地 HTTP:
npm run dev:http默认的 HTTP MCP 端点为:
http://127.0.0.1:3001/mcp健康检查:
Invoke-RestMethod http://127.0.0.1:3001/healthz | ConvertTo-Json -Compress预期响应:
{"ok":true,"transport":"http","activeAccount":"fcbnews2026","mode":"read-only"}本地 MCP 服务器生命周期
当 ChatGPT 通过隧道使用此 MCP 时,必须运行两个本地进程:
1. The MCP HTTP server
-> npm run dev:http
-> http://127.0.0.1:3001/mcp
2. tunnel-client
-> .\.tools\tunnel-client\tunnel-client.exe run --profile <profile>
-> OpenAI Secure MCP Tunnel如果任一进程停止,ChatGPT 将无法使用 MCP 工具。
手动启动
终端 1:
cd C:\Repos\x-mcp-server
npm run dev:http终端 2:
cd C:\Repos\x-mcp-server
.\.tools\tunnel-client\tunnel-client.exe run --profile x-fcbnews保持两个终端都处于打开状态。
验证本地可用性
检查 MCP 服务器:
Invoke-RestMethod http://127.0.0.1:3001/healthz | ConvertTo-Json -Compress检查隧道客户端:
Invoke-WebRequest http://127.0.0.1:8080/readyz -UseBasicParsing隧道就绪端点应返回 HTTP 200。
手动停止
在以下位置按下 Ctrl+C:
运行
npm run dev:http的终端。运行
tunnel-client run的终端。
一旦两者都停止,ChatGPT 将无法访问本地 MCP 服务器。
更改账户或安全模式
编辑 .env。
更改活动账户:
X_MCP_ACCOUNT=fcbnews2026启用写入模式:
X_MCP_MODE=read-write返回安全的只读模式:
X_MCP_MODE=read-only更改 .env 后重启 MCP HTTP 服务器:
Ctrl+C
npm run dev:http如果本地端口和 MCP 路径未更改,隧道可以保持运行。
在 Windows 登录时自动启动
对于需要定期托管此 MCP 的计算机,请使用 Windows 任务计划程序。
创建一个本地启动脚本,例如:
C:\Users\<user>\mcp-start\x-fcbnews-start.ps1脚本:
$repo = "C:\Repos\x-mcp-server"
$profile = "x-fcbnews"
Set-Location $repo
Start-Process powershell.exe -ArgumentList @(
"-NoExit",
"-ExecutionPolicy", "Bypass",
"-Command", "cd `"$repo`"; npm run dev:http"
) -WindowStyle Minimized
Start-Sleep -Seconds 5
Start-Process powershell.exe -ArgumentList @(
"-NoExit",
"-ExecutionPolicy", "Bypass",
"-Command", "cd `"$repo`"; .\.tools\tunnel-client\tunnel-client.exe run --profile $profile"
) -WindowStyle Minimized注册计划任务:
$action = New-ScheduledTaskAction `
-Execute "powershell.exe" `
-Argument "-ExecutionPolicy Bypass -File `"C:\Users\<user>\mcp-start\x-fcbnews-start.ps1`""
$trigger = New-ScheduledTaskTrigger -AtLogOn
Register-ScheduledTask `
-TaskName "X MCP FCBNews2026" `
-Action $action `
-Trigger $trigger `
-Description "Starts the local X MCP server and OpenAI tunnel-client at Windows logon."禁用自动启动:
Disable-ScheduledTask -TaskName "X MCP FCBNews2026"重新启用:
Enable-ScheduledTask -TaskName "X MCP FCBNews2026"删除它:
Unregister-ScheduledTask -TaskName "X MCP FCBNews2026" -Confirm:$false完整生命周期指南:
docs/local-server-lifecycle.md
连接到 ChatGPT
高层流程:
1. Run the MCP server over local HTTP.
2. Create a tunnel in OpenAI Platform.
3. Create a local tunnel-client profile pointing to http://127.0.0.1:3001/mcp.
4. Start tunnel-client.
5. Create a custom MCP app in the ChatGPT agent using Connection: Tunnel.
6. Test x_get_active_account or x_get_me before any write operation.推荐的 ChatGPT 自定义 MCP 设置:
Connection: Tunnel
Tunnel: <your OpenAI tunnel>
Authentication: No authentication当 MCP 服务器在本地管理最终服务凭据时(例如通过 .env),请使用 No authentication。
完整的 ChatGPT 设置指南:
重新授权 X 账户
在 X Developer 中配置应用:
OAuth 2.0: Enabled
App permissions: Read and write
Callback URI: http://127.0.0.1:3002/callback
Website URL: http://127.0.0.1:3002运行:
$env:X_OAUTH_CLIENT_ID = "<OAuth 2.0 Client ID>"
$env:X_MCP_ACCOUNT = "fcbnews2026"
npm run x:oauth在登录目标 X 账户的状态下打开生成的 URL。授权后,辅助工具会使用所选账户令牌更新 .env。
重新授权后重启 MCP 服务器:
npm run dev:http然后使用以下命令验证:
x_get_active_account详细的 OAuth 指南:
安全模型
服务器默认以只读模式启动:
X_MCP_MODE=read-only写入工具需要:
X_MCP_MODE=read-write发布前:
使用
x_get_active_account验证活动账户。确认要发布的确切文本。
确保 X 令牌具有
tweet.write。要求代理返回生成的
post_id。在 X 返回 ID 之前,不要将帖子视为已发布。
脚本
脚本 | 目的 |
| 通过 |
| 通过本地 HTTP 启动 MCP 服务器。 |
| 运行本地 X OAuth 授权辅助工具。 |
| 将 TypeScript 编译到 |
| 通过 |
| 通过 HTTP 启动编译后的服务器。 |
| 运行 TypeScript 而不输出文件。 |
| 运行 Vitest 测试套件。 |
文档
docs/configuration.md:环境变量和多账户设置。
docs/local-server-lifecycle.md:启动、停止本地 MCP 服务器并实现自动化。
docs/tools.md:MCP 工具和使用约定。
docs/x-oauth.md:X OAuth 重新授权。
docs/development.md:开发、测试和变更指南。
docs/chatgpt-mcp-setup.md:分步 ChatGPT MCP 设置。
操作安全
将凭据保留在 Git 之外。
保持
read-only为默认模式。仅对受控工作流启用
read-write。发布前验证活动账户。
不要记录访问令牌或刷新令牌。
不要将令牌粘贴到聊天、问题、文档或拉取请求中。
不要在共享计算机上以
read-write模式运行自动启动。
许可证
尚未选择开源许可证。
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Servers
- FlicenseAqualityDmaintenanceAn MCP server that provides AI agents with full access to the X (Twitter) API for posting, searching, and managing engagement through natural language. It supports comprehensive tools for tweet management, media uploads, and account analytics across multiple MCP-compatible clients.1550

X API FastMCP Serverofficial
Flicense-qualityFmaintenanceA 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.851- AlicenseAqualityDmaintenanceMCP server for Twitter/X enabling AI agents to search, post, reply, and engage with tweets.14131MIT
- AlicenseBqualityDmaintenanceMCP server for interacting with the X platform (Twitter) via MCP clients like Claude, Cursor AI, and Windsurf AI.20146MIT
Related MCP Connectors
X (formerly Twitter) posts, profiles, and search for AI agents. Free key, self-minted, no signup.
FastMCP server for posting formatted content to X (Twitter) — Tollbooth-monetized, DPYC-native
Hosted MCP with 91 agent tools: X, domains, SEO, Maps, Trends, Search, YouTube, TikTok, and more.
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/lluisfont/x-mcp-server'
If you have feedback or need assistance with the MCP directory API, please join our Discord server