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
- [ ] 支持通过大模型进行在线验证
- [ ] 支持 completion/complete 协议字段
- [ ] 支持 对用户对应服务器的调试工作内容进行保存
- [x] 支持 对用户对应服务器的调试工作内容进行保存
- [ ] 高危操作权限确认
## Dev
- `app`: 前端 UI 的定义
- `test`: 测试 `app` 的部分,包含一个简易的转发层
- `renderer`: 前端 UI 的定义
- `service`: 测试 `renderer` 的部分,包含一个简易的转发层
- `src`: vscode 插件端定义
### 初始化环境
### Renderer & Service Dev
```mermaid
flowchart LR
D[renderer] <--> A[Dev Server] <--ws--> B[service]
B <--mcp--> m(MCP Server)
```
配置项目
```bash
source configure.sh
```
### 启动前端
启动 dev server
```bash
cd renderer
npm run serve
```
### 启动后端 (Test)
启动 service
```bash
cd service
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

View File

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

View File

@ -16,9 +16,22 @@
{
"command": "openmcp.showOpenMCP",
"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": {
"activitybar": [
{

View File

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

View File

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

View File

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

View File

@ -17,12 +17,19 @@ function getWebviewContent(context: vscode.ExtensionContext, panel: vscode.Webvi
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) {
console.log('activate openmcp');
// 注册 showOpenMCP 命令
context.subscriptions.push(
vscode.commands.registerCommand('openmcp.showOpenMCP', async () => {
vscode.commands.registerCommand('openmcp.showOpenMCP', async (uri: vscode.Uri) => {
const panel = vscode.window.createWebviewPanel(
'OpenMCP',
@ -35,6 +42,8 @@ export function activate(context: vscode.ExtensionContext) {
}
);
const cwd = getLaunchCWD(context, uri);
// 设置HTML内容
const html = getWebviewContent(context, panel);
panel.webview.html = html || '';
@ -43,9 +52,23 @@ export function activate(context: vscode.ExtensionContext) {
panel.webview.onDidReceiveMessage(message => {
const { command, data } = message;
console.log('receive message', message);
// 拦截消息,注入额外信息
switch (command) {
case 'connect':
data.cwd = cwd;
break;
default:
break;
}
OpenMCPService.messageController(command, data, panel.webview as any);
});
panel.onDidDispose(() => {
panel.dispose();
});
})
);