Content
This is a runnable demo of an **mcp (model context protocol)** server with only **9 lines** of code, suitable for beginners who want to get started with mcp.
## Step 1: Download the Code
Download the complete code or simply copy the 9 lines of code below.
```python
import datetime
from mcp.server.fastmcp import FastMCP
mcp = FastMCP(name="time-service")
@mcp.tool(name="get_current_time", description="Get the current system time")
def get_current_time(format_str: str = "%Y-%m-%d %H:%M:%S") -> str:
now = datetime.datetime.now()
return now.strftime(format_str)
if __name__ == "__main__":
mcp.run(transport='sse') # Run the service in SSE mode
```
## Step 2: Configure the Conda Environment
```
conda.exe create -n mcp python=3.12
conda activate mcp
```
## Step 3: Install Dependencies
```
pip install "mcp[cli]"
pip install psutil
```
## Step 4: Run the Code
```
python mcp_get_current_time.py
```
## Step 5: Configure the mcp server in the chatbot and use it
Connection Info
You Might Also Like
markitdown
MarkItDown-MCP is a lightweight server for converting URIs to Markdown.
servers
Model Context Protocol Servers
Time
A Model Context Protocol server for time and timezone conversions.
Filesystem
Node.js MCP Server for filesystem operations with dynamic access control.
Sequential Thinking
A structured MCP server for dynamic problem-solving and reflective thinking.
git
A Model Context Protocol server for Git automation and interaction.