Upload mcp_server_fastmcp.py
Browse files
EasyReportDataMCP/mcp_server_fastmcp.py
CHANGED
|
@@ -390,12 +390,13 @@ if __name__ == "__main__":
|
|
| 390 |
else:
|
| 391 |
return JSONResponse({"jsonrpc": "2.0", "id": json_data.get("id"), "error": {"code": -32601, "message": f"Unknown tool: {tool_name}"}}, status_code=200)
|
| 392 |
|
| 393 |
-
# Return MCP-formatted response
|
|
|
|
| 394 |
return JSONResponse({
|
| 395 |
"jsonrpc": "2.0",
|
| 396 |
"id": json_data.get("id"),
|
| 397 |
"result": {
|
| 398 |
-
"content": [{"type": "text", "text":
|
| 399 |
}
|
| 400 |
}, status_code=200)
|
| 401 |
elif method == "tools/list":
|
|
@@ -407,6 +408,8 @@ if __name__ == "__main__":
|
|
| 407 |
else:
|
| 408 |
return JSONResponse({"jsonrpc": "2.0", "id": json_data.get("id"), "error": {"code": -32601, "message": f"Unknown method: {method}"}}, status_code=200)
|
| 409 |
except Exception as e:
|
|
|
|
|
|
|
| 410 |
return JSONResponse({"jsonrpc": "2.0", "id": 1, "error": {"code": -32603, "message": str(e)}}, status_code=500)
|
| 411 |
|
| 412 |
async def run_custom_sse():
|
|
|
|
| 390 |
else:
|
| 391 |
return JSONResponse({"jsonrpc": "2.0", "id": json_data.get("id"), "error": {"code": -32601, "message": f"Unknown tool: {tool_name}"}}, status_code=200)
|
| 392 |
|
| 393 |
+
# Return MCP-formatted response with JSON serialization
|
| 394 |
+
import json as json_module
|
| 395 |
return JSONResponse({
|
| 396 |
"jsonrpc": "2.0",
|
| 397 |
"id": json_data.get("id"),
|
| 398 |
"result": {
|
| 399 |
+
"content": [{"type": "text", "text": json_module.dumps(result, ensure_ascii=False)}]
|
| 400 |
}
|
| 401 |
}, status_code=200)
|
| 402 |
elif method == "tools/list":
|
|
|
|
| 408 |
else:
|
| 409 |
return JSONResponse({"jsonrpc": "2.0", "id": json_data.get("id"), "error": {"code": -32601, "message": f"Unknown method: {method}"}}, status_code=200)
|
| 410 |
except Exception as e:
|
| 411 |
+
import traceback
|
| 412 |
+
traceback.print_exc()
|
| 413 |
return JSONResponse({"jsonrpc": "2.0", "id": 1, "error": {"code": -32603, "message": str(e)}}, status_code=500)
|
| 414 |
|
| 415 |
async def run_custom_sse():
|