Skip to content

Conversation

@majiayu000
Copy link
Contributor

Summary

This PR fixes #7334

Changes

  • Add MCP configuration validation: The Validate() function now checks if MCP configuration (mcp.stdio and mcp.remote) contains valid JSON by calling MCPConfigFromYAML(), which will catch malformed JSON with missing commas or other syntax errors
  • Improve error reporting: Updated all validation callers in model_config_loader.go to properly capture and report validation errors instead of discarding them
  • Add comprehensive tests: Added test cases for both invalid (missing comma) and valid MCP configurations to ensure the validation works correctly

Problem

Previously, the Validate() function was not checking MCP configuration validity. This caused malformed JSON with missing commas to be silently accepted during validation, leading to runtime errors when the configuration was actually used.

Solution

The fix adds validation that unmarshals the MCP YAML/JSON configuration. If the JSON is malformed (e.g., missing commas), the unmarshaling will fail and return an error, which is now properly caught and reported to the user.


Generated with Claude Code

Fixes mudler#7334

The Validate() function was not checking if MCP configuration
(mcp.stdio and mcp.remote) contains valid JSON. This caused
malformed JSON with missing commas to be silently accepted.

Changes:
- Add MCP configuration validation to ModelConfig.Validate()
- Properly report validation errors instead of discarding them
- Add test cases for valid and invalid MCP configurations

The fix ensures that malformed JSON in MCP config sections
will now be caught and reported during validation.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Signed-off-by: majiayu000 <1835304752@qq.com>
@netlify
Copy link

netlify bot commented Dec 30, 2025

Deploy Preview for localai ready!

Name Link
🔨 Latest commit 3c7d81e
🔍 Latest deploy log https://app.netlify.com/projects/localai/deploys/695390adc2797b0008c6d573
😎 Deploy Preview https://deploy-preview-7787--localai.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@mudler mudler changed the title fix: Validate on model config does not correctly validate fix: propagate validation errors Dec 30, 2025
Copy link
Owner

@mudler mudler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking good!

@mudler mudler merged commit 8bd7143 into mudler:master Dec 30, 2025
11 checks passed
@majiayu000 majiayu000 deleted the fix-7334-validate-on-model-config-does--1230-1631 branch December 30, 2025 09:46
mudler pushed a commit to coffeerunhobby/LocalAI that referenced this pull request Jan 2, 2026
fix: validate MCP configuration in model config

Fixes mudler#7334

The Validate() function was not checking if MCP configuration
(mcp.stdio and mcp.remote) contains valid JSON. This caused
malformed JSON with missing commas to be silently accepted.

Changes:
- Add MCP configuration validation to ModelConfig.Validate()
- Properly report validation errors instead of discarding them
- Add test cases for valid and invalid MCP configurations

The fix ensures that malformed JSON in MCP config sections
will now be caught and reported during validation.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Signed-off-by: majiayu000 <1835304752@qq.com>
Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
@mudler mudler added the bug Something isn't working label Jan 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Validate on model config does not correctly validate

2 participants