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.
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 APIoperationId - Exposes discovery tools for LLMs:
x_schema_discoveryandx_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
authorizationKeywhenMCP_ADMIN_AUTH_KEYis configured - Supports stdio, HTTP, or both MCP transports
Runtime Layout
Key files:
- src/config/env.js: environment parsing and validation
- src/runtime/createRuntimeContext.js: shared runtime bootstrap
- src/services/xInventory.js: generated inventory loading and search
- src/services/xAuth.js: Vault/Postgres-backed credential profile storage and auth resolution
- src/services/xApi.js: authenticated X API execution layer
- src/mcp/server.js: MCP tool registration, mutation guards, and generated endpoint wiring
- src/http/server.js: HTTP MCP transport with auth, limits, and access logging
Persistence model:
- Vault stores actual secret values.
- Postgres stores profile metadata, default profile selectors, and all non-secret config.
APP_NAMEis 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 metadatax_scope_info: resolve tenant/principal scope paths and persistence detailsx_health_check: validate Vault and Postgres connectivity for a selected scopex_schema_discovery: search the generated X endpoint inventoryx_query_suggestion: recommend a safe tool sequence for a workflow
Credential tools:
x_auth_upsert_app_credentialsx_auth_upsert_principal_credentialsx_auth_get_scope_credentialsx_auth_delete_profile
Config tools:
x_config_listx_config_getx_config_setx_config_delete
Generated X API tools:
- one
x_api_*tool per OpenAPIoperationId - 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.defaultProfileKeyx.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_IDMCP_CONFIG_DEFAULT_USER_IDMCP_CONFIG_DEFAULT_ACCOUNT_IDMCP_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.
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.