-
Notifications
You must be signed in to change notification settings - Fork 4
[log] Add debug logging to MCP types schema normalization #606
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+16
−0
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,8 @@ import ( | |
| "github.com/github/gh-aw-mcpg/internal/logger" | ||
| ) | ||
|
|
||
| var log = logger.New("mcp:types") | ||
|
|
||
| // Request represents a JSON-RPC 2.0 request | ||
| type Request struct { | ||
| JSONRPC string `json:"jsonrpc"` | ||
|
|
@@ -59,9 +61,12 @@ type ContentItem struct { | |
| // but is missing the required "properties" field, we add an empty properties | ||
| // object to make it valid per JSON Schema standards. | ||
| func NormalizeInputSchema(schema map[string]interface{}, toolName string) map[string]interface{} { | ||
| log.Printf("Normalizing input schema for tool: %s", toolName) | ||
|
|
||
| // If backend didn't provide a schema, use a default empty object schema | ||
| // This allows the tool to be registered and clients will see it accepts any parameters | ||
| if schema == nil { | ||
| log.Printf("Tool %s has nil schema, applying default empty object schema", toolName) | ||
| logger.LogWarn("backend", "Tool schema normalized: %s - backend provided no inputSchema, using default empty object schema", toolName) | ||
| return map[string]interface{}{ | ||
| "type": "object", | ||
|
|
@@ -72,10 +77,13 @@ func NormalizeInputSchema(schema map[string]interface{}, toolName string) map[st | |
| // Check if this is an object type schema | ||
| typeVal, hasType := schema["type"] | ||
|
|
||
| log.Printf("Tool %s schema analysis: hasType=%v", toolName, hasType) | ||
|
|
||
|
||
| // If schema has no type but has properties, it's implicitly an object type | ||
| // The MCP SDK requires "type": "object" to be present, so add it | ||
| if !hasType { | ||
| _, hasProperties := schema["properties"] | ||
| log.Printf("Tool %s has no type field, hasProperties=%v", toolName, hasProperties) | ||
| if hasProperties { | ||
| logger.LogWarn("backend", "Tool schema normalized: %s - added 'type': 'object' to schema with properties", toolName) | ||
| // Create a copy of the schema to avoid modifying the original | ||
|
|
@@ -84,9 +92,11 @@ func NormalizeInputSchema(schema map[string]interface{}, toolName string) map[st | |
| normalized[k] = v | ||
| } | ||
| normalized["type"] = "object" | ||
| log.Printf("Tool %s schema normalized: added object type", toolName) | ||
| return normalized | ||
| } | ||
| // Schema without type and without properties - assume it's an empty object schema | ||
| log.Printf("Tool %s has no type and no properties, using empty object schema", toolName) | ||
| logger.LogWarn("backend", "Tool schema normalized: %s - schema missing type, assuming empty object schema", toolName) | ||
| return map[string]interface{}{ | ||
| "type": "object", | ||
|
|
@@ -96,13 +106,17 @@ func NormalizeInputSchema(schema map[string]interface{}, toolName string) map[st | |
|
|
||
| typeStr, isString := typeVal.(string) | ||
| if !isString || typeStr != "object" { | ||
| log.Printf("Tool %s has non-object type or invalid type value, returning schema as-is", toolName) | ||
| return schema | ||
| } | ||
|
|
||
| // Check if properties field exists | ||
| _, hasProperties := schema["properties"] | ||
| _, hasAdditionalProperties := schema["additionalProperties"] | ||
|
|
||
| log.Printf("Tool %s object type schema: hasProperties=%v, hasAdditionalProperties=%v", | ||
| toolName, hasProperties, hasAdditionalProperties) | ||
|
|
||
| // If it's an object type but missing both properties and additionalProperties, | ||
| // add an empty properties object to make it valid | ||
| if !hasProperties && !hasAdditionalProperties { | ||
|
|
@@ -115,8 +129,10 @@ func NormalizeInputSchema(schema map[string]interface{}, toolName string) map[st | |
| } | ||
| normalized["properties"] = map[string]interface{}{} | ||
|
|
||
| log.Printf("Tool %s schema normalized: added empty properties field", toolName) | ||
| return normalized | ||
| } | ||
|
|
||
| log.Printf("Tool %s schema is valid, no normalization needed", toolName) | ||
| return schema | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PR description states "7 strategic logging calls" but there are actually 9 log.Printf calls in the NormalizeInputSchema function (lines 64, 69, 80, 86, 95, 99, 109, 117-118, 132, and 136). Consider updating the PR description to reflect the accurate count.