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

# MCP execute examples for tweet search & replies

> Copy MCP execute examples that summarize tweets with guarded pagination and scrape tweet replies to CSV, JSON, or XLSX through the Xquik sandbox with credits.

> For the complete documentation index, see [llms.txt](https://docs.xquik.com/llms.txt).

Run these inside the [`execute` tool](https://docs.xquik.com/mcp/tools#execute). Each example is one sandbox call.

## Examples

> Summarize up to 100 tweets with guarded pagination (credits required)

Use `q` for keywords and X (Twitter) search operators.
For a single stored link, pass a plain Tweet ID or X status URL.

```javascript theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/bash.json","/languages/csharp.json","/languages/go.json","/languages/java.json","/languages/javascript.json","/languages/kotlin.json","/languages/php.json","/languages/python.json","/languages/ruby.json","/languages/typescript.json"]}}
async () => {
  const target = 100;
  const query = "from:username giveaway";
  const seenIds = new Set();
  const seenCursors = new Set();
  const sampleTweets = [];
  let cursor;
  let hasMore = true;
  let nextCursor = "";
  let stopReason = "page_cap";

  for (let pageNumber = 0; pageNumber < 10 && seenIds.size < target && hasMore; pageNumber += 1) {
    const { result: page } = await xquik.request({
      path: "/api/v1/x/tweets/search",
      query: {
        q: query,
        limit: String(Math.min(200, target - seenIds.size)),
        ...(cursor ? { cursor } : {}),
      },
    });

    for (const tweet of page.tweets) {
      if (seenIds.has(tweet.id) || seenIds.size >= target) continue;
      seenIds.add(tweet.id);
      if (sampleTweets.length < 20) {
        sampleTweets.push({
          tweet_id: tweet.id,
          text_excerpt: tweet.text?.slice(0, 120) ?? null,
          author_id: tweet.author?.id ?? null,
          author_username: tweet.author?.username ?? null,
          created: tweet["created"] ?? null,
          like_count: tweet.like_count ?? null,
          view_count: tweet.view_count ?? null,
        });
      }
    }

    hasMore = Boolean(page.has_more);
    nextCursor = page.next_cursor ?? "";
    if (!hasMore) {
      stopReason = "exhausted";
      break;
    }
    if (!nextCursor || nextCursor === cursor || seenCursors.has(nextCursor)) {
      stopReason = "cursor_stalled";
      break;
    }
    seenCursors.add(nextCursor);
    cursor = nextCursor;
  }

  return {
    source: "xquik_mcp",
    job: "tweet_search",
    query,
    rows_seen: seenIds.size,
    sample_tweets: sampleTweets,
    has_more: hasMore,
    next_cursor: nextCursor,
    stop_reason: seenIds.size >= target ? "requested_total" : stopReason,
  };
};
```

> Scrape tweet replies to CSV, JSON, or XLSX (credits required)

```javascript theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/bash.json","/languages/csharp.json","/languages/go.json","/languages/java.json","/languages/javascript.json","/languages/kotlin.json","/languages/php.json","/languages/python.json","/languages/ruby.json","/languages/typescript.json"]}}
async () => {
  const body = {
    toolType: "reply_extractor",
    targetTweetId: "1893704267862470862",
    resultsLimit: 500,
  };

  const { result: extraction } = await xquik.request({
    path: "/api/v1/extractions",
    method: "POST",
    body,
  });

  return {
    source: "xquik_mcp",
    job: "reply_extraction",
    extraction_id: extraction.id,
    status: extraction.status,
    target_tweet_id: body.targetTweetId,
    results_limit: body.resultsLimit,
    poll: `/api/v1/extractions/${extraction.id}`,
    export_csv: `/api/v1/extractions/${extraction.id}/export?format=csv`,
    export_json: `/api/v1/extractions/${extraction.id}/export?format=json`,
    export_xlsx: `/api/v1/extractions/${extraction.id}/export?format=xlsx`,
  };
};
```

## Next steps

* [MCP tools](https://docs.xquik.com/mcp/tools.md)
* [MCP overview](https://docs.xquik.com/mcp/overview.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.