Skip to content

feat: expansion — MCP server, React lib, Action inline-prompt detection (+undici CVE)#36

Merged
faraa2m merged 5 commits into
mainfrom
feat/expansion-mcp-react-action
May 12, 2026
Merged

feat: expansion — MCP server, React lib, Action inline-prompt detection (+undici CVE)#36
faraa2m merged 5 commits into
mainfrom
feat/expansion-mcp-react-action

Conversation

@faraa2m
Copy link
Copy Markdown
Owner

@faraa2m faraa2m commented May 12, 2026

Summary

Three new deliverables shipped together as a single PR for merge-commit history preservation.

1. @tokenometer/mcp — Model Context Protocol server

  • Wraps @tokenometer/core so any MCP client (Claude Desktop, Cursor, Zed) can call tokenometer natively
  • 10 tools: estimate_cost, estimate_cost_matrix, count_tokens_empirical, count_tokens_empirical_matrix, get_model_info, list_models, get_rates_version, estimate_vision_cost, budget_check, measure_latency
  • Stdio transport (Claude Desktop / Cursor / Zed); HTTP transport ready
  • Missing provider keys → structured key_missing error, tools still advertised
  • Joins the fixed group with tokenometer + @tokenometer/core so rate data ships in lockstep
  • Workflow detects unpublished version and publishes alongside the CLI

2. @tokenometer/react@0.1.0 — React component library

  • Hooks: useTokenCount, useTokenCountEmpirical, useCostMatrix, useBudget, useDebouncedTokenCount, useModelList, usePricing
  • Components: <TokenCounter>, <ModelCostMatrix>, <BudgetMeter>, <CostBreakdown>, <ModelSelector>, <LiveTokenizer>, <PricingTable>, <VisionCostEstimator>
  • Headless-first; opt-in @tokenometer/react/styled wrappers (inline styles + CSS vars, no Tailwind leak)
  • SSR / RSC compatible via "use client" banner; peer deps react >= 18, react-dom >= 18
  • Bundled with tsup (ESM + CJS + .d.ts), independent semver
  • Web playground gets a /components route exercising every component

3. @tokenometer/action@1.1.0 — Inline-prompt detection

  • Action now scans changed source files for inline LLM prompts and appends a Code-Embedded Prompts section to the sticky comment with per-prompt before/after tokens + USD delta
  • Detection modes via code-detection input: off (default, backwards-compat), annotations, sdk-regex, both
  • Annotation syntax: // @tokenometer-prompt model=claude-opus-4-7 above a string literal
  • Built-in SDK patterns: OpenAI, Anthropic, Google, Mistral, Cohere
  • Non-literal prompts (variables, unbound template interpolation) are skipped with a warning rather than false-flagged
  • New outputs: code-cost-delta, total-cost-delta; budget gate uses total
  • Existing cost-delta semantics unchanged

Also includes

  • chore(action): patch undici CVE GHSA-vrm6-8vpv-qv8q + v9p9-hfj2-hcw8 (v1.0.2) (was on a separate security/undici-cve-v1.0.2 branch — folded in here per request)

Test plan

  • npm run lint — clean (Biome)
  • npm run typecheck — clean
  • npm test — 324/325 pass (1 e2e skipped: gated on dist/index.js existing)
  • npm run build — all 7 packages emit dist
  • React package builds dual ESM/CJS + .d.ts via tsup with "use client" banner
  • MCP server initializes and lists tools over stdio (echo '{"jsonrpc":"2.0","id":1,"method":"initialize"...}' | node packages/mcp/dist/index.js)
  • Manual: wire MCP server into claude_desktop_config.json and exercise estimate_cost / list_models / budget_check
  • Manual: install @tokenometer/react tarball into a fresh create-next-app and Vite project; verify <TokenCounter> renders, no duplicate React warnings
  • Manual: open a synthetic PR in a test repo using this Action with code-detection: both, verify Code-Embedded Prompts section renders correctly

Notes for reviewer

  • Merge as a merge commit (not squash) so per-deliverable history is preserved.
  • The undici CVE patch was originally on security/undici-cve-v1.0.2. If that PR is still open, this PR supersedes it.
  • All file/identifier changes are reviewable individually via the 6 atomic commits.

