Skip to content

Conversation

alimoradi296
Copy link

@alimoradi296 alimoradi296 commented Jul 27, 2025

Implements comprehensive WebSocket transport following UTCP architecture with reviewer feedback addressed.

Core Features

  • Real-time bidirectional communication via WebSocket protocol
  • Tool discovery through WebSocket handshake using UTCP messages
  • Streaming tool execution with proper error handling
  • Connection management with keep-alive and reconnection support

Architecture Compliance

  • Dependency injection pattern with constructor injection
  • Implements ClientTransportInterface contract
  • Composition over inheritance design
  • Clear separation of data and business logic
  • Thread-safe and scalable implementation

Authentication & Security

  • Full authentication support (API Key, Basic Auth, OAuth2)
  • Security enforcement (WSS required, localhost exception)
  • Custom headers and protocol specification support

Reviewer Feedback Addressed

  • Individual tool providers: Each tool now gets its own WebSocketProvider instance instead of sharing the manual provider
  • Flexible message format: Added message_format field for custom WebSocket message formatting to support existing services
    without modification
  • New branch: Created feature/websockets branch as requested by @h3xxit

Testing & Quality

  • Unit tests covering all functionality (80%+ coverage)
  • Mock WebSocket server for development/testing
  • Integration with existing UTCP test patterns
  • Comprehensive error handling and edge cases

Protocol Implementation

  • Discovery: {"type": "discover", "request_id": "id"}
  • Tool calls: {"type": "call_tool", "tool_name": "name", "arguments": {...}}
  • Responses: {"type": "tool_response|tool_error", "result": {...}}
  • Custom formats supported via message_format template

Documentation

  • Complete example with interactive client/server demo
  • Updated README removing "work in progress" status
  • Protocol specification and usage examples

Addresses the "No wrapper tax" principle by enabling direct WebSocket communication without requiring changes to existing
WebSocket services. Maintains "No security tax" with full authentication support and secure connection enforcement.

Replaces PR #33 with the requested feature/websockets branch.
updates:
- ✅ Resolved merge conflicts with upstream/dev

  • ✅ Aligned WebSocket implementation with official UDP pattern
  • ✅ Maintained backward compatibility while adding new features
  • ✅ All tests passing (WebSocket, TCP, UDP)

alimoradi296 and others added 2 commits July 27, 2025 15:54
Implements comprehensive WebSocket transport following UTCP architecture:

## Core Features
- Real-time bidirectional communication via WebSocket protocol
- Tool discovery through WebSocket handshake using UTCP messages
- Streaming tool execution with proper error handling
- Connection management with keep-alive and reconnection support

## Architecture Compliance
- Dependency injection pattern with constructor injection
- Implements ClientTransportInterface contract
- Composition over inheritance design
- Clear separation of data and business logic
- Thread-safe and scalable implementation

## Authentication & Security
- Full authentication support (API Key, Basic Auth, OAuth2)
- Security enforcement (WSS required, localhost exception)
- Custom headers and protocol specification support

## Testing & Quality
- Unit tests covering all functionality (80%+ coverage)
- Mock WebSocket server for development/testing
- Integration with existing UTCP test patterns
- Comprehensive error handling and edge cases

## Protocol Implementation
- Discovery: {"type": "discover", "request_id": "id"}
- Tool calls: {"type": "call_tool", "tool_name": "name", "arguments": {...}}
- Responses: {"type": "tool_response|tool_error", "result": {...}}

## Documentation
- Complete example with interactive client/server demo
- Updated README removing "work in progress" status
- Protocol specification and usage examples

Addresses the "No wrapper tax" principle by enabling direct WebSocket
communication without requiring changes to existing WebSocket services.
Maintains "No security tax" with full authentication support and secure
connection enforcement.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
…ormat

- Each tool now gets its own WebSocketProvider instance (addresses h3xxit feedback)
- Added message_format field for custom WebSocket message formatting
- Maintains backward compatibility with default UTCP format
- Allows integration with existing WebSocket services without modification

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@h3xxit
Copy link
Member

h3xxit commented Jul 30, 2025

@alimoradi296 Hey, I'm back. I have now implemented the official version for UDP. Check it out on the dev branch, and make sure to follow the same logic for the data types and processing. Remember, the goal is to support as many websocket implementations as possible without the tools needing to change anything.
Once you're happy with it, tag me and I'll look through the code again. Thank you for your patience!!!

This commit resolves merge conflicts between the WebSocket feature branch and the
upstream dev branch, while aligning the WebSocket transport implementation with
the official UDP implementation patterns for consistency and compatibility.

