File tree Expand file tree Collapse file tree 1 file changed +32
-2
lines changed
Expand file tree Collapse file tree 1 file changed +32
-2
lines changed Original file line number Diff line number Diff line change @@ -221,8 +221,38 @@ export class McpHub {
221221 }
222222
223223 private async updateProjectMcpServers ( ) : Promise < void > {
224- await this . cleanupProjectMcpServers ( )
225- await this . initializeProjectMcpServers ( )
224+ try {
225+ const projectMcpPath = await this . getProjectMcpPath ( )
226+ if ( ! projectMcpPath ) return
227+
228+ const content = await fs . readFile ( projectMcpPath , "utf-8" )
229+ let config : any
230+
231+ try {
232+ config = JSON . parse ( content )
233+ } catch ( parseError ) {
234+ const errorMessage = t ( "common:errors.invalid_mcp_settings_syntax" )
235+ console . error ( errorMessage , parseError )
236+ vscode . window . showErrorMessage ( errorMessage )
237+ return
238+ }
239+
240+ // 验证配置结构
241+ const result = McpSettingsSchema . safeParse ( config )
242+ if ( result . success ) {
243+ // 使用与全局MCP相同的增量更新策略
244+ await this . updateServerConnections ( result . data . mcpServers || { } , "project" )
245+ } else {
246+ // 格式化验证错误以提供更好的用户反馈
247+ const errorMessages = result . error . errors
248+ . map ( ( err ) => `${ err . path . join ( "." ) } : ${ err . message } ` )
249+ . join ( "\n" )
250+ console . error ( "Invalid project MCP settings format:" , errorMessages )
251+ vscode . window . showErrorMessage ( t ( "common:errors.invalid_mcp_settings_validation" , { errorMessages } ) )
252+ }
253+ } catch ( error ) {
254+ this . showErrorMessage ( "Failed to update project MCP servers" , error )
255+ }
226256 }
227257
228258 private async cleanupProjectMcpServers ( ) : Promise < void > {
You can’t perform that action at this time.
0 commit comments