mcp-context-optimizer 0.1.5 → 0.1.7
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.
- package/README.md +127 -3
- package/dist/compact.d.ts +70 -0
- package/dist/compact.d.ts.map +1 -0
- package/dist/compact.js +174 -0
- package/dist/compact.js.map +1 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/optimizer.d.ts +7 -2
- package/dist/optimizer.d.ts.map +1 -1
- package/dist/optimizer.js +35 -5
- package/dist/optimizer.js.map +1 -1
- package/dist/render.d.ts +22 -3
- package/dist/render.d.ts.map +1 -1
- package/dist/render.js +21 -7
- package/dist/render.js.map +1 -1
- package/dist/score.d.ts +5 -0
- package/dist/score.d.ts.map +1 -1
- package/dist/score.js +13 -5
- package/dist/score.js.map +1 -1
- package/dist/select.d.ts +9 -0
- package/dist/select.d.ts.map +1 -1
- package/dist/select.js +103 -1
- package/dist/select.js.map +1 -1
- package/dist/types.d.ts +32 -2
- package/dist/types.d.ts.map +1 -1
- package/package.json +3 -2
- package/skills/pro/AGENSI-LISTING-PRO.md +52 -0
- package/skills/pro/CASE-STUDY.md +143 -0
- package/skills/pro/README.md +84 -0
- package/skills/pro/SKILL.md +101 -0
- package/skills/pro/bench/token-comparison.json +69 -0
- package/skills/pro/bench/token-savings.svg +67 -0
- package/skills/pro/examples/pro-debugging-session.md +47 -0
- package/skills/pro/mcp.json +17 -0
- package/skills/pro/profiles/debug.json +15 -0
- package/skills/pro/profiles/refactor.json +15 -0
- package/skills/pro/profiles/review.json +15 -0
- package/skills/pro/references/fixtures/sample-errors.json +21 -0
- package/skills/pro/references/fixtures/sample-test-results.json +30 -0
- package/skills/pro/scripts/analyze-report.ts +73 -0
- package/skills/pro/scripts/prepare-context.ts +59 -0
- package/skills/pro/setup/INSTALLATION.md +64 -0
- package/skills/pro/setup/claude-code-command.txt +1 -0
- package/skills/pro/setup/mcp-config.example.json +17 -0
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* analyze-report.ts - Pro feature: Visualizes optimization reports from build_context
|
|
4
|
+
*
|
|
5
|
+
* Usage: npx tsx scripts/analyze-report.ts <report.json>
|
|
6
|
+
*
|
|
7
|
+
* This script parses the optimization report and displays:
|
|
8
|
+
* - Summary statistics
|
|
9
|
+
* - Top retained fragments
|
|
10
|
+
* - Omitted records and reasons
|
|
11
|
+
* - Token budget utilization
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { readFileSync } from 'node:fs';
|
|
15
|
+
|
|
16
|
+
interface ReportStats {
|
|
17
|
+
reduction?: number;
|
|
18
|
+
contextTokens?: number;
|
|
19
|
+
tokenBudget?: number;
|
|
20
|
+
utilization?: number;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
interface ReportSource {
|
|
24
|
+
kind?: string;
|
|
25
|
+
selectionReason?: string;
|
|
26
|
+
score?: number;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
interface OmittedRecord {
|
|
30
|
+
kind?: string;
|
|
31
|
+
reason?: string;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
interface OptimizationReport {
|
|
35
|
+
stats?: ReportStats;
|
|
36
|
+
sources?: ReportSource[];
|
|
37
|
+
omitted?: OmittedRecord[];
|
|
38
|
+
warnings?: string[];
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const reportPath: string = process.argv[2];
|
|
42
|
+
const report: OptimizationReport = JSON.parse(readFileSync(reportPath, 'utf-8'));
|
|
43
|
+
|
|
44
|
+
console.log('=== Optimization Report Analysis ===\n');
|
|
45
|
+
|
|
46
|
+
// Summary
|
|
47
|
+
console.log('Summary:');
|
|
48
|
+
console.log(` Reduction: ${report.stats?.reduction || 'N/A'}`);
|
|
49
|
+
console.log(` Context size: ${report.stats?.contextTokens || 'N/A'} tokens`);
|
|
50
|
+
console.log(` Budget: ${report.stats?.tokenBudget || 'N/A'} tokens`);
|
|
51
|
+
console.log(` Utilized: ${report.stats?.utilization || 'N/A'}%\n`);
|
|
52
|
+
|
|
53
|
+
// Retained fragments
|
|
54
|
+
console.log('Top retained fragments:');
|
|
55
|
+
report.sources?.slice(0, 5).forEach((s: ReportSource, i: number) => {
|
|
56
|
+
console.log(` ${i + 1}. [${s.kind || 'unknown'}] ${s.selectionReason || 'Retained'} (score: ${s.score || 'N/A'})`);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
// Omissions
|
|
60
|
+
console.log('\nOmitted records:');
|
|
61
|
+
report.omitted?.forEach((o: OmittedRecord) => {
|
|
62
|
+
console.log(` - [${o.kind || 'unknown'}] ${o.reason || 'Reason not specified'}`);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
// Warnings
|
|
66
|
+
if (report.warnings && report.warnings.length > 0) {
|
|
67
|
+
console.log('\nWarnings:');
|
|
68
|
+
report.warnings.forEach((w: string) => {
|
|
69
|
+
console.log(` ⚠️ ${w}`);
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
console.log('\n=== Analysis complete ===');
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* prepare-context.ts - Pro feature: Prepares records from files before calling build_context
|
|
4
|
+
*
|
|
5
|
+
* Usage: npx tsx scripts/prepare-context.ts <file1> <file2> ... [--task "Task description"]
|
|
6
|
+
*
|
|
7
|
+
* This script reads specified files and generates ready-to-use record objects
|
|
8
|
+
* for ingest_records or build_context tools.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { readFileSync } from 'node:fs';
|
|
12
|
+
import { resolve } from 'node:path';
|
|
13
|
+
|
|
14
|
+
interface FileRecord {
|
|
15
|
+
kind: 'file';
|
|
16
|
+
path: string;
|
|
17
|
+
content: string;
|
|
18
|
+
language: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const args: string[] = process.argv.slice(2);
|
|
22
|
+
const taskIndex = args.indexOf('--task');
|
|
23
|
+
const task: string = taskIndex > -1 ? args[taskIndex + 1] : 'Analyze the following code files';
|
|
24
|
+
const files: string[] = args.filter(a => !a.startsWith('--') && (taskIndex === -1 || a !== args[taskIndex + 1]));
|
|
25
|
+
|
|
26
|
+
if (files.length === 0) {
|
|
27
|
+
console.error('Usage: npx tsx scripts/prepare-context.ts <file1> <file2> ... [--task "Task description"]');
|
|
28
|
+
process.exit(1);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
console.log('---');
|
|
32
|
+
console.log('title: Preparing context records');
|
|
33
|
+
console.log('tags: [workflow]');
|
|
34
|
+
console.log('---\n');
|
|
35
|
+
|
|
36
|
+
console.log(`Task: "${task}"\n`);
|
|
37
|
+
console.log('Records to ingest:');
|
|
38
|
+
|
|
39
|
+
const records: FileRecord[] = [];
|
|
40
|
+
|
|
41
|
+
files.forEach((file: string) => {
|
|
42
|
+
const content = readFileSync(resolve(file), 'utf-8');
|
|
43
|
+
const record: FileRecord = {
|
|
44
|
+
kind: 'file',
|
|
45
|
+
path: file,
|
|
46
|
+
content: content.substring(0, 500) + (content.length > 500 ? '... (truncated)' : ''),
|
|
47
|
+
language: file.split('.').pop() || 'unknown'
|
|
48
|
+
};
|
|
49
|
+
records.push(record);
|
|
50
|
+
console.log(JSON.stringify(record, null, 2));
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
console.log('\n---');
|
|
54
|
+
console.log('title: Ready to build context');
|
|
55
|
+
console.log('---');
|
|
56
|
+
console.log('\nNext steps:');
|
|
57
|
+
console.log('1. Call `ingest_records` with the records above');
|
|
58
|
+
console.log('2. Call `build_context` with your task description');
|
|
59
|
+
console.log('3. Inspect the optimized context, sources, and omissions');
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# Installation and setup
|
|
2
|
+
|
|
3
|
+
This guide configures the MCP server separately from the Skill.
|
|
4
|
+
|
|
5
|
+
## Requirements
|
|
6
|
+
|
|
7
|
+
- Node.js 20+
|
|
8
|
+
- An MCP-compatible client
|
|
9
|
+
- Internet access during first-time package installation if using `npx`
|
|
10
|
+
|
|
11
|
+
## Option A: MCP clients using `mcpServers`
|
|
12
|
+
|
|
13
|
+
1. Copy `mcp-config.example.json` into the MCP configuration file used by your client.
|
|
14
|
+
2. Merge the `mcpServers` entry into the existing configuration; do not overwrite other servers.
|
|
15
|
+
3. Restart/reload the client or its MCP server connection.
|
|
16
|
+
4. Confirm these tools appear: `ingest_records`, `search_context`, `get_decisions`, `get_relevant_errors`, `get_file_history`, `build_context`.
|
|
17
|
+
|
|
18
|
+
The example uses `npx` to run the published package and make the MCP SDK dependencies available in the same invocation:
|
|
19
|
+
|
|
20
|
+
```json
|
|
21
|
+
{
|
|
22
|
+
"mcpServers": {
|
|
23
|
+
"mcp-context-optimizer": {
|
|
24
|
+
"command": "npx",
|
|
25
|
+
"args": [
|
|
26
|
+
"-y",
|
|
27
|
+
"-p",
|
|
28
|
+
"mcp-context-optimizer",
|
|
29
|
+
"-p",
|
|
30
|
+
"@modelcontextprotocol/server",
|
|
31
|
+
"-p",
|
|
32
|
+
"zod",
|
|
33
|
+
"mcp-ctx-optimizer"
|
|
34
|
+
]
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
This is a template for clients that accept the `mcpServers` key. Some clients use a different configuration schema or location; follow the host client's documentation and adapt the entry as needed.
|
|
41
|
+
|
|
42
|
+
## Option B: Claude Code
|
|
43
|
+
|
|
44
|
+
Run this command in a terminal:
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
claude mcp add mcp-context-optimizer -- npx -y -p mcp-context-optimizer -p @modelcontextprotocol/server -p zod mcp-ctx-optimizer
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Then verify the server is listed in Claude Code and that its tools are available.
|
|
51
|
+
|
|
52
|
+
## If the server does not start
|
|
53
|
+
|
|
54
|
+
1. Check `node --version`; it should be 20 or newer.
|
|
55
|
+
2. Check `npx --version`.
|
|
56
|
+
3. Confirm the package/bin name is spelled `mcp-context-optimizer` / `mcp-ctx-optimizer` respectively.
|
|
57
|
+
4. Check the client's MCP logs for package resolution or peer dependency errors.
|
|
58
|
+
5. If the host requires a different config key or supports a different command runner, adapt the configuration to that host.
|
|
59
|
+
|
|
60
|
+
Do not put API keys in this configuration: the optimizer does not require them.
|
|
61
|
+
|
|
62
|
+
## Privacy and data handling
|
|
63
|
+
|
|
64
|
+
The optimizer itself is designed for local operation and does not make network requests during processing. The initial `npx` command may download the package and dependencies. Only provide records that are relevant and that you are permitted to share with the agent. The default store is in memory; restarting the server clears it.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
claude mcp add mcp-context-optimizer -- npx -y -p mcp-context-optimizer -p @modelcontextprotocol/server -p zod mcp-ctx-optimizer
|