da2-mcp-socket 0.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- da2_mcp_socket-0.2.0/.gitignore +75 -0
- da2_mcp_socket-0.2.0/CHANGELOG.md +51 -0
- da2_mcp_socket-0.2.0/LICENSE +21 -0
- da2_mcp_socket-0.2.0/PKG-INFO +204 -0
- da2_mcp_socket-0.2.0/README.md +176 -0
- da2_mcp_socket-0.2.0/README_TW.md +176 -0
- da2_mcp_socket-0.2.0/pyproject.toml +56 -0
- da2_mcp_socket-0.2.0/src/mcp_socket/__init__.py +6 -0
- da2_mcp_socket-0.2.0/src/mcp_socket/server.py +559 -0
- da2_mcp_socket-0.2.0/src/mcp_socket/socket_manager.py +1103 -0
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
*.egg-info/
|
|
24
|
+
.installed.cfg
|
|
25
|
+
*.egg
|
|
26
|
+
|
|
27
|
+
# PyInstaller
|
|
28
|
+
*.manifest
|
|
29
|
+
*.spec
|
|
30
|
+
|
|
31
|
+
# Installer logs
|
|
32
|
+
pip-log.txt
|
|
33
|
+
pip-delete-this-directory.txt
|
|
34
|
+
|
|
35
|
+
# Unit test / coverage reports
|
|
36
|
+
htmlcov/
|
|
37
|
+
.tox/
|
|
38
|
+
.nox/
|
|
39
|
+
.coverage
|
|
40
|
+
.coverage.*
|
|
41
|
+
.cache
|
|
42
|
+
nosetests.xml
|
|
43
|
+
coverage.xml
|
|
44
|
+
*.cover
|
|
45
|
+
*.py,cover
|
|
46
|
+
.hypothesis/
|
|
47
|
+
.pytest_cache/
|
|
48
|
+
|
|
49
|
+
# Translations
|
|
50
|
+
*.mo
|
|
51
|
+
*.pot
|
|
52
|
+
|
|
53
|
+
# Environments
|
|
54
|
+
.env
|
|
55
|
+
.venv
|
|
56
|
+
env/
|
|
57
|
+
venv/
|
|
58
|
+
ENV/
|
|
59
|
+
env.bak/
|
|
60
|
+
venv.bak/
|
|
61
|
+
|
|
62
|
+
# IDE
|
|
63
|
+
.idea/
|
|
64
|
+
.vscode/
|
|
65
|
+
*.swp
|
|
66
|
+
*.swo
|
|
67
|
+
*~
|
|
68
|
+
|
|
69
|
+
# mypy
|
|
70
|
+
.mypy_cache/
|
|
71
|
+
.dmypy.json
|
|
72
|
+
dmypy.json
|
|
73
|
+
|
|
74
|
+
# Ruff
|
|
75
|
+
.ruff_cache/
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [0.2.0] - 2026-02-05
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
- Background listener feature for continuous packet reception
|
|
12
|
+
- `start_listening` tool: Start background listener thread
|
|
13
|
+
- `stop_listening` tool: Stop background listener
|
|
14
|
+
- `get_packets` tool: Get all buffered packets (clears buffer)
|
|
15
|
+
- `get_buffer_status` tool: Query buffer status (count/overflow)
|
|
16
|
+
- `max_buffer_packets` parameter for connect (default: 100)
|
|
17
|
+
- `auto_listen` parameter for automatic background listening on connect
|
|
18
|
+
- `drop_oldest` overflow policy for packet buffer
|
|
19
|
+
- Thread-safe packet buffer with locking
|
|
20
|
+
|
|
21
|
+
### Changed
|
|
22
|
+
- Default protocol mode changed to `line` with `\r\n` end delimiter
|
|
23
|
+
- Updated documentation with RFID reader (AL-510) examples
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
## [0.1.1] - 2026-02-05
|
|
28
|
+
|
|
29
|
+
### Added
|
|
30
|
+
- Protocol management feature for packet parsing
|
|
31
|
+
- `set_protocol` tool: Configure receive mode (raw/line/packet) with custom delimiters
|
|
32
|
+
- `receive_packet` tool: Receive complete packet based on configured protocol
|
|
33
|
+
- `get_protocol` tool: Query current protocol settings
|
|
34
|
+
- Support for start/end delimiters in both text and hex format
|
|
35
|
+
- Packet buffering for handling partial data
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
## [0.1.0] - 2026-02-05
|
|
41
|
+
|
|
42
|
+
### Added
|
|
43
|
+
- Initial release
|
|
44
|
+
- TCP/IP socket connection management
|
|
45
|
+
- Multi-connection support with unique connection IDs
|
|
46
|
+
- Data transmission (send_data, receive_data, receive_line, receive_until)
|
|
47
|
+
- Text and Hex data format support
|
|
48
|
+
- STDIO mode for Cursor/Claude Desktop
|
|
49
|
+
- HTTP mode for Antigravity/Docker
|
|
50
|
+
- Configurable timeout and buffer size settings
|
|
51
|
+
- Thread-safe connection management
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Danny, DA2 Studio (https://da2.35g.tw)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: da2-mcp-socket
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: A Socket TCP/IP MCP Server - enables AI assistants to communicate via TCP/IP sockets
|
|
5
|
+
Project-URL: Homepage, https://da2.35g.tw
|
|
6
|
+
Project-URL: Repository, https://github.com/anthropics/mcp
|
|
7
|
+
Project-URL: Documentation, https://da2.35g.tw
|
|
8
|
+
Author-email: Danny <danny@35g.tw>, DA2 Studio <contact@35g.tw>
|
|
9
|
+
License: MIT
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: ai,claude,cursor,ip,llm,mcp,network,socket,tcp
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
21
|
+
Classifier: Topic :: Communications
|
|
22
|
+
Classifier: Topic :: Internet
|
|
23
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
24
|
+
Requires-Python: >=3.10
|
|
25
|
+
Requires-Dist: mcp[cli]>=1.0.0
|
|
26
|
+
Requires-Dist: python-dotenv>=1.0.0
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
|
|
29
|
+
# Socket MCP Server
|
|
30
|
+
|
|
31
|
+
A powerful Model Context Protocol (MCP) Server designed for **AI-assisted development**. It enables your AI assistant to communicate via TCP/IP sockets directly.
|
|
32
|
+
|
|
33
|
+
## Key Features
|
|
34
|
+
|
|
35
|
+
* **Easy Integration**: Connect to any TCP/IP device or service
|
|
36
|
+
* **Ready to Use**: Simple `pip` installation with zero complex setup
|
|
37
|
+
* **Multi-Connection**: Manage multiple socket connections simultaneously
|
|
38
|
+
* **Packet Protocol**: Custom start/end delimiter packet parsing
|
|
39
|
+
* **Background Listener**: Auto-receive and buffer packets with drop_oldest overflow policy
|
|
40
|
+
* **Data Transmission**: Send/receive text or binary (hex) data
|
|
41
|
+
* **Dual Execution Modes**: Supports STDIO (default) and HTTP modes
|
|
42
|
+
|
|
43
|
+
## Installation
|
|
44
|
+
|
|
45
|
+
Ensure you have Python 3.10 or higher installed.
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
pip install da2-mcp-socket
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Quick Start
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
# STDIO mode (for Cursor/Claude Desktop)
|
|
55
|
+
da2-mcp-socket
|
|
56
|
+
|
|
57
|
+
# HTTP mode (for Antigravity)
|
|
58
|
+
da2-mcp-socket --http --port 8000
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Client Configuration
|
|
62
|
+
|
|
63
|
+
### Cursor / Claude Desktop
|
|
64
|
+
|
|
65
|
+
```json
|
|
66
|
+
{
|
|
67
|
+
"mcpServers": {
|
|
68
|
+
"socket": {
|
|
69
|
+
"command": "da2-mcp-socket",
|
|
70
|
+
"args": [],
|
|
71
|
+
"env": { "LOG_LEVEL": "INFO" }
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### Antigravity
|
|
78
|
+
|
|
79
|
+
```json
|
|
80
|
+
{
|
|
81
|
+
"mcpServers": {
|
|
82
|
+
"socket": {
|
|
83
|
+
"serverUrl": "http://localhost:8000/mcp"
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
---
|
|
90
|
+
|
|
91
|
+
## Available Tools (15)
|
|
92
|
+
|
|
93
|
+
### Connection Management
|
|
94
|
+
| Tool | Description |
|
|
95
|
+
| :--- | :--- |
|
|
96
|
+
| **connect** | Connect to a TCP server (host:port) |
|
|
97
|
+
| **disconnect** | Close a specific connection |
|
|
98
|
+
| **get_connection_status** | Get status of active connection(s) |
|
|
99
|
+
|
|
100
|
+
### Data Transmission
|
|
101
|
+
| Tool | Description |
|
|
102
|
+
| :--- | :--- |
|
|
103
|
+
| **send_data** | Send text or hex data through a connection |
|
|
104
|
+
| **receive_data** | Receive data from a connection (with timeout) |
|
|
105
|
+
| **receive_line** | Receive a line (until newline character) |
|
|
106
|
+
| **receive_until** | Receive until a specific terminator |
|
|
107
|
+
|
|
108
|
+
### Protocol Management
|
|
109
|
+
| Tool | Description |
|
|
110
|
+
| :--- | :--- |
|
|
111
|
+
| **set_protocol** | Configure receive mode (raw/line/packet) with custom delimiters |
|
|
112
|
+
| **receive_packet** | Receive complete packet based on configured protocol |
|
|
113
|
+
| **get_protocol** | Get current protocol settings for a connection |
|
|
114
|
+
|
|
115
|
+
### Background Listener
|
|
116
|
+
| Tool | Description |
|
|
117
|
+
| :--- | :--- |
|
|
118
|
+
| **start_listening** | Start background listener thread |
|
|
119
|
+
| **stop_listening** | Stop background listener |
|
|
120
|
+
| **get_packets** | Get all buffered packets (clears buffer) |
|
|
121
|
+
| **get_buffer_status** | Query buffer status (count/overflow) |
|
|
122
|
+
|
|
123
|
+
### Server Info
|
|
124
|
+
| Tool | Description |
|
|
125
|
+
| :--- | :--- |
|
|
126
|
+
| **get_server_info** | Get server version and default settings |
|
|
127
|
+
|
|
128
|
+
---
|
|
129
|
+
|
|
130
|
+
## Usage Examples
|
|
131
|
+
|
|
132
|
+
### RFID Reader Connection (AL-510)
|
|
133
|
+
|
|
134
|
+
```python
|
|
135
|
+
# 1. Connect to device
|
|
136
|
+
connect("192.168.248.70", 1001)
|
|
137
|
+
|
|
138
|
+
# 2. Set packet protocol: <0x0A>[data]<0x0D0A>
|
|
139
|
+
set_protocol("conn_id", mode="packet",
|
|
140
|
+
start_delimiter_hex="0A",
|
|
141
|
+
end_delimiter_hex="0D0A")
|
|
142
|
+
|
|
143
|
+
# 3. Send command (Inventory EPC+TID)
|
|
144
|
+
send_data("conn_id", "0A4055322C52322C302C360D", as_hex=True)
|
|
145
|
+
|
|
146
|
+
# 4. Receive packet
|
|
147
|
+
receive_packet("conn_id", timeout=5.0)
|
|
148
|
+
# → @2000/01/01 01:31:11.981-Antenna1-U3000E300...,RE28069952...
|
|
149
|
+
|
|
150
|
+
# 5. Disconnect
|
|
151
|
+
disconnect("conn_id")
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
### Background Continuous Listening
|
|
155
|
+
|
|
156
|
+
```python
|
|
157
|
+
# 1. Connect and set protocol
|
|
158
|
+
connect("192.168.248.70", 1001, max_buffer_packets=100)
|
|
159
|
+
set_protocol("conn_id", mode="packet", start_delimiter_hex="0A", end_delimiter_hex="0D0A")
|
|
160
|
+
|
|
161
|
+
# 2. Start background listener
|
|
162
|
+
start_listening("conn_id")
|
|
163
|
+
|
|
164
|
+
# 3. Get accumulated packets anytime
|
|
165
|
+
get_packets("conn_id")
|
|
166
|
+
# → { packets: [{data_hex, data_text, timestamp}, ...], count: 5 }
|
|
167
|
+
|
|
168
|
+
# 4. Query buffer status
|
|
169
|
+
get_buffer_status("conn_id")
|
|
170
|
+
# → { buffer: { count: 5, max: 100, overflow_count: 0 } }
|
|
171
|
+
|
|
172
|
+
# 5. Stop listening
|
|
173
|
+
stop_listening("conn_id")
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
### HTTP Request
|
|
177
|
+
|
|
178
|
+
```python
|
|
179
|
+
connect("example.com", 80)
|
|
180
|
+
send_data("conn_id", "GET / HTTP/1.1\r\nHost: example.com\r\n\r\n")
|
|
181
|
+
receive_data("conn_id", size=4096, timeout=5.0)
|
|
182
|
+
disconnect("conn_id")
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
---
|
|
186
|
+
|
|
187
|
+
## Default Settings
|
|
188
|
+
|
|
189
|
+
| Parameter | Default Value |
|
|
190
|
+
| :--- | :--- |
|
|
191
|
+
| **Connection Timeout** | 10.0 seconds |
|
|
192
|
+
| **Read Timeout** | 5.0 seconds |
|
|
193
|
+
| **Buffer Size** | 4096 bytes |
|
|
194
|
+
| **Max Buffer Packets** | 100 |
|
|
195
|
+
| **Overflow Policy** | drop_oldest |
|
|
196
|
+
|
|
197
|
+
---
|
|
198
|
+
|
|
199
|
+
## License
|
|
200
|
+
|
|
201
|
+
MIT License
|
|
202
|
+
|
|
203
|
+
Copyright (c) 2026 Danny, DA2 Studio (https://da2.35g.tw)
|
|
204
|
+
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
# Socket MCP Server
|
|
2
|
+
|
|
3
|
+
A powerful Model Context Protocol (MCP) Server designed for **AI-assisted development**. It enables your AI assistant to communicate via TCP/IP sockets directly.
|
|
4
|
+
|
|
5
|
+
## Key Features
|
|
6
|
+
|
|
7
|
+
* **Easy Integration**: Connect to any TCP/IP device or service
|
|
8
|
+
* **Ready to Use**: Simple `pip` installation with zero complex setup
|
|
9
|
+
* **Multi-Connection**: Manage multiple socket connections simultaneously
|
|
10
|
+
* **Packet Protocol**: Custom start/end delimiter packet parsing
|
|
11
|
+
* **Background Listener**: Auto-receive and buffer packets with drop_oldest overflow policy
|
|
12
|
+
* **Data Transmission**: Send/receive text or binary (hex) data
|
|
13
|
+
* **Dual Execution Modes**: Supports STDIO (default) and HTTP modes
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
Ensure you have Python 3.10 or higher installed.
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
pip install da2-mcp-socket
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Quick Start
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
# STDIO mode (for Cursor/Claude Desktop)
|
|
27
|
+
da2-mcp-socket
|
|
28
|
+
|
|
29
|
+
# HTTP mode (for Antigravity)
|
|
30
|
+
da2-mcp-socket --http --port 8000
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Client Configuration
|
|
34
|
+
|
|
35
|
+
### Cursor / Claude Desktop
|
|
36
|
+
|
|
37
|
+
```json
|
|
38
|
+
{
|
|
39
|
+
"mcpServers": {
|
|
40
|
+
"socket": {
|
|
41
|
+
"command": "da2-mcp-socket",
|
|
42
|
+
"args": [],
|
|
43
|
+
"env": { "LOG_LEVEL": "INFO" }
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Antigravity
|
|
50
|
+
|
|
51
|
+
```json
|
|
52
|
+
{
|
|
53
|
+
"mcpServers": {
|
|
54
|
+
"socket": {
|
|
55
|
+
"serverUrl": "http://localhost:8000/mcp"
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
---
|
|
62
|
+
|
|
63
|
+
## Available Tools (15)
|
|
64
|
+
|
|
65
|
+
### Connection Management
|
|
66
|
+
| Tool | Description |
|
|
67
|
+
| :--- | :--- |
|
|
68
|
+
| **connect** | Connect to a TCP server (host:port) |
|
|
69
|
+
| **disconnect** | Close a specific connection |
|
|
70
|
+
| **get_connection_status** | Get status of active connection(s) |
|
|
71
|
+
|
|
72
|
+
### Data Transmission
|
|
73
|
+
| Tool | Description |
|
|
74
|
+
| :--- | :--- |
|
|
75
|
+
| **send_data** | Send text or hex data through a connection |
|
|
76
|
+
| **receive_data** | Receive data from a connection (with timeout) |
|
|
77
|
+
| **receive_line** | Receive a line (until newline character) |
|
|
78
|
+
| **receive_until** | Receive until a specific terminator |
|
|
79
|
+
|
|
80
|
+
### Protocol Management
|
|
81
|
+
| Tool | Description |
|
|
82
|
+
| :--- | :--- |
|
|
83
|
+
| **set_protocol** | Configure receive mode (raw/line/packet) with custom delimiters |
|
|
84
|
+
| **receive_packet** | Receive complete packet based on configured protocol |
|
|
85
|
+
| **get_protocol** | Get current protocol settings for a connection |
|
|
86
|
+
|
|
87
|
+
### Background Listener
|
|
88
|
+
| Tool | Description |
|
|
89
|
+
| :--- | :--- |
|
|
90
|
+
| **start_listening** | Start background listener thread |
|
|
91
|
+
| **stop_listening** | Stop background listener |
|
|
92
|
+
| **get_packets** | Get all buffered packets (clears buffer) |
|
|
93
|
+
| **get_buffer_status** | Query buffer status (count/overflow) |
|
|
94
|
+
|
|
95
|
+
### Server Info
|
|
96
|
+
| Tool | Description |
|
|
97
|
+
| :--- | :--- |
|
|
98
|
+
| **get_server_info** | Get server version and default settings |
|
|
99
|
+
|
|
100
|
+
---
|
|
101
|
+
|
|
102
|
+
## Usage Examples
|
|
103
|
+
|
|
104
|
+
### RFID Reader Connection (AL-510)
|
|
105
|
+
|
|
106
|
+
```python
|
|
107
|
+
# 1. Connect to device
|
|
108
|
+
connect("192.168.248.70", 1001)
|
|
109
|
+
|
|
110
|
+
# 2. Set packet protocol: <0x0A>[data]<0x0D0A>
|
|
111
|
+
set_protocol("conn_id", mode="packet",
|
|
112
|
+
start_delimiter_hex="0A",
|
|
113
|
+
end_delimiter_hex="0D0A")
|
|
114
|
+
|
|
115
|
+
# 3. Send command (Inventory EPC+TID)
|
|
116
|
+
send_data("conn_id", "0A4055322C52322C302C360D", as_hex=True)
|
|
117
|
+
|
|
118
|
+
# 4. Receive packet
|
|
119
|
+
receive_packet("conn_id", timeout=5.0)
|
|
120
|
+
# → @2000/01/01 01:31:11.981-Antenna1-U3000E300...,RE28069952...
|
|
121
|
+
|
|
122
|
+
# 5. Disconnect
|
|
123
|
+
disconnect("conn_id")
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### Background Continuous Listening
|
|
127
|
+
|
|
128
|
+
```python
|
|
129
|
+
# 1. Connect and set protocol
|
|
130
|
+
connect("192.168.248.70", 1001, max_buffer_packets=100)
|
|
131
|
+
set_protocol("conn_id", mode="packet", start_delimiter_hex="0A", end_delimiter_hex="0D0A")
|
|
132
|
+
|
|
133
|
+
# 2. Start background listener
|
|
134
|
+
start_listening("conn_id")
|
|
135
|
+
|
|
136
|
+
# 3. Get accumulated packets anytime
|
|
137
|
+
get_packets("conn_id")
|
|
138
|
+
# → { packets: [{data_hex, data_text, timestamp}, ...], count: 5 }
|
|
139
|
+
|
|
140
|
+
# 4. Query buffer status
|
|
141
|
+
get_buffer_status("conn_id")
|
|
142
|
+
# → { buffer: { count: 5, max: 100, overflow_count: 0 } }
|
|
143
|
+
|
|
144
|
+
# 5. Stop listening
|
|
145
|
+
stop_listening("conn_id")
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### HTTP Request
|
|
149
|
+
|
|
150
|
+
```python
|
|
151
|
+
connect("example.com", 80)
|
|
152
|
+
send_data("conn_id", "GET / HTTP/1.1\r\nHost: example.com\r\n\r\n")
|
|
153
|
+
receive_data("conn_id", size=4096, timeout=5.0)
|
|
154
|
+
disconnect("conn_id")
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
---
|
|
158
|
+
|
|
159
|
+
## Default Settings
|
|
160
|
+
|
|
161
|
+
| Parameter | Default Value |
|
|
162
|
+
| :--- | :--- |
|
|
163
|
+
| **Connection Timeout** | 10.0 seconds |
|
|
164
|
+
| **Read Timeout** | 5.0 seconds |
|
|
165
|
+
| **Buffer Size** | 4096 bytes |
|
|
166
|
+
| **Max Buffer Packets** | 100 |
|
|
167
|
+
| **Overflow Policy** | drop_oldest |
|
|
168
|
+
|
|
169
|
+
---
|
|
170
|
+
|
|
171
|
+
## License
|
|
172
|
+
|
|
173
|
+
MIT License
|
|
174
|
+
|
|
175
|
+
Copyright (c) 2026 Danny, DA2 Studio (https://da2.35g.tw)
|
|
176
|
+
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
# Socket MCP Server
|
|
2
|
+
|
|
3
|
+
一款強大的 Model Context Protocol (MCP) 伺服器,專為 **AI 輔助開發** 設計。讓您的 AI 助手能夠直接通過 TCP/IP Socket 進行通訊。
|
|
4
|
+
|
|
5
|
+
## 主要功能
|
|
6
|
+
|
|
7
|
+
* **簡易整合**:連接到任何 TCP/IP 設備或服務
|
|
8
|
+
* **即裝即用**:簡單的 `pip` 安裝,無需複雜設定
|
|
9
|
+
* **多連線支援**:同時管理多個 Socket 連線
|
|
10
|
+
* **封包協議**:支援自訂起始/結束分隔符號的封包解析
|
|
11
|
+
* **背景監聽**:自動接收並緩衝封包,支援 drop_oldest 溢出策略
|
|
12
|
+
* **資料傳輸**:發送/接收文字或二進位(Hex)資料
|
|
13
|
+
* **雙模式執行**:支援 STDIO(預設)和 HTTP 模式
|
|
14
|
+
|
|
15
|
+
## 安裝
|
|
16
|
+
|
|
17
|
+
請確保已安裝 Python 3.10 或更高版本。
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
pip install da2-mcp-socket
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## 快速開始
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
# STDIO 模式(給 Cursor/Claude Desktop)
|
|
27
|
+
da2-mcp-socket
|
|
28
|
+
|
|
29
|
+
# HTTP 模式(給 Antigravity)
|
|
30
|
+
da2-mcp-socket --http --port 8000
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## 客戶端配置
|
|
34
|
+
|
|
35
|
+
### Cursor / Claude Desktop
|
|
36
|
+
|
|
37
|
+
```json
|
|
38
|
+
{
|
|
39
|
+
"mcpServers": {
|
|
40
|
+
"socket": {
|
|
41
|
+
"command": "da2-mcp-socket",
|
|
42
|
+
"args": [],
|
|
43
|
+
"env": { "LOG_LEVEL": "INFO" }
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Antigravity
|
|
50
|
+
|
|
51
|
+
```json
|
|
52
|
+
{
|
|
53
|
+
"mcpServers": {
|
|
54
|
+
"socket": {
|
|
55
|
+
"serverUrl": "http://localhost:8000/mcp"
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
---
|
|
62
|
+
|
|
63
|
+
## 可用工具 (15 個)
|
|
64
|
+
|
|
65
|
+
### 連線管理
|
|
66
|
+
| 工具 | 說明 |
|
|
67
|
+
| :--- | :--- |
|
|
68
|
+
| **connect** | 連接到 TCP 伺服器(host:port) |
|
|
69
|
+
| **disconnect** | 關閉指定的連線 |
|
|
70
|
+
| **get_connection_status** | 查詢活動連線的狀態 |
|
|
71
|
+
|
|
72
|
+
### 資料傳輸
|
|
73
|
+
| 工具 | 說明 |
|
|
74
|
+
| :--- | :--- |
|
|
75
|
+
| **send_data** | 通過連線發送文字或 Hex 資料 |
|
|
76
|
+
| **receive_data** | 從連線接收資料(支援超時) |
|
|
77
|
+
| **receive_line** | 接收一行(直到換行符號) |
|
|
78
|
+
| **receive_until** | 接收直到指定的結束符號 |
|
|
79
|
+
|
|
80
|
+
### 協議管理
|
|
81
|
+
| 工具 | 說明 |
|
|
82
|
+
| :--- | :--- |
|
|
83
|
+
| **set_protocol** | 設定接收模式(raw/line/packet)及自訂分隔符號 |
|
|
84
|
+
| **receive_packet** | 依照已設定的協議接收完整封包 |
|
|
85
|
+
| **get_protocol** | 查詢連線的當前協議設定 |
|
|
86
|
+
|
|
87
|
+
### 背景監聽
|
|
88
|
+
| 工具 | 說明 |
|
|
89
|
+
| :--- | :--- |
|
|
90
|
+
| **start_listening** | 啟動背景監聽執行緒 |
|
|
91
|
+
| **stop_listening** | 停止背景監聽 |
|
|
92
|
+
| **get_packets** | 取得所有累積的封包(清空 buffer) |
|
|
93
|
+
| **get_buffer_status** | 查詢 buffer 狀態(數量/溢出次數) |
|
|
94
|
+
|
|
95
|
+
### 伺服器資訊
|
|
96
|
+
| 工具 | 說明 |
|
|
97
|
+
| :--- | :--- |
|
|
98
|
+
| **get_server_info** | 取得伺服器版本和預設設定 |
|
|
99
|
+
|
|
100
|
+
---
|
|
101
|
+
|
|
102
|
+
## 使用範例
|
|
103
|
+
|
|
104
|
+
### RFID 讀取器連線(AL-510)
|
|
105
|
+
|
|
106
|
+
```python
|
|
107
|
+
# 1. 連接設備
|
|
108
|
+
connect("192.168.248.70", 1001)
|
|
109
|
+
|
|
110
|
+
# 2. 設定封包協議:<0x0A>[資料]<0x0D0A>
|
|
111
|
+
set_protocol("conn_id", mode="packet",
|
|
112
|
+
start_delimiter_hex="0A",
|
|
113
|
+
end_delimiter_hex="0D0A")
|
|
114
|
+
|
|
115
|
+
# 3. 發送命令(盤點 EPC+TID)
|
|
116
|
+
send_data("conn_id", "0A4055322C52322C302C360D", as_hex=True)
|
|
117
|
+
|
|
118
|
+
# 4. 接收封包
|
|
119
|
+
receive_packet("conn_id", timeout=5.0)
|
|
120
|
+
# → @2000/01/01 01:31:11.981-Antenna1-U3000E300...,RE28069952...
|
|
121
|
+
|
|
122
|
+
# 5. 關閉連線
|
|
123
|
+
disconnect("conn_id")
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### 背景持續監聽
|
|
127
|
+
|
|
128
|
+
```python
|
|
129
|
+
# 1. 連接並設定協議
|
|
130
|
+
connect("192.168.248.70", 1001, max_buffer_packets=100)
|
|
131
|
+
set_protocol("conn_id", mode="packet", start_delimiter_hex="0A", end_delimiter_hex="0D0A")
|
|
132
|
+
|
|
133
|
+
# 2. 啟動背景監聽
|
|
134
|
+
start_listening("conn_id")
|
|
135
|
+
|
|
136
|
+
# 3. 隨時取得累積的封包
|
|
137
|
+
get_packets("conn_id")
|
|
138
|
+
# → { packets: [{data_hex, data_text, timestamp}, ...], count: 5 }
|
|
139
|
+
|
|
140
|
+
# 4. 查詢 buffer 狀態
|
|
141
|
+
get_buffer_status("conn_id")
|
|
142
|
+
# → { buffer: { count: 5, max: 100, overflow_count: 0 } }
|
|
143
|
+
|
|
144
|
+
# 5. 停止監聽
|
|
145
|
+
stop_listening("conn_id")
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### HTTP 請求
|
|
149
|
+
|
|
150
|
+
```python
|
|
151
|
+
connect("example.com", 80)
|
|
152
|
+
send_data("conn_id", "GET / HTTP/1.1\r\nHost: example.com\r\n\r\n")
|
|
153
|
+
receive_data("conn_id", size=4096, timeout=5.0)
|
|
154
|
+
disconnect("conn_id")
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
---
|
|
158
|
+
|
|
159
|
+
## 預設設定
|
|
160
|
+
|
|
161
|
+
| 參數 | 預設值 |
|
|
162
|
+
| :--- | :--- |
|
|
163
|
+
| **連線超時** | 10.0 秒 |
|
|
164
|
+
| **讀取超時** | 5.0 秒 |
|
|
165
|
+
| **緩衝區大小** | 4096 位元組 |
|
|
166
|
+
| **最大封包數** | 100 個 |
|
|
167
|
+
| **溢出策略** | drop_oldest |
|
|
168
|
+
|
|
169
|
+
---
|
|
170
|
+
|
|
171
|
+
## 授權
|
|
172
|
+
|
|
173
|
+
MIT License
|
|
174
|
+
|
|
175
|
+
Copyright (c) 2026 Danny, DA2 Studio (https://da2.35g.tw)
|
|
176
|
+
|