DEV Community

Cover image for How to Connect Real-Time Stock Data to Your AI Agent (MCP Tutorial)
Kevin Meneses González
Kevin Meneses González

Posted on • Originally published at Medium

How to Connect Real-Time Stock Data to Your AI Agent (MCP Tutorial)

Most AI agents sound impressive until you ask for something that depends on the present moment:

"What's Apple trading at right now?"
"Show me the latest fundamentals for Microsoft."
"Which stocks are moving today?"

That's when the weakness appears.

A model can be eloquent, persuasive, and fast. But without access to external tools and live data, it is still reasoning in a closed room. Claude's tool use lets it request external functions that your application executes, and MCP is an open standard for connecting AI applications like Claude to tools and data sources.

In finance, that limitation is fatal.

Because in this category, "almost correct" is just another way of being wrong.

The Real Problem: AI Without Data Is Not a Financial Product

A lot of people are building "AI finance apps" that are really just polished chat interfaces.

They have:

  • a nice prompt
  • a clean UI
  • maybe some charts

But they do not have a robust data layer.

That means the assistant cannot reliably access:

  • live prices
  • historical candles
  • fundamental data
  • market news

And that destroys trust.

If a financial assistant cannot access current market information through tools or APIs, it either refuses, guesses, or answers from stale context. Claude's tool flow is explicitly designed so the model decides when to call a tool, your application runs it, and then the result is sent back for a grounded answer.

That is why the real product is not "the chatbot."

The real product is the combination of: LLM + tool access + reliable financial data


Why MCP Matters Here

MCP matters because it gives your AI a clean way to interact with external capabilities instead of pretending to know everything.

The MCP architecture is client-server based: a host such as Claude or Claude Desktop connects to one or more MCP servers, and those servers expose tools and resources. In practice, that means your AI can ask for a stock price, a fundamentals lookup, or a market-news request through an external tool instead of inventing an answer.

That is the bridge from "smart text generation" to "useful financial system."


Why EODHD APIs Are So Important

This is the part people underestimate.

You do not just need an API. You need a data source that is broad enough, stable enough, and practical enough to power repeated tool calls.


👉 Try EODHD APIs — the financial data layer that turns Claude from a language model into a finance-aware assistant.

For an AI financial assistant, the data layer needs to support use cases like:

  • current quote retrieval
  • historical chart context
  • fundamentals for deeper analysis
  • news-driven reasoning

If your data is fragmented across multiple providers, integration gets messy fast. If the responses are inconsistent, the AI layer becomes brittle. If the coverage is weak, the user notices immediately.

So the role of EODHD here is not cosmetic. It is the system that turns Claude from a language model into a finance-aware assistant.


Two Practical Ways to Connect Claude

Option 1: Claude API + Tool Calling

This is the easiest path if you are building your own app or backend. Claude supports tool use through the Messages API: you define the tools, Claude decides when to request one, your app executes it, and then Claude uses the returned data in the final answer.

Option 2: Claude + MCP Server

This is ideal if you want Claude clients such as Claude Desktop or Claude Code to connect to your tools through MCP. Claude Code supports MCP connections, and Claude Desktop can connect to local MCP servers; Claude also supports remote MCP servers through custom connectors.

For most projects, start with tool calling — it is simpler to understand. Then graduate to MCP when you want reusability across AI clients.


Part 1 — Simple Claude Integration with Tool Calling

Step 1: Install the SDK

Anthropic provides an official Python SDK for Claude.

pip install anthropic requests
Enter fullscreen mode Exit fullscreen mode

Step 2: Create the EODHD function

This is the function your app will execute when Claude asks for stock data.

import requests

EODHD_API_KEY = "YOUR_EODHD_API_KEY"

def get_stock_price(symbol: str) -> dict:
    url = f"https://eodhd.com/api/real-time/{symbol}?api_token={EODHD_API_KEY}&fmt=json"
    response = requests.get(url, timeout=20)
    response.raise_for_status()
    return response.json()
