Jofthomas commited on
Commit
700465c
·
verified ·
1 Parent(s): 24b4137

Update echo_server.py

Browse files
Files changed (1) hide show
  1. echo_server.py +5 -30
echo_server.py CHANGED
@@ -1,32 +1,7 @@
1
- from fastmcp import FastMCP
2
- from fastmcp.server.dependencies import get_http_headers
3
 
 
4
 
5
- mcp = FastMCP("My MCP Server", stateless_http=True)
6
-
7
-
8
- @mcp.tool
9
- def greet() -> str:
10
- headers = get_http_headers()
11
- print(f"Received headers: {headers}")
12
- name = headers.get("x-given-name", "unknown")
13
- return f"Hello, {name}!"
14
-
15
-
16
- @mcp.tool
17
- async def safe_header_info() -> dict:
18
- """Safely get header information without raising errors."""
19
- # Get headers (returns empty dict if no request context)
20
- headers = get_http_headers()
21
-
22
- # Get authorization header
23
- auth_header = headers.get("authorization", "")
24
- is_bearer = auth_header.startswith("Bearer ")
25
-
26
- return {
27
- "user_agent": headers.get("user-agent", "Unknown"),
28
- "content_type": headers.get("content-type", "Unknown"),
29
- "has_auth": bool(auth_header),
30
- "auth_type": "Bearer" if is_bearer else "Other" if auth_header else "None",
31
- "headers_count": len(headers),
32
- }
 
1
+ from mcp.server.fastmcp import FastMCP
 
2
 
3
+ mcp = FastMCP(name="EchoServer", stateless_http=True)
4
 
5
+ @mcp.tool(description="A simple echo tool")
6
+ def echo(message: str) -> str:
7
+ return f"Echo: {message}"