A LangChain agent should not invent source strings. Give it a tool that POSTs https://api.trendsapi.ai/api, or connect the host to the product MCP server. The envelope body is a JSON string and must be parsed inside the tool before anything reaches the model. There is no required langchain-trendsapi package. MCP setup is on the MCP page. Fields: the API reference. Caps: pricing.
StructuredTool posts and returns inner JSON
import json, os, requests
from langchain.tools import tool
@tool
def keyword_growth(keyword: str, source: str = "google search") -> dict:
"""Point-to-point growth for one keyword and source."""
resp = requests.post(
"https://api.trendsapi.ai/api",
headers={
"Authorization": f"Bearer {os.environ['TRENDSAPI_API_KEY']}",
"Content-Type": "application/json",
},
json={"mode": "get_growth", "source": source, "keyword": keyword, "percent_growth": ["12M"]},
timeout=60,
)
resp.raise_for_status()
return json.loads(resp.json()["body"])
Official LangChain tool docs cover @tool / StructuredTool. The docstring is what the model sees. The key is not in the docstring. Auth rules sit on authentication.
Return the inner object, not the envelope. A raw body string trains the model to guess results. The parse step is on parse the body.
Prefer get_growth for percent questions
The tool above is one POST for a window list. A tool that pulls get_time_series and asks the model to subtract dates wastes tokens and lookups. Mode choice is on get_growth. A live board tool must send type and no keyword.
Constrain source to MCP names. google without search is invalid_source.
MCP instead of a second wrapper
Hosts that already load https://api.trendsapi.ai/mcp expose get_time_series, get_growth, and get_top_trends. Do not also register a StructuredTool that posts the same three modes. n8n can attach HTTP Request as an agent tool. That canvas path is on n8n.