Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/logger/slog_adapter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ func TestSlogHandler_Handle_EdgeCases(t *testing.T) {
handler := NewSlogHandler(logger)

// Enabled should work with nil context (underscore param means it's ignored)
enabled := handler.Enabled(nil, slog.LevelInfo)
enabled := handler.Enabled(context.TODO(), slog.LevelInfo)
assert.Equal(logger.Enabled(), enabled)
})
}
28 changes: 14 additions & 14 deletions internal/mcp/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/github/gh-aw-mcpg/internal/logger"
)

var log = logger.New("mcp:types")
var logTypes = logger.New("mcp:types")

// Request represents a JSON-RPC 2.0 request
type Request struct {
Expand Down Expand Up @@ -61,12 +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)
logTypes.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)
logTypes.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",
Expand All @@ -77,13 +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)
logTypes.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)
logTypes.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
Expand All @@ -92,11 +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)
logTypes.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)
logTypes.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",
Expand All @@ -106,17 +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)
logTypes.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",
logTypes.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 {
Expand All @@ -129,10 +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)
logTypes.Printf("Tool %s schema normalized: added empty properties field", toolName)
return normalized
}

log.Printf("Tool %s schema is valid, no normalization needed", toolName)
logTypes.Printf("Tool %s schema is valid, no normalization needed", toolName)
return schema
}
Loading