@vibe-forge/mcp 0.9.1-alpha.2 → 0.9.2-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,11 +1,22 @@
1
- import { describe, expect, it } from 'vitest'
1
+ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
2
2
 
3
3
  import wait from '#~/tools/general/wait.js'
4
4
  import { createMcpTools } from '#~/tools/index.js'
5
+ import askUser from '#~/tools/interaction/ask-user.js'
5
6
 
6
7
  import { createToolTester } from './mcp-test-utils.js'
7
8
 
8
9
  describe('mcp tools integration', () => {
10
+ beforeEach(() => {
11
+ process.env.__VF_PROJECT_AI_SESSION_ID__ = 'sess-1'
12
+ vi.stubGlobal('fetch', vi.fn())
13
+ })
14
+
15
+ afterEach(() => {
16
+ delete process.env.__VF_PROJECT_AI_SESSION_ID__
17
+ vi.unstubAllGlobals()
18
+ })
19
+
9
20
  it('registers task tools by default', () => {
10
21
  expect(createMcpTools()).toHaveProperty('task')
11
22
  })
@@ -46,4 +57,39 @@ describe('mcp tools integration', () => {
46
57
  .rejects.toThrow()
47
58
  })
48
59
  })
60
+
61
+ describe('askUserQuestion tool', () => {
62
+ it('returns scalar answers as plain text content', async () => {
63
+ const tester = createToolTester()
64
+ askUser(tester.mockRegister)
65
+ vi.mocked(fetch).mockResolvedValue({
66
+ ok: true,
67
+ json: async () => ({ success: true, data: { result: '米饭' } })
68
+ } as Response)
69
+
70
+ const result = await tester.callTool('AskUserQuestion', {
71
+ question: '今晚吃了什么?',
72
+ options: [{ label: '米饭' }]
73
+ }) as any
74
+
75
+ expect(result.content).toEqual([{ type: 'text', text: '米饭' }])
76
+ })
77
+
78
+ it('returns multiselect answers as newline-separated text', async () => {
79
+ const tester = createToolTester()
80
+ askUser(tester.mockRegister)
81
+ vi.mocked(fetch).mockResolvedValue({
82
+ ok: true,
83
+ json: async () => ({ success: true, data: { result: ['米饭', '面条'] } })
84
+ } as Response)
85
+
86
+ const result = await tester.callTool('AskUserQuestion', {
87
+ question: '今晚吃了什么?',
88
+ options: [{ label: '米饭' }, { label: '面条' }],
89
+ multiselect: true
90
+ }) as any
91
+
92
+ expect(result.content).toEqual([{ type: 'text', text: '米饭\n面条' }])
93
+ })
94
+ })
49
95
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vibe-forge/mcp",
3
- "version": "0.9.1-alpha.2",
3
+ "version": "0.9.2-alpha.0",
4
4
  "description": "Vibe Forge MCP server",
