Skip to content

Commit 1902b41

Browse files
committed
fix: review suggestion
1 parent 6e57aaa commit 1902b41

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

packages/vue-generator/src/plugins/genMcpPlugin.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,10 @@ export const handleTinyMcpConfigAttrHook = (schemaData, globalHooks, config) =>
790790
if (globalHooks && globalHooks.addStatement) {
791791
const pageId = config?.pageId || config?.fileName || 'current-page'
792792

793+
// 使用 JSON.stringify 来转义 pageId,防止特殊字符破坏生成的代码
794+
const pageIdLiteral = JSON.stringify(pageId)
795+
const descriptionLiteral = JSON.stringify(`${pageId}页面`)
796+
793797
// 添加必要的导入
794798
globalHooks.addImport('vue', {
795799
destructuring: true,
@@ -808,10 +812,10 @@ export const handleTinyMcpConfigAttrHook = (schemaData, globalHooks, config) =>
808812
position: INSERT_POSITION.AFTER_METHODS,
809813
value: `
810814
// 使用统一管理的页面服务器
811-
const { server, connect, disconnect } = usePageMcpServer('${pageId}', {
815+
const { server, connect, disconnect } = usePageMcpServer(${pageIdLiteral}, {
812816
business: {
813-
id: '${pageId}',
814-
description: '${pageId}页面'
817+
id: ${pageIdLiteral},
818+
description: ${descriptionLiteral}
815819
}
816820
})
817821

0 commit comments

Comments
 (0)