Skip to content

Integrate Model Context Protocol (MCP) #15

@jsham042

Description

@jsham042

Summary:
Set up the Model Context Protocol (MCP) in our Python project using uv, define and expose a tool that uses a structured data type (BMI calculator), and verify interaction via MCP server.

Description:
This task involves integrating MCP into our Python project to allow structured and typed tool execution over an MCP server. We'll use a dataclass as input for one tool (BMI calculation) to demonstrate this capability.

Acceptance Criteria:

Project environment set up using uv

MCP SDK installed and working

MCP server created and running

At least one MCP tool implemented using a custom data class

Tool accepts input and returns output correctly

Code tested and documented

Steps to Implement:

  1. Set Up Environment

bash
Copy
Edit
pip install uv
uv init my_mcp_project
cd my_mcp_project
uv venv
source .venv/bin/activate # On Windows use .venv\Scripts\activate
2. Install MCP SDK

bash
Copy
Edit
uv add mcp
3. Create a Data Type

python
Copy
Edit

bmi_input.py

from dataclasses import dataclass

@DataClass
class BMIInput:
weight_kg: float
height_m: float
4. Set Up MCP Server

python
Copy
Edit

main.py

from mcp.server.fastmcp import FastMCP
from bmi_input import BMIInput

mcp = FastMCP("BMIServer")

@mcp.tool()
def calculate_bmi(input_data: BMIInput) -> float:
"""Calculate BMI from weight and height."""
return input_data.weight_kg / (input_data.height_m ** 2)

if name == "main":
mcp.run()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions