LangChain & Python agents
Load every ClickAPIs operation as a LangChain tool through the MCP adapter, or wrap the REST API in a single tool for any Python agent framework.
LangChain with the MCP adapter
# pip install langchain langchain-mcp-adapters langchain-anthropic
import asyncio, os
from langchain.agents import create_agent
from langchain_mcp_adapters.client import MultiServerMCPClient
async def main():
client = MultiServerMCPClient({
"clickapis": {
"transport": "streamable_http",
"url": "https://clickapis.com/mcp",
"headers": {"Authorization": f"Bearer {os.environ['CLICKAPIS_KEY']}"},
}
})
tools = await client.get_tools() # one LangChain tool per ClickAPIs operation
agent = create_agent("anthropic:claude-opus-5-5", tools)
result = await agent.ainvoke({"messages": [{
"role": "user",
"content": "Find oversold large caps above their 200-day average, "
"then tell me how that setup has performed historically for the top three.",
}]})
print(result["messages"][-1].content)
asyncio.run(main())Works with LangGraph as well: pass the same tools to your graph’s tool node. Any chat model with tool calling can drive it.
One tool over the REST API
# A plain-Python tool you can register with any framework (LangChain @tool, LlamaIndex, CrewAI, your own loop).
import os
import requests
from langchain_core.tools import tool
API = "https://clickapis.com/v1"
@tool
def clickapis(op: str, body: dict) -> dict:
\"\"\"Compute market analytics. op: snapshot, performance, query, drawdowns, seasonality,
distribution, levels, correlation, compare, risk, event-study, backtest, screen, movers,
sectors or peers. body: the JSON body documented at https://clickapis.com/docs/<op>.
Conditions use expressions like 'rsi(14) < 30 and close > sma(200)'. Returns are decimals.\"\"\"
r = requests.post(f"{API}/{op}", json=body, timeout=120,
headers={"Authorization": f"Bearer {os.environ['CLICKAPIS_KEY']}"})
j = r.json()
return j["data"] if j.get("ok") else {"error": j.get("error")}For jobs (large screens and event studies), add "async": true and poll as shown in Jobs & async, or let the MCP server wait for you.