Skip to main content

Overview

Use the X Live Search MCP server from your ATXP-powered agent to search X (formerly Twitter) for posts and conversations using xAI’s Grok models. The server provides advanced filtering capabilities and returns AI-generated summaries with citations to source posts.

Example prompts

  • “What are the latest updates from Stripe?”
  • “Find popular tweets about AI from the last week with at least 100 likes”
  • “Search for posts from @elonmusk about SpaceX”

Tools

Usage

1

Define the X Live Search service

Create a reusable service configuration that points to the MCP server and standardizes how you pass arguments and read results. This lets your agent easily interact with the X Live Search tool in a consistent manner.
const xLiveSearchService = {
    mcpServer: 'https://x-live-search.mcp.atxp.ai/',
    toolName: 'x_live_search',
    description: 'ATXP X Live Search MCP server',
    getArguments: (params: {
      query: string,
      included_x_handles?: string[],
      excluded_x_handles?: string[],
      post_favorite_count?: number,
      post_view_count?: number,
      from_date?: string,
      to_date?: string
    }) => params,
    getResult: (result: any) => {
      const jsonResult = result.content[0].text;
      const parsed = JSON.parse(jsonResult);
      return {
        status: parsed.status,
        query: parsed.query,
        message: parsed.message,
        citations: parsed.citations,
        errorMessage: parsed.errorMessage
      };
    }
  };
2

Create an ATXP client

  • Using an ATXP account
  • Using a Base account
  • Using a Solana account
  • Using a Worldchain account
  • Using a Polygon account
Create a client using an ATXP account by importing the ATXP client SDK and other dependencies.
// Import the ATXP client SDK
import { atxpClient, ATXPAccount } from '@atxp/client';

// Read the ATXP account details from environment variables
const atxpConnectionString = process.env.ATXP_CONNECTION;

// Create a client using the `atxpClient` function
const client = await atxpClient({
  mcpServer: xLiveSearchService.mcpServer,
  account: new ATXPAccount(atxpConnectionString),
});
3

Use the X Live Search service in your agent

Call the X Live Search tool by passing your search query and optional filters as arguments.Read the response using the getResult method.
const searchParams = {
  query: "What are the latest updates from Stripe?",
  included_x_handles: ["stripe"],
  post_favorite_count: 100,
  from_date: "2024-01-01"
};

try {
  const result = await client.callTool({
      name: xLiveSearchService.toolName,
      arguments: xLiveSearchService.getArguments(searchParams),
  });
  const { status, query, message, citations, errorMessage } = xLiveSearchService.getResult(result);

  if (status === 'success') {
    console.log('Query:', query);
    console.log('Summary:', message);
    console.log('Citations:', citations);
  } else {
    console.error('Search failed:', errorMessage);
  }
} catch (error) {
  console.error(`Error with ${xLiveSearchService.description}:`, error);
  process.exit(1);
}
You should see the search summary and citations printed in your console.