trassir-mcp 0.1.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.
@@ -0,0 +1,17 @@
1
+ # Single-server TRASSIR configuration (used if TRASSIR_SERVERS_FILE / TRASSIR_SERVERS_JSON is not set)
2
+ TRASSIR_HOST=192.168.1.200
3
+ TRASSIR_PORT=8080
4
+ TRASSIR_STREAM_PORT=555
5
+ TRASSIR_SCHEME=https
6
+ TRASSIR_VERIFY_TLS=false
7
+ TRASSIR_TIMEOUT=15
8
+
9
+ # User credentials (required for /channels, /get_video, /archive_status, /archive_command, /archive_events)
10
+ TRASSIR_USERNAME=Admin
11
+ TRASSIR_PASSWORD=
12
+
13
+ # SDK password (required for /objects, /classes, /events, /lpr_events, /pos_events, /fr_events, /deep_detector, /screenshot, /ptz)
14
+ TRASSIR_SDK_PASSWORD=
15
+
16
+ # Optional multi-server config file path (JSON)
17
+ # TRASSIR_SERVERS_FILE=./servers.json
@@ -0,0 +1,3 @@
1
+ * text=auto eol=lf
2
+ *.ps1 text eol=crlf
3
+ *.bat text eol=crlf
@@ -0,0 +1,36 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: ["main"]
6
+ pull_request:
7
+ branches: ["main"]
8
+
9
+ jobs:
10
+ lint-and-test:
11
+ runs-on: ubuntu-latest
12
+ strategy:
13
+ matrix:
14
+ python-version: ["3.11", "3.12", "3.13"]
15
+
16
+ steps:
17
+ - name: Checkout repository
18
+ uses: actions/checkout@v4
19
+
20
+ - name: Install uv
21
+ uses: astral-sh/setup-uv@v5
22
+
23
+ - name: Set up Python ${{ matrix.python-version }}
24
+ run: uv python install ${{ matrix.python-version }}
25
+
26
+ - name: Install dependencies
27
+ run: uv sync --python ${{ matrix.python-version }} --extra dev
28
+
29
+ - name: Lint with Ruff
30
+ run: uv run --python ${{ matrix.python-version }} ruff check .
31
+
32
+ - name: Run test suite
33
+ run: uv run --python ${{ matrix.python-version }} pytest -v
34
+
35
+ - name: Build package
36
+ run: uv build
@@ -0,0 +1,11 @@
1
+ .venv/
2
+ .env
3
+ servers.json
4
+ __pycache__/
5
+ *.pyc
6
+ .pytest_cache/
7
+ .ruff_cache/
8
+ dist/
9
+ build/
10
+ *.egg-info/
11
+ docs/
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 queukat
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,217 @@
1
+ Metadata-Version: 2.5
2
+ Name: trassir-mcp
3
+ Version: 0.1.0
4
+ Summary: Full-featured MCP server for DSSL TRASSIR VMS HTTP/Web SDK
5
+ Project-URL: Homepage, https://github.com/queukat/trassir-mcp
6
+ Project-URL: Repository, https://github.com/queukat/trassir-mcp
7
+ Project-URL: Issues, https://github.com/queukat/trassir-mcp/issues
8
+ License: MIT
9
+ License-File: LICENSE
10
+ Keywords: cctv,dssl,mcp,model-context-protocol,surveillance,trassir,vms
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Intended Audience :: System Administrators
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.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Topic :: Multimedia :: Video
21
+ Classifier: Topic :: System :: Monitoring
22
+ Requires-Python: >=3.11
23
+ Requires-Dist: httpx>=0.27.0
24
+ Requires-Dist: mcp>=2.0.0
25
+ Requires-Dist: pydantic>=2.7.0
26
+ Provides-Extra: dev
27
+ Requires-Dist: pytest-asyncio>=0.24.0; extra == 'dev'
28
+ Requires-Dist: pytest>=8.0.0; extra == 'dev'
29
+ Requires-Dist: ruff>=0.6.0; extra == 'dev'
30
+ Description-Content-Type: text/markdown
31
+
32
+ <!-- mcp-name: io.github.queukat/trassir-mcp -->
33
+
34
+ # TRASSIR MCP Server (`trassir-mcp`)
35
+
36
+ > **Language:** **English** | [Русский](README.ru.md)
37
+
38
+ [![TRASSIR SDK](https://img.shields.io/badge/TRASSIR_SDK-HTTP%2FHTTPS_REST-0A66C2?style=flat-square)](https://trassir.com/)
39
+ [![MCP](https://img.shields.io/badge/MCP-2.0%2B_(stdio_%7C_HTTP)-6D28D9?style=flat-square)](https://modelcontextprotocol.io/)
40
+ [![Tools](https://img.shields.io/badge/Capabilities-32_Tools_%C2%B7_4_Resources_%C2%B7_2_Prompts-059669?style=flat-square)](#tool-reference)
41
+ [![Auth](https://img.shields.io/badge/Auth-Dual--Session_(SDK_%2B_User)-D97706?style=flat-square)](#key-features)
42
+ [![Python](https://img.shields.io/badge/Python-3.11%2B-3776AB?style=flat-square&logo=python&logoColor=white)](https://www.python.org/)
43
+ [![Tests](https://img.shields.io/badge/Tests-13_passed_(Mock_%2B_Live)-16A34A?style=flat-square)](#development--testing)
44
+ [![Ruff](https://img.shields.io/badge/Code_Style-Ruff-D7FF64?style=flat-square&logo=ruff&logoColor=black)](https://docs.astral.sh/ruff/)
45
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue?style=flat-square)](LICENSE)
46
+
47
+ A full-featured [Model Context Protocol (MCP)](https://modelcontextprotocol.io/) server for the **DSSL TRASSIR VMS HTTP/Web SDK**. Enables AI assistants (Claude, Codex, Cursor, Antigravity, etc.) to inspect server health, browse channels and object trees, capture live/archived JPEG frames directly as visual images, control PTZ cameras, navigate and export archive footage, and read real-time server & video analytics events.
48
+
49
+ ---
50
+
51
+ ## Key Features
52
+
53
+ - **Automatic Dual-Session Auth (`sdk` + `user`)**:
54
+ - `TRASSIR_SDK_PASSWORD` (`Script` user rights) is automatically used for `/objects/`, `/classes/`, `/events`, `/lpr_events`, `/pos_events`, `/fr_events`, `/deep_detector`, `/screenshot`, `/ptz`, and `/settings/users/user_add/`.
55
+ - `TRASSIR_USERNAME` + `TRASSIR_PASSWORD` are automatically used for `/channels`, `/get_video`, `/archive_status`, `/archive_command`, and `/archive_events`.
56
+ - **Resilient Session Lifecycle & TLS Compatibility**:
57
+ - Single-flight `sid` refresh under `asyncio.Lock` before TRASSIR's 15-minute idle TTL and on `401` / `invalid sid`, while respecting the 5-second `/login` cooldown.
58
+ - Works out of the box with TRASSIR's self-signed HTTPS certificates and older TLS ciphers (`DEFAULT@SECLEVEL=1` when `TRASSIR_VERIFY_TLS=false`).
59
+ - **Multi-Server & Portable Config Discovery**:
60
+ - Supports multiple TRASSIR servers via `servers.json` / `TRASSIR_SERVERS_JSON` or a single server via `.env` / environment variables.
61
+ - Automatically checks project root, current working directory, and `~/.config/trassir-mcp/`.
62
+ - **Visual Camera Inspection**: `trassir_get_screenshot` returns structured JSON metadata first (`TextContent`) and the raw JPEG frame second (`ImageContent`), supporting both multimodal and text-only clients (`return_image=false`).
63
+ - **Human-Readable TRASSIR Decoders**:
64
+ - Decodes 16-bit channel rights bitmasks, AutoTRASSIR LPR flags, `TimelineEvent` (per-second recording bitmaps), and `ActivityLevelEvent` / `SoundActivityLevelEvent` (per-second intensity 0..15).
65
+ - Event endpoints support both `mode="recent"` (non-blocking last 100 events) and `mode="poll"` (incremental long-poll with bounded timeout).
66
+ - **Mutation Safety Gates**: modifying settings (`trassir_set_setting`), invoking object methods (`trassir_call_object_method`), and creating/deleting users (`trassir_manage_users`) require explicit `confirm=True`.
67
+
68
+ ---
69
+
70
+ ## Supported Media & Export Formats
71
+
72
+ | Workflow | Tool | Formats |
73
+ | :--- | :--- | :--- |
74
+ | **Remote Archive Export (JIT)** | `trassir_jit_export_clip` / `trassir_jit_export_create` | **`.mp4`** (downloaded over HTTP, up to 30 min per task) |
75
+ | **Local Server Archive Export** | `trassir_local_archive_export` | **`.avi`** (`out_format=0`) or proprietary **`.travi`** (`out_format=1`) saved to TRASSIR's `Screenshots` folder; video codecs `""` (passthrough), `MPEG4`, `WMV` (Windows); audio `""`, `No audio`, `PCM`, `WMA` (Windows) |
76
+ | **Live & Archive Streams** | `trassir_open_video_stream` | `mjpeg`, `flv`, `rtsp`, `hls`, `jpeg`, `custom` (audio `ogg`/`aac`) |
77
+ | **Snapshots (Live / Archive)** | `trassir_get_screenshot` | **JPEG** (`image/jpeg`, optional analytics overlays via `figures=true`) |
78
+
79
+ ---
80
+
81
+ ## TRASSIR Server Prerequisites
82
+
83
+ In TRASSIR **Server Settings → Web Server → SDK**:
84
+ 1. Enable **TRASSIR SDK** and the required permission flags (*Object tree, Call methods, Events, POS events, AutoTRASSIR events, Deep Events, Read settings, Screenshots, PTZ, FLV/JPEG/MJPEG*).
85
+ 2. Set an **SDK Password** (uses the built-in `Script` user permissions).
86
+ 3. For `/channels`, `/get_video`, and archive endpoints, enable **Allow connection from mobile/browser** on a dedicated user account with the required channel/archive permissions.
87
+
88
+ ---
89
+
90
+ ## Installation & Configuration
91
+
92
+ ### Quick Run with `uvx`
93
+
94
+ ```bash
95
+ uvx --from git+https://github.com/queukat/trassir-mcp.git trassir-mcp
96
+ ```
97
+
98
+ *(Once published to PyPI, you can also run `uvx trassir-mcp` directly.)*
99
+
100
+ ### Local Installation (`uv` or `pip`)
101
+
102
+ ```bash
103
+ git clone https://github.com/queukat/trassir-mcp.git
104
+ cd trassir-mcp
105
+
106
+ uv venv --python 3.13 .venv
107
+ uv pip install --python .venv/bin/python -e ".[dev]"
108
+ ```
109
+
110
+ ### Environment Variables
111
+
112
+ Create `.env` in the repository root or `~/.config/trassir-mcp/.env` (see [.env.example](.env.example)), or pass variables in your MCP client config:
113
+
114
+ ```env
115
+ TRASSIR_HOST=192.168.1.200
116
+ TRASSIR_PORT=8080
117
+ TRASSIR_STREAM_PORT=555
118
+ TRASSIR_SCHEME=https
119
+ TRASSIR_VERIFY_TLS=false
120
+ TRASSIR_TIMEOUT=15
121
+
122
+ TRASSIR_USERNAME=Admin
123
+ TRASSIR_PASSWORD=your_user_password
124
+ TRASSIR_SDK_PASSWORD=your_sdk_password
125
+ ```
126
+
127
+ For multiple servers, copy [servers.example.json](servers.example.json) to `~/.config/trassir-mcp/servers.json` (or set `TRASSIR_SERVERS_FILE` / `TRASSIR_SERVERS_JSON`).
128
+
129
+ ---
130
+
131
+ ## Connecting to MCP Clients
132
+
133
+ ### Antigravity / Claude Desktop / Cursor (JSON)
134
+
135
+ - Antigravity: `~/.gemini/config/mcp_config.json`
136
+ - Cursor: `.cursor/mcp.json` or `~/.cursor/mcp.json`
137
+ - Claude Desktop: `claude_desktop_config.json`
138
+
139
+ ```json
140
+ {
141
+ "mcpServers": {
142
+ "trassir": {
143
+ "command": "uvx",
144
+ "args": ["--from", "git+https://github.com/queukat/trassir-mcp.git", "trassir-mcp"],
145
+ "env": {
146
+ "TRASSIR_HOST": "192.168.1.200",
147
+ "TRASSIR_PORT": "8080",
148
+ "TRASSIR_USERNAME": "Admin",
149
+ "TRASSIR_PASSWORD": "your_user_password",
150
+ "TRASSIR_SDK_PASSWORD": "your_sdk_password"
151
+ }
152
+ }
153
+ }
154
+ }
155
+ ```
156
+
157
+ ### OpenAI Codex CLI (`~/.codex/config.toml`)
158
+
159
+ ```toml
160
+ [mcp_servers.trassir]
161
+ command = "uvx"
162
+ args = ["--from", "git+https://github.com/queukat/trassir-mcp.git", "trassir-mcp"]
163
+
164
+ [mcp_servers.trassir.env]
165
+ TRASSIR_HOST = "192.168.1.200"
166
+ TRASSIR_PORT = "8080"
167
+ TRASSIR_USERNAME = "Admin"
168
+ TRASSIR_PASSWORD = "your_user_password"
169
+ TRASSIR_SDK_PASSWORD = "your_sdk_password"
170
+ ```
171
+
172
+ ### Claude Code CLI
173
+
174
+ ```bash
175
+ claude mcp add trassir \
176
+ -e TRASSIR_HOST=192.168.1.200 \
177
+ -e TRASSIR_PORT=8080 \
178
+ -e TRASSIR_USERNAME=Admin \
179
+ -e TRASSIR_PASSWORD=your_user_password \
180
+ -e TRASSIR_SDK_PASSWORD=your_sdk_password \
181
+ -- uvx --from git+https://github.com/queukat/trassir-mcp.git trassir-mcp
182
+ ```
183
+
184
+ ---
185
+
186
+ ## Tool Reference
187
+
188
+ ### Tools (32)
189
+
190
+ | Category | Tools |
191
+ | :--- | :--- |
192
+ | **Server & Health** | `trassir_list_servers`, `trassir_login`, `trassir_server_health` |
193
+ | **Channels & Object Tree** | `trassir_list_channels`, `trassir_get_objects`, `trassir_get_object`, `trassir_get_class`, `trassir_call_object_method` |
194
+ | **Settings & Users** | `trassir_get_settings`, `trassir_set_setting`, `trassir_manage_users` |
195
+ | **Screenshots & Streams** | `trassir_get_screenshot`, `trassir_open_video_stream`, `trassir_ping_stream` |
196
+ | **Archive & Export** | `trassir_archive_status`, `trassir_archive_command`, `trassir_archive_events`, `trassir_local_archive_export`, `trassir_local_export_tasks`, `trassir_local_export_cancel`, `trassir_jit_export_create`, `trassir_jit_export_status`, `trassir_jit_export_download`, `trassir_jit_export_cancel`, `trassir_jit_export_clip` |
197
+ | **Events & Analytics** | `trassir_get_events`, `trassir_get_lpr_events`, `trassir_get_pos_events`, `trassir_get_fr_events`, `trassir_get_deep_detector` |
198
+ | **PTZ & Raw SDK** | `trassir_ptz_control`, `trassir_raw_request` |
199
+
200
+ ### Resources & Prompts
201
+
202
+ - **Resources**: `trassir://servers`, `trassir://{server}/channels`, `trassir://{server}/health`, `trassir://{server}/objects`
203
+ - **Prompts**: `investigate_incident`, `server_health_audit`
204
+
205
+ ---
206
+
207
+ ## Development & Testing
208
+
209
+ ```bash
210
+ ruff check .
211
+ pytest -v
212
+ uv build
213
+ ```
214
+
215
+ ## License
216
+
217
+ [MIT](LICENSE)
@@ -0,0 +1,186 @@
1
+ <!-- mcp-name: io.github.queukat/trassir-mcp -->
2
+
3
+ # TRASSIR MCP Server (`trassir-mcp`)
4
+
5
+ > **Language:** **English** | [Русский](README.ru.md)
6
+
7
+ [![TRASSIR SDK](https://img.shields.io/badge/TRASSIR_SDK-HTTP%2FHTTPS_REST-0A66C2?style=flat-square)](https://trassir.com/)
8
+ [![MCP](https://img.shields.io/badge/MCP-2.0%2B_(stdio_%7C_HTTP)-6D28D9?style=flat-square)](https://modelcontextprotocol.io/)
9
+ [![Tools](https://img.shields.io/badge/Capabilities-32_Tools_%C2%B7_4_Resources_%C2%B7_2_Prompts-059669?style=flat-square)](#tool-reference)
10
+ [![Auth](https://img.shields.io/badge/Auth-Dual--Session_(SDK_%2B_User)-D97706?style=flat-square)](#key-features)
11
+ [![Python](https://img.shields.io/badge/Python-3.11%2B-3776AB?style=flat-square&logo=python&logoColor=white)](https://www.python.org/)
12
+ [![Tests](https://img.shields.io/badge/Tests-13_passed_(Mock_%2B_Live)-16A34A?style=flat-square)](#development--testing)
13
+ [![Ruff](https://img.shields.io/badge/Code_Style-Ruff-D7FF64?style=flat-square&logo=ruff&logoColor=black)](https://docs.astral.sh/ruff/)
14
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue?style=flat-square)](LICENSE)
15
+
16
+ A full-featured [Model Context Protocol (MCP)](https://modelcontextprotocol.io/) server for the **DSSL TRASSIR VMS HTTP/Web SDK**. Enables AI assistants (Claude, Codex, Cursor, Antigravity, etc.) to inspect server health, browse channels and object trees, capture live/archived JPEG frames directly as visual images, control PTZ cameras, navigate and export archive footage, and read real-time server & video analytics events.
17
+
18
+ ---
19
+
20
+ ## Key Features
21
+
22
+ - **Automatic Dual-Session Auth (`sdk` + `user`)**:
23
+ - `TRASSIR_SDK_PASSWORD` (`Script` user rights) is automatically used for `/objects/`, `/classes/`, `/events`, `/lpr_events`, `/pos_events`, `/fr_events`, `/deep_detector`, `/screenshot`, `/ptz`, and `/settings/users/user_add/`.
24
+ - `TRASSIR_USERNAME` + `TRASSIR_PASSWORD` are automatically used for `/channels`, `/get_video`, `/archive_status`, `/archive_command`, and `/archive_events`.
25
+ - **Resilient Session Lifecycle & TLS Compatibility**:
26
+ - Single-flight `sid` refresh under `asyncio.Lock` before TRASSIR's 15-minute idle TTL and on `401` / `invalid sid`, while respecting the 5-second `/login` cooldown.
27
+ - Works out of the box with TRASSIR's self-signed HTTPS certificates and older TLS ciphers (`DEFAULT@SECLEVEL=1` when `TRASSIR_VERIFY_TLS=false`).
28
+ - **Multi-Server & Portable Config Discovery**:
29
+ - Supports multiple TRASSIR servers via `servers.json` / `TRASSIR_SERVERS_JSON` or a single server via `.env` / environment variables.
30
+ - Automatically checks project root, current working directory, and `~/.config/trassir-mcp/`.
31
+ - **Visual Camera Inspection**: `trassir_get_screenshot` returns structured JSON metadata first (`TextContent`) and the raw JPEG frame second (`ImageContent`), supporting both multimodal and text-only clients (`return_image=false`).
32
+ - **Human-Readable TRASSIR Decoders**:
33
+ - Decodes 16-bit channel rights bitmasks, AutoTRASSIR LPR flags, `TimelineEvent` (per-second recording bitmaps), and `ActivityLevelEvent` / `SoundActivityLevelEvent` (per-second intensity 0..15).
34
+ - Event endpoints support both `mode="recent"` (non-blocking last 100 events) and `mode="poll"` (incremental long-poll with bounded timeout).
35
+ - **Mutation Safety Gates**: modifying settings (`trassir_set_setting`), invoking object methods (`trassir_call_object_method`), and creating/deleting users (`trassir_manage_users`) require explicit `confirm=True`.
36
+
37
+ ---
38
+
39
+ ## Supported Media & Export Formats
40
+
41
+ | Workflow | Tool | Formats |
42
+ | :--- | :--- | :--- |
43
+ | **Remote Archive Export (JIT)** | `trassir_jit_export_clip` / `trassir_jit_export_create` | **`.mp4`** (downloaded over HTTP, up to 30 min per task) |
44
+ | **Local Server Archive Export** | `trassir_local_archive_export` | **`.avi`** (`out_format=0`) or proprietary **`.travi`** (`out_format=1`) saved to TRASSIR's `Screenshots` folder; video codecs `""` (passthrough), `MPEG4`, `WMV` (Windows); audio `""`, `No audio`, `PCM`, `WMA` (Windows) |
45
+ | **Live & Archive Streams** | `trassir_open_video_stream` | `mjpeg`, `flv`, `rtsp`, `hls`, `jpeg`, `custom` (audio `ogg`/`aac`) |
46
+ | **Snapshots (Live / Archive)** | `trassir_get_screenshot` | **JPEG** (`image/jpeg`, optional analytics overlays via `figures=true`) |
47
+
48
+ ---
49
+
50
+ ## TRASSIR Server Prerequisites
51
+
52
+ In TRASSIR **Server Settings → Web Server → SDK**:
53
+ 1. Enable **TRASSIR SDK** and the required permission flags (*Object tree, Call methods, Events, POS events, AutoTRASSIR events, Deep Events, Read settings, Screenshots, PTZ, FLV/JPEG/MJPEG*).
54
+ 2. Set an **SDK Password** (uses the built-in `Script` user permissions).
55
+ 3. For `/channels`, `/get_video`, and archive endpoints, enable **Allow connection from mobile/browser** on a dedicated user account with the required channel/archive permissions.
56
+
57
+ ---
58
+
59
+ ## Installation & Configuration
60
+
61
+ ### Quick Run with `uvx`
62
+
63
+ ```bash
64
+ uvx --from git+https://github.com/queukat/trassir-mcp.git trassir-mcp
65
+ ```
66
+
67
+ *(Once published to PyPI, you can also run `uvx trassir-mcp` directly.)*
68
+
69
+ ### Local Installation (`uv` or `pip`)
70
+
71
+ ```bash
72
+ git clone https://github.com/queukat/trassir-mcp.git
73
+ cd trassir-mcp
74
+
75
+ uv venv --python 3.13 .venv
76
+ uv pip install --python .venv/bin/python -e ".[dev]"
77
+ ```
78
+
79
+ ### Environment Variables
80
+
81
+ Create `.env` in the repository root or `~/.config/trassir-mcp/.env` (see [.env.example](.env.example)), or pass variables in your MCP client config:
82
+
83
+ ```env
84
+ TRASSIR_HOST=192.168.1.200
85
+ TRASSIR_PORT=8080
86
+ TRASSIR_STREAM_PORT=555
87
+ TRASSIR_SCHEME=https
88
+ TRASSIR_VERIFY_TLS=false
89
+ TRASSIR_TIMEOUT=15
90
+
91
+ TRASSIR_USERNAME=Admin
92
+ TRASSIR_PASSWORD=your_user_password
93
+ TRASSIR_SDK_PASSWORD=your_sdk_password
94
+ ```
95
+
96
+ For multiple servers, copy [servers.example.json](servers.example.json) to `~/.config/trassir-mcp/servers.json` (or set `TRASSIR_SERVERS_FILE` / `TRASSIR_SERVERS_JSON`).
97
+
98
+ ---
99
+
100
+ ## Connecting to MCP Clients
101
+
102
+ ### Antigravity / Claude Desktop / Cursor (JSON)
103
+
104
+ - Antigravity: `~/.gemini/config/mcp_config.json`
105
+ - Cursor: `.cursor/mcp.json` or `~/.cursor/mcp.json`
106
+ - Claude Desktop: `claude_desktop_config.json`
107
+
108
+ ```json
109
+ {
110
+ "mcpServers": {
111
+ "trassir": {
112
+ "command": "uvx",
113
+ "args": ["--from", "git+https://github.com/queukat/trassir-mcp.git", "trassir-mcp"],
114
+ "env": {
115
+ "TRASSIR_HOST": "192.168.1.200",
116
+ "TRASSIR_PORT": "8080",
117
+ "TRASSIR_USERNAME": "Admin",
118
+ "TRASSIR_PASSWORD": "your_user_password",
119
+ "TRASSIR_SDK_PASSWORD": "your_sdk_password"
120
+ }
121
+ }
122
+ }
123
+ }
124
+ ```
125
+
126
+ ### OpenAI Codex CLI (`~/.codex/config.toml`)
127
+
128
+ ```toml
129
+ [mcp_servers.trassir]
130
+ command = "uvx"
131
+ args = ["--from", "git+https://github.com/queukat/trassir-mcp.git", "trassir-mcp"]
132
+
133
+ [mcp_servers.trassir.env]
134
+ TRASSIR_HOST = "192.168.1.200"
135
+ TRASSIR_PORT = "8080"
136
+ TRASSIR_USERNAME = "Admin"
137
+ TRASSIR_PASSWORD = "your_user_password"
138
+ TRASSIR_SDK_PASSWORD = "your_sdk_password"
139
+ ```
140
+
141
+ ### Claude Code CLI
142
+
143
+ ```bash
144
+ claude mcp add trassir \
145
+ -e TRASSIR_HOST=192.168.1.200 \
146
+ -e TRASSIR_PORT=8080 \
147
+ -e TRASSIR_USERNAME=Admin \
148
+ -e TRASSIR_PASSWORD=your_user_password \
149
+ -e TRASSIR_SDK_PASSWORD=your_sdk_password \
150
+ -- uvx --from git+https://github.com/queukat/trassir-mcp.git trassir-mcp
151
+ ```
152
+
153
+ ---
154
+
155
+ ## Tool Reference
156
+
157
+ ### Tools (32)
158
+
159
+ | Category | Tools |
160
+ | :--- | :--- |
161
+ | **Server & Health** | `trassir_list_servers`, `trassir_login`, `trassir_server_health` |
162
+ | **Channels & Object Tree** | `trassir_list_channels`, `trassir_get_objects`, `trassir_get_object`, `trassir_get_class`, `trassir_call_object_method` |
163
+ | **Settings & Users** | `trassir_get_settings`, `trassir_set_setting`, `trassir_manage_users` |
164
+ | **Screenshots & Streams** | `trassir_get_screenshot`, `trassir_open_video_stream`, `trassir_ping_stream` |
165
+ | **Archive & Export** | `trassir_archive_status`, `trassir_archive_command`, `trassir_archive_events`, `trassir_local_archive_export`, `trassir_local_export_tasks`, `trassir_local_export_cancel`, `trassir_jit_export_create`, `trassir_jit_export_status`, `trassir_jit_export_download`, `trassir_jit_export_cancel`, `trassir_jit_export_clip` |
166
+ | **Events & Analytics** | `trassir_get_events`, `trassir_get_lpr_events`, `trassir_get_pos_events`, `trassir_get_fr_events`, `trassir_get_deep_detector` |
167
+ | **PTZ & Raw SDK** | `trassir_ptz_control`, `trassir_raw_request` |
168
+
169
+ ### Resources & Prompts
170
+
171
+ - **Resources**: `trassir://servers`, `trassir://{server}/channels`, `trassir://{server}/health`, `trassir://{server}/objects`
172
+ - **Prompts**: `investigate_incident`, `server_health_audit`
173
+
174
+ ---
175
+
176
+ ## Development & Testing
177
+
178
+ ```bash
179
+ ruff check .
180
+ pytest -v
181
+ uv build
182
+ ```
183
+
184
+ ## License
185
+
186
+ [MIT](LICENSE)
@@ -0,0 +1,109 @@
1
+ # TRASSIR MCP Server (`trassir-mcp`)
2
+
3
+ > **Язык:** [English](README.md) | **Русский**
4
+
5
+ [![TRASSIR SDK](https://img.shields.io/badge/TRASSIR_SDK-HTTP%2FHTTPS_REST-0A66C2?style=flat-square)](https://trassir.com/)
6
+ [![MCP](https://img.shields.io/badge/MCP-2.0%2B_(stdio_%7C_HTTP)-6D28D9?style=flat-square)](https://modelcontextprotocol.io/)
7
+ [![Tools](https://img.shields.io/badge/Capabilities-32_Tools_%C2%B7_4_Resources_%C2%B7_2_Prompts-059669?style=flat-square)](#справочник-возможностей)
8
+ [![Auth](https://img.shields.io/badge/Auth-Dual--Session_(SDK_%2B_User)-D97706?style=flat-square)](#ключевые-особенности)
9
+ [![Python](https://img.shields.io/badge/Python-3.11%2B-3776AB?style=flat-square&logo=python&logoColor=white)](https://www.python.org/)
10
+ [![Tests](https://img.shields.io/badge/Tests-13_passed_(Mock_%2B_Live)-16A34A?style=flat-square)](#разработка-и-проверка)
11
+ [![Ruff](https://img.shields.io/badge/Code_Style-Ruff-D7FF64?style=flat-square&logo=ruff&logoColor=black)](https://docs.astral.sh/ruff/)
12
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue?style=flat-square)](LICENSE)
13
+
14
+ Полноценный [Model Context Protocol (MCP)](https://modelcontextprotocol.io/) сервер для **DSSL TRASSIR VMS HTTP/Web SDK**. Позволяет AI-ассистентам диагностировать сервер, просматривать каналы и дерево объектов, получать живые и архивные скриншоты напрямую как изображения, управлять PTZ, работать с архивом и экспортировать фрагменты, а также читать события сервера и видеоаналитики.
15
+
16
+ ---
17
+
18
+ ## Ключевые особенности
19
+
20
+ - **Двухсессионная авторизация (`sdk` + `user`)**:
21
+ - `TRASSIR_SDK_PASSWORD` (права `Script`) автоматически используется для `/objects/`, `/classes/`, `/events`, `/lpr_events`, `/pos_events`, `/fr_events`, `/deep_detector`, `/screenshot`, `/ptz`, `/settings/users/user_add/`.
22
+ - `TRASSIR_USERNAME` + `TRASSIR_PASSWORD` автоматически используются для `/channels`, `/get_video`, `/archive_status`, `/archive_command`, `/archive_events`.
23
+ - **Защита от блокировок, гонок и TLS-сюрпризов**:
24
+ - Single-flight обновление `sid` под `asyncio.Lock` до истечения 15-минутного TTL и при `401` / `invalid sid`, плюс соблюдение 5-секундного cooldown на `/login`.
25
+ - Поддержка self-signed сертификатов и `DEFAULT@SECLEVEL=1` для встроенного HTTPS-сервера TRASSIR (при `TRASSIR_VERIFY_TLS=false`).
26
+ - **Мультисерверность и универсальный поиск конфигов**:
27
+ - Поиск `.env` / `servers.json` в корне проекта, текущей директории и `~/.config/trassir-mcp/`, либо через переменные окружения / `TRASSIR_SERVERS_JSON`.
28
+ - **Визуальный анализ**: `trassir_get_screenshot` возвращает JSON-метаданные первым блоком и JPEG-кадр вторым (`ImageContent`), чтобы работали и мультимодальные, и текстовые клиенты (`return_image=false`).
29
+ - **Умный разбор данных TRASSIR**:
30
+ - Декодирование 16-битной маски прав каналов, флагов AutoTRASSIR LPR, `TimelineEvent` (посекундная карта записи) и `ActivityLevelEvent` / `SoundActivityLevelEvent` (уровень активности 0..15 по секундам).
31
+ - События поддерживают `mode="recent"` (последние 100 событий без блокировки) и `mode="poll"` (инкрементальный long-poll с безопасным таймаутом).
32
+ - **Безопасность мутаций**: запись настроек (`trassir_set_setting`), вызов методов объектов (`trassir_call_object_method`) и управление пользователями (`trassir_manage_users`) требуют явного `confirm=True`.
33
+
34
+ ---
35
+
36
+ ## Форматы видео, потоков и экспорта
37
+
38
+ | Сценарий | Инструмент | Поддерживаемые форматы |
39
+ | :--- | :--- | :--- |
40
+ | **Удалённый экспорт архива (JIT)** | `trassir_jit_export_clip` / `trassir_jit_export_create` | **`.mp4`** (скачивается по HTTP, до 30 минут за задачу) |
41
+ | **Локальный экспорт на сервер TRASSIR** | `trassir_local_archive_export` | **`.avi`** (`out_format=0`) или проприетарный **`.travi`** (`out_format=1`) в папку `Screenshots` сервера; видеокодеки `""` (без перекодирования), `MPEG4`, `WMV` (Windows); аудио `""`, `No audio`, `PCM`, `WMA` (Windows) |
42
+ | **Потоки live / archive** | `trassir_open_video_stream` | `mjpeg`, `flv`, `rtsp`, `hls`, `jpeg`, `custom` (аудио `ogg`/`aac`) |
43
+ | **Скриншоты (live / archive)** | `trassir_get_screenshot` | **JPEG** (`image/jpeg`, с фигурами или без) |
44
+
45
+ ---
46
+
47
+ ## Подготовка сервера TRASSIR
48
+
49
+ В настройках сервера (**Веб-сервер -> SDK**):
50
+ 1. Включите **TRASSIR SDK** и нужные разрешения: *Дерево объектов, Вызов методов, События, События POS, События AutoTRASSIR, Deep Events, Чтение настроек, Скриншоты, Управление PTZ, FLV/JPEG/MJPEG*.
51
+ 2. Укажите **Пароль к SDK** (использует права служебного пользователя `Script`).
52
+ 3. Для `/channels`, `/get_video` и архива включите у отдельной служебной учётной записи флаг **Разрешить подключение с мобильного/из браузера** и нужные права на каналы/архив.
53
+
54
+ ---
55
+
56
+ ## Установка и подключение
57
+
58
+ ### Быстрый запуск через `uvx`
59
+
60
+ ```bash
61
+ uvx --from git+https://github.com/queukat/trassir-mcp.git trassir-mcp
62
+ ```
63
+
64
+ ### Локальная установка (`uv` / `pip`)
65
+
66
+ ```bash
67
+ git clone https://github.com/queukat/trassir-mcp.git
68
+ cd trassir-mcp
69
+
70
+ uv venv --python 3.13 .venv
71
+ uv pip install --python .venv/bin/python -e ".[dev]"
72
+ ```
73
+
74
+ Создайте `.env` в корне репозитория или в `~/.config/trassir-mcp/.env` (см. [.env.example](.env.example)), либо передайте переменные в конфиге клиента (см. примеры для Antigravity, Claude Desktop, Claude Code, Cursor и Codex CLI в [README.md](README.md#connecting-to-mcp-clients)).
75
+
76
+ ---
77
+
78
+ ## Справочник возможностей
79
+
80
+ ### Инструменты (32 tools)
81
+
82
+ | Категория | Инструменты |
83
+ | :--- | :--- |
84
+ | **Сервер и здоровье** | `trassir_list_servers`, `trassir_login`, `trassir_server_health` |
85
+ | **Каналы и дерево объектов** | `trassir_list_channels`, `trassir_get_objects`, `trassir_get_object`, `trassir_get_class`, `trassir_call_object_method` |
86
+ | **Настройки и пользователи** | `trassir_get_settings`, `trassir_set_setting`, `trassir_manage_users` |
87
+ | **Скриншоты и видеопотоки** | `trassir_get_screenshot`, `trassir_open_video_stream`, `trassir_ping_stream` |
88
+ | **Архив и экспорт** | `trassir_archive_status`, `trassir_archive_command`, `trassir_archive_events`, `trassir_local_archive_export`, `trassir_local_export_tasks`, `trassir_local_export_cancel`, `trassir_jit_export_create`, `trassir_jit_export_status`, `trassir_jit_export_download`, `trassir_jit_export_cancel`, `trassir_jit_export_clip` |
89
+ | **События и видеоаналитика** | `trassir_get_events`, `trassir_get_lpr_events`, `trassir_get_pos_events`, `trassir_get_fr_events`, `trassir_get_deep_detector` |
90
+ | **PTZ и Raw SDK** | `trassir_ptz_control`, `trassir_raw_request` |
91
+
92
+ ### MCP Resources и Prompts
93
+
94
+ - **Resources**: `trassir://servers`, `trassir://{server}/channels`, `trassir://{server}/health`, `trassir://{server}/objects`
95
+ - **Prompts**: `investigate_incident`, `server_health_audit`
96
+
97
+ ---
98
+
99
+ ## Разработка и проверка
100
+
101
+ ```bash
102
+ ruff check .
103
+ pytest -v
104
+ uv build
105
+ ```
106
+
107
+ ## Лицензия
108
+
109
+ [MIT](LICENSE)