Skip to content

Commit a2bec46

Browse files
committed
Increment version to 0.0.84 in pyproject.toml and uv.lock, update agent functionality in mcp-sse.py and openai-mcp.py for improved task handling, and enhance timeout management in MCP tools for better performance.
1 parent 3468c90 commit a2bec46

7 files changed

Lines changed: 25 additions & 22 deletions

File tree

src/praisonai-agents/mcp-sse.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
from praisonaiagents import Agent, MCP
22

3-
qa_agent = Agent(
4-
instructions="""You are a Question Answering Agent.""",
5-
llm="openai/gpt-4o-mini",
6-
tools=MCP("http://localhost:8080/agents/sse")
3+
tweet_agent = Agent(
4+
instructions="""You are a Tweet Formatter Agent.""",
5+
tools=MCP("http://localhost:8080/sse")
76
)
87

9-
qa_agent.start("AI in 2025")
8+
tweet_agent.start("AI in Healthcare")

src/praisonai-agents/openai-mcp.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
search_agent = Agent(
44
instructions="""You help book apartments on Airbnb.""",
5-
llm="openai/gpt-4o-mini",
65
tools=MCP("npx -y @openbnb/mcp-server-airbnb --ignore-robots-txt")
76
)
87

9-
search_agent.start("I want to book an apartment in Paris for 2 nights. 03/28 - 03/30 for 2 adults")
8+
search_agent.start("Search apartment in Paris for 2 nights. 07/28 - 07/30 for 2 adults")

src/praisonai-agents/praisonaiagents/mcp/mcp.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@
1616
class MCPToolRunner(threading.Thread):
1717
"""A dedicated thread for running MCP operations."""
1818

19-
def __init__(self, server_params):
19+
def __init__(self, server_params, timeout=60):
2020
super().__init__(daemon=True)
2121
self.server_params = server_params
2222
self.queue = queue.Queue()
2323
self.result_queue = queue.Queue()
2424
self.initialized = threading.Event()
2525
self.tools = []
26+
self.timeout = timeout
2627
self.start()
2728

2829
def run(self):
@@ -74,9 +75,9 @@ async def _run_async(self):
7475
def call_tool(self, tool_name, arguments):
7576
"""Call an MCP tool and wait for the result."""
7677
if not self.initialized.is_set():
77-
self.initialized.wait(timeout=30)
78+
self.initialized.wait(timeout=self.timeout)
7879
if not self.initialized.is_set():
79-
return "Error: MCP initialization timed out"
80+
return f"Error: MCP initialization timed out after {self.timeout} seconds"
8081

8182
# Put request in queue
8283
self.queue.put((tool_name, arguments))
@@ -189,7 +190,7 @@ def __init__(self, command_or_string=None, args=None, *, command=None, timeout=6
189190
if isinstance(command_or_string, str) and re.match(r'^https?://', command_or_string):
190191
# Import the SSE client implementation
191192
from .mcp_sse import SSEMCPClient
192-
self.sse_client = SSEMCPClient(command_or_string, debug=debug)
193+
self.sse_client = SSEMCPClient(command_or_string, debug=debug, timeout=timeout)
193194
self._tools = list(self.sse_client.tools)
194195
self.is_sse = True
195196
self.is_npx = False
@@ -216,11 +217,11 @@ def __init__(self, command_or_string=None, args=None, *, command=None, timeout=6
216217
args=arguments,
217218
**kwargs
218219
)
219-
self.runner = MCPToolRunner(self.server_params)
220+
self.runner = MCPToolRunner(self.server_params, timeout)
220221

221222
# Wait for initialization
222-
if not self.runner.initialized.wait(timeout=30):
223-
print("Warning: MCP initialization timed out")
223+
if not self.runner.initialized.wait(timeout=self.timeout):
224+
print(f"Warning: MCP initialization timed out after {self.timeout} seconds")
224225

225226
# Automatically detect if this is an NPX command
226227
self.is_npx = cmd == 'npx' or (isinstance(cmd, str) and os.path.basename(cmd) == 'npx')

src/praisonai-agents/praisonaiagents/mcp/mcp_sse.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,15 @@ def get_event_loop():
3131
class SSEMCPTool:
3232
"""A wrapper for an MCP tool that can be used with praisonaiagents."""
3333

34-
def __init__(self, name: str, description: str, session: ClientSession, input_schema: Optional[Dict[str, Any]] = None):
34+
def __init__(self, name: str, description: str, session: ClientSession, input_schema: Optional[Dict[str, Any]] = None, timeout: int = 60):
3535
self.name = name
3636
self.__name__ = name # Required for Agent to recognize it as a tool
3737
self.__qualname__ = name # Required for Agent to recognize it as a tool
3838
self.__doc__ = description # Required for Agent to recognize it as a tool
3939
self.description = description
4040
self.session = session
4141
self.input_schema = input_schema or {}
42+
self.timeout = timeout
4243

4344
# Create a signature based on input schema
4445
params = []
@@ -66,7 +67,7 @@ def __call__(self, **kwargs):
6667
future = asyncio.run_coroutine_threadsafe(self._async_call(**kwargs), loop)
6768
try:
6869
# Wait for the result with a timeout
69-
return future.result(timeout=30)
70+
return future.result(timeout=self.timeout)
7071
except Exception as e:
7172
logger.error(f"Error calling tool {self.name}: {e}")
7273
return f"Error: {str(e)}"
@@ -102,16 +103,18 @@ def to_openai_tool(self):
102103
class SSEMCPClient:
103104
"""A client for connecting to an MCP server over SSE."""
104105

105-
def __init__(self, server_url: str, debug: bool = False):
106+
def __init__(self, server_url: str, debug: bool = False, timeout: int = 60):
106107
"""
107108
Initialize an SSE MCP client.
108109
109110
Args:
110111
server_url: The URL of the SSE MCP server
111112
debug: Whether to enable debug logging
113+
timeout: Timeout in seconds for operations (default: 60)
112114
"""
113115
self.server_url = server_url
114116
self.debug = debug
117+
self.timeout = timeout
115118
self.session = None
116119
self.tools = []
117120

@@ -139,7 +142,7 @@ def run_event_loop():
139142

140143
# Run the initialization in the event loop
141144
future = asyncio.run_coroutine_threadsafe(self._async_initialize(), loop)
142-
self.tools = future.result(timeout=30)
145+
self.tools = future.result(timeout=self.timeout)
143146

144147
async def _async_initialize(self):
145148
"""Asynchronously initialize the connection and tools."""
@@ -169,7 +172,8 @@ async def _async_initialize(self):
169172
name=tool.name,
170173
description=tool.description if hasattr(tool, 'description') else f"Call the {tool.name} tool",
171174
session=self.session,
172-
input_schema=input_schema
175+
input_schema=input_schema,
176+
timeout=self.timeout
173177
)
174178
tools.append(wrapper)
175179

src/praisonai-agents/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "praisonaiagents"
7-
version = "0.0.83"
7+
version = "0.0.84"
88
description = "Praison AI agents for completing complex tasks with Self Reflection Agents"
99
authors = [
1010
{ name="Mervin Praison" }
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
from praisonaiagents import Agent
22

3-
agent = Agent(name="TweetAgent", instructions="Create a Tweet based on the topic provided")
3+
agent = Agent(instructions="Create a Tweet")
44
agent.launch(port=8080, protocol="mcp")

src/praisonai-agents/uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)