@vibe-forge/mcp 0.9.0 → 0.9.1-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.
@@ -0,0 +1,94 @@
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
+ })
@@ -1,22 +1,11 @@
1
- import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
1
+ import { describe, expect, it } from 'vitest'
2
2
 
3
- import askUser from '#~/tools/interaction/ask-user.js'
4
3
  import wait from '#~/tools/general/wait.js'
5
4
  import { createMcpTools } from '#~/tools/index.js'
6
5
 
7
6
  import { createToolTester } from './mcp-test-utils.js'
8
7
 
9
8
  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
-
20
9
  it('registers task tools by default', () => {
21
10
  expect(createMcpTools()).toHaveProperty('task')
22
11
  })
@@ -57,39 +46,4 @@ describe('mcp tools integration', () => {
57
46
  .rejects.toThrow()
58
47
  })
59
48
  })
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
- })
95
49
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vibe-forge/mcp",
3
- "version": "0.9.0",
3
+ "version": "0.9.1-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.9.0",
37
- "@vibe-forge/hooks": "^0.9.0",
38
- "@vibe-forge/task": "^0.9.0",
39
- "@vibe-forge/utils": "^0.9.0",
40
- "@vibe-forge/types": "^0.9.0",
41
- "@vibe-forge/cli-helper": "^0.9.0",
42
- "@vibe-forge/register": "^0.9.0"
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/cli-helper": "^0.8.0",
41
+ "@vibe-forge/hooks": "^0.8.0",
42
+ "@vibe-forge/task": "^0.8.3"
43
43
  },
44
44
  "scripts": {
45
45
  "test": "pnpm -C ../.. exec vitest run --workspace vitest.workspace.ts --project bundler packages/mcp/__tests__"
package/src/index.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  export { configureMcpCommand, registerMcpCommand } from './command'
2
2
  export type {
3
3
  McpManagedTaskInput,
4
+ McpResolvedManagedTaskInput,
4
5
  McpOptions,
5
6
  McpResolvedTaskQueryOptions,
6
7
  McpSelectionFilter,
@@ -6,18 +6,9 @@ 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'),
10
9
  description: z.string().optional().describe('The description of the option')
11
10
  })).optional().describe('The options for the user to select from'),
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
- }).optional().describe('Extra context for permission escalation prompts')
11
+ multiselect: z.boolean().optional().describe('Whether the user can select multiple options')
21
12
  })
22
13
 
23
14
  export default defineRegister(({ registerTool }) => {
@@ -29,7 +20,7 @@ export default defineRegister(({ registerTool }) => {
29
20
  inputSchema: Schema
30
21
  },
31
22
  async (args) => {
32
- const { question, options, multiselect, kind, permissionContext } = args
23
+ const { question, options, multiselect } = args
33
24
  const sessionId = process.env.__VF_PROJECT_AI_SESSION_ID__
34
25
 
35
26
  if (!sessionId) {
@@ -49,9 +40,7 @@ export default defineRegister(({ registerTool }) => {
49
40
  sessionId,
50
41
  question,
51
42
  options,
52
- multiselect,
53
- kind,
54
- permissionContext
43
+ multiselect
55
44
  })
56
45
  })
57
46
 
@@ -60,35 +49,12 @@ export default defineRegister(({ registerTool }) => {
60
49
  throw new Error(`Failed to ask user question: ${response.statusText} - ${errorText}`)
61
50
  }
62
51
 
63
- const result = await response.json() as { data?: unknown; result?: unknown } | unknown
64
- const body = (
65
- result != null &&
66
- typeof result === 'object' &&
67
- 'data' in result
68
- ? (result as { data?: unknown }).data
69
- : result
70
- )
71
- const answer = (
72
- body != null &&
73
- typeof body === 'object' &&
74
- 'result' in body
75
- ? (body as { result?: unknown }).result
76
- : body
77
- )
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
-
52
+ const result = await response.json()
87
53
  return {
88
54
  content: [
89
55
  {
90
56
  type: 'text',
91
- text
57
+ text: JSON.stringify(result.result)
92
58
  }
93
59
  ]
94
60
  }
@@ -5,7 +5,7 @@ import { uuid } from '@vibe-forge/utils/uuid'
5
5
  import { z } from 'zod'
6
6
 
7
7
  import { createChildSession, getParentSessionId } from '#~/sync.js'
8
- import type { McpManagedTaskInput } from '../../types'
8
+ import type { McpResolvedManagedTaskInput } from '../../types'
9
9
  import { defineRegister } from '../types'
10
10
  import { TaskManager } from './manager'
11
11
 
@@ -56,7 +56,7 @@ export const createTaskRegister = () => {
56
56
  })
57
57
  },
58
58
  async ({ tasks }) => {
59
- const resolvedTasks = tasks.map((task): McpManagedTaskInput & { taskId: string } => ({
59
+ const resolvedTasks = tasks.map((task): McpResolvedManagedTaskInput => ({
60
60
  ...task,
61
61
  taskId: uuid()
62
62
  }))
@@ -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
68
+ tasks: resolvedTasks
69
69
  })
70
70
  const syncResults = parentSessionId
71
71
  ? await Promise.allSettled(resolvedTasks.map(task =>
@@ -117,7 +117,6 @@ export class TaskManager {
117
117
  skills: resolvedConfig.skills,
118
118
  mcpServers: resolvedConfig.mcpServers,
119
119
  promptAssetIds: resolvedConfig.promptAssetIds,
120
- assetBundle: resolvedConfig.assetBundle,
121
120
  onEvent: (event: McpTaskOutputEvent) => {
122
121
  this.handleEvent(taskId, event)
123
122
  }
package/src/types.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export type {
2
2
  McpManagedTaskInput,
3
+ McpResolvedManagedTaskInput,
3
4
  McpResolvedTaskQueryOptions,
4
5
  McpSelectionFilter,
5
6
  McpTaskBindings,