Skip to content

feat(mcp-server): add prometheus metrics endpoint#305

Merged
kvz merged 3 commits into
mainfrom
feat/mcp-metrics
Feb 3, 2026
Merged

feat(mcp-server): add prometheus metrics endpoint#305
kvz merged 3 commits into
mainfrom
feat/mcp-metrics

Conversation

@kvz
Copy link
Copy Markdown
Member

@kvz kvz commented Feb 2, 2026

Summary

  • expose /metrics for mcp-server HTTP and Express
  • add prom-client default metrics and config for metricsPath
  • add e2e test coverage and docs

Testing

  • corepack yarn check
  • vitest run packages/mcp-server/test/e2e/metrics.test.ts

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fdfb025468

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +56 to +60
const handler = (async (req, res) => {
if (metricsPath) {
const pathname = normalizePath(parsePathname(req.url, expectedPath))
if (pathname === metricsPath) {
if (req.method !== 'GET' && req.method !== 'HEAD') {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Require auth on the raw HTTP metrics endpoint

The metrics branch short‑circuits before mcpHandler, so it never applies the bearer token check that createMcpRequestHandler enforces for MCP requests. In deployments where mcpToken is required (e.g., non‑localhost binds), /metrics is still publicly readable and exposes process/runtime metrics to unauthenticated callers. Consider reusing the token check (or a separate metrics token) before returning metrics.

Useful? React with 👍 / 👎.

Comment on lines +42 to +46
if (metricsPath) {
router.get(metricsPath, async (_req, res) => {
res.setHeader('Content-Type', getMetricsContentType())
res.status(200).send(await getMetrics())
})
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Require auth on the Express metrics endpoint

The Express router adds GET/HEAD handlers for metricsPath without any of the MCP auth/CORS checks, so a configured mcpToken does not protect the metrics route. If this router is mounted on a public host, anyone can scrape runtime/process metrics. Consider applying the same auth check as the MCP handler (or a dedicated metrics token) before responding.

Useful? React with 👍 / 👎.

@kvz kvz merged commit b7795dd into main Feb 3, 2026
17 of 50 checks passed
@kvz kvz deleted the feat/mcp-metrics branch February 3, 2026 06:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant