The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.
TypeScript agentai-chatai-studioall-in-onecoding-agentdesktop-appfluximage-generationlinuxllmlocal-ailocal-llmopen-sourceprivacyself-hostedstable-diffusionuncensoreduncensored-aivideo-generationwindows
fix(mcp): parse server arguments with shell-like quoting
purple7dbb736b3d31
diff --git a/src/components/settings/MCPServerSettings.tsx b/src/components/settings/MCPServerSettings.tsxindex e8a9a2f0..6abef27e 100644--- a/src/components/settings/MCPServerSettings.tsx+++ b/src/components/settings/MCPServerSettings.tsx@@ -4,6 +4,7 @@ import { Plus, Trash2, Power, PowerOff, Pencil } from 'lucide-react'import { useMCPStore } from '../../stores/mcpStore'import { toolRegistry } from '../../api/mcp'import type { MCPServerConfig } from '../../api/mcp/types'+import { joinArgs, parseArgs } from '../../lib/mcp-args'// `import type` und nicht `import`: die Klasse wird unten bewusst dynamisch// geladen, damit der Tauri-Import im Dev-Modus nicht mitkommt. Ein Typ-Import// wird beim Uebersetzen geloescht und erzeugt keine Laufzeit-Abhaengigkeit —@@ -67,7 +68,7 @@ export function MCPServerSettings() {setEditingId(server.id)setFormName(server.name)setFormCommand(server.command)- setFormArgs(server.args.join(' '))+ setFormArgs(joinArgs(server.args))setError(null)setShowAddForm(true)}@@ -77,7 +78,7 @@ export function MCPServerSettings() {const felder = {name: formName.trim(),command: formCommand.trim(),- args: formArgs.trim() ? formArgs.trim().split(' ') : [],+ args: parseArgs(formArgs),}if (editingId) {// Ein laufender Server traegt noch den alten Befehl. Ihn stehen zu@@ -208,7 +209,7 @@ export function MCPServerSettings() {<div className="flex-1 min-w-0"><p className="text-[0.7rem] text-gray-300 font-medium">{server.name}</p><p className="text-[0.55rem] text-gray-600 font-mono truncate">- {server.command} {server.args.join(' ')}+ {server.command} {joinArgs(server.args)}</p></div>@@ -296,7 +297,7 @@ export function MCPServerSettings() {<inputvalue={formArgs}onChange={(e) => setFormArgs(e.target.value)}- placeholder="Args (e.g. -y @modelcontextprotocol/server-filesystem /path)"+ placeholder='Args (e.g. -y @modelcontextprotocol/server-filesystem "/My Folder")'className="w-full px-2 py-1 rounded bg-white/5 border border-white/10 text-[0.65rem] text-gray-300 placeholder-gray-600 font-mono focus:border-white/20 outline-none"/><div className="flex gap-1.5">diff --git a/src/components/settings/__tests__/mcp-args-keep-spaces-and-quotes.test.tsx b/src/components/settings/__tests__/mcp-args-keep-spaces-and-quotes.test.tsxnew file mode 100644index 00000000..b630ef28--- /dev/null+++ b/src/components/settings/__tests__/mcp-args-keep-spaces-and-quotes.test.tsx@@ -0,0 +1,64 @@+/**+ * @vitest-environment jsdom+ *+ * Settings, Agent, MCP Servers (Jaeger B, B8): the Arguments field was split+ * on single spaces. A path with spaces could not be passed at all (the quotes+ * became part of two broken arguments) and a double space produced an empty+ * argument, so the server exited on Connect while the row looked right. Edit+ * joined with spaces and Save split again, repeating the damage.+ *+ * Run: npx vitest run src/components/settings/__tests__/mcp-args-keep-spaces-and-quotes.test.tsx+ */+import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest'+import { createElement } from 'react'+import { render, screen, cleanup, fireEvent } from '@testing-library/react'++vi.mock('../../../api/mcp/external-client', () => ({ MCPExternalClient: class {} }))++const { MCPServerSettings } = await import('../MCPServerSettings')+const { useMCPStore } = await import('../../../stores/mcpStore')++const argsInput = () => screen.getByPlaceholderText(/^Args/) as HTMLInputElement+const savedArgs = () => useMCPStore.getState().servers.map((s) => s.args)++function addServer(args: string) {+ fireEvent.click(screen.getByText('Add MCP Server'))+ fireEvent.change(screen.getByPlaceholderText('Server name'), { target: { value: 'fs' } })+ fireEvent.change(screen.getByPlaceholderText(/^Command/), { target: { value: 'npx' } })+ fireEvent.change(argsInput(), { target: { value: args } })+ fireEvent.click(screen.getByText('Add Server'))+}++beforeEach(() => {+ useMCPStore.setState({ servers: [], connectedServers: [], serverTools: {} })+})+afterEach(() => cleanup())++describe('MCP server arguments', () => {+ it('double quotes keep a path with spaces in one argument', () => {+ render(createElement(MCPServerSettings))+ addServer('--yes "/Users/me/Application Support/pkg space" 0')+ expect(savedArgs()).toEqual([['--yes', '/Users/me/Application Support/pkg space', '0']])+ })++ it('single quotes group too, and runs of whitespace give no empty argument', () => {+ render(createElement(MCPServerSettings))+ addServer(" --yes '/My Tools/pkg'\t0 ")+ expect(savedArgs()).toEqual([['--yes', '/My Tools/pkg', '0']])+ })++ it('a Windows path keeps its backslashes', () => {+ render(createElement(MCPServerSettings))+ addServer('-y C:\\Tools\\server.js')+ expect(savedArgs()).toEqual([['-y', 'C:\\Tools\\server.js']])+ })++ it('Edit then Save keeps the saved list unchanged', () => {+ const args = ['--yes', '/My Tools/pkg', "it's", 'say "hi"', '', 'plain']+ useMCPStore.setState({ servers: [{ id: 'e1', name: 'fs', command: 'npx', args, enabled: true }] })+ render(createElement(MCPServerSettings))+ fireEvent.click(screen.getByTitle('Edit server'))+ fireEvent.click(screen.getByText('Save Changes'))+ expect(savedArgs()).toEqual([args])+ })+})diff --git a/src/lib/mcp-args.ts b/src/lib/mcp-args.tsnew file mode 100644index 00000000..644148dd--- /dev/null+++ b/src/lib/mcp-args.ts@@ -0,0 +1,59 @@+/**+ * The Arguments field of an MCP server is one line of text, but the server+ * receives a list. Splitting on a single space made a path with spaces+ * impossible ("Application Support", "My Tools") and turned a double space+ * into an empty argument that stopped the server from starting.+ *+ * Simple shell-like rules: runs of whitespace separate arguments, "..." and+ * '...' group text with spaces into one argument, and inside "..." only \"+ * and \\ are escapes. Outside quotes a backslash is a plain character, so+ * a Windows path like C:\Tools\server.js arrives as typed. No variables, no+ * globbing. `joinArgs` is the reverse, so opening a saved server for editing+ * and saving it again keeps the list unchanged.+ */+export function parseArgs(line: string): string[] {+ const out: string[] = []+ let cur = ''+ let has = false+ let quote: '"' | "'" | null = null+ for (let i = 0; i < line.length; i++) {+ const c = line[i]+ if (quote === "'") {+ if (c === "'") quote = null+ else cur += c+ continue+ }+ if (quote === '"') {+ if (c === '\\' && (line[i + 1] === '"' || line[i + 1] === '\\')) cur += line[++i]+ else if (c === '"') quote = null+ else cur += c+ continue+ }+ if (c === '"' || c === "'") {+ quote = c+ has = true+ continue+ }+ if (/\s/.test(c)) {+ if (has) out.push(cur)+ cur = ''+ has = false+ continue+ }+ cur += c+ has = true+ }+ if (has) out.push(cur)+ return out+}++/** Quote one argument only when it needs it, so plain args stay readable. */+function quoteArg(arg: string): string {+ if (arg !== '' && !/[\s"']/.test(arg)) return arg+ if (!arg.includes("'")) return `'${arg}'`+ return `"${arg.replace(/[\\"]/g, (m) => `\\${m}`)}"`+}++export function joinArgs(args: string[]): string {+ return args.map(quoteArg).join(' ')+}