From bac3e5c25399fbaeb77675cb4a6d2d835c5f5aea Mon Sep 17 00:00:00 2001 From: Kirigaya <1193466151@qq.com> Date: Sat, 29 Mar 2025 13:19:47 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=20MCP=20client=20=E7=9A=84?= =?UTF-8?q?=20patch?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/App.vue | 6 +- .../sidebar/sidebar-item-container.vue | 5 +- app/src/views/connect/connection-args.vue | 68 +++++++++++ app/src/views/connect/connection.ts | 68 +++++++++-- app/src/views/connect/index.vue | 26 +++-- test/patch-mcp-sdk.js | 77 +++++++++++++ test/src/controller/connect.ts | 107 +----------------- 7 files changed, 231 insertions(+), 126 deletions(-) create mode 100644 app/src/views/connect/connection-args.vue create mode 100644 test/patch-mcp-sdk.js diff --git a/app/src/App.vue b/app/src/App.vue index 2392c7a..926f181 100644 --- a/app/src/App.vue +++ b/app/src/App.vue @@ -15,16 +15,16 @@ import { setDefaultCss } from './hook/css'; import { pinkLog } from './views/setting/util'; import { useMessageBridge } from './api/message-bridge'; -const { postMessage, onMessage, isConnected } = useMessageBridge(); +const bridge = useMessageBridge(); // 监听所有消息 -onMessage((message) => { +bridge.onMessage((message) => { console.log('Received:', message.command, message.data); }); // 发送消息 const sendPing = () => { - postMessage({ + bridge.postMessage({ command: 'ping', data: { timestamp: Date.now() } }); diff --git a/app/src/components/sidebar/sidebar-item-container.vue b/app/src/components/sidebar/sidebar-item-container.vue index 92a8390..c5e9748 100644 --- a/app/src/components/sidebar/sidebar-item-container.vue +++ b/app/src/components/sidebar/sidebar-item-container.vue @@ -60,8 +60,9 @@ function gotoOption(ident: string) { } .sidebar-option-item .iconfont { - margin-right: 5px; - font-size: 20px; + margin-top: 2px; + margin-right: 7px; + font-size: 17px; } .sidebar-option-item.active { diff --git a/app/src/views/connect/connection-args.vue b/app/src/views/connect/connection-args.vue new file mode 100644 index 0000000..19753ca --- /dev/null +++ b/app/src/views/connect/connection-args.vue @@ -0,0 +1,68 @@ + + + \ No newline at end of file diff --git a/app/src/views/connect/connection.ts b/app/src/views/connect/connection.ts index 6f75c6b..0e47617 100644 --- a/app/src/views/connect/connection.ts +++ b/app/src/views/connect/connection.ts @@ -1,21 +1,23 @@ +import { useMessageBridge } from '@/api/message-bridge'; import { reactive } from 'vue'; export const connectionMethods = reactive({ - current: 'stdio', + current: 'STDIO', data: [ { - value: 'stdio', - label: 'stdio' + value: 'STDIO', + label: 'STDIO' }, { - value: 'sse', - label: 'sse' + value: 'SSE', + label: 'SSE' } ] }); -export const connectionCommand = reactive({ - commandString: '' +export const connectionArgs = reactive({ + commandString: '', + urlString: '' }); export interface EnvItem { @@ -38,4 +40,56 @@ export const connectionEnv = reactive({ export function onconnectionmethodchange() { console.log(); +} + +// 定义连接类型 +type ConnectionType = 'STDIO' | 'SSE'; + +// 定义命令行参数接口 +export interface MCPOptions { + connectionType: ConnectionType; + // STDIO 特定选项 + command?: string; + args?: string[]; + // SSE 特定选项 + url?: string; + // 通用客户端选项 + clientName?: string; + clientVersion?: string; +} + + + +export function doConnect() { + let connectOption: MCPOptions; + + if (connectionMethods.current === 'STDIO') { + const commandComponents = connectionArgs.commandString.split(/\s+/g); + const command = commandComponents[0]; + commandComponents.shift(); + + connectOption = { + connectionType: 'STDIO', + command: command, + args: commandComponents, + clientName: 'openmcp.connect.stdio.' + command, + clientVersion: '0.0.1' + } + + } else { + const url = connectionArgs.urlString; + + connectOption = { + connectionType: 'SSE', + url: url, + clientName: 'openmcp.connect.sse', + clientVersion: '0.0.1' + } + } + + const bridge = useMessageBridge(); + bridge.postMessage({ + command: 'connect', + data: connectOption + }); } \ No newline at end of file diff --git a/app/src/views/connect/index.vue b/app/src/views/connect/index.vue index de76785..61332dc 100644 --- a/app/src/views/connect/index.vue +++ b/app/src/views/connect/index.vue @@ -11,12 +11,9 @@ -
- {{ t('command') }} - - - -
+ + +
{{ t('env-var') }} @@ -50,7 +47,9 @@
- + Connect
@@ -60,12 +59,23 @@