@@ -36,6 +36,18 @@ function getAuthStatusText(status: MCP.AuthStatus): string {
3636 }
3737}
3838
39+ type McpEntry = NonNullable < Config . Info [ "mcp" ] > [ string ]
40+
41+ type McpConfigured = Config . Mcp
42+ function isMcpConfigured ( config : McpEntry ) : config is McpConfigured {
43+ return typeof config === "object" && config !== null && "type" in config
44+ }
45+
46+ type McpRemote = Extract < McpConfigured , { type : "remote" } >
47+ function isMcpRemote ( config : McpEntry ) : config is McpRemote {
48+ return isMcpConfigured ( config ) && config . type === "remote"
49+ }
50+
3951export const McpCommand = cmd ( {
4052 command : "mcp" ,
4153 builder : ( yargs ) =>
@@ -64,15 +76,19 @@ export const McpListCommand = cmd({
6476 const mcpServers = config . mcp ?? { }
6577 const statuses = await MCP . status ( )
6678
67- if ( Object . keys ( mcpServers ) . length === 0 ) {
79+ const servers = Object . entries ( mcpServers ) . filter ( ( entry ) : entry is [ string , McpConfigured ] =>
80+ isMcpConfigured ( entry [ 1 ] ) ,
81+ )
82+
83+ if ( servers . length === 0 ) {
6884 prompts . log . warn ( "No MCP servers configured" )
6985 prompts . outro ( "Add servers with: opencode mcp add" )
7086 return
7187 }
7288
73- for ( const [ name , serverConfig ] of Object . entries ( mcpServers ) ) {
89+ for ( const [ name , serverConfig ] of servers ) {
7490 const status = statuses [ name ]
75- const hasOAuth = serverConfig . type === "remote" && ! ! serverConfig . oauth
91+ const hasOAuth = isMcpRemote ( serverConfig ) && ! ! serverConfig . oauth
7692 const hasStoredTokens = await MCP . hasStoredTokens ( name )
7793
7894 let statusIcon : string
@@ -110,7 +126,7 @@ export const McpListCommand = cmd({
110126 )
111127 }
112128
113- prompts . outro ( `${ Object . keys ( mcpServers ) . length } server(s)` )
129+ prompts . outro ( `${ servers . length } server(s)` )
114130 } ,
115131 } )
116132 } ,
@@ -138,7 +154,7 @@ export const McpAuthCommand = cmd({
138154
139155 // Get OAuth-capable servers (remote servers with oauth not explicitly disabled)
140156 const oauthServers = Object . entries ( mcpServers ) . filter (
141- ( [ _ , cfg ] ) => cfg . type === "remote" && cfg . oauth !== false ,
157+ ( entry ) : entry is [ string , McpRemote ] => isMcpRemote ( entry [ 1 ] ) && entry [ 1 ] . oauth !== false ,
142158 )
143159
144160 if ( oauthServers . length === 0 ) {
@@ -163,7 +179,7 @@ export const McpAuthCommand = cmd({
163179 const authStatus = await MCP . getAuthStatus ( name )
164180 const icon = getAuthStatusIcon ( authStatus )
165181 const statusText = getAuthStatusText ( authStatus )
166- const url = cfg . type === "remote" ? cfg . url : ""
182+ const url = cfg . url
167183 return {
168184 label : `${ icon } ${ name } (${ statusText } )` ,
169185 value : name ,
@@ -187,8 +203,8 @@ export const McpAuthCommand = cmd({
187203 return
188204 }
189205
190- if ( serverConfig . type !== "remote" || serverConfig . oauth === false ) {
191- prompts . log . error ( `MCP server ${ serverName } does not support OAuth (oauth is disabled) ` )
206+ if ( ! isMcpRemote ( serverConfig ) || serverConfig . oauth === false ) {
207+ prompts . log . error ( `MCP server ${ serverName } is not an OAuth-capable remote server ` )
192208 prompts . outro ( "Done" )
193209 return
194210 }
@@ -263,7 +279,7 @@ export const McpAuthListCommand = cmd({
263279
264280 // Get OAuth-capable servers
265281 const oauthServers = Object . entries ( mcpServers ) . filter (
266- ( [ _ , cfg ] ) => cfg . type === "remote" && cfg . oauth !== false ,
282+ ( entry ) : entry is [ string , McpRemote ] => isMcpRemote ( entry [ 1 ] ) && entry [ 1 ] . oauth !== false ,
267283 )
268284
269285 if ( oauthServers . length === 0 ) {
@@ -276,7 +292,7 @@ export const McpAuthListCommand = cmd({
276292 const authStatus = await MCP . getAuthStatus ( name )
277293 const icon = getAuthStatusIcon ( authStatus )
278294 const statusText = getAuthStatusText ( authStatus )
279- const url = serverConfig . type === "remote" ? serverConfig . url : ""
295+ const url = serverConfig . url
280296
281297 prompts . log . info ( `${ icon } ${ name } ${ UI . Style . TEXT_DIM } ${ statusText } \n ${ UI . Style . TEXT_DIM } ${ url } ` )
282298 }
@@ -506,7 +522,7 @@ export const McpDebugCommand = cmd({
506522 return
507523 }
508524
509- if ( serverConfig . type !== "remote" ) {
525+ if ( ! isMcpRemote ( serverConfig ) ) {
510526 prompts . log . error ( `MCP server ${ serverName } is not a remote server` )
511527 prompts . outro ( "Done" )
512528 return
0 commit comments