Skip to main content
Haystack is a good fit when X/Twitter data becomes part of a retrieval pipeline. Use a small MCP collection step, then convert rows into Haystack Document objects.

Prerequisites

  • Python 3.10+
  • A Twexapi API key
  • Haystack installed in your retrieval pipeline

Install

MCP collection step

  1. Call Twexapi MCP with a focused task, such as searching tweets or loading a thread.
  2. Convert returned rows into Document objects.
  3. Add metadata fields like tweet_id, author_username, created_at, route_used, and next_cursor.
  4. Write documents into your Haystack store.

Example handoff shape

Convert to documents

Use MCP for endpoint discovery and collection, then hand the normalized JSON into your Haystack pipeline.

User timeline

For timeline retrieval, ask the agent to preserve a stable user identity and cursor.

Pagination

Store has_more and next_cursor separately from the embedded documents. Do not embed cursors into vector content; keep them in pipeline state so the next run can resume without changing indexed text.

Document mapping

Agent prompt

Async usage

When your pipeline has async stages, run the MCP collection outside the synchronous Haystack pipeline and pass the resulting documents into the async branch.

Error handling

Handle Twexapi errors before creating documents.

Source