Skip to content

Commit b04b238

Browse files
committed
Update the MCP functions to handle API response JSON
Signed-off-by: Michael Yuan <[email protected]>
1 parent 8f00e39 commit b04b238

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

app/mcp_tools.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,12 @@ async def generate(description: str, requirements: str) -> str:
4646
try:
4747
response = await client.post(f"{API_BASE_URL}/generate-sync", json={'description': description, 'requirements': requirements})
4848
response.raise_for_status()
49-
return response.text
49+
50+
resp_json = json.loads(response.text)
51+
if "combined_text" in resp_json:
52+
return resp_json["combined_text"]
53+
else:
54+
return "Rust project creation error."
5055
except httpx.HTTPError as e:
5156
print(f"HTTP error occurred: {e}")
5257
return f"Error trying to generate a Rust project: {str(e)}"
@@ -84,7 +89,7 @@ async def compile_and_fix(code: str, description: str = "A Rust project", max_at
8489

8590
resp_json = json.loads(response.text)
8691
if "combined_text" in resp_json:
87-
return ["combined_text"]
92+
return resp_json["combined_text"]
8893
else:
8994
return "Cannot fix the Rust compiler error."
9095
# return response.text
@@ -122,7 +127,7 @@ async def compile(code: str) -> str:
122127

123128
resp_json = json.loads(response.text)
124129
if "build_output" in resp_json:
125-
return ["build_output"]
130+
return resp_json["build_output"]
126131
else:
127132
return "Rust compiler error."
128133
except httpx.HTTPError as e:

0 commit comments

Comments
 (0)