From ddb4dfb565fc961452509c41503854085339e292 Mon Sep 17 00:00:00 2001 From: Kirigaya <1193466151@qq.com> Date: Wed, 23 Apr 2025 19:14:31 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=20SSE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 3 +-- src/extension.ts | 20 ++++++++++---------- src/webview.ts | 16 ++++++++++++++++ 3 files changed, 27 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 349ca07..38c86ec 100644 --- a/README.md +++ b/README.md @@ -40,12 +40,11 @@ |---------|---------|--------|---------|-----------| | `all` | 完成最基本的各类基础设施 | `完整版本` | 100% | `Done` | | `render` | chat 模式下支持进行成本分析 | `迭代版本` | 100% | `Done` | -| `ext` | 支持基本的 MCP 项目管理 | `MVP` | 70% | `P0` | +| `ext` | 支持基本的 MCP 项目管理 | `MVP` | 90% | `P0` | | `service` | 支持自定义支持 openai 接口协议的大模型接入 | `完整版本` | 100% | `Done` | | `service` | 支持自定义接口协议的大模型接入 | `MVP` | 0% | `P1` | | `all` | 支持同时调试多个 MCP Server | `MVP` | 0% | `P1` | | `all` | 支持通过大模型进行在线验证 | `迭代版本` | 100% | `Done` | -| `all` | 支持 completion/complete 协议字段 | `MVP` | 0% | `P1` | | `all` | 支持对用户对应服务器的调试工作内容进行保存 | `迭代版本` | 100% | `Done` | | `render` | 高危操作权限确认 | `MVP` | 0% | `P1` | | `service` | 对于连接的 mcp server 进行热更新 | `MVP` | 0% | `P1` | diff --git a/src/extension.ts b/src/extension.ts index a4e7088..9f5afbc 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -2,7 +2,7 @@ import * as vscode from 'vscode'; import * as fspath from 'path'; import * as OpenMCPService from '../resources/service'; -import { getLaunchCWD, revealOpenMcpWebviewPanel } from './webview'; +import { getDefaultLanunchSigature, getLaunchCWD, revealOpenMcpWebviewPanel } from './webview'; import { ConnectionViewItem, registerSidebar } from './sidebar'; import { getWorkspaceConnectionConfigItemByPath, ISSEConnectionItem, IStdioConnectionItem } from './global'; @@ -31,19 +31,19 @@ export function activate(context: vscode.ExtensionContext) { if (!connectionItem) { // 项目不存在连接信息 const cwd = getLaunchCWD(context, uri); + + const sigature = getDefaultLanunchSigature(uri.fsPath, cwd); - // 获取 uri 相对于 cwd 的路径 - const relativePath = fspath.relative(cwd, uri.fsPath); - - // TODO: 实现从 connection.json 中读取配置,然后启动对应的 connection - const command = 'mcp'; - const args = ['run', relativePath]; - + if (!sigature) { + vscode.window.showErrorMessage('OpenMCP: 无法获取启动参数'); + return; + } + revealOpenMcpWebviewPanel(context, uri.fsPath, { type: 'stdio', name: 'OpenMCP', - command, - args, + command: sigature.command, + args: sigature.args, cwd }); } else { diff --git a/src/webview.ts b/src/webview.ts index 5609f39..2f65158 100644 --- a/src/webview.ts +++ b/src/webview.ts @@ -112,4 +112,20 @@ export function revealOpenMcpWebviewPanel( }); return panel; +} + +export function getDefaultLanunchSigature(path: string, cwd: string) { + const relativePath = fspath.relative(cwd, path); + + if (relativePath.endsWith('.py')) { + return { + command: 'mcp', + args: ['run', relativePath] + }; + } else if (relativePath.endsWith('.js')) { + return { + command:'node', + args: [relativePath] + }; + } } \ No newline at end of file