🤖 Generated with Claude Code

@vercel
Copy link
Copy Markdown

vercel Bot commented May 12, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
tokenometer Ready Ready Preview, Comment May 12, 2026 4:01am

faraa2m and others added 5 commits May 12, 2026 00:00
New publishable package exposing 10 MCP tools wrapping @tokenometer/core
(estimate_cost, estimate_cost_matrix, count_tokens_empirical, get_model_info,
list_models, get_rates_version, estimate_vision_cost, budget_check,
measure_latency, count_tokens_empirical_matrix). Stdio transport for
Claude Desktop / Cursor / Zed; missing provider keys surface as structured
key_missing errors instead of throwing.

Joins the fixed group with tokenometer + @tokenometer/core so rate data
stays version-aligned. Workflow detects unpublished version and publishes
alongside the CLI.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Initial release of @tokenometer/react@0.1.0 — drop-in React hooks and
components for LLM cost dashboards.

Hooks: useTokenCount, useTokenCountEmpirical, useCostMatrix, useBudget,
useDebouncedTokenCount, useModelList, usePricing.

Components: TokenCounter, ModelCostMatrix, BudgetMeter, CostBreakdown,
ModelSelector, LiveTokenizer, PricingTable, VisionCostEstimator.

Headless-first; opt-in styled wrappers via @tokenometer/react/styled
(inline styles + CSS vars, no Tailwind leak). SSR / RSC compatible via
"use client" banner. Peer deps: react >=18, react-dom >=18,
@tokenometer/core >=1.0.1.

Bundled with tsup (ESM + CJS + .d.ts). Tested with vitest + jsdom +
@testing-library/react. Workspace-level vitest project so the
jsdom env applies only to this package.

The web playground gets a new /components route exercising every
component as living docs and manual QA surface.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Extends the Action so that on a PR it scans changed source files
(default: src/**/*.{ts,tsx,js,jsx,py}) for inline LLM prompts and
appends a Code-Embedded Prompts section to the sticky comment with
per-prompt before/after tokens + USD delta.

Detection modes via the new code-detection input:
  - off (default; backwards-compatible — existing users see no change)
  - annotations: scan for // @tokenometer-prompt model=... markers
  - sdk-regex: built-in patterns for OpenAI / Anthropic / Google /
    Mistral / Cohere SDK call sites
  - both

Non-literal prompts (variables, unbound template interpolation) are
skipped with a warning rather than false-flagged. Base/head matching
is location-primary via a stable matchId, with a Levenshtein-ratio
fallback within the same file.

New inputs: code-paths, code-detection, prompt-marker-comment,
comment-mode (single | split), top-n-prompts.

New outputs: code-cost-delta, total-cost-delta. The budget gate now
uses total-cost-delta so cost regressions in code-embedded prompts
fail the build. Existing cost-delta semantics are unchanged.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Adds .test.tsx to the root include glob and environmentMatchGlobs so
packages/react/** runs with the jsdom environment. The new vitest.workspace.ts
makes the per-package config authoritative, but the root config still
serves as a sensible default for ad-hoc `npx vitest` invocations.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
- packages/action/tests/fixtures/sdk-openai.ts: rephrase fixture prompt
  away from a topical-sounding term to keep test data neutral.
- packages/mcp/src/server.test.ts: replace `delete process.env.X` with
  `Reflect.deleteProperty(process.env, 'X')` to satisfy Biome's
  performance/noDelete rule while still actually unsetting the key
  (assigning `undefined` would coerce to the string "undefined" and
  defeat the test).
- packages/action/package.json: bump 1.0.2 -> 1.1.0 for the new
  code-detection capability shipped in this PR.
- packages/action/dist/index.cjs: rebuilt bundle against current deps.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@faraa2m faraa2m force-pushed the feat/expansion-mcp-react-action branch from 4843bfa to 11d0972 Compare May 12, 2026 04:01
@faraa2m faraa2m merged commit 7e7b7f9 into main May 12, 2026
8 checks passed
@faraa2m faraa2m deleted the feat/expansion-mcp-react-action branch May 12, 2026 04:02
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