> ## Documentation Index
> Fetch the complete documentation index at: https://opensre.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# X (Twitter) MCP

> Connect X's official MCP server so OpenSRE can search, read, and post on X

## Overview

OpenSRE connects to X’s official [Model Context Protocol (MCP)](https://github.com/xdevplatform/xmcp) server. The agent can call X API capabilities — tweet search, timelines, user profiles, likes, retweets, bookmarks, and posting — through MCP tools.

Unlike PostHog or Sentry’s always-on hosted MCP servers, [xmcp](https://github.com/xdevplatform/xmcp) is designed to run **locally**: you clone the repo, supply your own X API credentials, and run the server yourself. OpenSRE connects to that local endpoint (or a tunneled URL if you need remote access, for example via ngrok).

## Prerequisites

* A **running** [xmcp](https://github.com/xdevplatform/xmcp) instance with your X API credentials configured on that server (`X_BEARER_TOKEN`, and OAuth1/OAuth2 credentials if you need write access such as posting)
* Network access from OpenSRE to the xmcp server URL (local by default; tunnel it if OpenSRE runs elsewhere)

## Setup

### Option 1: Interactive CLI

```bash theme={null}
opensre integrations setup x_mcp
opensre integrations verify x_mcp
```

You will be prompted for the xmcp server URL (defaults to `http://127.0.0.1:8000/mcp`) and, optionally, an auth token if the endpoint is tunneled behind an authenticating proxy.

### Option 2: Environment variables

```bash theme={null}
X_MCP_MODE=streamable-http
X_MCP_URL=http://127.0.0.1:8000/mcp
X_MCP_AUTH_TOKEN=                     # optional, only for a tunneled/proxied endpoint
```

| Variable           | Default                     | Description                                                                                                   |
| ------------------ | --------------------------- | ------------------------------------------------------------------------------------------------------------- |
| `X_MCP_URL`        | `http://127.0.0.1:8000/mcp` | X MCP server URL (local or tunneled)                                                                          |
| `X_MCP_MODE`       | `streamable-http`           | Transport: `streamable-http`, `sse`, or `stdio`                                                               |
| `X_MCP_AUTH_TOKEN` | —                           | Optional bearer token, only if the endpoint requires client auth                                              |
| `X_MCP_COMMAND`    | —                           | Command to launch the xmcp server (`stdio` mode only)                                                         |
| `X_MCP_ARGS`       | —                           | Arguments for the local xmcp command (`stdio` mode only)                                                      |
| `X_BEARER_TOKEN`   | —                           | X API bearer token forwarded when OpenSRE launches the server (`stdio` only); not sent over the MCP transport |

Have OpenSRE launch xmcp via `stdio` instead of connecting to a server you already started:

```bash theme={null}
X_MCP_MODE=stdio
X_MCP_COMMAND=python
X_MCP_ARGS=server.py
X_BEARER_TOKEN=your_x_api_bearer_token
```

### Option 3: Persistent store

```json theme={null}
{
  "version": 1,
  "integrations": [
    {
      "id": "x-mcp-local",
      "service": "x_mcp",
      "status": "active",
      "credentials": {
        "url": "http://127.0.0.1:8000/mcp",
        "mode": "streamable-http"
      }
    }
  ]
}
```

## Credentials

XMCP authenticates to the X API using its own environment (`X_BEARER_TOKEN`, OAuth credentials) at startup. For `streamable-http` / `sse` connections to an already-running server, OpenSRE does **not** need your X API credentials — only the server URL. Set an optional auth token only if the endpoint sits behind an authenticating tunnel or proxy. `X_BEARER_TOKEN` in OpenSRE’s environment is used when OpenSRE launches xmcp itself via `stdio`.

## Tools

| Tool           | What it does                                                                             |
| -------------- | ---------------------------------------------------------------------------------------- |
| `list_x_tools` | List tools the connected X MCP server exposes (compact, filterable)                      |
| `call_x_tool`  | Call a named X MCP tool (for example search tweets, inspect a timeline, look up a tweet) |

Typical flow: call `list_x_tools` first, then `call_x_tool` with the chosen name and arguments. Pass `name_filter` (space- or comma-separated terms, e.g. `"search tweet"`) to narrow a large list, and `include_schema=true` on a narrowed list for the full input schema.

## Verify

```bash theme={null}
opensre integrations verify x_mcp
```

A successful check connects to the MCP server and reports how many tools it discovered.

## Troubleshooting

| Symptom                             | Fix                                                                         |
| ----------------------------------- | --------------------------------------------------------------------------- |
| Verify cannot connect               | Confirm the xmcp server is running and reachable at the configured URL      |
| Tools discovery fails               | Confirm the server’s own X API credentials (`X_BEARER_TOKEN`) are valid     |
| Auth failure to a tunneled endpoint | Set `X_MCP_AUTH_TOKEN` if the proxy requires client auth                    |
| `stdio` launch fails                | Set `X_MCP_COMMAND`, `X_MCP_ARGS`, and `X_BEARER_TOKEN` on the OpenSRE side |

## Security

* Keep X API credentials on the xmcp server process, not in OpenSRE config, when using `streamable-http` / `sse` to an already-running server.
* Prefer read-only X tokens when the agent only needs search and timeline access.
* Do not commit `X_BEARER_TOKEN` or OAuth secrets to source control.
