Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | import { EmptyRequest } from "@shared/proto/cline/common" import { AddRemoteMcpServerRequest, McpServers } from "@shared/proto/cline/mcp" import { convertProtoMcpServersToMcpServers } from "@shared/proto-conversions/mcp/mcp-server-conversion" import { VSCodeButton, VSCodeLink, VSCodeTextField } from "@vscode/webview-ui-toolkit/react" import { useState } from "react" import { LINKS } from "@/constants" import { useExtensionState } from "@/context/ExtensionStateContext" import { McpServiceClient } from "@/services/grpc-client" const AddRemoteServerForm = ({ onServerAdded }: { onServerAdded: () => void }) => { const [serverName, setServerName] = useState("") const [serverUrl, setServerUrl] = useState("") const [isSubmitting, setIsSubmitting] = useState(false) const [error, setError] = useState("") const [showConnectingMessage, setShowConnectingMessage] = useState(false) const { setMcpServers } = useExtensionState() const handleSubmit = async (e: React.FormEvent<HTMLFormElement>) => { e.preventDefault() if (!serverName.trim()) { setError("Server name is required") return } if (!serverUrl.trim()) { setError("Server URL is required") return } try { new URL(serverUrl) } catch (_err) { setError("Invalid URL format") return } setError("") setIsSubmitting(true) setShowConnectingMessage(true) try { const servers: McpServers = await McpServiceClient.addRemoteMcpServer( AddRemoteMcpServerRequest.create({ serverName: serverName.trim(), serverUrl: serverUrl.trim(), }), ) setIsSubmitting(false) const mcpServers = convertProtoMcpServersToMcpServers(servers.mcpServers) setMcpServers(mcpServers) setServerName("") setServerUrl("") onServerAdded() setShowConnectingMessage(false) } catch (error) { setIsSubmitting(false) setError(error instanceof Error ? error.message : "Failed to add server") setShowConnectingMessage(false) } } return ( <div className="p-4 px-5"> <div className="text-[var(--vscode-foreground)] mb-2"> Add a remote MCP server by providing a name and its URL endpoint. Learn more{" "} <VSCodeLink href={LINKS.DOCUMENTATION.REMOTE_MCP_SERVER_DOCS} style={{ display: "inline" }}> here. </VSCodeLink> </div> <form onSubmit={handleSubmit}> <div className="mb-2"> <VSCodeTextField className="w-full" disabled={isSubmitting} onChange={(e) => { setServerName((e.target as HTMLInputElement).value) setError("") }} placeholder="mcp-server" value={serverName}> Server Name </VSCodeTextField> </div> <div className="mb-2"> <VSCodeTextField className="w-full mr-4" disabled={isSubmitting} onChange={(e) => { setServerUrl((e.target as HTMLInputElement).value) setError("") }} placeholder="https://example.com/mcp-server" value={serverUrl}> Server URL </VSCodeTextField> </div> {error && <div className="mb-3 text-[var(--vscode-errorForeground)]">{error}</div>} <div className="flex items-center mt-3 w-full"> <VSCodeButton className="w-full" disabled={isSubmitting} type="submit"> {isSubmitting ? "Adding..." : "Add Server"} </VSCodeButton> {showConnectingMessage && ( <div className="ml-3 text-[var(--vscode-notificationsInfoIcon-foreground)] text-sm"> Connecting to server... This may take a few seconds. </div> )} </div> <VSCodeButton appearance="secondary" onClick={() => { McpServiceClient.openMcpSettings(EmptyRequest.create({})).catch((error) => { console.error("Error opening MCP settings:", error) }) }} style={{ width: "100%", marginBottom: "5px", marginTop: 15 }}> Edit Configuration </VSCodeButton> </form> </div> ) } export default AddRemoteServerForm |