prompt-compressor-mcp 0.0.0-stage → 1.0.0

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 (4) hide show
  1. package/README.md +92 -2
  2. package/bin.js +7 -0
  3. package/index.js +126 -0
  4. package/package.json +35 -4
package/README.md CHANGED
@@ -1,3 +1,93 @@
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
+
7
+ ⭐ **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)**
8
+
9
+ 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.
10
+
11
+ ## Tools
12
+
13
+ | Tool | What it does |
14
+ |---|---|
15
+ | `compress_prompt` | Compress text at a chosen risk level → compressed text + token stats |
16
+ | `compress_file` | Read a local text file and return a compressed version (the file is not modified) |
17
+ | `compare_levels` | Run all four levels on the same text and show the savings for each |
18
+ | `estimate_tokens` | Quick token estimate for any text |
19
+
20
+ Resource: `prompt-compressor://levels` lists which algorithms run at each level.
21
+
22
+ ### Risk levels
23
+
24
+ | Level | What runs | Typical saving |
25
+ |---|---|---|
26
+ | `none` | Whitespace, unicode normalization, indentation | 5–15% |
27
+ | `very-low` | + filler lead-ins, phrase shortening, JSON/SQL minify | 15–30% |
28
+ | `low` (default) | + hedging, code comments, deduplication, stack-trace truncation | 25–45% |
29
+ | `medium` | + fuzzy dedup, TF-IDF, TextRank (may drop sentences) | 30–70% |
30
+
31
+ ## Install
32
+
33
+ No install step. Your MCP client runs it with `npx`.
34
+
35
+ ### Claude Desktop / Claude Code
36
+
37
+ ```json
38
+ {
39
+ "mcpServers": {
40
+ "prompt-compressor": {
41
+ "command": "npx",
42
+ "args": ["-y", "prompt-compressor-mcp"]
43
+ }
44
+ }
45
+ }
46
+ ```
47
+
48
+ Claude Code one-liner:
49
+
50
+ ```bash
51
+ claude mcp add prompt-compressor -- npx -y prompt-compressor-mcp
52
+ ```
53
+
54
+ ### Cursor / Windsurf
55
+
56
+ Add the same `mcpServers` block to `~/.cursor/mcp.json` or `~/.codeium/windsurf/mcp_config.json`.
57
+
58
+ ### VS Code
59
+
60
+ ```json
61
+ {
62
+ "servers": {
63
+ "prompt-compressor": {
64
+ "type": "stdio",
65
+ "command": "npx",
66
+ "args": ["-y", "prompt-compressor-mcp"]
67
+ }
68
+ }
69
+ }
70
+ ```
71
+
72
+ ## Example
73
+
74
+ > "Compress the system prompt in `prompts/support.md` at low risk and show me how many tokens it saves."
75
+
76
+ ```
77
+ Tokens: 1200 → 820 (saved 380, 31%)
78
+ ```
79
+
80
+ ## Use it in your own server
81
+
82
+ ```js
83
+ import { createServer } from 'prompt-compressor-mcp';
84
+ import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
85
+
86
+ await createServer().connect(new StdioServerTransport());
87
+ ```
88
+
89
+ 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)**.
90
+
91
+ ## License
92
+
93
+ 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' = + extractive summarization (may drop sentences)."
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.0",
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.1",
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
+ }