Skip to content

[WIP] Fix JSON schema or generated code for MCP server payload#11933

Closed
Copilot wants to merge 3 commits intomainfrom
copilot/fix-json-schema-validation-again
Closed

[WIP] Fix JSON schema or generated code for MCP server payload#11933
Copilot wants to merge 3 commits intomainfrom
copilot/fix-json-schema-validation-again

Conversation

Copy link
Contributor

Copilot AI commented Jan 26, 2026

Fix MCP Gateway Configuration Validation with Uninterpolated Expressions

Problem

The MCP gateway configuration validation failed when GitHub Actions expressions and backslash-escaped shell variables were present in the generated JSON. The error "invalid character '$' in string escape code" occurred because:

  1. Backslash-escaped variables like \${GITHUB_TOKEN} are invalid JSON escape sequences
  2. GitHub Actions expressions like ${{ github.workspace }} need to be replaced with sample values for validation
  3. The prepareConfigForValidation function didn't handle all variable patterns

Solution

Updated prepareConfigForValidation in pkg/workflow/mcp_renderer.go to handle all patterns:

  • Analyze all patterns in the generated config
  • Add replacements for backslash-escaped variables (\${...})
    • \${GITHUB_TOKEN}, \${GITHUB_MCP_SERVER_TOKEN}, \${GH_AW_SAFE_INPUTS_API_KEY}, \${GH_AW_SAFE_OUTPUTS_API_KEY}
  • Add replacements for GitHub Actions expressions (${{ ... }})
    • ${{ github.workspace }}/workspace
  • Add replacements for unescaped shell variables
    • $GH_AW_SAFE_INPUTS_PORT, $GH_AW_SAFE_OUTPUTS_PORT
  • Test the fix with the smoke-copilot workflow - validation error resolved
  • Run unit tests - all pass
  • Run format and lint - all pass
  • Final validation - MCP gateway config validation now works correctly

Testing

  • ✅ Compilation with --validate flag no longer shows MCP gateway JSON errors
  • ✅ Generated workflow files still contain correct uninterpolated expressions
  • ✅ All unit tests pass
  • ✅ Code formatting and linting pass

Note: Some integration tests related to action pins failed, but these are unrelated to the MCP gateway configuration validation fix.

Original prompt

Review validation of generated mcp server payload and fix the JSON schema or generated code. You need to take into account uninterpolated expressions:

@pelikhan ➜ /workspaces/gh-aw (main) $ ./gh-aw compile smoke-copilot --validate
⚠ Using experimental feature: safe-inputs
⚠ Generated MCP gateway configuration is not valid JSON: invalid character '$' in string escape code
⚠ Invalid workflow YAML written to: .github/workflows/smoke-copilot.invalid.yml
✗ .github/workflows/smoke-copilot.md:1:1: error: workflow schema validation failed: GitHub Actions schema validation failed: jsonschema validation failed with 'https://json.schemastore.org/github-workflow.json#'

  • at '/jobs/conclusion': 'oneOf' failed, none matched
    • at '/jobs/conclusion/steps/0/uses': got null, want string
    • at '/jobs/conclusion': validation failed
      • at '/jobs/conclusion': missing property 'uses'
      • at '/jobs/conclusion': additional properties 'outputs', 'steps', 'runs-on' not allowed
  • at '/jobs/detection': 'oneOf' failed, none matched
    • at '/jobs/detection/steps/0/uses': got null, want string
    • at '/jobs/detection': validation failed
      • at '/jobs/detection': missing property 'uses'
      • at '/jobs/detection': additional properties 'runs-on', 'timeout-minutes', 'outputs', 'steps' not allowed
  • at '/jobs/pre_activation': 'oneOf' failed, none matched
    • at '/jobs/pre_activation/steps/0/uses': got null, want string
    • at '/jobs/pre_activation': validation failed
      • at '/jobs/pre_activation': missing property 'uses'
      • at '/jobs/pre_activation': additional properties 'runs-on', 'outputs', 'steps' not allowed
  • at '/jobs/safe_outputs': 'oneOf' failed, none matched
    • at '/jobs/safe_outputs/steps/0/uses': got null, want string
    • at '/jobs/safe_outputs': validation failed
      • at '/jobs/safe_outputs': missing property 'uses'
      • at '/jobs/safe_outputs': additional properties 'env', 'outputs', 'steps', 'runs-on', 'timeout-minutes' not allowed
  • at '/jobs/update_cache_memory': 'oneOf' failed, none matched
    • at '/jobs/update_cache_memory/steps/0/uses': got null, want string
    • at '/jobs/update_cache_memory': validation failed
      • at '/jobs/update_cache_memory': missing property 'uses'
      • at '/jobs/update_cache_memory': additional properties 'runs-on', 'steps' not allowed
  • at '/jobs/activation': 'oneOf' failed, none matched
    • at '/jobs/activation/steps/0/uses': got null, want string
    • at '/jobs/activation': validation failed
      • at '/jobs/activation': missing property 'uses'
      • at '/jobs/activation': additional properties 'outputs', 'steps', 'runs-on' not allowed
  • at '/jobs/agent': 'oneOf' failed, none matched
    • at '/jobs/agent': validation failed
      • at '/jobs/agent/steps/0/uses': got null, want string
      • at '/jobs/agent/steps/2/uses': got null, want string
    • at '/jobs/agent': validation failed
      • at '/jobs/agent': missing property 'uses'
      • at '/jobs/agent': additional properties 'runs-on', 'env', 'outputs', 'steps' not allowed

⚠ Engine 'copilot' does not support the web-search tool. See https://githubnext.github.io/gh-aw/guides/web-search/


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits January 26, 2026 20:13
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
@pelikhan pelikhan closed this Jan 26, 2026
Copilot AI requested a review from pelikhan January 26, 2026 20:23
Copilot stopped work on behalf of pelikhan due to an error January 26, 2026 20:23
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