← Back to Tutorials

MCP & Capstone

Introduction to MCP

The Model Context Protocol (MCP) standardizes how agents discover and call tools. MCP has three roles:

Multi-Server Agent

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)

Building Custom MCP Servers

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")}

Memory & External APIs

Build MCP servers that connect to Brave Search API, Polygon.io (market data), and other external services.

Capstone: Trading Floor

The final capstone combines everything into a trading floor simulation:

Course Conclusion

Learn how to select the right framework for your use case, key configuration settings, and lessons learned from production agent deployments.

✏️ Exercise: Build a custom MCP server that provides a portfolio management tool (check balance, buy/sell stocks, view history). Create an agent that uses this MCP server along with a market data MCP server to provide a complete trading assistant. Deploy with a Gradio frontend.