How to Query Financial Data with Anthropic's MCP and Claude Sonnet-4


In this tutorial, we'll explore how to leverage Anthropic's Model-Context Prompt (MCP) feature with Claude Sonnet-4, integrated with CoinAPI, to query financial data from multiple sources.. MCP (Model Context Protocol) allows you to connect Claude to external APIs, enabling powerful, context-aware queries. We'll walk through setting up a Python environment, configuring credentials, and querying two financial data sources to retrieve and summarize Apple's SEC 8-K filings.
Contents
Install Prerequisites
Configure Credentials
One-Shot Query with Two MCP Servers
Continuing the Conversation
Mixing Structured and Natural-Language Queries
1. Install Prerequisites
To get started, install the required Python packages: anthropic for interacting with Claude and rich for pretty-printing responses.
pip install -q anthropic rich
2. Configure Credentials
You'll need an Anthropic API key from console.anthropic.com. For security, store it in an environment variable to keep it out of your code.
import os
os.environ["ANTHROPIC_API_KEY"] = "YOUR_ANTHROPIC_API_KEY"
Replace YOUR_ANTHROPIC_API_KEY with your actual key.
3. One-Shot Query with Two MCP Servers
We'll query two external data sources using MCP:
Historical stock-price feed (mcp_api_apibricks_io)
SEC filings stream (mcp_sec_apibricks_io)
The MCP configuration is passed as a list of dictionaries to the mcp_servers parameter. Below, we ask Claude to find the date of Apple's most recent 8-K filing.
from anthropic import Anthropic
from rich import print
client = Anthropic()
api_key = "YOUR-FINFEED-API-KEY"
MCP_SERVERS = [
{
"type": "url",
"url": "https://mcp-historical.stock.finfeedapi.com/mcp",
"name": "mcp_api_apibricks_io",
"authorization_token": api_key
},
{
"type": "url",
"url": "https://mcp.sec.finfeedapi.com/sse",
"name": "mcp_sec_apibricks_io",
"authorization_token": api_key
}
]
response = client.beta.messages.create(
model="claude-sonnet-4-20250514",
max_tokens=1000,
messages=[{
"role": "user",
"content": "When did Apple last file an 8-K report?"
}],
mcp_servers=MCP_SERVERS,
extra_headers={"anthropic-beta": "mcp-client-2025-04-04"}
)
print(response.content)
Output Explanation: Claude queries the SEC filings stream and returns a structured response, indicating that Apple's most recent 8-K was filed on May 12, 2025, covering items 8.01 and 9.01. It also provides a brief history of recent filings, showcasing how MCP integrates data from external sources seamlessly.
4. Continuing the Conversation
To maintain context, append the previous user prompt and assistant response to the messages list. Here, we ask Claude to summarize the key points of the May 12, 2025, 8-K filing in bullet form.
conversation = [
{"role": "user", "content": "When did Apple last file an 8-K report?"},
{"role": "assistant", "content": response.content}
]
conversation.append({
"role": "user",
"content": "Great, could you summarize the key points from that 8-K in bullet form?"
})
follow_up = client.beta.messages.create(
model="claude-sonnet-4-20250514",
max_tokens=750,
messages=conversation,
mcp_servers=MCP_SERVERS,
extra_headers={"anthropic-beta": "mcp-client-2025-04-04"}
)
print(follow_up.content)
Output Summary:
Total Amount Raised: $4.5 billion through four series of corporate bonds
Bond Details:
$1.5 billion in 4.000% Notes due 2028
$1.0 billion in 4.200% Notes due 2030
$1.0 billion in 4.500% Notes due 2032
$1.0 billion in 4.750% Notes due 2035
Interest Payment Schedule: Semi-annual payments on May 12 and November 12, starting November 12, 2025
Underwriters: Goldman Sachs, Barclays Capital, BofA Securities, and J.P. Morgan Securities
Security Type: Senior unsecured obligations
Legal Structure: Issued under an existing indenture with Bank of New York Mellon Trust Company
Purpose: Likely a routine debt financing transaction
This demonstrates Claude's ability to maintain conversational context and extract detailed insights from the same data source.
5. Mixing Structured and Natural-Language Queries
Claude can handle structured outputs, such as JSON, for precise data extraction. Let's request only the filing date and a JSON summary of the 8-K filing.
conversation.append({
"role": "assistant",
"content": follow_up.content
})
conversation.append({
"role": "user",
"content": "Return ONLY a JSON object with keys `filing_date` and `highlights`."
})
json_reply = client.beta.messages.create(
model="claude-sonnet-4-20250514",
max_tokens=300,
messages=conversation,
mcp_servers=MCP_SERVERS,
extra_headers={"anthropic-beta": "mcp-client-2025-04-04"}
)
print(json_reply.content)
Output:
{
"filing_date": "2025-05-12",
"highlights": [
"Issued $4.5 billion in corporate bonds across four series",
"$1.5 billion in 4.000% Notes due 2028",
"$1.0 billion in 4.200% Notes due 2030",
"$1.0 billion in 4.500% Notes due 2032",
"$1.0 billion in 4.750% Notes due 2035",
"Underwritten by Goldman Sachs, Barclays Capital, BofA Securities, and J.P. Morgan Securities",
"Semi-annual interest payments beginning November 12, 2025",
"Senior unsecured obligations ranking equally with other Apple debt"
]
}
This JSON output shows Claude's flexibility in delivering structured data, ideal for developers integrating with other systems.
Conclusion
Using Anthropic's MCP with Claude Sonnet-4, you can seamlessly query multiple data sources, maintain conversational context, and generate both natural-language and structured outputs. This tutorial demonstrated how to:
Set up the Anthropic SDK and configure credentials securely
Query financial data from two MCP servers
Continue a conversation with context
Extract structured JSON responses
Try experimenting with other MCP-compatible APIs or different queries to unlock the full potential of Claude's multi-context capabilities!
Tags: #Anthropic #Claude #MCP #Python #FinancialData #API
Subscribe to my newsletter
Read articles from Ada Szymanska-Krowiak directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Ada Szymanska-Krowiak
Ada Szymanska-Krowiak
I'm Adrianna Szymanska-Krowiak, a dedicated Business-to-Developer (B2D) specialist with a passion for technology and innovation. Before diving into the world of APIs at CoinAPI, I cut my teeth in the tech industry at Dronehub, a leading drone company. There, I gained invaluable experience and insights into tech-driven solutions. Now, at CoinAPI, I focus on API products, using my expertise to bridge the gap between developers and business needs. My journey has been an exciting blend of technology and business, and I'm thrilled to contribute to the ever-evolving landscape of API solutions.