add new icon

This commit is contained in:
锦恢 2025-04-11 15:23:49 +08:00
parent 98cd0c6166
commit 64df3b93bf
7 changed files with 88 additions and 19 deletions

View File

@ -28,37 +28,63 @@
- [ ] 支持同时调试多个 MCP Server - [ ] 支持同时调试多个 MCP Server
- [ ] 支持通过大模型进行在线验证 - [ ] 支持通过大模型进行在线验证
- [ ] 支持 completion/complete 协议字段 - [ ] 支持 completion/complete 协议字段
- [ ] 支持 对用户对应服务器的调试工作内容进行保存 - [x] 支持 对用户对应服务器的调试工作内容进行保存
- [ ] 高危操作权限确认 - [ ] 高危操作权限确认
## Dev ## Dev
- `app`: 前端 UI 的定义 - `renderer`: 前端 UI 的定义
- `test`: 测试 `app` 的部分,包含一个简易的转发层 - `service`: 测试 `renderer` 的部分,包含一个简易的转发层
- `src`: vscode 插件端定义 - `src`: vscode 插件端定义
### 初始化环境 ### Renderer & Service Dev
```mermaid
flowchart LR
D[renderer] <--> A[Dev Server] <--ws--> B[service]
B <--mcp--> m(MCP Server)
```
配置项目
```bash ```bash
source configure.sh source configure.sh
``` ```
### 启动前端 启动 dev server
```bash ```bash
cd renderer cd renderer
npm run serve npm run serve
``` ```
### 启动后端 (Test) 启动 service
```bash ```bash
cd service cd service
npm run serve npm run serve
``` ```
---
### Extention Dev
```mermaid
flowchart LR
D[renderer] <--> A[extention.ts] <--> B[service]
B <--mcp--> m(MCP Server)
```
负载部署
```bash
## linux
./build_service.sh
## windows
./build_service.ps1
```
and just press f5, いただきます
## Flowchart ## Flowchart

View File

@ -1,2 +1,3 @@
cd app && npm i && cd .. cd renderer && npm i && cd ..
cd test && npm i && node patch-mcp-sdk.js && cd .. cd service && npm i && node patch-mcp-sdk.js && cd ..
npm i

View File

