Skip to content

DeepSeek Harness Tauri 桌面版 | Only 8mb installer, zero environment setup, preset plugins, Windows / macOS / Linux.

fix(dsh-tauri-panel-extension): MCP stdio 源归一为 command + args

hairyf0f26f5cbeebd
diff --git a/packages/dsh-tauri-panel-extension/src/host/service/mcp.ts b/packages/dsh-tauri-panel-extension/src/host/service/mcp.ts
index bcbc02a6..61ba52b8 100644
--- a/packages/dsh-tauri-panel-extension/src/host/service/mcp.ts
+++ b/packages/dsh-tauri-panel-extension/src/host/service/mcp.ts
@@ -11,6 +11,7 @@ import {
loadPatch,
managedInsert,
mcpRowItems,
+ normalizeStdioCommand,
readRows,
rowSeq,
savePatch,
@@ -66,12 +67,13 @@ export const mcp = defineService({
id = `mcp-${input.serverName}-${suffix++}`
}
+ const stdio = normalizeStdioCommand(input.command ?? '', input.args)
const config: Record<string, unknown> = input.transport === 'stdio'
? {
serverName: input.serverName,
transport: input.transport,
- command: input.command,
- ...(!isEmpty(input.args) ? { args: input.args } : {}),
+ command: stdio.command,
+ ...(!isEmpty(stdio.args) ? { args: stdio.args } : {}),
...(!isEmpty(input.env) ? { env: input.env } : {}),
...(!isEmpty(input.cwd) ? { cwd: input.cwd } : {}),
}
diff --git a/packages/dsh-tauri-panel-extension/src/host/service/mcp.utils.test.ts b/packages/dsh-tauri-panel-extension/src/host/service/mcp.utils.test.ts
new file mode 100644
index 00000000..29cb3924
--- /dev/null
+++ b/packages/dsh-tauri-panel-extension/src/host/service/mcp.utils.test.ts
@@ -0,0 +1,62 @@
+import { mkdtempSync, readFileSync, writeFileSync } from 'node:fs'
+import { tmpdir } from 'node:os'
+import { join } from 'node:path'
+import { describe, expect, it } from 'vitest'
+import { mcp } from './mcp'
+import { normalizeStdioCommand, splitCommandLine } from './mcp.utils'
+
+describe('splitCommandLine', () => {
+ it('keeps quoted segments intact', () => {
+ expect(splitCommandLine('"C:/Program Files/node.exe" --experimental')).toEqual(['C:/Program Files/node.exe', '--experimental'])
+ expect(splitCommandLine('\'a b\' c')).toEqual(['a b', 'c'])
+ })
+
+ it('drops empty segments', () => {
+ expect(splitCommandLine(' npx -y ')).toEqual(['npx', '-y'])
+ })
+})
+
+describe('normalizeStdioCommand', () => {
+ it('splits a whole command line into command and args', () => {
+ expect(normalizeStdioCommand('npx -y @heroui/react-mcp@latest', undefined))
+ .toEqual({ command: 'npx', args: ['-y', '@heroui/react-mcp@latest'] })
+ })
+
+ it('splits when args is present but empty', () => {
+ expect(normalizeStdioCommand('npx -y @heroui/react-mcp@latest', []))
+ .toEqual({ command: 'npx', args: ['-y', '@heroui/react-mcp@latest'] })
+ })
+
+ it('keeps explicit args untouched', () => {
+ expect(normalizeStdioCommand('npx', ['-y', '@heroui/react-mcp@latest']))
+ .toEqual({ command: 'npx', args: ['-y', '@heroui/react-mcp@latest'] })
+ })
+
+ it('leaves a bare executable alone', () => {
+ expect(normalizeStdioCommand('node', undefined)).toEqual({ command: 'node' })
+ expect(normalizeStdioCommand('', undefined)).toEqual({ command: '' })
+ })
+
+ it('leaves an existing path containing spaces alone', () => {
+ const dir = mkdtempSync(join(tmpdir(), 'dsh mcp '))
+ const executable = join(dir, 'my server.exe')
+ writeFileSync(executable, '')
+ expect(normalizeStdioCommand(executable, undefined)).toEqual({ command: executable })
+ })
+})
+
+describe('mcp.save', () => {
+ it('persists a whole command line as command plus args', () => {
+ const dir = mkdtempSync(join(tmpdir(), 'dsh-mcp-save-'))
+ mcp.save(dir, {
+ id: '',
+ serverName: 'heroui-react',
+ transport: 'stdio',
+ command: 'npx -y @heroui/react-mcp@latest',
+ })
+ const patch = readFileSync(join(dir, 'cordis.patch.yml'), 'utf8')
+ expect(patch).toContain('command: npx')
+ expect(patch).not.toContain('npx -y @heroui')
+ expect(patch).toContain('@heroui/react-mcp@latest')
+ })
+})
diff --git a/packages/dsh-tauri-panel-extension/src/host/service/mcp.utils.ts b/packages/dsh-tauri-panel-extension/src/host/service/mcp.utils.ts
index 7cdb2548..3a0a3aad 100644
--- a/packages/dsh-tauri-panel-extension/src/host/service/mcp.utils.ts
+++ b/packages/dsh-tauri-panel-extension/src/host/service/mcp.utils.ts
@@ -11,6 +11,39 @@ const SERVER_NAME_RE = /^[\w-]{1,32}$/
const EMPTY_PATCH = '[]'
+const COMMAND_TOKEN_RE = /"([^"]*)"|'([^']*)'|(\S+)/g
+
+/** 按 shell 习惯切 token,保留引号内的空格(`"C:/Program Files/node.exe" --flag`)。 */
+export function splitCommandLine(line: string): string[] {
+ const tokens: string[] = []
+ for (const match of line.matchAll(COMMAND_TOKEN_RE)) {
+ const token = match[1] ?? match[2] ?? match[3]
+ if (token !== undefined && token !== '')
+ tokens.push(token)
+ }
+ return tokens
+}
+
+/**
+ * 把 stdio 源归一成内核契约(`command` 是可执行文件,参数进 `args`)。
+ *
+ * Cursor 等客户端会把整条命令行塞进 `command`(`args` 留空),内核拿它当可执行文件
+ * spawn,条目必然起不来;写入侧拆开,历史条目读出来也走同一条归一。
+ * 显式给了 args、或本身就是一个存在的路径(含空格,如 Program Files)时原样保留。
+ */
+export function normalizeStdioCommand(command: string, args: readonly string[] | undefined): { command: string, args?: string[] } {
+ const given = args ?? []
+ if (given.length > 0)
+ return { command, args: [...given] }
+ const trimmed = command.trim()
+ if (trimmed === '' || !/\s/.test(trimmed) || existsSync(trimmed))
+ return { command }
+ const [head, ...rest] = splitCommandLine(trimmed)
+ if (head === undefined)
+ return { command }
+ return rest.length === 0 ? { command: head } : { command: head, args: rest }
+}
+
export function normalizeMcpScope(value: unknown): McpScope {
return value === 'global' ? 'global' : 'profile'
}