updated example

pull/819/head
Pavan Kumar 3 months ago committed by ascender1729
parent 51bb308c45
commit e8912f3c83

@ -0,0 +1,59 @@
=== MINIMAL MCP AGENT INTEGRATION TEST ===
Agent created successfully!
Enter a math query or 'exit' to quit
Math query: add 2 and 2
Processing: add 2 and 2
╭────────────────── Agent Name MCP Test Agent [Max Loops: 1 ] ───────────────────╮
│ MCP Test Agent: {"tool_name": "add", "a": 2, "b": 2} │
╰────────────────────────────────────────────────────────────────────────────────╯
2025-04-21T06:57:50.226670+0000 | ERROR | Error initializing MCP server: unhandled errors in a TaskGroup (1 sub-exception)
2025-04-21T06:57:50.226857+0000 | ERROR | Error in abatch_mcp_flow: unhandled errors in a TaskGroup (1 sub-exception)
╭────────── Agent Name MCP Test Agent - Tool Executor [Max Loops: 1 ] ───────────╮
│ MCP Test Agent - Tool Executor: Error in batch operation: unhandled errors in │
│ a TaskGroup (1 sub-exception) │
╰────────────────────────────────────────────────────────────────────────────────╯
╭────────── Agent Name MCP Test Agent - Agent Analysis [Max Loops: 1 ] ──────────╮
│ MCP Test Agent - Agent Analysis: {"tool_name": "add", "a": 1, "b": 1} │
╰────────────────────────────────────────────────────────────────────────────────╯
Result: System: : Your Name: MCP Test Agent
Your Description: None
You are a math calculator assistant.
When asked for calculations:
1. Determine the operation (add, multiply, or divide)
2. Extract the numbers
3. Return the JSON format of the calculation
For example:
- For "add 5 and 3", respond with: {"tool_name": "add", "a": 5, "b": 3}
- For "multiply 7 by 4", respond with: {"tool_name": "multiply", "a": 7, "b": 4}
- For "divide 10 by 2", respond with: {"tool_name": "divide", "a": 10, "b": 2}
When asked about your capabilities, respond with: {"tool_name": "add", "a": 1, "b": 1}
Human:: add 2 and 2
MCP Test Agent: {"tool_name": "add", "a": 2, "b": 2}
assistant: Tool execution result: ['Error in batch operation: unhandled errors in a TaskGroup (1 sub-exception)']
Tool Executor: Error in batch operation: unhandled errors in a TaskGroup (1 sub-exception)
MCP Test Agent: {"tool_name": "add", "a": 1, "b": 1}
Math query:

@ -0,0 +1,59 @@
=== MINIMAL MCP AGENT INTEGRATION TEST ===
Agent created successfully!
Enter a math query or 'exit' to quit
Math query: add 2 and 2
Processing: add 2 and 2
╭────────────────── Agent Name MCP Test Agent [Max Loops: 1 ] ───────────────────╮
│ MCP Test Agent: {"tool_name": "add", "a": 2, "b": 2} │
╰────────────────────────────────────────────────────────────────────────────────╯
2025-04-21T06:57:50.226670+0000 | ERROR | Error initializing MCP server: unhandled errors in a TaskGroup (1 sub-exception)
2025-04-21T06:57:50.226857+0000 | ERROR | Error in abatch_mcp_flow: unhandled errors in a TaskGroup (1 sub-exception)
╭────────── Agent Name MCP Test Agent - Tool Executor [Max Loops: 1 ] ───────────╮
│ MCP Test Agent - Tool Executor: Error in batch operation: unhandled errors in │
│ a TaskGroup (1 sub-exception) │
╰────────────────────────────────────────────────────────────────────────────────╯
╭────────── Agent Name MCP Test Agent - Agent Analysis [Max Loops: 1 ] ──────────╮
│ MCP Test Agent - Agent Analysis: {"tool_name": "add", "a": 1, "b": 1} │
╰────────────────────────────────────────────────────────────────────────────────╯
Result: System: : Your Name: MCP Test Agent
Your Description: None
You are a math calculator assistant.
When asked for calculations:
1. Determine the operation (add, multiply, or divide)
2. Extract the numbers
3. Return the JSON format of the calculation
For example:
- For "add 5 and 3", respond with: {"tool_name": "add", "a": 5, "b": 3}
- For "multiply 7 by 4", respond with: {"tool_name": "multiply", "a": 7, "b": 4}
- For "divide 10 by 2", respond with: {"tool_name": "divide", "a": 10, "b": 2}
When asked about your capabilities, respond with: {"tool_name": "add", "a": 1, "b": 1}
Human:: add 2 and 2
MCP Test Agent: {"tool_name": "add", "a": 2, "b": 2}
assistant: Tool execution result: ['Error in batch operation: unhandled errors in a TaskGroup (1 sub-exception)']
Tool Executor: Error in batch operation: unhandled errors in a TaskGroup (1 sub-exception)
MCP Test Agent: {"tool_name": "add", "a": 1, "b": 1}
Math query:

