Skip to content

Commit 6ac1c7e

Browse files
committed
fix: mcp issue
1 parent d7c3a1f commit 6ac1c7e

8 files changed

Lines changed: 66 additions & 54 deletions

File tree

packages/plugins/page/src/mcp/tools/editSpecificPage.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const inputSchema = z.object({
66
})
77

88
export const editSpecificPage = {
9-
name: 'Edit_page_in_canvas.',
9+
name: 'edit_page_in_canvas',
1010
title: '在画布中编辑页面',
1111
order: 9,
1212
description: 'Edit a specific page in canvas. Use this tool when you need to edit some page in canvas.',
70.5 KB
Loading

packages/plugins/robot/src/Main.vue

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
@item-click="handlePromptItemClick"
5454
></tr-prompts>
5555
</div>
56-
<tr-bubble-provider :content-renderers="{ markdown: MarkdownRenderer }" v-else>
56+
<tr-bubble-provider :content-renderers="contentRenderers" v-else>
5757
<tr-bubble-list :items="activeMessages" :roles="roles" autoScroll></tr-bubble-list>
5858
</tr-bubble-provider>
5959
</div>
@@ -80,7 +80,18 @@
8080

8181
<script lang="ts">
8282
/* metaService: engine.plugins.robot.Main */
83-
import { ref, onMounted, watchEffect, type CSSProperties, h, resolveComponent, computed, watch } from 'vue'
83+
import {
84+
ref,
85+
onMounted,
86+
watchEffect,
87+
type CSSProperties,
88+
h,
89+
resolveComponent,
90+
computed,
91+
watch,
92+
nextTick,
93+
type Component
94+
} from 'vue'
8495
import { Notify, Loading, TinyPopover } from '@opentiny/vue'
8596
import { useCanvas, useHistory, usePage, useModal, getMetaApi, META_SERVICE } from '@opentiny/tiny-engine-meta-register'
8697
import { extend } from '@opentiny/vue-renderless/common/object'
@@ -92,6 +103,7 @@ import { getBlockContent, initBlockList, getAIModelOptions } from './js/robotSet
92103
import McpServer from './mcp/McpServer.vue'
93104
import useMcpServer from './mcp/useMcp'
94105
import MarkdownRenderer from './mcp/MarkdownRenderer.vue'
106+
import LoadingRenderer from './mcp/LoadingRenderer.vue'
95107
import { sendMcpRequest } from './mcp/utils'
96108
97109
export default {
@@ -151,6 +163,14 @@ export default {
151163
)
152164
}
153165
166+
const scrollContent = async () => {
167+
await nextTick()
168+
const el = chatContainerRef.value as HTMLElement | null
169+
if (el) {
170+
el.scrollTop = el.scrollHeight
171+
}
172+
}
173+
154174
const createNewPage = (schema) => {
155175
if (!(pageSettingState.isNew && pageSettingState.isAIPage)) {
156176
pageSettingState.isNew = true
@@ -206,7 +226,7 @@ export default {
206226
if (useMcpServer().isToolsEnabled) {
207227
try {
208228
requestLoading.value = true
209-
await scrollContent() // eslint-disable-line
229+
await scrollContent()
210230
await sendMcpRequest(messages.value, {
211231
model: selectedModel.value.value,
212232
headers: {
@@ -218,7 +238,7 @@ export default {
218238
} finally {
219239
inProcesing.value = false
220240
requestLoading.value = false
221-
await scrollContent() // eslint-disable-line
241+
await scrollContent()
222242
}
223243
return
224244
}
@@ -246,12 +266,6 @@ export default {
246266
})
247267
}
248268
249-
const scrollContent = async () => {
250-
if (chatContainerRef.value) {
251-
chatContainerRef.value.scrollTop = chatContainerRef.value.scrollHeight
252-
}
253-
}
254-
255269
const resetContent = async () => {
256270
activeMessages.value = messages.value
257271
await scrollContent()
@@ -429,10 +443,15 @@ export default {
429443
user: { placement: 'end', avatar: userAvatar, maxWidth: '90%', contentRenderer: MarkdownRenderer }
430444
}
431445
432-
watch([activeMessages.value.length, activeMessages.value.at(-1)?.renderContent?.length], async () => {
433-
await scrollContent()
446+
watch([() => activeMessages.value.length, () => activeMessages.value.at(-1)?.renderContent?.length ?? 0], () => {
447+
scrollContent()
434448
})
435449
450+
const contentRenderers: Record<string, Component> = {
451+
markdown: MarkdownRenderer,
452+
loading: LoadingRenderer
453+
}
454+
436455
const mcpDrawerPosition = computed(() => {
437456
return {
438457
type: 'fixed',
@@ -468,7 +487,7 @@ export default {
468487
handlePromptItemClick,
469488
welcomeIcon,
470489
roles,
471-
MarkdownRenderer,
490+
contentRenderers,
472491
requestLoading,
473492
mcpDrawerPosition
474493
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<template>
2+
<img src="../../assets/loading.webp" alt="loading" style="width: 24px; height: 24px" />
3+
</template>

packages/plugins/robot/src/mcp/MarkdownRenderer.vue

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@
33
</template>
44

55
<script setup lang="ts">
6-
import { computed, watch, onMounted, nextTick } from 'vue'
6+
import { computed } from 'vue'
77
import DOMPurify from 'dompurify'
88
import MarkdownIt, { type Options } from 'markdown-it'
99
import hljs from 'highlight.js/lib/core'
1010
import 'highlight.js/styles/github.css'
11-
import 'highlight.js/styles/github-dark.css'
1211
1312
// 按需加载语言
1413
import bash from 'highlight.js/lib/languages/bash'
@@ -35,7 +34,7 @@ const props = defineProps({
3534
},
3635
theme: {
3736
type: String as () => 'light' | 'dark',
38-
default: 'dark'
37+
default: 'light'
3938
},
4039
options: {
4140
type: Object as () => Options,
@@ -70,26 +69,6 @@ const markdownIt = new MarkdownIt({
7069
const renderContent = computed(() => {
7170
return DOMPurify.sanitize(markdownIt.render(props.content))
7271
})
73-
74-
// 动态切换主题时重新高亮
75-
watch(
76-
() => props.theme,
77-
() => {
78-
nextTick(() => {
79-
document.querySelectorAll('.markdown-renderer pre code').forEach((el) => {
80-
hljs.highlightElement(el as HTMLElement)
81-
})
82-
})
83-
}
84-
)
85-
86-
onMounted(() => {
87-
nextTick(() => {
88-
document.querySelectorAll('.markdown-renderer pre code').forEach((el) => {
89-
hljs.highlightElement(el as HTMLElement)
90-
})
91-
})
92-
})
9372
</script>
9473

9574
<style lang="less">
@@ -101,8 +80,12 @@ onMounted(() => {
10180
padding: 1em;
10281
overflow: auto;
10382
line-height: 1.45;
83+
> code {
84+
font-size: 12px;
85+
}
10486
}
10587
88+
// TODO: 适配TInyEngine主题,实现跟随主题自动切换
10689
/* 亮色主题 */
10790
&.hljs-theme-light {
10891
@import 'highlight.js/styles/github.css';

packages/plugins/robot/src/mcp/McpServer.vue

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,6 @@ onMounted(() => {
9090
display: none !important;
9191
}
9292
}
93-
:deep(.mcp-server-picker__content-item) {
94-
.plugin-card__operations {
95-
.tiny-popconfirm {
96-
display: none !important;
97-
}
98-
}
99-
}
10093
10194
:deep(.mcp-server-picker__content) {
10295
.tiny-tabs.tiny-tabs .tiny-tabs__header .tiny-tabs__nav {
@@ -109,13 +102,23 @@ onMounted(() => {
109102
.tiny-tabs.tiny-tabs .tiny-tabs__header .tiny-tabs__nav {
110103
width: 160px;
111104
}
112-
}
113-
114-
:deep(.tiny-tabs__content) {
115-
.plugin-card__add-button {
116-
display: flex;
117-
align-items: center;
118-
justify-content: center;
105+
.tiny-tabs__content {
106+
.plugin-card__operations {
107+
.tiny-popconfirm {
108+
display: none;
109+
}
110+
}
111+
.plugin-card__add-button {
112+
display: flex;
113+
align-items: center;
114+
justify-content: center;
115+
}
116+
.plugin-card__name {
117+
text-align: left;
118+
}
119+
.plugin-card__desc {
120+
font-size: 12px;
121+
}
119122
}
120123
}
121124

packages/plugins/robot/src/mcp/useMcp.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import type { McpListToolsResponse, McpTool, RequestTool } from './types'
55

66
const ENGINE_MCP_SERVER: PluginInfo = {
77
id: 'tiny-engine-mcp-server',
8-
name: 'Tiny Engine MCP 服务器',
8+
name: 'Tiny Engine MCP 工具',
99
icon: 'https://res.hc-cdn.com/lowcode-portal/1.1.80.20250515160330/assets/opentiny-tinyengine-logo-4f8a3801.svg',
10-
description: '使用TinyEngine设计器能力,如添加国际化',
10+
description: '使用TinyEngine设计器能力,如操作画布、编辑页面等',
1111
added: true
1212
}
1313

@@ -27,7 +27,7 @@ const updateEngineTools = async () => {
2727
(await getMetaApi(META_SERVICE.McpService)?.getToolList?.()) || []
2828
const engineTools = tools.map((tool) => ({
2929
id: tool.name,
30-
name: tool.title ? `${tool.title}${tool.name}` : tool.name,
30+
name: tool.title ? `${tool.title} ${tool.name}` : tool.name,
3131
description: tool.description,
3232
enabled: tool.status === 'enabled'
3333
}))

packages/plugins/robot/src/mcp/utils.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,9 @@ const handleToolCall = async (
8989
result: toolCallResult.content
9090
}
9191
}
92+
currentMessage.renderContent.push({ type: 'loading', content: '' })
9293
const newResp = await fetchLLM(toolMessages, tools)
94+
currentMessage.renderContent.pop()
9395
const hasToolCall = newResp.choices[0].message.tool_calls?.length > 0
9496
if (hasToolCall) {
9597
await handleToolCall(newResp, tools, messages, toolMessages)
@@ -110,7 +112,9 @@ export const sendMcpRequest = async (messages: LLMMessage[], options: RequestOpt
110112
}
111113
const tools = await useMcpServer().getLLMTools()
112114
requestOptions = options
115+
messages.at(-1)!.renderContent = [{ type: 'loading', content: '' }]
113116
const res = await fetchLLM(formatMessages(messages.slice(0, -1)), tools, options)
117+
delete messages.at(-1)!.renderContent
114118
const hasToolCall = res.choices[0].message.tool_calls?.length > 0
115119
if (hasToolCall) {
116120
await handleToolCall(res, tools, messages)

0 commit comments

Comments
 (0)