Appearance
Build a Read/Write X Agent Fresh
A worked pattern: an agent that searches X, summarizes what it finds, and posts a result - with write access deliberately scoped through an allow-list.
Architecture
flowchart TD
User[Operator prompt] --> Agent[AI Agent / MCP client]
Agent --> Docs[Docs MCP
search_x, get_page_x]
Agent --> XMCP[XMCP
allow-listed tools]
XMCP --> API[(X API v2)]
subgraph Allow-list
T1[searchPostsRecent]
T2[getUsersByUsername]
T3[getPostsById]
T4[createPosts]
end
XMCP --- T1
XMCP --- T2
XMCP --- T3
XMCP --- T4Step 1 - Scope the tools
Give the agent exactly what it needs and nothing more. In .env:
bash
X_API_TOOL_ALLOWLIST=searchPostsRecent,getUsersByUsername,getPostsById,createPostsRestart XMCP so the allow-list takes effect. The agent can now read and create posts, but cannot delete, follow, message, or manage lists.
Step 2 - Wire both servers
json
{
"mcpServers": {
"xmcp": { "url": "http://127.0.0.1:8000/mcp" },
"x-docs": { "url": "https://docs.x.com/mcp" }
}
}Step 3 - The task flow
sequenceDiagram
participant Op as Operator
participant Ag as Agent
participant D as Docs MCP
participant X as XMCP
Op->>Ag: "Summarize what people say about MCP today, then post a takeaway"
Ag->>D: search_x("recent search query operators")
D-->>Ag: Query syntax + params
Ag->>X: searchPostsRecent(query="MCP -is:retweet lang:en")
X-->>Ag: Recent posts
Ag->>Ag: Summarize themes
Ag->>X: createPosts(text="Today's MCP takeaways: ...")
X-->>Ag: New post ID
Ag-->>Op: Done - posted, here is the linkStep 4 - Guardrails to add
| Concern | Mitigation |
|---|---|
| Agent posts something unintended | Keep createPosts out of the allow-list until you trust it; require human confirmation before write tools |
| Runaway loops hit rate limits | Cache reads, respect x-rate-limit-reset, back off on 429 (see Rate Limits) |
| Credential exposure | Keep .env gitignored; never echo tokens |
| Compliance | Respect Developer Guidelines and Display Requirements; do not automate prohibited behavior |
Read-only variant
For a purely analytical agent, drop the write tool:
bash
X_API_TOOL_ALLOWLIST=searchPostsRecent,getUsersByUsername,getPostsById,getUsersPostsNow the agent can research and summarize but cannot change anything on X.