MCP Learning Series - Part 2

 


In the previous post we say what is MCP? In this post, we will create an MCP server and add it to Claude Desktop.

Claude Desktop is our AI application (MCP Host) which has inbuild MCP Client to connect to our MCP Server.

The MCP server which I am going to create is a simple math tool which can perform basic mathematical operations.

Simple Code for creating Mathematics Operations:

We use the decorator @mcp.tool to create a MCP tool. MCP allows to create Tools, Resources and Prompts.
# server.py
from mcp.server.mcpserver import MCPServer

mcp = MCPServer("Math Server")

@mcp.tool()
def add(a: int, b: int) -> int:
"""Add two numbers together."""
return a + b

def sub(a: int, b:int) -> int:
"""Sub two numbers"""
return a - b

def multiply(a: int, b:int) -> int:
"""Multiple two numbers"""
return a * b

def divide(a:int, b:int) -> int:
"""Divide two numbers"""
return a / b

if __name__ == "__main__":
mcp.run()
Start the MCP server using the command $ mcp dev math_server.py


The above command starts the MCP Server Debug mode in MCP Inspector. Click on the URL.



Now, under the tools you should see the math tool which we built.





Why we are seeing just add tool alone? Not the other ones?

In the Python MCP SDK:

  • Only functions decorated with @mcp.tool() become tools

  • Undecorated functions (like your sub, multiply, divide) remain normal Python functions and are not exposed to the MCP client

So the server currently exposes exactly one tool.

Updated code:

# server.py
from mcp.server import MCPServer

mcp = MCPServer("MathsMCP")

@mcp.tool()
def add(a: int, b: int) -> int:
"""Add two numbers together."""
return a + b

@mcp.tool()
def sub(a: int, b:int) -> int:
"""Sub two numbers"""
return a - b

@mcp.tool()
def multiply(a: int, b:int) -> int:
"""Multiple two numbers"""
return a * b

@mcp.tool()
def divide(a:int, b:int) -> int:
"""Divide two numbers"""
return a / b

if __name__ == "__main__":
mcp.run()


Now all the tools are visible in the MCP server. In the next blog, We will see how to connect to the MCP Server from AI Agent Tool like Claude.



Comments

Popular posts from this blog

Agentic AI - Series 3

Principal SRE - Interview Question

S3 - Directory Bucket