Enter fullscreen mode Exit fullscreen mode

This function is the bridge between Claude and real market data.

Step 3: Define the tool for Claude

Claude needs a schema so it knows the tool exists, what it does, and which input it requires. Anthropic's tool use docs emphasize defining tool schemas and descriptions clearly so Claude knows when to call them.

tools = [
    {
        "name": "get_stock_price",
        "description": "Get the latest real-time stock price for a public company ticker symbol using EODHD APIs.",
        "input_schema": {
            "type": "object",
            "properties": {
                "symbol": {
                    "type": "string",
                    "description": "Stock ticker symbol, for example AAPL, MSFT, TSLA"
                }
            },
            "required": ["symbol"]
        }
    }
]
Enter fullscreen mode Exit fullscreen mode

Step 4: Send the user question to Claude

from anthropic import Anthropic

client = Anthropic(api_key="YOUR_ANTHROPIC_API_KEY")

response = client.messages.create(
    model="claude-sonnet-4-5",
    max_tokens=500,
    tools=tools,
    messages=[
        {
            "role": "user",
            "content": "What is the current price of Apple stock?"
        }
    ]
)
Enter fullscreen mode Exit fullscreen mode

Anthropic's Messages API is the standard way to construct turns, manage state, and build the tool loop yourself.

Step 5: Detect Claude's tool request

When Claude decides the question requires live data, it returns a tool-use block instead of answering directly. That is the expected flow in Anthropic's tool use pattern.

for block in response.content:
    print(block)
Enter fullscreen mode Exit fullscreen mode

Typically, Claude will request something equivalent to:

{
  "type": "tool_use",
  "name": "get_stock_price",
  "input": {
    "symbol": "AAPL"
  }
}
Enter fullscreen mode Exit fullscreen mode

Step 6: Execute the function in your backend

tool_result = get_stock_price("AAPL")
print(tool_result)
Enter fullscreen mode Exit fullscreen mode

At this point, your application has done the real work: it queried EODHD APIs and got live data.

Step 7: Send the result back to Claude

Now you continue the conversation and give Claude the tool result so it can answer the user with grounded data.

follow_up = client.messages.create(
    model="claude-sonnet-4-5",
    max_tokens=500,
    tools=tools,
    messages=[
        {
            "role": "user",
            "content": "What is the current price of Apple stock?"
        },
        {
            "role": "assistant",
            "content": response.content
        },
        {
            "role": "user",
            "content": [
                {
                    "type": "tool_result",
                    "tool_use_id": next(block.id for block in response.content if block.type == "tool_use"),
                    "content": str(tool_result)
                }
            ]
        }
    ]
)

print(follow_up.content)
Enter fullscreen mode Exit fullscreen mode

And now Claude can answer with real market information instead of guessing.


Full Working Example (Claude + EODHD)

import requests
from anthropic import Anthropic

ANTHROPIC_API_KEY = "YOUR_ANTHROPIC_API_KEY"
EODHD_API_KEY = "YOUR_EODHD_API_KEY"

client = Anthropic(api_key=ANTHROPIC_API_KEY)

def get_stock_price(symbol: str) -> dict:
    url = f"https://eodhd.com/api/real-time/{symbol}?api_token={EODHD_API_KEY}&fmt=json"
    response = requests.get(url, timeout=20)
    response.raise_for_status()
    return response.json()

tools = [
    {
        "name": "get_stock_price",
        "description": "Get the latest real-time stock price for a public company ticker symbol using EODHD APIs.",
        "input_schema": {
            "type": "object",
            "properties": {
                "symbol": {
                    "type": "string",
                    "description": "Stock ticker symbol, for example AAPL, MSFT, TSLA"
                }
            },
            "required": ["symbol"]
        }
    }
]

user_question = "What is the current price of Apple stock?"

response = client.messages.create(
    model="claude-sonnet-4-5",
    max_tokens=500,
    tools=tools,
    messages=[
        {
            "role": "user",
            "content": user_question
        }
    ]
)

tool_use_block = None
for block in response.content:
    if block.type == "tool_use" and block.name == "get_stock_price":
        tool_use_block = block
        break

if tool_use_block is None:
    print("Claude answered directly:")
    print(response.content)
else:
    symbol = tool_use_block.input["symbol"]
    tool_result = get_stock_price(symbol)

    follow_up = client.messages.create(
        model="claude-sonnet-4-5",
        max_tokens=500,
        tools=tools,
        messages=[
            {
                "role": "user",
                "content": user_question
            },
            {
                "role": "assistant",
                "content": response.content
            },
            {
                "role": "user",
                "content": [
                    {
                        "type": "tool_result",
                        "tool_use_id": tool_use_block.id,
                        "content": str(tool_result)
                    }
                ]
            }
        ]
    )

    print("Claude final grounded answer:")
    print(follow_up.content)
Enter fullscreen mode Exit fullscreen mode

How the Claude Connection Actually Works

Claude does not call your API directly by magic.

The flow is this:

  1. The user asks Claude a question.
  2. Claude sees that it needs external financial data.
  3. Claude requests a tool call.
  4. Your backend executes that tool.
  5. The tool fetches live data from EODHD APIs.
  6. Your backend sends the result back to Claude.
  7. Claude writes the final answer using that live data.

That means Claude is the reasoning layer. Your tool is the execution layer. And EODHD APIs is the data layer that makes the whole thing useful.


If You Want Claude to Access This Through MCP

If you want to expose the same capability through MCP, the idea is simple:

  1. You create an MCP server
  2. That server exposes a tool such as get_stock_price
  3. Claude Desktop, Claude Code, or another MCP-compatible client connects to that server
  4. Claude can then use the tool through the MCP connection

MCP servers are the standard way to expose tools to compatible AI clients, and Claude Code plus Claude Desktop both support MCP-based tool connections.

Conceptually, it looks like this

Claude / Claude Desktop / Claude Code

MCP Client

MCP Server

EODHD API request

Real-time market data

Tool calling is great when you control the app. MCP is great when you want to make your tool reusable across AI clients and workflows.

  • If you're building a custom finance app, tool calling is the fastest way to connect Claude to EODHD APIs.
  • If you want a reusable integration that works across AI clients, MCP is the better long-term structure.

Why EODHD APIs Is the Layer That Creates Trust

In AI finance products, trust is not created by the model alone.

It is created by:

  • data freshness
  • response consistency
  • source reliability
  • breadth of market coverage

That is why the data provider matters so much.

A model can explain. A model can summarize. A model can compare.

But only a strong financial API can provide the live market context that makes those outputs valuable.


👉 Explore EODHD APIs — it gives Claude something far more important than words. It gives Claude evidence.

FAQ

What is the easiest way to connect Claude to a financial API?

The easiest way is to define a tool in the Claude Messages API, let Claude request it when needed, execute the API call in your backend, and return the result so Claude can answer with grounded data.

What is the difference between Claude tool calling and MCP?

Tool calling is the direct API pattern where your application defines and runs tools for Claude. MCP is an open standard for exposing tools and data sources to compatible AI clients like Claude Desktop or Claude Code.

Why use a financial API with Claude?

Because Claude alone does not have guaranteed access to live market information. A financial API supplies current prices, fundamentals, and other real-world data needed for reliable finance use cases.

Why is EODHD APIs useful for AI agents?

Because it gives your AI agent a practical source of financial data that can be called through tools, which makes the assistant more accurate, more useful, and far more product-ready.


Final Thought

Most AI agents in finance fail for one simple reason: they have intelligence, but they do not have access to reality.

Claude can reason beautifully. MCP can connect tools elegantly. But EODHD APIs is what gives the system real financial substance.

If you want to build an AI finance assistant that does more than generate polished guesses, start with the data layer.

That is where the real product begins.


Looking for technical content for your company? I can help — LinkedIn · kevinmenesesgonzalez@gmail.com

Top comments (0)