context-mcp-server 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 (58) hide show
  1. package/README.md +464 -0
  2. package/codegraph/__init__.py +0 -0
  3. package/codegraph/__main__.py +24 -0
  4. package/codegraph/__pycache__/__init__.cpython-313.pyc +0 -0
  5. package/codegraph/__pycache__/__main__.cpython-313.pyc +0 -0
  6. package/codegraph/__pycache__/cache.cpython-313.pyc +0 -0
  7. package/codegraph/__pycache__/config.cpython-313.pyc +0 -0
  8. package/codegraph/__pycache__/report.cpython-313.pyc +0 -0
  9. package/codegraph/__pycache__/scanner.cpython-313.pyc +0 -0
  10. package/codegraph/__pycache__/server.cpython-313.pyc +0 -0
  11. package/codegraph/cache.py +137 -0
  12. package/codegraph/config.py +31 -0
  13. package/codegraph/extractors/__init__.py +0 -0
  14. package/codegraph/extractors/__pycache__/__init__.cpython-313.pyc +0 -0
  15. package/codegraph/extractors/__pycache__/ast_extractor.cpython-313.pyc +0 -0
  16. package/codegraph/extractors/__pycache__/audio_extractor.cpython-313.pyc +0 -0
  17. package/codegraph/extractors/__pycache__/doc_extractor.cpython-313.pyc +0 -0
  18. package/codegraph/extractors/__pycache__/image_extractor.cpython-313.pyc +0 -0
  19. package/codegraph/extractors/ast_extractor.py +222 -0
  20. package/codegraph/extractors/audio_extractor.py +8 -0
  21. package/codegraph/extractors/doc_extractor.py +34 -0
  22. package/codegraph/extractors/image_extractor.py +26 -0
  23. package/codegraph/graph/__init__.py +0 -0
  24. package/codegraph/graph/__pycache__/__init__.cpython-313.pyc +0 -0
  25. package/codegraph/graph/__pycache__/builder.cpython-313.pyc +0 -0
  26. package/codegraph/graph/__pycache__/clustering.cpython-313.pyc +0 -0
  27. package/codegraph/graph/__pycache__/query.cpython-313.pyc +0 -0
  28. package/codegraph/graph/builder.py +145 -0
  29. package/codegraph/graph/clustering.py +40 -0
  30. package/codegraph/graph/query.py +283 -0
  31. package/codegraph/report.py +115 -0
  32. package/codegraph/scanner.py +92 -0
  33. package/codegraph/server.py +514 -0
  34. package/package.json +62 -0
  35. package/src/cli.js +1010 -0
  36. package/src/config.js +89 -0
  37. package/src/db.js +786 -0
  38. package/src/guard.js +20 -0
  39. package/src/hooks/autoContext.js +17 -0
  40. package/src/hooks/autoLink.js +7 -0
  41. package/src/http.js +765 -0
  42. package/src/index.js +47 -0
  43. package/src/search.js +50 -0
  44. package/src/server.js +80 -0
  45. package/src/summarizer.js +124 -0
  46. package/src/templates/AGENTS.md +76 -0
  47. package/src/templates/CLAUDE.md +94 -0
  48. package/src/templates/GEMINI.md +76 -0
  49. package/src/templates/cursor-rules.mdc +41 -0
  50. package/src/templates/windsurf-rules.md +35 -0
  51. package/src/tools/codegraph.js +215 -0
  52. package/src/tools/context.js +188 -0
  53. package/src/tools/discussion.js +123 -0
  54. package/src/tools/errorCheck.js +65 -0
  55. package/src/tools/fileTools.js +185 -0
  56. package/src/tools/gitTools.js +259 -0
  57. package/src/tools/search.js +55 -0
  58. package/src/vector.js +153 -0
package/src/config.js ADDED
@@ -0,0 +1,89 @@
1
+ import { readFileSync, writeFileSync, existsSync, mkdirSync } from 'node:fs';
2
+ import { homedir, platform } from 'node:os';
3
+ import { join } from 'node:path';
4
+ import { randomBytes } from 'node:crypto';
5
+
6
+ const DATA_DIR = process.env.CONTEXT_MCP_DIR || join(homedir(), '.context-mcp');
7
+ const CONFIG_PATH = join(DATA_DIR, 'contextconfig.json');
8
+ const KEYTAR_SERVICE = 'context-mcp';
9
+ const KEYTAR_ACCOUNT = 'client_secret';
10
+
11
+ const DEFAULTS = {
12
+ client_id: 'context-mcp',
13
+ client_secret: '',
14
+ access_git: false,
15
+ port: 3100,
16
+ host: 'localhost',
17
+ };
18
+
19
+ function generateSecret() {
20
+ return randomBytes(32).toString('hex');
21
+ }
22
+
23
+ async function _keytarGet() {
24
+ try {
25
+ const kt = await import('keytar');
26
+ return kt.default.getPassword(KEYTAR_SERVICE, KEYTAR_ACCOUNT);
27
+ } catch { return null; }
28
+ }
29
+
30
+ async function _keytarSet(secret) {
31
+ try {
32
+ const kt = await import('keytar');
33
+ await kt.default.setPassword(KEYTAR_SERVICE, KEYTAR_ACCOUNT, secret);
34
+ return true;
35
+ } catch { return false; }
36
+ }
37
+
38
+ export function getConfig() {
39
+ let config = { ...DEFAULTS };
40
+
41
+ if (!existsSync(DATA_DIR)) mkdirSync(DATA_DIR, { recursive: true });
42
+
43
+ if (existsSync(CONFIG_PATH)) {
44
+ try {
45
+ const stored = JSON.parse(readFileSync(CONFIG_PATH, 'utf8'));
46
+ config = { ...config, ...stored };
47
+ } catch (err) {
48
+ console.error(`\x1b[91m⚠ Error reading config at ${CONFIG_PATH}: ${err.message}\x1b[0m`);
49
+ }
50
+ }
51
+
52
+ // Auto-generate secret if missing
53
+ let dirty = false;
54
+ if (!config.client_secret) {
55
+ config.client_secret = generateSecret();
56
+ dirty = true;
57
+ }
58
+
59
+ // Save if new or updated
60
+ if (dirty || !existsSync(CONFIG_PATH)) {
61
+ saveConfig(config);
62
+ }
63
+
64
+ return config;
65
+ }
66
+
67
+ export async function getConfigWithKeytar() {
68
+ const config = getConfig();
69
+ const keytarSecret = await _keytarGet();
70
+ if (keytarSecret) config.client_secret = keytarSecret;
71
+ return config;
72
+ }
73
+
74
+ export function saveConfig(config) {
75
+ try {
76
+ if (!existsSync(DATA_DIR)) mkdirSync(DATA_DIR, { recursive: true });
77
+ writeFileSync(CONFIG_PATH, JSON.stringify(config, null, 2), 'utf8');
78
+ } catch (err) {
79
+ console.error(`\x1b[91m⚠ Error saving config at ${CONFIG_PATH}: ${err.message}\x1b[0m`);
80
+ }
81
+ }
82
+
83
+ export async function saveSecretToKeytar(secret) {
84
+ return _keytarSet(secret);
85
+ }
86
+
87
+ export function getConfigPath() {
88
+ return CONFIG_PATH;
89
+ }