@ -0,0 +1,59 @@
=== MINIMAL MCP AGENT INTEGRATION TEST ===
Agent created successfully!
Enter a math query or 'exit' to quit
Math query: add 2 and 3
Processing: add 2 and 3
╭────────────────── Agent Name MCP Test Agent [Max Loops: 1 ] ───────────────────╮
│ MCP Test Agent: {"tool_name": "add", "a": 2, "b": 3} │
╰────────────────────────────────────────────────────────────────────────────────╯
2025-04-21T07:36:01.678279+0000 | ERROR | Error initializing MCP server: unhandled errors in a TaskGroup (1 sub-exception)
2025-04-21T07:36:01.678457+0000 | ERROR | Error in abatch_mcp_flow: unhandled errors in a TaskGroup (1 sub-exception)
╭────────── Agent Name MCP Test Agent - Tool Executor [Max Loops: 1 ] ───────────╮
│ MCP Test Agent - Tool Executor: Error in batch operation: unhandled errors in │
│ a TaskGroup (1 sub-exception) │
╰────────────────────────────────────────────────────────────────────────────────╯
╭────────── Agent Name MCP Test Agent - Agent Analysis [Max Loops: 1 ] ──────────╮
│ MCP Test Agent - Agent Analysis: {"tool_name": "add", "a": 1, "b": 1} │
╰────────────────────────────────────────────────────────────────────────────────╯
Result: System: : Your Name: MCP Test Agent
Your Description: None
You are a math calculator assistant.
When asked for calculations:
1. Determine the operation (add, multiply, or divide)
2. Extract the numbers
3. Return the JSON format of the calculation
For example:
- For "add 5 and 3", respond with: {"tool_name": "add", "a": 5, "b": 3}
- For "multiply 7 by 4", respond with: {"tool_name": "multiply", "a": 7, "b": 4}
- For "divide 10 by 2", respond with: {"tool_name": "divide", "a": 10, "b": 2}
When asked about your capabilities, respond with: {"tool_name": "add", "a": 1, "b": 1}
Human:: add 2 and 3
MCP Test Agent: {"tool_name": "add", "a": 2, "b": 3}
assistant: Tool execution result: ['Error in batch operation: unhandled errors in a TaskGroup (1 sub-exception)']
Tool Executor: Error in batch operation: unhandled errors in a TaskGroup (1 sub-exception)
MCP Test Agent: {"tool_name": "add", "a": 1, "b": 1}
Math query:

