@@ -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" ;
3840import 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 - z 0 - 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 (
0 commit comments