Quick answer
Use Vercel AI SDK to expose a small, typed FXMacroData tool from your server, then require a structured research result. The model can ask for current evidence; your application validates the request, performs the read, and preserves the result. For EUR/USD, that gives a reviewer current release context rather than a fluent answer based on stale model memory.
Good fit
TypeScript teams building a web-based FX research desk, briefing workflow, or analyst-facing agent with controlled tool calls.
Not the goal
Do not let a web-agent tool place orders, resize positions, or change risk limits. Keep execution beyond the model boundary.
Why Vercel AI SDK works for FX research
Vercel AI SDK gives application teams a typed tool boundary around a model call. That matters in FX research because the agent should not decide what counts as market evidence. Your server decides which FXMacroData request is allowed, validates the input, records the result, and only then returns it to the model for interpretation.
A question about the Federal Reserve, an upcoming US CPI release, or the next event on the release calendar should start with a controlled read. The model is useful after that: it can organize facts, name uncertainty, and write a concise handover for the desk.
Evidence workflow
State one research question.
Check the typed tool input.
Fetch current macro evidence.
Return a structured brief.
Choose SDK tools, REST, or MCP deliberately
| Surface | Use it when | Why it matters |
|---|---|---|
| AI SDK tool | Your app owns the research workflow. | Typed inputs, server-side execution, and an auditable contract. |
| FXMacroData REST | Your tool executes a narrow data request. | Production default for requests to https://api.fxmacrodata.com. |
| AI SDK structured output | A reviewer needs an object rather than a paragraph. | Facts, unknowns, and source paths can be checked before display. |
| FXMacroData MCP | An MCP-compatible host should discover hosted macro tools. | Use https://mcp.fxmacrodata.com for the hosted tool surface. |
Vercel recommends application-defined SDK tools when a production app needs control and type safety. Use MCP when the host is already MCP-native or a user brings a compatible tool environment. Do not add MCP merely because a model is present; an SDK tool backed by REST is often the cleanest production path.
Prerequisites
- A TypeScript server route or backend process where the tool can run safely.
- Vercel AI SDK and Zod or JSON Schema validation in the application.
- An FXMacroData API key stored server-side for protected data access.
- A review rule for the final brief before it reaches a trading decision workflow.
How to build the workflow
1. Define a narrow, read-only research tool
Start with one use case such as: "What USD macro events should a reviewer watch before the next session overlap?" Include FX sessions in the response context when needed, but keep the tool input to currency, indicator, and a bounded row limit. Do not give the model a raw URL field or a generic proxy to external services.
2. Fetch FXMacroData inside the tool
The tool executes on your server. It is responsible for credentials, timeouts, input validation, and retaining the source path with the returned payload.
import { tool } from 'ai';
import { z } from 'zod';
export const macroTools = {
getUsdInflation: tool({
description: 'Get recent confirmed USD inflation releases.',
inputSchema: z.object({ limit: z.number().int().min(1).max(24) }),
strict: true,
execute: async ({ limit }) => {
const url = new URL('https://api.fxmacrodata.com/v1/announcements/usd/inflation');
url.searchParams.set('api_key', process.env.FXMD_API_KEY!);
url.searchParams.set('limit', String(limit));
const response = await fetch(url);
return { source_path: '/v1/announcements/usd/inflation', payload: await response.json() };
},
}),
};
The example deliberately exposes one task. Add separate, well-named tools for calendar context or pair context rather than an all-purpose macro endpoint that the model can misuse.
3. Let the model request the tool, not invent the evidence
Give the model the approved tool inventory and an instruction to use it whenever it makes a claim about a current release or schedule. The SDK validates the call input against the schema before execution. Persist the tool input, output, source path, and model identifier with the research run.
import { generateText } from 'ai';
const result = await generateText({
model: yourReviewedModel,
tools: macroTools,
prompt: [
'Prepare a USD event-risk brief for EUR/USD.',
'Use tools for current facts.',
'State unknowns and require human review.',
].join(' '),
});
4. Require a structured research result
A trading desk should be able to scan what is confirmed, what is interpretation, and what is still unknown. Use a structured object or validated response schema for the final step instead of treating prose as the system of record.
{
"facts": ["Confirmed data returned by the selected FXMacroData tool."],
"scenario_notes": ["Review points around confirmed event windows."],
"unknowns": ["No future outcome is supplied by the source."],
"source_paths": ["/v1/announcements/usd/inflation"],
"review_status": "human_review_required"
}
5. Add MCP only where it improves the host
AI SDK supports MCP tools, but its own guidance distinguishes app-defined tools from dynamically discovered MCP tools. Use the hosted FXMacroData MCP server when a compatible agent host needs tool discovery or a user-managed connector. For an application-owned route, keep the SDK tool and REST adapter as the default.
What to measure after launch
| Measure | Healthy behavior | Failure to catch |
|---|---|---|
| Schema adherence | Only approved fields and bounded limits reach the data tool. | Malformed or over-broad tool input. |
| Evidence preservation | The result retains source paths and response quality metadata. | A market claim that cannot be traced to data. |
| Unknown handling | The agent names absent or stale information. | A confident narrative that fills a data gap. |
| Review boundary | The result is routed to a human or policy check. | Agent output driving execution directly. |
Minimum guardrails
- Keep API keys and provider credentials out of model-visible text and client-side bundles.
- Expose only read-only macro tools to the model.
- Reject outputs that omit the source path, unknowns, or review status.
- Record tool calls and outputs before displaying a research brief.
- Keep order routing, sizing, and risk changes behind deterministic controls.
Common questions
Can Vercel AI SDK use FXMacroData?
Yes. Define a server-side AI SDK tool that performs a narrow FXMacroData REST request, returns source-backed evidence, and gives the model a structured result to interpret.
Should a Vercel AI SDK trading app use REST or MCP?
Use REST through an application-defined tool when the app owns credentials, logging, and validation. Use FXMacroData MCP when an MCP-compatible host needs hosted-tool discovery.
Does strict tool calling make an FX agent safe to trade automatically?
No. It reduces invalid tool inputs where the provider supports it, but execution still needs separate policy controls, risk limits, and approval.
Related FXMacroData guides
Sources and references