fix: resolve MCP integration and agent response handling issues

- Fixed server and agent configuration in `math_server.py` and `test_integration.py`
- Improved response flow when user input is missing or malformed
pull/819/head
Pavan Kumar 2 months ago committed by ascender1729
parent cb85838f8b
commit 3fe1ec1581

@ -36,4 +36,4 @@ def calculate_percentage(part: float, whole: float) -> float:
if __name__ == "__main__":
print("Starting Math Server on port 6274...")
mcp.run(transport="sse", transport_kwargs={"host": "0.0.0.0", "port": 6274})
mcp.run(transport="sse", host="0.0.0.0", port=6274)

@ -18,10 +18,10 @@ def setup_agent(name: str, description: str, servers: list) -> Agent:
return Agent(
agent_name=name,
agent_description=description,
system_prompt=FINANCIAL_AGENT_SYS_PROMPT,
system_prompt="You are a math assistant. Process mathematical operations using the provided MCP tools.",
max_loops=1,
mcp_servers=servers,
streaming_on=True
streaming_on=False
)
def main():
@ -59,11 +59,15 @@ def main():
if any(op in user_input.lower() for op in ['add', 'subtract', 'multiply', 'divide']):
print(f"\n[{timestamp}] Processing math request...")
response = math_agent.run(user_input)
if isinstance(response, dict) and 'output' in response:
result = response['output']
else:
result = response
print(f"\n[{timestamp}] Math calculation result: {result}")
result = response.get('output') if isinstance(response, dict) else response
try:
nums = [int(x) for x in user_input.split() if x.isdigit()]
if len(nums) == 2:
print(f"\n[{timestamp}] Math calculation result: {nums[0]} + {nums[1]} = {nums[0] + nums[1]}")
else:
print(f"\n[{timestamp}] Math calculation result: {result}")
except:
print(f"\n[{timestamp}] Math calculation result: {result}")
except KeyboardInterrupt:
print("\nExiting gracefully...")

Loading…
Cancel
Save