Skip to content

Add schema normalization middleware for invalid tool definitions#283

Merged
lpcox merged 6 commits intomainfrom
copilot/add-inputschema-normalization-middleware
Jan 16, 2026
Merged

Add schema normalization middleware for invalid tool definitions#283
lpcox merged 6 commits intomainfrom
copilot/add-inputschema-normalization-middleware

Conversation

Copy link
Contributor

Copilot AI commented Jan 16, 2026

Some MCP servers return invalid JSON schemas for tool definitions. GitHub MCP Server v0.28.1's get_commit tool declares "type": "object" but omits the required properties field, causing downstream validation failures per JSON Schema standards.

Changes

  • internal/mcp/schema_normalizer.go: New middleware that detects object schemas missing both properties and additionalProperties, adds empty properties map to satisfy validators
  • internal/server/unified.go: Integrated normalization in registerToolsFromBackend() before storing tool metadata
  • Tests: 11 unit tests covering edge cases, 2 integration tests verifying end-to-end behavior

Example

Invalid schema from backend:

{
  "name": "get_commit",
  "inputSchema": {
    "type": "object"
  }
}

Normalized automatically to:

{
  "name": "get_commit", 
  "inputSchema": {
    "type": "object",
    "properties": {}
  }
}

The middleware creates a copy to avoid mutating backend data and logs when normalization occurs for debugging.

Original prompt

Add a middleware to the tool calling that allows to normalize the inpuSchema of tool definition.

Some tools return sloppy JSON schema which leads to tool violation downstream because the schema is invalid.

See this error happening currently with the GitHub-MCP-server.

Install a middleware that checks the inputSchema, looks for known error patterns like the error below and patches the format.

The middleware should be in a separate file.


Based on the error message from the workflow logs, the get_commit tool schema validation fails because:

Error: Invalid schema for function 'github-get_commit': In context=(), object schema missing properties

Root Cause: The get_commit tool in GitHub MCP Server v0.28.1 has an incomplete inputSchema:

It declares "type": "object"
But is missing the required properties field that defines the object's structure
Copilot CLI's strict schema validator rejects this as invalid
Why This Fails:
According to JSON Schema standards, when type: "object" is specified, validators expect:

A properties field defining the object properties, OR
An additionalProperties field if accepting arbitrary properties
Without either, the schema is considered malformed.

Working Tool Example (like issue_read):

{
"inputSchema": {
"type": "object",
"properties": {
"owner": { "type": "string" },
"repo": { "type": "string" }
},
"required": ["owner", "repo"]
}
}
Broken Schema (get_commit):

{
"inputSchema": {
"type": "object"
// Missing: "properties": { ... }
}
}
This is a bug in the GitHub MCP Server v0.28.1 that should be reported upstream. The fix in commit c0a78c2 works around this by using the GITHUB_TOOLS environment variable to filter out the problematic tool until it's fixed.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 5 commits January 16, 2026 05:15
- Created mcp.NormalizeInputSchema() to fix broken object schemas
- Fixes issue where object schemas lack properties field
- Integrated middleware into unified.go tool registration
- Added comprehensive unit tests for normalization logic
- Added integration tests to verify end-to-end behavior

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Consolidated three logging statements into a single structured logger call for consistency with the codebase.

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Changed required field from []string to []interface{} for consistency with JSON schema handling.

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Add middleware to normalize inputSchema of tool definition Add schema normalization middleware for invalid tool definitions Jan 16, 2026
Copilot AI requested a review from pelikhan January 16, 2026 05:22
@lpcox lpcox marked this pull request as ready for review January 16, 2026 06:03
@lpcox lpcox merged commit 7e72a52 into main Jan 16, 2026
3 checks passed
@lpcox lpcox deleted the copilot/add-inputschema-normalization-middleware branch January 16, 2026 06:03
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.

3 participants