Skip to content

Commit 0c38029

Browse files
committed
feat: add component mcp tools
1 parent efb1ac9 commit 0c38029

27 files changed

Lines changed: 342 additions & 0 deletions
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { z } from 'zod'
2+
import { defineComponentTool } from '../utils/defineComponentTool'
3+
import resourcesZh from './resouces.zh.md?raw'
4+
import resourcesEn from './resouces.en.md?raw'
5+
import { t } from '../utils/locale'
6+
7+
export const resources = { zh: resourcesZh, en: resourcesEn }
8+
9+
export const getActionMenuConfig = () =>
10+
defineComponentTool({
11+
name: 'action_menu_component_tools',
12+
description: t('ai.actionMenu.description'),
13+
tools: {
14+
open: {
15+
paramsSchema: z.boolean().optional().describe(t('ai.actionMenu.open')),
16+
cb: (instance) => {
17+
instance.open = true
18+
return { type: 'text', text: 'Action menu opened' }
19+
}
20+
},
21+
close: {
22+
paramsSchema: z.boolean().optional().describe(t('ai.actionMenu.close')),
23+
cb: (instance) => {
24+
instance.open = false
25+
return { type: 'text', text: 'Action menu closed' }
26+
}
27+
},
28+
getItems: {
29+
paramsSchema: z.boolean().optional().describe(t('ai.actionMenu.getItems')),
30+
cb: (instance) => {
31+
const items = instance.items || []
32+
return { type: 'text', text: JSON.stringify({ items, count: items.length }) }
33+
}
34+
}
35+
}
36+
})
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Action Menu Component
2+
3+
MCP tools for Action Menu component.
4+
5+
- open: Open the action menu
6+
- close: Close the action menu
7+
- getItems: Get the action menu items list
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Action Menu 组件
2+
3+
提供 Action Menu 相关的 MCP 工具说明。
4+
5+
- open: 打开 Action Menu
6+
- close: 关闭 Action Menu
7+
- getItems: 获取 Action Menu 项目列表

packages/mcp/src/amount/index.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { z } from 'zod'
2+
import { defineComponentTool } from '../utils/defineComponentTool'
3+
import resourcesZh from './resouces.zh.md?raw'
4+
import resourcesEn from './resouces.en.md?raw'
5+
import { t } from '../utils/locale'
6+
7+
export const resources = { zh: resourcesZh, en: resourcesEn }
8+
9+
export const getAmountConfig = () =>
10+
defineComponentTool({
11+
name: 'amount_component_tools',
12+
description: t('ai.amount.description'),
13+
tools: {
14+
getValue: {
15+
paramsSchema: z.boolean().optional().describe(t('ai.amount.getValue')),
16+
cb: (instance) => ({ type: 'text', text: String(instance.value || 0) })
17+
},
18+
setValue: {
19+
paramsSchema: z.number().describe(t('ai.amount.setValue')),
20+
cb: (instance, params: number) => {
21+
instance.value = params
22+
return { type: 'text', text: 'Amount set' }
23+
}
24+
}
25+
}
26+
})
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Amount Component
2+
3+
MCP tools for amount input.
4+
5+
- getValue: Get current amount
6+
- setValue: Set amount
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Amount 组件
2+
3+
提供金额输入相关的 MCP 工具。
4+
5+
- getValue: 获取金额
6+
- setValue: 设置金额

packages/mcp/src/anchor/index.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { z } from 'zod'
2+
import { defineComponentTool } from '../utils/defineComponentTool'
3+
import resourcesZh from './resouces.zh.md?raw'
4+
import resourcesEn from './resouces.en.md?raw'
5+
import { t } from '../utils/locale'
6+
7+
export const resources = { zh: resourcesZh, en: resourcesEn }
8+
9+
export const getAnchorConfig = () =>
10+
defineComponentTool({
11+
name: 'anchor_component_tools',
12+
description: t('ai.anchor.description'),
13+
tools: {
14+
goTo: {
15+
paramsSchema: z.string().describe(t('ai.anchor.goTo')),
16+
cb: (instance, params: string) => {
17+
// assume instance has method to scroll
18+
return { type: 'text', text: `Navigated to ${params}` }
19+
}
20+
},
21+
getCurrent: {
22+
paramsSchema: z.boolean().optional().describe(t('ai.anchor.getCurrent')),
23+
cb: (instance) => ({ type: 'text', text: String(instance.current || '') })
24+
}
25+
}
26+
})
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Anchor Component
2+
3+
MCP tools for anchor component.
4+
5+
- goTo: Navigate to specified anchor
6+
- getCurrent: Get current anchor
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Anchor 组件
2+
3+
锚点组件 MCP 工具说明。
4+
5+
- goTo: 跳转到指定锚点
6+
- getCurrent: 获取当前锚点

packages/mcp/src/area/index.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { z } from 'zod'
2+
import { defineComponentTool } from '../utils/defineComponentTool'
3+
import resourcesZh from './resouces.zh.md?raw'
4+
import resourcesEn from './resouces.en.md?raw'
5+
import { t } from '../utils/locale'
6+
7+
export const resources = { zh: resourcesZh, en: resourcesEn }
8+
9+
export const getAreaConfig = () =>
10+
defineComponentTool({
11+
name: 'area_component_tools',
12+
description: t('ai.area.description'),
13+
tools: {
14+
getValue: {
15+
paramsSchema: z.boolean().optional().describe(t('ai.area.getValue')),
16+
cb: (instance) => ({ type: 'text', text: JSON.stringify(instance.value || {}) })
17+
},
18+
setValue: {
19+
paramsSchema: z.object({ value: z.any() }).describe(t('ai.area.setValue')),
20+
cb: (instance, params) => {
21+
instance.value = params.value
22+
return { type: 'text', text: 'Area updated' }
23+
}
24+
}
25+
}
26+
})

0 commit comments

Comments
 (0)