https://stockcontext.com/mcp (setup). This page shows the plain HTTP function-calling pattern for agents or frameworks where you register tools yourself: expose each tool as a function that POSTs to /v1/tools/{name} and returns the parsed JSON.
The tool-selection policy
Start narrow. For a “tell me about X” question the first call is almost alwaysstock_overview — it carries the latest financials, valuation, and growth in one payload. Add exactly one more call per dimension the question opens, and stop when it is answered. See Choose a tool for the full map.
Tool functions
Each tool is one function. The key lives in theX-API-Key header, server-side — never in a prompt or a client bundle.
- Python
- TypeScript
agent_tools.py
A worked trace
User: Is Apple growing, and how is it priced? Call 1,stock_search — resolve the ticker and confirm coverage.
stock_search q=AAPL (trimmed)
coverage.financials: true, so fundamentals are served. The agent proceeds.
Call 2, stock_overview — one call covers growth and valuation.
stock_overview symbol=AAPL (trimmed)
Apple grew revenue about 6.4% and net income about 19.5% year over year, and it trades at a trailing P/E of roughly 39.5 with a free-cash-flow yield near 2.3%. The growth figures come from SEC-filed financials (That last paragraph is not optional. The instruction that produces it — answer first, cite provenance and the clock, never give buy/sell advice, never invent data the API refused — is in Agent instructions. Paste that block into your system prompt.as_of.sec2026-06-26). The P/E and FCF yield arecomputed_from_prices— a fundamentals input times a market close on 2026-07-01 — so they move with the price, not the filings. Calls used: stock_search, stock_overview. This is context, not advice.
Where agents go wrong
- Reading a refusal as a value. A field with
unavailablehas no value. Never substitute0ornull; report the token (and look it up in therefusal_tokenscatalog if needed). - Parsing magnitudes as floats. Exact values are decimal strings — use a decimal type so precision survives.
- Blending the two clocks. A
computed_from_pricesmultiple mixes an SEC-filed input with a market close. Do not present it as “the filing says,” and cite the price date. - Treating 13F as total ownership.
stock_ownershipis a tracked subset withexhaustive: false. Say “among tracked managers.” - Retrying non-retryable failures.
invalid_api_key(401) and a422validation error do not change on retry — fix the cause. See Errors and retries.
Agent instructions
The operating rules to paste into your system prompt.