@elliotding/ai-agent-mcp 0.1.26 → 0.1.28
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 +330 -30
- package/dist/api/cached-client.d.ts +48 -0
- package/dist/api/cached-client.d.ts.map +1 -0
- package/dist/api/cached-client.js +126 -0
- package/dist/api/cached-client.js.map +1 -0
- package/dist/api/client.d.ts +295 -0
- package/dist/api/client.d.ts.map +1 -0
- package/dist/api/client.js +385 -0
- package/dist/api/client.js.map +1 -0
- package/dist/auth/index.d.ts +8 -0
- package/dist/auth/index.d.ts.map +1 -0
- package/dist/auth/index.js +26 -0
- package/dist/auth/index.js.map +1 -0
- package/dist/auth/middleware.d.ts +36 -0
- package/dist/auth/middleware.d.ts.map +1 -0
- package/dist/auth/middleware.js +194 -0
- package/dist/auth/middleware.js.map +1 -0
- package/dist/auth/permissions.d.ts +60 -0
- package/dist/auth/permissions.d.ts.map +1 -0
- package/dist/auth/permissions.js +262 -0
- package/dist/auth/permissions.js.map +1 -0
- package/dist/auth/token-validator.d.ts +52 -0
- package/dist/auth/token-validator.d.ts.map +1 -0
- package/dist/auth/token-validator.js +215 -0
- package/dist/auth/token-validator.js.map +1 -0
- package/dist/cache/cache-manager.d.ts +49 -0
- package/dist/cache/cache-manager.d.ts.map +1 -0
- package/dist/cache/cache-manager.js +191 -0
- package/dist/cache/cache-manager.js.map +1 -0
- package/dist/cache/index.d.ts +6 -0
- package/dist/cache/index.d.ts.map +1 -0
- package/dist/cache/index.js +12 -0
- package/dist/cache/index.js.map +1 -0
- package/dist/cache/redis-client.d.ts +45 -0
- package/dist/cache/redis-client.d.ts.map +1 -0
- package/dist/cache/redis-client.js +210 -0
- package/dist/cache/redis-client.js.map +1 -0
- package/dist/config/constants.d.ts +28 -0
- package/dist/config/constants.d.ts.map +1 -0
- package/dist/config/constants.js +31 -0
- package/dist/config/constants.js.map +1 -0
- package/dist/config/index.d.ts +71 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +190 -0
- package/dist/config/index.js.map +1 -0
- package/dist/filesystem/manager.d.ts +45 -0
- package/dist/filesystem/manager.d.ts.map +1 -0
- package/dist/filesystem/manager.js +246 -0
- package/dist/filesystem/manager.js.map +1 -0
- package/dist/git/multi-source-manager.d.ts +105 -0
- package/dist/git/multi-source-manager.d.ts.map +1 -0
- package/dist/git/multi-source-manager.js +677 -0
- package/dist/git/multi-source-manager.js.map +1 -0
- package/dist/git/operations.d.ts +27 -0
- package/dist/git/operations.d.ts.map +1 -0
- package/dist/git/operations.js +83 -0
- package/dist/git/operations.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +122 -0
- package/dist/index.js.map +1 -0
- package/dist/monitoring/health.d.ts +35 -0
- package/dist/monitoring/health.d.ts.map +1 -0
- package/dist/monitoring/health.js +105 -0
- package/dist/monitoring/health.js.map +1 -0
- package/dist/prompts/cache.d.ts +69 -0
- package/dist/prompts/cache.d.ts.map +1 -0
- package/dist/prompts/cache.js +163 -0
- package/dist/prompts/cache.js.map +1 -0
- package/dist/prompts/generator.d.ts +49 -0
- package/dist/prompts/generator.d.ts.map +1 -0
- package/dist/prompts/generator.js +160 -0
- package/dist/prompts/generator.js.map +1 -0
- package/dist/prompts/index.d.ts +13 -0
- package/dist/prompts/index.d.ts.map +1 -0
- package/dist/prompts/index.js +24 -0
- package/dist/prompts/index.js.map +1 -0
- package/dist/prompts/manager.d.ts +213 -0
- package/dist/prompts/manager.d.ts.map +1 -0
- package/dist/prompts/manager.js +587 -0
- package/dist/prompts/manager.js.map +1 -0
- package/dist/resources/index.d.ts +6 -0
- package/dist/resources/index.d.ts.map +1 -0
- package/dist/resources/index.js +10 -0
- package/dist/resources/index.js.map +1 -0
- package/dist/resources/loader.d.ts +88 -0
- package/dist/resources/loader.d.ts.map +1 -0
- package/dist/resources/loader.js +492 -0
- package/dist/resources/loader.js.map +1 -0
- package/dist/server/http.d.ts +57 -0
- package/dist/server/http.d.ts.map +1 -0
- package/dist/server/http.js +435 -0
- package/dist/server/http.js.map +1 -0
- package/dist/server.d.ts +13 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +201 -0
- package/dist/server.js.map +1 -0
- package/dist/session/manager.d.ts +91 -0
- package/dist/session/manager.d.ts.map +1 -0
- package/dist/session/manager.js +251 -0
- package/dist/session/manager.js.map +1 -0
- package/dist/telemetry/index.d.ts +3 -0
- package/dist/telemetry/index.d.ts.map +1 -0
- package/dist/telemetry/index.js +7 -0
- package/dist/telemetry/index.js.map +1 -0
- package/dist/telemetry/manager.d.ts +151 -0
- package/dist/telemetry/manager.d.ts.map +1 -0
- package/dist/telemetry/manager.js +367 -0
- package/dist/telemetry/manager.js.map +1 -0
- package/dist/tools/index.d.ts +13 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +29 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/manage-subscription.d.ts +47 -0
- package/dist/tools/manage-subscription.d.ts.map +1 -0
- package/dist/tools/manage-subscription.js +317 -0
- package/dist/tools/manage-subscription.js.map +1 -0
- package/dist/tools/registry.d.ts +40 -0
- package/dist/tools/registry.d.ts.map +1 -0
- package/dist/tools/registry.js +85 -0
- package/dist/tools/registry.js.map +1 -0
- package/dist/tools/resolve-prompt-content.d.ts +35 -0
- package/dist/tools/resolve-prompt-content.d.ts.map +1 -0
- package/dist/tools/resolve-prompt-content.js +99 -0
- package/dist/tools/resolve-prompt-content.js.map +1 -0
- package/dist/tools/search-resources.d.ts +35 -0
- package/dist/tools/search-resources.d.ts.map +1 -0
- package/dist/tools/search-resources.js +159 -0
- package/dist/tools/search-resources.js.map +1 -0
- package/dist/tools/sync-resources.d.ts +54 -0
- package/dist/tools/sync-resources.d.ts.map +1 -0
- package/dist/tools/sync-resources.js +793 -0
- package/dist/tools/sync-resources.js.map +1 -0
- package/dist/tools/track-usage.d.ts +63 -0
- package/dist/tools/track-usage.d.ts.map +1 -0
- package/dist/tools/track-usage.js +90 -0
- package/dist/tools/track-usage.js.map +1 -0
- package/dist/tools/uninstall-resource.d.ts +30 -0
- package/dist/tools/uninstall-resource.d.ts.map +1 -0
- package/dist/tools/uninstall-resource.js +186 -0
- package/dist/tools/uninstall-resource.js.map +1 -0
- package/dist/tools/upload-resource.d.ts +81 -0
- package/dist/tools/upload-resource.d.ts.map +1 -0
- package/dist/tools/upload-resource.js +393 -0
- package/dist/tools/upload-resource.js.map +1 -0
- package/dist/transport/sse.d.ts +29 -0
- package/dist/transport/sse.d.ts.map +1 -0
- package/dist/transport/sse.js +271 -0
- package/dist/transport/sse.js.map +1 -0
- package/dist/types/errors.d.ts +60 -0
- package/dist/types/errors.d.ts.map +1 -0
- package/dist/types/errors.js +112 -0
- package/dist/types/errors.js.map +1 -0
- package/dist/types/index.d.ts +7 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +23 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/mcp.d.ts +50 -0
- package/dist/types/mcp.d.ts.map +1 -0
- package/dist/types/mcp.js +6 -0
- package/dist/types/mcp.js.map +1 -0
- package/dist/types/resources.d.ts +109 -0
- package/dist/types/resources.d.ts.map +1 -0
- package/dist/types/resources.js +7 -0
- package/dist/types/resources.js.map +1 -0
- package/dist/types/tools.d.ts +274 -0
- package/dist/types/tools.d.ts.map +1 -0
- package/dist/types/tools.js +6 -0
- package/dist/types/tools.js.map +1 -0
- package/dist/utils/cursor-paths.d.ts +84 -0
- package/dist/utils/cursor-paths.d.ts.map +1 -0
- package/dist/utils/cursor-paths.js +166 -0
- package/dist/utils/cursor-paths.js.map +1 -0
- package/dist/utils/log-cleaner.d.ts +18 -0
- package/dist/utils/log-cleaner.d.ts.map +1 -0
- package/dist/utils/log-cleaner.js +112 -0
- package/dist/utils/log-cleaner.js.map +1 -0
- package/dist/utils/logger.d.ts +59 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +292 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/validation.d.ts +58 -0
- package/dist/utils/validation.d.ts.map +1 -0
- package/dist/utils/validation.js +214 -0
- package/dist/utils/validation.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* PromptCache: manages the .prompt-cache/ directory inside the MCP Server's
|
|
4
|
+
* runtime working directory.
|
|
5
|
+
*
|
|
6
|
+
* Cache files hold the fully-expanded Prompt content for each Command/Skill
|
|
7
|
+
* resource so that the MCP Prompt handler can serve them without re-generating
|
|
8
|
+
* on every invocation.
|
|
9
|
+
*
|
|
10
|
+
* The cache directory is intentionally NOT committed to Git — it is regenerated
|
|
11
|
+
* from the canonical source files after every git pull or resource upload.
|
|
12
|
+
*
|
|
13
|
+
* File naming: {type}-{resource_id}.md
|
|
14
|
+
* e.g. cmd-client-sdk-generate-testcase.md
|
|
15
|
+
* skill-client-sdk-analyze-sdk-log.md
|
|
16
|
+
*/
|
|
17
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
18
|
+
if (k2 === undefined) k2 = k;
|
|
19
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
20
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
21
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
22
|
+
}
|
|
23
|
+
Object.defineProperty(o, k2, desc);
|
|
24
|
+
}) : (function(o, m, k, k2) {
|
|
25
|
+
if (k2 === undefined) k2 = k;
|
|
26
|
+
o[k2] = m[k];
|
|
27
|
+
}));
|
|
28
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
29
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
30
|
+
}) : function(o, v) {
|
|
31
|
+
o["default"] = v;
|
|
32
|
+
});
|
|
33
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
34
|
+
var ownKeys = function(o) {
|
|
35
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
36
|
+
var ar = [];
|
|
37
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
38
|
+
return ar;
|
|
39
|
+
};
|
|
40
|
+
return ownKeys(o);
|
|
41
|
+
};
|
|
42
|
+
return function (mod) {
|
|
43
|
+
if (mod && mod.__esModule) return mod;
|
|
44
|
+
var result = {};
|
|
45
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
46
|
+
__setModuleDefault(result, mod);
|
|
47
|
+
return result;
|
|
48
|
+
};
|
|
49
|
+
})();
|
|
50
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
51
|
+
exports.promptCache = exports.PromptCache = void 0;
|
|
52
|
+
const fs = __importStar(require("fs"));
|
|
53
|
+
const path = __importStar(require("path"));
|
|
54
|
+
const logger_js_1 = require("../utils/logger.js");
|
|
55
|
+
/** Relative directory name inside the MCP Server CWD for cached Prompt files. */
|
|
56
|
+
const CACHE_DIR_NAME = '.prompt-cache';
|
|
57
|
+
class PromptCache {
|
|
58
|
+
cacheDir;
|
|
59
|
+
/**
|
|
60
|
+
* @param baseDir Absolute base directory (defaults to process.cwd()).
|
|
61
|
+
*/
|
|
62
|
+
constructor(baseDir = process.cwd()) {
|
|
63
|
+
this.cacheDir = path.join(baseDir, CACHE_DIR_NAME);
|
|
64
|
+
}
|
|
65
|
+
/** Absolute path to the cache directory. */
|
|
66
|
+
get directory() {
|
|
67
|
+
return this.cacheDir;
|
|
68
|
+
}
|
|
69
|
+
/** Ensure the cache directory exists (idempotent). */
|
|
70
|
+
ensureDir() {
|
|
71
|
+
fs.mkdirSync(this.cacheDir, { recursive: true });
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Derive the cache file name for a resource.
|
|
75
|
+
* @param resourceType 'command' | 'skill'
|
|
76
|
+
* @param resourceId Canonical resource ID
|
|
77
|
+
*/
|
|
78
|
+
cacheFileName(resourceType, resourceId) {
|
|
79
|
+
// Normalise type prefix: 'command' → 'cmd', 'skill' → 'skill'
|
|
80
|
+
const prefix = resourceType === 'command' ? 'cmd' : resourceType;
|
|
81
|
+
// Sanitise resourceId — remove characters unsafe in filenames.
|
|
82
|
+
const safeId = resourceId.replace(/[/\\:*?"<>|]/g, '-');
|
|
83
|
+
return `${prefix}-${safeId}.md`;
|
|
84
|
+
}
|
|
85
|
+
/** Absolute path to the cache file for a given resource. */
|
|
86
|
+
cachePath(resourceType, resourceId) {
|
|
87
|
+
return path.join(this.cacheDir, this.cacheFileName(resourceType, resourceId));
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Write (or overwrite) a resource's Prompt content to the cache.
|
|
91
|
+
* Uses atomic write-then-rename to prevent partial reads.
|
|
92
|
+
*
|
|
93
|
+
* @param resourceType 'command' | 'skill'
|
|
94
|
+
* @param resourceId Canonical resource ID
|
|
95
|
+
* @param content Fully-expanded Prompt Markdown content
|
|
96
|
+
*/
|
|
97
|
+
write(resourceType, resourceId, content) {
|
|
98
|
+
this.ensureDir();
|
|
99
|
+
const dest = this.cachePath(resourceType, resourceId);
|
|
100
|
+
const tmp = `${dest}.${process.pid}.tmp`;
|
|
101
|
+
try {
|
|
102
|
+
fs.writeFileSync(tmp, content, 'utf8');
|
|
103
|
+
fs.renameSync(tmp, dest);
|
|
104
|
+
logger_js_1.logger.debug({ resourceId, resourceType, path: dest }, 'Prompt cache written');
|
|
105
|
+
}
|
|
106
|
+
catch (err) {
|
|
107
|
+
// Best-effort cleanup of temp file
|
|
108
|
+
try {
|
|
109
|
+
fs.unlinkSync(tmp);
|
|
110
|
+
}
|
|
111
|
+
catch { /* ignore */ }
|
|
112
|
+
throw new Error(`Failed to write prompt cache for ${resourceId}: ${err.message}`);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Read the cached Prompt content for a resource.
|
|
117
|
+
* Returns null if the cache file does not exist or cannot be read.
|
|
118
|
+
*
|
|
119
|
+
* @param resourceType 'command' | 'skill'
|
|
120
|
+
* @param resourceId Canonical resource ID
|
|
121
|
+
*/
|
|
122
|
+
read(resourceType, resourceId) {
|
|
123
|
+
const p = this.cachePath(resourceType, resourceId);
|
|
124
|
+
try {
|
|
125
|
+
return fs.readFileSync(p, 'utf8');
|
|
126
|
+
}
|
|
127
|
+
catch {
|
|
128
|
+
return null;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Delete the cache file for a resource.
|
|
133
|
+
* Silently succeeds if the file does not exist.
|
|
134
|
+
*
|
|
135
|
+
* @param resourceType 'command' | 'skill'
|
|
136
|
+
* @param resourceId Canonical resource ID
|
|
137
|
+
*/
|
|
138
|
+
delete(resourceType, resourceId) {
|
|
139
|
+
const p = this.cachePath(resourceType, resourceId);
|
|
140
|
+
try {
|
|
141
|
+
fs.unlinkSync(p);
|
|
142
|
+
logger_js_1.logger.debug({ resourceId, resourceType }, 'Prompt cache deleted');
|
|
143
|
+
}
|
|
144
|
+
catch (err) {
|
|
145
|
+
if (err.code !== 'ENOENT') {
|
|
146
|
+
logger_js_1.logger.warn({ resourceId, error: err.message }, 'Failed to delete prompt cache file');
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Check whether a valid cache entry exists for a resource.
|
|
152
|
+
*
|
|
153
|
+
* @param resourceType 'command' | 'skill'
|
|
154
|
+
* @param resourceId Canonical resource ID
|
|
155
|
+
*/
|
|
156
|
+
exists(resourceType, resourceId) {
|
|
157
|
+
return fs.existsSync(this.cachePath(resourceType, resourceId));
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
exports.PromptCache = PromptCache;
|
|
161
|
+
/** Singleton cache instance using the process CWD as the base directory. */
|
|
162
|
+
exports.promptCache = new PromptCache();
|
|
163
|
+
//# sourceMappingURL=cache.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C,CAAC;YACjB,kBAAM,CAAC,KAAK,CAAC,EAAE,UAAU,EAAE,YAAY,EAAE,EAAE,sBAAsB,CAAC,CAAC;QACrE,CAAC;QAAC,OAAO,GAAY,EAAE,CAAC;YACtB,IAAK,GAA6B,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;gBACrD,kBAAM,CAAC,IAAI,CACT,EAAE,UAAU,EAAE,KAAK,EAAG,GAAa,CAAC,OAAO,EAAE,EAC7C,oCAAoC,CACrC,CAAC;YACJ,CAAC;QACH,CAAC;IACH,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,YAAoB,EAAE,UAAkB;QAC7C,OAAO,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,YAAY,EAAE,UAAU,CAAC,CAAC,CAAC;IACjE,CAAC;CACF;AAjHD,kCAiHC;AAED,4EAA4E;AAC/D,QAAA,WAAW,GAAG,IAAI,WAAW,EAAE,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PromptGenerator: converts raw Command/Skill Markdown assets into MCP Prompt content.
|
|
3
|
+
*
|
|
4
|
+
* Two-step pipeline:
|
|
5
|
+
* 1. parseMarkdownWithImports — recursively inline `import 'path'` directives.
|
|
6
|
+
* 2. replaceMDVariables — substitute ${VAR} placeholders with runtime values.
|
|
7
|
+
*
|
|
8
|
+
* The resulting string is returned to the caller who can pass it directly as
|
|
9
|
+
* the MCP Prompt message text, or write it to the .prompt-cache/ directory.
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Recursively resolve and inline all `import 'path'` statements in a Markdown
|
|
13
|
+
* file. Each imported file's content replaces its import statement in the
|
|
14
|
+
* parent document.
|
|
15
|
+
*
|
|
16
|
+
* @param filePath Absolute path to the root Markdown file.
|
|
17
|
+
* @param depth Current recursion depth (used for cycle detection).
|
|
18
|
+
* @returns Fully expanded Markdown string.
|
|
19
|
+
*/
|
|
20
|
+
export declare function parseMarkdownWithImports(filePath: string, depth?: number): Promise<string>;
|
|
21
|
+
/**
|
|
22
|
+
* Replace ${VARIABLE_NAME} placeholders in content with values from the
|
|
23
|
+
* provided variable map. Variables not found in the map are left unchanged so
|
|
24
|
+
* they remain visible in the output for debugging.
|
|
25
|
+
*
|
|
26
|
+
* @param content Markdown string (after import expansion).
|
|
27
|
+
* @param variables Key-value map of variable names to their replacement strings.
|
|
28
|
+
* @returns Content with placeholders substituted.
|
|
29
|
+
*/
|
|
30
|
+
export declare function replaceMDVariables(content: string, variables: Record<string, string>): string;
|
|
31
|
+
/**
|
|
32
|
+
* High-level entry point: expand imports then substitute variables.
|
|
33
|
+
*
|
|
34
|
+
* @param filePath Absolute path to the root Markdown file.
|
|
35
|
+
* @param variables Optional variable substitution map (defaults to empty).
|
|
36
|
+
* @returns Final Prompt content ready for MCP registration.
|
|
37
|
+
*/
|
|
38
|
+
export declare function generatePromptContent(filePath: string, variables?: Record<string, string>): Promise<string>;
|
|
39
|
+
/**
|
|
40
|
+
* Generate Prompt content from a raw Markdown string (no file I/O).
|
|
41
|
+
* Used when the resource content has already been downloaded from the API.
|
|
42
|
+
*
|
|
43
|
+
* @param rawContent Raw Markdown string.
|
|
44
|
+
* @param basePath Absolute directory used to resolve relative `import` paths.
|
|
45
|
+
* @param variables Optional variable substitution map.
|
|
46
|
+
* @returns Final Prompt content.
|
|
47
|
+
*/
|
|
48
|
+
export declare function generatePromptContentFromString(rawContent: string | undefined | null, basePath: string, variables?: Record<string, string>): Promise<string>;
|
|
49
|
+
//# sourceMappingURL=generator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../../src/prompts/generator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAYH;;;;;;;;GAQG;AACH,wBAAsB,wBAAwB,CAC5C,QAAQ,EAAE,MAAM,EAChB,KAAK,SAAI,GACR,OAAO,CAAC,MAAM,CAAC,CA6CjB;AAED;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAChC,MAAM,CAOR;AAED;;;;;;GAMG;AACH,wBAAsB,qBAAqB,CACzC,QAAQ,EAAE,MAAM,EAChB,SAAS,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,GACrC,OAAO,CAAC,MAAM,CAAC,CAGjB;AAED;;;;;;;;GAQG;AACH,wBAAsB,+BAA+B,CACnD,UAAU,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,EACrC,QAAQ,EAAE,MAAM,EAChB,SAAS,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,GACrC,OAAO,CAAC,MAAM,CAAC,CAajB"}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* PromptGenerator: converts raw Command/Skill Markdown assets into MCP Prompt content.
|
|
4
|
+
*
|
|
5
|
+
* Two-step pipeline:
|
|
6
|
+
* 1. parseMarkdownWithImports — recursively inline `import 'path'` directives.
|
|
7
|
+
* 2. replaceMDVariables — substitute ${VAR} placeholders with runtime values.
|
|
8
|
+
*
|
|
9
|
+
* The resulting string is returned to the caller who can pass it directly as
|
|
10
|
+
* the MCP Prompt message text, or write it to the .prompt-cache/ directory.
|
|
11
|
+
*/
|
|
12
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
13
|
+
if (k2 === undefined) k2 = k;
|
|
14
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
15
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
16
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
17
|
+
}
|
|
18
|
+
Object.defineProperty(o, k2, desc);
|
|
19
|
+
}) : (function(o, m, k, k2) {
|
|
20
|
+
if (k2 === undefined) k2 = k;
|
|
21
|
+
o[k2] = m[k];
|
|
22
|
+
}));
|
|
23
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
24
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
25
|
+
}) : function(o, v) {
|
|
26
|
+
o["default"] = v;
|
|
27
|
+
});
|
|
28
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
29
|
+
var ownKeys = function(o) {
|
|
30
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
31
|
+
var ar = [];
|
|
32
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
33
|
+
return ar;
|
|
34
|
+
};
|
|
35
|
+
return ownKeys(o);
|
|
36
|
+
};
|
|
37
|
+
return function (mod) {
|
|
38
|
+
if (mod && mod.__esModule) return mod;
|
|
39
|
+
var result = {};
|
|
40
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
41
|
+
__setModuleDefault(result, mod);
|
|
42
|
+
return result;
|
|
43
|
+
};
|
|
44
|
+
})();
|
|
45
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
46
|
+
exports.parseMarkdownWithImports = parseMarkdownWithImports;
|
|
47
|
+
exports.replaceMDVariables = replaceMDVariables;
|
|
48
|
+
exports.generatePromptContent = generatePromptContent;
|
|
49
|
+
exports.generatePromptContentFromString = generatePromptContentFromString;
|
|
50
|
+
const fs = __importStar(require("fs"));
|
|
51
|
+
const path = __importStar(require("path"));
|
|
52
|
+
const logger_js_1 = require("../utils/logger.js");
|
|
53
|
+
// Maximum import recursion depth to guard against circular imports.
|
|
54
|
+
const MAX_IMPORT_DEPTH = 20;
|
|
55
|
+
// Matches lines like: import 'relative/path/to/file.md'
|
|
56
|
+
const IMPORT_REGEX = /^import\s+['"]([^'"]+)['"]\s*$/gm;
|
|
57
|
+
/**
|
|
58
|
+
* Recursively resolve and inline all `import 'path'` statements in a Markdown
|
|
59
|
+
* file. Each imported file's content replaces its import statement in the
|
|
60
|
+
* parent document.
|
|
61
|
+
*
|
|
62
|
+
* @param filePath Absolute path to the root Markdown file.
|
|
63
|
+
* @param depth Current recursion depth (used for cycle detection).
|
|
64
|
+
* @returns Fully expanded Markdown string.
|
|
65
|
+
*/
|
|
66
|
+
async function parseMarkdownWithImports(filePath, depth = 0) {
|
|
67
|
+
if (depth > MAX_IMPORT_DEPTH) {
|
|
68
|
+
throw new Error(`Import depth exceeded ${MAX_IMPORT_DEPTH} levels at ${filePath}. ` +
|
|
69
|
+
'Check for circular imports.');
|
|
70
|
+
}
|
|
71
|
+
let content;
|
|
72
|
+
try {
|
|
73
|
+
content = fs.readFileSync(filePath, 'utf8');
|
|
74
|
+
}
|
|
75
|
+
catch (err) {
|
|
76
|
+
throw new Error(`Cannot read Markdown file: ${filePath} — ${err.message}`);
|
|
77
|
+
}
|
|
78
|
+
const fileDir = path.dirname(filePath);
|
|
79
|
+
const matches = [];
|
|
80
|
+
let match;
|
|
81
|
+
// Reset lastIndex before each exec loop (regex is stateful with 'g' flag).
|
|
82
|
+
IMPORT_REGEX.lastIndex = 0;
|
|
83
|
+
while ((match = IMPORT_REGEX.exec(content)) !== null) {
|
|
84
|
+
const importPath = match[1];
|
|
85
|
+
if (importPath) {
|
|
86
|
+
matches.push({
|
|
87
|
+
statement: match[0],
|
|
88
|
+
resolvedPath: path.resolve(fileDir, importPath),
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
// Process imports sequentially to preserve insertion order.
|
|
93
|
+
for (const { statement, resolvedPath } of matches) {
|
|
94
|
+
try {
|
|
95
|
+
const importedContent = await parseMarkdownWithImports(resolvedPath, depth + 1);
|
|
96
|
+
content = content.replace(statement, importedContent);
|
|
97
|
+
}
|
|
98
|
+
catch (err) {
|
|
99
|
+
logger_js_1.logger.warn({ importPath: resolvedPath, parentFile: filePath, error: err.message }, 'Failed to resolve import — leaving placeholder in place');
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return content;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Replace ${VARIABLE_NAME} placeholders in content with values from the
|
|
106
|
+
* provided variable map. Variables not found in the map are left unchanged so
|
|
107
|
+
* they remain visible in the output for debugging.
|
|
108
|
+
*
|
|
109
|
+
* @param content Markdown string (after import expansion).
|
|
110
|
+
* @param variables Key-value map of variable names to their replacement strings.
|
|
111
|
+
* @returns Content with placeholders substituted.
|
|
112
|
+
*/
|
|
113
|
+
function replaceMDVariables(content, variables) {
|
|
114
|
+
let result = content;
|
|
115
|
+
for (const [key, value] of Object.entries(variables)) {
|
|
116
|
+
const regex = new RegExp(`\\$\\{${key}\\}`, 'g');
|
|
117
|
+
result = result.replace(regex, value);
|
|
118
|
+
}
|
|
119
|
+
return result;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* High-level entry point: expand imports then substitute variables.
|
|
123
|
+
*
|
|
124
|
+
* @param filePath Absolute path to the root Markdown file.
|
|
125
|
+
* @param variables Optional variable substitution map (defaults to empty).
|
|
126
|
+
* @returns Final Prompt content ready for MCP registration.
|
|
127
|
+
*/
|
|
128
|
+
async function generatePromptContent(filePath, variables = {}) {
|
|
129
|
+
const expanded = await parseMarkdownWithImports(filePath);
|
|
130
|
+
return replaceMDVariables(expanded, variables);
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Generate Prompt content from a raw Markdown string (no file I/O).
|
|
134
|
+
* Used when the resource content has already been downloaded from the API.
|
|
135
|
+
*
|
|
136
|
+
* @param rawContent Raw Markdown string.
|
|
137
|
+
* @param basePath Absolute directory used to resolve relative `import` paths.
|
|
138
|
+
* @param variables Optional variable substitution map.
|
|
139
|
+
* @returns Final Prompt content.
|
|
140
|
+
*/
|
|
141
|
+
async function generatePromptContentFromString(rawContent, basePath, variables = {}) {
|
|
142
|
+
if (!rawContent)
|
|
143
|
+
return '';
|
|
144
|
+
// Write to a temp file so parseMarkdownWithImports can resolve relative imports.
|
|
145
|
+
const tmpPath = path.join(basePath, `.tmp-prompt-${Date.now()}-${process.pid}.md`);
|
|
146
|
+
let result;
|
|
147
|
+
try {
|
|
148
|
+
fs.mkdirSync(basePath, { recursive: true });
|
|
149
|
+
fs.writeFileSync(tmpPath, rawContent, 'utf8');
|
|
150
|
+
result = await parseMarkdownWithImports(tmpPath);
|
|
151
|
+
}
|
|
152
|
+
finally {
|
|
153
|
+
try {
|
|
154
|
+
fs.unlinkSync(tmpPath);
|
|
155
|
+
}
|
|
156
|
+
catch { /* best-effort cleanup */ }
|
|
157
|
+
}
|
|
158
|
+
return replaceMDVariables(result, variables);
|
|
159
|
+
}
|
|
160
|
+
//# sourceMappingURL=generator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../src/prompts/generator.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqBH,4DAgDC;AAWD,gDAUC;AASD,sDAMC;AAWD,0EAiBC;AAnID,uCAAyB;AACzB,2CAA6B;AAC7B,kDAA4C;AAE5C,oEAAoE;AACpE,MAAM,gBAAgB,GAAG,EAAE,CAAC;AAE5B,yDAAyD;AACzD,MAAM,YAAY,GAAG,kCAAkC,CAAC;AAExD;;;;;;;;GAQG;AACI,KAAK,UAAU,wBAAwB,CAC5C,QAAgB,EAChB,KAAK,GAAG,CAAC;IAET,IAAI,KAAK,GAAG,gBAAgB,EAAE,CAAC;QAC7B,MAAM,IAAI,KAAK,CACb,yBAAyB,gBAAgB,cAAc,QAAQ,IAAI;YACnE,6BAA6B,CAC9B,CAAC;IACJ,CAAC;IAED,IAAI,OAAe,CAAC;IACpB,IAAI,CAAC;QACH,OAAO,GAAG,EAAE,CAAC,YAAY,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IAC9C,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,C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O,kBAAkB,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;AAC/C,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* prompts module — public API
|
|
3
|
+
*
|
|
4
|
+
* Exports:
|
|
5
|
+
* - PromptGenerator utilities (parseMarkdownWithImports, replaceMDVariables,
|
|
6
|
+
* generatePromptContent, generatePromptContentFromString)
|
|
7
|
+
* - PromptCache class and the shared singleton `promptCache`
|
|
8
|
+
* - PromptManager class and the shared singleton `promptManager`
|
|
9
|
+
*/
|
|
10
|
+
export { parseMarkdownWithImports, replaceMDVariables, generatePromptContent, generatePromptContentFromString, } from './generator.js';
|
|
11
|
+
export { PromptCache, promptCache } from './cache.js';
|
|
12
|
+
export { PromptManager, promptManager } from './manager.js';
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/prompts/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EACL,wBAAwB,EACxB,kBAAkB,EAClB,qBAAqB,EACrB,+BAA+B,GAChC,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEtD,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* prompts module — public API
|
|
4
|
+
*
|
|
5
|
+
* Exports:
|
|
6
|
+
* - PromptGenerator utilities (parseMarkdownWithImports, replaceMDVariables,
|
|
7
|
+
* generatePromptContent, generatePromptContentFromString)
|
|
8
|
+
* - PromptCache class and the shared singleton `promptCache`
|
|
9
|
+
* - PromptManager class and the shared singleton `promptManager`
|
|
10
|
+
*/
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.promptManager = exports.PromptManager = exports.promptCache = exports.PromptCache = exports.generatePromptContentFromString = exports.generatePromptContent = exports.replaceMDVariables = exports.parseMarkdownWithImports = void 0;
|
|
13
|
+
var generator_js_1 = require("./generator.js");
|
|
14
|
+
Object.defineProperty(exports, "parseMarkdownWithImports", { enumerable: true, get: function () { return generator_js_1.parseMarkdownWithImports; } });
|
|
15
|
+
Object.defineProperty(exports, "replaceMDVariables", { enumerable: true, get: function () { return generator_js_1.replaceMDVariables; } });
|
|
16
|
+
Object.defineProperty(exports, "generatePromptContent", { enumerable: true, get: function () { return generator_js_1.generatePromptContent; } });
|
|
17
|
+
Object.defineProperty(exports, "generatePromptContentFromString", { enumerable: true, get: function () { return generator_js_1.generatePromptContentFromString; } });
|
|
18
|
+
var cache_js_1 = require("./cache.js");
|
|
19
|
+
Object.defineProperty(exports, "PromptCache", { enumerable: true, get: function () { return cache_js_1.PromptCache; } });
|
|
20
|
+
Object.defineProperty(exports, "promptCache", { enumerable: true, get: function () { return cache_js_1.promptCache; } });
|
|
21
|
+
var manager_js_1 = require("./manager.js");
|
|
22
|
+
Object.defineProperty(exports, "PromptManager", { enumerable: true, get: function () { return manager_js_1.PromptManager; } });
|
|
23
|
+
Object.defineProperty(exports, "promptManager", { enumerable: true, get: function () { return manager_js_1.promptManager; } });
|
|
24
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/prompts/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG;;;AAEH,+CAKwB;AAJtB,wHAAA,wBAAwB,OAAA;AACxB,kHAAA,kBAAkB,OAAA;AAClB,qHAAA,qBAAqB,OAAA;AACrB,+HAAA,+BAA+B,OAAA;AAGjC,uCAAsD;AAA7C,uGAAA,WAAW,OAAA;AAAE,uGAAA,WAAW,OAAA;AAEjC,2CAA4D;AAAnD,2GAAA,aAAa,OAAA;AAAE,2GAAA,aAAa,OAAA"}
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PromptManager: manages the lifecycle of MCP Prompts for Command and Skill resources.
|
|
3
|
+
*
|
|
4
|
+
* Design decisions:
|
|
5
|
+
* - Uses the low-level MCP SDK `Server` class (same as the rest of this project)
|
|
6
|
+
* via `setRequestHandler` for `ListPromptsRequestSchema` and `GetPromptRequestSchema`.
|
|
7
|
+
* - Maintains an in-memory registry of registered prompts so list/get handlers
|
|
8
|
+
* can be served without touching the disk on every request.
|
|
9
|
+
* - Prompt content is read from the `.prompt-cache/` directory written by
|
|
10
|
+
* PromptGenerator. If the cache file is missing, a fallback message is returned.
|
|
11
|
+
* - `jira_id` is an optional Prompt argument; when provided it is forwarded to
|
|
12
|
+
* TelemetryManager so usage can be correlated with a Jira issue.
|
|
13
|
+
*
|
|
14
|
+
* Prompt naming convention: `{type}/{team}/{resource-name}`
|
|
15
|
+
* e.g. command/client-sdk/generate-testcase
|
|
16
|
+
* skill/client-sdk/analyze-sdk-log
|
|
17
|
+
*/
|
|
18
|
+
import type { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
19
|
+
import type { LocalAction } from '../types/tools.js';
|
|
20
|
+
export interface PromptResourceMeta {
|
|
21
|
+
/** Canonical resource ID from the CSP platform (e.g. "cmd-client-sdk-001"). */
|
|
22
|
+
resource_id: string;
|
|
23
|
+
/** 'command' | 'skill' */
|
|
24
|
+
resource_type: 'command' | 'skill';
|
|
25
|
+
/** Human-readable resource name. */
|
|
26
|
+
resource_name: string;
|
|
27
|
+
/** Team that owns the resource. */
|
|
28
|
+
team: string;
|
|
29
|
+
/** Description shown in the Cursor slash command menu. */
|
|
30
|
+
description: string;
|
|
31
|
+
/** Raw Markdown content of the resource (from API download). */
|
|
32
|
+
rawContent: string;
|
|
33
|
+
}
|
|
34
|
+
interface RegisteredPrompt {
|
|
35
|
+
name: string;
|
|
36
|
+
description: string;
|
|
37
|
+
meta: PromptResourceMeta;
|
|
38
|
+
}
|
|
39
|
+
export interface ResolvedPromptContent {
|
|
40
|
+
promptName: string;
|
|
41
|
+
description: string;
|
|
42
|
+
meta: PromptResourceMeta;
|
|
43
|
+
content: string;
|
|
44
|
+
contentSource: 'cache' | 'generated' | 'raw_fallback';
|
|
45
|
+
}
|
|
46
|
+
export declare class PromptManager {
|
|
47
|
+
/**
|
|
48
|
+
* Per-user prompt store: userToken → (promptName → RegisteredPrompt).
|
|
49
|
+
*
|
|
50
|
+
* Keeping prompts scoped to each user's token ensures that a ListPrompts
|
|
51
|
+
* request for user A never leaks user B's resources and vice-versa.
|
|
52
|
+
* The anonymous fallback key '' is used for non-authenticated connections.
|
|
53
|
+
*/
|
|
54
|
+
private readonly userPrompts;
|
|
55
|
+
/**
|
|
56
|
+
* Per-user cache of the most recent local_actions_required from sync_resources.
|
|
57
|
+
*
|
|
58
|
+
* Populated by storeSyncActions() after each background sync on connect.
|
|
59
|
+
* Consumed by GetPrompt(csp-ai-agent-setup) so the AI receives the actions
|
|
60
|
+
* directly in the prompt content without needing to call sync_resources again.
|
|
61
|
+
* Cleared after being served to avoid replaying stale actions on subsequent
|
|
62
|
+
* GetPrompt calls.
|
|
63
|
+
*/
|
|
64
|
+
private readonly userSyncActions;
|
|
65
|
+
/**
|
|
66
|
+
* Tracks which Server instances already have handlers installed.
|
|
67
|
+
* Each SSE connection creates a new Server instance, so we track per-instance
|
|
68
|
+
* rather than using a global boolean flag (which would skip registration on
|
|
69
|
+
* subsequent connections and cause "Method not found" errors).
|
|
70
|
+
*/
|
|
71
|
+
private readonly installedServers;
|
|
72
|
+
/** Return (or lazily create) the prompt Map for a given user token. */
|
|
73
|
+
private promptsFor;
|
|
74
|
+
/**
|
|
75
|
+
* Cache the local_actions_required result from the most recent background
|
|
76
|
+
* sync for a user. Called by http.ts after oninitialized sync completes.
|
|
77
|
+
*
|
|
78
|
+
* @param userToken The authenticated token identifying the user.
|
|
79
|
+
* @param actions The list of local file-system actions to execute.
|
|
80
|
+
*/
|
|
81
|
+
storeSyncActions(userToken: string, actions: LocalAction[]): void;
|
|
82
|
+
/**
|
|
83
|
+
* Consume and return the cached sync actions for a user.
|
|
84
|
+
* Returns undefined if no actions are cached (nothing to do).
|
|
85
|
+
* The cache is cleared after retrieval to prevent stale replays.
|
|
86
|
+
*/
|
|
87
|
+
consumeSyncActions(userToken: string): LocalAction[] | undefined;
|
|
88
|
+
/**
|
|
89
|
+
* Build the MCP Prompt name for a resource.
|
|
90
|
+
* Format: `{type}/{resource-name}`
|
|
91
|
+
*
|
|
92
|
+
* We deliberately omit the team segment: Cursor prepends the MCP server name
|
|
93
|
+
* already (e.g. "user-csp-ai-agent/"), so adding team would create an
|
|
94
|
+
* unnecessarily deep slash path in the UI. type + name is sufficient to be
|
|
95
|
+
* unique across commands and skills on this server.
|
|
96
|
+
*/
|
|
97
|
+
buildPromptName(meta: Pick<PromptResourceMeta, 'resource_type' | 'resource_name'>): string;
|
|
98
|
+
private normalizeJiraId;
|
|
99
|
+
/**
|
|
100
|
+
* Resolve a registered prompt by resource ID for a specific user.
|
|
101
|
+
*/
|
|
102
|
+
getByResourceId(resourceId: string, userToken: string): RegisteredPrompt | undefined;
|
|
103
|
+
/**
|
|
104
|
+
* Resolve the fully expanded prompt content for a registered prompt.
|
|
105
|
+
* This is the shared content path used by both native prompts/get and
|
|
106
|
+
* the resolve_prompt_content tool.
|
|
107
|
+
*/
|
|
108
|
+
resolvePromptContent(params: {
|
|
109
|
+
promptName?: string;
|
|
110
|
+
resourceId?: string;
|
|
111
|
+
userToken: string;
|
|
112
|
+
}): Promise<ResolvedPromptContent | undefined>;
|
|
113
|
+
/**
|
|
114
|
+
* Resolve prompt content and record usage telemetry server-side.
|
|
115
|
+
* Used by the stable tool fallback for dynamic workflows.
|
|
116
|
+
*/
|
|
117
|
+
resolvePromptContentForInvocation(params: {
|
|
118
|
+
promptName?: string;
|
|
119
|
+
resourceId?: string;
|
|
120
|
+
userToken: string;
|
|
121
|
+
jiraId?: string;
|
|
122
|
+
}): Promise<ResolvedPromptContent | undefined>;
|
|
123
|
+
/**
|
|
124
|
+
* Install `ListPrompts` and `GetPrompt` request handlers on the given MCP
|
|
125
|
+
* `Server` instance. Must be called once after the server is created, before
|
|
126
|
+
* `server.connect()`.
|
|
127
|
+
*
|
|
128
|
+
* @param server The MCP Server instance for this SSE connection.
|
|
129
|
+
* @param userToken The authenticated token for this connection's user.
|
|
130
|
+
* Used to attribute telemetry invocations to the correct user.
|
|
131
|
+
*
|
|
132
|
+
* Calling this a second time with the same server is a no-op.
|
|
133
|
+
*/
|
|
134
|
+
installHandlers(server: Server, userToken?: string): void;
|
|
135
|
+
/**
|
|
136
|
+
* Register (or refresh) a single resource as an MCP Prompt.
|
|
137
|
+
* Generates the intermediate cache file and adds the prompt to the registry.
|
|
138
|
+
* Safe to call for an already-registered prompt — it will update the entry.
|
|
139
|
+
*/
|
|
140
|
+
/**
|
|
141
|
+
* Build the telemetry header that is prepended to every Command/Skill prompt.
|
|
142
|
+
*
|
|
143
|
+
* When the AI receives this prompt it must call `track_usage` first so that
|
|
144
|
+
* the server records the invocation even though Cursor's slash command menu
|
|
145
|
+
* does not trigger `prompts/get`. The header is deliberately short and
|
|
146
|
+
* authoritative so the AI does not skip it.
|
|
147
|
+
*/
|
|
148
|
+
private buildTrackingHeader;
|
|
149
|
+
/**
|
|
150
|
+
* Remove the synthetic tracking header from prompt content.
|
|
151
|
+
* Tool-based prompt resolution records usage on the server directly, so the
|
|
152
|
+
* returned content should not ask the AI to call track_usage again.
|
|
153
|
+
*/
|
|
154
|
+
private stripTrackingHeader;
|
|
155
|
+
/**
|
|
156
|
+
* Build a guidance prefix for cross-resource invocation.
|
|
157
|
+
* This instructs the AI Agent how to handle references to other Commands/Skills
|
|
158
|
+
* to ensure telemetry tracking for every independent resource invocation.
|
|
159
|
+
*/
|
|
160
|
+
private buildCrossResourceGuidance;
|
|
161
|
+
/**
|
|
162
|
+
* Register (or refresh) a single resource as an MCP Prompt for a specific user.
|
|
163
|
+
* Generates the intermediate cache file and adds the prompt to the user's registry.
|
|
164
|
+
* Safe to call for an already-registered prompt — it will update the entry.
|
|
165
|
+
*
|
|
166
|
+
* @param meta Resource metadata including content.
|
|
167
|
+
* @param userToken The token of the user subscribing this prompt.
|
|
168
|
+
*/
|
|
169
|
+
registerPrompt(meta: PromptResourceMeta, userToken: string): Promise<void>;
|
|
170
|
+
/**
|
|
171
|
+
* Unregister a prompt for a specific user.
|
|
172
|
+
* @param resourceId The canonical resource ID.
|
|
173
|
+
* @param resourceType 'command' | 'skill'
|
|
174
|
+
* @param resourceName Resource name (used to reconstruct the prompt name).
|
|
175
|
+
* @param userToken The token of the user to remove the prompt from.
|
|
176
|
+
*/
|
|
177
|
+
unregisterPrompt(resourceId: string, resourceType: 'command' | 'skill', resourceName: string, userToken: string): void;
|
|
178
|
+
/**
|
|
179
|
+
* Refresh a prompt's cached content and description for a specific user.
|
|
180
|
+
* Equivalent to calling registerPrompt() again.
|
|
181
|
+
*/
|
|
182
|
+
refreshPrompt(meta: PromptResourceMeta, userToken: string): Promise<void>;
|
|
183
|
+
/**
|
|
184
|
+
* Re-register all provided resources as MCP Prompts for a specific user.
|
|
185
|
+
* Existing prompts NOT in the list are NOT removed (use pruneStalePrompts for that).
|
|
186
|
+
*/
|
|
187
|
+
refreshAllPrompts(resources: PromptResourceMeta[], userToken: string): Promise<void>;
|
|
188
|
+
/** Return the number of currently registered prompts for a given user. */
|
|
189
|
+
sizeFor(userToken: string): number;
|
|
190
|
+
/** Return the total number of registered prompts across all users. */
|
|
191
|
+
get size(): number;
|
|
192
|
+
/** Check if a prompt with the given name is currently registered for a user. */
|
|
193
|
+
has(promptName: string, userToken: string): boolean;
|
|
194
|
+
/** Return the registered prompt metadata for a given prompt name and user, or undefined. */
|
|
195
|
+
getByPromptName(promptName: string, userToken: string): RegisteredPrompt | undefined;
|
|
196
|
+
/** Return a snapshot of all registered prompt names for a given user. */
|
|
197
|
+
promptNames(userToken: string): string[];
|
|
198
|
+
/**
|
|
199
|
+
* Remove any prompts for a specific user whose names are NOT in the provided
|
|
200
|
+
* set of expected prompt names built from the current subscription list.
|
|
201
|
+
*
|
|
202
|
+
* Call this after every sync_resources run to prevent stale prompts from
|
|
203
|
+
* accumulating across subscription changes.
|
|
204
|
+
*
|
|
205
|
+
* @param expectedNames Set of prompt names that SHOULD exist for this user.
|
|
206
|
+
* @param userToken The token identifying the user's prompt namespace.
|
|
207
|
+
*/
|
|
208
|
+
pruneStalePrompts(expectedNames: Set<string>, userToken: string): void;
|
|
209
|
+
}
|
|
210
|
+
/** Singleton PromptManager shared across the server process. */
|
|
211
|
+
export declare const promptManager: PromptManager;
|
|
212
|
+
export {};
|
|
213
|
+
//# sourceMappingURL=manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../../src/prompts/manager.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAMH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AAKxE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAErD,MAAM,WAAW,kBAAkB;IACjC,+EAA+E;IAC/E,WAAW,EAAE,MAAM,CAAC;IACpB,0BAA0B;IAC1B,aAAa,EAAE,SAAS,GAAG,OAAO,CAAC;IACnC,oCAAoC;IACpC,aAAa,EAAE,MAAM,CAAC;IACtB,mCAAmC;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,0DAA0D;IAC1D,WAAW,EAAE,MAAM,CAAC;IACpB,gEAAgE;IAChE,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,UAAU,gBAAgB;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,kBAAkB,CAAC;CAC1B;AAED,MAAM,WAAW,qBAAqB;IACpC,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,kBAAk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