@vibe-forge/mcp 0.8.0 → 0.9.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.
- package/AGENTS.md +2 -2
- package/__tests__/tools.spec.ts +48 -2
- package/package.json +8 -8
- package/src/command.ts +1 -1
- package/src/tools/index.ts +1 -1
- package/src/tools/interaction/ask-user.ts +39 -5
- package/src/tools/task/manager.ts +1 -0
package/AGENTS.md
CHANGED
|
@@ -34,6 +34,6 @@
|
|
|
34
34
|
|
|
35
35
|
## 相关文档
|
|
36
36
|
|
|
37
|
-
- [架构说明](/Users/bytedance/projects/vibe-forge.ai/.ai/rules/
|
|
38
|
-
- [使用文档](/Users/bytedance/projects/vibe-forge.ai/.ai/rules/
|
|
37
|
+
- [架构说明](/Users/bytedance/projects/vibe-forge.ai/.ai/rules/ARCHITECTURE.md)
|
|
38
|
+
- [使用文档](/Users/bytedance/projects/vibe-forge.ai/.ai/rules/USAGE.md)
|
|
39
39
|
- [CLI 维护说明](/Users/bytedance/projects/vibe-forge.ai/apps/cli/src/AGENTS.md)
|
package/__tests__/tools.spec.ts
CHANGED
|
@@ -1,11 +1,22 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest'
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
|
2
2
|
|
|
3
|
-
import
|
|
3
|
+
import askUser from '#~/tools/interaction/ask-user.js'
|
|
4
4
|
import wait from '#~/tools/general/wait.js'
|
|
5
|
+
import { createMcpTools } from '#~/tools/index.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.
|
|
3
|
+
"version": "0.9.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/
|
|
37
|
-
"@vibe-forge/
|
|
38
|
-
"@vibe-forge/
|
|
39
|
-
"@vibe-forge/
|
|
40
|
-
"@vibe-forge/
|
|
41
|
-
"@vibe-forge/
|
|
42
|
-
"@vibe-forge/
|
|
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"
|
|
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
|
@@ -4,9 +4,9 @@ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
|
|
|
4
4
|
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'
|
|
5
5
|
import type { Command } from 'commander'
|
|
6
6
|
|
|
7
|
-
import type { McpOptions } from './types'
|
|
8
7
|
import { createMcpTools } from './tools'
|
|
9
8
|
import { createFilteredRegister, shouldEnableCategory } from './tools/proxy'
|
|
9
|
+
import type { McpOptions } from './types'
|
|
10
10
|
|
|
11
11
|
export const configureMcpCommand = (command: Command, version: string) => (
|
|
12
12
|
command
|
package/src/tools/index.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import wait from './general/wait'
|
|
2
2
|
import askUser from './interaction/ask-user'
|
|
3
|
-
import type { Register } from './types'
|
|
4
3
|
import { createTaskRegister } from './task'
|
|
4
|
+
import type { Register } from './types'
|
|
5
5
|
|
|
6
6
|
export const createMcpTools = (): Record<string, Register> => ({
|
|
7
7
|
general: (server) => {
|
|
@@ -6,9 +6,18 @@ 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
|
+
}).optional().describe('Extra context for permission escalation prompts')
|
|
12
21
|
})
|
|
13
22
|
|
|
14
23
|
export default defineRegister(({ registerTool }) => {
|
|
@@ -20,7 +29,7 @@ export default defineRegister(({ registerTool }) => {
|
|
|
20
29
|
inputSchema: Schema
|
|
21
30
|
},
|
|
22
31
|
async (args) => {
|
|
23
|
-
const { question, options, multiselect } = args
|
|
32
|
+
const { question, options, multiselect, kind, permissionContext } = args
|
|
24
33
|
const sessionId = process.env.__VF_PROJECT_AI_SESSION_ID__
|
|
25
34
|
|
|
26
35
|
if (!sessionId) {
|
|
@@ -40,7 +49,9 @@ export default defineRegister(({ registerTool }) => {
|
|
|
40
49
|
sessionId,
|
|
41
50
|
question,
|
|
42
51
|
options,
|
|
43
|
-
multiselect
|
|
52
|
+
multiselect,
|
|
53
|
+
kind,
|
|
54
|
+
permissionContext
|
|
44
55
|
})
|
|
45
56
|
})
|
|
46
57
|
|
|
@@ -49,12 +60,35 @@ export default defineRegister(({ registerTool }) => {
|
|
|
49
60
|
throw new Error(`Failed to ask user question: ${response.statusText} - ${errorText}`)
|
|
50
61
|
}
|
|
51
62
|
|
|
52
|
-
const result = await response.json()
|
|
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
|
+
|
|
53
87
|
return {
|
|
54
88
|
content: [
|
|
55
89
|
{
|
|
56
90
|
type: 'text',
|
|
57
|
-
text
|
|
91
|
+
text
|
|
58
92
|
}
|
|
59
93
|
]
|
|
60
94
|
}
|
|
@@ -117,6 +117,7 @@ export class TaskManager {
|
|
|
117
117
|
skills: resolvedConfig.skills,
|
|
118
118
|
mcpServers: resolvedConfig.mcpServers,
|
|
119
119
|
promptAssetIds: resolvedConfig.promptAssetIds,
|
|
120
|
+
assetBundle: resolvedConfig.assetBundle,
|
|
120
121
|
onEvent: (event: McpTaskOutputEvent) => {
|
|
121
122
|
this.handleEvent(taskId, event)
|
|
122
123
|
}
|