diff --git a/packages/experimental/liveshare/src/endpoint-classification.ts b/packages/experimental/liveshare/src/endpoint-classification.ts index cf50fb00e7..7b53fe7567 100644 --- a/packages/experimental/liveshare/src/endpoint-classification.ts +++ b/packages/experimental/liveshare/src/endpoint-classification.ts @@ -209,6 +209,9 @@ export const VIEWER_ENDPOINT_CLASSES = { 'mcpServers/probe': 'owner-only', // owner MCP server management 'mcpServers/restart': 'owner-only', // owner MCP server management 'mcpServers/watch': 'owner-only', // owner MCP server management + 'mcpServers/startAuthorization': 'owner-only', // owner MCP server management + 'mcpServers/cancelAuthorization': 'owner-only', // owner MCP server management + 'mcpServers/signOut': 'owner-only', // owner MCP server management 'commands/execute': 'owner-only', // owner executes a slash command 'permissionPresets/catalog': 'owner-only', // owner permission presets 'userQuestions/answer': 'owner-only', // owner answers a pending question diff --git a/packages/mcp/mcp-client/tests/oauth-fixture.ts b/packages/mcp/mcp-client/tests/oauth-fixture.ts index 270de44542..e0f1b69700 100644 --- a/packages/mcp/mcp-client/tests/oauth-fixture.ts +++ b/packages/mcp/mcp-client/tests/oauth-fixture.ts @@ -10,6 +10,7 @@ import Authorization from '@deepseek-ai/dsh-authorization' import { LocalCredentialProvider } from '@deepseek-ai/dsh-credentials-local' import WebServer from '@deepseek-ai/dsh-host-webserver' import SystemPrompt from '@deepseek-ai/dsh-system-prompt' +import * as NativeToolExecutor from '@deepseek-ai/dsh-tool-executor-native' import Tools from '@deepseek-ai/dsh-tools' import { createMcpHandler, McpServer } from '@modelcontextprotocol/server' import { toNodeHandler, type NodeIncomingMessageLike } from '@modelcontextprotocol/node' @@ -116,6 +117,7 @@ export async function oauthWorld(interactive = true, webHost = '127.0.0.1') { } await ctx.plugin(SystemPrompt) await ctx.plugin(Tools) + await ctx.plugin(NativeToolExecutor) const resolved = Config({ transport: 'streamable-http', serverName: 'oauth', url: origin + '/mcp', headers: { 'x-resource-only': 'fixture-resource-secret' }, oauth: { credentialKey: 'mcp-client/oauth' }, reconnect: { enabled: false } }) if (resolved.transport !== 'streamable-http' || resolved.oauth === undefined) throw new Error('Missing HTTP OAuth configuration') diff --git a/packages/mcp/mcp-client/tests/oauth.spec.ts b/packages/mcp/mcp-client/tests/oauth.spec.ts index 417930ab2c..682f1f6039 100644 --- a/packages/mcp/mcp-client/tests/oauth.spec.ts +++ b/packages/mcp/mcp-client/tests/oauth.spec.ts @@ -3,6 +3,7 @@ import { describe, expect, it, onTestFinished, vi } from 'vitest' import { Client, UnauthorizedError } from '@modelcontextprotocol/client' import { parseCredentialKey } from '@deepseek-ai/dsh-credentials' import { ToolCallId } from '@deepseek-ai/dsh-llm' +import { executeToolFixture } from '@deepseek-ai/dsh-tool-testkit' import { apply, connectionStatusOf, probeServer, type Config } from '../src/index.ts' import { McpTemplateBinding } from '../src/credentials.ts' import { McpOAuthCredentials, oauthRecord } from '../src/oauth-credentials.ts' @@ -494,12 +495,12 @@ describe('MCP OAuth', () => { onTestFinished(() => { spy.mockRestore() }) expect(await callback(waiting)).toBe(200) await entered.promise - const call = await world.ctx.tools.execute({ callId: ToolCallId('stale-grant'), name: 'mcp__oauth__ping', arguments: {}, signal: new AbortController().signal }) + const call = await executeToolFixture(world.ctx, { callId: ToolCallId('stale-grant'), name: 'mcp__oauth__ping', arguments: {}, signal: new AbortController().signal }) expect(call).toMatchObject({ isError: true }) release.resolve() await reconnected.promise expect(states).toEqual(['connected', 'connecting', 'connected']) - expect(await world.ctx.tools.execute({ callId: ToolCallId('fresh-grant'), name: 'mcp__oauth__ping', arguments: {}, signal: new AbortController().signal })) + expect(await executeToolFixture(world.ctx, { callId: ToolCallId('fresh-grant'), name: 'mcp__oauth__ping', arguments: {}, signal: new AbortController().signal })) .toMatchObject({ isError: false }) }) diff --git a/packages/mcp/mcp-manager/package.json b/packages/mcp/mcp-manager/package.json index c9e2734e3c..2cdd25dcbb 100644 --- a/packages/mcp/mcp-manager/package.json +++ b/packages/mcp/mcp-manager/package.json @@ -64,6 +64,7 @@ "@deepseek-ai/dsh-mcp-client": "workspace:*", "@deepseek-ai/dsh-settings": "workspace:*", "@deepseek-ai/dsh-system-prompt": "workspace:*", + "@deepseek-ai/dsh-tool-testkit": "workspace:*", "@deepseek-ai/dsh-tools": "workspace:*", "@deepseek-ai/dsh-util-values": "workspace:*", "@deepseek-ai/cordis": "workspace:~", diff --git a/packages/mcp/mcp-manager/tests/oauth.spec.ts b/packages/mcp/mcp-manager/tests/oauth.spec.ts index f2b7c36495..deb924ea61 100644 --- a/packages/mcp/mcp-manager/tests/oauth.spec.ts +++ b/packages/mcp/mcp-manager/tests/oauth.spec.ts @@ -1,6 +1,7 @@ /** OAuth management through the real profile loader, SDK, and durable credential provider. */ import { expect, it, onTestFinished, vi } from 'vitest' import { ToolCallId } from '@deepseek-ai/dsh-llm' +import { executeToolFixture } from '@deepseek-ai/dsh-tool-testkit' import { Client, UnauthorizedError } from '@modelcontextprotocol/client' import { McpOAuthCredentials } from '@deepseek-ai/dsh-mcp-client/src/oauth-credentials.ts' import { callback, oauthWorld, phase } from '../../mcp-client/tests/oauth-fixture.ts' @@ -22,7 +23,7 @@ async function managed(layer: 'base' | 'user' = 'base') { await phase(() => view().authorization, 'authorized') await state('connected') } - const invoke = () => world.ctx.tools.execute({ callId: ToolCallId('oauth-call'), name: 'mcp__oauth__ping', arguments: {}, signal: new AbortController().signal }) + const invoke = () => executeToolFixture(world.ctx, { callId: ToolCallId('oauth-call'), name: 'mcp__oauth__ping', arguments: {}, signal: new AbortController().signal }) const store = new McpOAuthCredentials(world.ctx, world.config.oauth) return { ...world, manager, view, state, login, invoke, store } } @@ -352,7 +353,7 @@ it('registers an OAuth server, streams its authorization, and redacts its access const waiting = await next(view => view?.authorization?.phase === 'waiting-browser') expect(await callback(waiting.authorization!)).toBe(200) await next(view => view?.status.state === 'connected') - const result = await world.ctx.tools.execute({ + const result = await executeToolFixture(world.ctx, { callId: ToolCallId('oauth-reject'), name: 'mcp__oauth__reject', arguments: {}, signal: new AbortController().signal, }) if (!result.isError) throw new Error('expected the fixture to reject the call') diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 5918b8f0e3..0f23062993 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -13726,6 +13726,9 @@ importers: '@deepseek-ai/dsh-system-prompt': specifier: workspace:* version: link:../../core/system-prompt + '@deepseek-ai/dsh-tool-testkit': + specifier: workspace:* + version: link:../../test-support/tool-testkit '@deepseek-ai/dsh-tools': specifier: workspace:* version: link:../../core/tools diff --git a/snapshots/session/mcp-oauth-error/session.v4.jsonl b/snapshots/session/mcp-oauth-error/session.v4.jsonl index f458d3abf5..1659e6dff2 100644 --- a/snapshots/session/mcp-oauth-error/session.v4.jsonl +++ b/snapshots/session/mcp-oauth-error/session.v4.jsonl @@ -9,7 +9,7 @@ {"type":"system/message","data":{"turn":1,"step":1,"message":{"role":"system","content":[{"type":"text","text":"{{system}}"}],"source":{"kind":"system-prompt"},"id":"{{message:2}}"}},"surfaceOp":"append"} {"type":"user/message","data":{"content":[{"type":"text","text":"Call mcp__protected__ping exactly once with {}. Do not call other tools and do not retry. After the tool fails, reply with only MCP_ERROR_OBSERVED."}],"source":{"kind":"user"},"role":"user","id":"{{message:1}}"},"surfaceOp":"append"} {"type":"user/message","data":{"content":[{"type":"text","text":"Current runtime context. This snapshot supersedes earlier runtime-context snapshots.\n\nCurrent working directory: \"{{cwd}}\".\n\nCurrent DSH file policy: danger-full-access. The DSH file sandbox does not restrict file modifications by available operations.\n\nApproval prompts are disabled in this session: actions that require approval are rejected automatically — do not request sandbox escalation (do not set `sandbox_permissions`)."}],"source":{"kind":"runtime-context","form":"snapshot","sections":[{"name":"working-directory:current","text":"Current working directory: \"{{cwd}}\"."},{"name":"sandbox:policy","text":"Current DSH file policy: danger-full-access. The DSH file sandbox does not restrict file modifications by available operations."},{"name":"approval:policy","text":"Approval prompts are disabled in this session: actions that require approval are rejected automatically — do not request sandbox escalation (do not set `sandbox_permissions`)."}]},"role":"user","id":"{{message:3}}"},"surfaceOp":"append"} -{"type":"request/header","data":{"header":{"config":{"provider":"deepseek-official","model":"deepseek-flash","maxTokens":256000,"reasoningEffort":"max"},"adapterDefaults":{"reasoningEffort":true,"maxTokens":true},"tools":["bash","create_goal","edit","exit_plan_mode","get_goal","glob","grep","interrupt_agent","job_kill","job_list","job_output","list_agents","list_mcp_resource_templates","list_mcp_resources","mcp__protected__ping","read","read_image","read_mcp_resource","send_message","skill","subagent","subagent_fork","todo_write","update_goal","web_fetch","web_search","workflow","working_directory","write"]},"reason":"initial"}} +{"type":"request/header","data":{"header":{"config":{"provider":"deepseek-official","model":"deepseek-flash","maxTokens":256000,"reasoningEffort":"max"},"adapterDefaults":{"reasoningEffort":true,"maxTokens":true},"tools":["bash","create_goal","edit","get_goal","glob","grep","interrupt_agent","job_kill","job_list","job_output","list_agents","list_mcp_resource_templates","list_mcp_resources","mcp__protected__ping","read","read_image","read_mcp_resource","send_message","skill","subagent","subagent_fork","todo_write","update_goal","web_fetch","web_search","workflow","working_directory","write"]},"reason":"initial"}} {"type":"request/context","data":{"provider":"deepseek-official","model":"deepseek-flash","contextWindow":1000000}} {"type":"session/title","data":{"title":"Call mcp__protected__ping exactly once w","messageSeqs":[8],"source":{"kind":"fallback"}}} {"type":"assistant/message","data":{"turn":1,"step":1,"message":{"role":"assistant","content":[{"type":"reasoning","text":"The user wants me to call mcp__protected__ping exactly once with {}. Let me do that.\n\nNote: the tool may fail. The instruction says after the tool fails, reply with only MCP_ERROR_OBSERVED. But I should call it once and see the result. If it succeeds, then... the instruction assumes failure. Let me just call it.\n\nActually, the instruction says \"Do not call other tools and do not retry.\" So a single call. If it succeeds, I should probably report success, not MCP_ERROR_OBSERVED. Let's see."},{"type":"tool-call","id":"call_00_UtMXFAu1EIPuL264bFLM6298","name":"mcp__protected__ping","arguments":"{}"}],"source":{"kind":"model","provider":"deepseek-official","model":"deepseek-flash","replayState":{"response":{"kind":"deepseek-messages","version":1,"model":"deepseek-flash"},"blocks":[{"type":"reasoning","signature":"6610ccac-b3b1-4b1e-afb1-f787fb63a39e"},{"type":"tool-call"}]}},"id":"{{message:4}}"},"usage":{"inputTokens":5830,"outputTokens":147,"cacheReadTokens":0,"cacheWriteTokens":0,"totalTokens":5977},"stream":[{"type":"chunk","time":1790580419314,"chunk":{"type":"block-start","index":0,"blockType":"reasoning"}},{"type":"reasoning-chunks","time0":1790580419314,"index":0,"dt":[0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"texts":["The"," user"," wants"," me"," to"," call"," m","cp","__","protected","__","ping"," exactly"," once"," with"," {","}."," Let"," me"," do"," that",".\n\n","Note",":"," the"," tool"," may"," fail","."," The"," instruction"," says"," after"," the"," tool"," fails",","," reply"," with"," only"," M","CP","_ERROR","_O","BS","ERV","ED","."," But"," I"," should"," call"," it"," once"," and"," see"," the"," result","."," If"," it"," succeeds",","," then","..."," the"," instruction"," assumes"," failure","."," Let"," me"," just"," call"," it",".\n\n","Actually",","," the"," instruction"," says"," \"","Do"," not"," call"," other"," tools"," and"," do"," not"," ret","ry",".\""," So"," a"," single"," call","."," If"," it"," succeeds",","," I"," should"," probably"," report"," success",","," not"," M","CP","_ERROR","_O","BS","ERV","ED","."," Let","'s"," see","."]},{"type":"chunk","time":1790580419315,"chunk":{"type":"block-end","index":0,"block":{"type":"reasoning","text":"The user wants me to call mcp__protected__ping exactly once with {}. Let me do that.\n\nNote: the tool may fail. The instruction says after the tool fails, reply with only MCP_ERROR_OBSERVED. But I should call it once and see the result. If it succeeds, then... the instruction assumes failure. Let me just call it.\n\nActually, the instruction says \"Do not call other tools and do not retry.\" So a single call. If it succeeds, I should probably report success, not MCP_ERROR_OBSERVED. Let's see."}}},{"type":"chunk","time":1790580419315,"chunk":{"type":"block-start","index":1,"blockType":"tool-call"}},{"type":"tool-call-chunks","time0":1790580419315,"index":1,"dt":[],"id":"call_00_UtMXFAu1EIPuL264bFLM6298","name":"mcp__protected__ping","args":[""]},{"type":"tool-call-chunks","time0":1790580419315,"index":1,"dt":[],"id":"call_00_UtMXFAu1EIPuL264bFLM6298","args":["{}"]},{"type":"chunk","time":1790580419315,"chunk":{"type":"block-end","index":1,"block":{"type":"tool-call","id":"call_00_UtMXFAu1EIPuL264bFLM6298","name":"mcp__protected__ping","arguments":"{}"}}},{"type":"chunk","time":1790580419315,"chunk":{"type":"usage","usage":{"inputTokens":5830,"outputTokens":147,"cacheReadTokens":0,"cacheWriteTokens":0,"totalTokens":5977}}},{"type":"chunk","time":1790580419315,"chunk":{"type":"finish","reason":{"kind":"tool-calls"},"replayState":{"response":{"kind":"deepseek-messages","version":1,"model":"deepseek-flash"},"blocks":[{"type":"reasoning","signature":"6610ccac-b3b1-4b1e-afb1-f787fb63a39e"},{"type":"tool-call"}]}}}]},"surfaceOp":"append"} @@ -18,7 +18,7 @@ {"type":"step/end","data":{"turn":1,"step":1}} {"type":"step/start","data":{"turn":1,"step":2}} {"type":"system/message","data":{"turn":1,"step":2,"message":{"role":"system","content":[{"type":"text","text":"{{system}}"}],"source":{"kind":"system-prompt"},"id":"{{message:6}}"}},"sourceEventSeqs":[7],"surfaceOp":{"op":"replace","startSeq":7,"endSeq":7}} -{"type":"request/header","data":{"header":{"config":{"provider":"deepseek-official","model":"deepseek-flash","maxTokens":256000,"reasoningEffort":"max"},"adapterDefaults":{"reasoningEffort":true,"maxTokens":true},"tools":["bash","create_goal","edit","exit_plan_mode","get_goal","glob","grep","interrupt_agent","job_kill","job_list","job_output","list_agents","list_mcp_resource_templates","list_mcp_resources","read","read_image","read_mcp_resource","send_message","skill","subagent","subagent_fork","todo_write","update_goal","web_fetch","web_search","workflow","working_directory","write"]},"reason":"change","startsSeries":true}} +{"type":"request/header","data":{"header":{"config":{"provider":"deepseek-official","model":"deepseek-flash","maxTokens":256000,"reasoningEffort":"max"},"adapterDefaults":{"reasoningEffort":true,"maxTokens":true},"tools":["bash","create_goal","edit","get_goal","glob","grep","interrupt_agent","job_kill","job_list","job_output","list_agents","list_mcp_resource_templates","list_mcp_resources","read","read_image","read_mcp_resource","send_message","skill","subagent","subagent_fork","todo_write","update_goal","web_fetch","web_search","workflow","working_directory","write"]},"reason":"change","startsSeries":true}} {"type":"developer/message","data":{"turn":1,"step":2,"message":{"source":{"kind":"tool-registry"},"content":[{"type":"tool-removal","toolName":"mcp__protected__ping"}],"role":"developer","id":"{{message:7}}"}},"surfaceOp":"append"} {"type":"assistant/message","data":{"turn":1,"step":2,"message":{"role":"assistant","content":[{"type":"reasoning","text":""},{"type":"text","text":"MCP_ERROR_OBSERVED"}],"source":{"kind":"model","provider":"deepseek-official","model":"deepseek-flash","replayState":{"response":{"kind":"deepseek-messages","version":1,"model":"deepseek-flash"},"blocks":[{"type":"reasoning","signature":"de1ccb67-7856-4e2d-8ce8-f6b76958453d"},{"type":"text"}]}},"id":"{{message:8}}"},"usage":{"inputTokens":248,"outputTokens":8,"cacheReadTokens":5760,"cacheWriteTokens":0,"totalTokens":6016},"stream":[{"type":"chunk","time":1790580419351,"chunk":{"type":"block-start","index":0,"blockType":"reasoning"}},{"type":"chunk","time":1790580419351,"chunk":{"type":"block-end","index":0,"block":{"type":"reasoning","text":""}}},{"type":"chunk","time":1790580419351,"chunk":{"type":"block-start","index":1,"blockType":"text"}},{"type":"text-chunks","time0":1790580419351,"index":1,"dt":[0,0,0,0,0,0],"texts":["M","CP","_ERROR","_O","BS","ERV","ED"]},{"type":"chunk","time":1790580419351,"chunk":{"type":"block-end","index":1,"block":{"type":"text","text":"MCP_ERROR_OBSERVED"}}},{"type":"chunk","time":1790580419351,"chunk":{"type":"usage","usage":{"inputTokens":248,"outputTokens":8,"cacheReadTokens":5760,"cacheWriteTokens":0,"totalTokens":6016}}},{"type":"chunk","time":1790580419351,"chunk":{"type":"finish","reason":{"kind":"stop"},"replayState":{"response":{"kind":"deepseek-messages","version":1,"model":"deepseek-flash"},"blocks":[{"type":"reasoning","signature":"de1ccb67-7856-4e2d-8ce8-f6b76958453d"},{"type":"text"}]}}}]},"surfaceOp":"append"} {"type":"step/end","data":{"turn":1,"step":2}} diff --git a/snapshots/session/mcp-oauth-error/system-prompt.expected.md b/snapshots/session/mcp-oauth-error/system-prompt.expected.md index 62fb9bd8c4..c771dde51d 100644 --- a/snapshots/session/mcp-oauth-error/system-prompt.expected.md +++ b/snapshots/session/mcp-oauth-error/system-prompt.expected.md @@ -27,7 +27,7 @@ create_goal may infer goal intent from a direct human request in any language. A Use the workflow tool ONLY when the user explicitly asks for a workflow or for large multi-agent orchestration: you write a JavaScript script (the tool description documents the exact format) that fans work out across many subagents with phases and structured results. For one or two delegations, prefer plain subagent calls. -Start independent delegations with `subagent` or `subagent_fork` together in one assistant message and continue useful work while they run. +Start independent delegations with `subagent` or `subagent_fork` together in one assistant message and continue useful work while they run. When only waiting for their results remains, end your turn instead of sleeping or polling; the next result starts a new turn. ## MCP resource servers @@ -68,7 +68,7 @@ create_goal may infer goal intent from a direct human request in any language. A Use the workflow tool ONLY when the user explicitly asks for a workflow or for large multi-agent orchestration: you write a JavaScript script (the tool description documents the exact format) that fans work out across many subagents with phases and structured results. For one or two delegations, prefer plain subagent calls. -Start independent delegations with `subagent` or `subagent_fork` together in one assistant message and continue useful work while they run. +Start independent delegations with `subagent` or `subagent_fork` together in one assistant message and continue useful work while they run. When only waiting for their results remains, end your turn instead of sleeping or polling; the next result starts a new turn. ## MCP resource servers diff --git a/snapshots/session/mcp-oauth-error/tool-schemas.expected.json b/snapshots/session/mcp-oauth-error/tool-schemas.expected.json index 2b6d605ffa..b3158e6737 100644 --- a/snapshots/session/mcp-oauth-error/tool-schemas.expected.json +++ b/snapshots/session/mcp-oauth-error/tool-schemas.expected.json @@ -107,22 +107,6 @@ ] } }, - { - "name": "exit_plan_mode", - "description": "Use only in plan mode. Present your plan for the user's review and, on approval, leave plan mode. The user may approve (carry out the plan from your next step) or keep planning — their feedback comes back in the tool result; revise and present again.", - "parameters": { - "type": "object", - "properties": { - "plan": { - "type": "string", - "description": "The complete plan, as markdown, starting with a # heading that names it." - } - }, - "required": [ - "plan" - ] - } - }, { "name": "get_goal", "description": "Read the current session goal, including the id and revision that update_goal requires.", @@ -810,22 +794,6 @@ ] } }, - { - "name": "exit_plan_mode", - "description": "Use only in plan mode. Present your plan for the user's review and, on approval, leave plan mode. The user may approve (carry out the plan from your next step) or keep planning — their feedback comes back in the tool result; revise and present again.", - "parameters": { - "type": "object", - "properties": { - "plan": { - "type": "string", - "description": "The complete plan, as markdown, starting with a # heading that names it." - } - }, - "required": [ - "plan" - ] - } - }, { "name": "get_goal", "description": "Read the current session goal, including the id and revision that update_goal requires.",