@@ -1098,6 +1098,37 @@ def _get_repos_config(self) -> list[dict]:
10981098 return []
10991099 return []
11001100
1101+ def _filter_mcp_servers (self , servers : dict ) -> dict :
1102+ """Filter MCP servers to only allow http and sse types.
1103+
1104+ Args:
1105+ servers: Dictionary of MCP server configurations
1106+
1107+ Returns:
1108+ Filtered dictionary containing only allowed server types
1109+ """
1110+ allowed_servers = {}
1111+ allowed_types = {'http' , 'sse' }
1112+
1113+ for name , server_config in servers .items ():
1114+ if not isinstance (server_config , dict ):
1115+ logging .warning (f"MCP server '{ name } ' has invalid configuration format, skipping" )
1116+ continue
1117+
1118+ server_type = server_config .get ('type' , '' ).lower ()
1119+
1120+ if server_type in allowed_types :
1121+ url = server_config .get ('url' , '' )
1122+ if url :
1123+ allowed_servers [name ] = server_config
1124+ logging .info (f"MCP server '{ name } ' allowed (type: { server_type } , url: { url } )" )
1125+ else :
1126+ logging .warning (f"MCP server '{ name } ' rejected: missing 'url' field" )
1127+ else :
1128+ logging .warning (f"MCP server '{ name } ' rejected: type '{ server_type } ' not allowed" )
1129+
1130+ return allowed_servers
1131+
11011132 def _load_mcp_config (self , cwd_path : str ) -> dict | None :
11021133 """Load MCP server configuration from .mcp.json file in the workspace.
11031134
@@ -1106,6 +1137,8 @@ def _load_mcp_config(self, cwd_path: str) -> dict | None:
11061137 2. cwd_path/.mcp.json (main working directory)
11071138 3. workspace root/.mcp.json (for multi-repo setups)
11081139
1140+ Only allows http and sse type MCP servers.
1141+
11091142 Returns the parsed MCP servers configuration dict, or None if not found.
11101143 """
11111144 try :
@@ -1122,8 +1155,13 @@ def _load_mcp_config(self, cwd_path: str) -> dict | None:
11221155 logging .info (f"Loading MCP config from MCP_CONFIG_PATH: { mcp_file } " )
11231156 with open (mcp_file , 'r' ) as f :
11241157 config = _json .load (f )
1125- logging .info (f"MCP servers loaded: { list (config .get ('mcpServers' , {}).keys ())} " )
1126- return config .get ('mcpServers' )
1158+ all_servers = config .get ('mcpServers' , {})
1159+ filtered_servers = self ._filter_mcp_servers (all_servers )
1160+ if filtered_servers :
1161+ logging .info (f"MCP servers loaded: { list (filtered_servers .keys ())} " )
1162+ return filtered_servers
1163+ logging .info ("No valid MCP servers found after filtering" )
1164+ return None
11271165 else :
11281166 logging .warning (f"MCP_CONFIG_PATH specified but file not found: { explicit_path } " )
11291167
@@ -1133,9 +1171,13 @@ def _load_mcp_config(self, cwd_path: str) -> dict | None:
11331171 logging .info (f"Found .mcp.json in working directory: { mcp_file } " )
11341172 with open (mcp_file , 'r' ) as f :
11351173 config = _json .load (f )
1136- server_names = list (config .get ('mcpServers' , {}).keys ())
1137- logging .info (f"MCP servers loaded from { mcp_file } : { server_names } " )
1138- return config .get ('mcpServers' )
1174+ all_servers = config .get ('mcpServers' , {})
1175+ filtered_servers = self ._filter_mcp_servers (all_servers )
1176+ if filtered_servers :
1177+ logging .info (f"MCP servers loaded from { mcp_file } : { list (filtered_servers .keys ())} " )
1178+ return filtered_servers
1179+ logging .info ("No valid MCP servers found after filtering" )
1180+ return None
11391181
11401182 # Option 3: Look in workspace root (for multi-repo setups)
11411183 if self .context and self .context .workspace_path != cwd_path :
@@ -1144,9 +1186,13 @@ def _load_mcp_config(self, cwd_path: str) -> dict | None:
11441186 logging .info (f"Found .mcp.json in workspace root: { workspace_mcp_file } " )
11451187 with open (workspace_mcp_file , 'r' ) as f :
11461188 config = _json .load (f )
1147- server_names = list (config .get ('mcpServers' , {}).keys ())
1148- logging .info (f"MCP servers loaded from { workspace_mcp_file } : { server_names } " )
1149- return config .get ('mcpServers' )
1189+ all_servers = config .get ('mcpServers' , {})
1190+ filtered_servers = self ._filter_mcp_servers (all_servers )
1191+ if filtered_servers :
1192+ logging .info (f"MCP servers loaded from { workspace_mcp_file } : { list (filtered_servers .keys ())} " )
1193+ return filtered_servers
1194+ logging .info ("No valid MCP servers found after filtering" )
1195+ return None
11501196
11511197 logging .info ("No .mcp.json file found in any search location" )
11521198 return None
0 commit comments