fix(mcp-client): await Cordis startup discovery

This commit is contained in:
Tianyi Cui
2026-08-08 21:13:20 +08:00
parent 67b9e9b1d6
commit 913ecf5f1d
18 changed files with 108 additions and 39 deletions
@@ -22,6 +22,7 @@ describe('repository plugin common .mcp.json support', () => {
serverName: 'expo',
url: 'https://mcp.expo.dev/mcp',
headers: {},
failOnStartupError: true,
}])
})
@@ -43,6 +44,7 @@ describe('repository plugin common .mcp.json support', () => {
args: ['--endpoint', 'http://localhost:8000'],
env: { DJ_API_URL: 'http://localhost:8000' },
cwd: '/plugin',
failOnStartupError: true,
}])
})
@@ -74,12 +76,14 @@ describe('repository plugin common .mcp.json support', () => {
args: [],
env: {},
cwd: '/plugin',
failOnStartupError: true,
},
{
transport: 'streamable-http',
serverName: 'remote',
url: 'http://localhost:3000/mcp',
headers: { Authorization: 'Bearer test-token' },
failOnStartupError: true,
},
])
})
@@ -261,7 +261,7 @@ describe('prepared repository plugin Loader composition', () => {
await ctx.fiber.dispose()
})
it('delegates an MCP-only plugin to the existing client without turning connect failure into Loader failure', async () => {
it('fails an MCP repository plugin load when its declared server cannot connect', async () => {
const root = await temporaryDirectory('mcp-loader')
await writeFile(join(root, '.mcp.json'), JSON.stringify({
mcpServers: { offline: { command: join(root, 'missing-mcp-command') } },
@@ -275,12 +275,10 @@ describe('prepared repository plugin Loader composition', () => {
await ctx.plugin(SystemPrompt)
await ctx.plugin(ToolRegistry)
await ctx.plugin(RepositoryPlugin)
const id = await ctx.loader.create({
await expect(ctx.loader.create({
name: pathToFileURL(join(directory, RepositoryPlugin.PREPARED_ENTRY_FILENAME)).href,
})
await ctx.loader.await()
})).rejects.toThrow('initial connection or tool discovery failed')
expect(ctx.tools.schemas().some(tool => tool.name.startsWith('mcp__offline__'))).toBe(false)
await ctx.loader.remove(id)
await ctx.fiber.dispose()
})