forked from modelcontextprotocol/python-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_mcp_server.py
More file actions
32 lines (24 loc) · 826 Bytes
/
example_mcp_server.py
File metadata and controls
32 lines (24 loc) · 826 Bytes
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
#
# Small Demo server using FastMCP and illustrating debugging and notification streams
#
import logging
from mcp.server.fastmcp import FastMCP, Context
import time
mcp = FastMCP("MCP EXAMPLE SERVER", debug=True, log_level="DEBUG")
logger = logging.getLogger(__name__)
logger.debug(f"MCP STARTING EXAMPLE SERVER")
@mcp.resource("config://app")
def get_config() -> str:
"""Static configuration data"""
return "Test Server 2024-02-25"
@mcp.tool()
async def simple_tool(x:float, y:float, ctx:Context) -> str:
logger.debug("IN SIMPLE_TOOL")
await ctx.report_progress(1, 2)
return x*y
@mcp.tool()
async def simple_tool_with_logging(x:float, y:float, ctx:Context) -> str:
await ctx.info(f"Processing Simple Tool")
logger.debug("IN SIMPLE_TOOL")
await ctx.report_progress(1, 2)
return x*y