Skip to content

[log] Add debug logging to MCP types schema normalization#606

Merged
lpcox merged 1 commit intomainfrom
log/mcp-types-debug-logging-9b7c624d47174726
Feb 3, 2026
Merged

[log] Add debug logging to MCP types schema normalization#606
lpcox merged 1 commit intomainfrom
log/mcp-types-debug-logging-9b7c624d47174726

Conversation

@github-actions
Copy link
Contributor

@github-actions github-actions bot commented Feb 3, 2026

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

Enhanced internal/mcp/types.go with debug logging for better troubleshooting:
- Added logger declaration: var log = logger.New("mcp:types")
- Added 7 strategic logging calls to NormalizeInputSchema function
- Logs schema validation decisions and normalization actions
- All log arguments have no side effects (values already in scope)
- Follows project logging guidelines from AGENTS.md
@github-actions github-actions bot added automation enhancement New feature or request labels Feb 3, 2026
@lpcox lpcox marked this pull request as ready for review February 3, 2026 17:04
Copilot AI review requested due to automatic review settings February 3, 2026 17:04
@lpcox lpcox merged commit 5b20b1b into main Feb 3, 2026
3 checks passed
@lpcox lpcox deleted the log/mcp-types-debug-logging-9b7c624d47174726 branch February 3, 2026 17:05
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR enhances the MCP types schema normalization function with debug logging to improve troubleshooting capabilities. The changes add a debug logger instance and 9 strategic log statements throughout the NormalizeInputSchema function to provide visibility into schema validation and normalization operations.

Changes:

  • Added debug logger declaration following the project convention (var log = logger.New("mcp:types"))
  • Added 9 debug logging statements at key decision points in the schema normalization flow
  • No changes to function behavior or logic - purely additive logging
Comments suppressed due to low confidence (2)

internal/mcp/types.go:119

  • Remove trailing whitespace from this blank line. This improves consistency with Go formatting standards.
    internal/mcp/types.go:65
  • Remove trailing whitespace from this blank line. This improves consistency with Go formatting standards.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

typeVal, hasType := schema["type"]

log.Printf("Tool %s schema analysis: hasType=%v", toolName, hasType)

Copy link

Copilot AI Feb 3, 2026

Choose a reason for hiding this comment

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

Remove trailing whitespace from this blank line. This improves consistency with Go formatting standards.

This issue also appears in the following locations of the same file:

  • line 119
  • line 65

Copilot uses AI. Check for mistakes.
// 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)
Copy link

Copilot AI Feb 3, 2026

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.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

automation enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant