Skip to main content
Glama
baryhuang

MCP Server - Twitter NoAuth

twitter_search_tweets

Search for tweets using a specified query and return results via the Twitter API, without requiring local credential setup. Ideal for extracting tweet data programmatically.

Instructions

Search for tweets using the Twitter API

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
max_resultsNoMaximum number of tweets to return (default: 10)
queryYesThe search query to execute
twitter_access_tokenYesTwitter OAuth2 access token

Implementation Reference

  • Core handler logic for the twitter_search_tweets tool: TwitterClient.search_tweets method performs the actual API request to Twitter's search endpoint.
    def search_tweets(self, query: str, max_results: int = 10) -> str:
        """Search for tweets using the Twitter API
        
        Args:
            query: The search query to execute
            max_results: Maximum number of tweets to return (default: 10)
            
        Returns:
            JSON string with search results
        """
        try:
            if not self.access_token:
                return json.dumps({
                    "error": "No valid access token provided. Please refresh your token first.",
                    "status": "error"
                })
            
            logger.debug(f"Searching tweets with query: {query}, max_results: {max_results}")
            
            # Twitter API v2 search recent endpoint
            url = f"{self.api_base_url}/tweets/search/recent"
            
            headers = {
                "Authorization": f"Bearer {self.access_token}"
            }
            
            params = {
                "query": query,
                "max_results": max_results,
                "tweet.fields": "id,text,created_at,author_id",
                "expansions": "author_id",
                "user.fields": "id,name,username"
            }
            
            response = requests.get(url, headers=headers, params=params)
            response.raise_for_status()
            
            # Return the raw JSON response
            return json.dumps(response.json())
            
        except requests.exceptions.RequestException as e:
            logger.error(f"API request error: {str(e)}")
            return json.dumps({"error": str(e), "status": "error"})
        except Exception as e:
            logger.error(f"Exception in search_tweets: {str(e)}")
            return json.dumps({"error": str(e), "status": "error"})
  • Registration of the twitter_search_tweets tool in the MCP server's list_tools decorator, defining name, description, and input schema.
    types.Tool(
        name="twitter_search_tweets",
        description="Search for tweets using the Twitter API",
        inputSchema={
            "type": "object",
            "properties": {
                "twitter_access_token": {"type": "string", "description": "Twitter OAuth2 access token"},
                "query": {"type": "string", "description": "The search query to execute"},
                "max_results": {"type": "integer", "description": "Maximum number of tweets to return (default: 10)"}
            },
            "required": ["twitter_access_token", "query"]
        },
    ),
  • Dispatch handler in @server.call_tool() that extracts arguments and calls TwitterClient.search_tweets for the twitter_search_tweets tool.
    if name == "twitter_search_tweets":
        query = arguments.get("query")
        max_results = int(arguments.get("max_results", 10))
        
        if not query:
            raise ValueError("query is required for twitter_search_tweets")
        
        results = twitter.search_tweets(query=query, max_results=max_results)
        return [types.TextContent(type="text", text=results)]
  • Input schema definition for the twitter_search_tweets tool, specifying required parameters and types.
    "type": "object",
    "properties": {
        "twitter_access_token": {"type": "string", "description": "Twitter OAuth2 access token"},
        "query": {"type": "string", "description": "The search query to execute"},
        "max_results": {"type": "integer", "description": "Maximum number of tweets to return (default: 10)"}
    },
    "required": ["twitter_access_token", "query"]
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It mentions using the Twitter API but fails to describe key traits: whether it's read-only or has side effects, rate limits, authentication requirements (implied by the twitter_access_token parameter but not explained), or what the search returns (e.g., format, pagination). This is inadequate for a tool with no annotation coverage.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence with no wasted words, making it appropriately concise. However, it's front-loaded with only basic information and lacks structure for more complex details, which slightly limits its effectiveness given the tool's functionality.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity of a search tool with no annotations and no output schema, the description is incomplete. It doesn't explain return values, error handling, or behavioral nuances like rate limiting. With siblings present, it also fails to provide contextual differentiation, leaving significant gaps for an AI agent to understand full usage.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents all three parameters (max_results, query, twitter_access_token) with clear descriptions. The description adds no additional meaning beyond what the schema provides, such as query syntax examples or token usage details, resulting in a baseline score of 3.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose3/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description 'Search for tweets using the Twitter API' states the basic action (search) and resource (tweets), but it's vague about scope and differentiation. It doesn't specify what kind of search (e.g., public, recent, filtered) or how it differs from sibling tools like twitter_get_user_tweets or twitter_get_user_replies, which also retrieve tweets.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention context (e.g., for general searches vs. user-specific queries), prerequisites like authentication, or exclusions. With siblings like twitter_get_user_tweets for user timelines, the lack of differentiation leaves usage unclear.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/baryhuang/mcp-twitter-noauth'

If you have feedback or need assistance with the MCP directory API, please join our Discord server