MCP solves a similar problem for AI, creating a standard way for AI Clients (like Claude, Cursor or others) to connect to a wide range of tools and data sources. Think of it as a standardized port that allows your AI to effortlessly access things like real-time stock prices, your email inbox, or even complex APIs, all without complicated, one-off setups.
Imagine giving your AI a Swiss Army knife. With MCP, it gains a set of tools: it can fetch information, generate images, interact with services, and even automate tasks, all while keeping your data access secure within your own infrastructure. It’s about making AI agents truly capable and versatile.
uv init server
cd server
uv venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
uv add "mcp[cli]" httpx aiohttp yfinance asyncio
touch server.py # Windows: New-Item server.py
import yfinance as yf
from mcp.server.fastmcp import FastMCP
import asyncio
import aiohttp
mcp = FastMCP("stock_prices")
@mcp.tool()
async def get_stock_price(ticker: str) -> str:
@mcp.tool()
async def generate_t2i_image(prompt: str) -> str:
{
"mcpServers": {
"server": {
"command": "/full/path/to/uv", # **Replace this** with the full path to your 'uv' executable
"args": [
"--directory",
"/full/path/to/server",# **Replace this** with the full absolute path to your 'server' project directory
"run",
"server.py"
]
}
}
}
How It All Fits Together
Claude (MCP Client/Host): Claude acts as the intelligent brain, equipped with an MCP client. It wants to extend its capabilities by using external tools.
Your MCP Server (server.py): This is the tool provider (the MCP server). It exposes specific functionalities — like fetching stock prices and generating images — via the MCP protocol.
MCP Protocol: This is the standardized language and set of rules that allows Claude (via its MCP client) to communicate with your MCP server. It’s the “bridge” enabling smooth interaction.
Your Client sends a request (e.g., “Get AAPL price”), the Server processes it, and sends back “$174.50”. Simple and fast.
No comments:
Post a Comment