Skip to content

Auto-discovery fails to work if one or more client config files are broken #347

Open
@rdimitrov

Description

@rdimitrov

I got the following error message when doing the auto-discovery command -

➜  toolhive git:(main) thv config auto-discovery true    
2:14PM WRN failed to validate config file: %!w(*errors.errorString=&{file does not exist: /Users/dimitrovr/Library/Application Support/Code - Insiders/User/settings.json})
2:14PM WRN failed to validate config file: %!w(*errors.errorString=&{file does not exist: /Users/dimitrovr/.cursor/mcp.json})
Warning: Failed to add running MCPs to client roo-code: failed to find client configurations: failed to validate config file format: failed to parse JSON for file /Users/dimitrovr/Library/Application Support/Code/User/settings.json: hujson: line 46, column 1: parsing comment: unexpected EOF
Auto-discovery of MCP clients enabled

Findings:

  • Validating if the config file is a valid json causes the whole processing to exit but wrongfully shows a positive message at the end that the setting is enabled. Instead I think we should skip the failing ones, present them to the user, but still try to update the rest.
  • I think we can avoid being so verbose if a client config file is missing.

Quick experiment:

For the sake of the experiment I did a quick patch that continues on json validation failure and I think this unleashed another bug which is we should process/take into account only the clients that are currently registered. What I mean is from the logs below we say we are updating the config files for all clients we were able to find whereas we only have the roo-code registered

➜  toolhive git:(main) ✗ thv rm fetch  
2:40PM INF Removing container fetch...
2:40PM INF Deleted run configuration for fetch
2:40PM INF Saved state for fetch removed
2:40PM INF Container fetch removed
2:40PM WRN failed to validate config file: %!w(*errors.errorString=&{file does not exist: /Users/dimitrovr/Library/Application Support/Code - Insiders/User/settings.json})
2:40PM WRN failed to validate config file: %!w(*errors.errorString=&{file does not exist: /Users/dimitrovr/.cursor/mcp.json})
2:40PM INF Removing MCP server from client configuration: /Users/dimitrovr/Library/Application Support/Code/User/globalStorage/rooveterinaryinc.roo-cline/settings/mcp_settings.json
2:40PM INF Successfully removed the MCPServer fetch from the client config file
2:40PM INF Successfully removed MCP server from client configuration: /Users/dimitrovr/Library/Application Support/Code/User/globalStorage/rooveterinaryinc.roo-cline/settings/mcp_settings.json
2:40PM INF Removing MCP server from client configuration: /Users/dimitrovr/Library/Application Support/Code/User/settings.json
2:40PM INF Successfully removed the MCPServer fetch from the client config file
2:40PM INF Successfully removed MCP server from client configuration: /Users/dimitrovr/Library/Application Support/Code/User/settings.json
2:40PM INF Removing MCP server from client configuration: /Users/dimitrovr/.claude.json
2:40PM INF Successfully removed the MCPServer fetch from the client config file
2:40PM INF Successfully removed MCP server from client configuration: /Users/dimitrovr/.claude.json
2:40PM INF Client configurations for fetch removed
➜  toolhive git:(main) ✗ thv config list-registered-clients
Registered clients:
  - roo-code

Metadata

Metadata

Assignees

No one assigned

    Labels

    p1Medium

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions