Files
deepseek-harness/apps/cli/tests/profile-mcp.spec.ts
T
gengruilin 30086a0c0a refactor(mcp): reach mcp-client only through the MCP client host
The MCP manager imported validation, probe, status, and authorization values
from the mcp-client plugin entry and mounted its servers through a static
import of that entry. Plugin entries may export only what the Loader loads,
and the static references break source reloads: when mcp-client also has its
own Loader entry, a reload replaces only mcp-client, and HMR replaces the
instances the manager mounted without the manager knowing, so it keeps the
old code, reports stale status, and cannot stop the replacement instance.

An mcp-client entry loaded with `host: true` now provides
`ctx.mcpClientHost`. The host validates a server configuration through its
transport's own schema, so refusals still name the field; mounts instances
below its own Fiber; probes; and creates OAuth authorization owners from its
own context. The manager injects the host, imports only mcp-client types, and
passes `reconnect` and `oauth` to the host unresolved. Replacing the host
disposes its instances and restarts the manager against the replacement.

The Web composition mounts the host row before the manager. The entry stops
exporting probeServer, connectionStatusOf, assertTemplateSyntax,
resolveReconnectPolicy, ReconnectSchema, SERVER_NAME_PATTERN,
McpOAuthAuthorization, and OAuthSchema, and the plugin entry export list keeps
only createMcpToolDefinition for it.
2026-11-06 03:18:23 +08:00

60 lines
2.6 KiB
TypeScript

/** MCP resource and server-manager ownership across the resolved shipped profile templates. */
import { mkdtempSync, readFileSync, rmSync } from 'node:fs'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { fileURLToPath } from 'node:url'
import { describe, expect, it } from 'vitest'
import { composeEntries, loadProfile } from '@deepseek-ai/dsh-app-boot'
import { PROFILE_TEMPLATES } from '@deepseek-ai/dsh-official-bundles'
const installAnchor = fileURLToPath(new URL('../package.json', import.meta.url))
const resourcePackage = '@deepseek-ai/dsh-mcp-resources'
describe('shipped MCP resource composition', () => {
it.each(Object.keys(PROFILE_TEMPLATES))('%s carries one shared resource consumer and no MCP server instance', (name) => {
const home = mkdtempSync(join(tmpdir(), 'dsh-profile-mcp-'))
try {
const profile = loadProfile('dsh', name, installAnchor, home)
const warnings: string[] = []
const rows = composeEntries([
...profile.layers.map(layer => layer.patches),
profile.patches,
], message => warnings.push(message))
expect(rows.filter(row => row.name === resourcePackage)).toEqual([
{ id: 'mcp-resources', name: resourcePackage },
])
expect(rows.filter(row => row.name === '@deepseek-ai/dsh-mcp-client')).toEqual(name === 'web'
? [{ id: 'mcp-client-host', name: '@deepseek-ai/dsh-mcp-client', config: { host: true } }]
: [])
expect(warnings).toEqual([])
const owners = profile.layers.filter((layer) => {
const manifest = JSON.parse(readFileSync(join(layer.packageDir, 'package.json'), 'utf8')) as {
dependencies?: Record<string, string>
}
return manifest.dependencies?.[resourcePackage] !== undefined
})
expect(owners.map(owner => owner.packageName)).toEqual([
name === 'sdk-minimal' ? '@deepseek-ai/dsh-sdk-minimal' : '@deepseek-ai/dsh-base',
])
} finally {
rmSync(home, { recursive: true, force: true })
}
})
it.each(Object.keys(PROFILE_TEMPLATES))('%s mounts the server manager only with the Web application', (name) => {
const home = mkdtempSync(join(tmpdir(), 'dsh-profile-mcp-'))
try {
const profile = loadProfile('dsh', name, installAnchor, home)
const rows = composeEntries([...profile.layers.map(layer => layer.patches), profile.patches])
expect(rows.filter(row => row.name === '@deepseek-ai/dsh-mcp-manager')).toEqual(name === 'web'
? [{ id: 'mcp-manager', name: '@deepseek-ai/dsh-mcp-manager', inject: ['credentials'] }]
: [])
} finally {
rmSync(home, { recursive: true, force: true })
}
})
})