speakdock-mcp 0.0.0-stage → 0.5.0
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.
- package/LICENSE +21 -0
- package/README.md +32 -2
- package/bin/speakdock-mcp.mjs +419 -0
- package/package.json +35 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 SpeakDock contributors
|
|
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.
|
package/README.md
CHANGED
|
@@ -1,3 +1,33 @@
|
|
|
1
|
-
#
|
|
1
|
+
# speakdock-mcp
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Official MCP stdio server for **[SpeakDock](https://github.com/gggoe/SpeakDock)** — cross-host local live voice & screen companion gateway (`127.0.0.1:8780`).
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
```json
|
|
8
|
+
{
|
|
9
|
+
"mcpServers": {
|
|
10
|
+
"sense": {
|
|
11
|
+
"command": "npx",
|
|
12
|
+
"args": ["-y", "speakdock-mcp@latest"],
|
|
13
|
+
"env": {
|
|
14
|
+
"SENSE_GATEWAY_URL": "http://127.0.0.1:8780",
|
|
15
|
+
"SENSE_TARGET": "dsh"
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Tools (8)
|
|
23
|
+
|
|
24
|
+
- `sense_wait` — Wait for next user voice/text message
|
|
25
|
+
- `sense_say` — Speak aloud via gateway TTS & sync to floating dock (`source` selectable)
|
|
26
|
+
- `sense_record` — Append assistant message to dock without speaking
|
|
27
|
+
- `sense_state` — Inspect local gateway health (mic/ASR/TTS/screen)
|
|
28
|
+
- `sense_open_window` — Open SpeakDock floating window
|
|
29
|
+
- `sense_window_style` — Adjust window topmost & opacity
|
|
30
|
+
- `sense_view_upload` — Secure read-only view of user-uploaded images from `/uploads/`
|
|
31
|
+
- `sense_frame` — Capture compressed screen frame on demand
|
|
32
|
+
|
|
33
|
+
Full setup guide: https://github.com/gggoe/SpeakDock
|
|
@@ -0,0 +1,419 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// DSH 侧的「感官网关」客户端(stdio MCP server)。
|
|
3
|
+
//
|
|
4
|
+
// 目的:让 DSH 里的助手能用**共用的**那套语音能力(麦克风 / 说话 / 打断),
|
|
5
|
+
// 而不是各自维护一份。能力本体在本地 SpeakDock Gateway(127.0.0.1:8780),
|
|
6
|
+
// 这个文件只是一层薄壳:把 HTTP 端点包成 4 个工具。
|
|
7
|
+
//
|
|
8
|
+
// 为什么走 MCP 而不是改插件:
|
|
9
|
+
// dsh-see-now 在 node_modules 里,每次升级都会被整包替换(今天已经踩过两次),
|
|
10
|
+
// 而这层薄壳在我们自己的仓库里,升级不会动。
|
|
11
|
+
//
|
|
12
|
+
// 为什么用「工具返回值」而不是别的投递方式:
|
|
13
|
+
// 工具结果不是用户消息 —— 主会话不会因此多出一条可见消息,
|
|
14
|
+
// 但模型拿得到全部文字。这是 Antigravity 那边验证过的同一条路子。
|
|
15
|
+
//
|
|
16
|
+
// 分工(2026-11-29 与哈基米商定):
|
|
17
|
+
// · 听 / 说 / 打断 / 对话流 → 走网关(这个文件)
|
|
18
|
+
// · 看屏幕(挑帧 + 拼图 + token 预算)→ 仍由 dsh-see-now 负责,不在这里重做
|
|
19
|
+
import fs from 'node:fs';
|
|
20
|
+
import path from 'node:path';
|
|
21
|
+
import os from 'node:os';
|
|
22
|
+
|
|
23
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
24
|
+
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
25
|
+
import { z } from 'zod';
|
|
26
|
+
|
|
27
|
+
const BASE = (process.env.SENSE_GATEWAY_URL || 'http://127.0.0.1:8780').replace(/\/+$/, '');
|
|
28
|
+
const DEFAULT_TARGET = process.env.SENSE_TARGET || 'dsh';
|
|
29
|
+
|
|
30
|
+
/** 游标:记住 `/chat/wait` 已经消费到哪个 msg_seq,免得每次都靠我传参。 */
|
|
31
|
+
const CURSOR_FILE = process.env.SENSE_CURSOR_FILE
|
|
32
|
+
|| path.join(os.homedir(), '.speakdock', 'sense-cursor.json');
|
|
33
|
+
|
|
34
|
+
function readCursor(target) {
|
|
35
|
+
try {
|
|
36
|
+
const all = JSON.parse(fs.readFileSync(CURSOR_FILE, 'utf8')) || {};
|
|
37
|
+
return Number(all[target]) || 0;
|
|
38
|
+
} catch {
|
|
39
|
+
return 0;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function writeCursor(target, seq) {
|
|
44
|
+
try {
|
|
45
|
+
let all = {};
|
|
46
|
+
try { all = JSON.parse(fs.readFileSync(CURSOR_FILE, 'utf8')) || {}; } catch { /* 首次 */ }
|
|
47
|
+
all[target] = Number(seq) || 0;
|
|
48
|
+
fs.mkdirSync(path.dirname(CURSOR_FILE), { recursive: true });
|
|
49
|
+
fs.writeFileSync(CURSOR_FILE, JSON.stringify(all, null, 1), 'utf8');
|
|
50
|
+
} catch { /* 游标写不进去不该影响这次调用 */ }
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
async function call(method, pathAndQuery, body, timeoutMs) {
|
|
54
|
+
const url = `${BASE}${pathAndQuery}`;
|
|
55
|
+
const init = { method, signal: AbortSignal.timeout(timeoutMs) };
|
|
56
|
+
if (body !== undefined) {
|
|
57
|
+
init.headers = { 'content-type': 'application/json; charset=utf-8' };
|
|
58
|
+
init.body = Buffer.from(JSON.stringify(body), 'utf8');
|
|
59
|
+
}
|
|
60
|
+
const res = await fetch(url, init);
|
|
61
|
+
const text = await res.text();
|
|
62
|
+
if (!res.ok) {
|
|
63
|
+
throw new Error(`网关 ${res.status}:${text.slice(0, 200)}`);
|
|
64
|
+
}
|
|
65
|
+
try {
|
|
66
|
+
return JSON.parse(text);
|
|
67
|
+
} catch {
|
|
68
|
+
return { raw: text };
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** 统一的失败话术:网关没起是**最常见**的情况,别让它看起来像模型出错。 */
|
|
73
|
+
function failText(err) {
|
|
74
|
+
const msg = String(err?.message ?? err);
|
|
75
|
+
if (/ECONNREFUSED|fetch failed|无法连接/i.test(msg)) {
|
|
76
|
+
return `感官网关没在跑(${BASE})。启动:首次使用请先运行 SpeakDock 的 gateway/scripts/setup.ps1 完成环境初始化,再运行 gateway/scripts/open-window.ps1 启动本机网关与浮窗。`;
|
|
77
|
+
}
|
|
78
|
+
return `感官网关调用失败:${msg}`;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function readMcpVersion() {
|
|
82
|
+
for (const rel of ['../package.json', '../../package.json']) {
|
|
83
|
+
try {
|
|
84
|
+
const p = new URL(rel, import.meta.url);
|
|
85
|
+
const pkg = JSON.parse(fs.readFileSync(p, 'utf8'));
|
|
86
|
+
if (pkg?.version) return String(pkg.version);
|
|
87
|
+
} catch {}
|
|
88
|
+
}
|
|
89
|
+
return '0.5.0';
|
|
90
|
+
}
|
|
91
|
+
const MCP_VERSION = readMcpVersion();
|
|
92
|
+
const server = new McpServer({ name: 'sense-gateway', version: MCP_VERSION });
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* sense_wait —— 阻塞等一句用户输入。
|
|
96
|
+
*
|
|
97
|
+
* 这是整条链的入口:调用它就等于「我现在在听」。网关那边有语音就立刻返回。
|
|
98
|
+
* 默认 25 秒:MCP 工具被宿主判"卡死"的风险随超时线性上升,25 秒足够又不至于过线。
|
|
99
|
+
*/
|
|
100
|
+
server.tool(
|
|
101
|
+
'sense_wait',
|
|
102
|
+
'等用户说下一句(阻塞)。返回他说的话 / 屏幕变化提醒 / 待回执提醒。',
|
|
103
|
+
{
|
|
104
|
+
target: z.string().optional().describe(`取值归属,默认 ${DEFAULT_TARGET}`),
|
|
105
|
+
timeout_sec: z.number().min(1).max(60).optional().describe('等多久,默认 25 秒'),
|
|
106
|
+
after_seq: z.number().optional().describe('从哪条之后开始等;不填就用上次的游标'),
|
|
107
|
+
},
|
|
108
|
+
async ({ target, timeout_sec, after_seq }) => {
|
|
109
|
+
const who = target || DEFAULT_TARGET;
|
|
110
|
+
const since = Number.isFinite(after_seq) ? Number(after_seq) : readCursor(who);
|
|
111
|
+
const seconds = Math.min(60, Math.max(1, Number(timeout_sec) || 25));
|
|
112
|
+
try {
|
|
113
|
+
const data = await call(
|
|
114
|
+
'GET',
|
|
115
|
+
`/chat/wait?after_seq=${since}&target=${encodeURIComponent(who)}&timeout_sec=${seconds}`,
|
|
116
|
+
undefined,
|
|
117
|
+
(seconds + 10) * 1000,
|
|
118
|
+
);
|
|
119
|
+
const nextSeq = Number(data?.next_seq ?? since);
|
|
120
|
+
if (nextSeq !== since) writeCursor(who, nextSeq);
|
|
121
|
+
|
|
122
|
+
const msgs = Array.isArray(data?.messages) ? data.messages : [];
|
|
123
|
+
if (data?.status === 'message' && msgs.length) {
|
|
124
|
+
const lines = msgs.map((m) => {
|
|
125
|
+
const kind = m?.kind || m?.role || 'text';
|
|
126
|
+
// broadcast = 网关按"你们俩/都说说"把同一句同时发给了两个宿主
|
|
127
|
+
const to = m?.broadcast ? ' · 说给你们俩' : '';
|
|
128
|
+
return `「${String(m?.text ?? '').trim()}」(${kind}, seq=${m?.msg_seq}${to})`;
|
|
129
|
+
});
|
|
130
|
+
const both = msgs.some((m) => m?.broadcast);
|
|
131
|
+
return {
|
|
132
|
+
content: [{
|
|
133
|
+
type: 'text',
|
|
134
|
+
text: `[语音·用户] ${lines.join('\n')}\n\n`
|
|
135
|
+
+ '**先说话再干活**:用 `sense_say` 回他(普通回复他听不到)。'
|
|
136
|
+
+ (both ? '\n**这句是同时说给两个助手的** —— 简短回,别抢话。' : '')
|
|
137
|
+
+ '\n要看屏幕仍然用 `see_now`。',
|
|
138
|
+
}],
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
if (data?.status === 'reminder') {
|
|
142
|
+
return {
|
|
143
|
+
content: [{
|
|
144
|
+
type: 'text',
|
|
145
|
+
text: `[待回执] 刚才那句你还没回 —— 用 \`sense_say\` 回一句。${data?.unreplied_reminder ? `(${data.unreplied_reminder})` : ''}`,
|
|
146
|
+
}],
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
if (data?.status === 'screen_changed') {
|
|
150
|
+
return {
|
|
151
|
+
content: [{
|
|
152
|
+
type: 'text',
|
|
153
|
+
text: '[屏幕变了] 网关检测到画面变化。要看就用 `see_now`(挑帧拼图的能力在那边)。',
|
|
154
|
+
}],
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
if (data?.status === 'stop') {
|
|
158
|
+
return { content: [{ type: 'text', text: '[语音会话结束] 用户停了这次的语音会话。' }] };
|
|
159
|
+
}
|
|
160
|
+
return {
|
|
161
|
+
content: [{
|
|
162
|
+
type: 'text',
|
|
163
|
+
text: `[安静] ${seconds} 秒没人说话(status=${data?.status ?? 'idle'})。不用出声,继续等或做别的事。`,
|
|
164
|
+
}],
|
|
165
|
+
};
|
|
166
|
+
} catch (err) {
|
|
167
|
+
return { content: [{ type: 'text', text: failText(err) }], isError: true };
|
|
168
|
+
}
|
|
169
|
+
},
|
|
170
|
+
);
|
|
171
|
+
|
|
172
|
+
/** sense_say —— 说出来(并同步进小窗气泡)。 */
|
|
173
|
+
server.tool(
|
|
174
|
+
'sense_say',
|
|
175
|
+
'让助手用语音说一句话(同时写进小窗气泡)。这是用户在语音里唯一能「听到」的输出。',
|
|
176
|
+
{
|
|
177
|
+
text: z.string().min(1).describe('要念出来的话(建议 60 字以内,念太久会挡住对方说话)'),
|
|
178
|
+
display_text: z.string().optional().describe('气泡里显示的全文;不填就用 text'),
|
|
179
|
+
interrupt: z.boolean().optional().describe('是否打断当前正在播的,默认 true'),
|
|
180
|
+
source: z.string().optional()
|
|
181
|
+
.describe("谁的音色/气泡:dsh(大鲸鱼) / feiyu_qq(肥鱼) / antigravity(哈基米),默认 dsh"),
|
|
182
|
+
},
|
|
183
|
+
async ({ text, display_text, interrupt, source }) => {
|
|
184
|
+
try {
|
|
185
|
+
const r = await call('POST', '/tts', {
|
|
186
|
+
text: String(text),
|
|
187
|
+
display_text: display_text ? String(display_text) : String(text),
|
|
188
|
+
interrupt: interrupt !== false,
|
|
189
|
+
record_chat: true,
|
|
190
|
+
// 网关按 source 分气泡颜色和音色(config.tts_voice_by_source 可再覆盖)。
|
|
191
|
+
// 肥鱼那个会话调这个工具时传 feiyu_qq,才能用她自己的头像和嗓子。
|
|
192
|
+
source: String(source || 'dsh').trim() || 'dsh',
|
|
193
|
+
}, 60_000);
|
|
194
|
+
return { content: [{ type: 'text', text: `已说(${JSON.stringify(r).slice(0, 160)})` }] };
|
|
195
|
+
} catch (err) {
|
|
196
|
+
return { content: [{ type: 'text', text: failText(err) }], isError: true };
|
|
197
|
+
}
|
|
198
|
+
},
|
|
199
|
+
);
|
|
200
|
+
|
|
201
|
+
/** sense_record —— 只记气泡不说话(长总结、不想念出来的内容)。 */
|
|
202
|
+
server.tool(
|
|
203
|
+
'sense_record',
|
|
204
|
+
'把一段话记进小窗气泡,但不念出来。适合长总结/带格式的内容。',
|
|
205
|
+
{
|
|
206
|
+
text: z.string().min(1),
|
|
207
|
+
role: z.enum(['assistant', 'user', 'system']).optional(),
|
|
208
|
+
},
|
|
209
|
+
async ({ text, role }) => {
|
|
210
|
+
try {
|
|
211
|
+
await call('POST', '/chat/send', {
|
|
212
|
+
role: role || 'assistant',
|
|
213
|
+
record_only: true,
|
|
214
|
+
text: String(text),
|
|
215
|
+
target: DEFAULT_TARGET,
|
|
216
|
+
}, 15_000);
|
|
217
|
+
return { content: [{ type: 'text', text: '已记进气泡(没念)。' }] };
|
|
218
|
+
} catch (err) {
|
|
219
|
+
return { content: [{ type: 'text', text: failText(err) }], isError: true };
|
|
220
|
+
}
|
|
221
|
+
},
|
|
222
|
+
);
|
|
223
|
+
|
|
224
|
+
/** sense_state —— 网关健康状态(含抓屏是否可用)。 */
|
|
225
|
+
server.tool(
|
|
226
|
+
'sense_state',
|
|
227
|
+
'看感官网关的健康状态:抓屏能不能用、麦克风在不在跑、TTS 是否在线。',
|
|
228
|
+
{
|
|
229
|
+
probe_frame: z.boolean().optional().describe('顺便实测一次抓屏(慢一点,但准)'),
|
|
230
|
+
},
|
|
231
|
+
async ({ probe_frame }) => {
|
|
232
|
+
try {
|
|
233
|
+
const h = await call('GET', `/health${probe_frame ? '?probe_frame=1' : ''}`, undefined, 20_000);
|
|
234
|
+
// 0.2.0 没有 frame_ok 这个字段 —— 别把「没这个字段」显示成「抓屏坏了」
|
|
235
|
+
const frame = h.frame_ok === undefined
|
|
236
|
+
? '未知(网关 <0.2.1 没有这个字段,用 probe_frame 实测)'
|
|
237
|
+
: (h.frame_ok ? '✅' : `❌${h.frame_error ? `(${String(h.frame_error).slice(0, 80)})` : ''}`);
|
|
238
|
+
const bits = [
|
|
239
|
+
`版本 网关 v${h.version ?? '?'} / MCP v${MCP_VERSION} · pid ${h.pid ?? '?'}`,
|
|
240
|
+
`抓屏 ${frame}`,
|
|
241
|
+
`麦克风 ${h.mic_running ? '在听' : '没开'}`,
|
|
242
|
+
`TTS ${h.voxd_ok ? '在线' : '离线'}${h.tts_speaking ? '(正在说)' : ''}`,
|
|
243
|
+
`当前焦点 ${h?.config?.active_target ?? '?'}`,
|
|
244
|
+
];
|
|
245
|
+
if (h.version && String(h.version) !== MCP_VERSION) {
|
|
246
|
+
bits.push(`⚠️ 版本不一致(网关 v${h.version} vs MCP v${MCP_VERSION}),建议更新并重启网关`);
|
|
247
|
+
}
|
|
248
|
+
return { content: [{ type: 'text', text: bits.join('\n') }] };
|
|
249
|
+
} catch (err) {
|
|
250
|
+
return { content: [{ type: 'text', text: failText(err) }], isError: true };
|
|
251
|
+
}
|
|
252
|
+
},
|
|
253
|
+
);
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* sense_open_window —— 打开**跨宿主统一浮窗**(网关 0.3.1+ 的 Edge --app 窗口)。
|
|
257
|
+
*
|
|
258
|
+
* 为什么要它:以前 DSH 这边要自己拉一个 window.py 读 chat.jsonl,还得靠桥同步;
|
|
259
|
+
* 现在网关直接给一个高颜值浮窗(置顶 / 半透明 / 按 source 分色气泡),
|
|
260
|
+
* DSH 只要叫一声就行,两边看到的是同一个窗口、同一条流。
|
|
261
|
+
*/
|
|
262
|
+
server.tool(
|
|
263
|
+
'sense_open_window',
|
|
264
|
+
'打开跨宿主统一浮窗(置顶 + 半透明的聊天窗,DSH 和哈基米共用同一个)。',
|
|
265
|
+
{
|
|
266
|
+
topmost: z.boolean().optional().describe('是否始终置顶,默认 true'),
|
|
267
|
+
opacity: z.number().min(0.35).max(1).optional().describe('不透明度 0.35~1.0,默认 0.92'),
|
|
268
|
+
},
|
|
269
|
+
async ({ topmost, opacity }) => {
|
|
270
|
+
try {
|
|
271
|
+
const body = { topmost: topmost !== false };
|
|
272
|
+
if (Number.isFinite(opacity)) body.opacity = Number(opacity);
|
|
273
|
+
const r = await call('POST', '/window/open', body, 25_000);
|
|
274
|
+
return { content: [{ type: 'text', text: `浮窗已开:${JSON.stringify(r).slice(0, 200)}` }] };
|
|
275
|
+
} catch (err) {
|
|
276
|
+
return { content: [{ type: 'text', text: failText(err) }], isError: true };
|
|
277
|
+
}
|
|
278
|
+
},
|
|
279
|
+
);
|
|
280
|
+
|
|
281
|
+
/** sense_window_style —— 调置顶 / 透明度(不重开窗,即时生效)。 */
|
|
282
|
+
server.tool(
|
|
283
|
+
'sense_window_style',
|
|
284
|
+
'调浮窗的置顶和透明度(即时生效,不重开)。',
|
|
285
|
+
{
|
|
286
|
+
topmost: z.boolean().optional(),
|
|
287
|
+
opacity: z.number().min(0.35).max(1).optional(),
|
|
288
|
+
},
|
|
289
|
+
async ({ topmost, opacity }) => {
|
|
290
|
+
try {
|
|
291
|
+
const body = {};
|
|
292
|
+
if (typeof topmost === 'boolean') body.topmost = topmost;
|
|
293
|
+
if (Number.isFinite(opacity)) body.opacity = Number(opacity);
|
|
294
|
+
if (!Object.keys(body).length) {
|
|
295
|
+
return { content: [{ type: 'text', text: '没给参数:要么 topmost,要么 opacity(0.35~1.0)。' }] };
|
|
296
|
+
}
|
|
297
|
+
const r = await call('POST', '/window/style', body, 10_000);
|
|
298
|
+
return { content: [{ type: 'text', text: `已调整:${JSON.stringify(r).slice(0, 160)}` }] };
|
|
299
|
+
} catch (err) {
|
|
300
|
+
return { content: [{ type: 'text', text: failText(err) }], isError: true };
|
|
301
|
+
}
|
|
302
|
+
},
|
|
303
|
+
);
|
|
304
|
+
|
|
305
|
+
/** sense_view_upload —— 安全只读查看用户在浮窗上传/粘贴的图片(仅限网关 /uploads/ 目录,不触碰本机其他文件)。 */
|
|
306
|
+
server.tool(
|
|
307
|
+
'sense_view_upload',
|
|
308
|
+
'查看用户在浮窗里 Ctrl+V 粘贴或上传的图片(安全只读,仅限感官网关 /uploads/ 下的单层文件名)。',
|
|
309
|
+
{
|
|
310
|
+
filename: z.string().min(1).describe('网关上传文件名,例如 1795967304309_c5670db2.png'),
|
|
311
|
+
},
|
|
312
|
+
async ({ filename }) => {
|
|
313
|
+
const clean = String(filename || '').trim().replace(/^\/?uploads\//, '');
|
|
314
|
+
if (!/^[A-Za-z0-9._-]+$/.test(clean)) {
|
|
315
|
+
return { content: [{ type: 'text', text: '非法文件名(仅允许单层上传图片名)' }], isError: true };
|
|
316
|
+
}
|
|
317
|
+
try {
|
|
318
|
+
const ac = new AbortController();
|
|
319
|
+
const t = setTimeout(() => ac.abort(), 12_000);
|
|
320
|
+
try {
|
|
321
|
+
const res = await fetch(`${BASE}/uploads/${encodeURIComponent(clean)}`, { signal: ac.signal });
|
|
322
|
+
if (!res.ok) {
|
|
323
|
+
return { content: [{ type: 'text', text: `读取图片失败:HTTP ${res.status}` }], isError: true };
|
|
324
|
+
}
|
|
325
|
+
const mimeType = (res.headers.get('content-type') || 'image/png').split(';')[0].trim();
|
|
326
|
+
// 只收图片:网关是本地服务,但 content-type 仍然不可信(可能是 text/html 之类)
|
|
327
|
+
if (!/^image\//i.test(mimeType)) {
|
|
328
|
+
return { content: [{ type: 'text', text: `不是图片(content-type=${mimeType}),已拒绝` }], isError: true };
|
|
329
|
+
}
|
|
330
|
+
const buf = Buffer.from(await res.arrayBuffer());
|
|
331
|
+
// 上限 8MB:base64 会膨胀 1/3,再大就既吃内存又吃上下文预算
|
|
332
|
+
const MAX_BYTES = 8 * 1024 * 1024;
|
|
333
|
+
if (buf.length > MAX_BYTES) {
|
|
334
|
+
return {
|
|
335
|
+
content: [{
|
|
336
|
+
type: 'text',
|
|
337
|
+
text: `图片 ${(buf.length / 1024 / 1024).toFixed(1)}MB,超过 ${MAX_BYTES / 1024 / 1024}MB 上限,已拒绝(先压缩再传)`,
|
|
338
|
+
}],
|
|
339
|
+
isError: true,
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
return {
|
|
343
|
+
content: [
|
|
344
|
+
{ type: 'text', text: `已加载浮窗上传图片 ${clean} (${buf.length} bytes)` },
|
|
345
|
+
{ type: 'image', data: buf.toString('base64'), mimeType },
|
|
346
|
+
],
|
|
347
|
+
};
|
|
348
|
+
} finally {
|
|
349
|
+
clearTimeout(t);
|
|
350
|
+
}
|
|
351
|
+
} catch (err) {
|
|
352
|
+
return { content: [{ type: 'text', text: failText(err) }], isError: true };
|
|
353
|
+
}
|
|
354
|
+
},
|
|
355
|
+
);
|
|
356
|
+
|
|
357
|
+
/**
|
|
358
|
+
* sense_frame —— 看屏幕(走网关 `/frame`,0.4.1+ 支持「挑变化最大的几帧拼一张」)。
|
|
359
|
+
*
|
|
360
|
+
* 为什么不让肥鱼继续用老的 see_now:
|
|
361
|
+
* 那套会拉起 window.py 弹窗(一被唤醒就弹),而且窗口/语音是绑在一起的。
|
|
362
|
+
* 这里只要一张图,走 HTTP 就行,零弹窗。
|
|
363
|
+
*
|
|
364
|
+
* token 口径(和 see-now 一致,42px 一格):
|
|
365
|
+
* 798×462 ≈ 222 token(4–6 帧拼图)
|
|
366
|
+
* 720×405 ≈ 192 token(更省,格子小一点)
|
|
367
|
+
* 带 region 时是局部裁剪,适合读小字(整屏压到 399×231 之后字就糊了)。
|
|
368
|
+
*/
|
|
369
|
+
server.tool(
|
|
370
|
+
'sense_frame',
|
|
371
|
+
'看屏幕:抓当前一帧,或把变化最大的几帧拼成一张(走感官网关 /frame,省 token)。',
|
|
372
|
+
{
|
|
373
|
+
frames: z.number().min(1).max(6).optional().describe('拼几帧,默认 4;1 = 只抓当前一帧'),
|
|
374
|
+
region: z.string().optional().describe('只看一块:x,y,w,h(屏幕物理像素,用来读小字)'),
|
|
375
|
+
width: z.number().optional().describe('画布宽,默认 798'),
|
|
376
|
+
height: z.number().optional().describe('画布高,默认 462'),
|
|
377
|
+
},
|
|
378
|
+
async ({ frames, region, width, height }) => {
|
|
379
|
+
const n = Math.min(6, Math.max(1, Math.trunc(Number(frames) || 4)));
|
|
380
|
+
const w = Math.max(200, Math.min(1600, Math.trunc(Number(width) || 798)));
|
|
381
|
+
const h = Math.max(120, Math.min(1200, Math.trunc(Number(height) || 462)));
|
|
382
|
+
const qs = new URLSearchParams({
|
|
383
|
+
pack: 'grid',
|
|
384
|
+
frames: String(n),
|
|
385
|
+
cols: '2',
|
|
386
|
+
w: String(w),
|
|
387
|
+
h: String(h),
|
|
388
|
+
base64: '1',
|
|
389
|
+
});
|
|
390
|
+
if (region) qs.set('region', String(region).trim());
|
|
391
|
+
try {
|
|
392
|
+
const data = await call('GET', `/frame?${qs.toString()}`, undefined, 30_000);
|
|
393
|
+
if (!data?.ok || !data?.base64) {
|
|
394
|
+
return {
|
|
395
|
+
content: [{ type: 'text', text: `抓屏失败:${JSON.stringify(data).slice(0, 200)}` }],
|
|
396
|
+
isError: true,
|
|
397
|
+
};
|
|
398
|
+
}
|
|
399
|
+
const list = Array.isArray(data.frames) ? data.frames : [];
|
|
400
|
+
const meta = list
|
|
401
|
+
.map((f) => `${f.time ?? '?'}${Number.isFinite(Number(f.diff)) ? `(Δ${Number(f.diff).toFixed(2)})` : ''}`)
|
|
402
|
+
.join(' / ');
|
|
403
|
+
const head = `${data.width}x${data.height} · 约 ${data.token_est ?? '?'} token · ${list.length} 帧`
|
|
404
|
+
+ (meta ? ` · ${meta}` : '')
|
|
405
|
+
+ (region ? ` · 局部 ${region}` : '');
|
|
406
|
+
return {
|
|
407
|
+
content: [
|
|
408
|
+
{ type: 'text', text: head },
|
|
409
|
+
{ type: 'image', data: String(data.base64), mimeType: 'image/jpeg' },
|
|
410
|
+
],
|
|
411
|
+
};
|
|
412
|
+
} catch (err) {
|
|
413
|
+
return { content: [{ type: 'text', text: failText(err) }], isError: true };
|
|
414
|
+
}
|
|
415
|
+
},
|
|
416
|
+
);
|
|
417
|
+
|
|
418
|
+
const transport = new StdioServerTransport();
|
|
419
|
+
await server.connect(transport);
|
package/package.json
CHANGED
|
@@ -1,6 +1,38 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "speakdock-mcp",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.5.0",
|
|
4
|
+
"description": "MCP stdio bridge for SpeakDock — cross-host local live voice & screen companion gateway (Windows 10/11).",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"mcp",
|
|
7
|
+
"model-context-protocol",
|
|
8
|
+
"speakdock",
|
|
9
|
+
"dsh",
|
|
10
|
+
"voice",
|
|
11
|
+
"tts",
|
|
12
|
+
"asr",
|
|
13
|
+
"screen-companion"
|
|
14
|
+
],
|
|
15
|
+
"type": "module",
|
|
16
|
+
"bin": {
|
|
17
|
+
"speakdock-mcp": "./bin/speakdock-mcp.mjs"
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"bin",
|
|
21
|
+
"README.md",
|
|
22
|
+
"LICENSE"
|
|
23
|
+
],
|
|
24
|
+
"engines": {
|
|
25
|
+
"node": ">=18"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@modelcontextprotocol/sdk": "^1.0.0",
|
|
29
|
+
"zod": "^3.23.0"
|
|
30
|
+
},
|
|
31
|
+
"license": "MIT",
|
|
32
|
+
"repository": {
|
|
33
|
+
"type": "git",
|
|
34
|
+
"url": "git+https://github.com/gggoe/SpeakDock.git",
|
|
35
|
+
"directory": "packages/speakdock-mcp"
|
|
36
|
+
},
|
|
37
|
+
"homepage": "https://github.com/gggoe/SpeakDock#readme"
|
|
6
38
|
}
|