# How to Use Haystack with FXMacroData: Pipelines, Agents, REST and MCP

Canonical: https://fxmacrodata.com/articles/how-to-use-haystack-with-fxmacrodata
Author: FXMacroData
Published: 2026-07-11T11:04:23Z

Use Haystack with FXMacroData by combining production pipelines, tool-calling agents, read-only REST tools, MCPToolset, and finance guardrails for evidence-first FX macro workflows.

[Haystack](https://docs.haystack.deepset.ai/docs/intro) is a useful fit when an FX macro workflow needs a production-oriented AI pipeline, a tool-calling agent, or a standard MCP tool surface without turning the whole application into one prompt. FXMacroData supplies the current market evidence: confirmed[release calendars](/dashboard/release-calendar) , announcement history,[EUR/USD](/dashboard/EUR_USD) context,[COT](/dashboard/cot) positioning,[commodities](/dashboard/commodities) , and[FX session](/dashboard/fx-sessions) data.

**Quick answer:**use Haystack with FXMacroData by keeping macro data access in narrow read-only tools, then choosing a deterministic pipeline when the workflow is fixed or an`Agent`when the model should decide which tool to call. Use REST when your service owns credentials and validation, and use MCP when Haystack should load FXMacroData tools from`https://mcp.fxmacrodata.com`.

The boundary is simple. Haystack should coordinate components, tools, agents, and pipelines. FXMacroData should answer the factual market questions: what printed, what was prior, what is scheduled, which rows are available, and which dashboard a human can inspect. That matters for[US CPI](/united-states/inflation) ,[Non-Farm Payrolls](/usd/labor/non-farm-payrolls) , a[Federal Reserve policy rate](/united-states/policy-rate) decision, or a[USD/JPY](/dashboard/USD_JPY) release-risk brief.

**Fit**

**Use this for**

Production macro briefings, tool-calling agents, RAG-style research flows, release monitors, and analyst review systems.

**Use pipelines when**

The route is known: fetch data, format evidence, run the model, validate the answer, and return a reviewable note.

**Use agents when**

The model needs to choose between calendar, announcement, FX, COT, commodity, or session tools.

## Why Haystack Fits FX Macro Workflows

Haystack is an open-source AI framework for building agents, RAG applications, search systems, tools, and pipelines. Its useful finance trait is modularity: you can make data access, model calls, validation, and final formatting separate parts of the system instead of hiding everything inside a single model prompt.

That matters for FX macro because "current" is the hard part. A model may know what[CPI](/articles/inflation-indicators-fx-guide) is, but it should not rely on memory for the next release, the latest print, the prior value, a[COT positioning](/articles/cot-report-guide-fx-traders) row, or whether a dataset is unavailable. Those facts should come from FXMacroData before the model writes the briefing.

**Core principle**

Let Haystack control the route. Let FXMacroData control the evidence. The final answer should show which source paths and returned facts support the market interpretation.

## Workflow Shape

**1. Request**

Ask for a release brief, pair setup, calendar check, or evidence packet.

**2. Route**

Use a fixed pipeline or an agent loop with a clear stopping condition.

**3. Evidence**

Call FXMacroData through REST tools or the hosted MCP endpoint.

**4. Review**

Return facts, interpretation, source paths, timestamps, and data gaps separately.

## Pipeline, Agent, REST, or MCP?

Choice Best for Tradeoff**Haystack Pipeline**Known workflows such as daily release briefings, scheduled checks, and repeatable evidence formatting. You must define the route and component interfaces up front.**Haystack Agent**Questions where the model should choose between a small set of data tools. Needs stricter loop caps, tool filtering, and answer validation.**FXMacroData REST**Applications that own credentials, retries, logging, caching, and schema validation. You maintain the wrapper code and endpoint mapping.**FXMacroData MCP**Hosts that should discover a shared FXMacroData tool surface from`https://mcp.fxmacrodata.com`. You should restrict tool names when the available catalog is larger than the task needs.

## Prerequisites

- Python 3.10 or later.

- Haystack and a chat model provider configured for your environment.

- An FXMacroData API key stored outside prompts and logs.

- The`mcp-haystack`integration if you want Haystack to load MCP tools.

- A first workflow that is read-only and easy to review.

```
pip install -U haystack-ai requests
pip install -U mcp-haystack
export OPENAI_API_KEY="YOUR_MODEL_PROVIDER_KEY"
export FXMD_API_KEY="YOUR_FXMACRODATA_API_KEY"
```

For direct REST checks, use production FXMacroData endpoints and send the API key in the`X-API-Key`header:

```
curl -H "X-API-Key: YOUR_API_KEY" "https://api.fxmacrodata.com/v1/calendar/usd"
curl -H "X-API-Key: YOUR_API_KEY" "https://api.fxmacrodata.com/v1/announcements/usd/inflation"
curl -H "X-API-Key: YOUR_API_KEY" "https://api.fxmacrodata.com/v1/forex/eur/usd"
curl -H "X-API-Key: YOUR_API_KEY" "https://api.fxmacrodata.com/v1/cot/usd"
```

## Step 1: Wrap FXMacroData REST as Haystack Tools

Start with a small HTTP helper. Keep the API key in server-side configuration. The model should receive returned evidence and endpoint paths, not credentials.

```
import os
import requests

API_ROOT = "https://api.fxmacrodata.com/v1"

def fxmd_get(path: str, **params) -> dict:
    headers = {"X-API-Key": os.environ["FXMD_API_KEY"]}
    response = requests.get(f"{API_ROOT}{path}", params=params, headers=headers, timeout=20)
    response.raise_for_status()
    return {
        "source": f"/v1{path}",
        "payload": response.json(),
    }
```

Haystack tools can be created with the`@tool`decorator. Keep each tool narrow so the agent cannot wander across unrelated endpoint families.

```
from typing import Annotated
from haystack.tools import tool

@tool
def fxmacrodata_calendar(
    currency: Annotated[str, "Three-letter currency code, such as USD"]
) -> dict:
    """Return scheduled macro releases for one currency."""
    return fxmd_get(f"/calendar/{currency.lower()}")

@tool
def fxmacrodata_announcement(
    currency: Annotated[str, "Three-letter currency code"],
    indicator: Annotated[str, "Indicator slug, such as inflation"],
) -> dict:
    """Return historical announcement rows for one indicator."""
    return fxmd_get(f"/announcements/{currency.lower()}/{indicator}")
```

## Step 2: Use a Pipeline for Fixed Briefings

Use a pipeline when the sequence is known. For example, a daily[USD](/united-states) release briefing can always fetch the calendar, fetch the last announcement rows for the selected indicator, pass both into a model, and validate the result.

```
from haystack import Pipeline, component

@component
class FetchCalendar:
    @component.output_types(evidence=dict)
    def run(self, currency: str):
        return {"evidence": fxmd_get(f"/calendar/{currency.lower()}")}

pipeline = Pipeline()
pipeline.add_component("calendar", FetchCalendar())
pipeline.add_component("brief", FxMacroBriefGenerator())
pipeline.connect("calendar.evidence", "brief.calendar")

result = pipeline.run({"calendar": {"currency": "usd"}})
```

The exact briefing component can be your own model wrapper, a prompt builder, or a generator connected to the rest of the pipeline. The important point is that the route is inspectable: data retrieval is a component, generation is a component, and validation is a component.

## Step 3: Use an Agent for Tool Choice

Use Haystack's`Agent`component when the model needs to choose tools. The official Agent component manages the tool-calling loop, invokes tools, updates state, and exits when a stopping condition is met.

```
from haystack.components.agents import Agent
from haystack.components.generators.chat import OpenAIChatGenerator
from haystack.dataclasses import ChatMessage

agent = Agent(
    chat_generator=OpenAIChatGenerator(model="gpt-4o-mini"),
    tools=[fxmacrodata_calendar, fxmacrodata_announcement],
    system_prompt=(
        "Use FXMacroData tools for current macro facts. "
        "Name source paths and data gaps in the final answer."
    ),
)

result = agent.run(
    messages=[ChatMessage.from_user("Brief the next USD release risk.")]
)
```

Do not give the first version a broad web tool, file tool, order-placement tool, or arbitrary HTTP tool. A useful finance agent starts with a small evidence surface and a conservative final-answer contract.

## Step 4: Load FXMacroData Through MCP

Use MCP when you want Haystack to consume the same FXMacroData tool surface used by other agent hosts. Haystack's`MCPToolset`can load tools from MCP-compliant servers and pass them to an`Agent`. The FXMacroData MCP endpoint is:

```
https://mcp.fxmacrodata.com
```

For remote HTTP MCP, use streamable HTTP and restrict the tool list to the workflow you are building.

```
from haystack_integrations.tools.mcp import (
    MCPToolset,
    StreamableHttpServerInfo,
)

server_info = StreamableHttpServerInfo(
    url="https://mcp.fxmacrodata.com",
)

toolset = MCPToolset(
    server_info=server_info,
    tool_names=["release_calendar", "indicator_query"],
)
```

Then pass that toolset into the same Agent pattern:

```
agent = Agent(
    chat_generator=OpenAIChatGenerator(model="gpt-4o-mini"),
    tools=toolset,
    exit_conditions=["text"],
    system_prompt="Use FXMacroData MCP tools before writing.",
)

response = agent.run(
    messages=[ChatMessage.from_user("Summarize upcoming USD macro events.")]
)
```

If your editor or agent host expects JSON configuration, the canonical VS Code-style MCP shape for FXMacroData is:

```
{
  "servers": {
    "FXMacroData": {
      "type": "http",
      "url": "https://mcp.fxmacrodata.com"
    }
  }
}
```

## Step 5: Add Finance Guardrails

Haystack gives you structure. You still need finance-specific controls so a model does not turn a partial data pull into a confident trading call.

**Finance guardrail checklist**

- Keep all first tools read-only: calendar, announcements, FX context, COT, commodities, and sessions.

- Store`FXMD_API_KEY`outside prompts and never return the key or request headers to the model output.

- Filter MCP tools to the smallest set required for the workflow.

- Require final answers to separate fetched facts, interpretation, source paths, and data gaps.

- Use human review before customer-facing alerts or desk workflows.

- Keep order placement, account changes, and risk-limit changes outside the model path.

A reviewable output shape is more useful than a fluent paragraph. Return enough structure for another system or analyst to check the answer.

```
{
  "brief": "Upcoming USD event risk should be reviewed against calendar rows.",
  "evidence": [
    {
      "source": "FXMacroData calendar",
      "path": "/v1/calendar/usd",
      "used_for": "Next known release window"
    }
  ],
  "interpretation": "Model-generated summary based on fetched evidence.",
  "data_gaps": []
}
```

## Related FXMacroData Guides

- [FXMacroData API documentation](/documentation)

- [FXMacroData MCP server documentation](/documentation/mcp-server)

- [How to Use smolagents with FXMacroData](/articles/how-to-use-smolagents-with-fxmacrodata)

- [How to Use DSPy with FXMacroData](/articles/how-to-use-dspy-with-fxmacrodata)

- [How to Build LangGraph FX Macro Agents with FXMacroData](/articles/build-langgraph-fx-macro-agents-with-fxmacrodata)

## Sources

- [Haystack introduction](https://docs.haystack.deepset.ai/docs/intro)

- [Haystack pipelines documentation](https://docs.haystack.deepset.ai/docs/pipelines)

- [Haystack agents documentation](https://docs.haystack.deepset.ai/docs/agents)

- [Haystack Tool documentation](https://docs.haystack.deepset.ai/docs/tool)

- [Haystack MCPToolset documentation](https://docs.haystack.deepset.ai/docs/mcptoolset)

- [FXMacroData API documentation](https://fxmacrodata.com/documentation)

- [FXMacroData MCP documentation](https://fxmacrodata.com/documentation/mcp-server)

- [FXMacroData production OpenAPI schema](https://api.fxmacrodata.com/openapi.json)

Source: FXMacroData
