-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_server.py
More file actions
67 lines (46 loc) · 1.49 KB
/
example_server.py
File metadata and controls
67 lines (46 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
"""
Example MCP server for testing the CLI.
Run this server with:
python example_server.py
Then test with the CLI using example_config.json
"""
from fastmcp import FastMCP
mcp = FastMCP(name="Example Server")
@mcp.tool
def greet(name: str) -> str:
"""Greet someone by name."""
return f"Hello, {name}! Welcome to MCP CLI."
@mcp.tool
def add(a: int, b: int) -> int:
"""Add two numbers together."""
return a + b
@mcp.tool
def multiply(x: float, y: float) -> float:
"""Multiply two numbers."""
return x * y
@mcp.resource("data://example/info")
def get_info() -> dict:
"""Get example server information."""
return {
"name": "Example Server",
"version": "1.0.0",
"description": "A simple example MCP server for testing"
}
@mcp.resource("data://example/{item}")
def get_item(item: str) -> dict:
"""Get information about a specific item."""
items = {
"apple": {"name": "Apple", "color": "red", "price": 1.50},
"banana": {"name": "Banana", "color": "yellow", "price": 0.75},
"orange": {"name": "Orange", "color": "orange", "price": 1.25}
}
if item.lower() in items:
return items[item.lower()]
return {"error": f"Item '{item}' not found"}
@mcp.prompt
def analyze_data(data: str) -> str:
"""Create a prompt for analyzing data."""
return f"Please analyze the following data and provide insights:\n\n{data}"
if __name__ == "__main__":
# Run with stdio transport (default)
mcp.run()