Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 13, 2026

Add MCP Gateway Configuration JSON Schema Validation

This PR adds JSON schema validation for MCP gateway configurations before they are sent to the gateway script, ensuring the compiler generates correct configurations. Validation only runs when the --validate flag is enabled.

Plan

  • Analyze codebase structure and MCP gateway flow
  • Embed MCP gateway schema from docs/public/schemas/mcp-gateway-config.schema.json
  • Create validation function using jsonschema library (similar to schema_validation.go)
  • Add validation call in RenderJSONMCPConfig before writing to script
  • Return internal compiler error if validation fails
  • Make validation conditional on --validate flag
  • Merge main branch (multiple times)
  • Format and lint code
  • Fix build failures (nil pointer dereference)
  • Test manually with sample workflows
  • Recompile all workflows
  • Run make agent-finish for full validation

Key Changes

  1. New file: pkg/workflow/mcp_gateway_schema_validation.go

    • Embed MCP gateway schema
    • Implement ValidateMCPGatewayConfig() function
    • Cache compiled schema for performance
  2. Update: pkg/workflow/mcp_renderer.go

    • Add SkipValidation flag to JSONMCPConfigOptions struct
    • Add validation before generating gateway config (only when --validate is enabled)
    • Return compiler error if validation fails
  3. Update: All engines (copilot, claude, codex, custom)

    • Pass SkipValidation flag through options
    • Flag is derived from compiler's skipValidation setting
    • Add nil checks to prevent crashes when workflowData is nil
  4. Update: pkg/workflow/compiler_types.go

    • Add CompilerSkipValidation field to WorkflowData to pass flag from compiler to engines

Behavior

  • Without --validate flag (default): Validation is skipped for backward compatibility
  • With --validate flag: MCP gateway configuration is validated against schema before being written
  • On validation failure: Returns an internal compiler error (indicates compiler bug)

Testing

  • ✅ All MCP-related tests pass
  • ✅ Workflows compile successfully with and without --validate flag
  • ✅ Build and lint pass
  • ✅ All 121 workflows recompiled successfully
Original prompt

Before writing the "start MCP gateway", the compiler should do a JSON schema validation of the configuration it generated using the MCP gateway json schema to ensure that the compiler is correct.

If not valid, return an internal compiler error.

The schema should be embedded as a resource, not downloaded.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
// This catches compiler bugs that generate invalid configurations
// Note: We need to clean up the indentation and substitute variables for validation
configForValidation := prepareConfigForValidation(generatedConfig)
if err := ValidateMCPGatewayConfig(configForValidation); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

@copilot should only happen with --validate flag enabled

- Add SkipValidation flag to JSONMCPConfigOptions struct
- Pass compiler's skipValidation flag through WorkflowData
- Validation only runs when --validate flag is enabled
- Embed MCP gateway schema in pkg/workflow/schemas/
- Update all engine implementations to pass SkipValidation flag
- Update tests to skip validation

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Add JSON schema validation for MCP gateway configuration Add JSON schema validation for MCP gateway configuration (--validate flag) Jan 13, 2026
Copilot AI requested a review from pelikhan January 13, 2026 16:02
@pelikhan
Copy link
Contributor

@copilot merge main, format, lint, review code

Copilot AI and others added 2 commits January 13, 2026 17:12
- Merge main branch
- Recompile all workflow files
- Fix staticcheck QF1012: Use WriteString instead of fmt.Fprintf for simple strings

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jan 13, 2026

@copilot merge main, format, lint, review code

Done:

  • ✅ Merged main branch (commit a15e266)
  • ✅ Formatted all code with make fmt
  • ✅ Linted code with make lint and fixed staticcheck issues
  • ✅ Recompiled all 121 workflow files

All changes in commit 1bb77e7.

@pelikhan
Copy link
Contributor

@copilot investigate the build failures and fix compiler so that the agentic workflows compile (fix the compiler)

- Add nil checks for workflowData before accessing CompilerSkipValidation
- Fix logic: skip validation when workflowData is nil OR flag is not set OR flag is true
- Update TestCustomEngineRenderMCPConfig to match new output format
- All MCP-related tests now pass

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jan 13, 2026

@copilot investigate the build failures and fix compiler so that the agentic workflows compile (fix the compiler)

Fixed the build failure. The issue was a nil pointer dereference when accessing workflowData.CompilerSkipValidation without checking if workflowData was nil first.

Changes in commit 2f8199f:

  • Added nil checks in all engines (copilot, claude, codex, custom) before accessing CompilerSkipValidation
  • Fixed logic: validation is skipped when workflowData is nil OR flag is not set OR flag is true
  • Updated TestCustomEngineRenderMCPConfig to match new output format

Verification:

  • ✅ All MCP-related tests pass
  • ✅ Workflows compile successfully with --validate flag
  • ✅ Build and lint pass

@pelikhan pelikhan marked this pull request as ready for review January 13, 2026 17:39
@pelikhan
Copy link
Contributor

@copilot merge main, format, lint go

Copilot AI and others added 2 commits January 13, 2026 17:44
- Merge latest changes from main branch
- Format all code with make fmt
- Lint Go code with make lint (all checks pass)
- Recompile all 121 workflow files

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jan 13, 2026

@copilot merge main, format, lint go

Done:

  • ✅ Merged main branch
  • ✅ Formatted all code with make fmt
  • ✅ Linted Go code with make lint (0 issues)
  • ✅ Recompiled all 121 workflow files

All changes in commit dfd554c.

@pelikhan
Copy link
Contributor

@copilot recompile workflows and report results if they all validate

@pelikhan pelikhan merged commit a8854f2 into main Jan 13, 2026
1 check failed
@pelikhan pelikhan deleted the copilot/validate-json-schema-configuration branch January 13, 2026 17:53
Copilot stopped work on behalf of pelikhan due to an error January 13, 2026 17:54
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