The Model Context Protocol (MCP) standardizes how agents discover and call tools. MCP has three roles:
from mcp import ClientSession
from contextlib import AsyncExitStack
class MCPServer:
async def connect(self, server_command: str):
# Connect to an MCP server process
self.session = await ClientSession.create(server_command)
async def list_tools(self):
return await self.session.list_tools()
async def call_tool(self, name: str, args: dict):
return await self.session.call_tool(name, args)
from mcp.server import Server
server = Server("market-data-server")
@server.list_tools()
async def list_tools():
return [
Tool(name="get_stock_price",
description="Get current stock price",
inputSchema={"type": "object", "properties": {"ticker": {"type": "string"}}})
]
@server.call_tool()
async def call_tool(name, arguments):
if name == "get_stock_price":
import yfinance as yf
stock = yf.Ticker(arguments["ticker"])
return {"price": stock.info.get("currentPrice")}
Build MCP servers that connect to Brave Search API, Polygon.io (market data), and other external services.
The final capstone combines everything into a trading floor simulation:
Learn how to select the right framework for your use case, key configuration settings, and lessons learned from production agent deployments.