|
1 | 1 | import { VSCodeButton, VSCodeLink, VSCodePanels, VSCodePanelTab, VSCodePanelView } from "@vscode/webview-ui-toolkit/react" |
2 | | -import { useState, useEffect } from "react" |
3 | | -import { vscode } from "../../utils/vscode" |
4 | | -import { useExtensionState } from "../../context/ExtensionStateContext" |
5 | | -import { McpServer } from "../../../../src/shared/mcp" |
6 | | -import McpToolRow from "./McpToolRow" |
7 | | -import McpResourceRow from "./McpResourceRow" |
8 | | -import McpMarketplaceView from "./marketplace/McpMarketplaceView" |
| 2 | +import { useEffect, useState } from "react" |
9 | 3 | import styled from "styled-components" |
| 4 | +import { McpServer } from "../../../../src/shared/mcp" |
| 5 | +import { useExtensionState } from "../../context/ExtensionStateContext" |
10 | 6 | import { getMcpServerDisplayName } from "../../utils/mcp" |
| 7 | +import { vscode } from "../../utils/vscode" |
11 | 8 | import DangerButton from "../common/DangerButton" |
| 9 | +import McpMarketplaceView from "./marketplace/McpMarketplaceView" |
| 10 | +import McpResourceRow from "./McpResourceRow" |
| 11 | +import McpToolRow from "./McpToolRow" |
12 | 12 |
|
13 | 13 | type McpViewProps = { |
14 | 14 | onDone: () => void |
15 | 15 | } |
16 | 16 |
|
17 | 17 | const McpView = ({ onDone }: McpViewProps) => { |
18 | | - const { mcpServers: servers } = useExtensionState() |
19 | | - const [activeTab, setActiveTab] = useState("marketplace") |
| 18 | + const { mcpServers: servers, mcpMarketplaceEnabled } = useExtensionState() |
| 19 | + const [activeTab, setActiveTab] = useState(mcpMarketplaceEnabled ? "marketplace" : "installed") |
20 | 20 |
|
21 | 21 | const handleTabChange = (tab: string) => { |
22 | 22 | setActiveTab(tab) |
23 | 23 | } |
24 | 24 |
|
25 | 25 | useEffect(() => { |
26 | | - vscode.postMessage({ type: "silentlyRefreshMcpMarketplace" }) |
27 | | - vscode.postMessage({ type: "fetchLatestMcpServersFromHub" }) |
28 | | - }, []) |
| 26 | + if (!mcpMarketplaceEnabled && activeTab === "marketplace") { |
| 27 | + // If marketplace is disabled and we're on marketplace tab, switch to installed |
| 28 | + setActiveTab("installed") |
| 29 | + } |
| 30 | + }, [mcpMarketplaceEnabled, activeTab]) |
29 | 31 |
|
30 | | - // const [servers, setServers] = useState<McpServer[]>([ |
31 | | - // // Add some mock servers for testing |
32 | | - // { |
33 | | - // name: "local-tools", |
34 | | - // config: JSON.stringify({ |
35 | | - // mcpServers: { |
36 | | - // "local-tools": { |
37 | | - // command: "npx", |
38 | | - // args: ["-y", "@modelcontextprotocol/server-tools"], |
39 | | - // }, |
40 | | - // }, |
41 | | - // }), |
42 | | - // status: "connected", |
43 | | - // tools: [ |
44 | | - // { |
45 | | - // name: "execute_command", |
46 | | - // description: "Run a shell command on the local system", |
47 | | - // }, |
48 | | - // { |
49 | | - // name: "read_file", |
50 | | - // description: "Read contents of a file from the filesystem", |
51 | | - // }, |
52 | | - // ], |
53 | | - // }, |
54 | | - // { |
55 | | - // name: "postgres-db", |
56 | | - // config: JSON.stringify({ |
57 | | - // mcpServers: { |
58 | | - // "postgres-db": { |
59 | | - // command: "npx", |
60 | | - // args: ["-y", "@modelcontextprotocol/server-postgres", "postgresql://localhost/mydb"], |
61 | | - // }, |
62 | | - // }, |
63 | | - // }), |
64 | | - // status: "disconnected", |
65 | | - // error: "Failed to connect to database: Connection refused", |
66 | | - // }, |
67 | | - // { |
68 | | - // name: "github-tools", |
69 | | - // config: JSON.stringify({ |
70 | | - // mcpServers: { |
71 | | - // "github-tools": { |
72 | | - // command: "npx", |
73 | | - // args: ["-y", "@modelcontextprotocol/server-github"], |
74 | | - // }, |
75 | | - // }, |
76 | | - // }), |
77 | | - // status: "connecting", |
78 | | - // resources: [ |
79 | | - // { |
80 | | - // uri: "github://repo/issues", |
81 | | - // name: "Repository Issues", |
82 | | - // }, |
83 | | - // { |
84 | | - // uri: "github://repo/pulls", |
85 | | - // name: "Pull Requests", |
86 | | - // }, |
87 | | - // ], |
88 | | - // }, |
89 | | - // ]) |
| 32 | + useEffect(() => { |
| 33 | + if (mcpMarketplaceEnabled) { |
| 34 | + vscode.postMessage({ type: "silentlyRefreshMcpMarketplace" }) |
| 35 | + vscode.postMessage({ type: "fetchLatestMcpServersFromHub" }) |
| 36 | + } |
| 37 | + }, [mcpMarketplaceEnabled]) |
90 | 38 |
|
91 | 39 | return ( |
92 | 40 | <div |
@@ -119,17 +67,19 @@ const McpView = ({ onDone }: McpViewProps) => { |
119 | 67 | padding: "0 20px 0 20px", |
120 | 68 | borderBottom: "1px solid var(--vscode-panel-border)", |
121 | 69 | }}> |
122 | | - <TabButton isActive={activeTab === "marketplace"} onClick={() => handleTabChange("marketplace")}> |
123 | | - Marketplace |
124 | | - </TabButton> |
| 70 | + {mcpMarketplaceEnabled && ( |
| 71 | + <TabButton isActive={activeTab === "marketplace"} onClick={() => handleTabChange("marketplace")}> |
| 72 | + Marketplace |
| 73 | + </TabButton> |
| 74 | + )} |
125 | 75 | <TabButton isActive={activeTab === "installed"} onClick={() => handleTabChange("installed")}> |
126 | 76 | Installed |
127 | 77 | </TabButton> |
128 | 78 | </div> |
129 | 79 |
|
130 | 80 | {/* Content container */} |
131 | 81 | <div style={{ width: "100%" }}> |
132 | | - {activeTab === "marketplace" && <McpMarketplaceView />} |
| 82 | + {mcpMarketplaceEnabled && activeTab === "marketplace" && <McpMarketplaceView />} |
133 | 83 | {activeTab === "installed" && ( |
134 | 84 | <div style={{ padding: "16px 20px" }}> |
135 | 85 | <div |
@@ -472,7 +422,6 @@ const ServerRow = ({ server }: { server: McpServer }) => { |
472 | 422 | </VSCodeButton> |
473 | 423 |
|
474 | 424 | <DangerButton |
475 | | - // appearance="secondary" |
476 | 425 | onClick={handleDelete} |
477 | 426 | disabled={isDeleting} |
478 | 427 | style={{ |
|
0 commit comments