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

Update echo_server.py

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