@@ -34,53 +34,51 @@ async def run_auth_demo():
3434
3535 @server .tool (name = "echo" , description = "Echo with authentication" )
3636 async def echo (msg : str , auth : Dict = None ) -> str :
37- """Echo with authentication
38-
39- Args:
40- msg: The text to echo
41- auth: Authentication data with signature
37+ """Echo with authentication"""
38+ # Log to file instead of printing
39+ with open ("server_logs.txt" , "a" ) as log :
40+ log .write ("\n === SERVER RECEIVED REQUEST ===\n " )
41+ log .write (f"Message: { msg } \n " )
42+ log .write (f"Auth: { auth } \n " )
4243
43- Returns:
44- Authenticated response as text
45- """
46- print ("\n === SERVER RECEIVED REQUEST ===" )
47- print (f"Message: { msg } " )
48- print (f"Auth: { auth } " )
49-
50- # Validate request
51- auth_valid = False
52- if auth and "data" in auth and "signature" in auth :
53- # Verify signature
54- auth_valid = verify_signature (auth ["data" ], auth ["signature" ])
55- print (f"Auth valid: { auth_valid } " )
56- else :
57- print ("Missing auth data or signature" )
58-
59- # Create response with embedded auth
60- response_data = {
61- "text" : f"Echo: { msg } " ,
62- "timestamp" : datetime .now ().isoformat (),
63- "auth_valid" : auth_valid
64- }
65-
66- # Sign the response
67- response_signature = generate_signature (response_data )
68-
69- # Embed auth in response as JSON
70- response_json = json .dumps ({
71- "result" : response_data ,
72- "auth" : {
73- "data" : {
74- "server_id" : "s1" ,
75- "res_id" : f"res-{ uuid .uuid4 ()} " ,
76- "timestamp" : datetime .now ().isoformat ()
77- },
78- "signature" : response_signature
44+ # Validate request
45+ auth_valid = False
46+ if auth and "data" in auth and "signature" in auth :
47+ # Verify signature
48+ auth_valid = verify_signature (auth ["data" ], auth ["signature" ])
49+ log .write (f"Auth valid: { auth_valid } \n " )
50+ else :
51+ log .write ("Missing auth data or signature\n " )
52+
53+ # Create response with embedded auth
54+ response_data = {
55+ "text" : f"Echo: { msg } " ,
56+ "timestamp" : datetime .now ().isoformat (),
57+ "auth_valid" : auth_valid
7958 }
80- })
81-
82- print (f"Sending response: { response_json } " )
83- return response_json
59+
60+ # Sign the response
61+ response_signature = generate_signature (response_data )
62+
63+ # Embed auth in response as JSON
64+ response_json = json .dumps ({
65+ "result" : response_data ,
66+ "auth" : {
67+ "data" : {
68+ "server_id" : "s1" ,
69+ "res_id" : f"res-{ uuid .uuid4 ()} " ,
70+ "timestamp" : datetime .now ().isoformat ()
71+ },
72+ "signature" : response_signature
73+ }
74+ })
75+
76+ log .write (f"Sending response: { response_json } \n " )
77+ log .write ("=== END SERVER PROCESSING ===\n " )
78+ log .flush ()
79+
80+ # Try returning just a simple string instead of JSON
81+ return f"Echo via SSESSS: { msg } "
8482
8583 # Start server
8684 import uvicorn
0 commit comments