Skip to content

Commit d52fe43

Browse files
committed
futz
1 parent ec3e070 commit d52fe43

File tree

1 file changed

+41
-24
lines changed

1 file changed

+41
-24
lines changed

jacspy-mcp/src/jacs_mcp/fast_mcp_auth3.py

Lines changed: 41 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ async def run_auth_demo():
3232
# Create server
3333
server = FastMCP("AuthEchoServer")
3434

35-
@server.tool(name="echo", description="Echo with authentication")
36-
async def echo(msg: str, auth: Dict = None) -> str:
35+
@server.tool(name="echos", description="Echos with authentication")
36+
async def echos(msg: str, auth: Dict = None) -> str:
3737
"""Echo with authentication"""
3838
# Log to file instead of printing
3939
with open("server_logs.txt", "a") as log:
@@ -78,7 +78,7 @@ async def echo(msg: str, auth: Dict = None) -> str:
7878
log.flush()
7979

8080
# Try returning just a simple string instead of JSON
81-
return f"Echo via SSESSS: {msg}"
81+
return f"Echo via SSESSS: {str(response_json)} s"
8282

8383
# Start server
8484
import uvicorn
@@ -120,36 +120,53 @@ async def echo(msg: str, auth: Dict = None) -> str:
120120
print(f"Request params: {params}")
121121

122122
# Call the tool
123-
result = await client.call_tool("echo", params)
123+
result = await client.call_tool("echos", params)
124124
print("\n=== CLIENT RECEIVED RESPONSE ===")
125125
print(f"Raw result: {result}")
126126

127127
# Parse the response
128128
if isinstance(result, list) and len(result) > 0:
129129
# Response is a TextContent object
130-
content = result[0].text
131-
try:
132-
# Parse the JSON response
133-
response_json = json.loads(content)
134-
print(f"Parsed response: {response_json}")
130+
content_object = result[0]
131+
if hasattr(content_object, 'text'):
132+
content = content_object.text
135133

136-
# Verify the response authentication
137-
if "result" in response_json and "auth" in response_json:
138-
response_data = response_json["result"]
139-
auth = response_json["auth"]
134+
# Extract the JSON part from the string
135+
try:
136+
# Find the start and end of the JSON object
137+
json_start = content.find('{')
138+
json_end = content.rfind('}') + 1
140139

141-
if "data" in auth and "signature" in auth:
142-
# Verify signature
143-
is_valid = verify_signature(auth["data"], auth["signature"])
144-
print(f"Response signature valid: {is_valid}")
145-
print(f"Response data: {response_data}")
146-
print(f"Auth data: {auth['data']}")
140+
if json_start != -1 and json_end != -1:
141+
json_string = content[json_start:json_end]
142+
143+
# Parse the extracted JSON string
144+
response_json = json.loads(json_string)
145+
print(f"Parsed JSON response: {response_json}")
146+
147+
# Verify the response authentication
148+
if "result" in response_json and "auth" in response_json:
149+
response_data = response_json["result"]
150+
auth = response_json["auth"]
151+
152+
if "data" in auth and "signature" in auth:
153+
# Verify signature
154+
is_valid = verify_signature(auth["data"], auth["signature"])
155+
print(f"Response signature valid: {is_valid}")
156+
print(f"Response data: {response_data}")
157+
print(f"Auth data: {auth['data']}")
158+
else:
159+
print("Missing auth data or signature in response")
160+
else:
161+
print("Invalid response format")
147162
else:
148-
print("Missing auth data or signature in response")
149-
else:
150-
print("Invalid response format")
151-
except json.JSONDecodeError:
152-
print("Failed to parse response as JSON")
163+
print("Could not find JSON object in response string")
164+
except json.JSONDecodeError:
165+
print(f"Failed to parse extracted JSON: {json_string}")
166+
except Exception as e:
167+
print(f"Error processing response content: {e}")
168+
else:
169+
print("TextContent object does not have 'text' attribute")
153170
else:
154171
print("Unexpected response format")
155172
finally:

0 commit comments

Comments
 (0)