Skip to content

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

fix(panel-extension): satisfy CI lint

hairyf7f4fc95d94ad
diff --git a/packages/dsh-tauri-panel-extension/src/client/components/mcp-tab.tsx b/packages/dsh-tauri-panel-extension/src/client/components/mcp-tab.tsx
index dbe06d6c..047a0f17 100644
--- a/packages/dsh-tauri-panel-extension/src/client/components/mcp-tab.tsx
+++ b/packages/dsh-tauri-panel-extension/src/client/components/mcp-tab.tsx
@@ -334,7 +334,11 @@ export function McpTab({ t }: McpTabProps): ReactElement {
<div className="dshp-extension__list-head">
<h3>{t('mcpTab')}</h3>
{servers !== null && <span className="dshp-extension__count">{servers.length}</span>}
- <select aria-label={t('scope')} value={scope} onChange={event => setScope(event.target.value as typeof scope)}><option value="all">{t('scopeAll')}</option><option value="global">{t('global')}</option><option value="profile">{t('profile')}</option></select>
+ <select aria-label={t('scope')} value={scope} onChange={event => setScope(event.target.value as typeof scope)}>
+ <option value="all">{t('scopeAll')}</option>
+ <option value="global">{t('global')}</option>
+ <option value="profile">{t('profile')}</option>
+ </select>
<span className="dshp-extension__spacer" />
<button type="button" className="dshp-extension__refresh" aria-label={t('view')} title={t('view')} disabled={busy} onClick={() => setReload(value => value + 1)}>
<Icon as={ArrowRotateRight} />
@@ -356,9 +360,15 @@ export function McpTab({ t }: McpTabProps): ReactElement {
<p className="dshp-extension__card-desc">
{row.transport === 'stdio' ? `${row.command ?? ''} ${(row.args ?? []).join(' ')}` : row.url ?? ''}
</p>
- {row.shadowed === true && <p className="dshp-extension__form-error">{t('shadowedByGlobal')}</p>}\n {row.globalError !== undefined && <p className="dshp-extension__form-error">{row.globalError}</p>}\n <div className="dshp-extension__card-row">
+ {row.shadowed === true && <p className="dshp-extension__form-error">{t('shadowedByGlobal')}</p>}
+ \n
+ {row.globalError !== undefined && <p className="dshp-extension__form-error">{row.globalError}</p>}
+ \n
+ <div className="dshp-extension__card-row">
<span className="dshp-extension__spacer" />
- <Button variant="ghost" size="sm" disabled={busy || checking === row.id} onClick={() => void checkConnectivity(row)}>{checking === row.id ? t('checkRunning') : t('checkLabel')}</Button>\n <Button variant="ghost" size="sm" disabled={busy} onClick={() => void doToggle(row)}>{t('toggle')}</Button>
+ <Button variant="ghost" size="sm" disabled={busy || checking === row.id} onClick={() => void checkConnectivity(row)}>{checking === row.id ? t('checkRunning') : t('checkLabel')}</Button>
+ \n
+ <Button variant="ghost" size="sm" disabled={busy} onClick={() => void doToggle(row)}>{t('toggle')}</Button>
<Button variant="ghost" size="sm" disabled={busy} onClick={() => openEdit(row)}>{t('edit')}</Button>
<Button variant="ghost" size="sm" disabled={busy} onClick={() => setConfirmId(row.id)}>{t('delete')}</Button>
</div>
diff --git a/packages/dsh-tauri-panel-extension/src/client/locales/index.ts b/packages/dsh-tauri-panel-extension/src/client/locales/index.ts
index 151e53fe..500b22b0 100644
--- a/packages/dsh-tauri-panel-extension/src/client/locales/index.ts
+++ b/packages/dsh-tauri-panel-extension/src/client/locales/index.ts
@@ -101,7 +101,14 @@ const zh: Record<string, string> = {
formatPaste: '粘贴 JSON 配置(mcpServers 包装或单条目均可)',
formatFill: '解析并切换到表单',
pasteTransportMismatch: '该行传输方式已锁定,与粘贴配置不一致。',
- scope: '范围', scopeAll: '全部', global: '全局', profile: 'Profile', shadowed: '已覆盖', globalError: '全局错误', connectivityOk: '连接成功', connectivityFailed: '连接失败',
+ scope: '范围',
+ scopeAll: '全部',
+ global: '全局',
+ profile: 'Profile',
+ shadowed: '已覆盖',
+ globalError: '全局错误',
+ connectivityOk: '连接成功',
+ connectivityFailed: '连接失败',
}
const en: Record<string, string> = {
diff --git a/packages/dsh-tauri-panel-extension/src/host/routes/mcp.ts b/packages/dsh-tauri-panel-extension/src/host/routes/mcp.ts
index 6aea0868..a62fe6dc 100644
--- a/packages/dsh-tauri-panel-extension/src/host/routes/mcp.ts
+++ b/packages/dsh-tauri-panel-extension/src/host/routes/mcp.ts
@@ -203,33 +203,63 @@ export function registerMcpRoutes(
}))
disposers.push(register({
- kind: 'exact', path: `${API_PREFIX}/mcp/check`,
+ kind: 'exact',
+ path: `${API_PREFIX}/mcp/check`,
handler: async (request: IncomingMessage, response: ServerResponse) => {
- if (request.method !== 'POST') { response.writeHead(405, { allow: 'POST' }); response.end(); return }
- if (!sameOrigin(request)) { sendJson(response, 403, { error: 'untrusted origin' }); return }
+ if (request.method !== 'POST') {
+ response.writeHead(405, { allow: 'POST' })
+ response.end()
+ return
+ }
+ if (!sameOrigin(request)) {
+ sendJson(response, 403, { error: 'untrusted origin' })
+ return
+ }
try {
const body = (await readJsonBody(request)) as { id?: unknown, scope?: unknown }
- if (typeof body.id !== 'string') { sendJson(response, 400, { error: 'id is required' }); return }
+ if (typeof body.id !== 'string') {
+ sendJson(response, 400, { error: 'id is required' })
+ return
+ }
const row = listMcp(scopeDir(body.scope)).find(item => item.id === body.id)
- if (row === undefined) { sendJson(response, 404, { error: 'server row not found' }); return }
+ if (row === undefined) {
+ sendJson(response, 404, { error: 'server row not found' })
+ return
+ }
sendJson(response, 200, await checkMcpRow(row))
- } catch (error) { sendJson(response, 500, { error: error instanceof Error ? error.message : String(error) }) }
+ }
+ catch (error) { sendJson(response, 500, { error: error instanceof Error ? error.message : String(error) }) }
},
}))
disposers.push(register({
- kind: 'exact', path: `${API_PREFIX}/mcp/copy`,
+ kind: 'exact',
+ path: `${API_PREFIX}/mcp/copy`,
handler: async (request: IncomingMessage, response: ServerResponse) => {
- if (request.method !== 'POST') { response.writeHead(405, { allow: 'POST' }); response.end(); return }
- if (!sameOrigin(request)) { sendJson(response, 403, { error: 'untrusted origin' }); return }
+ if (request.method !== 'POST') {
+ response.writeHead(405, { allow: 'POST' })
+ response.end()
+ return
+ }
+ if (!sameOrigin(request)) {
+ sendJson(response, 403, { error: 'untrusted origin' })
+ return
+ }
try {
const body = (await readJsonBody(request)) as { id?: unknown, scope?: unknown, toScope?: unknown }
- if (typeof body.id !== 'string') { sendJson(response, 400, { error: 'id is required' }); return }
+ if (typeof body.id !== 'string') {
+ sendJson(response, 400, { error: 'id is required' })
+ return
+ }
const source = listMcp(scopeDir(body.scope)).find(item => item.id === body.id)
- if (source === undefined) { sendJson(response, 404, { error: 'server row not found' }); return }
+ if (source === undefined) {
+ sendJson(response, 404, { error: 'server row not found' })
+ return
+ }
const scope = readScope(body.toScope)
const id = upsertMcp(mcpScopeDir(scope, config.profileDirPath, config.dshHomePath), mcpRowToInput(source))
sendJson(response, 200, { ok: true, id, scope, restartNeeded: true })
- } catch (error) { sendJson(response, 500, { error: error instanceof Error ? error.message : String(error) }) }
+ }
+ catch (error) { sendJson(response, 500, { error: error instanceof Error ? error.message : String(error) }) }
},
}))
return disposers
diff --git a/packages/dsh-tauri-panel-extension/src/host/service/agents.ts b/packages/dsh-tauri-panel-extension/src/host/service/agents.ts
index 1b6dae9f..ae359713 100644
--- a/packages/dsh-tauri-panel-extension/src/host/service/agents.ts
+++ b/packages/dsh-tauri-panel-extension/src/host/service/agents.ts
@@ -5,11 +5,11 @@
* well-known paths; anything missing or malformed yields an empty list.
*/
+import type { McpTransport } from './mcp.ts'
import { existsSync, readFileSync } from 'node:fs'
import { homedir } from 'node:os'
import { join } from 'pathe'
import { parse as parseToml } from 'smol-toml'
-import type { McpTransport } from './mcp.ts'
/** One MCP server discovered in a foreign agent's config. */
export interface ImportedServer {
@@ -25,38 +25,48 @@ export interface ImportedServer {
/** Keep only string-valued entries of a record (configs may hold numbers). */
function stringEntries(value: unknown): Record<string, string> | undefined {
- if (typeof value !== 'object' || value === null || Array.isArray(value)) return undefined
+ if (typeof value !== 'object' || value === null || Array.isArray(value))
+ return undefined
const out: Record<string, string> = {}
for (const [key, entry] of Object.entries(value)) {
- if (typeof entry === 'string') out[key] = entry
+ if (typeof entry === 'string')
+ out[key] = entry
}
return Object.keys(out).length > 0 ? out : undefined
}
function stringArray(value: unknown): string[] | undefined {
- if (!Array.isArray(value)) return undefined
+ if (!Array.isArray(value))
+ return undefined
const out = value.filter((entry): entry is string => typeof entry === 'string')
return out.length > 0 ? out : undefined
}
/** Map one mcpServers entry (Claude / Cursor share the shape); null for unsupported shapes (sse). */
function mapMcpServersEntry(agent: ImportedServer['agent'], name: string, entry: unknown): ImportedServer | null {
- if (typeof entry !== 'object' || entry === null) return null
+ if (typeof entry !== 'object' || entry === null)
+ return null
const record = entry as Record<string, unknown>
const type = typeof record.type === 'string' ? record.type : 'stdio'
if (type === 'stdio' || (type === 'stdio' && record.command !== undefined)) {
- if (typeof record.command !== 'string' || record.command === '') return null
+ if (typeof record.command !== 'string' || record.command === '')
+ return null
return {
- agent, name, transport: 'stdio',
+ agent,
+ name,
+ transport: 'stdio',
command: record.command,
args: stringArray(record.args),
env: stringEntries(record.env),
}
}
if (type === 'http' || type === 'streamable-http') {
- if (typeof record.url !== 'string' || record.url === '') return null
+ if (typeof record.url !== 'string' || record.url === '')
+ return null
return {
- agent, name, transport: 'streamable-http',
+ agent,
+ name,
+ transport: 'streamable-http',
url: record.url,
headers: stringEntries(record.headers),
}
@@ -69,20 +79,23 @@ function mapMcpServersEntry(agent: ImportedServer['agent'], name: string, entry:
export function scanClaudeMcp(home: string = homedir()): ImportedServer[] {
const merged: Record<string, unknown> = {}
for (const file of [join(home, '.claude', 'settings.json'), join(home, '.claude.json')]) {
- if (!existsSync(file)) continue
+ if (!existsSync(file))
+ continue
try {
const parsed = JSON.parse(readFileSync(file, 'utf8')) as { mcpServers?: unknown }
if (typeof parsed.mcpServers === 'object' && parsed.mcpServers !== null) {
Object.assign(merged, parsed.mcpServers)
}
- } catch {
+ }
+ catch {
// Broken or partial config: skip the file, keep earlier merges.
}
}
const out: ImportedServer[] = []
for (const [name, entry] of Object.entries(merged)) {
const mapped = mapMcpServersEntry('claude-code', name, entry)
- if (mapped !== null) out.push(mapped)
+ if (mapped !== null)
+ out.push(mapped)
}
return out
}
@@ -90,46 +103,59 @@ export function scanClaudeMcp(home: string = homedir()): ImportedServer[] {
/** MCP servers from Cursor's ~/.cursor/mcp.json (mcpServers, Claude-shaped). */
export function scanCursorMcp(home: string = homedir()): ImportedServer[] {
const file = join(home, '.cursor', 'mcp.json')
- if (!existsSync(file)) return []
+ if (!existsSync(file))
+ return []
let parsed: { mcpServers?: unknown }
try {
parsed = JSON.parse(readFileSync(file, 'utf8')) as { mcpServers?: unknown }
- } catch {
+ }
+ catch {
return []
}
- if (typeof parsed.mcpServers !== 'object' || parsed.mcpServers === null) return []
+ if (typeof parsed.mcpServers !== 'object' || parsed.mcpServers === null)
+ return []
const out: ImportedServer[] = []
for (const [name, entry] of Object.entries(parsed.mcpServers)) {
const mapped = mapMcpServersEntry('cursor', name, entry)
- if (mapped !== null) out.push(mapped)
+ if (mapped !== null)
+ out.push(mapped)
}
return out
}
-/** MCP servers from Gemini CLI's ~/.gemini/settings.json (mcpServers; httpUrl
- * keys map to streamable-http, plain `url` marks SSE and is skipped). */
+/**
+ * MCP servers from Gemini CLI's ~/.gemini/settings.json (mcpServers; httpUrl
+ * keys map to streamable-http, plain `url` marks SSE and is skipped).
+ */
export function scanGeminiMcp(home: string = homedir()): ImportedServer[] {
const file = join(home, '.gemini', 'settings.json')
- if (!existsSync(file)) return []
+ if (!existsSync(file))
+ return []
let parsed: { mcpServers?: unknown }
try {
parsed = JSON.parse(readFileSync(file, 'utf8')) as { mcpServers?: unknown }
- } catch {
+ }
+ catch {
return []
}
- if (typeof parsed.mcpServers !== 'object' || parsed.mcpServers === null) return []
+ if (typeof parsed.mcpServers !== 'object' || parsed.mcpServers === null)
+ return []
const out: ImportedServer[] = []
for (const [name, entry] of Object.entries(parsed.mcpServers)) {
- if (typeof entry !== 'object' || entry === null) continue
+ if (typeof entry !== 'object' || entry === null)
+ continue
const record = entry as Record<string, unknown>
if (typeof record.command === 'string' && record.command !== '') {
out.push({
- agent: 'gemini', name, transport: 'stdio',
+ agent: 'gemini',
+ name,
+ transport: 'stdio',
command: record.command,
args: stringArray(record.args),
env: stringEntries(record.env),
})
- } else if (typeof record.httpUrl === 'string' && record.httpUrl !== '') {
+ }
+ else if (typeof record.httpUrl === 'string' && record.httpUrl !== '') {
out.push({ agent: 'gemini', name, transport: 'streamable-http', url: record.httpUrl })
}
// `url`-only entries are SSE endpoints, which dsh's client cannot speak.
@@ -140,27 +166,34 @@ export function scanGeminiMcp(home: string = homedir()): ImportedServer[] {
/** MCP servers from Codex's config.toml ([mcp_servers.<name>] tables). */
export function scanCodexMcp(home: string = homedir()): ImportedServer[] {
const file = join(home, '.codex', 'config.toml')
- if (!existsSync(file)) return []
+ if (!existsSync(file))
+ return []
let root: Record<string, unknown>
try {
root = parseToml(readFileSync(file, 'utf8')) as Record<string, unknown>
- } catch {
+ }
+ catch {
return []
}
const table = root.mcp_servers
- if (typeof table !== 'object' || table === null) return []
+ if (typeof table !== 'object' || table === null)
+ return []
const out: ImportedServer[] = []
for (const [name, entry] of Object.entries(table)) {
- if (typeof entry !== 'object' || entry === null) continue
+ if (typeof entry !== 'object' || entry === null)
+ continue
const record = entry as Record<string, unknown>
if (typeof record.command === 'string' && record.command !== '') {
out.push({
- agent: 'codex', name, transport: 'stdio',
+ agent: 'codex',
+ name,
+ transport: 'stdio',
command: record.command,
args: stringArray(record.args),
env: stringEntries(record.env),
})
- } else if (typeof record.url === 'string' && record.url !== '') {
+ }
+ else if (typeof record.url === 'string' && record.url !== '') {
out.push({ agent: 'codex', name, transport: 'streamable-http', url: record.url })
}
}
@@ -171,9 +204,10 @@ export function scanCodexMcp(home: string = homedir()): ImportedServer[] {
export function scanAllMcp(home: string = homedir()): ImportedServer[] {
const seen = new Set<string>()
return [...scanClaudeMcp(home), ...scanCodexMcp(home), ...scanCursorMcp(home), ...scanGeminiMcp(home)]
- .filter(server => {
+ .filter((server) => {
const key = `${server.agent}/${server.name}`
- if (seen.has(key)) return false
+ if (seen.has(key))
+ return false
seen.add(key)
return true
})
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 bc11245f..eb6a115c 100644
--- a/packages/dsh-tauri-panel-extension/src/host/service/mcp.ts
+++ b/packages/dsh-tauri-panel-extension/src/host/service/mcp.ts
@@ -18,14 +18,16 @@
* directory holding its `cordis.patch.yml`; `listMcpScoped` merges both.
*/
+import type { YAMLMap, YAMLSeq } from 'yaml'
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs'
+import process from 'node:process'
import { join } from 'pathe'
-import { parseDocument, Document, type YAMLMap, type YAMLSeq } from 'yaml'
+import { Document, parseDocument } from 'yaml'
/** The plugin every managed row instantiates. */
export const MCP_PLUGIN = '@deepseek-ai/dsh-mcp-client'
/** MCP serverName grammar (dsh-mcp-client's contract). */
-export const SERVER_NAME_RE = /^[A-Za-z0-9_-]{1,32}$/
+export const SERVER_NAME_RE = /^[\w-]{1,32}$/
/** Transport choices the client supports. */
export type McpTransport = 'stdio' | 'streamable-http'
@@ -72,7 +74,8 @@ export type McpInput = Omit<McpRow, 'disabled'> & { disabled?: boolean }
* say what is actually wrong and which file to fix.
*/
function assertPatchParses(path: string, doc: Document): void {
- if (doc.errors.length === 0) return
+ if (doc.errors.length === 0)
+ return
const at = String(doc.errors[0].message).split('\n', 1)[0]
const total = doc.errors.length > 1 ? `, +${doc.errors.length - 1} more` : ''
throw new Error(
@@ -90,7 +93,8 @@ function loadPatch(dirPath: string): Document {
const contents = doc.contents as YAMLSeq | null
// The default-empty file parses as a flow `[]`; the patch layer is
// human-edited block YAML, so flip the flag before anything appends.
- if (contents !== null && contents.flow === true && contents.items.length === 0) contents.flow = false
+ if (contents !== null && contents.flow === true && contents.items.length === 0)
+ contents.flow = false
return doc
}
@@ -120,7 +124,8 @@ function isSeqNode(value: unknown): value is YAMLSeq<YAMLMap> {
/** A patch entry's insert list when it is the anonymous create form. */
function insertListOf(item: YAMLMap): YAMLSeq<YAMLMap> | undefined {
- if (item.has('id')) return undefined
+ if (item.has('id'))
+ return undefined
const node = item.get('insert')
return isSeqNode(node) ? node : undefined
}
@@ -129,10 +134,12 @@ function insertListOf(item: YAMLMap): YAMLSeq<YAMLMap> | undefined {
function mcpRowItems(doc: Document): { node: YAMLMap, list?: YAMLSeq<YAMLMap> }[] {
const found: { node: YAMLMap, list?: YAMLSeq<YAMLMap> }[] = []
for (const item of rowSeq(doc).items ?? []) {
- if (item.get('name') === MCP_PLUGIN) found.push({ node: item })
+ if (item.get('name') === MCP_PLUGIN)
+ found.push({ node: item })
const list = insertListOf(item)
for (const row of list?.items ?? []) {
- if (row.get('name') === MCP_PLUGIN) found.push({ node: row, list })
+ if (row.get('name') === MCP_PLUGIN)
+ found.push({ node: row, list })
}
}
return found
@@ -143,7 +150,7 @@ function rowToMcp(doc: Document, item: YAMLMap): McpRow {
// config is a YAMLMap node — materialize it before property access.
const configNode = item.get('config') as unknown
const plain = (typeof configNode === 'object' && configNode !== null && typeof (configNode as { toJS?: unknown }).toJS === 'function'
- ? (configNode as { toJS(document: Document): unknown }).toJS(doc)
+ ? (configNode as { toJS: (document: Document) => unknown }).toJS(doc)
: {}) as Record<string, unknown>
return {
id: String(item.get('id') ?? ''),
@@ -160,7 +167,8 @@ function rowToMcp(doc: Document, item: YAMLMap): McpRow {
}
function isStringMap(value: unknown): value is Record<string, string> {
- if (typeof value !== 'object' || value === null || Array.isArray(value)) return false
+ if (typeof value !== 'object' || value === null || Array.isArray(value))
+ return false
return Object.values(value).every(entry => typeof entry === 'string')
}
@@ -175,9 +183,11 @@ function managedInsert(doc: Document): YAMLSeq<YAMLMap> {
const bare: YAMLMap[] = []
let target: YAMLSeq<YAMLMap> | undefined
for (const item of seq.items ?? []) {
- if (item.get('name') === MCP_PLUGIN) bare.push(item)
+ if (item.get('name') === MCP_PLUGIN)
+ bare.push(item)
const list = insertListOf(item)
- if (list !== undefined && list.items.some(row => row.get('name') === MCP_PLUGIN)) target ??= list
+ if (list !== undefined && list.items.some(row => row.get('name') === MCP_PLUGIN))
+ target ??= list
}
if (target === undefined) {
const entry = toNode<YAMLMap>({ insert: [] })
@@ -197,10 +207,12 @@ function takenIds(doc: Document): Set<string> {
const taken = new Set<string>()
for (const item of rowSeq(doc).items ?? []) {
const id = String(item.get('id') ?? '')
- if (id !== '') taken.add(id)
+ if (id !== '')
+ taken.add(id)
for (const row of insertListOf(item)?.items ?? []) {
const rowId = String(row.get('id') ?? '')
- if (rowId !== '') taken.add(rowId)
+ if (rowId !== '')
+ taken.add(rowId)
}
}
return taken
@@ -226,7 +238,8 @@ export function listMcpScoped(profileDirPath: string, dshHomePath: string): McpL
if (existsSync(join(dshHomePath, 'cordis.patch.yml'))) {
try {
globalRows = listMcp(dshHomePath)
- } catch (error) {
+ }
+ catch (error) {
globalError = error instanceof Error ? error.message : String(error)
}
}
@@ -251,13 +264,17 @@ export function mcpScopeDir(scope: McpScope, profileDirPath: string, dshHomePath
/** Validate one write request; returns the rejection reason or null. */
export function validateMcpInput(input: McpInput): string | null {
- if (!SERVER_NAME_RE.test(input.serverName)) return 'serverName must be 1-32 chars of A-Z a-z 0-9 _ -'
+ if (!SERVER_NAME_RE.test(input.serverName))
+ return 'serverName must be 1-32 chars of A-Z a-z 0-9 _ -'
// The route casts raw JSON to McpInput; a create request may omit `id`.
const id = input.id ?? ''
- if (id.includes('/') || id.includes('..')) return 'invalid id'
+ if (id.includes('/') || id.includes('..'))
+ return 'invalid id'
if (input.transport === 'stdio') {
- if (input.command === undefined || input.command.trim() === '') return 'stdio transport requires a command'
- } else if (input.url === undefined || !/^https?:\/\//.test(input.url)) {
+ if (input.command === undefined || input.command.trim() === '')
+ return 'stdio transport requires a command'
+ }
+ else if (input.url === undefined || !/^https?:\/\//.test(input.url)) {
return 'http transport requires an http(s) url'
}
return null
@@ -296,14 +313,17 @@ export function upsertMcp(dirPath: string, input: McpInput): string {
...(input.headers !== undefined && Object.keys(input.headers).length > 0 ? { headers: input.headers } : {}),
}
const row: Record<string, unknown> = { id, name: MCP_PLUGIN, config }
- if (input.disabled === true) row.disabled = true
+ if (input.disabled === true)
+ row.disabled = true
const node = toNode<YAMLMap>(row)
if (existing === undefined) {
list.add(node)
- } else if (existing.list !== undefined) {
+ }
+ else if (existing.list !== undefined) {
existing.list.items.splice(existing.list.items.indexOf(existing.node), 1, node)
- } else {
+ }
+ else {
// Bare rows were absorbed above; reaching here means a foreign-shaped row.
rowSeq(doc).items.splice(rowSeq(doc).items.indexOf(existing.node), 1, node)
}
@@ -317,8 +337,10 @@ export function setMcpDisabled(dirPath: string, id: string, disabled: boolean):
const doc = loadPatch(dirPath)
managedInsert(doc)
const hit = mcpRowItems(doc).find(({ node }) => String(node.get('id') ?? '') === id)
- if (hit === undefined) return false
- if (disabled) hit.node.set('disabled', true)
+ if (hit === undefined)
+ return false
+ if (disabled)
+ hit.node.set('disabled', true)
else hit.node.delete('disabled')
savePatch(dirPath, doc)
return true
@@ -329,7 +351,8 @@ export function removeMcp(dirPath: string, id: string): boolean {
const doc = loadPatch(dirPath)
managedInsert(doc)
const hit = mcpRowItems(doc).find(({ node }) => String(node.get('id') ?? '') === id)
- if (hit === undefined || hit.list === undefined) return false
+ if (hit === undefined || hit.list === undefined)
+ return false
hit.list.items.splice(hit.list.items.indexOf(hit.node), 1)
// An insert entry left with no rows is dead weight; drop it when the
@@ -344,8 +367,10 @@ export function removeMcp(dirPath: string, id: string): boolean {
return true
}
-/** Rebuild a create request from an existing row (id emptied; identity fields
- * carried over) — used to copy a row into the other patch layer. */
+/**
+ * Rebuild a create request from an existing row (id emptied; identity fields
+ * carried over) — used to copy a row into the other patch layer.
+ */
export function mcpRowToInput(row: McpRow): McpInput {
return {
id: '',
@@ -373,14 +398,17 @@ export function mcpRowToInput(row: McpRow): McpInput {
* process is spawned, so no console-window or side-effect concerns.
*/
export function resolveCommandOnPath(command: string, pathEnv: string, platform: string = process.platform): boolean {
- if (command.includes('/') || command.includes('\\')) return existsSync(command)
+ if (command.includes('/') || command.includes('\\'))
+ return existsSync(command)
const exts = platform === 'win32' ? ['', '.com', '.exe', '.bat', '.cmd'] : ['']
const separator = platform === 'win32' ? ';' : ':'
for (const rawDir of pathEnv.split(separator)) {
const dir = rawDir.trim().replace(/^"|"$/g, '')
- if (dir === '') continue
+ if (dir === '')
+ continue
for (const ext of exts) {
- if (existsSync(join(dir, command + ext))) return true
+ if (existsSync(join(dir, command + ext)))
+ return true
}
}
return false
@@ -399,23 +427,26 @@ export interface McpCheckResult {
* streamable-http rows get a short GET — any HTTP status proves reachability,
* since MCP endpoints legitimately answer 405 to plain GETs.
*/
-export async function checkMcpRow(row: McpRow, options: { timeoutMs?: number; pathEnv?: string; platform?: string } = {}): Promise<McpCheckResult> {
+export async function checkMcpRow(row: McpRow, options: { timeoutMs?: number, pathEnv?: string, platform?: string } = {}): Promise<McpCheckResult> {
const pathEnv = options.pathEnv ?? process.env.PATH ?? ''
if (row.transport === 'stdio') {
const command = row.command ?? ''
- if (command === '') return { ok: false, detail: 'row has no command' }
+ if (command === '')
+ return { ok: false, detail: 'row has no command' }
return resolveCommandOnPath(command, pathEnv, options.platform)
? { ok: true, detail: command }
: { ok: false, detail: `${command} not found on PATH` }
}
- if (row.url === undefined || !/^https?:\/\//.test(row.url)) return { ok: false, detail: 'row has no http url' }
+ if (row.url === undefined || !/^https?:\/\//.test(row.url))
+ return { ok: false, detail: 'row has no http url' }
try {
const response = await fetch(row.url, {
headers: { accept: 'application/json, text/event-stream' },
signal: AbortSignal.timeout(options.timeoutMs ?? 5000),
})
return { ok: true, detail: `HTTP ${response.status}` }
- } catch (error) {
+ }
+ catch (error) {
const message = error instanceof Error ? error.message : String(error)
const cause = (error as { cause?: { code?: unknown } }).cause?.code
return { ok: false, detail: cause !== undefined ? String(cause) : message }