refactor(mcp-client): resolve on-demand tool loading through the host schemas

The server schemas moved to config.ts, where the MCP client host and the
entry share them, so `toolLoading` and `catalogDescriptionMaxLength`
join the stdio and Streamable HTTP schemas and input types there; the
merge already passes the manager entry's `toolLoading` to the host with
the other client fields. The tool-loading spec reads instance status
from the status module, as the entry no longer exports it, and the API
catalog records the two fields.
This commit is contained in:
gengruilin committed 2026-11-06 03:52:38 +08:00
1 parent 93e00db6eb
commit 29669c4d07
3 files changed
+15 -7

No files matched your search

@@ -9506,7 +9506,7 @@ export const TYPE_API: readonly TypeApiEntry[] = [
},
{
name: 'StdioConfig',
declaration: 'export interface StdioConfig {\n transport: \'stdio\';\n serverName: string;\n command: string;\n args: string[];\n env: Record<string, string>;\n cwd: string;\n toolCallTimeoutMs: number;\n startupTimeoutMs?: number;\n closeTimeoutMs: number;\n expandTemplates: boolean;\n failOnStartupError: boolean;\n maxInstructionBytes?: number;\n reconnect?: ReconnectConfig;\n}',
declaration: 'export interface StdioConfig {\n transport: \'stdio\';\n serverName: string;\n command: string;\n args: string[];\n env: Record<string, string>;\n cwd: string;\n toolCallTimeoutMs: number;\n startupTimeoutMs?: number;\n closeTimeoutMs: number;\n expandTemplates: boolean;\n failOnStartupError: boolean;\n maxInstructionBytes?: number;\n reconnect?: ReconnectConfig;\n toolLoading: \'eager\' | \'on-demand\';\n catalogDescriptionMaxLength: number;\n}',
},
{
name: 'StopShareRequest',
@@ -9530,7 +9530,7 @@ export const TYPE_API: readonly TypeApiEntry[] = [
},
{
name: 'StreamableHttpConfig',
declaration: 'export interface StreamableHttpConfig {\n oauth?: McpOAuthConfig;\n transport: \'streamable-http\';\n serverName: string;\n url: string;\n headers: Record<string, string>;\n toolCallTimeoutMs: number;\n startupTimeoutMs?: number;\n closeTimeoutMs: number;\n expandTemplates: boolean;\n failOnStartupError: boolean;\n maxInstructionBytes?: number;\n reconnect?: ReconnectConfig;\n}',
declaration: 'export interface StreamableHttpConfig {\n oauth?: McpOAuthConfig;\n transport: \'streamable-http\';\n serverName: string;\n url: string;\n headers: Record<string, string>;\n toolCallTimeoutMs: number;\n startupTimeoutMs?: number;\n closeTimeoutMs: number;\n expandTemplates: boolean;\n failOnStartupError: boolean;\n maxInstructionBytes?: number;\n reconnect?: ReconnectConfig;\n toolLoading: \'eager\' | \'on-demand\';\n catalogDescriptionMaxLength: number;\n}',
},
{
name: 'StreamChunk',
+11 -4
View File
@@ -19,16 +19,19 @@ const DEFAULT_TOOL_CALL_TIMEOUT_MS = 60_000
/** Default budget for transport closure and local cleanup (ms). */
const DEFAULT_CLOSE_TIMEOUT_MS = 5_000
/** Default cap on each tool summary in an on-demand server's prompt catalog. */
const DEFAULT_CATALOG_DESCRIPTION_MAX_LENGTH = 160
/** Valid `serverName`, kept below the public tool-name budget. */
export const SERVER_NAME_PATTERN = /^[A-Za-z0-9_-]{1,32}$/
/** {@link StdioConfig} before defaults. */
type StdioConfigInput = Omit<StdioConfig, 'args' | 'env' | 'cwd' | 'toolCallTimeoutMs' | 'startupTimeoutMs' | 'failOnStartupError' | 'closeTimeoutMs' | 'expandTemplates'>
& Partial<Pick<StdioConfig, 'args' | 'env' | 'cwd' | 'toolCallTimeoutMs' | 'startupTimeoutMs' | 'failOnStartupError' | 'closeTimeoutMs' | 'expandTemplates'>>
type StdioConfigInput = Omit<StdioConfig, 'args' | 'env' | 'cwd' | 'toolCallTimeoutMs' | 'startupTimeoutMs' | 'failOnStartupError' | 'closeTimeoutMs' | 'expandTemplates' | 'toolLoading' | 'catalogDescriptionMaxLength'>
& Partial<Pick<StdioConfig, 'args' | 'env' | 'cwd' | 'toolCallTimeoutMs' | 'startupTimeoutMs' | 'failOnStartupError' | 'closeTimeoutMs' | 'expandTemplates' | 'toolLoading' | 'catalogDescriptionMaxLength'>>
/** {@link StreamableHttpConfig} before defaults. */
type StreamableHttpConfigInput = Omit<StreamableHttpConfig, 'oauth' | 'headers' | 'toolCallTimeoutMs' | 'startupTimeoutMs' | 'failOnStartupError' | 'closeTimeoutMs' | 'expandTemplates'>
& Partial<Pick<StreamableHttpConfig, 'headers' | 'toolCallTimeoutMs' | 'startupTimeoutMs' | 'failOnStartupError' | 'closeTimeoutMs' | 'expandTemplates'>>
type StreamableHttpConfigInput = Omit<StreamableHttpConfig, 'oauth' | 'headers' | 'toolCallTimeoutMs' | 'startupTimeoutMs' | 'failOnStartupError' | 'closeTimeoutMs' | 'expandTemplates' | 'toolLoading' | 'catalogDescriptionMaxLength'>
& Partial<Pick<StreamableHttpConfig, 'headers' | 'toolCallTimeoutMs' | 'startupTimeoutMs' | 'failOnStartupError' | 'closeTimeoutMs' | 'expandTemplates' | 'toolLoading' | 'catalogDescriptionMaxLength'>>
& { oauth?: McpOAuthConfigInput }
/** One server's configuration before defaults. */
@@ -61,6 +64,8 @@ export const StdioSchema = z.object({
failOnStartupError: z.boolean().default(false),
maxInstructionBytes: z.number().step(1).min(1).default(DEFAULT_MAX_INSTRUCTION_BYTES),
reconnect: ReconnectSchema,
toolLoading: z.union(['eager', 'on-demand']).default('eager'),
catalogDescriptionMaxLength: z.natural().min(4).default(DEFAULT_CATALOG_DESCRIPTION_MAX_LENGTH),
}) as z<StdioConfigInput, StdioConfig>
/** Schema of {@link StreamableHttpConfig}. */
@@ -77,6 +82,8 @@ export const StreamableHttpSchema = z.object({
failOnStartupError: z.boolean().default(false),
maxInstructionBytes: z.number().step(1).min(1).default(DEFAULT_MAX_INSTRUCTION_BYTES),
reconnect: ReconnectSchema,
toolLoading: z.union(['eager', 'on-demand']).default('eager'),
catalogDescriptionMaxLength: z.natural().min(4).default(DEFAULT_CATALOG_DESCRIPTION_MAX_LENGTH),
}) as z<StreamableHttpConfigInput, StreamableHttpConfig>
/* jscpd:ignore-end */
@@ -8,6 +8,7 @@ import { executeToolFixture } from '@deepseek-ai/dsh-tool-testkit'
import * as NativeToolExecutor from '@deepseek-ai/dsh-tool-executor-native'
import ToolRuntime, { defineTool } from '@deepseek-ai/dsh-tools'
import * as McpClient from '../src/index.ts'
import { connectionStatusIn } from '../src/status.ts'
import { McpToolLoader } from '../src/tool-loading.ts'
import { McpToolRegistrationError, syncTools, type ToolBridgeOptions, type ToolDisposers } from '../src/tools.ts'
import { startHttpMcpFixture } from './http-fixture.ts'
@@ -248,7 +249,7 @@ it('loads and calls an on-demand server\'s tool through the plugin and withdraws
toolLoading: 'on-demand', failOnStartupError: true, reconnect: { enabled: false },
}))
expect(McpClient.connectionStatusOf(fiber)!.current()).toMatchObject({ state: 'connected', toolCount: 1 })
expect(connectionStatusIn(fiber)!.current()).toMatchObject({ state: 'connected', toolCount: 1 })
expect(ctx.tools.get('mcp__demo__ping', agent)).toBeUndefined()
const prompt = await ctx.systemPrompt.assemble({ scope: agent })
expect(prompt.sections.map(section => section.text)).toContain([