How to Use the X (Twitter) MCP in LangChain
Run complex social intelligence pipelines using LangChain's multi-step reasoning agents.
Works with every AI agent you already use
…and any MCP-compatible client
Connect X (Twitter) MCP to LangChain
Create your Vinkius account to connect X (Twitter) to LangChain and route execution through our secure gateway. The platform manages server hosting, runtime updates, and security layers. Configuration requires no manual server provisioning.
Profile analysis via `lookup_user_by_username`
You can fetch a user’s full profile details by calling `lookup_user_by_username`. This tool returns the follower count, bio, and verification status for any given X (Twitter) handle. Your agent uses this output as a key piece of data. For instance, one step might get a list of potential accounts, and the next step in the chain filters that list based on whether the profile was found to be verified.
Targeted search via `search_recent_tweets`
The `search_recent_tweets` tool lets you find recent public tweets using specific keywords, handles, or hashtags over the last seven days. You pass a query string, and it returns relevant results. This is perfect for building pipelines. An initial search finds 50 potential topics; your agent then feeds those topics into another step to pull detailed metrics on the most popular ones.
Deep dive with `get_tweet_details`
To get all the deep data, use `get_tweet_details`, which accepts a specific numeric Tweet ID. This gives you the full text and engagement metrics associated with that single post. After your agent identifies an interesting tweet via search, it uses this tool to pull the exact numbers—likes, retweets, etc.—so the final step of the chain can report on its virality score.
Set up X (Twitter) MCP in LangChain
Prerequisites
- Python 3.10+ installed
-
langchain-mcp-adapters+langgraphpackages - Active Vinkius subscription with a valid endpoint token
- 1
Install dependencies
Run
pip install langchain-mcp-adapters langgraph langchain-openai. The MCP adapters package converts MCP tools into native LangChainBaseToolobjects. - 2
Connect via HTTP transport
Use
MultiServerMCPClientwith"transport": "http"pointing to your Vinkius endpoint. Replace[YOUR_TOKEN_HERE]with your token from cloud.vinkius.com. - 3
Create a ReAct agent
Pass the discovered tools to
create_react_agent()from LangGraph. The agent automatically routes X (Twitter) tool calls through the MCP protocol. - 4
Run with any LLM
Swap
ChatOpenAIforChatAnthropic,ChatGoogleGenerativeAI, or any LangChain-compatible model. The MCP tools work identically across all providers.
from langchain_mcp_adapters.client import MultiServerMCPClient
from langgraph.prebuilt import create_react_agent
from langchain_openai import ChatOpenAI
async with MultiServerMCPClient({
"x-twitter-mcp": {
"transport": "http",
"url": "https://edge.vinkius.com/[YOUR_TOKEN_HERE]/mcp",
}
}) as client:
tools = client.get_tools()
agent = create_react_agent(
ChatOpenAI(model="gpt-4o"),
tools,
)
result = await agent.ainvoke({
"messages": "List recent X (Twitter) transactions"
})
print(result["messages"][-1].content) Independent Platform Disclaimer: Vinkius is an independent platform and is not affiliated with, endorsed by, sponsored by, verified by, or otherwise authorized by X (Twitter). All third-party trademarks, logos, and brand names are the property of their respective owners. Their use on this website is strictly for informational purposes to identify service compatibility and interoperability.
Why Choose Vinkius
Vinkius connects your tools to AI with real-time monitoring and automatic cost savings — all from one dashboard.
Real-time monitoring
Live
visibility into every interaction
Connect your favorite tools to your AI and see exactly what's happening — every request, every response, in real time.
Built-in savings
60%
lower AI costs
Vinkius compresses data between your apps and your AI automatically. Lower bills every month — no configuration required.
Single dashboard
One
place for every integration
Every tool your AI connects to, managed from a single screen. One account, complete control.
Common questions about X (Twitter) MCP in LangChain
Use it with your favorite AI tools
Connect this server to Cursor, Claude, VS Code, and more.
Start using the X (Twitter) MCP today
We host it, we monitor it, we maintain it. You just paste one token.