prompt-compressor-mcp 0.0.0-stage → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (5) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +97 -2
  3. package/bin.js +7 -0
  4. package/index.js +126 -0
  5. package/package.json +35 -4
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Tom Ketter
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,98 @@
1
- # Temporary Holding Version
1
+ # prompt-compressor-mcp
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ > MCP server for rule-based prompt compression. Cut LLM token usage without a model, without an API key, and without sending data anywhere.
4
+
5
+ [![npm](https://img.shields.io/npm/v/prompt-compressor-mcp)](https://www.npmjs.com/package/prompt-compressor-mcp)
6
+ [![kettertom/prompt-compressor MCP server](https://glama.ai/mcp/servers/kettertom/prompt-compressor/badges/score.svg)](https://glama.ai/mcp/servers/kettertom/prompt-compressor)
7
+
8
+ ⭐ **Find it useful? [Star it on GitHub](https://github.com/kettertom/prompt-compressor)** · 🐛 **Found a bug or have an idea? [Open an issue](https://github.com/kettertom/prompt-compressor/issues/new)**
9
+
10
+ Gives Claude, Cursor, VS Code, Windsurf, or any MCP client tools to shrink prompts, system prompts, docs, logs and JSON before they go into context. Built on [`prompt-compressor`](https://www.npmjs.com/package/prompt-compressor). Fully deterministic and runs locally. Template variables like `{{name}}` are preserved.
11
+
12
+ **No model. No API key. Deterministic. Zero dependencies. Your data never leaves your machine.** At the default level it cut **23% of tokens across 8 real-world prompt types while keeping 94/94 critical instructions**. See the [benchmark](https://github.com/kettertom/prompt-compressor#benchmark).
13
+
14
+ ## Tools
15
+
16
+ | Tool | What it does |
17
+ |---|---|
18
+ | `compress_prompt` | Compress text at a chosen risk level → compressed text + token stats |
19
+ | `compress_file` | Read a local text file and return a compressed version (the file is not modified) |
20
+ | `compare_levels` | Run all four levels on the same text and show the savings for each |
21
+ | `estimate_tokens` | Quick token estimate for any text |
22
+
23
+ Resource: `prompt-compressor://levels` lists which algorithms run at each level.
24
+
25
+ ### Risk levels
26
+
27
+ | Level | What runs | Measured saving ([benchmark](https://github.com/kettertom/prompt-compressor#benchmark)) |
28
+ |---|---|---|
29
+ | `none` | Whitespace, unicode normalization, indentation | 4% avg (0–24%) |
30
+ | `very-low` | + filler lead-ins, phrase shortening, JSON/SQL minify | 9% avg (0–32%) |
31
+ | `low` (default) | + hedging, code comments, deduplication, stack-trace truncation | **23% avg (2–59%)**, 100% of critical facts kept |
32
+ | `medium` | + Near-duplicate removal (fuzzy / n-gram / Levenshtein), TextRank on plain prose only | 24% avg (5–59%), 100% of critical facts kept |
33
+
34
+ > **`medium` = `low` + near-duplicate removal + light summarization of plain prose.** Code blocks, lists, tables, `Key: value` lines, questions, and any sentence with a rule, number, ID or variable are never removed. On the dense prompts in the benchmark it saves about the same as `low` (24% vs 23%) and kept 94/94 critical facts. It helps most on long, chatty prose. *(Before 1.0.3, `medium` chained three summarizers and kept only 22% of critical facts. Upgrade if you used it.)*
35
+
36
+ ## Install
37
+
38
+ No install step. Your MCP client runs it with `npx`.
39
+
40
+ ### Claude Desktop / Claude Code
41
+
42
+ ```json
43
+ {
44
+ "mcpServers": {
45
+ "prompt-compressor": {
46
+ "command": "npx",
47
+ "args": ["-y", "prompt-compressor-mcp"]
48
+ }
49
+ }
50
+ }
51
+ ```
52
+
53
+ Claude Code one-liner:
54
+
55
+ ```bash
56
+ claude mcp add prompt-compressor -- npx -y prompt-compressor-mcp
57
+ ```
58
+
59
+ ### Cursor / Windsurf
60
+
61
+ Add the same `mcpServers` block to `~/.cursor/mcp.json` or `~/.codeium/windsurf/mcp_config.json`.
62
+
63
+ ### VS Code
64
+
65
+ ```json
66
+ {
67
+ "servers": {
68
+ "prompt-compressor": {
69
+ "type": "stdio",
70
+ "command": "npx",
71
+ "args": ["-y", "prompt-compressor-mcp"]
72
+ }
73
+ }
74
+ }
75
+ ```
76
+
77
+ ## Example
78
+
79
+ > "Compress the system prompt in `prompts/support.md` at low risk and show me how many tokens it saves."
80
+
81
+ ```
82
+ Tokens: 1200 → 820 (saved 380, 31%)
83
+ ```
84
+
85
+ ## Use it in your own server
86
+
87
+ ```js
88
+ import { createServer } from 'prompt-compressor-mcp';
89
+ import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
90
+
91
+ await createServer().connect(new StdioServerTransport());
92
+ ```
93
+
94
+ Want the library without MCP? Use [`prompt-compressor`](https://www.npmjs.com/package/prompt-compressor) directly, or try the web tool at **[prompt-compressor.com](https://prompt-compressor.com)**.
95
+
96
+ ## License
97
+
98
+ MIT © Tom Ketter
package/bin.js ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env node
2
+ import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
3
+ import { createServer } from './index.js';
4
+
5
+ const server = createServer();
6
+ await server.connect(new StdioServerTransport());
7
+ console.error('prompt-compressor MCP server running on stdio');
package/index.js ADDED
@@ -0,0 +1,126 @@
1
+ /**
2
+ * prompt-compressor-mcp
3
+ *
4
+ * MCP server for prompt-compressor: rule-based prompt compression.
5
+ * No model, no API, nothing leaves your machine.
6
+ */
7
+
8
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
9
+ import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
10
+ import { readFile } from 'node:fs/promises';
11
+ import { createRequire } from 'node:module';
12
+ import { z } from 'zod';
13
+ import { compress, estimateTokens, LEVELS } from 'prompt-compressor';
14
+
15
+ const require = createRequire(import.meta.url);
16
+ const { version } = require('./package.json');
17
+
18
+ const LEVEL_NAMES = ['none', 'very-low', 'low', 'medium'];
19
+ const levelSchema = z
20
+ .enum(LEVEL_NAMES)
21
+ .default('low')
22
+ .describe(
23
+ "Risk level. 'none' = whitespace/unicode only; 'very-low' = + filler, phrases, JSON/SQL minify; " +
24
+ "'low' = + hedging, comments, dedup (recommended); 'medium' = + near-duplicate removal and light summarization of plain prose (code, lists, questions and sentences with rules/numbers/IDs are always kept)."
25
+ );
26
+
27
+ const statsLine = (s) =>
28
+ `Tokens: ${s.tokensBefore} → ${s.tokensAfter} (saved ${s.saved}, ${s.reductionPct}%)`;
29
+
30
+ export function createServer() {
31
+ const server = new McpServer({ name: 'prompt-compressor', version });
32
+
33
+ server.registerTool(
34
+ 'compress_prompt',
35
+ {
36
+ title: 'Compress prompt',
37
+ description:
38
+ 'Compress a prompt, system prompt, or context block to use fewer tokens, using deterministic rule-based ' +
39
+ 'algorithms (no LLM call). Template variables like {{name}} and {var} are preserved. ' +
40
+ 'Returns the compressed text and token stats.',
41
+ inputSchema: {
42
+ text: z.string().min(1).describe('The text to compress.'),
43
+ level: levelSchema,
44
+ },
45
+ annotations: { readOnlyHint: true, openWorldHint: false },
46
+ },
47
+ async ({ text, level }) => {
48
+ const { output, stats } = compress(text, level);
49
+ return {
50
+ content: [{ type: 'text', text: output }, { type: 'text', text: statsLine(stats) }],
51
+ structuredContent: { output, stats, level },
52
+ };
53
+ }
54
+ );
55
+
56
+ server.registerTool(
57
+ 'compress_file',
58
+ {
59
+ title: 'Compress file',
60
+ description:
61
+ 'Read a local text file (prompt, docs, logs, JSON, code) and return a compressed version with token stats. ' +
62
+ 'Does not modify the file.',
63
+ inputSchema: {
64
+ path: z.string().min(1).describe('Absolute path to a local text file.'),
65
+ level: levelSchema,
66
+ },
67
+ annotations: { readOnlyHint: true, openWorldHint: false },
68
+ },
69
+ async ({ path, level }) => {
70
+ let text;
71
+ try {
72
+ text = await readFile(path, 'utf8');
73
+ } catch (err) {
74
+ return { isError: true, content: [{ type: 'text', text: `Could not read ${path}: ${err.message}` }] };
75
+ }
76
+ const { output, stats } = compress(text, level);
77
+ return {
78
+ content: [{ type: 'text', text: output }, { type: 'text', text: statsLine(stats) }],
79
+ structuredContent: { output, stats, level, path },
80
+ };
81
+ }
82
+ );
83
+
84
+ server.registerTool(
85
+ 'compare_levels',
86
+ {
87
+ title: 'Compare compression levels',
88
+ description:
89
+ 'Run every risk level on the same text and report token savings for each, so you can pick the right trade-off.',
90
+ inputSchema: { text: z.string().min(1).describe('The text to analyze.') },
91
+ annotations: { readOnlyHint: true, openWorldHint: false },
92
+ },
93
+ async ({ text }) => {
94
+ const rows = LEVEL_NAMES.map((level) => ({ level, ...compress(text, level).stats }));
95
+ const table = [
96
+ '| Level | Tokens before | Tokens after | Saved | Reduction |',
97
+ '|---|---|---|---|---|',
98
+ ...rows.map((r) => `| ${r.level} | ${r.tokensBefore} | ${r.tokensAfter} | ${r.saved} | ${r.reductionPct}% |`),
99
+ ].join('\n');
100
+ return { content: [{ type: 'text', text: table }], structuredContent: { levels: rows } };
101
+ }
102
+ );
103
+
104
+ server.registerTool(
105
+ 'estimate_tokens',
106
+ {
107
+ title: 'Estimate tokens',
108
+ description: 'Estimate the token count of a text (fast heuristic, no tokenizer download).',
109
+ inputSchema: { text: z.string().describe('The text to measure.') },
110
+ annotations: { readOnlyHint: true, openWorldHint: false },
111
+ },
112
+ async ({ text }) => {
113
+ const tokens = estimateTokens(text);
114
+ return { content: [{ type: 'text', text: `~${tokens} tokens` }], structuredContent: { tokens } };
115
+ }
116
+ );
117
+
118
+ server.registerResource(
119
+ 'levels',
120
+ 'prompt-compressor://levels',
121
+ { title: 'Compression levels', description: 'Which algorithms run at each risk level', mimeType: 'application/json' },
122
+ async (uri) => ({ contents: [{ uri: uri.href, mimeType: 'application/json', text: JSON.stringify(LEVELS, null, 2) }] })
123
+ );
124
+
125
+ return server;
126
+ }
package/package.json CHANGED
@@ -1,6 +1,37 @@
1
1
  {
2
2
  "name": "prompt-compressor-mcp",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.0.1",
4
+ "mcpName": "io.github.kettertom/prompt-compressor",
5
+ "description": "MCP server for rule-based prompt compression — cut LLM token usage without a model, without an API, without sending data anywhere.",
6
+ "type": "module",
7
+ "main": "index.js",
8
+ "bin": {
9
+ "prompt-compressor-mcp": "bin.js"
10
+ },
11
+ "exports": {
12
+ ".": "./index.js"
13
+ },
14
+ "files": ["index.js", "bin.js", "README.md"],
15
+ "scripts": {
16
+ "test": "node --test test/*.test.js"
17
+ },
18
+ "dependencies": {
19
+ "@modelcontextprotocol/sdk": "^1.32.2",
20
+ "prompt-compressor": "^1.0.3",
21
+ "zod": "^4.0.0"
22
+ },
23
+ "keywords": [
24
+ "mcp", "mcp-server", "model-context-protocol", "prompt", "compression",
25
+ "llm", "tokens", "claude", "cursor", "token-optimization"
26
+ ],
27
+ "author": "Tom Ketter",
28
+ "license": "MIT",
29
+ "repository": {
30
+ "type": "git",
31
+ "url": "https://github.com/kettertom/prompt-compressor.git",
32
+ "directory": "src/mcp-package"
33
+ },
34
+ "bugs": { "url": "https://github.com/kettertom/prompt-compressor/issues" },
35
+ "homepage": "https://prompt-compressor.com",
36
+ "engines": { "node": ">=18" }
37
+ }