Skip to content

Commit 018806c

Browse files
authored
Merge pull request #52 from universal-tool-calling-protocol/dev
Add docs and update http to 1.0.2
2 parents d28dc58 + e1b1fd9 commit 018806c

File tree

4 files changed

+9
-41
lines changed

4 files changed

+9
-41
lines changed

plugins/communication_protocols/http/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 = "utcp-http"
7-
version = "1.0.1"
7+
version = "1.0.2"
88
authors = [
99
{ name = "UTCP Contributors" },
1010
]

plugins/communication_protocols/http/src/utcp_http/http_communication_protocol.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,11 @@ async def call_tool(self, caller, tool_name: str, tool_args: Dict[str, Any], too
310310
timeout=aiohttp.ClientTimeout(total=30.0)
311311
) as response:
312312
response.raise_for_status()
313-
return await response.json()
313+
314+
content_type = response.headers.get('Content-Type', '').lower()
315+
if 'application/json' in content_type:
316+
return await response.json()
317+
return await response.text()
314318

315319
except aiohttp.ClientResponseError as e:
316320
logger.error(f"Error calling tool '{tool_name}' on call template '{tool_call_template.name}': {e}")

plugins/communication_protocols/http/src/utcp_http/sse_communication_protocol.py

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ class SseCommunicationProtocol(CommunicationProtocol):
3030

3131
def __init__(self, logger: Optional[Callable[[str], None]] = None):
3232
self._oauth_tokens: Dict[str, Dict[str, Any]] = {}
33-
self._active_connections: Dict[str, tuple[aiohttp.ClientResponse, aiohttp.ClientSession]] = {}
3433

3534
def _apply_auth(self, provider: SseCallTemplate, headers: Dict[str, str], query_params: Dict[str, Any]) -> tuple:
3635
"""Apply authentication to the request based on the provider's auth configuration.
@@ -148,13 +147,9 @@ async def register_manual(self, caller, manual_call_template: CallTemplate) -> R
148147

149148
async def deregister_manual(self, caller, manual_call_template: CallTemplate) -> None:
150149
"""REQUIRED
151-
Deregister an SSE manual and close any active connections."""
152-
template_name = manual_call_template.name
153-
if template_name in self._active_connections:
154-
response, session = self._active_connections.pop(template_name)
155-
response.close()
156-
await session.close()
157-
150+
Deregister an SSE manual."""
151+
pass
152+
158153
async def call_tool(self, caller, tool_name: str, tool_args: Dict[str, Any], tool_call_template: CallTemplate) -> Any:
159154
"""REQUIRED
160155
Execute a tool call through SSE transport."""
@@ -210,7 +205,6 @@ async def call_tool_streaming(self, caller, tool_name: str, tool_args: Dict[str,
210205
auth=auth, cookies=cookies, json=json_data, data=data, timeout=None
211206
)
212207
response.raise_for_status()
213-
self._active_connections[tool_call_template.name] = (response, session)
214208
async for event in self._process_sse_stream(response, tool_call_template.event_type):
215209
yield event
216210
except Exception as e:
@@ -300,15 +294,6 @@ async def _handle_oauth2(self, auth_details: OAuth2Auth) -> str:
300294
except aiohttp.ClientError as e:
301295
logger.error(f"OAuth2 with header failed: {e}")
302296
raise e
303-
304-
async def close(self):
305-
"""Closes all active connections and sessions."""
306-
for provider_name in list(self._active_connections.keys()):
307-
if provider_name in self._active_connections:
308-
response, session = self._active_connections.pop(provider_name)
309-
response.close()
310-
await session.close()
311-
self._active_connections.clear()
312297

313298
def _build_url_with_path_params(self, url_template: str, tool_args: Dict[str, Any]) -> str:
314299
"""Build URL by substituting path parameters from arguments.

plugins/communication_protocols/http/tests/test_sse_communication_protocol.py

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ async def sse_transport():
112112
"""Fixture to create and properly tear down an SseCommunicationProtocol instance."""
113113
transport = SseCommunicationProtocol()
114114
yield transport
115-
await transport.close()
116115

117116
@pytest.fixture
118117
def app():
@@ -273,26 +272,6 @@ async def test_call_tool_error(sse_transport, aiohttp_client, app):
273272

274273
assert excinfo.value.status == 500
275274

276-
@pytest.mark.asyncio
277-
async def test_deregister_manual(sse_transport, aiohttp_client, app):
278-
"""Test deregistering a manual closes the connection."""
279-
client = await aiohttp_client(app)
280-
call_template = SseCallTemplate(name="test-deregister", url=f"{client.make_url('/events')}")
281-
282-
# Make a call to establish a connection
283-
stream_iterator = sse_transport.call_tool_streaming(None, "test_tool", {}, call_template)
284-
await anext(stream_iterator)
285-
assert call_template.name in sse_transport._active_connections
286-
response, session = sse_transport._active_connections[call_template.name]
287-
288-
# Deregister
289-
await sse_transport.deregister_manual(None, call_template)
290-
291-
# Verify connection and session are closed and removed
292-
assert call_template.name not in sse_transport._active_connections
293-
assert response.closed
294-
assert session.closed
295-
296275
@pytest.mark.asyncio
297276
async def test_call_tool_basic_nonstream(sse_transport, aiohttp_client, app):
298277
"""Non-streaming call should aggregate SSE events into a list (basic)."""

0 commit comments

Comments
 (0)