WEIR

LangChain Twitter Tool in 2026: Read X Posts in an Agent

A working LangChain Twitter tool for 2026: load Weir's X tools over MCP or wrap one REST call in @tool, tested on real X output, with the cost per search.


Published · Updated · 7 min read

Cover image: X posts, inside a LangChain agent

For a LangChain Twitter tool in 2026, load an X MCP server with langchain-mcp-adapters, or wrap one REST call in a custom @tool.

This guide is for Python developers whose LangChain or LangGraph agent reads X (Twitter). You get both routes, tested on a real response, with costs. We run Weir, the API in the examples, so weigh our view knowing that.

from langchain_mcp_adapters.client import MultiServerMCPClient

client = MultiServerMCPClient({"weir": {
    "transport": "http",
    "url": "https://api.weirapp.io/mcp",
    "headers": {"Authorization": "Bearer weir_live_..."},
}})
tools = await client.get_tools()  # in async code: search_x, get_x_thread, ...
  1. Get a keySign up with no card and set WEIR_API_KEY.
  2. Load the X toolsMultiServerMCPClient connects to Weir over streamable HTTP.
  3. Ask a LangGraph agentcreate_agent picks search_x and its filters itself.
  4. Or write a @toolWrap POST /v1/x/search and return only the fields you need.

Is there a LangChain Twitter tool in 2026?

LangChain's community package ships one X integration, and it predates X's current API.

TwitterTweetLoader calls Tweepy's API.user_timeline and API.get_user, which Tweepy documents as its "Twitter API v1.1 Interface". X's versioning page calls v1.1 "Legacy" and says to use v2 for all new projects.

Good

  • Ships in langchain-community and installs with LangChain 1.x

Watch out

  • Needs your own X developer app and its keys
  • Returns text, date and profile only, with no like counts
  • We couldn't confirm that new pay-per-use apps can call its v1.1 timeline

twitter-langchain is a separate toolkit built on Coinbase's cdp-agentkit-core. Its last release came in January 2025.

Good

  • Posts and replies from your own account

Watch out

  • Reads only your own account and mentions, with no search
  • Pins langchain<0.4.0, so it can't share an environment with LangChain 1.x

Pick by job: only the last two routes search X, and neither needs your own developer app.

Route Searches X LangChain 1.x Your own X app Cost to read
TwitterTweetLoader No, timelines Yes Required X API rates
twitter-langchain No No Required X API rates
Weir over MCP Yes Yes Not needed 1 credit a post
Weir as a @tool Yes Yes Not needed 1 credit a post

On X's API you pay $0.005 per post read, as of October 2026. Weir adds a credit per call.

Step 1: Get a key and install

Sign up with no card, create a key, then install LangChain, a model package and the adapters:

pip install "langchain[anthropic]" langchain-mcp-adapters requests
export WEIR_API_KEY="weir_live_..."
export ANTHROPIC_API_KEY="sk-ant-..."

You can use any chat model with tool calling; the examples use Claude Sonnet 5.5.

Step 2: Load X tools with langchain-mcp-adapters

Weir's MCP server takes a key as an Authorization: Bearer header, and the adapter sends your headers with every request:

import asyncio, os
from langchain_mcp_adapters.client import MultiServerMCPClient

client = MultiServerMCPClient({"weir": {
    "transport": "http",  # streamable HTTP; "streamable_http" also works
    "url": "https://api.weirapp.io/mcp",
    "headers": {"Authorization": f"Bearer {os.environ['WEIR_API_KEY']}"},
}})

async def x_tools():
    tools = await client.get_tools()
    return [t for t in tools if t.name.startswith(("search_x", "get_x_", "get_usage"))]

Three things to know about it:

  • Names arrive as Weir sends them. You get search_x, not weir_search_x, unless you pass tool_name_prefix=True.
  • The filter keeps the model's list short. Weir also serves Reddit tools, and every tool you pass costs tokens.
  • Errors reach the model. The adapter passes Weir's 402 text, "Out of credits. This is not retryable", to your agent.

The example targets adapters 0.3.2. On LangChain 1.4 you can also install langchain[mcp], a built-in its docs mark as beta.

Step 3: Ask a LangGraph Twitter agent about recent posts

LangChain's docs say its agents "are built on top of LangGraph", so create_agent gives you a LangGraph agent with no graph code:

from langchain.agents import create_agent

async def main():
    agent = create_agent("anthropic:claude-sonnet-5-5", await x_tools(),
        system_prompt="Search X with limit 10 or less. Never retry a 402 error.")
    result = await agent.ainvoke({"messages": [{"role": "user",
        "content": "What did @LangChain post on X this week? One line each, with links."}]})
    print(result["messages"][-1].content)

asyncio.run(main())

To answer you, the model needs search_x with fromUsers and since. We ran that search through Weir's MCP server on 22 October 2026, with onlyOriginal and limit: 3:

