diff --git a/docs/tool-reference.md b/docs/tool-reference.md index 04a9db529..619fd571d 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 cl100k_base tokens) - **[Input automation](#input-automation)** (8 tools) - [`click`](#click) diff --git a/package-lock.json b/package-lock.json index c3c9581c8..e8159812a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -39,6 +39,7 @@ "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" @@ -7115,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 f981a340a..3f43152ce 100644 --- a/package.json +++ b/package.json @@ -67,6 +67,7 @@ "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 8ae3dc191..691e0edc2 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'; 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} cl100k_base tokens) `;