Build a LangChain Tool for Live Social Media Data (Followers, Posts, Comments)
Build a LangChain Tool for Live Social Media Data (Followers, Posts, Comments)
To build a LangChain social media tool, wrap a public social data read (such as the SocialLens /v1/profile endpoint) in a function decorated with @tool, give it a typed Pydantic args schema, and pass it to a LangGraph create_react_agent. The agent then calls the tool at run time and answers with live follower counts, posts, and comments instead of stale training data.
Key facts
- SocialLens reads public data from 17 networks with one API key and one JSON schema. It is read-only and never logs in.
- A LangChain tool is a Python function plus a description. With
@tool, the docstring becomes the description the model sees. - Every SocialLens profile response carries
is_exact(exact vs rounded count) andfetched_at(when it was read). - Live anchor: Instagram @cristiano had 679,519,176 followers on 2026-12-04, with
is_exact: true. - If you would rather not write tools, the SocialLens MCP server (
npx -y sociallens-mcp) exposes the same reads as ready-made tools.
The tool is the easy part. Twenty lines of Python turn any HTTP endpoint into a LangChain tool. The hard part is the data behind it: reliable public counts across many networks, one schema your agent can learn once, and honest provenance so the agent knows whether a number is exact and how fresh it is. This guide covers both. For the broader picture of why agents need live social data, start with the pillar guide on social media data for AI agents.
What does the live data look like before any LangChain code?
Before you add an abstraction, look at the raw read. Below is the one hard data point this article is built on: a live SocialLens read of Cristiano Ronaldo's Instagram profile.
Original data: one live profile read, with computed ratios
| Field (as returned) | Value | Notes |
|---|---|---|
platform |
||
username |
cristiano | |
followers |
679,519,176 | Exact count |
is_exact |
true | Instagram exposes a precise figure |
verified |
true | |
following |
640 | |
videos |
4,164 | Post/media count field |
| Followers per account followed | about 1,061,749 | Computed: 679,519,176 ÷ 640 |
Followers per item in videos |
about 163,189 | Computed: 679,519,176 ÷ 4,164 |
Data last verified: 2026-12-04
The two computed rows are simple division on the live figures, rounded to the nearest whole number. They show the reason a tool beats model memory: any number a model "remembers" for an account this size is wrong by millions within weeks. A live read with is_exact: true is the only defensible source for an exact answer.
How do I call the SocialLens API directly?
Get a key at sociallens.dev/keys (register at sociallens.dev/register). Then make a plain HTTP request. All three endpoints in this guide use the same header: Authorization: Bearer YOUR_KEY.
pip install langchain langchain-anthropic langgraph requests
export SOCIALLENS_API_KEY=sk_live_YOUR_KEY
export ANTHROPIC_API_KEY=your_anthropic_key
import os
import requests
API = "https://api.sociallens.dev/v1"
HEADERS = {"Authorization": f"Bearer {os.environ['SOCIALLENS_API_KEY']}"}
r = requests.get(
f"{API}/profile",
params={"platform": "instagram", "username": "cristiano"},
headers=HEADERS,
timeout=30,
)
r.raise_for_status()
data = r.json()
print(data["followers"], data["is_exact"], data["fetched_at"])
The /profile response contains these fields: exists, username, platform, nickname, verified, private, followers, is_exact, following, likes, videos, bio, avatar, id, created_at, external_link, category, fetched_at, cached, source_cached, credits.
A trimmed view of the live read (other fields omitted, timestamp shown as a placeholder for the 2026-12-04 read):
{
"exists": true,
"platform": "instagram",
"username": "cristiano",
"verified": true,
"followers": 679519176,
"is_exact": true,
"following": 640,
"videos": 4164,
"fetched_at": "<ISO 8601 timestamp, 2026-12-04>"
}
The schema is identical when you change platform=instagram to platform=tiktok or platform=youtube. That consistency is what lets one tool cover many networks. The unified social media data API guide explains the schema design in more depth, and the follower count API guide covers count precision per network.
How do I turn an API into a LangChain tool?
Decorate a function with @tool from langchain_core.tools. LangChain reads three things from it: the function name (tool name), the type hints (argument schema), and the docstring (tool description). The model never sees your code. It only sees the name, the description, and the argument schema, so the docstring is effectively a prompt.
import json
import os
import requests
from langchain_core.tools import tool
API = "https://api.sociallens.dev/v1"
HEADERS = {"Authorization": f"Bearer {os.environ['SOCIALLENS_API_KEY']}"}
@tool
def get_social_profile(platform: str, username: str) -> str:
"""Get the LIVE public profile of a social media account.
Use this whenever the user asks about follower counts, following counts,
verification, bio, or post counts for a public account. Never answer those
from memory.
Args:
platform: lowercase network name, e.g. instagram, tiktok, youtube, x,
reddit, facebook, threads, linkedin, pinterest.
username: the account handle without the leading @.
Returns JSON with followers, is_exact (true = exact count, false = rounded
by the platform), and fetched_at (when the data was read).
"""
r = requests.get(
f"{API}/profile",
params={"platform": platform, "username": username.lstrip("@")},
headers=HEADERS,
timeout=30,
)
r.raise_for_status()
d = r.json()
keep = ["exists", "platform", "username", "nickname", "verified", "private",
"followers", "is_exact", "following", "videos", "bio", "fetched_at"]
return json.dumps({k: d.get(k) for k in keep})
The docstring-as-description behavior (the part that trips people up)
Print what the model will actually receive:
print(get_social_profile.name) # get_social_profile
print(get_social_profile.description) # the docstring text
print(get_social_profile.args) # {'platform': {...}, 'username': {...}}
print(get_social_profile.invoke({"platform": "instagram", "username": "cristiano"}))
Three consequences follow:
- An empty or vague docstring means the model guesses. A docstring of "Gets profile" leads to the tool being skipped or called with wrong arguments.
- The docstring is where you state when to call the tool. "Never answer from memory" in the description measurably shifts behavior in practice, because it sits right next to the tool schema the model reasons over.
- Trim the return payload. Returning
avatarURLs and internal fields burns context tokens for nothing. The tool above keeps 12 fields.
Returning a JSON string rather than a dict keeps the tool message predictable across LangChain versions.
Why use a typed Pydantic args schema?
A typed schema constrains what the model can send. If platform is a free string, the model may send "Instagram", "IG", or "twitter". If it is a Literal, the schema the model sees lists the allowed values, and invalid calls fail validation before they ever hit the API.
from typing import Literal
from pydantic import BaseModel, Field
from langchain_core.tools import StructuredTool
Platform = Literal[
"instagram", "tiktok", "youtube", "x", "reddit",
"facebook", "threads", "linkedin", "pinterest",
]
class ProfileArgs(BaseModel):
platform: Platform = Field(description="Lowercase social network name.")
username: str = Field(description="Account handle without the leading @.")
def _get_profile(platform: str, username: str) -> str:
r = requests.get(
f"{API}/profile",
params={"platform": platform, "username": username.lstrip("@")},
headers=HEADERS,
timeout=30,
)
r.raise_for_status()
d = r.json()
keep = ["exists", "platform", "username", "nickname", "verified", "private",
"followers", "is_exact", "following", "videos", "bio", "fetched_at"]
return json.dumps({k: d.get(k) for k in keep})
profile_tool = StructuredTool.from_function(
func=_get_profile,
name="get_social_profile",
description=(
"Get the LIVE public profile of a social account: followers, following, "
"verified, bio, post count. Returns is_exact (exact vs rounded) and "
"fetched_at. Always use this for follower questions; never use memory."
),
args_schema=ProfileArgs,
)
The Literal lists nine values from the SocialLens platform set. SocialLens reads 17 networks in total; extend the list with the exact platform strings published in the OpenAPI file at sociallens.dev/openapi.json rather than guessing spellings.
Typed args reduce bad tool calls for three reasons: the model sees an enum instead of guessing, the Field descriptions give per-argument guidance, and Pydantic rejects malformed input with a readable error the agent can correct on the next step.
How does the agent know when to call the tool?
The model decides based on three inputs: the user question, your system prompt, and each tool's description. A LangGraph ReAct agent loops: the model reads the question, emits a tool call if one fits, receives the tool result, and repeats until it can answer. Your job is to make "call the tool" the obvious choice for any live fact.
Here is the agent wired to Claude through the official LangChain Anthropic integration. The tool itself is model-agnostic, so any chat model with tool calling would work, but this guide uses Claude throughout.
from langchain_anthropic import ChatAnthropic
from langgraph.prebuilt import create_react_agent
model = ChatAnthropic(model="claude-sonnet-5-5", temperature=0)
SYSTEM = """You answer questions about public social media accounts.
Rules:
1. For any follower count, post, or comment, call a tool. Never use memory.
2. Report the number exactly as returned.
3. If is_exact is true, say it is an exact count. If false, say the platform
only exposes a rounded figure and do not add false precision.
4. Always state when the data was read, using fetched_at.
5. If a tool returns an error or exists is false, say so plainly."""
agent = create_react_agent(model, tools=[profile_tool], prompt=SYSTEM)
result = agent.invoke(
{"messages": [{"role": "user",
"content": "How many Instagram followers does Cristiano Ronaldo have?"}]}
)
print(result["messages"][-1].content)
What a grounded answer looks like (based on the 2026-12-04 read):
Cristiano Ronaldo (@cristiano) has 679,519,176 Instagram followers. This is an exact count (is_exact: true), read live on 2026-12-04. The account is verified and follows 640 accounts.
Without the tool, a model answers from training data with an outdated, usually rounded figure and no date. With the tool, the answer is exact, dated, and traceable to a specific read. That difference is the whole point of the build.
Why the agent must respect is_exact and fetched_at
Quotable answer: An agent should report
is_exactbecause some platforms only expose rounded follower counts. YouTube, for example, returnsis_exact: false. If the agent prints a rounded figure as if it were precise, it invents accuracy. Reportingfetched_attells the reader when the number was true, which matters for any count that changes daily.
is_exact value |
What it means | How the agent should phrase it |
|---|---|---|
true (Instagram @cristiano, 2026-12-04) |
Platform exposed a precise count | "exactly N followers, as of DATE" |
false (YouTube) |
Platform shows a rounded figure | "about N followers (rounded by the platform), as of DATE" |
To watch the loop step by step, stream it:
for step in agent.stream(
{"messages": [{"role": "user", "content": "Is @cristiano verified on Instagram?"}]},
stream_mode="values",
):
step["messages"][-1].pretty_print()
You will see the user message, Claude's tool call with platform="instagram" and username="cristiano", the JSON tool result, and the final answer. For a full profile-analysis agent built on this pattern, see social media profile analysis with an AI agent.
How do I add posts and comments tools?
Add two more tools against the same base URL and header. One agent then covers profiles, posts, and comments.
The endpoints:
GET https://api.sociallens.dev/v1/profile-posts?platform=PLATFORM&username=USERNAME&limit=10
GET https://api.sociallens.dev/v1/post-comments?platform=PLATFORM&url=POST_URL&limit=50
/profile-posts returns top-level exists, username, platform, count, has_more, next_cursor, is_exact, fetched_at, plus posts, each with id, url, caption, published_at, likes, views, comments, shares, likes_hidden.
/post-comments returns top-level exists, url, platform, count, total, has_more, next_cursor, fetched_at, plus comments, each with id, text, author (username, name, verified), likes, replies, published_at.
A complete multi-tool module with error handling
This version adds a shared request helper so every tool degrades gracefully. It is the code to copy.
import json
import os
from typing import Literal
import requests
from pydantic import BaseModel, Field
from langchain_core.tools import StructuredTool
from langchain_anthropic import ChatAnthropic
from langgraph.prebuilt import create_react_agent
API = "https://api.sociallens.dev/v1"
HEADERS = {"Authorization": f"Bearer {os.environ['SOCIALLENS_API_KEY']}"}
Platform = Literal[
"instagram", "tiktok", "youtube", "x", "reddit",
"facebook", "threads", "linkedin", "pinterest",
]
def _call(path: str, params: dict) -> dict:
"""GET a SocialLens endpoint. Never raises; returns {'error': ...} instead."""
try:
r = requests.get(f"{API}/{path}", params=params, headers=HEADERS, timeout=30)
except requests.RequestException as e:
return {"error": f"Network error reaching SocialLens: {e}"}
if r.status_code in (401, 403):
return {"error": "SocialLens rejected the API key. Check SOCIALLENS_API_KEY."}
if not r.ok:
return {"error": f"SocialLens returned HTTP {r.status_code}: {r.text[:200]}"}
try:
data = r.json()
except ValueError:
return {"error": "SocialLens returned a non-JSON response."}
if data.get("exists") is False:
return {"error": f"No public account or post found for {params}. "
"Check the spelling or platform."}
return data
# ---- profile -------------------------------------------------------------
class ProfileArgs(BaseModel):
platform: Platform = Field(description="Lowercase social network name.")
username: str = Field(description="Account handle without the leading @.")
def _profile(platform: str, username: str) -> str:
d = _call("profile", {"platform": platform, "username": username.lstrip("@")})
if "error" in d:
return json.dumps(d)
keep = ["platform", "username", "nickname", "verified", "private",
"followers", "is_exact", "following", "videos", "bio", "fetched_at"]
return json.dumps({k: d.get(k) for k in keep})
# ---- posts ---------------------------------------------------------------
class PostsArgs(BaseModel):
platform: Platform = Field(description="Lowercase social network name.")
username: str = Field(description="Account handle without the leading @.")
limit: int = Field(default=10, ge=1, le=50, description="How many recent posts.")
def _posts(platform: str, username: str, limit: int = 10) -> str:
d = _call("profile-posts", {"platform": platform,
"username": username.lstrip("@"), "limit": limit})
if "error" in d:
return json.dumps(d)
posts = [
{k: p.get(k) for k in ["url", "caption", "published_at", "likes",
"views", "comments", "shares", "likes_hidden"]}
for p in d.get("posts", [])
]
for p in posts:
if p["caption"]:
p["caption"] = p["caption"][:280]
return json.dumps({"username": d.get("username"), "count": d.get("count"),
"has_more": d.get("has_more"), "is_exact": d.get("is_exact"),
"fetched_at": d.get("fetched_at"), "posts": posts})
# ---- comments ------------------------------------------------------------
class CommentsArgs(BaseModel):
platform: Platform = Field(description="Lowercase social network name.")
url: str = Field(description="Full public URL of the post.")
limit: int = Field(default=50, ge=1, le=100, description="How many comments.")
def _comments(platform: str, url: str, limit: int = 50) -> str:
d = _call("post-comments", {"platform": platform, "url": url, "limit": limit})
if "error" in d:
return json.dumps(d)
comments = [
{"text": c.get("text"),
"author": (c.get("author") or {}).get("username"),
"author_verified": (c.get("author") or {}).get("verified"),
"likes": c.get("likes"), "replies": c.get("replies"),
"published_at": c.get("published_at")}
for c in d.get("comments", [])
]
return json.dumps({"url": d.get("url"), "count": d.get("count"),
"total": d.get("total"), "has_more": d.get("has_more"),
"fetched_at": d.get("fetched_at"), "comments": comments})
tools = [
StructuredTool.from_function(
func=_profile, name="get_social_profile", args_schema=ProfileArgs,
description="LIVE public profile: followers, following, verified, bio, "
"post count, is_exact, fetched_at. Use for any account question."),
StructuredTool.from_function(
func=_posts, name="get_profile_posts", args_schema=PostsArgs,
description="LIVE recent public posts of an account with likes, views, "
"comments, shares, and post URLs. Use for 'latest posts' or "
"engagement questions. Post URLs feed get_post_comments."),
StructuredTool.from_function(
func=_comments, name="get_post_comments", args_schema=CommentsArgs,
description="LIVE public comments on one post, given its full URL. Use for "
"sentiment, audience reaction, or 'what are people saying'."),
]
SYSTEM = """You answer questions about public social media accounts.
Use tools for every follower count, post, and comment. Never use memory.
Report is_exact honestly (exact vs rounded) and always state fetched_at.
If a tool returns an error, explain it plainly and do not guess."""
agent = create_react_agent(
ChatAnthropic(model="claude-sonnet-5-5", temperature=0),
tools=tools,
prompt=SYSTEM,
)
if __name__ == "__main__":
q = ("Check @cristiano on Instagram: follower count, his 3 latest posts, "
"and summarize the comments on the most liked one.")
out = agent.invoke({"messages": [{"role": "user", "content": q}]})
print(out["messages"][-1].content)
That question triggers a chain: get_social_profile, then get_profile_posts with limit=3, then get_post_comments with the URL of the most-liked post. The descriptions make the chain explicit ("Post URLs feed get_post_comments"), which is how the model knows to pass one tool's output into another.
Fewer, well-described tools beat many vague ones
Three tools with sharp descriptions outperform ten overlapping ones. Every tool you add is another description the model must weigh on every turn, and overlapping tools ("get_followers", "get_profile", "get_user_stats") invite the wrong pick. Group by the noun (profile, posts, comments), not by the field. For comment-specific patterns such as sentiment summaries and pagination, see the social media comments API guide.
Pagination note: both list endpoints return has_more and next_cursor. The cursor query parameter is documented in the OpenAPI file; add it as an optional cursor argument once you have confirmed the exact parameter name there.
How do I handle errors and missing accounts?
Quotable answer: A LangChain tool should return a clear error string instead of raising. If the account does not exist (
exists: false), the key is invalid, or the network fails, return text like "No public account found for that username." The agent reads it, tells the user, and keeps running instead of crashing the graph.
The _call helper above covers five failure modes:
| Failure | What _call returns |
What the agent does |
|---|---|---|
| Network timeout or DNS failure | "Network error reaching SocialLens" | Reports a temporary failure |
| 401 or 403 | "SocialLens rejected the API key" | Tells you to fix config |
| Other non-2xx status | Status code plus first 200 chars of body | Reports the error |
| Non-JSON body | "non-JSON response" | Reports the error |
exists: false |
"No public account or post found" | Asks the user to check the handle |
Two more cases need handling in the prompt rather than the code:
private: true. SocialLens is public-data-only and never logs in. A private account returns profile metadata but no posts. Tell the agent to say the account is private, not that it has no posts.likes_hidden: true. Some posts hide like counts. The agent should say likes are hidden rather than reporting zero.
If you prefer exceptions, LangChain tools also accept handle_tool_error=True, which converts a raised ToolException into a message for the model. Returning strings is simpler and keeps the behavior explicit.
Can I use the MCP server instead of writing tools?
Yes. SocialLens ships an MCP server that already exposes these reads as tools. It runs locally over stdio via npx. It is not a remote HTTP endpoint. If you are new to the protocol, read what an MCP server is or the official spec at modelcontextprotocol.io.
LangChain / Claude agent
|
MCP client (stdio)
|
SocialLens MCP server (npx -y sociallens-mcp, on your machine)
|
[ read-only boundary: public data only, no login, no DMs, no private accounts ]
|
Public data on 17 networks
Claude Code
One command (see the Claude Code MCP docs):
claude mcp add --env SOCIALLENS_API_KEY=sk_live_YOUR_KEY --transport stdio sociallens -- npx -y sociallens-mcp
Claude Desktop and Cursor
Both use the same block. Put it in claude_desktop_config.json for Claude Desktop or .cursor/mcp.json for Cursor:
{
"mcpServers": {
"sociallens": {
"command": "npx",
"args": ["-y", "sociallens-mcp"],
"env": { "SOCIALLENS_API_KEY": "sk_live_YOUR_KEY" }
}
}
}
Fully quit and reopen the app after editing. More detail is in the Claude social media data guide.
ChatGPT
Build a Custom GPT and import the OpenAPI file at https://sociallens.dev/openapi.json, or use function calling with the same endpoints.
LangChain via the MCP adapter
LangChain can consume MCP servers through the langchain-mcp-adapters package, which converts MCP tools into LangChain tools:
pip install langchain-mcp-adapters
import asyncio
import os
from langchain_mcp_adapters.client import MultiServerMCPClient
from langchain_anthropic import ChatAnthropic
from langgraph.prebuilt import create_react_agent
async def main():
client = MultiServerMCPClient({
"sociallens": {
"command": "npx",
"args": ["-y", "sociallens-mcp"],
"env": {
"SOCIALLENS_API_KEY": os.environ["SOCIALLENS_API_KEY"],
"PATH": os.environ["PATH"],
},
"transport": "stdio",
}
})
tools = await client.get_tools()
agent = create_react_agent(ChatAnthropic(model="claude-sonnet-5-5"), tools)
out = await agent.ainvoke({"messages": [{"role": "user",
"content": "How many Instagram followers does Cristiano Ronaldo have?"}]})
print(out["messages"][-1].content)
asyncio.run(main())
Passing PATH through matters: when you set env explicitly, the child process may not find npx without it.
Which should you pick? Hand-written tools give you control over payload trimming, error text, and descriptions. The MCP route gives you zero tool code and upstream updates for free. The trade-offs are laid out in MCP vs API for AI agent social data, and server options are reviewed in the best social media MCP server guide.
Does it work with Claude?
Yes. Every code sample here uses ChatAnthropic(model="claude-sonnet-5-5") from langchain-anthropic, and Claude handles multi-step tool chains (profile, then posts, then comments) well. Claude Code, Claude Desktop, and Cursor can also use the SocialLens MCP server directly, with no LangChain code at all.
What can the agent read, and what can it not?
Can read (public data only): profiles, recent posts, a single post by URL, post comments, follower and following listings (TikTok), keyword search, video transcripts, and audience demographics, across 17 networks: TikTok, Instagram, YouTube, Facebook, X, Reddit, LinkedIn, Threads, Pinterest, Telegram, Bluesky, Truth Social, Cosmos, SoundCloud, Kwai, GitHub, and Spotify. For finding accounts before reading them, see the social media profile search API.
Cannot read: private accounts' content, DMs, logged-in feeds, or anything behind a login. SocialLens never logs in and cannot post, like, follow, or message. An agent built on it is read-only by construction, which removes a whole class of risk from autonomous agents.
Honest limits: some platforms only expose rounded counts (is_exact: false), and private profiles return metadata without posts. If you need write access (scheduling posts, replying to comments), you need the platform's official API with OAuth, not a read-only data API.
Is it legal to give an agent public social data?
Reading publicly available data is on firmer ground than accessing data behind a login. In hiQ Labs v. LinkedIn, the US Ninth Circuit found that scraping public profiles likely did not violate the Computer Fraud and Abuse Act, though the case later ended with findings tied to LinkedIn's user agreement. The takeaway is that public data is not risk-free: platform terms, GDPR, and CCPA still apply to how you store and use personal data. SocialLens limits exposure by reading only public data and never logging in. Minimize what you store, and do not build profiles of private individuals. This is not legal advice.
Troubleshooting
KeyError: 'SOCIALLENS_API_KEY'. The env var is not set in the shell running Python. Export it, or load it with a.envloader before importing your tools module.- The agent answers from memory and never calls the tool. Strengthen the tool description ("Never answer from memory") and the system prompt. Check
get_social_profile.descriptionis not empty. - Tool called with
"Instagram"or"@cristiano". Use theLiteralplatform type and strip@in the function, as shown. - Context window fills up. You are returning full payloads. Trim fields and truncate captions, as in the multi-tool module.
- MCP server does not appear in Claude Desktop or Cursor. Usually malformed JSON (a trailing comma) or the app was not fully restarted. Quit completely and reopen.
npxnot found when launched from an app or the adapter. GUI apps and explicitenvblocks may not inherit your shellPATH. PassPATH, or use an absolute path tonpx.- Cursor uses the wrong config. Cursor reads both a global and a project
.cursor/mcp.json. Check which file definessociallensand remove duplicates. - 401 or 403. The key is wrong, revoked, or has a stray space. Regenerate at sociallens.dev/keys.
FAQ
How do I build a LangChain tool for social media data?
Wrap a SocialLens read such as /v1/profile in an @tool function or StructuredTool with a Pydantic schema, write a clear docstring, and pass it to LangGraph's create_react_agent. The agent calls it whenever a question needs live follower, post, or comment data.
Does LangChain use the docstring as the tool description?
Yes. With @tool, the function's docstring becomes the description the model sees. The model never reads your code, so the docstring must say what the tool returns and when to call it.
Should I use @tool or StructuredTool?
Use @tool for quick prototypes. Use StructuredTool (or @tool(args_schema=...)) with a Pydantic model when you want enums, defaults, bounds, and per-argument descriptions. Typed arguments reduce malformed tool calls.
What does is_exact mean?
is_exact: true means the platform exposed a precise count. false means the figure is rounded by the platform, as with YouTube. Agents should say "about" for rounded figures and never add false precision.
How many Instagram followers does Cristiano Ronaldo have?
On 2026-12-04, a live SocialLens read returned 679,519,176 Instagram followers for @cristiano, with is_exact: true. Counts change daily, so an agent should fetch the current figure at run time.
Can the agent read private accounts or DMs? No. SocialLens is read-only and public-data-only. It never logs in, so private posts, DMs, and logged-in feeds are out of reach by design.
Can I use the MCP server with LangChain?
Yes. The langchain-mcp-adapters package loads the SocialLens MCP server (npx -y sociallens-mcp) over stdio and converts its tools into LangChain tools you pass to create_react_agent.
Is initialize_agent still the right way to build agents?
No. initialize_agent is deprecated. Use create_react_agent from langgraph.prebuilt, which takes a chat model, a list of tools, and an optional system prompt.
How many networks can one tool cover?
SocialLens reads 17 networks with one key and one JSON schema, so a single get_social_profile tool works across all of them by changing the platform argument.
Where do I get an API key? Create one at sociallens.dev/keys after registering. Agent-specific docs are at sociallens.dev/agents.
Related guides
- Social Media APIs Compared: Official APIs vs One Public Data API
- Best LinkedIn Data API in 2026: Company Followers, Employees and Posts
- Best Reddit Data API in 2026: Subreddit Profiles, Posts and Comments
- Best Instagram Data API in 2026: Profiles, Posts and Comments
- How to Read Public Subreddit Data via API: Posts, Scores and Comments as JSON (2026)
- Social Media Followers Count API for SMM Panels: Read Instagram and TikTok Public Data (2026)
- LinkedIn Company Data API: Followers, Employee Count and Company Posts