← 3 posts · 4 credits (1 + 3 × 1)
   9 likes  @LangChain  Join us, @ExtendHQ, and @tryramp this Thursday for a private screening...
   0 likes  @LangChain  RT, a repost of another account
  10 likes  @LangChain  On October 28th, go behind the scenes of our design agent...

One surprise: onlyOriginal drops replies, not reposts, so a repost came back. The tool in Step 4 filters them out for you.

Building your own StateGraph instead? The adapter's README passes the same tools to LangGraph's ToolNode.

Step 4: Or skip MCP with a custom @tool

A plain @tool around POST /v1/x/search gives you two controls MCP doesn't: which fields the model reads, and the most a call can spend.

import os, requests
from langchain_core.tools import tool

@tool
def search_x(query: str, limit: int = 10) -> list[dict] | str:
    """Search public X (Twitter) posts. X search syntax works in query,
    e.g. "from:LangChain since:2026-10-15" or "langgraph lang:en"."""
    r = requests.post("https://api.weirapp.io/v1/x/search", timeout=60,
        headers={"Authorization": f"Bearer {os.environ['WEIR_API_KEY']}"},
        json={"query": query, "limit": min(limit, 20)})
    if not r.ok:  # 402 = out of credits: report it, never retry
        return f"Weir error {r.status_code}: {r.json()['error']['message']}"
    return [{"user": p["author"]["username"], "text": p["text"],
             "likes": p["likeCount"], "url": p["url"]}
            for p in r.json()["data"] if not p.get("retweetedPost")]

Pass [search_x] to create_agent instead of the MCP tools. We ran the real response from Step 3 through it offline, and it returned two posts and dropped the repost:

[
  {
    "user": "LangChain",
    "text": "Join us, @ExtendHQ, and @tryramp this Thursday...",
    "likes": 9,
    "url": "https://x.com/LangChain/status/2112998266715459829"
  },
  {
    "user": "LangChain",
    "text": "On October 28th, go behind the scenes of our design agent...",
    "likes": 10,
    "url": "https://x.com/LangChain/status/2112975823095628272"
  }
]

Three choices in that tool matter:

  • min(limit, 20) caps a call at 21 credits. X serves about 20 posts per page anyway.
  • Four fields, not twenty. Fewer fields mean fewer tokens per result.
  • A 402 comes back as text. The agent can tell you it's out of credits instead of retrying.

If you need paging and CSV export, see how to get tweets with Python.

What does a LangChain Twitter agent cost?

Each search_x call costs a credit plus a credit per post, and failed calls are free.

Reading 1,000 X posts, as of October 2026
X API, pay-per-use$5.00
Weir, $5 pack$0.21
TwitterAPI.io$0.15

X's pricing page lists $0.005 per post read. Weir's figure assumes 20-post pages. That's 1,050 credits for the thousand.

Your 5,000 free monthly credits cover about 450 ten-post agent searches. Price your own job with the X API cost calculator.

If it doesn't work

  • 401 on connect. The header must read Bearer weir_live_..., with a space after Bearer.
  • 429 in a loop. Weir's free tier allows 30 requests a minute, and a search counts as 2. Wait for Retry-After.
  • Your filter finds no tools. With tool_name_prefix=True, names start with weir_, so match weir_search_x.
  • A call times out. The adapter waits 30 seconds by default. Set "timeout" in the connection to change it.

When not to use Weir

  • Your agent has to post or reply. Weir is read-only. Use Tweepy with X's API, where a post costs $0.015 as of October 2026, or $0.20 with a link.
  • A contract with X is a must. Weir isn't licensed by X or affiliated with it, so access can change.
  • Price per post is all that matters. TwitterAPI.io lists $0.15 per 1,000 tweets, less than you'd pay us.
  • You already pay for an X app. X's official MCP server runs on your own developer app; see our guide to X's MCP server.

FAQ

Does LangChain have a Twitter tool?

Not a current one. langchain-community ships TwitterTweetLoader, a document loader built on Tweepy's v1.1 calls, and its tools folder has no X tool. Third-party packages and MCP servers fill the gap.

Does TwitterTweetLoader still work?

It installs with LangChain 1.x, but it needs your own X developer app and calls the v1.1 user timeline. X lists v1.1 as legacy with limited support, and we couldn't confirm that new pay-per-use apps can call it. Start new work on v2 or MCP.

How do I connect an MCP server to LangChain?

Install langchain-mcp-adapters and give MultiServerMCPClient a server name with transport, url and any headers. Then await client.get_tools() returns LangChain tools you can pass to create_agent.

Can I use the official X API in LangChain to post?

Yes. Wrap Tweepy's v2 Client in a @tool, as in Step 4, and its create_tweet can post. You need your own developer app with credits. Weir can't post, since it only reads public data. Put a human approval step in front of any tool that can.

Sources

All pages checked on 22 October 2026.