On this hands-on tutorial, we’ll construct an MCP (Mannequin Context Protocol) server that permits Claude Desktop to fetch inventory information sentiment and each day prime gainers and movers by way of the AlphaVantage API. Since most LLMs can’t immediately entry real-time monetary knowledge, this answer makes use of MCP to offer real-time insights.
We’ll expose two instruments from our server:
- get_news_sentiment
- get_top_movers
Let’s stroll by means of every step.
Step 1: Setting Up the Surroundings
We’ll first arrange the environment and begin with putting in the uv bundle supervisor. For Mac or Linux:
curl -LsSf https://astral.sh/uv/set up.sh | sh
For Home windows (PowerShell):
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/set up.ps1 | iex"
We’ll then create a brand new venture listing and initialize it with uv
uv init stockNews
cd stockNews
We will now create and activate a digital setting. For Mac or Linux:
uv venv
supply .venv/bin/activate
For Home windows:
uv venv
.venvScriptsactivate
We’ll now set up the required dependencies
uv add mcp httpx python-dotenv
Step 3: Setting Up the Surroundings Variables
We’ll now create a .env file that comprises the API key for AlphaVantage. To generate a free API key:
Now, create a .env file and add the next line:
ALPHA_VANTAGE_API_KEY = your_api_key
Step 4: Implementing the MCP Server and integrating AlphaVantage
First create a stockNews.py file within the listing that we created and add the next code snippets:
Importing packages and establishing the occasion:
We’ll first import the required packages and arrange occasion to make use of the API
from typing import Any
import os
import httpx
from mcp.server.fastmcp import FastMCP
from dotenv import load_dotenv
# Load .env variables
load_dotenv()
API_KEY = os.getenv("ALPHA_VANTAGE_API_KEY")
# Initialize FastMCP server
mcp = FastMCP("alpha-finance")
# Constants
BASE_URL = "https://www.alphavantage.co/question"
Helper features
Subsequent, let’s add our helper features for querying the info from AlphaVantage.
async def call_alpha_vantage(endpoint: str, params: dict[str, Any]) -> dict[str, Any] | None:
"""Generic async caller to Alpha Vantage."""
params["apikey"] = API_KEY
params["function"] = endpoint
async with httpx.AsyncClient() as shopper:
strive:
response = await shopper.get(BASE_URL, params=params, timeout=30.0)
response.raise_for_status()
return response.json()
besides Exception:
return None
Implementing software execution
The software execution handler is answerable for executing the logic of every software.
@mcp.software()
async def get_news_sentiment(ticker: str) -> str:
"""Get information sentiment knowledge for a inventory ticker.
Args:
ticker: Inventory ticker image (e.g., MSFT, AAPL)
"""
knowledge = await call_alpha_vantage("NEWS_SENTIMENT", {"tickers": ticker.higher()})
if not knowledge or "feed" not in knowledge:
return "Could not retrieve information sentiment."
articles = knowledge["feed"][:3]
outcome = []
for merchandise in articles:
outcome.append(f"""
📰 {merchandise['title']}
Abstract: {merchandise['summary']}
Supply: {merchandise['source']} | Printed: {merchandise['time_published']}
""")
return "n---n".be a part of(outcome)
@mcp.software()
async def get_top_movers() -> str:
"""Get prime gainers and losers from the inventory market.
No arguments required.
"""
knowledge = await call_alpha_vantage("TOP_GAINERS_LOSERS", {})
if not knowledge:
return "Could not retrieve prime movers."
gainers = knowledge.get("top_gainers", [])[:3]
losers = knowledge.get("top_losers", [])[:3]
outcome = "**Prime Gainers**n"
outcome += "n".be a part of([
f"{g['ticker']} ({g.get('change_percentage', 'N/A')})"
for g in gainers
])
outcome += "nn**Prime Losers**n"
outcome += "n".be a part of([
f"{l['ticker']} ({l.get('change_percentage', 'N/A')})"
for l in losers
])
return outcome
Operating the server
Lastly, let’s initialize and run the server:
if __name__ == "__main__":
mcp.run(transport="stdio")
We’ll now take a look at our server from an present MCP host, Claude for Desktop.
Step 5: Testing the server
First, guarantee you might have Claude for Desktop put in. If not, obtain and set up the most recent model from the official supply. If you have already got it, be certain it’s updated.
Subsequent, you’ll have to configure Claude to attach together with your MCP server. To do that, open the claude_desktop_config.json file positioned within the Claude listing utilizing any textual content editor. If the file doesn’t exist, go forward and create it manually.
For MacOS/Linux:
{
"mcpServers": {
"stockNews": {
"command": "uv",
"args": [
"--directory",
"/ABSOLUTE/PATH/TO/PARENT/FOLDER/stockNews",
"run",
"stockNews.py"
]
}
}
}
For Home windows:
{
"mcpServers": {
"stockNews": {
"command": "uv",
"args": [
"--directory",
"C:ABSOLUTEPATHTOPARENTFOLDERstockNews",
"run",
"stockNews.py"
]
}
}
}
This configuration lets Claude for Desktop know that:
- There’s an MCP server known as “stockNews”.
- It needs to be launched utilizing the next command:
uv –listing /ABSOLUTE/PATH/TO/PARENT/FOLDER/stockNews run stockNews.py
When you’ve added this to your config file, save the file and restart Claude for Desktop to use the adjustments.
Take a look at with instructions
To verify that Claude for Desktop has acknowledged the 2 instruments out of your stockNews server, search for the hammer icon within the Claude interface — this icon signifies software entry.
After clicking on the hammer icon, you must see two instruments listed:
We will take a look at the server by operating the next prompts:
- What’s the information sentiment for Apple?
- Who’re the highest gainers and losers from the inventory market?
Whenever you ask Claude a query:
- The shopper sends your question to Claude.
- Claude critiques the obtainable instruments (like get_news_sentiment or get_top_movers) and determines which one(s) to make use of based mostly in your query.
- The chosen software is executed by way of the MCP server you configured earlier.
- The software returns the outcomes again to Claude.
- Claude makes use of these outcomes to craft a pure language response.
- The ultimate response is proven to you within the chat interface.
This seamless circulate is what permits Claude to work together with real-time knowledge in a structured and managed method.
Conclusion:
Our MCP-based inventory insights server extends Claude Desktop’s capabilities by enabling real-time monetary knowledge retrieval. By integrating the AlphaVantage API with a customized MCP server, customers can fetch stay information sentiment and monitor prime market movers immediately by means of Claude. This setup empowers customers with well timed, actionable inventory insights—all inside a conversational interface—making monetary evaluation extra environment friendly, contextual, and interactive.

I’m a Civil Engineering Graduate (2022) from Jamia Millia Islamia, New Delhi, and I’ve a eager curiosity in Information Science, particularly Neural Networks and their software in numerous areas.