explore before twexapi_request, and require durable handoff output instead of chat-only summaries.
Handoff checklist
Connect the API MCP server
Add
https://api.twexapi.io/mcp to your MCP client with either x-api-key or Authorization: Bearer <token>.Connect the Docs MCP server
Add
https://docs.twexapi.io/mcp when the agent should search Twexapi documentation before choosing API routes.Discover before calling
Instruct the agent to call
explore first, using a query or category that matches the task.Require relative paths
Instruct the agent to call
twexapi_request only with relative paths returned by explore.Preserve handoff fields
Require IDs, cursors, task IDs, route names, status, and credit fields in the final output.
Agent route checklist
Read docs first
Use Docs MCP athttps://docs.twexapi.io/mcp for public documentation, API parameters, setup instructions, error codes, SDK guidance, and examples.
Discover the API route
Use API MCPexplore to find the exact endpoint, method, request schema, category, and safety flag.
Execute the API call
Use API MCPtwexapi_request with the exact method and relative path returned by explore. Pass only the documented query and body fields.
Persist outside chat
Use REST, SDKs, a queue, or a workflow tool when a backend must own retries, cursor storage, file downloads, scheduled jobs, or batch orchestration.Hand off results
Store the endpoint path, request parameters, returned IDs,has_more, next_cursor, task IDs, write action IDs, charged credits, and any export or poll route before ending the agent run.
Copy-paste agent instruction
Paste this into your agent’s system instructions, project instructions, or task prompt:Common workflows
Research trending topics
explore(category="trending")twexapi_requestfor/twitter/global-trending/countriestwexapi_requestfor/twitter/global-trending/topicstwexapi_requestfor/twitter/global-trending/tweets
country, topic, content, tweet_id, author_username, created_at, engagement metrics, has_more, next_cursor.
Search tweets
explore(query="advanced search tweets")twexapi_requestfor/twitter/advanced_search- Use
/twitter/advanced_search/pageif the catalog returns a pagination flow
tweet_id, text, author metadata, created time, direct URL, has_more, next_cursor.
Export followers
explore(category="followers")twexapi_requestfor/twitter/followers/{screen_name}/{count}or a page/task endpoint returned byexplore
user_id, username, name, bio, follower count, verified status, task ID, has_more, next_cursor.
Scrape replies
explore(query="tweet replies")twexapi_requestfor/twitter/tweets/{tweet_id}/replies/{count}or/twitter/tweets/{tweet_id}/replies/page
has_more, next_cursor.
Fetch X articles
explore(category="articles")twexapi_requestfor/x/article/{tweet_id}/markdown
Run a write action
explore(query="create tweet", include_writes=true)- Present the exact write body to the user
- Wait for explicit confirmation
twexapi_requestfor the returned write endpoint
tweet_id, write_action_id, status, charged credits, reply target, media URLs.
Handoff output contract
For durable workflows, ask the agent to return compact JSON:rows for records that should go into a CRM, spreadsheet, database, or queue. Use ids when the next worker only needs durable identifiers.
Safety model
Twexapi MCP has three important guardrails:| Guardrail | Behavior |
|---|---|
| API key auth | MCP uses the same API key validation, credit checks, and account controls as the REST API. |
| Allowlisted paths | twexapi_request rejects endpoints outside the MCP catalog. |
| Write flags | Side-effecting actions are marked read_only: false so agents can request confirmation. |
Error handling
When MCP authentication fails, the tool does not run. Preserve the JSON-RPC error:twexapi_request runs and the underlying Twexapi API returns a non-2xx response, ask the agent to preserve the tool result:
| Status | Meaning |
|---|---|
401 | MCP authentication failed before the tool ran; check x-api-key or Bearer auth. |
403 | The API key is unavailable, credits are exhausted, or the action is not allowed. |
429 | Rate limit exceeded. Retry after the limit window. |
5xx | Service-side failure or upstream X/Twitter fetch issue. |
Production guidance
- Use a scoped API key when the agent only needs a specific workflow.
- Prefer read-only workflows for autonomous agents.
- Log prompts, request bodies, route names, and MCP responses for write workflows.
- Require human approval before
read_only: falsecalls. - Keep cookies, auth tokens, API keys, and private DM text out of final user-visible messages.
- Store cursors and task IDs outside chat when another worker needs to continue the job.
- Use direct REST or generated SDKs for scheduled production jobs that need retries, queueing, and durable storage.