5
5
  "imports": {
6
6
  "#~/*.js": {
@@ -33,13 +33,13 @@
33
33
  "@modelcontextprotocol/sdk": "^1.25.3",
34
34
  "commander": "^12.1.0",
35
35
  "zod": "^3.24.1",
36
- "@vibe-forge/config": "^0.8.3",
37
- "@vibe-forge/register": "^0.8.0",
38
- "@vibe-forge/types": "^0.8.3",
39
- "@vibe-forge/utils": "^0.8.3",
40
- "@vibe-forge/task": "^0.8.3",
41
- "@vibe-forge/cli-helper": "^0.8.0",
42
- "@vibe-forge/hooks": "^0.8.0"
36
+ "@vibe-forge/hooks": "^0.9.1",
37
+ "@vibe-forge/config": "^0.9.1-alpha.0",
38
+ "@vibe-forge/cli-helper": "^0.9.0",
39
+ "@vibe-forge/task": "^0.9.0",
40
+ "@vibe-forge/types": "^0.9.0",
41
+ "@vibe-forge/utils": "^0.9.0",
42
+ "@vibe-forge/register": "^0.9.0"
43
43
  },
44
44
  "scripts": {
45
45
  "test": "pnpm -C ../.. exec vitest run --workspace vitest.workspace.ts --project bundler packages/mcp/__tests__"
package/src/command.ts CHANGED
@@ -59,5 +59,5 @@ export const configureMcpCommand = (command: Command, version: string) => (
59
59
  )
60
60
 
61
61
  export function registerMcpCommand(program: Command, version: string) {
62
- return configureMcpCommand(program.command('mcp'), version)
62
+ return configureMcpCommand(program, version)
63
63
  }
@@ -6,9 +6,22 @@ const Schema = z.object({
6
6
  question: z.string().describe('The question to ask the user'),
7
7
  options: z.array(z.object({
8
8
  label: z.string().describe('The label of the option'),
9
+ value: z.string().optional().describe('Stable value returned when the option is chosen'),
9
10
  description: z.string().optional().describe('The description of the option')
10
11
  })).optional().describe('The options for the user to select from'),
11
- multiselect: z.boolean().optional().describe('Whether the user can select multiple options')
12
+ multiselect: z.boolean().optional().describe('Whether the user can select multiple options'),
13
+ kind: z.enum(['question', 'permission']).optional().describe('UI hint for how to present the interaction'),
14
+ permissionContext: z.object({
15
+ adapter: z.string().optional(),
16
+ currentMode: z.enum(['default', 'acceptEdits', 'plan', 'dontAsk', 'bypassPermissions']).optional(),
17
+ suggestedMode: z.enum(['default', 'acceptEdits', 'plan', 'dontAsk', 'bypassPermissions']).optional(),
18
+ deniedTools: z.array(z.string()).optional(),
19
+ reasons: z.array(z.string()).optional(),
20
+ subjectKey: z.string().optional(),
21
+ subjectLabel: z.string().optional(),
22
+ scope: z.enum(['tool']).optional(),
23
+ projectConfigPath: z.string().optional()
24
+ }).optional().describe('Extra context for permission escalation prompts')
12
25
  })
13
26
 
14
27
  export default defineRegister(({ registerTool }) => {
@@ -20,7 +33,7 @@ export default defineRegister(({ registerTool }) => {
20
33
  inputSchema: Schema
21
34
  },
22
35
  async (args) => {
23
- const { question, options, multiselect } = args
36
+ const { question, options, multiselect, kind, permissionContext } = args
24
37
  const sessionId = process.env.__VF_PROJECT_AI_SESSION_ID__
25
38
 
26
39
  if (!sessionId) {
@@ -40,7 +53,9 @@ export default defineRegister(({ registerTool }) => {
40
53
  sessionId,
41
54
  question,
42
55
  options,
43
- multiselect
56
+ multiselect,
57
+ kind,
58
+ permissionContext
44
59
  })
45
60
  })
46
61
 
@@ -49,12 +64,31 @@ export default defineRegister(({ registerTool }) => {
49
64
  throw new Error(`Failed to ask user question: ${response.statusText} - ${errorText}`)
50
65
  }
51
66
 
52
- const result = await response.json()
67
+ const result = await response.json() as { data?: unknown; result?: unknown } | unknown
68
+ const body = result != null &&
69
+ typeof result === 'object' &&
70
+ 'data' in result
71
+ ? (result as { data?: unknown }).data
72
+ : result
73
+ const answer = body != null &&
74
+ typeof body === 'object' &&
75
+ 'result' in body
76
+ ? (body as { result?: unknown }).result
77
+ : body
78
+
79
+ if (answer == null) {
80
+ throw new Error('AskUserQuestion returned an empty result')
81
+ }
82
+
83
+ const text = Array.isArray(answer)
84
+ ? answer.map(item => String(item)).join('\n')
85
+ : String(answer)
86
+
53
87
  return {
54
88
  content: [
55
89
  {
56
90
  type: 'text',
57
- text: JSON.stringify(result.result)
91
+ text
58
92
  }
59
93
  ]
60
94
  }
@@ -65,7 +65,7 @@ export const createTaskRegister = () => {
65
65
  await callHook('StartTasks', {
66
66
  cwd: process.cwd(),
67
67
  sessionId: process.env.__VF_PROJECT_AI_SESSION_ID__!,
68
- tasks: resolvedTasks
68
+ tasks
69
69
  })
70
70
  const syncResults = parentSessionId
71
71
  ? await Promise.allSettled(resolvedTasks.map(task =>
@@ -3,7 +3,7 @@ import process from 'node:process'
3
3
  import { loadInjectDefaultSystemPromptValue, mergeSystemPrompts } from '@vibe-forge/config'
4
4
  import { callHook } from '@vibe-forge/hooks'
5
5
  import { generateAdapterQueryOptions, run } from '@vibe-forge/task'
6
- import type { ChatMessage, McpTaskOutputEvent, McpTaskSession, SessionPermissionMode } from '@vibe-forge/types'
6
+ import type { AdapterOutputEvent, ChatMessage, McpTaskSession, SessionPermissionMode } from '@vibe-forge/types'
7
7
  import { extractTextFromMessage } from '@vibe-forge/utils/chat-message'
8
8
 
9
9
  import { fetchSessionMessages, postSessionEvent } from '#~/sync.js'
@@ -117,7 +117,8 @@ export class TaskManager {
117
117
  skills: resolvedConfig.skills,
118
118
  mcpServers: resolvedConfig.mcpServers,
119
119
  promptAssetIds: resolvedConfig.promptAssetIds,
120
- onEvent: (event: McpTaskOutputEvent) => {
120
+ assetBundle: resolvedConfig.assetBundle,
121
+ onEvent: (event: AdapterOutputEvent) => {
121
122
  this.handleEvent(taskId, event)
122
123
  }
123
124
  })
@@ -164,7 +165,7 @@ export class TaskManager {
164
165
  return { taskId }
165
166
  }
166
167
 
167
- private handleEvent(taskId: string, event: McpTaskOutputEvent) {
168
+ private handleEvent(taskId: string, event: AdapterOutputEvent) {
168
169
  const task = this.tasks.get(taskId)
169
170
  if (!task) return
170
171
 
@@ -220,6 +221,8 @@ export class TaskManager {
220
221
  this.stopServerPolling(taskId)
221
222
  task.onStop?.()
222
223
  break
224
+ default:
225
+ break
223
226
  }
224
227
  }
225
228
 
@@ -271,7 +274,7 @@ export class TaskManager {
271
274
  }
272
275
  }
273
276
 
274
- private async syncEvent(task: TaskInfo, event: McpTaskOutputEvent) {
277
+ private async syncEvent(task: TaskInfo, event: AdapterOutputEvent) {
275
278
  if (!task.serverSync) return
276
279
  try {
277
280
  await postSessionEvent(task.serverSync.sessionId, event as unknown as Record<string, unknown>)
@@ -1,94 +0,0 @@
1
- import { beforeEach, describe, expect, it, vi } from 'vitest'
2
-
3
- const mocks = vi.hoisted(() => ({
4
- callHook: vi.fn(),
5
- uuid: vi.fn(),
6
- createChildSession: vi.fn(),
7
- getParentSessionId: vi.fn(),
8
- startTask: vi.fn(),
9
- getTask: vi.fn()
10
- }))
11
-
12
- vi.mock('@vibe-forge/hooks', () => ({
13
- callHook: mocks.callHook
14
- }))
15
-
16
- vi.mock('@vibe-forge/utils/uuid', () => ({
17
- uuid: mocks.uuid
18
- }))
19
-
20
- vi.mock('#~/sync.js', () => ({
21
- createChildSession: mocks.createChildSession,
22
- getParentSessionId: mocks.getParentSessionId
23
- }))
24
-
25
- vi.mock('#~/tools/task/manager.js', () => ({
26
- TaskManager: class {
27
- startTask = mocks.startTask
28
- getTask = mocks.getTask
29
- }
30
- }))
31
-
32
- import { createTaskRegister } from '#~/tools/task/index.js'
33
-
34
- import { createToolTester } from './mcp-test-utils.js'
35
-
36
- describe('StartTasks hook payload', () => {
37
- beforeEach(() => {
38
- vi.clearAllMocks()
39
- mocks.callHook.mockResolvedValue({ continue: true })
40
- mocks.getParentSessionId.mockReturnValue(undefined)
41
- mocks.startTask.mockImplementation(async ({ taskId }: { taskId: string }) => ({ taskId }))
42
- mocks.getTask.mockImplementation((taskId: string) => ({
43
- taskId,
44
- status: 'running',
45
- logs: []
46
- }))
47
- })
48
-
49
- it('passes resolved task ids to the StartTasks hook before launching child tasks', async () => {
50
- mocks.uuid
51
- .mockReturnValueOnce('task-1')
52
- .mockReturnValueOnce('task-2')
53
-
54
- const tester = createToolTester()
55
- createTaskRegister()(tester.mockRegister)
56
-
57
- await tester.callTool('StartTasks', {
58
- tasks: [
59
- { description: 'first task', type: 'entity', name: 'alpha' },
60
- { description: 'second task', type: 'spec', name: 'beta', background: false }
61
- ]
62
- })
63
-
64
- expect(mocks.callHook).toHaveBeenCalledWith(
65
- 'StartTasks',
66
- expect.objectContaining({
67
- tasks: [
68
- {
69
- taskId: 'task-1',
70
- description: 'first task',
71
- type: 'entity',
72
- name: 'alpha'
73
- },
74
- {
75
- taskId: 'task-2',
76
- description: 'second task',
77
- type: 'spec',
78
- name: 'beta',
79
- background: false
80
- }
81
- ]
82
- })
83
- )
84
-
85
- expect(mocks.startTask).toHaveBeenNthCalledWith(
86
- 1,
87
- expect.objectContaining({ taskId: 'task-1' })
88
- )
89
- expect(mocks.startTask).toHaveBeenNthCalledWith(
90
- 2,
91
- expect.objectContaining({ taskId: 'task-2' })
92
- )
93
- })
94
- })