test: enhance MCP integration test with tool discovery and user guidance

pull/819/head
Pavan Kumar 2 days ago committed by ascender1729
parent 2e2ebc40c8
commit 10e056a05e

@ -41,3 +41,20 @@ mode = "sequential"
[[workflows.workflow.tasks]]
task = "shell.exec"
args = "python examples/mcp_example/test_integration.py"
[[workflows.workflow]]
name = "Run MCP Test"
author = 13983571
mode = "sequential"
[[workflows.workflow.tasks]]
task = "shell.exec"
args = "python examples/mcp_example/math_server.py & "
[[workflows.workflow.tasks]]
task = "shell.exec"
args = "sleep 2"
[[workflows.workflow.tasks]]
task = "shell.exec"
args = "python examples/mcp_example/test_integration.py"

@ -1,43 +1,47 @@
from swarms import Agent
from swarms.prompts.finance_agent_sys_prompt import FINANCIAL_AGENT_SYS_PROMPT
from swarms.tools.mcp_integration import MCPServerSseParams
import logging
# Configure MCP server connection
server = MCPServerSseParams(
url="http://0.0.0.0:6274",
headers={"Content-Type": "application/json"},
timeout=10.0,
sse_read_timeout=300.0
)
def main():
# Configure MCP server connection
server = MCPServerSseParams(
url="http://0.0.0.0:6274",
headers={"Content-Type": "application/json"},
timeout=10.0,
sse_read_timeout=300.0
)
# Initialize agent with MCP capabilities
agent = Agent(
agent_name="Math-Agent",
agent_description="Agent that performs math operations",
system_prompt=FINANCIAL_AGENT_SYS_PROMPT,
max_loops=1,
mcp_servers=[server],
streaming_on=True
)
# Initialize agent with MCP capabilities
agent = Agent(
agent_name="Math-Agent",
agent_description="Agent that performs math operations",
system_prompt=FINANCIAL_AGENT_SYS_PROMPT,
max_loops=1,
mcp_servers=[server],
streaming_on=True
)
def test_mcp_operations():
"""Test basic MCP operations with error handling"""
try:
# Test addition
print("\nTesting addition...")
add_result = agent.run("Use the add tool to add 5 and 3")
print("Addition result:", add_result)
# Test multiplication
print("\nTesting multiplication...")
mult_result = agent.run("Use the multiply tool to multiply 4 and 6")
print("Multiplication result:", mult_result)
# Test error case
print("\nTesting error handling...")
error_result = agent.run("Use the add tool with invalid inputs")
print("Error handling result:", error_result)
# First get available tools from server
print("\nDiscovering available tools from MCP server...")
tools = agent.mcp_tool_handling()
print("\nAvailable tools:", tools)
while True:
# Get user input
user_input = input("\nEnter a math operation (or 'exit' to quit): ")
if user_input.lower() == 'exit':
break
# Process user input through agent
try:
result = agent.run(user_input)
print("\nResult:", result)
except Exception as e:
print(f"Error processing request: {e}")
except Exception as e:
logging.error(f"Test failed: {e}")
@ -45,4 +49,4 @@ def test_mcp_operations():
if __name__ == "__main__":
logging.basicConfig(level=logging.INFO)
test_mcp_operations()
main()

Loading…
Cancel
Save