Skip to main content
Glama
baryhuang

MCP Server - Twitter NoAuth

twitter_post_tweet

Publish tweets directly using a Twitter OAuth2 access token and text content. Integrate with the MCP Server - Twitter NoAuth to enable Twitter API operations without local credential setup.

Instructions

Post a new tweet

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
textYesThe tweet text content
twitter_access_tokenYesTwitter OAuth2 access token

Implementation Reference

  • Core handler function in TwitterClient that performs the HTTP POST to Twitter API v2 /tweets endpoint to create a new tweet, using the provided access token and text.
    def post_tweet(self, text: str) -> str:
        """Post a new tweet
        
        Args:
            text: The tweet text content
        """
        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"Posting tweet with text: {text[:30]}...")
            
            # Twitter API v2 create tweet endpoint
            url = f"{self.api_base_url}/tweets"
            
            headers = {
                "Authorization": f"Bearer {self.access_token}",
                "Content-Type": "application/json"
            }
            
            # Create request body
            data = {
                "text": text
            }
            
            response = requests.post(url, headers=headers, json=data)
            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 post_tweet: {str(e)}")
            return json.dumps({"error": str(e), "status": "error"})
  • Registers the 'twitter_post_tweet' tool with the MCP server in the list_tools handler, including name, description, and input schema.
    types.Tool(
        name="twitter_post_tweet",
        description="Post a new tweet",
        inputSchema={
            "type": "object",
            "properties": {
                "twitter_access_token": {"type": "string", "description": "Twitter OAuth2 access token"},
                "text": {"type": "string", "description": "The tweet text content"}
            },
            "required": ["twitter_access_token", "text"]
        },
    ),
  • Dispatch logic in the main @server.call_tool() handler that extracts arguments, validates 'text', instantiates TwitterClient, calls post_tweet, and returns the result.
    elif name == "twitter_post_tweet":
        text = arguments.get("text")
        
        if not text:
            raise ValueError("text is required for twitter_post_tweet")
        
        results = twitter.post_tweet(text=text)
        return [types.TextContent(type="text", text=results)]
  • Pydantic-like input schema definition for the tool, specifying required parameters: twitter_access_token and text.
    inputSchema={
        "type": "object",
        "properties": {
            "twitter_access_token": {"type": "string", "description": "Twitter OAuth2 access token"},
            "text": {"type": "string", "description": "The tweet text content"}
        },
        "required": ["twitter_access_token", "text"]
    },

Tool Definition Quality

Score is being calculated. Check back soon.

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