migrate download MCP response to proto (#4682)
This commit is contained in:
1 parent
3577c2efa9
commit
6d2cf55fc5
5 files changed
+60
-82
No files matched your search
@@ -1,6 +1,7 @@
|
||||
import { Controller } from ".."
|
||||
import { Empty, StringRequest } from "../../../shared/proto/common"
|
||||
import { McpServer, McpDownloadResponse } from "@shared/mcp"
|
||||
import { StringRequest } from "../../../shared/proto/common"
|
||||
import { McpDownloadResponse } from "../../../shared/proto/mcp"
|
||||
import { McpServer } from "@shared/mcp"
|
||||
import axios from "axios"
|
||||
import * as vscode from "vscode"
|
||||
import { sendChatButtonClickedEvent } from "../ui/subscribeToChatButtonClicked"
|
||||
@@ -9,9 +10,9 @@ import { sendChatButtonClickedEvent } from "../ui/subscribeToChatButtonClicked"
|
||||
* Download an MCP server from the marketplace
|
||||
* @param controller The controller instance
|
||||
* @param request The request containing the MCP ID
|
||||
* @returns Empty response
|
||||
* @returns MCP download response with details or error
|
||||
*/
|
||||
export async function downloadMcp(controller: Controller, request: StringRequest): Promise<Empty> {
|
||||
export async function downloadMcp(controller: Controller, request: StringRequest): Promise<McpDownloadResponse> {
|
||||
try {
|
||||
// Check if mcpId is provided
|
||||
if (!request.value) {
|
||||
@@ -54,12 +55,6 @@ export async function downloadMcp(controller: Controller, request: StringRequest
|
||||
throw new Error("Missing README content in MCP download response")
|
||||
}
|
||||
|
||||
// Send details to webview
|
||||
await controller.postMessageToWebview({
|
||||
type: "mcpDownloadDetails",
|
||||
mcpDownloadDetails: mcpDetails,
|
||||
})
|
||||
|
||||
// Create task with context from README and added guidelines for MCP server installation
|
||||
const task = `Set up the MCP server from ${mcpDetails.githubUrl} while adhering to these MCP server installation rules:
|
||||
- Start by loading the MCP documentation.
|
||||
@@ -80,8 +75,17 @@ Here is the project's README to help you get started:\n\n${mcpDetails.readmeCont
|
||||
await controller.initTask(task)
|
||||
await sendChatButtonClickedEvent(controller.id)
|
||||
|
||||
// Return an empty response - the client only cares if the call succeeded
|
||||
return Empty.create()
|
||||
// Return the download details directly
|
||||
return McpDownloadResponse.create({
|
||||
mcpId: mcpDetails.mcpId,
|
||||
githubUrl: mcpDetails.githubUrl,
|
||||
name: mcpDetails.name,
|
||||
author: mcpDetails.author,
|
||||
description: mcpDetails.description,
|
||||
readmeContent: mcpDetails.readmeContent,
|
||||
llmsInstallationContent: mcpDetails.llmsInstallationContent,
|
||||
requiresApiKey: mcpDetails.requiresApiKey,
|
||||
})
|
||||
} catch (error) {
|
||||
console.error("Failed to download MCP:", error)
|
||||
let errorMessage = "Failed to download MCP"
|
||||
@@ -100,13 +104,17 @@ Here is the project's README to help you get started:\n\n${mcpDetails.readmeCont
|
||||
errorMessage = error.message
|
||||
}
|
||||
|
||||
// Show error in both notification and marketplace UI
|
||||
vscode.window.showErrorMessage(errorMessage)
|
||||
await controller.postMessageToWebview({
|
||||
type: "mcpDownloadDetails",
|
||||
// Return error in the response instead of throwing
|
||||
return McpDownloadResponse.create({
|
||||
mcpId: "",
|
||||
githubUrl: "",
|
||||
name: "",
|
||||
author: "",
|
||||
description: "",
|
||||
readmeContent: "",
|
||||
llmsInstallationContent: "",
|
||||
requiresApiKey: false,
|
||||
error: errorMessage,
|
||||
})
|
||||
|
||||
throw error
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user