diff --git a/renderer/src/App.vue b/renderer/src/App.vue index 73580ee..5b69939 100644 --- a/renderer/src/App.vue +++ b/renderer/src/App.vue @@ -61,8 +61,6 @@ async function initProduce() { // 初始化 tab await loadPanels(); - - console.log(route); if (route.name !== 'debug') { router.replace('/debug'); diff --git a/renderer/src/views/connect/connection.ts b/renderer/src/views/connect/connection.ts index d15c6d8..59450cf 100644 --- a/renderer/src/views/connect/connection.ts +++ b/renderer/src/views/connect/connection.ts @@ -1,6 +1,7 @@ import { useMessageBridge } from '@/api/message-bridge'; import { reactive } from 'vue'; import { pinkLog } from '../setting/util'; +import { ElMessage } from 'element-plus'; export const connectionMethods = reactive({ current: 'STDIO', @@ -66,9 +67,17 @@ export function doConnect() { connectionResult.success = (code === 200); connectionResult.logString = msg; - const res = await getServerVersion() as { name: string, version: string }; - connectionResult.serverInfo.name = res.name || ''; - connectionResult.serverInfo.version = res.version || ''; + if (code === 200) { + const res = await getServerVersion() as { name: string, version: string }; + connectionResult.serverInfo.name = res.name || ''; + connectionResult.serverInfo.version = res.version || ''; + } else { + ElMessage({ + type: 'error', + message: msg + }); + } + resolve(void 0); }, { once: true }); diff --git a/service/src/controller/connect.ts b/service/src/controller/connect.ts index 8b0e494..0077bea 100644 --- a/service/src/controller/connect.ts +++ b/service/src/controller/connect.ts @@ -3,6 +3,7 @@ import { Client } from "@modelcontextprotocol/sdk/client/index.js"; import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js"; import { SSEClientTransport } from "@modelcontextprotocol/sdk/client/sse.js"; import { Implementation } from "@modelcontextprotocol/sdk/types"; +import { Writable, Stream } from "node:stream"; // 定义连接类型 type ConnectionType = 'STDIO' | 'SSE'; @@ -31,6 +32,8 @@ export class MCPClient { private options: MCPOptions; private serverVersion: IServerVersion; + private transportStdErr: string = ''; + constructor(options: MCPOptions) { this.options = options; this.serverVersion = undefined; @@ -52,28 +55,48 @@ export class MCPClient { // 连接方法 public async connect(): Promise { + this.transportStdErr = ''; + // 根据连接类型创建传输层 switch (this.options.connectionType) { case 'STDIO': this.transport = new StdioClientTransport({ command: this.options.command || '', args: this.options.args || [], - cwd: this.options.cwd || process.cwd() + cwd: this.options.cwd || process.cwd(), + // TODO + stderr: 'pipe' }); + + this.transport.onmessage = (message) => { + console.log('Received message from server:', message); + this.transportStdErr += message; + }; + + this.transport.onerror = (error) => { + console.log('Error from server:', error); + this.transportStdErr += error; + }; + break; case 'SSE': if (!this.options.url) { throw new Error('URL is required for SSE connection'); } - this.transport = new SSEClientTransport(new URL(this.options.url)); + this.transport = new SSEClientTransport( + new URL(this.options.url) + ); + break; default: throw new Error(`Unsupported connection type: ${this.options.connectionType}`); } // 建立连接 - await this.client.connect(this.transport); - console.log(`Connected to MCP server via ${this.options.connectionType}`); + if (this.transport) { + await this.client.connect(this.transport); + console.log(`Connected to MCP server via ${this.options.connectionType}`); + } } public getServerVersion() { diff --git a/service/tabs.untitle.json b/service/tabs.untitle.json index 3f3172a..5df3c19 100644 --- a/service/tabs.untitle.json +++ b/service/tabs.untitle.json @@ -1,12 +1,4 @@ { "currentIndex": 0, - "tabs": [ - { - "name": "Blank test 1", - "icon": "icon-blank", - "type": "blank", - "componentIndex": -1, - "storage": {} - } - ] + "tabs": [] } \ No newline at end of file