Commit 5b20b1b
authored
[log] Add debug logging to MCP types schema normalization (#606)
## Summary
Enhanced `internal/mcp/types.go` with debug logging to improve
troubleshooting of MCP tool schema normalization.
## Changes Made
Added debug logger declaration and 7 strategic logging calls to the
`NormalizeInputSchema` function:
1. **Function entry logging** - Logs when schema normalization starts
for a tool
2. **Nil schema detection** - Logs when a backend provides no input
schema
3. **Type field analysis** - Logs schema structure (presence of type
field)
4. **Missing type handling** - Logs when schema lacks type field and
properties status
5. **Type normalization** - Logs when object type is added to schema
6. **Non-object type handling** - Logs when schema has non-object or
invalid type
7. **Properties validation** - Logs object schema structure (properties
and additionalProperties)
8. **Properties normalization** - Logs when empty properties are added
9. **Valid schema confirmation** - Logs when no normalization is needed
## Benefits
- Easier debugging of schema validation issues from backend MCP servers
- Visibility into which normalizations are applied and why
- Better understanding of tool registration flow
- No side effects in log arguments (all values already computed)
## Testing
- Added logger following project convention: `var log =
logger.New("mcp:types")`
- All logging statements use parameters already available in scope
- No expensive computations in log arguments
- Preserved existing file logger warnings for operational visibility
## Quality Checklist
- ✅ Exactly 1 file modified (focused, single-file PR)
- ✅ No test files modified
- ✅ Logger naming follows `pkg:filename` convention (`mcp:types`)
- ✅ Logger arguments don't compute anything or cause side effects
- ✅ Logging messages are meaningful and helpful for debugging
- ✅ No duplicate logging with existing logs
- ✅ Import statements properly ordered
- ✅ Preserved all existing file logger calls for operational logging
## Example Debug Output
With `DEBUG=mcp:*`, developers will see:
```````
mcp:types Normalizing input schema for tool: github-search
mcp:types Tool github-search schema analysis: hasType=true
mcp:types Tool github-search object type schema: hasProperties=true, hasAdditionalProperties=false
mcp:types Tool github-search schema is valid, no normalization needed
``````
Or when normalization is needed:
``````
mcp:types Normalizing input schema for tool: legacy-tool
mcp:types Tool legacy-tool has nil schema, applying default empty object schema
```````
> AI generated by [Go Logger
Enhancement](https://github.com/github/gh-aw-mcpg/actions/runs/21629700132)
<!-- gh-aw-workflow-id: go-logger -->1 file changed
Lines changed: 16 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
| 10 | + | |
9 | 11 | | |
10 | 12 | | |
11 | 13 | | |
| |||
59 | 61 | | |
60 | 62 | | |
61 | 63 | | |
| 64 | + | |
| 65 | + | |
62 | 66 | | |
63 | 67 | | |
64 | 68 | | |
| 69 | + | |
65 | 70 | | |
66 | 71 | | |
67 | 72 | | |
| |||
72 | 77 | | |
73 | 78 | | |
74 | 79 | | |
| 80 | + | |
| 81 | + | |
75 | 82 | | |
76 | 83 | | |
77 | 84 | | |
78 | 85 | | |
| 86 | + | |
79 | 87 | | |
80 | 88 | | |
81 | 89 | | |
| |||
84 | 92 | | |
85 | 93 | | |
86 | 94 | | |
| 95 | + | |
87 | 96 | | |
88 | 97 | | |
89 | 98 | | |
| 99 | + | |
90 | 100 | | |
91 | 101 | | |
92 | 102 | | |
| |||
96 | 106 | | |
97 | 107 | | |
98 | 108 | | |
| 109 | + | |
99 | 110 | | |
100 | 111 | | |
101 | 112 | | |
102 | 113 | | |
103 | 114 | | |
104 | 115 | | |
105 | 116 | | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
106 | 120 | | |
107 | 121 | | |
108 | 122 | | |
| |||
115 | 129 | | |
116 | 130 | | |
117 | 131 | | |
| 132 | + | |
118 | 133 | | |
119 | 134 | | |
120 | 135 | | |
| 136 | + | |
121 | 137 | | |
122 | 138 | | |
0 commit comments