修复无法重新连接的问题
This commit is contained in:
parent
3e0622f7e7
commit
5c9f46d2f1
@ -62,8 +62,6 @@ async function initProduce() {
|
||||
// 初始化 tab
|
||||
await loadPanels();
|
||||
|
||||
console.log(route);
|
||||
|
||||
if (route.name !== 'debug') {
|
||||
router.replace('/debug');
|
||||
router.push('/debug');
|
||||
|
@ -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 });
|
||||
|
||||
|
@ -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<void> {
|
||||
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() {
|
||||
|
@ -1,12 +1,4 @@
|
||||
{
|
||||
"currentIndex": 0,
|
||||
"tabs": [
|
||||
{
|
||||
"name": "Blank test 1",
|
||||
"icon": "icon-blank",
|
||||
"type": "blank",
|
||||
"componentIndex": -1,
|
||||
"storage": {}
|
||||
}
|
||||
]
|
||||
"tabs": []
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user