x-mcp

x-mcp

An MCP server that exposes X API tools generated from OpenAPI spec, with tenant-aware auth, secret management via Vault, and configuration via Postgres. Enables natural language-driven interaction with X API operations, schema discovery, and query suggestions.

Category
访问服务器

README

x-mcp

x-mcp is an X API MCP server built in Node.js. It exposes dedicated MCP tools generated from the upstream X OpenAPI spec, keeps secrets in Vault, keeps non-secret configuration in Postgres, and enforces tenant-aware auth scope as tenant/user or tenant/account.

The scope model is tenant/user or tenant/account.

What It Does

  • Generates one x_api_* MCP tool per documented X API operationId
  • Exposes discovery tools for LLMs: x_schema_discovery and x_query_suggestion
  • Stores tenant-scoped app credentials and tenant/principal-scoped user credentials in Vault-backed profiles
  • Stores defaults, metadata, and non-secret runtime configuration in Postgres
  • Protects mutating tools with authorizationKey when MCP_ADMIN_AUTH_KEY is configured
  • Supports stdio, HTTP, or both MCP transports

Runtime Layout

Key files:

Persistence model:

  • Vault stores actual secret values.
  • Postgres stores profile metadata, default profile selectors, and all non-secret config.
  • APP_NAME is the single naming source for derived Vault paths and Postgres table names.

Generated Inventory

Committed artifacts:

Generate them with:

npm run inventory:generate

Check that the committed artifacts are current with:

npm run inventory:check

MCP Tool Families

All tools return JSON inside MCP text content.

Core tools:

  • x_connection_info: runtime, inventory, Vault, and Postgres connection metadata
  • x_scope_info: resolve tenant/principal scope paths and persistence details
  • x_health_check: validate Vault and Postgres connectivity for a selected scope
  • x_schema_discovery: search the generated X endpoint inventory
  • x_query_suggestion: recommend a safe tool sequence for a workflow

Credential tools:

  • x_auth_upsert_app_credentials
  • x_auth_upsert_principal_credentials
  • x_auth_get_scope_credentials
  • x_auth_delete_profile

Config tools:

  • x_config_list
  • x_config_get
  • x_config_set
  • x_config_delete

Generated X API tools:

  • one x_api_* tool per OpenAPI operationId
  • rich tool descriptions include use cases, auth prerequisites, parameter constraints, response shape, common failures, and safety warnings

Generic fallback:

  • x_api_request

Auth And Scope Model

App-scoped credentials are stored per tenant:

  • Vault path: ${APP_NAME}/tenants/<tenant>/x-api/app-profiles/<profileKey>
  • Postgres key: x.auth.app.profile.<profileKey>.meta

Principal-scoped credentials are stored per tenant principal:

  • Vault path: ${APP_NAME}/tenants/<tenant>/<users|accounts>/<principal>/x-api/profiles/<profileKey>
  • Postgres key: x.auth.principal.profile.<profileKey>.meta

Default selectors are stored in Postgres:

  • x.auth.app.defaultProfileKey
  • x.auth.principal.defaultProfileKey

Supported auth types:

  • bearer token
  • OAuth 2 user token
  • OAuth 1a user token

If MCP_ADMIN_AUTH_KEY is configured, every mutating tool requires authorizationKey, including generated mutating endpoint tools and mutating x_api_request calls.

Environment

See .env.example for the full set. The most important groups are:

  • POSTGRES_*
  • VAULT_*
  • MCP_*
  • X_API_*

The default local scope is controlled by:

  • MCP_CONFIG_DEFAULT_TENANT_ID
  • MCP_CONFIG_DEFAULT_USER_ID
  • MCP_CONFIG_DEFAULT_ACCOUNT_ID
  • MCP_CONFIG_DEFAULT_PRINCIPAL_TYPE

Local Development

Install dependencies and generate the inventory:

npm ci
npm run inventory:generate

Run stdio:

npm run start:stdio

Run HTTP:

npm run start:http

Run both:

npm run start:both

MCP Client Registration

VS Code example:

{
  "command": "npm",
  "args": ["run", "start:stdio"],
  "cwd": "/Users/lesterjohn/Documents/GitHub/X-mcp"
}

Claude Desktop example:

{
  "mcpServers": {
    "x-mcp": {
      "command": "npm",
      "args": ["run", "start:stdio"],
      "cwd": "/Users/lesterjohn/Documents/GitHub/X-mcp"
    }
  }
}

If you need HTTP transport, point the client at http://127.0.0.1:3000/mcp after starting npm run start:http.

Infrastructure

docker-compose.yml runs local Postgres, Vault, and the HTTP MCP service. It preserves Vault Raft persistence and runs vault-unseal-key-init before Vault starts.

External Services Mode

docker-compose.external.yml is the supported External Services Mode for existing Vault and Postgres infrastructure. It requires POSTGRES_HOST, POSTGRES_PORT, POSTGRES_DB, POSTGRES_USER, POSTGRES_PASSWORD, VAULT_ADDR, and VAULT_TOKEN to be provided by the deployment environment.

initdb/001_config.sh creates ${APP_NAME}_config with tenant/principal primary keys.

Production Vault

vault-production/README.md covers migration from the local development Vault to the Raft-backed production layout used by x-mcp.

CI And Push Enforcement

GitHub Actions in .github/workflows/inventory-and-tests.yml regenerates the X API inventory, fails if artifacts are stale, uploads the generated inventory artifacts, and runs npm run verify.

The local pre-push hook in .githooks/pre-push also runs:

npm run verify

This repository is configured to use .githooks as core.hooksPath.

Verification

Run the full verification path with:

npm run verify

The test suite covers:

  • HTTP auth and transport behavior
  • generated X tool registration and mutation auth enforcement
  • discovery and query-suggestion behavior
  • Vault token indexing and fallback semantics
  • Vault production migration scaffolding
  • X inventory artifact presence and push/test enforcement

License

MIT. See LICENSE.

推荐服务器

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

官方
精选