AI agents & LLMs

How do I give an OpenAI Agents SDK agent access to fund data?

Add a function tool that calls the fund API by ISIN, or attach the hosted MCP server, so an OpenAI Agents SDK agent answers fund questions with current figures. Code for both.Updated 12 September 2026 · by FundFacts API

Short answer

Either wrap one API call in a @function_tool (Python) or tool() (TypeScript) that returns the fields you want the agent to see, or attach the FundFacts MCP server (https://fundfactsapi.com/api/mcp) as a hosted MCP tool with an Authorization header. The agent then calls get_fund, search_funds, compare_funds, analyze_portfolio or fund_overlap as needed and answers with the current published figures and their as-of date.

Function tool (Python)

python
# pip install openai-agents fundfacts
from agents import Agent, Runner, function_tool
from fundfacts import FundFacts
ff = FundFacts() # reads FUNDFACTS_API_KEY
@function_tool
def fund_facts(isin: str) -> dict:
"""Current factsheet for a fund or ETF ISIN: name, TER, 1-7 risk, category, top holdings, sector/country split, returns, as-of date."""
f = ff.get_fund(isin)
d = f["data"]
return {"name": f["name"], "ter": d["headlineMetrics"]["ter"], "risk": d["riskRating"], "category": d["profile"]["category"],
"top_holdings": d["topHoldings"][:10], "sectors": d["sector"][:8], "countries": d["geography"][:8],
"calendar_returns": d["calendarReturns"], "as_of": d["dataAsOf"]}
agent = Agent(name="Fund analyst", instructions="Answer with figures from the tool and always state as_of. Empty fields are 'not disclosed'.", tools=[fund_facts])
print(Runner.run_sync(agent, "Compare the cost and sector mix of IE00B4L5Y983 and IE00B3RBWM25").final_output)

Hosted MCP tool

The Agents SDK and the Responses API can call a remote MCP server on your behalf; no wrapper code:

python
from agents import Agent, HostedMCPTool
agent = Agent(
name="Fund analyst",
tools=[HostedMCPTool(tool_config={
"type": "mcp",
"server_label": "fundfacts",
"server_url": "https://fundfactsapi.com/api/mcp",
"headers": {"Authorization": "Bearer ffk_..."},
"require_approval": "never",
})],
)
typescript
// npm install @openai/agents
import { Agent, hostedMcpTool, run } from "@openai/agents";
const agent = new Agent({
name: "Fund analyst",
instructions: "Quote dataAsOf with every figure.",
tools: [hostedMcpTool({ serverLabel: "fundfacts", serverUrl: "https://fundfactsapi.com/api/mcp", headers: { Authorization: `Bearer ${process.env.FUNDFACTS_API_KEY}` } })],
});
const result = await run(agent, "How much do IE00B4L5Y983 and IE00B3RBWM25 overlap?");
console.log(result.finalOutput);

The MCP server exposes six 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, Pro and above), fund_overlap (shared holdings between funds, Pro and above) and get_scpi (French SCPI data by name or ISIN). Authentication is the same bearer API key as the REST API, sent as an Authorization header.

Production notes

Give function tools a 300-second timeout for cold ISINs, cache by ISIN until expiresAt, and tell the agent that a 404 means "not a covered fund". Tool calls cost one request per ISIN answered, the same as REST.

Verify it yourself

The demo endpoint returns the live payload for a fund that is already in the store, without a key. Everything on this page can be checked against it.
bash
curl -s https://fundfactsapi.com/api/v1/demo/funds/IE00B4L5Y983 | jq '{name, asOf: .data.dataAsOf, ter: .data.headlineMetrics.ter, risk: .data.riskRating, top: .data.topHoldings[:3]}'

Frequently asked questions

Do I need a credit card to try it?

No. The Free plan is 15 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.

Try it on your own ISINs

One request returns key facts, holdings, risk and performance as JSON. Free plan, no card.