Token Counter

<mcp-token-counter>

Token usage counter with visual progress indicator and warning states.

AIWeb Component

Overview

Token usage counter with visual progress indicator and warning states.

Preview

Preview
Loading components...

Import

javascript
// Import all components (recommended)
import '@mcpsystem/ui';

// Or import the class for TypeScript
import { McpTokenCounter } from '@mcpsystem/ui';

Basic Usage

html
<mcp-token-counter used="3500" limit="4096"></mcp-token-counter>

API Reference

Properties(5)

PropertyAttributeType
usedusednumber
limitlimitnumber
showLabelshow-labelboolean
variantvariant'default' | 'compact'
warningThresholdwarning-thresholdnumber

Events(2)

EventDetail
mcp-limit-warning{ used, limit, percentage }
mcp-limit-exceeded{ used, limit, percentage }

CSS Parts(4)

Style internal elements using ::part() selector.

PartDescription
::part(container)The outer container
::part(bar)The progress bar track
::part(bar-fill)The progress bar fill
::part(label)The text label

CSS Custom Properties(5)

Customize appearance by setting these CSS variables.

PropertyDescription
--mcp-token-bar-bgProgress bar background
--mcp-token-bar-fillProgress bar fill color
--mcp-token-bar-heightProgress bar height
--mcp-token-warningWarning state color
--mcp-token-errorError/exceeded state color

Examples

Basic Usage

Preview
Loading components...
html
<mcp-token-counter used="3500" limit="4096"></mcp-token-counter>

With Label

Preview
Loading components...
html
<mcp-token-counter used="100000" limit="128000" show-label></mcp-token-counter>

Handle Warning

Preview
Loading components...
html
<mcp-token-counter id="counter" used="0" limit="4096"></mcp-token-counter>
<script>
  document.getElementById('counter').addEventListener('mcp-limit-warning', (e) => {
    console.log('Warning:', e.detail.percentage + '% used');
  });
</script>

More Components