Skip to content

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

Open
visitorise wants to merge 4 commits 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 4 commits 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.
@Blankeos

Copy link
Copy Markdown
Owner

Wow cool! I really appreciate the contribution. I'll be reviewing it when I become free this week. Thank you!

@Blankeos

Copy link
Copy Markdown
Owner

Pushed maintainer fixes directly to this branch (3922482, followed by merge commit 081e535 to bring it up to current main).

What changed:

  • Preserve and resolve provider.<id>.options.apiKey at request time, including {env:VAR} references; persisted auth still takes precedence.
  • Parse standard OpenCode custom-model fields (limit, capability flags, and modalities).
  • Make provider/model overlays non-destructive so omitted fields retain models.dev metadata.
  • Reapply custom providers after model-cache refreshes.
  • Avoid treating timeout-only provider entries as custom catalog providers.
  • Added regression coverage for credentials, auth precedence, capabilities/modalities, metadata preservation, and limits.

Validation:

  • cargo fmt --all -- --check
  • cargo check
  • Focused custom-provider/auth regression tests
  • Broad suite: 1,034 passed with four environment-sensitive tests excluded from the combined run; all four passed when rerun individually (the UI fixture requires the canonical repo cwd).

GitHub now reports the PR as mergeable with current main. Merge confidence: 9/10. The remaining unstable label is from a pending combined status with zero configured check runs, not a merge conflict or failing check.

@visitorise

Copy link
Copy Markdown
Author

Thank you for the quick fixes and test coverage!

I am happy to contribute to Crabcode. :)

Repository owner deleted a comment from carlo-bilby Jul 27, 2026
@Blankeos

Copy link
Copy Markdown
Owner

Follow-up pushed in d093451: configured OpenCode-compatible providers/models now appear and are selectable in /models without requiring /connect.

This also covers:

  • config edits invalidating the cached model dialog,
  • stale/effective catalog snapshots receiving the current config overlay,
  • configured providers coexisting with runtime providers such as Ollama,
  • deduplication of runtime + persistent model rows,
  • avoiding stale async model-load results being cached under a newer config signature.

Validation:

  • cargo fmt --all -- --check
  • cargo check
  • focused configured-provider/model-dialog/cache tests
  • broad suite: 1,039 passed
  • cwd-sensitive UI fixture passed separately from its expected repository cwd

Manual happy path:

  1. Add a custom provider/model with options.baseURL and options.apiKey/{env:...} to project crabcode.jsonc or opencode.jsonc.
  2. Start Crabcode in that project without running /connect.
  3. Run /models and confirm the configured provider/model is listed and selectable.
  4. Select it and send a prompt; confirm the request reaches the configured endpoint.
  5. Rename/add/remove a configured model, reopen /models, and confirm the list reflects the edit.

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.

2 participants