MCP Server
- In the last session we have used existing mcp Servers with Claude Desktop.
- Goal:
- Today lets try to write our own mcp server and call it from claude
- Introduce mcp inspector.
- MCP Server has 3 components
- tools
- resources
- prompts
Steps
- Refer Here for mcp server quick start with python.
- Create a new directory
demo - Now execute
cd demo
uv init .
- open this folder in vs code
code . - Now create a virtual environment and activate
uv venv .venv
.venv\Scripts\activate
- Select python interpretor
ctrl+shift+pin vscode to the virtual environment - Now add a package
uv add "mcp[cli]" - Now make changes in main.py
from mcp.server.fastmcp import FastMCP
mcp = FastMCP(name="Demo")
@mcp.tool()
def add(a:int, b: int) -> int:
"""Adds two numbers
Args:
a (int): a
b (int): b
Returns:
int: a + b
"""
return a + b
@mcp.tool()
def sub(a:int, b: int) -> int:
"""Subtracts two numbers
Args:
a (int): a
b (int): b
Returns:
int: a - b
"""
return a - b
if __name__ == "__main__":
mcp.run(transport='stdio')
- Now for testing the mcp server lets add the configuration of the current mcp in claude_desktop_config.json
{
"mcpServers": {
"demo": {
"command": "uv",
"args": [
"--directory",
"C:\\khajaclassroom\\GenerativeAI\\agenticai\\june25\\mcp\\servers\\demo",
"run",
"main.py"
]
}
}
}
- Ensure claude is relaunched

- Now write a prompt
add 1 and 5


- Refer Here for all the changes done to build a simple mcp server with add and subtract
Lets build an mcp server which takes notes
- Refer Here for official docs
- Resources are identified by uris Refer Here
- Refer Here for the changes done
- We can run mcp inspector
mcp dev <filename>.py 
