Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/praisonai-agents/praisonaiagents/agent/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -934,7 +934,12 @@ def _format_tools_for_completion(self, tools=None):
logging.warning(f"Could not generate definition for tool: {tool}")
# Handle objects with to_openai_tool method (MCP tools)
elif hasattr(tool, "to_openai_tool"):
formatted_tools.append(tool.to_openai_tool())
openai_tools = tool.to_openai_tool()
# MCP tools can return either a single tool or a list of tools
if isinstance(openai_tools, list):
formatted_tools.extend(openai_tools)
elif openai_tools is not None:
formatted_tools.append(openai_tools)
# Handle callable functions
elif callable(tool):
tool_def = self._generate_tool_definition(tool.__name__)
Expand Down
50 changes: 50 additions & 0 deletions test_mcp_fix.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/usr/bin/env python3
"""Test script to verify MCP schema fix"""

import os
import sys

# Add the src directory to Python path
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'src', 'praisonai-agents'))
Comment on lines +7 to +8
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Modifying sys.path is generally discouraged as it can create fragile tests and obscure import dependencies. Consider structuring your project as an installable package and using pip install -e . for development.[^1]


from dotenv import load_dotenv
from praisonaiagents import Agent, MCP

# Load .env before importing anything else
load_dotenv()

# Define allowed directories for filesystem access
allowed_dirs = [
"/Users/praison/praisonai-package/src/praisonai-agents",
]

# Test with minimal example
print("Testing MCP filesystem agent...")

try:
# Use the correct pattern from filesystem MCP documentation
filesystem_agent = Agent(
instructions="""You are a helpful assistant that can interact with the filesystem.
Use the available tools when relevant to manage files and directories.""",
llm="gpt-4o-mini",
tools=MCP(
command="npx",
args=["-y", "@modelcontextprotocol/server-filesystem"] + allowed_dirs
)
)

print("✓ Agent created successfully")
print("✓ MCP tools loaded without schema errors")

# Try to start the agent (this will validate the tool schemas)
result = filesystem_agent.start("List files in /Users/praison/praisonai-package/src/praisonai-agents directory using MCP list_files")
print("✓ Agent executed successfully")
print(f"Result: {result}")

except Exception as e:
print(f"✗ Error: {e}")
import traceback
traceback.print_exc()
sys.exit(1)

print("\nTest passed! The MCP schema fix is working correctly.")
Comment on lines +24 to +50
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

This test script uses hardcoded paths and print statements for validation, impacting portability and maintainability. Refactor to use pytest for portability, automated test discovery, and proper assertions.[^1]

Loading