@ -1,57 +1,38 @@
from swarms import Agent
from swarms.tools.mcp_integration import MCPServerSseParams
from loguru import logger
import sys
from swarms.prompts.agent_prompts import MATH_PROMPT
# Configure logging
logger.remove()
logger.add(sys.stdout,
level="INFO",
format="{time} | {level} | {module}:{function}:{line} - {message}")
logger.add(sys.stdout, level="INFO", format="{time} | {level} | {message}")
# Math prompt for testing MCP integration
MATH_PROMPT = """
You are a math calculator assistant that uses tools to perform calculations.
When asked for calculations, determine the operation and numbers, then use one of these tools:
- add: Add two numbers
- multiply: Multiply two numbers
- divide: Divide first number by second
FORMAT as JSON:
{"tool_name": "add", "a": 5, "b": 10}
"""
def main():
"""Main function to test MCP integration with Agent."""
"""Test MCP integration with Agent."""
print("=== MINIMAL MCP AGENT INTEGRATION TEST ===")
print("Testing only the core MCP integration with Agent")
try:
# Create the server parameters correctly
logger.info("Creating MCP server parameters...")
mcp_server = MCPServerSseParams(
url="http://0.0.0.0:8000",
headers={
# Create the MCP server parameters as a dictionary
mcp_server = {
"url": "http://0.0.0.0:8000",
"headers": {
"Content-Type": "application/json",
"Accept": "text/event-stream"
},
timeout=10.0,
sse_read_timeout=30.0
)
# Log the server params to verify they're correct
logger.info(f"MCP Server URL: {mcp_server.url}")
logger.info("MCP Headers configured")
"timeout": 10.0,
"sse_read_timeout": 30.0
}
# Create agent with minimal configuration
logger.info("Creating Agent with MCP integration...")
agent = Agent(
agent_name="MCP Test Agent",
system_prompt=MATH_PROMPT,
mcp_servers=[mcp_server], # Pass server params object
verbose=True)
mcp_servers=[mcp_server], # Pass as a list of dictionaries
model_name="gpt-4o-mini",
verbose=False # Reduce verbosity to focus on errors
)
print("\nAgent created successfully!")
print("Enter a math query or 'exit' to quit")
@ -62,16 +43,17 @@ def main():
if query.lower() == 'exit':
break
# Run the agent, which should use the MCP server
logger.info(f"Processing query: {query}")
# Run the agent
print(f"\nProcessing: {query}")
result = agent.run(query)
# Display result
print(f"\nResult: {result}")
except Exception as e:
logger.error(f"Error during MCP integration test: {e}", exc_info=True)
print(f"\nERROR: {type(e).__name__}: {str(e)}")
logger.error(f"Error: {str(e)}")
import traceback
traceback.print_exc()
if __name__ == "__main__":

@ -1,24 +1,19 @@
# Agent prompts for MCP testing and interactions
MATH_AGENT_PROMPT = """
You are a helpful math calculator assistant.
Your role is to understand natural language math requests and perform calculations.
When asked to perform calculations:
MATH_PROMPT = """
You are a math calculator assistant.
When asked for calculations:
1. Determine the operation (add, multiply, or divide)
2. Extract the numbers from the request
3. Call the appropriate operation
You can use these tools:
- add: Add two numbers together
- multiply: Multiply two numbers together
- divide: Divide the first number by the second number
2. Extract the numbers
3. Return the JSON format of the calculation
If the user asks for a list of available tools or functions, tell them about the above operations.
For example:
- For "add 5 and 3", respond with: {"tool_name": "add", "a": 5, "b": 3}
- For "multiply 7 by 4", respond with: {"tool_name": "multiply", "a": 7, "b": 4}
- For "divide 10 by 2", respond with: {"tool_name": "divide", "a": 10, "b": 2}
Just tell me which operation to perform and what numbers to use in natural language.
No need for strict JSON formatting - I'll handle the tool calling for you.
When asked about your capabilities, respond with: {"tool_name": "add", "a": 1, "b": 1}
"""
FINANCE_AGENT_PROMPT = """You are a financial analysis agent with access to stock market data services.
Key responsibilities:

Loading…
Cancel
Save