Skip to content
Closed
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
20 changes: 3 additions & 17 deletions src/praisonai-agents/praisonaiagents/mcp/mcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,8 @@
from typing import Any, List, Optional, Callable, Iterable, Union
from functools import wraps, partial

try:
from mcp import ClientSession, StdioServerParameters
from mcp.client.stdio import stdio_client
MCP_AVAILABLE = True
except ImportError:
MCP_AVAILABLE = False
ClientSession = None
StdioServerParameters = None
stdio_client = None
from mcp import ClientSession, StdioServerParameters
from mcp.client.stdio import stdio_client

class MCPToolRunner(threading.Thread):
"""A dedicated thread for running MCP operations."""
Expand Down Expand Up @@ -203,17 +196,10 @@ def __init__(self, command_or_string=None, args=None, *, command=None, timeout=6
debug: Enable debug logging for MCP operations (default: False)
**kwargs: Additional parameters for StdioServerParameters
"""
# Check if MCP is available
if not MCP_AVAILABLE:
raise ImportError(
"MCP (Model Context Protocol) package is not installed. "
"Install it with: pip install praisonaiagents[mcp]"
)

# Handle backward compatibility with named parameter 'command'
if command_or_string is None and command is not None:
command_or_string = command

# Set up logging - default to WARNING level to hide INFO messages
if debug:
logging.getLogger("mcp-wrapper").setLevel(logging.DEBUG)
Expand Down
26 changes: 3 additions & 23 deletions src/praisonai-agents/praisonaiagents/mcp/mcp_http_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,11 @@
from typing import List, Dict, Any, Optional, Callable, Iterable, Union
from urllib.parse import urlparse, urljoin

try:
from mcp import ClientSession
MCP_AVAILABLE = True
except ImportError:
MCP_AVAILABLE = False
ClientSession = None

from mcp import ClientSession
try:
import aiohttp
except ImportError:
aiohttp = None
raise ImportError("aiohttp is required for HTTP Stream transport. Install with: pip install praisonaiagents[mcp]")

logger = logging.getLogger("mcp-http-stream")

Expand Down Expand Up @@ -513,23 +507,9 @@ def __init__(self, server_url: str, debug: bool = False, timeout: int = 60, opti
timeout: Timeout in seconds for operations (default: 60)
options: Additional configuration options for the transport
"""
# Check if MCP is available
if not MCP_AVAILABLE:
raise ImportError(
"MCP (Model Context Protocol) package is not installed. "
"Install it with: pip install praisonaiagents[mcp]"
)

# Check if aiohttp is available
if aiohttp is None:
raise ImportError(
"aiohttp is required for HTTP Stream transport. "
"Install it with: pip install praisonaiagents[mcp]"
)

# Parse URL to extract base URL and endpoint
parsed = urlparse(server_url)

# If the URL already has a path, use it; otherwise use default /mcp endpoint
if parsed.path and parsed.path != '/':
self.base_url = server_url
Expand Down
19 changes: 3 additions & 16 deletions src/praisonai-agents/praisonaiagents/mcp/mcp_sse.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,8 @@
import json
from typing import List, Dict, Any, Optional, Callable, Iterable

try:
from mcp import ClientSession
from mcp.client.sse import sse_client
MCP_AVAILABLE = True
except ImportError:
MCP_AVAILABLE = False
ClientSession = None
sse_client = None
from mcp import ClientSession
from mcp.client.sse import sse_client

logger = logging.getLogger("mcp-sse")

Expand Down Expand Up @@ -175,19 +169,12 @@ def __init__(self, server_url: str, debug: bool = False, timeout: int = 60):
debug: Whether to enable debug logging
timeout: Timeout in seconds for operations (default: 60)
"""
# Check if MCP is available
if not MCP_AVAILABLE:
raise ImportError(
"MCP (Model Context Protocol) package is not installed. "
"Install it with: pip install praisonaiagents[mcp]"
)

self.server_url = server_url
self.debug = debug
self.timeout = timeout
self.session = None
self.tools = []

# Set up logging
if debug:
logger.setLevel(logging.DEBUG)
Expand Down
71 changes: 0 additions & 71 deletions src/praisonai-agents/tests/test_mcp_optional_import.py

This file was deleted.

Loading