Repository navigation
Consolidate hashing and environment helpers; cluster functions by responsibility - #16758
Conversation
…unctions Co-authored-by: copilot-swe-agent[bot] <[email protected]>
| // The returned path uses pathPrefix if provided, otherwise returns the actual filesystem path | ||
| func savePayload(baseDir, pathPrefix, sessionID, queryID string, payload []byte) (string, error) { | ||
| // Create directory structure: {baseDir}/{sessionID}/{queryID} | ||
| dir := filepath.Join(baseDir, sessionID, queryID) |
🔒 mcpg Read-Only Stress — defaultSurface coverage: MCP tool calls + proxied CLI (REST) + GraphQL mutations
Overall: INCONCLUSIVE
|
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are recorded for the helper-consolidation refactor.
No open issues 🎉
What changed in this PR
Refactors MCP Gateway’s internal helpers to reduce duplication and group functions by responsibility, addressing the mechanical cleanup in #16716.
Changes:
- Consolidates enclave-ID hashing, session log tokens, and agent-ID environment fallback logic.
- Extracts middleware, proxy, WASM, container-runtime, and utility helpers into focused files.
- Updates tests for token compatibility and environment handling while preserving existing formats and precedence.
| File | Description |
|---|---|
internal/util/number.go |
Houses existing numeric conversion logic. |
internal/util/hash.go |
Groups shared log-token hashing helpers. |
internal/util/format.go |
Retains string normalization; removes the session-token alias. |
internal/util/format_tool.go |
Isolates prefixed tool-name parsing. |
internal/util/format_time.go |
Groups time and duration formatting. |
internal/util/format_test.go |
Tests session tokens through the canonical helper. |
internal/server/tool_registry.go |
Migrates tool and prompt log tokens. |
internal/server/system_tools.go |
Migrates system-tool session log tokens. |
internal/server/session.go |
Uses canonical hashing for session diagnostics. |
internal/server/session_util_test.go |
Updates session-token assertions after alias removal. |
internal/server/session_auto_init.go |
Migrates automatic-initialization log tokens. |
internal/server/sdk_logging.go |
Migrates SDK request and error log tokens. |
internal/server/prompt_call.go |
Migrates prompt-response session logging. |
internal/server/middleware.go |
Uses canonical hashing for conversation trace identifiers. |
internal/server/http_helpers.go |
Migrates request-body diagnostic session tokens. |
internal/server/enclave_session.go |
Migrates enclave-session diagnostic tokens. |
internal/proxy/response_headers.go |
Houses response-header and artifact-download helpers. |
internal/proxy/handler.go |
Removes extracted response-shaping helpers. |
internal/middleware/url_audit.go |
Isolates observed URL-domain auditing. |
internal/middleware/schema.go |
Isolates recursive schema inference. |
internal/middleware/payload_storage.go |
Houses payload storage and path remapping. |
internal/middleware/jqschema.go |
Extracts unrelated helpers and migrates session tokens. |
internal/mcp/http_transport.go |
Migrates HTTP transport session log tokens. |
internal/mcp/connection_transport.go |
Migrates reconnection session logging. |
internal/launcher/log_helpers.go |
Migrates launch-related session log tokens. |
internal/launcher/launcher.go |
Migrates session-pool and startup diagnostics. |
internal/launcher/connection_pool.go |
Migrates connection-pool session log tokens. |
internal/guard/wasm_lifecycle.go |
Removes extracted cache and discovery responsibilities. |
internal/guard/wasm_discovery.go |
Groups WASM guard discovery helpers. |
internal/guard/wasm_cache.go |
Groups shared compilation-cache management. |
internal/enclavegithub/capability.go |
Reuses shared hashing for stable enclave identifiers. |
internal/enclavegithub/capability_test.go |
Adds fixed-token and component-boundary assertions. |
internal/config/validation_env.go |
Uses the canonical agent-ID environment fallback. |
internal/config/validation_env_test.go |
Covers both identifier variables and restores test environments. |
internal/config/container_runtime.go |
Houses runtime argument parsing and its option table. |
internal/config/config_core.go |
Removes the relocated runtime parsing helpers. |
Review effort: Max (adaptive)
Duplicated hashing and agent-ID fallback logic obscured shared contracts, while several files mixed unrelated responsibilities.
Shared helpers
util.HashForLogfor enclave IDs, preserving existing tokens.FormatSessionIDForLogwithHashIdentifierForLog.Function organization
Behavior preserved