---
title: "How do I add fund and ETF data as a tool in LangChain or LangGraph?"
description: "Wrap one API call in a LangChain @tool so an agent can answer questions about any ISIN with current TER, holdings, exposures and returns. Python code, plus the MCP adapter route."
canonical: https://fundfactsapi.com/answers/fund-data-for-langchain
published: 2026-09-12
updated: 2026-10-13
publisher: FundFacts API
---

# How do I add fund and ETF data as a tool in LangChain or LangGraph?

**Short answer:** Define a @tool that calls GET https://fundfactsapi.com/api/v1/funds/{isin} with your API key and returns a compact dict (name, TER, risk indicator, category, top holdings, sector split, returns, dataAsOf), then bind it to your model or LangGraph agent. Alternatively load the MCP server at https://fundfactsapi.com/api/mcp through langchain-mcp-adapters and get all seven tools without writing wrappers. Either way the agent answers with current published figures instead of training-data memory.

## A tool in twenty lines

```python
# pip install git+https://github.com/fundfactsapi/fundfactsapi-python langchain langchain-openai
import os
from langchain_core.tools import tool
from fundfacts import FundFacts

ff = FundFacts()  # reads FUNDFACTS_API_KEY

@tool
def fund_facts(isin: str) -> dict:
    """Current factsheet of a fund or ETF by 12-character ISIN: name, TER, 1-7 risk
    indicator, category, fund size, top holdings, sector and country split,
    calendar and annualised returns, as-of date. Returns {"error": ...} when the
    ISIN is not a covered fund."""
    try:
        f = ff.get_fund(isin)
    except Exception as e:  # FundFactsError carries status and code
        return {"error": str(e)}
    d = f["data"]
    return {
        "name": f["name"], "category": d["profile"]["category"], "risk_1_to_7": d["riskRating"],
        "ter": d["headlineMetrics"]["ter"], "aum": d["keyFacts"]["aum"],
        "top_holdings": d["topHoldings"][:10], "sectors": d["sector"][:8], "countries": d["geography"][:8],
        "calendar_returns": d["calendarReturns"], "annualised_returns": d["annualisedReturns"],
        "as_of": d["dataAsOf"],
    }

@tool
def search_funds(query: str) -> list[dict]:
    """Find fund ISINs by name or issuer, e.g. 'msci world' or 'vanguard all-world'. Free."""
    return [{"isin": r["isin"], "name": r["name"], "issuer": r["issuer"]} for r in ff.search(query)["results"][:10]]
```

Bind the tools to a model and run an agent:

```python
from langchain_openai import ChatOpenAI
from langgraph.prebuilt import create_react_agent

agent = create_react_agent(ChatOpenAI(model="gpt-4.1"), [fund_facts, search_funds],
    prompt="You answer questions about investment funds. Always quote as_of with figures. Say 'not disclosed' for empty fields; never estimate.")
result = agent.invoke({"messages": [("user", "What does IE00B4L5Y983 hold and what does it cost?")]})
print(result["messages"][-1].content)
```

Trimming the payload in the tool (the full one is a few kilobytes with the series) keeps the context small; return the whole `data` object if the agent needs the monthly series for calculations.

## Or use the MCP server directly

```python
# pip install langchain-mcp-adapters
from langchain_mcp_adapters.client import MultiServerMCPClient

client = MultiServerMCPClient({
    "fundfacts": {
        "transport": "streamable_http",
        "url": "https://fundfactsapi.com/api/mcp",
        "headers": {"Authorization": f"Bearer {os.environ['FUNDFACTS_API_KEY']}"},
    }
})
tools = await client.get_tools()  # get_fund, search_funds, compare_funds, analyze_portfolio, fund_overlap, get_scpi
```

The MCP server exposes seven tools, each counted like the REST endpoint it wraps: `get_fund` (ISIN → the full factsheet payload), `search_funds` (name → ISINs, free), `compare_funds` (side-by-side table for several ISINs), `analyze_portfolio` (weighted look-through of a list of positions, Starter and above), `fund_overlap` (shared holdings between funds, Starter and above), `get_scpi` (French SCPI data by name or ISIN) and `search_scpi` (SCPI name → matches, free), plus a `tour` prompt that explains the service on the example fund IE00B4L5Y983, which is not counted. Every tool only reads data. Authentication is either your FundFacts account (OAuth 2.1 with PKCE, the sign-in the claude.ai, Claude Desktop and ChatGPT connectors run) or the same bearer API key as the REST API, sent as an `Authorization` header by editors, CLIs and frameworks. The [MCP server guide](https://fundfactsapi.com/docs/mcp) has the full tool reference, setup for every client and troubleshooting.

## Notes for production agents

- The first call for a cold ISIN can take up to a few minutes; give the tool a 300-second timeout and tell the model a first lookup can be slow.
- One request per fund found. Cache tool results by ISIN until `expiresAt` if users repeat questions.
- The [fund data for AI agents guide](https://fundfactsapi.com/blog/fund-data-for-ai-agents-and-llms) covers prompt design and guardrails in more depth.

## FAQ

### Do I need a credit card to try it?

No. The Free plan is 5 lookups per month with no card; sign up with an e-mail address or Google and the key is shown in the dashboard.

### Which ISINs work?

Any share class of a UCITS fund, ETF, money-market fund or open-end fund whose management company publishes a product page, factsheet and KID. Each share class has its own ISIN and is looked up on its own. Stocks, bonds and indices are not funds and return 404 fund_not_found.

## About FundFacts API

FundFacts turns any fund or ETF ISIN into one dated factsheet (fees and KID costs, the 1–7 risk indicator, holdings, sector and country exposure, returns) read from the fund house's own documents: as a client-ready PDF under your firm's name for advisers and wealth managers, as JSON through its API for developers, or inside ChatGPT and Claude through its MCP server.

FundFacts works inside ChatGPT and Claude as a connector (a remote MCP server): ask about any fund or ETF by ISIN, ticker or name and the assistant answers from FundFacts' dated figures, fees, risk, holdings, exposure and returns, with fund cards, side-by-side comparisons, holdings overlap and portfolio look-through.

- Free API key, no card: https://fundfactsapi.com/signup
- Documentation: https://fundfactsapi.com/docs (OpenAPI: https://fundfactsapi.com/openapi.json)
- MCP server: https://fundfactsapi.com/api/mcp (set-up for every client: https://fundfactsapi.com/mcp-server)
- Pricing: https://fundfactsapi.com/pricing
- Site index for AI assistants: https://fundfactsapi.com/llms.txt
- Informational data, not investment advice.
