From e963d326abbd1fd2a28ced660fce93bf2f0f3d5e Mon Sep 17 00:00:00 2001 From: johnnyjoygh Date: Fri, 4 Sep 2026 08:19:44 +0800 Subject: [PATCH] chore(mcp): satisfy revive lint rules --- server/router/mcp/catalog_test.go | 2 ++ server/router/mcp/openapi.go | 2 ++ server/router/mcp/openapi_test.go | 12 ++++++++---- server/router/mcp/service.go | 2 ++ server/router/mcp/service_test.go | 3 ++- 5 files changed, 16 insertions(+), 5 deletions(-) diff --git a/server/router/mcp/catalog_test.go b/server/router/mcp/catalog_test.go index 09c346f3..09997367 100644 --- a/server/router/mcp/catalog_test.go +++ b/server/router/mcp/catalog_test.go @@ -424,6 +424,8 @@ func TestBuildCuratedToolsUseStandardSchemaFormats(t *testing.T) { for index, item := range typed { collectFormats(t, tool, path+"/"+strconv.Itoa(index), item) } + default: + // Scalars carry no nested schemas. } } diff --git a/server/router/mcp/openapi.go b/server/router/mcp/openapi.go index ca8ac7da..89aabf46 100644 --- a/server/router/mcp/openapi.go +++ b/server/router/mcp/openapi.go @@ -208,6 +208,8 @@ func normalizeSchemaFormat(schema map[string]any) { case "bytes": delete(schema, "format") schema["contentEncoding"] = "base64" + default: + // Standard JSON Schema formats (date-time, int64, ...) pass through. } } diff --git a/server/router/mcp/openapi_test.go b/server/router/mcp/openapi_test.go index 19414766..59424ce9 100644 --- a/server/router/mcp/openapi_test.go +++ b/server/router/mcp/openapi_test.go @@ -211,13 +211,16 @@ func TestResolveSchemaRefNormalizesNonStandardFormats(t *testing.T) { schema, err := resolveSchemaRef(spec, jsonSchema{"$ref": "#/components/schemas/Attachment"}) require.NoError(t, err) - properties := schema["properties"].(map[string]any) + properties, ok := schema["properties"].(map[string]any) + require.True(t, ok) - state := properties["state"].(map[string]any) + state, ok := properties["state"].(map[string]any) + require.True(t, ok) require.NotContains(t, state, "format") require.Equal(t, []any{"NORMAL", "ARCHIVED"}, state["enum"]) - content := properties["content"].(map[string]any) + content, ok := properties["content"].(map[string]any) + require.True(t, ok) require.NotContains(t, content, "format") require.Equal(t, "base64", content["contentEncoding"]) @@ -229,7 +232,8 @@ func TestResolveSchemaRefNormalizesNonStandardFormats(t *testing.T) { func TestSanitizeSchemaValueDoesNotMutateInput(t *testing.T) { original := jsonSchema{"type": "string", "format": "enum", "items": map[string]any{"format": "bytes"}} - sanitized := sanitizeSchemaValue(original).(map[string]any) + sanitized, ok := sanitizeSchemaValue(original).(map[string]any) + require.True(t, ok) require.NotContains(t, sanitized, "format") require.Equal(t, "base64", sanitized["items"].(map[string]any)["contentEncoding"]) diff --git a/server/router/mcp/service.go b/server/router/mcp/service.go index 554c6102..6721ba97 100644 --- a/server/router/mcp/service.go +++ b/server/router/mcp/service.go @@ -111,6 +111,8 @@ func catalogCacheMiddleware(next sdkmcp.MethodHandler) sdkmcp.MethodHandler { typed.TTLMs = int(toolCatalogTTL.Milliseconds()) case *sdkmcp.DiscoverResult: typed.TTLMs = int(toolCatalogTTL.Milliseconds()) + default: + // Other results carry no catalog TTL. } return result, nil } diff --git a/server/router/mcp/service_test.go b/server/router/mcp/service_test.go index 249a429b..839eca11 100644 --- a/server/router/mcp/service_test.go +++ b/server/router/mcp/service_test.go @@ -568,7 +568,8 @@ func TestMCPRequestBodyLimitMatchesAPI(t *testing.T) { echoServer.POST("/api/v1/attachments", func(c *echo.Context) error { body := map[string]any{} require.NoError(t, json.NewDecoder(c.Request().Body).Decode(&body)) - content, _ := body["content"].(string) + content, ok := body["content"].(string) + require.True(t, ok) receivedBytes = len(content) return c.JSON(http.StatusOK, map[string]any{"name": "attachments/1"}) })