Key changes:
- Resolved merge conflicts in utcp_client.py by combining WebSocket, TCP, and UDP transport imports
- Updated WebSocketProvider to follow UDP pattern with request_data_format, request_data_template, and timeout fields
- Enhanced WebSocket transport with UDP-style message formatting (_format_tool_call_message method)
- Added support for both JSON and text-based request formats with template substitution
- Updated discovery protocol to match UDP pattern ({"type": "utcp"} instead of custom format)
- Improved error handling and logging to be consistent with UDP transport
- Maintained backward compatibility with existing message_format field for maximum flexibility
- Added comprehensive support for UTCP_ARG_argname_UTCP_ARG placeholder substitution

The implementation now supports as many WebSocket implementations as possible without
requiring changes to existing tools, following the "No wrapper tax" principle while
maintaining the "No security tax" with full authentication support.

All existing tests pass, demonstrating compatibility with the updated architecture.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@alimoradi296
Copy link
Author

@h3xxit I've successfully merged the upstream/dev branch and aligned the WebSocket implementation with the official UDP patterns
as requested. Key updates:

  • ✅ Resolved all merge conflicts
  • ✅ Added request_data_format, request_data_template, and timeout fields to WebSocketProvider following UDP pattern
  • ✅ Updated discovery protocol to use {"type": "utcp"} format like UDP
  • ✅ Enhanced message formatting with UTCP_ARG_argname_UTCP_ARG placeholder support
  • ✅ Maintained backward compatibility with existing message_format field
  • ✅ All tests passing (WebSocket: 8 passed, UDP: 23 passed, TCP: 29 passed)

The implementation now supports as many WebSocket services as possible without requiring changes, following the "No wrapper tax"
principle while maintaining data types and processing logic consistent with the official transports.

Ready for review!

Copy link
Member

@h3xxit h3xxit left a comment

Choose a reason for hiding this comment

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

Looks pretty good. There only 2 small misconceptions to fix, and we're good to go

Comment on lines 253 to 265
tool_provider = WebSocketProvider(
name=f"{manual_provider.name}_{tool_data['name']}",
url=tool_data.get("url", manual_provider.url),
protocol=tool_data.get("protocol", manual_provider.protocol),
keep_alive=tool_data.get("keep_alive", manual_provider.keep_alive),
request_data_format=tool_data.get("request_data_format", manual_provider.request_data_format),
request_data_template=tool_data.get("request_data_template", manual_provider.request_data_template),
message_format=tool_data.get("message_format", manual_provider.message_format),
timeout=tool_data.get("timeout", manual_provider.timeout),
auth=tool_data.get("auth", manual_provider.auth),
headers=tool_data.get("headers", manual_provider.headers),
header_fields=tool_data.get("header_fields", manual_provider.header_fields)
)
Copy link
Member

Choose a reason for hiding this comment

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

This is not correct. Tools should come with a tool_provider themselves. There should not be any need to create providers yourself.

async for msg in ws:
if msg.type == aiohttp.WSMsgType.TEXT:
try:
response_data = json.loads(msg.data)
Copy link
Member

Choose a reason for hiding this comment

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

Response data for a /utcp endpoint NEEDS to be a UtcpManual.

- Tools now come with their own tool_provider instead of manually creating providers
- Response data for /utcp endpoint properly parsed as UtcpManual
- Maintains backward compatibility while following official UDP patterns
- All tests passing (145 passed, 1 skipped)

Addresses @h3xxit's review comments on PR universal-tool-calling-protocol#36

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@alimoradi296
Copy link
Author

Looks pretty good. There only 2 small misconceptions to fix, and we're good to go

@h3xxit I've addressed both review issues:

Fixed tool provider creation: Tools now come with their own tool_provider instead of manually creating WebSocketProvider
instances (line 255 now uses Tool(**tool_data) like UDP transport)

Fixed response data handling: /utcp endpoint response now properly parsed as UtcpManual object with fallback for
backward compatibility

The WebSocket implementation now follows the same patterns as the official UDP transport while maintaining all existing
functionality. All tests still passing (145 passed, 1 skipped).

Ready for re-review!

@alimoradi296 alimoradi296 requested a review from h3xxit August 14, 2025 09:30
@h3xxit
Copy link
Member

h3xxit commented Aug 19, 2025

Alright, good news. Finally UTCP 1.0.0 has been released. From now on UTCP should not have that many big breaking changes. Now I would request one final update to matche the new structure and new plugin system. If you have any questions or I can help with anything let me know. Also on the discord you can find people to help you with this!

Copy link
Member

@h3xxit h3xxit left a comment

Choose a reason for hiding this comment

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

Update to 1.0.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants