Skip to content

feat(config): add custom provider configuration support and mcp error screen broken fix#5

Open
visitorise wants to merge 1 commit into
Blankeos:mainfrom
visitorise:feat/custom-providder-config_and_supress-mcp-output
Open

feat(config): add custom provider configuration support and mcp error screen broken fix#5
visitorise wants to merge 1 commit into
Blankeos:mainfrom
visitorise:feat/custom-providder-config_and_supress-mcp-output

Conversation

@visitorise

Copy link
Copy Markdown

Add Custom Provider Configuration and Fix Startup Issues

Summary

This PR introduces three key improvements:

  1. Custom provider configuration — Users can now define custom AI providers in crabcode.json under the "provider" section (e.g., local llama.cpp, Ollama instances). These overlay on top of existing discovery data from models.dev and extensions.
  2. Config file parsing fix.json config files are now parsed with json5 for lenient handling (trailing commas, etc.), fixing the issue where a malformed config prevented the entire app from loading.
  3. MCP stderr suppression — Local MCP server child processes no longer leak stderr output (e.g., react-devtools-bridge port conflicts) into the terminal during startup.

Files Changed

  • src/config/configuration.rs
    Added CustomModelConfig, CustomProviderConfig structs, parse_custom_providers() function.
    custom_providers field on MergedConfig.
    simplified load_config_value() to use json5 for all .json files.

  • src/config/mod.rs
    Re-exported CustomProviderConfig, CustomModelConfig

  • src/model/discovery.rs
    Added custom_providers: Option<HashMap<...>> field to Discovery.
    new_with_custom() constructor; overlay logic in fetch_providers(). Discovery::new()` now auto-loads custom providers from config.

  • src/app.rs, App::new_with_model_override()
    passes custom providers via Discovery::new_with_custom(Some(...)).

  • src/mcp.rs
    Replaced TokioChildProcess::new() with builder().stderr(Stdio::null()).spawn() for local MCP server spawning, suppressing child process stderr output.

Custom Provider Config Format

{
  "provider": {
    "llama_cpp": {
      "name": "llama.cpp",
      "npm": "@ai-sdk/openai-compatible",
      "options": {
        "baseURL": "http://127.0.0.1:11400/v1"
      },
      "models": {
        "my-model": {
          "name": "My Model Display Name",
          "contextWindow": 262140,
          "maxTokens": 32000
        }
      }
    }
  }

Note: This format is fully compatible with OpenCode's custom provider/model configuration. The same JSON structure and field names (name, npm, options.baseURL, models) are used, so any config written for OpenCode works directly in crabcode without modification.

Overlay Priority Order

Custom providers are overlaid after all other discovery sources:

models.dev API → persistent extensions (catalog_extensions.json)
             → runtime extensions (Ollama CLI)
             → user custom providers

This means models.dev data and extension-provided models are preserved; user config only adds or overrides.

Testing

  • cargo build — succeeds
  • cargo test — 1009 passed, 4 pre-existing failures (unrelated: Ollama cache lock, chat diff rendering)
  • Verified custom providers load from real crabcode.json and appear in /model dialog

- Add CustomModelConfig and CustomProviderConfig structs for user-defined providers
- Implement parse_custom_providers() to extract provider config from crabcode.json
- Add custom_providers field to MergedConfig and Discovery struct
- Implement overlay logic in fetch_providers() with priority: models.dev → extensions → custom
- Update App::new_with_model_override() to pass custom providers via new_with_custom()
- Fix load_config_value() to use json5 for all .json files (lenient parsing)
- Suppress MCP child process stderr output using TokioChildProcess::builder().stderr(Stdio::null())

Custom provider format is compatible with OpenCode's configuration.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant