@@ -8,12 +8,21 @@ import { MCPHost } from '../../services/MCPHost'
88
99const mcpHost = new MCPHost ( )
1010
11+ const defaultMcpIcon =
12+ 'https://res.hc-cdn.com/lowcode-portal/1.1.80.20250515160330/assets/opentiny-tinyengine-logo-4f8a3801.svg'
13+
14+ enum PluginAddState {
15+ Added = 'added' ,
16+ Idle = 'idle' ,
17+ Loading = 'loading'
18+ }
19+
1120const ENGINE_MCP_SERVER : PluginInfo = {
1221 id : 'tiny-engine-mcp-server' ,
1322 name : 'Tiny Engine MCP 工具' ,
14- icon : 'https://res.hc-cdn.com/lowcode-portal/1.1.80.20250515160330/assets/opentiny-tinyengine-logo-4f8a3801.svg' ,
23+ icon : defaultMcpIcon ,
1524 description : '使用TinyEngine设计器能力,如操作画布、编辑页面等' ,
16- addState : 'added'
25+ addState : PluginAddState . Added
1726}
1827
1928const inUseMcpServers = ref < PluginInfo [ ] > ( [ { ...ENGINE_MCP_SERVER , enabled : true , expanded : true , tools : [ ] } ] )
@@ -94,13 +103,13 @@ const updateMcpServerToggle = async (server: PluginInfo, enabled: boolean) => {
94103
95104const updateMcpServerStatus = async ( server : PluginInfo , added : boolean ) => {
96105 // 市场添加状态修改
97- server . addState = added ? 'added' : 'idle'
106+ server . addState = added ? PluginAddState . Added : PluginAddState . Idle
98107 if ( added ) {
99108 const newServer : PluginInfo = {
100109 ...server ,
101110 id : server . id || `mcp-server-${ Date . now ( ) } ` ,
102111 enabled : true ,
103- addState : 'added' ,
112+ addState : PluginAddState . Added ,
104113 expanded : false ,
105114 tools : server . tools || [ ]
106115 }
@@ -129,37 +138,34 @@ const updateMcpServerToolStatus = (currentServer: PluginInfo, toolId: string, en
129138}
130139
131140const updateCustomMcpServers = async ( ) => {
132- const customMcpServers = getRobotServiceOptions ( ) . mcpConfig ?. mcpServers || { }
133- if ( Object . keys ( customMcpServers ) . length > 0 ) {
134- if (
135- Object . values ( customMcpServers ) . some (
136- ( server ) => ! [ 'streamablehttp' , 'sse' ] . includes ( server . type ?. toLowerCase ( ) ) || ! server . url
137- )
138- ) {
139- return {
140- result : 'failed' ,
141- message : '解析JSON失败,缺少type或url字段'
142- }
141+ const mcpServersConfig = getRobotServiceOptions ( ) . mcpConfig ?. mcpServers || { }
142+ if ( ! Object . keys ( mcpServersConfig ) . length ) return
143+ const customMcpServers = Object . entries ( mcpServersConfig ) . map ( ( [ id , config ] ) => ( { id, ...config } ) )
144+ const logger = console
145+
146+ customMcpServers . forEach ( ( server ) => {
147+ if ( ! [ 'streamablehttp' , 'sse' ] . includes ( server . type ?. toLowerCase ( ) ) || ! server . url ) {
148+ logger . error ( `解析mcpServer: ${ server . id } 配置失败,type/url字段缺失或有误.` )
149+ return
143150 }
144- for ( const [ serverName , server ] of Object . entries ( customMcpServers ) ) {
145- if ( inUseMcpServers . value . find ( ( s ) => s . id === serverName ) ) {
146- continue
147- }
148- const newServer : PluginInfo = {
149- id : serverName ,
150- name : serverName ,
151- icon : server . icon ,
152- description : server . description ,
153- enabled : false ,
154- addState : 'added' ,
155- expanded : false ,
156- type : server . type ,
157- url : server . url ,
158- tools : [ ]
159- }
160- inUseMcpServers . value . push ( newServer )
151+
152+ if ( inUseMcpServers . value . find ( ( s ) => s . id === server . id ) ) {
153+ return
161154 }
162- }
155+ const newServer : PluginInfo = {
156+ id : server . id ,
157+ name : server . name || server . id ,
158+ icon : server . icon || defaultMcpIcon ,
159+ description : server . description || '' ,
160+ enabled : false ,
161+ addState : PluginAddState . Added ,
162+ expanded : false ,
163+ type : server . type ,
164+ url : server . url ,
165+ tools : [ ]
166+ }
167+ inUseMcpServers . value . push ( newServer )
168+ } )
163169}
164170
165171const connectMcpServer = ( server : PluginInfo ) => {
0 commit comments