Skip to content

Commit d2dbaaa

Browse files
feat: add MCPs tab and config flow (anomalyco#106)
1 parent afdea99 commit d2dbaaa

6 files changed

Lines changed: 702 additions & 2 deletions

File tree

‎src/App.tsx‎

Lines changed: 182 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,13 @@ import {
3030
DEFAULT_MODEL,
3131
DEMO_MODE_PREF_KEY,
3232
DEMO_SEQUENCE_PREF_KEY,
33+
MCP_QUICK_CONNECT,
3334
MODEL_PREF_KEY,
3435
SUGGESTED_PLUGINS,
3536
THINKING_PREF_KEY,
3637
VARIANT_PREF_KEY,
3738
} from "./app/constants";
39+
import { parseMcpServersFromContent } from "./app/mcp";
3840
import type {
3941
Client,
4042
CuratedPackage,
@@ -52,6 +54,7 @@ import type {
5254
TodoItem,
5355
View,
5456
WorkspaceDisplay,
57+
McpServerEntry,
5558
WorkspaceTemplate,
5659
UpdateHandle,
5760
} from "./app/types";
@@ -672,10 +675,24 @@ export default function App() {
672675
const [notionSkillInstalled, setNotionSkillInstalled] = createSignal(false);
673676
const [tryNotionPromptVisible, setTryNotionPromptVisible] = createSignal(false);
674677
const notionIsActive = createMemo(() => notionStatus() === "connected");
678+
const [mcpServers, setMcpServers] = createSignal<McpServerEntry[]>([]);
679+
const [mcpStatus, setMcpStatus] = createSignal<string | null>(null);
680+
const [mcpLastUpdatedAt, setMcpLastUpdatedAt] = createSignal<number | null>(null);
681+
const [selectedMcp, setSelectedMcp] = createSignal<string | null>(null);
682+
const [advancedMcpName, setAdvancedMcpName] = createSignal("");
683+
const [advancedMcpUrl, setAdvancedMcpUrl] = createSignal("");
684+
const [advancedMcpOAuth, setAdvancedMcpOAuth] = createSignal(true);
685+
const [advancedMcpEnabled, setAdvancedMcpEnabled] = createSignal(true);
675686
const [cacheRepairBusy, setCacheRepairBusy] = createSignal(false);
676687
const [cacheRepairResult, setCacheRepairResult] = createSignal<string | null>(
677688
null
678689
);
690+
const advancedCommand = createMemo(() => "opencode mcp add");
691+
692+
const advancedAuthCommand = createMemo(() => {
693+
const name = advancedMcpName().trim() || "my-mcp";
694+
return `opencode mcp auth ${name}`;
695+
});
679696

680697

681698
const extensionsStore = createExtensionsStore({
@@ -1607,7 +1624,7 @@ export default function App() {
16071624
const mcp = typeof nextConfig.mcp === "object" && nextConfig.mcp ? { ...(nextConfig.mcp as Record<string, unknown>) } : {};
16081625
mcp.notion = {
16091626
type: "remote",
1610-
url: "https://mcp.notion.com",
1627+
url: "https://mcp.notion.com/mcp",
16111628
enabled: true,
16121629
};
16131630

@@ -1636,6 +1653,148 @@ export default function App() {
16361653
}
16371654
}
16381655

1656+
async function refreshMcpServers() {
1657+
if (!isTauriRuntime()) {
1658+
setMcpStatus("MCP configuration is only available in Host mode.");
1659+
setMcpServers([]);
1660+
return;
1661+
}
1662+
1663+
const projectDir = workspaceProjectDir().trim();
1664+
if (!projectDir) {
1665+
setMcpStatus("Pick a workspace folder to load MCP servers.");
1666+
setMcpServers([]);
1667+
return;
1668+
}
1669+
1670+
try {
1671+
setMcpStatus(null);
1672+
const config = await readOpencodeConfig("project", projectDir);
1673+
if (!config.exists || !config.content) {
1674+
setMcpServers([]);
1675+
setMcpStatus("No opencode.json found yet. Add an MCP to create one.");
1676+
return;
1677+
}
1678+
1679+
const next = parseMcpServersFromContent(config.content);
1680+
setMcpServers(next);
1681+
setMcpLastUpdatedAt(Date.now());
1682+
if (!next.length) {
1683+
setMcpStatus("No MCP servers configured yet.");
1684+
}
1685+
} catch (e) {
1686+
setMcpServers([]);
1687+
setMcpStatus(e instanceof Error ? e.message : "Failed to load MCP servers");
1688+
}
1689+
}
1690+
1691+
async function connectMcp(entry: (typeof MCP_QUICK_CONNECT)[number]) {
1692+
if (mode() !== "host") {
1693+
setMcpStatus("MCP connections are only available in Host mode.");
1694+
return;
1695+
}
1696+
1697+
const projectDir = workspaceProjectDir().trim();
1698+
if (!projectDir) {
1699+
setMcpStatus("Pick a workspace folder first.");
1700+
return;
1701+
}
1702+
1703+
if (!isTauriRuntime()) {
1704+
setMcpStatus("MCP connections require the desktop app.");
1705+
return;
1706+
}
1707+
1708+
try {
1709+
setMcpStatus(null);
1710+
const config = await readOpencodeConfig("project", projectDir);
1711+
const raw = config.content ?? "";
1712+
const nextConfig = raw.trim()
1713+
? (parse(raw) as Record<string, unknown>)
1714+
: { $schema: "https://opencode.ai/config.json" };
1715+
1716+
const mcp = typeof nextConfig.mcp === "object" && nextConfig.mcp ? { ...(nextConfig.mcp as Record<string, unknown>) } : {};
1717+
const slug = entry.name.toLowerCase().replace(/[^a-z0-9]+/g, "-");
1718+
mcp[slug] = {
1719+
type: "remote",
1720+
url: entry.url,
1721+
enabled: true,
1722+
...(entry.oauth ? { oauth: {} } : {}),
1723+
};
1724+
1725+
nextConfig.mcp = mcp;
1726+
const formatted = JSON.stringify(nextConfig, null, 2);
1727+
1728+
const result = await writeOpencodeConfig("project", projectDir, `${formatted}\n`);
1729+
if (!result.ok) {
1730+
throw new Error(result.stderr || result.stdout || "Failed to update opencode.json");
1731+
}
1732+
1733+
markReloadRequired("mcp");
1734+
setMcpStatus("Reload required to activate the new MCP.");
1735+
await refreshMcpServers();
1736+
} catch (e) {
1737+
setMcpStatus(e instanceof Error ? e.message : "Failed to connect MCP.");
1738+
}
1739+
}
1740+
1741+
async function addAdvancedMcp() {
1742+
const name = advancedMcpName().trim();
1743+
const url = advancedMcpUrl().trim();
1744+
1745+
if (!name || !url) {
1746+
setMcpStatus("Enter a server name and URL.");
1747+
return;
1748+
}
1749+
1750+
const projectDir = workspaceProjectDir().trim();
1751+
if (!projectDir) {
1752+
setMcpStatus("Pick a workspace folder first.");
1753+
return;
1754+
}
1755+
1756+
try {
1757+
const config = await readOpencodeConfig("project", projectDir);
1758+
const raw = config.content ?? "";
1759+
const nextConfig = raw.trim()
1760+
? (parse(raw) as Record<string, unknown>)
1761+
: { $schema: "https://opencode.ai/config.json" };
1762+
1763+
const mcp = typeof nextConfig.mcp === "object" && nextConfig.mcp ? { ...(nextConfig.mcp as Record<string, unknown>) } : {};
1764+
mcp[name] = {
1765+
type: "remote",
1766+
url,
1767+
enabled: advancedMcpEnabled(),
1768+
...(advancedMcpOAuth() ? { oauth: {} } : { oauth: false }),
1769+
};
1770+
1771+
nextConfig.mcp = mcp;
1772+
const formatted = JSON.stringify(nextConfig, null, 2);
1773+
1774+
const result = await writeOpencodeConfig("project", projectDir, `${formatted}\n`);
1775+
if (!result.ok) {
1776+
throw new Error(result.stderr || result.stdout || "Failed to update opencode.json");
1777+
}
1778+
1779+
markReloadRequired("mcp");
1780+
setMcpStatus("Reload required to activate the new MCP.");
1781+
setAdvancedMcpName("");
1782+
setAdvancedMcpUrl("");
1783+
await refreshMcpServers();
1784+
} catch (e) {
1785+
setMcpStatus(e instanceof Error ? e.message : "Failed to add MCP.");
1786+
}
1787+
}
1788+
1789+
async function testAdvancedMcp() {
1790+
if (!advancedMcpUrl().trim()) {
1791+
setMcpStatus("Enter a server URL first.");
1792+
return;
1793+
}
1794+
1795+
setMcpStatus("Use opencode mcp debug <name> to validate connection.");
1796+
}
1797+
16391798
async function createSessionAndOpen() {
16401799
console.log("[DEBUG] createSessionAndOpen");
16411800
console.log("[DEBUG] current baseUrl:", baseUrl());
@@ -2011,6 +2170,8 @@ export default function App() {
20112170
markReloadRequired("mcp");
20122171
}
20132172

2173+
await refreshMcpServers();
2174+
20142175
const storedNotionSkillInstalled = window.localStorage.getItem("openwork.notionSkillInstalled");
20152176
if (storedNotionSkillInstalled === "1") {
20162177
setNotionSkillInstalled(true);
@@ -2417,6 +2578,26 @@ export default function App() {
24172578
notionError: notionError(),
24182579
notionBusy: notionBusy(),
24192580
connectNotion,
2581+
mcpServers: mcpServers(),
2582+
mcpStatus: mcpStatus(),
2583+
mcpLastUpdatedAt: mcpLastUpdatedAt(),
2584+
selectedMcp: selectedMcp(),
2585+
setSelectedMcp,
2586+
quickConnect: MCP_QUICK_CONNECT,
2587+
connectMcp,
2588+
addAdvancedMcp,
2589+
testAdvancedMcp,
2590+
refreshMcpServers,
2591+
advancedName: advancedMcpName(),
2592+
setAdvancedName: setAdvancedMcpName,
2593+
advancedUrl: advancedMcpUrl(),
2594+
setAdvancedUrl: setAdvancedMcpUrl,
2595+
advancedOAuth: advancedMcpOAuth(),
2596+
setAdvancedOAuth: setAdvancedMcpOAuth,
2597+
advancedEnabled: advancedMcpEnabled(),
2598+
setAdvancedEnabled: setAdvancedMcpEnabled,
2599+
advancedCommand: advancedCommand(),
2600+
advancedAuthCommand: advancedAuthCommand(),
24202601
});
24212602

24222603
return (

‎src/app/constants.ts‎

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,55 @@ export const SUGGESTED_PLUGINS: SuggestedPlugin[] = [
9696
],
9797
},
9898
];
99+
100+
export type McpDirectoryInfo = {
101+
name: string;
102+
description: string;
103+
url: string;
104+
oauth: boolean;
105+
};
106+
107+
export const MCP_QUICK_CONNECT: McpDirectoryInfo[] = [
108+
{
109+
name: "Notion",
110+
description: "Pages, databases, and project docs in sync.",
111+
url: "https://mcp.notion.com/mcp",
112+
oauth: true,
113+
},
114+
{
115+
name: "Linear",
116+
description: "Plan sprints and ship tickets faster.",
117+
url: "https://mcp.linear.app/mcp",
118+
oauth: true,
119+
},
120+
{
121+
name: "Sentry",
122+
description: "Track releases and resolve production errors.",
123+
url: "https://mcp.sentry.dev/mcp",
124+
oauth: true,
125+
},
126+
{
127+
name: "Figma",
128+
description: "Pull specs and assets from design files.",
129+
url: "https://mcp.figma.com/mcp",
130+
oauth: true,
131+
},
132+
{
133+
name: "Stripe",
134+
description: "Inspect payments, invoices, and subscriptions.",
135+
url: "https://mcp.stripe.com",
136+
oauth: true,
137+
},
138+
{
139+
name: "HubSpot",
140+
description: "CRM notes, companies, and pipeline status.",
141+
url: "https://mcp.hubspot.com/anthropic",
142+
oauth: true,
143+
},
144+
{
145+
name: "Context7",
146+
description: "Search product docs with richer context.",
147+
url: "https://mcp.context7.com/mcp",
148+
oauth: false,
149+
},
150+
];

‎src/app/mcp.ts‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { parse } from "jsonc-parser";
2+
import type { McpServerConfig, McpServerEntry } from "./types";
3+
4+
type McpConfigValue = Record<string, unknown> | null | undefined;
5+
6+
export function parseMcpServersFromContent(content: string): McpServerEntry[] {
7+
if (!content.trim()) return [];
8+
9+
try {
10+
const parsed = parse(content) as Record<string, unknown> | undefined;
11+
const mcp = parsed?.mcp as McpConfigValue;
12+
13+
if (!mcp || typeof mcp !== "object") {
14+
return [];
15+
}
16+
17+
return Object.entries(mcp).flatMap(([name, value]) => {
18+
if (!value || typeof value !== "object") {
19+
return [];
20+
}
21+
22+
const config = value as McpServerConfig;
23+
if (config.type !== "remote" && config.type !== "local") {
24+
return [];
25+
}
26+
27+
return [{ name, config }];
28+
});
29+
} catch {
30+
return [];
31+
}
32+
}

‎src/app/types.ts‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export type Mode = "host" | "client";
6363

6464
export type OnboardingStep = "mode" | "host" | "client" | "connecting";
6565

66-
export type DashboardTab = "home" | "sessions" | "templates" | "skills" | "plugins" | "settings";
66+
export type DashboardTab = "home" | "sessions" | "templates" | "skills" | "plugins" | "mcp" | "settings";
6767

6868
export type DemoSequence = "cold-open" | "scheduler" | "summaries" | "groceries";
6969

@@ -128,6 +128,22 @@ export type SuggestedPlugin = {
128128

129129
export type PluginScope = "project" | "global";
130130

131+
export type McpServerConfig = {
132+
type: "remote" | "local";
133+
url?: string;
134+
command?: string[];
135+
enabled?: boolean;
136+
headers?: Record<string, string>;
137+
environment?: Record<string, string>;
138+
oauth?: Record<string, string> | false;
139+
timeout?: number;
140+
};
141+
142+
export type McpServerEntry = {
143+
name: string;
144+
config: McpServerConfig;
145+
};
146+
131147
export type ReloadReason = "plugins" | "skills" | "mcp";
132148

133149
export type PendingPermission = ApiPermissionRequest & {

0 commit comments

Comments
 (0)