Skip to main content

LangChain / LangGraph

Load the SocialAPIs MCP tools into a LangChain or LangGraph agent with the official langchain-mcp-adapters package. There's no separate SocialAPIs LangChain package: the adapter connects to our hosted MCP server.

Install​

pip install langchain-mcp-adapters langgraph

Load the tools​

import asyncio
import os

from langchain_mcp_adapters.client import MultiServerMCPClient


async def main():
client = MultiServerMCPClient(
{
"socialapis": {
"transport": "streamable_http",
"url": "https://mcp.socialapis.io/mcp",
"headers": {
"Authorization": f"Bearer {os.environ['SOCIALAPIS_API_KEY']}",
},
}
}
)
tools = await client.get_tools()
print(f"{len(tools)} tools:", [t.name for t in tools[:5]])


asyncio.run(main())

Set SOCIALAPIS_API_KEY to your key from the dashboard.

Use them in an agent​

Pass the tools to any tool-calling agent. With LangGraph's prebuilt agent:

from langgraph.prebuilt import create_react_agent

# `model` is any LangChain chat model that supports tool calling.
agent = create_react_agent(model, tools)

result = await agent.ainvoke(
{"messages": [("user", "Get Nike's Facebook page details and summarize their latest posts.")]}
)
print(result["messages"][-1].content)

Each tool call costs credits like a REST call. Tool descriptions state the price.

Without MCP​

If you'd rather call the REST API directly, use the Python SDK and wrap its methods as LangChain tools.