DEV Community

vorsprung
vorsprung

Posted on

Using the Model Context Protocol (MCP) to use FRED data

I've recently started using Claude Pro on the desktop. It can produce readable reports from a text prompt. Trouble is it can and will "make up" data. This is called "Halucinating" in the current AI/LLM discussions. This is a big problem for most people that just want accurate information!

One way it can interface with your data in a more reliable way is by using the Model Context Protocol (MCP). To greatly simplify what MCP does, it pushes external data into prompts

To get accurate historical financial markets I am using the Federal Reserve Economic Data (FRED) online database via a MCP Server

How to install FRED MCP server

I am using a MacBook with Claude Pro
First you need the python "uv" system. This allows programs like the FRED MCP server to download all the sub systems they need to work and start up. If you already have homebrew, then installing is

brew install uv
Enter fullscreen mode Exit fullscreen mode

then clone the github repo

git clone https://github.com/Jaldekoa/mcp-fredapi.git
Enter fullscreen mode Exit fullscreen mode

make a note of the path where the cloned repo is

cd mcp-fredapi
pwd
Enter fullscreen mode Exit fullscreen mode

Next, alter the Claude developer settings with the menu Claude->Settings then select developer and hit edit config

Add a json section like this, the "directory" setting will be the repo path from above


{

"mcpServers": {
"mcp-fredapi": {
      "command": "uv",
      "args": [
        "--directory",
        "/Users/jamesandrews/stuff/mcp-fredapi",
        "run",
        "--with",
        "mcp",
        "--with",
        "httpx",
        "mcp",
        "run",
        "server.py"
      ]
    }
    }
    }
Enter fullscreen mode Exit fullscreen mode

restart Claude and you should be good to go

What can it do?

initially I asked it

using the FRED data from the mcp-fredapi mcp server show the S&P 500 for the last 3 months
Enter fullscreen mode Exit fullscreen mode

It made this
Image description

Then I asked

if the trend downwards continues, approximately when will a price of 3000 be reached?
Enter fullscreen mode Exit fullscreen mode

It responded

To estimate when the S&P 500 might reach 3,000 if the current downward trend continues, I'll need to calculate the rate of decline from the FRED data and then project it forward

OutputResult

Starting date: 2025-01-23, value: 6118.71
Ending date: 2025-04-22, value: 5287.76
Total days: 89
Total change: -830.95 points
Average daily change: -9.34 points per day
Points to target (3000): 2287.76
Days needed to reach 3000: 245 days
Estimated date to reach 3000: 2025-12-23

Using only the last month of data:
Last month starting date: 2025-03-24, value: 5767.57
Last month days: 29
Last month change: -479.81 points
Last month average daily change: -16.55 points per day
Days needed to reach 3000 (recent trend): 138 days
Estimated date to reach 3000 (recent trend): 2025-09-07

Linear regression model:
Slope: -0.00000013 points per millisecond (-10.94 points per day)
Y-intercept: 226338.02
Estimated date to reach 3000 (regression): 2025-11-14
Days from last data point to reach 3000 (regression): 206 daysBased on my analysis of the S&P 500's downward trend, I've calculated several projections for when the index might reach 3,000:

Using the entire 3-month period (Jan 23 - Apr 22, 2025):

Average daily decline: 9.34 points per day
Estimated date to reach 3,000: December 23, 2025 (245 days from the last data point)


Using only the most recent month (which shows a more accelerated decline):

Average daily decline: 16.55 points per day
Estimated date to reach 3,000: September 7, 2025 (138 days from the last data point)


Using linear regression (most statistically sound approach):

Average daily decline: 10.94 points per day
Estimated date to reach 3,000: November 14, 2025 (206 days from the last data point)



The most recent month shows a much steeper decline (almost double the rate of the entire period), which suggests the downward momentum has been accelerating. If this recent, more aggressive trend continues, we could see the S&P 500 at 3,000 as early as September 2025.
However, the linear regression model, which accounts for the overall trend while smoothing out some volatility, points to mid-November 2025 as the most statistically reliable estimate.
It's important to note that these are purely mathematical projections based on past performance. The stock market is influenced by numerous factors including economic data, Federal Reserve policy, geopolitical events, and investor sentiment that could significantly alter this trajectory.
Enter fullscreen mode Exit fullscreen mode

Which is all quite fun!
The advantage of knowing it is FRED data is that it can be rechecked using another method and that the data is "good" and not hallucinated

Buyer beware...

If you ask it about stuff that isn't in FRED then it may well make something up. But it will say that it has done this. Read what it says carefully...

Top comments (0)