Consolidate MCP metrics helpers and add regression tests#375
Merged
calvadev merged 1 commit intoshopstr-eng:mainfrom Apr 9, 2026
Merged
Consolidate MCP metrics helpers and add regression tests#375calvadev merged 1 commit intoshopstr-eng:mainfrom
calvadev merged 1 commit intoshopstr-eng:mainfrom
Conversation
|
@YASH-ai-bit is attempting to deploy a commit to the shopstr-eng Team on Vercel. A member of the Team first needs to authorize it. |
calvadev
approved these changes
Apr 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR consolidates the duplicate MCP metrics helpers by keeping
utils/mcp/metrics.tsas the canonical implementation, turningutils/mcp/metric.tsinto a compatibility re-export, and adding direct regression coverage for the metrics behavior.What changed
kept
utils/mcp/metrics.tsas the live MCP metrics implementationupdated
utils/mcp/metrics.tsto track bounded request records in addition to the existing cumulative counterspreserved the current metrics fields and behavior already used by the MCP API routes
added compatible observability fields to
getMetrics():uptime.startedAtuptime.durationSecondsuptime.durationHumanlatency.unitlatency.sampleSizelatency.windowthroughput.requestsPerMinutethroughput.recentRequestsreplaced
utils/mcp/metric.tswith a thin re-export ofutils/mcp/metrics.tsso both paths share one state sourceadded
utils/mcp/__tests__/metrics.test.tsWhy
There were two MCP metrics helper modules with overlapping responsibilities:
utils/mcp/metrics.tsutils/mcp/metric.tsThe live MCP routes already import
utils/mcp/metrics.ts, so this PR keeps that file as the canonical implementation and removes the risk of the two modules drifting or maintaining separate state.The new tests add direct coverage for:
metric.tsre-exportTesting
Ran:
npm test -- utils/mcp/__tests__/metrics.test.ts utils/mcp/__tests__/auth.test.ts utils/mcp/__tests__/request-proof-server.test.tsManual MCP smoke checks:
GET /api/mcp/statusPOST /api/mcp/onboardPOST /api/mcpinitialize without the requiredAcceptheader returns the expected406POST /api/mcpinitialize with the required headers succeeds and returns a session idNotes
This PR is intended to preserve existing MCP behavior. The current
metrics.tsfields remain in place, and the extra metrics fields are additive only.Before:
This SQL syntax was throwing error in table creation while I was testing
mcp/api, this issue has also been mentioned in #354.