Skip to content

Commit 2cfa1f9

Browse files
committed
feat: Simple MCP server
1 parent a433482 commit 2cfa1f9

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ This repository demonstrates the usage of a simple Model Context Protocol (MCP)
66
- OpenAI Agents
77
- Pydantic-AI Agents
88

9+
Included MCP Server is based on [MCP Python SDK Quickstart](https://github.com/modelcontextprotocol/python-sdk/blob/b4c7db6a50a5c88bae1db5c1f7fba44d16eebc6e/README.md?plain=1#L104)
10+
- Modified to include a datetime tool and run as a server invoked by Agents
11+
912
Tracing is done through Pydantic Logfire.
1013

1114
# Quickstart
@@ -35,6 +38,8 @@ This project aims to teach:
3538
- `oai-agent_mcp.py` - Examoke of using MCP with OpenAI Agents
3639
- `pydantic_mcp.py` - Example of using MCP with Pydantic-AI
3740

41+
- `run_server.py` - Simple MCP server that runs locally implemented in Python
42+
3843

3944
## What is MCP?
4045

run_server.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from datetime import datetime
2+
3+
from mcp.server.fastmcp import FastMCP
4+
5+
# Create an MCP server
6+
mcp = FastMCP("Demo")
7+
8+
9+
# Add an addition tool
10+
@mcp.tool()
11+
def add(a: int, b: int) -> int:
12+
"""Add two numbers"""
13+
return a + b
14+
15+
16+
# Add a tool to get the current time
17+
@mcp.tool()
18+
def get_current_time() -> str:
19+
"""Get the current time"""
20+
return datetime.now().strftime("%Y-%m-%d %H:%M:%S")
21+
22+
23+
# Add a dynamic greeting resource
24+
@mcp.resource("greeting://{name}")
25+
def get_greeting(name: str) -> str:
26+
"""Get a personalized greeting"""
27+
return f"Hello, {name}!"
28+
29+
30+
if __name__ == "__main__":
31+
mcp.run()

0 commit comments

Comments
 (0)