From 952218cc9f1be2c767081186229505ec736301dd Mon Sep 17 00:00:00 2001 From: Alex Rudenko Date: Fri, 13 Feb 2026 19:15:41 +0100 Subject: [PATCH 1/2] docs: estimate tokens with tiktoken --- docs/tool-reference.md | 2 +- package-lock.json | 11 +++++++++++ package.json | 1 + scripts/generate-docs.ts | 41 +++++++++++++++++++++++++++++++++++++++- 4 files changed, 53 insertions(+), 2 deletions(-) diff --git a/docs/tool-reference.md b/docs/tool-reference.md index 04a9db529..9230edd7b 100644 --- a/docs/tool-reference.md +++ b/docs/tool-reference.md @@ -1,6 +1,6 @@ -# Chrome DevTools MCP Tool Reference +# Chrome DevTools MCP Tool Reference 6661 - **[Input automation](#input-automation)** (8 tools) - [`click`](#click) diff --git a/package-lock.json b/package-lock.json index c3c9581c8..7212fd566 100644 --- a/package-lock.json +++ b/package-lock.json @@ -33,6 +33,7 @@ "eslint-import-resolver-typescript": "^4.4.4", "eslint-plugin-import": "^2.32.0", "globals": "^17.0.0", + "js-tiktoken": "^1.0.21", "prettier": "^3.6.2", "puppeteer": "24.37.3", "rollup": "4.57.1", @@ -5078,6 +5079,16 @@ "sourcemap-codec": "^1.4.8" } }, + "node_modules/js-tiktoken": { + "version": "1.0.21", + "resolved": "https://registry.npmjs.org/js-tiktoken/-/js-tiktoken-1.0.21.tgz", + "integrity": "sha512-biOj/6M5qdgx5TKjDnFT1ymSpM5tbd3ylwDtrQvFQSu0Z7bBYko2dF+W/aUkXUPuk6IVpRxk/3Q2sHOzGlS36g==", + "dev": true, + "license": "MIT", + "dependencies": { + "base64-js": "^1.5.1" + } + }, "node_modules/js-tokens": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", diff --git a/package.json b/package.json index f981a340a..5b6ca296d 100644 --- a/package.json +++ b/package.json @@ -61,6 +61,7 @@ "eslint-import-resolver-typescript": "^4.4.4", "eslint-plugin-import": "^2.32.0", "globals": "^17.0.0", + "js-tiktoken": "^1.0.21", "prettier": "^3.6.2", "puppeteer": "24.37.3", "rollup": "4.57.1", diff --git a/scripts/generate-docs.ts b/scripts/generate-docs.ts index 8ae3dc191..188a42dc2 100644 --- a/scripts/generate-docs.ts +++ b/scripts/generate-docs.ts @@ -6,7 +6,10 @@ import fs from 'node:fs'; +import {Client} from '@modelcontextprotocol/sdk/client/index.js'; +import {StdioClientTransport} from '@modelcontextprotocol/sdk/client/stdio.js'; import type {Tool} from '@modelcontextprotocol/sdk/types.js'; +import {get_encoding} from 'tiktoken'; // npm install tiktoken import {cliOptions} from '../build/src/cli.js'; import {ToolCategory, labels} from '../build/src/tools/categories.js'; @@ -15,6 +18,42 @@ import {tools} from '../build/src/tools/tools.js'; const OUTPUT_PATH = './docs/tool-reference.md'; const README_PATH = './README.md'; +async function measureServer() { + // 1. Connect to your actual MCP server + const transport = new StdioClientTransport({ + command: 'node', + args: ['./build/src/index.js'], // Point to your built MCP server + }); + + const client = new Client( + {name: 'measurer', version: '1.0.0'}, + {capabilities: {}}, + ); + await client.connect(transport); + + // 2. Fetch all tools + const toolsList = await client.listTools(); + + // 3. Serialize exactly how an LLM would see it (JSON) + const jsonString = JSON.stringify(toolsList.tools, null, 2); + + // 4. Count tokens (using cl100k_base which is standard for GPT-4/Claude-3.5 approximation) + const enc = get_encoding('cl100k_base'); + const tokenCount = enc.encode(jsonString).length; + + console.log(`--- Measurement Results ---`); + console.log(`Total Tools: ${toolsList.tools.length}`); + console.log(`JSON Character Count: ${jsonString.length}`); + console.log(`Estimated Token Count: ~${tokenCount}`); + + // Clean up + enc.free(); + await client.close(); + return { + tokenCount, + }; +} + // Extend the MCP Tool type to include our annotations interface ToolWithAnnotations extends Tool { annotations?: { @@ -316,7 +355,7 @@ async function generateToolDocumentation(): Promise { // Generate markdown documentation let markdown = ` -# Chrome DevTools MCP Tool Reference +# Chrome DevTools MCP Tool Reference (~${(await measureServer()).tokenCount} tokens via js-tiktoken) `; From 8789a8b923b37a01d95e4859cc9bf01449d4302b Mon Sep 17 00:00:00 2001 From: Alex Rudenko Date: Fri, 13 Feb 2026 19:24:52 +0100 Subject: [PATCH 2/2] docs: estimate tokens using tiktoken --- docs/tool-reference.md | 2 +- package-lock.json | 19 ++++++++----------- package.json | 2 +- scripts/generate-docs.ts | 4 ++-- 4 files changed, 12 insertions(+), 15 deletions(-) diff --git a/docs/tool-reference.md b/docs/tool-reference.md index 9230edd7b..619fd571d 100644 --- a/docs/tool-reference.md +++ b/docs/tool-reference.md @@ -1,6 +1,6 @@ -# Chrome DevTools MCP Tool Reference 6661 +# Chrome DevTools MCP Tool Reference (~6661 cl100k_base tokens) - **[Input automation](#input-automation)** (8 tools) - [`click`](#click) diff --git a/package-lock.json b/package-lock.json index 7212fd566..e8159812a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -33,13 +33,13 @@ "eslint-import-resolver-typescript": "^4.4.4", "eslint-plugin-import": "^2.32.0", "globals": "^17.0.0", - "js-tiktoken": "^1.0.21", "prettier": "^3.6.2", "puppeteer": "24.37.3", "rollup": "4.57.1", "rollup-plugin-cleanup": "^3.2.1", "rollup-plugin-license": "^3.6.0", "sinon": "^21.0.0", + "tiktoken": "^1.0.22", "typescript": "^5.9.2", "typescript-eslint": "^8.43.0", "yargs": "18.0.0" @@ -5079,16 +5079,6 @@ "sourcemap-codec": "^1.4.8" } }, - "node_modules/js-tiktoken": { - "version": "1.0.21", - "resolved": "https://registry.npmjs.org/js-tiktoken/-/js-tiktoken-1.0.21.tgz", - "integrity": "sha512-biOj/6M5qdgx5TKjDnFT1ymSpM5tbd3ylwDtrQvFQSu0Z7bBYko2dF+W/aUkXUPuk6IVpRxk/3Q2sHOzGlS36g==", - "dev": true, - "license": "MIT", - "dependencies": { - "base64-js": "^1.5.1" - } - }, "node_modules/js-tokens": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", @@ -7126,6 +7116,13 @@ "b4a": "^1.6.4" } }, + "node_modules/tiktoken": { + "version": "1.0.22", + "resolved": "https://registry.npmjs.org/tiktoken/-/tiktoken-1.0.22.tgz", + "integrity": "sha512-PKvy1rVF1RibfF3JlXBSP0Jrcw2uq3yXdgcEXtKTYn3QJ/cBRBHDnrJ5jHky+MENZ6DIPwNUGWpkVx+7joCpNA==", + "dev": true, + "license": "MIT" + }, "node_modules/tinyglobby": { "version": "0.2.15", "resolved": "https://registry.npmjs.org/tinyglobby/-/tinyglobby-0.2.15.tgz", diff --git a/package.json b/package.json index 5b6ca296d..3f43152ce 100644 --- a/package.json +++ b/package.json @@ -61,13 +61,13 @@ "eslint-import-resolver-typescript": "^4.4.4", "eslint-plugin-import": "^2.32.0", "globals": "^17.0.0", - "js-tiktoken": "^1.0.21", "prettier": "^3.6.2", "puppeteer": "24.37.3", "rollup": "4.57.1", "rollup-plugin-cleanup": "^3.2.1", "rollup-plugin-license": "^3.6.0", "sinon": "^21.0.0", + "tiktoken": "^1.0.22", "typescript": "^5.9.2", "typescript-eslint": "^8.43.0", "yargs": "18.0.0" diff --git a/scripts/generate-docs.ts b/scripts/generate-docs.ts index 188a42dc2..691e0edc2 100644 --- a/scripts/generate-docs.ts +++ b/scripts/generate-docs.ts @@ -9,7 +9,7 @@ import fs from 'node:fs'; import {Client} from '@modelcontextprotocol/sdk/client/index.js'; import {StdioClientTransport} from '@modelcontextprotocol/sdk/client/stdio.js'; import type {Tool} from '@modelcontextprotocol/sdk/types.js'; -import {get_encoding} from 'tiktoken'; // npm install tiktoken +import {get_encoding} from 'tiktoken'; import {cliOptions} from '../build/src/cli.js'; import {ToolCategory, labels} from '../build/src/tools/categories.js'; @@ -355,7 +355,7 @@ async function generateToolDocumentation(): Promise { // Generate markdown documentation let markdown = ` -# Chrome DevTools MCP Tool Reference (~${(await measureServer()).tokenCount} tokens via js-tiktoken) +# Chrome DevTools MCP Tool Reference (~${(await measureServer()).tokenCount} cl100k_base tokens) `;