# bridge **Repository Path**: no1wudi/bridge ## Basic Information - **Project Name**: bridge - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-04-16 - **Last Updated**: 2026-04-16 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # IPC Bridge MCP (Model Context Protocol) 与 IPC 设备之间的 TCP 桥接服务。 ## 架构 ``` MCP Client <--HTTP:3000--> Bridge Server <--TCP:9000--> IPC Device (C) ``` ## 目录结构 ``` bridge/ ├── README.md # 本文档 ├── package.json ├── tsconfig.json ├── client/ # IPC 设备客户端 │ └── ipc_client.c └── src/ # Bridge Server ├── index.ts # HTTP 服务器入口 ├── mcp.ts # MCP 协议处理 ├── protocol.ts # JSON Lines 编解码 ├── tcp.ts # TCP 服务器 ├── types.ts # 类型定义 └── tools/ ├── ptz-move.ts # PTZ 控制工具 └── take-photo.ts ``` ## 快速开始 ### 启动 Server ```bash npm install npm start ``` ### 编译并运行 Client ```bash cd client gcc -o ipc_client ipc_client.c ./ipc_client kimoju.art 9000 ``` ## IPC JSON RPC 协议 ### 传输 - TCP 连接 `kimoju.art:9000` - JSON Lines 格式: `{json}\n` ### 请求格式 ```json {"id":"","method":"","params":{...}} ``` ### 响应格式 ```json {"id":"","result":{...}} ``` 错误响应: ```json {"id":"","error":{"code":-32601,"message":"Method not found"}} ``` ## 方法 ### ptz_move 控制摄像头 PTZ (Pan-Tilt-Zoom) 运动。 **请求参数:** | 参数 | 类型 | 范围 | 说明 | |------|------|------|------| | pan | int | 0-360 | 水平角度 | | tilt | int | -90~90 | 垂直角度 | **响应字段:** | 字段 | 类型 | 说明 | |------|------|------| | actual_pan | int | 实际水平角度 | | actual_tilt | int | 实际垂直角度 | **示例:** ```json // 请求 {"id":"1","method":"ptz_move","params":{"pan":180,"tilt":45}} // 响应 {"id":"1","result":{"actual_pan":180,"actual_tilt":45}} ``` ### take_photo 拍照并返回图像数据。 **请求参数:** 无 **响应字段:** | 字段 | 类型 | 必填 | 说明 | |------|------|------|------| | image_data | string | 是 | base64 JPEG 图片数据 | | timestamp | int | 否 | 拍照时间戳 | | angle | object | 否 | 拍照时角度 {pan, tilt} | **示例:** ```json // 请求 {"id":"2","method":"take_photo"} // 响应 {"id":"2","result":{"image_data":"/9j/4AAQ...","timestamp":1713250000,"angle":{"pan":180,"tilt":45}}} ``` ## 错误码 | 错误码 | 说明 | |--------|------| | -32600 | Invalid Request | | -32601 | Method not found | | -32700 | Parse error | ## 交互流程 ``` IPC Device Bridge Server | | |------- TCP Connect --------->| |<------ TCP Accept ------------| | | |<-- {"id":"1","method":"ptz_move", | | "params":{"pan":180, | | "tilt":45}} ------| | | |--> {"id":"1", | | "result":{"actual_pan":180,| | "actual_tilt":45}}| | | |<-- {"id":"2","method":"take_photo"}| | | |--> {"id":"2", | | "result":{"image_data": | | "...","timestamp":...}} | ```