From 2c643107ee3592cbb187586459fe8fa205293f7c Mon Sep 17 00:00:00 2001 From: Kirigaya <1193466151@qq.com> Date: Wed, 2 Apr 2025 01:19:32 +0800 Subject: [PATCH] update --- .gitignore | 1 + app/src/components/main-panel/tool/index.vue | 50 ++++-- .../main-panel/tool/tool-executor.vue | 147 +++++++++++++++++ .../components/main-panel/tool/tool-list.vue | 154 ++++++++++++++++++ .../main-panel/tool/tool-logger.vue | 109 +++++++++++++ app/src/components/main-panel/tool/tools.ts | 13 ++ app/src/hook/type.ts | 27 ++- app/src/i18n/ar.json | 3 +- app/src/i18n/de.json | 3 +- app/src/i18n/en.json | 3 +- app/src/i18n/fr.json | 3 +- app/src/i18n/ja.json | 3 +- app/src/i18n/ko.json | 3 +- app/src/i18n/ru.json | 3 +- app/src/i18n/zh-cn.json | 3 +- app/src/i18n/zh-tw.json | 3 +- test/.gitignore | 1 + test/src/controller/connect.ts | 5 + test/src/controller/handler.ts | 36 ++++ test/src/controller/index.ts | 6 +- test/src/controller/protocol.type.ts | 10 ++ test/src/util.ts | 12 ++ 22 files changed, 576 insertions(+), 22 deletions(-) create mode 100644 app/src/components/main-panel/tool/tool-executor.vue create mode 100644 app/src/components/main-panel/tool/tool-list.vue create mode 100644 app/src/components/main-panel/tool/tool-logger.vue create mode 100644 app/src/components/main-panel/tool/tools.ts create mode 100644 test/src/util.ts diff --git a/.gitignore b/.gitignore index 0b60dfa..93c2551 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ dist node_modules .vscode-test/ *.vsix +.env \ No newline at end of file diff --git a/app/src/components/main-panel/tool/index.vue b/app/src/components/main-panel/tool/index.vue index 87fad3d..277b5ba 100644 --- a/app/src/components/main-panel/tool/index.vue +++ b/app/src/components/main-panel/tool/index.vue @@ -1,27 +1,57 @@ \ No newline at end of file diff --git a/app/src/components/main-panel/tool/tool-executor.vue b/app/src/components/main-panel/tool/tool-executor.vue new file mode 100644 index 0000000..a2c6931 --- /dev/null +++ b/app/src/components/main-panel/tool/tool-executor.vue @@ -0,0 +1,147 @@ + + + + + \ No newline at end of file diff --git a/app/src/components/main-panel/tool/tool-list.vue b/app/src/components/main-panel/tool/tool-list.vue new file mode 100644 index 0000000..62a39c0 --- /dev/null +++ b/app/src/components/main-panel/tool/tool-list.vue @@ -0,0 +1,154 @@ + + + + + \ No newline at end of file diff --git a/app/src/components/main-panel/tool/tool-logger.vue b/app/src/components/main-panel/tool/tool-logger.vue new file mode 100644 index 0000000..c2ee2b8 --- /dev/null +++ b/app/src/components/main-panel/tool/tool-logger.vue @@ -0,0 +1,109 @@ + + + + + \ No newline at end of file diff --git a/app/src/components/main-panel/tool/tools.ts b/app/src/components/main-panel/tool/tools.ts new file mode 100644 index 0000000..d16bf07 --- /dev/null +++ b/app/src/components/main-panel/tool/tools.ts @@ -0,0 +1,13 @@ +import { ToolsListResponse, ToolCallResponse } from '@/hook/type'; +import { reactive } from 'vue'; + +export const toolsManager = reactive<{ + tools: ToolsListResponse['tools'] +}>({ + tools: [] +}); + +export interface ToolStorage { + currentToolName: string; + lastToolCallResponse?: ToolCallResponse; +} \ No newline at end of file diff --git a/app/src/hook/type.ts b/app/src/hook/type.ts index 64019d5..b2d6142 100644 --- a/app/src/hook/type.ts +++ b/app/src/hook/type.ts @@ -76,6 +76,16 @@ export interface PromptsGetResponse { }>; } +export interface ToolCallContent { + type: string; + text: string; +} + +export interface ToolCallResponse { + content: ToolCallContent[]; + isError: boolean; +} + // ==================== 请求接口定义 ==================== export interface BaseRequest { method: string; @@ -97,6 +107,17 @@ export interface PromptsGetRequest extends BaseRequest { }; } +export interface ToolCallRequest extends BaseRequest { + method: 'tools/call'; + params: { + name: string; + arguments: Record; + _meta?: { + progressToken?: number; + }; + }; +} + // ==================== 合并类型定义 ==================== export type APIResponse = | ToolsListResponse @@ -104,9 +125,11 @@ export type APIResponse = | ResourceTemplatesListResponse | ResourcesListResponse | ResourcesReadResponse - | PromptsGetResponse; + | PromptsGetResponse + | ToolCallResponse; export type APIRequest = | BaseRequest | ResourcesReadRequest - | PromptsGetRequest; \ No newline at end of file + | PromptsGetRequest + | ToolCallRequest; \ No newline at end of file diff --git a/app/src/i18n/ar.json b/app/src/i18n/ar.json index 2c2ba94..57bb9f1 100644 --- a/app/src/i18n/ar.json +++ b/app/src/i18n/ar.json @@ -112,5 +112,6 @@ "refresh": "تحديث", "finish-refresh": "تم التحديث", "response": "الاستجابة", - "read-prompt": "استخراج الكلمات الرئيسية" + "read-prompt": "استخراج الكلمات الرئيسية", + "execute-tool": "تشغيل الأداة" } \ No newline at end of file diff --git a/app/src/i18n/de.json b/app/src/i18n/de.json index 414477e..09236fb 100644 --- a/app/src/i18n/de.json +++ b/app/src/i18n/de.json @@ -112,5 +112,6 @@ "refresh": "Aktualisieren", "finish-refresh": "Aktualisierung abgeschlossen", "response": "Antwort", - "read-prompt": "Stichwörter extrahieren" + "read-prompt": "Stichwörter extrahieren", + "execute-tool": "Werkzeug ausführen" } \ No newline at end of file diff --git a/app/src/i18n/en.json b/app/src/i18n/en.json index 160ccde..30dc684 100644 --- a/app/src/i18n/en.json +++ b/app/src/i18n/en.json @@ -112,5 +112,6 @@ "refresh": "Refresh", "finish-refresh": "Refresh completed", "response": "Response", - "read-prompt": "Extract keywords" + "read-prompt": "Extract keywords", + "execute-tool": "Run tool" } \ No newline at end of file diff --git a/app/src/i18n/fr.json b/app/src/i18n/fr.json index f5cda80..73b2f89 100644 --- a/app/src/i18n/fr.json +++ b/app/src/i18n/fr.json @@ -112,5 +112,6 @@ "refresh": "Rafraîchir", "finish-refresh": "Actualisation terminée", "response": "Réponse", - "read-prompt": "Extraire des mots-clés" + "read-prompt": "Extraire des mots-clés", + "execute-tool": "Exécuter l'outil" } \ No newline at end of file diff --git a/app/src/i18n/ja.json b/app/src/i18n/ja.json index 7fe8073..2646b05 100644 --- a/app/src/i18n/ja.json +++ b/app/src/i18n/ja.json @@ -112,5 +112,6 @@ "refresh": "更新", "finish-refresh": "更新が完了しました", "response": "応答", - "read-prompt": "キーワードを抽出" + "read-prompt": "キーワードを抽出", + "execute-tool": "ツールを実行" } \ No newline at end of file diff --git a/app/src/i18n/ko.json b/app/src/i18n/ko.json index b262d0b..82356dc 100644 --- a/app/src/i18n/ko.json +++ b/app/src/i18n/ko.json @@ -112,5 +112,6 @@ "refresh": "새로 고침", "finish-refresh": "새로 고침 완료", "response": "응답", - "read-prompt": "키워드 추출" + "read-prompt": "키워드 추출", + "execute-tool": "도구 실행" } \ No newline at end of file diff --git a/app/src/i18n/ru.json b/app/src/i18n/ru.json index 1fde47e..44b0181 100644 --- a/app/src/i18n/ru.json +++ b/app/src/i18n/ru.json @@ -112,5 +112,6 @@ "refresh": "Обновить", "finish-refresh": "Обновление завершено", "response": "Ответ", - "read-prompt": "Извлечь ключевые слова" + "read-prompt": "Извлечь ключевые слова", + "execute-tool": "Запустить инструмент" } \ No newline at end of file diff --git a/app/src/i18n/zh-cn.json b/app/src/i18n/zh-cn.json index ea7cf1f..c1a0db2 100644 --- a/app/src/i18n/zh-cn.json +++ b/app/src/i18n/zh-cn.json @@ -112,5 +112,6 @@ "refresh": "刷新", "finish-refresh": "刷新完成", "response": "响应", - "read-prompt": "提取提词" + "read-prompt": "提取提词", + "execute-tool": "运行工具" } \ No newline at end of file diff --git a/app/src/i18n/zh-tw.json b/app/src/i18n/zh-tw.json index 99aaa28..e3cb79a 100644 --- a/app/src/i18n/zh-tw.json +++ b/app/src/i18n/zh-tw.json @@ -112,5 +112,6 @@ "refresh": "重新整理", "finish-refresh": "刷新完成", "response": "響應", - "read-prompt": "提取關鍵詞" + "read-prompt": "提取關鍵詞", + "execute-tool": "執行工具" } \ No newline at end of file diff --git a/test/.gitignore b/test/.gitignore index 403adbc..90d979e 100644 --- a/test/.gitignore +++ b/test/.gitignore @@ -21,3 +21,4 @@ pnpm-debug.log* *.njsproj *.sln *.sw? +config.json \ No newline at end of file diff --git a/test/src/controller/connect.ts b/test/src/controller/connect.ts index 6fc94d2..3352b0c 100644 --- a/test/src/controller/connect.ts +++ b/test/src/controller/connect.ts @@ -105,6 +105,11 @@ export class MCPClient { }); } + // 列出所有工具 + public async listTools() { + return await this.client.listTools(); + } + // 调用工具 public async callTool(options: { name: string; arguments: Record }) { return await this.client.callTool(options); diff --git a/test/src/controller/handler.ts b/test/src/controller/handler.ts index c84e487..4108202 100644 --- a/test/src/controller/handler.ts +++ b/test/src/controller/handler.ts @@ -182,6 +182,41 @@ export async function readResource( } } +/** + * @description 获取工具列表 + */ +export async function listTools( + client: MCPClient | undefined, + webview: VSCodeWebViewLike +) { + if (!client) { + const connectResult = { + code: 501, + msg: 'mcp client 尚未连接' + }; + webview.postMessage({ command: 'tools/list', data: connectResult }); + return; + } + + try { + const tools = await client.listTools(); + + const result = { + code: 200, + msg: tools + }; + + webview.postMessage({ command: 'tools/list', data: result }); + } catch (error) { + const result = { + code: 500, + msg: (error as any).toString() + }; + webview.postMessage({ command: 'tools/list', data: result }); + } +} + + /** * @description 调用工具 */ @@ -204,6 +239,7 @@ export async function callTool( name: option.toolName, arguments: option.toolArgs }); + const result = { code: 200, msg: toolResult diff --git a/test/src/controller/index.ts b/test/src/controller/index.ts index b136c46..0467c01 100644 --- a/test/src/controller/index.ts +++ b/test/src/controller/index.ts @@ -1,7 +1,7 @@ import { VSCodeWebViewLike } from '../adapter'; import { connect, MCPClient, type MCPOptions } from './connect'; -import { callTool, getPrompt, listPrompts, listResources, listResourceTemplates, readResource } from './handler'; +import { callTool, getPrompt, listPrompts, listResources, listResourceTemplates, listTools, readResource } from './handler'; import { ping } from './util'; @@ -57,6 +57,10 @@ export function messageController(command: string, data: any, webview: VSCodeWeb readResource(client, data, webview); break; + case 'tools/list': + listTools(client, webview); + break; + case 'tools/call': callTool(client, data, webview); break; diff --git a/test/src/controller/protocol.type.ts b/test/src/controller/protocol.type.ts index bf37883..8315dfe 100644 --- a/test/src/controller/protocol.type.ts +++ b/test/src/controller/protocol.type.ts @@ -67,6 +67,16 @@ export interface PromptsGetResponse { }>; } +export interface ToolListItem { + name: string; + description: string; + inputSchema: InputSchema; +} + +export interface ToolsListResponse { + tools: ToolListItem[]; +} + // ==================== 请求接口定义 ==================== export interface BaseRequest { method: string; diff --git a/test/src/util.ts b/test/src/util.ts new file mode 100644 index 0000000..840b34a --- /dev/null +++ b/test/src/util.ts @@ -0,0 +1,12 @@ +function getConfigurationPath() { + // 如果是 vscode 插件下,则修改为 ~/.openmcp/config.json + return 'config.json'; +} + +export function loadConfig() { + +} + +export function saveConfig() { + +} \ No newline at end of file