@ -16,9 +16,22 @@
{ {
"command": "openmcp.showOpenMCP", "command": "openmcp.showOpenMCP",
"title": "展示 OpenMCP", "title": "展示 OpenMCP",
"category": "openmcp" "category": "openmcp",
"icon": {
"light": "./icons/protocol.svg",
"dark": "./icons/protocol.svg"
}
} }
], ],
"menus": {
"editor/title": [
{
"command": "openmcp.showOpenMCP",
"group": "navigation",
"when": "editorLangId == python || editorLangId == javascript || editorLangId == typescript || editorLangId == java || editorLangId == csharp"
}
]
},
"viewsContainers": { "viewsContainers": {
"activitybar": [ "activitybar": [
{ {

View File

@ -16,6 +16,7 @@ export interface MCPOptions {
args?: string[]; args?: string[];
// SSE 特定选项 // SSE 特定选项
url?: string; url?: string;
cwd?: string;
// 通用客户端选项 // 通用客户端选项
clientName?: string; clientName?: string;
clientVersion?: string; clientVersion?: string;
@ -52,7 +53,8 @@ export class MCPClient {
case 'STDIO': case 'STDIO':
this.transport = new StdioClientTransport({ this.transport = new StdioClientTransport({
command: this.options.command || '', command: this.options.command || '',
args: this.options.args || [] args: this.options.args || [],
cwd: this.options.cwd || process.cwd()
}); });
break; break;
case 'SSE': case 'SSE':

View File

@ -6,6 +6,7 @@ export async function settingSaveHandler(client: MCPClient | undefined, data: an
try { try {
// 保存配置 // 保存配置
saveConfig(data); saveConfig(data);
console.log('Settings saved successfully');
webview.postMessage({ webview.postMessage({
command: 'setting/save', command: 'setting/save',
@ -15,6 +16,8 @@ export async function settingSaveHandler(client: MCPClient | undefined, data: an
} }
}); });
} catch (error) { } catch (error) {
console.log('Setting save failed:', error);
webview.postMessage({ webview.postMessage({
command: 'setting/save', command: 'setting/save',
data: { data: {

View File

@ -21,13 +21,12 @@ function getTabSavePath() {
// 如果是 vscode 插件下,则修改为 ~/.vscode/openmcp.json // 如果是 vscode 插件下,则修改为 ~/.vscode/openmcp.json
if (process.env.VSCODE_PID) { if (process.env.VSCODE_PID) {
// 在 VSCode 插件环境下 // 在 VSCode 插件环境下
// const homeDir = os.homedir(); const homeDir = os.homedir();
// const configDir = path.join(homeDir, '.openmcp'); const configDir = path.join(homeDir, '.openmcp');
// if (!fs.existsSync(configDir)) { if (!fs.existsSync(configDir)) {
// fs.mkdirSync(configDir, { recursive: true }); fs.mkdirSync(configDir, { recursive: true });
// } }
// return path.join(configDir, 'tabs.json'); return path.join(configDir, 'tabs.json');
return 'tabs.json';
} }
return 'tabs.json'; return 'tabs.json';
} }
@ -117,6 +116,8 @@ export function saveConfig(config: Partial<IConfig>): void {
const configPath = getConfigurationPath(); const configPath = getConfigurationPath();
let currentConfig: IConfig = DEFAULT_CONFIG; let currentConfig: IConfig = DEFAULT_CONFIG;
console.log('save to ' + configPath);
try { try {
fs.writeFileSync(configPath, JSON.stringify(config, null, 2), 'utf-8'); fs.writeFileSync(configPath, JSON.stringify(config, null, 2), 'utf-8');
} catch (error) { } catch (error) {

View File

@ -17,12 +17,19 @@ function getWebviewContent(context: vscode.ExtensionContext, panel: vscode.Webvi
return html; return html;
} }
function getLaunchCWD(context: vscode.ExtensionContext, uri: vscode.Uri) {
// TODO: 启动上下文?
// 获取当前打开的项目的路径
const workspaceFolder = vscode.workspace.getWorkspaceFolder(uri);
return workspaceFolder?.uri.fsPath || '';
}
export function activate(context: vscode.ExtensionContext) { export function activate(context: vscode.ExtensionContext) {
console.log('activate openmcp'); console.log('activate openmcp');
// 注册 showOpenMCP 命令 // 注册 showOpenMCP 命令
context.subscriptions.push( context.subscriptions.push(
vscode.commands.registerCommand('openmcp.showOpenMCP', async () => { vscode.commands.registerCommand('openmcp.showOpenMCP', async (uri: vscode.Uri) => {
const panel = vscode.window.createWebviewPanel( const panel = vscode.window.createWebviewPanel(
'OpenMCP', 'OpenMCP',
@ -35,6 +42,8 @@ export function activate(context: vscode.ExtensionContext) {
} }
); );
const cwd = getLaunchCWD(context, uri);
// 设置HTML内容 // 设置HTML内容
const html = getWebviewContent(context, panel); const html = getWebviewContent(context, panel);
panel.webview.html = html || ''; panel.webview.html = html || '';
@ -44,8 +53,22 @@ export function activate(context: vscode.ExtensionContext) {
const { command, data } = message; const { command, data } = message;
console.log('receive message', message); console.log('receive message', message);
// 拦截消息,注入额外信息
switch (command) {
case 'connect':
data.cwd = cwd;
break;
default:
break;
}
OpenMCPService.messageController(command, data, panel.webview as any); OpenMCPService.messageController(command, data, panel.webview as any);
}); });
panel.onDidDispose(() => {
panel.dispose();
});
}) })
); );