Skip to content

Commit 4432b15

Browse files
Thuraabtechh3xxitSalman Mohammed
authored
updated socket protocol implementation to be compatible with 1.0v (#72)
* socket protocol updated to be compatible with 1.0v utcp * cubic fixes done * pinned mcp-use to use langchain 0.3.27 * removed mcp denpendency on langchain * adding the langchain dependency for testing (temporary) * remove langchain-core pin to resolve dependency conflict --------- Co-authored-by: Razvan Radulescu <43811028+h3xxit@users.noreply.github.com> Co-authored-by: Salman Mohammed <thuraabtec@gmail.com>
1 parent d120862 commit 4432b15

File tree

13 files changed

+952
-198
lines changed

13 files changed

+952
-198
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,11 @@ jobs:
3131
pip install -e plugins/communication_protocols/http[dev]
3232
pip install -e plugins/communication_protocols/mcp[dev]
3333
pip install -e plugins/communication_protocols/text[dev]
34+
pip install -e plugins/communication_protocols/socket[dev]
3435
3536
- name: Run tests with pytest
3637
run: |
37-
pytest core/tests/ plugins/communication_protocols/cli/tests/ plugins/communication_protocols/http/tests/ plugins/communication_protocols/mcp/tests/ plugins/communication_protocols/text/tests/ --doctest-modules --junitxml=junit/test-results.xml --cov=core/src/utcp --cov-report=xml --cov-report=html
38+
pytest core/tests/ plugins/communication_protocols/cli/tests/ plugins/communication_protocols/http/tests/ plugins/communication_protocols/mcp/tests/ plugins/communication_protocols/text/tests/ plugins/communication_protocols/socket/tests/ --doctest-modules --junitxml=junit/test-results.xml --cov=core/src/utcp --cov-report=xml --cov-report=html
3839
3940
- name: Upload coverage reports to Codecov
4041
uses: codecov/codecov-action@v3

plugins/communication_protocols/mcp/pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ dependencies = [
1515
"pydantic>=2.0",
1616
"mcp>=1.12",
1717
"utcp>=1.0",
18-
"mcp-use>=1.3"
18+
"mcp-use>=1.3",
19+
"langchain==0.3.27",
1920
]
2021
classifiers = [
2122
"Development Status :: 4 - Beta",
Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,44 @@
1-
Find the UTCP readme at https://github.com/universal-tool-calling-protocol/python-utcp.
1+
# UTCP Socket Plugin (UDP/TCP)
2+
3+
This plugin adds UDP and TCP communication protocols to UTCP 1.0.
4+
5+
## Running Tests
6+
7+
Prerequisites:
8+
- Python 3.10+
9+
- `pip`
10+
- (Optional) a virtual environment
11+
12+
1) Install core and the socket plugin in editable mode with dev extras:
13+
14+
```bash
15+
pip install -e "core[dev]"
16+
pip install -e plugins/communication_protocols/socket[dev]
17+
```
18+
19+
2) Run the socket plugin tests:
20+
21+
```bash
22+
python -m pytest plugins/communication_protocols/socket/tests -v
23+
```
24+
25+
3) Run a single test or filter by keyword:
26+
27+
```bash
28+
# One file
29+
python -m pytest plugins/communication_protocols/socket/tests/test_tcp_communication_protocol.py -v
30+
31+
# Filter by keyword (e.g., delimiter framing)
32+
python -m pytest plugins/communication_protocols/socket/tests -k delimiter -q
33+
```
34+
35+
4) Optional end-to-end sanity check (mock UDP/TCP servers):
36+
37+
```bash
38+
python scripts/socket_sanity.py
39+
```
40+
41+
Notes:
42+
- On Windows, your firewall may prompt the first time tests open UDP/TCP sockets; allow access or run as admin if needed.
43+
- Tests use `pytest-asyncio`. The dev extras installed above provide required dependencies.
44+
- Streaming is single-chunk by design, consistent with HTTP/Text transports. Multi-chunk streaming can be added later behind provider configuration.

plugins/communication_protocols/socket/pyproject.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,7 @@ dev = [
3636
[project.urls]
3737
Homepage = "https://utcp.io"
3838
Source = "https://github.com/universal-tool-calling-protocol/python-utcp"
39-
Issues = "https://github.com/universal-tool-calling-protocol/python-utcp/issues"
39+
Issues = "https://github.com/universal-tool-calling-protocol/python-utcp/issues"
40+
41+
[project.entry-points."utcp.plugins"]
42+
socket = "utcp_socket:register"
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from utcp.plugins.discovery import register_communication_protocol, register_call_template
2+
from utcp_socket.tcp_communication_protocol import TCPTransport
3+
from utcp_socket.udp_communication_protocol import UDPTransport
4+
from utcp_socket.tcp_call_template import TCPProviderSerializer
5+
from utcp_socket.udp_call_template import UDPProviderSerializer
6+
7+
8+
def register() -> None:
9+
# Register communication protocols
10+
register_communication_protocol("tcp", TCPTransport())
11+
register_communication_protocol("udp", UDPTransport())
12+
13+
# Register call templates and their serializers
14+
register_call_template("tcp", TCPProviderSerializer())
15+
register_call_template("udp", UDPProviderSerializer())
16+
17+
18+
__all__ = ["register"]

plugins/communication_protocols/socket/src/utcp_socket/tcp_call_template.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
from utcp.data.call_template import CallTemplate
22
from typing import Optional, Literal
33
from pydantic import Field
4+
from utcp.interfaces.serializer import Serializer
5+
from utcp.exceptions import UtcpSerializerValidationError
6+
import traceback
47

58
class TCPProvider(CallTemplate):
69
"""Provider configuration for raw TCP socket tools.
@@ -63,7 +66,7 @@ class TCPProvider(CallTemplate):
6366
# Delimiter-based framing options
6467
message_delimiter: str = Field(
6568
default='\x00',
66-
description="Delimiter to detect end of TCP response (e.g., '\\n', '\\r\\n', '\\x00'). Used with 'delimiter' framing."
69+
description="Delimiter to detect end of TCP response (e.g., '\n', '\r\n', '\x00'). Used with 'delimiter' framing."
6770
)
6871
# Fixed-length framing options
6972
fixed_message_length: Optional[int] = Field(
@@ -77,3 +80,16 @@ class TCPProvider(CallTemplate):
7780
)
7881
timeout: int = 30000
7982
auth: None = None
83+
84+
85+
class TCPProviderSerializer(Serializer[TCPProvider]):
86+
def to_dict(self, obj: TCPProvider) -> dict:
87+
return obj.model_dump()
88+
89+
def validate_dict(self, data: dict) -> TCPProvider:
90+
try:
91+
return TCPProvider.model_validate(data)
92+
except Exception as e:
93+
raise UtcpSerializerValidationError(
94+
f"Invalid TCPProvider: {e}\n{traceback.format_exc()}"
95+
)

0 commit comments

Comments
 (0)