@elliotding/ai-agent-mcp 0.1.26 → 0.1.27
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/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 +281 -0
- package/dist/api/client.d.ts.map +1 -0
- package/dist/api/client.js +371 -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 +78 -0
- package/dist/git/multi-source-manager.d.ts.map +1 -0
- package/dist/git/multi-source-manager.js +577 -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 +207 -0
- package/dist/prompts/manager.d.ts.map +1 -0
- package/dist/prompts/manager.js +566 -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 +735 -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 +174 -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 +253 -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,317 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* manage_subscription Tool
|
|
4
|
+
* Manage resource subscriptions
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.manageSubscriptionTool = void 0;
|
|
8
|
+
exports.manageSubscription = manageSubscription;
|
|
9
|
+
const logger_1 = require("../utils/logger");
|
|
10
|
+
const client_1 = require("../api/client");
|
|
11
|
+
const errors_1 = require("../types/errors");
|
|
12
|
+
const sync_resources_1 = require("./sync-resources");
|
|
13
|
+
const uninstall_resource_1 = require("./uninstall-resource");
|
|
14
|
+
const index_js_1 = require("../prompts/index.js");
|
|
15
|
+
async function manageSubscription(params) {
|
|
16
|
+
const startTime = Date.now();
|
|
17
|
+
// Type assertion for params
|
|
18
|
+
const typedParams = params;
|
|
19
|
+
logger_1.logger.info({ tool: 'manage_subscription', params }, 'manage_subscription called');
|
|
20
|
+
try {
|
|
21
|
+
let result;
|
|
22
|
+
switch (typedParams.action) {
|
|
23
|
+
case 'subscribe': {
|
|
24
|
+
// Validate resource_ids
|
|
25
|
+
if (!typedParams.resource_ids || typedParams.resource_ids.length === 0) {
|
|
26
|
+
throw (0, errors_1.createValidationError)('resource_ids', 'array', 'resource_ids is required for subscribe action');
|
|
27
|
+
}
|
|
28
|
+
logger_1.logger.debug({ resourceIds: typedParams.resource_ids, autoSync: typedParams.auto_sync }, 'Subscribing to resources...');
|
|
29
|
+
// Subscribe to resources
|
|
30
|
+
const subResult = await client_1.apiClient.subscribe(typedParams.resource_ids, typedParams.auto_sync, undefined, typedParams.user_token);
|
|
31
|
+
logger_1.logger.info({ count: subResult.subscriptions.length }, 'Resources subscribed successfully');
|
|
32
|
+
// Auto-sync newly subscribed resources immediately (default: true)
|
|
33
|
+
const shouldAutoSync = typedParams.auto_sync !== false;
|
|
34
|
+
let syncSummary;
|
|
35
|
+
let syncDetails;
|
|
36
|
+
let pendingSetup;
|
|
37
|
+
if (shouldAutoSync && subResult.subscriptions.length > 0) {
|
|
38
|
+
logger_1.logger.info({ resourceIds: typedParams.resource_ids }, 'Auto-syncing newly subscribed resources...');
|
|
39
|
+
const syncResult = await (0, sync_resources_1.syncResources)({
|
|
40
|
+
mode: 'incremental',
|
|
41
|
+
scope: typedParams.scope || 'global',
|
|
42
|
+
user_token: typedParams.user_token,
|
|
43
|
+
});
|
|
44
|
+
if (syncResult.success && syncResult.data) {
|
|
45
|
+
const sd = syncResult.data;
|
|
46
|
+
syncSummary = `Auto-sync: ${sd.summary.synced} synced, ${sd.summary.cached} cached, ${sd.summary.failed} failed`;
|
|
47
|
+
syncDetails = sd.details.map(d => ({ id: d.id, name: d.name, action: d.action }));
|
|
48
|
+
if (sd.pending_setup && sd.pending_setup.length > 0) {
|
|
49
|
+
pendingSetup = sd.pending_setup;
|
|
50
|
+
}
|
|
51
|
+
logger_1.logger.info({ summary: sd.summary }, 'Auto-sync after subscribe completed');
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
logger_1.logger.warn({ error: syncResult.error }, 'Auto-sync after subscribe failed, subscription still recorded');
|
|
55
|
+
syncSummary = 'Auto-sync failed — run sync_resources manually if needed';
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
result = {
|
|
59
|
+
action: 'subscribe',
|
|
60
|
+
success: true,
|
|
61
|
+
subscriptions: subResult.subscriptions.map(sub => ({
|
|
62
|
+
id: sub.id,
|
|
63
|
+
name: sub.name,
|
|
64
|
+
type: sub.type,
|
|
65
|
+
subscribed_at: sub.subscribed_at,
|
|
66
|
+
})),
|
|
67
|
+
message: [
|
|
68
|
+
`Successfully subscribed to ${subResult.subscriptions.length} resource${subResult.subscriptions.length > 1 ? 's' : ''}.`,
|
|
69
|
+
syncSummary,
|
|
70
|
+
'If you need to execute a newly subscribed Command or Skill in this same conversation, call resolve_prompt_content next to retrieve the real prompt body.',
|
|
71
|
+
].filter(Boolean).join(' '),
|
|
72
|
+
...(syncDetails ? { sync_details: syncDetails } : {}),
|
|
73
|
+
...(pendingSetup ? { pending_setup: pendingSetup } : {}),
|
|
74
|
+
};
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
case 'unsubscribe': {
|
|
78
|
+
// Validate resource_ids
|
|
79
|
+
if (!typedParams.resource_ids || typedParams.resource_ids.length === 0) {
|
|
80
|
+
throw (0, errors_1.createValidationError)('resource_ids', 'array', 'resource_ids is required for unsubscribe action');
|
|
81
|
+
}
|
|
82
|
+
logger_1.logger.debug({ resourceIds: typedParams.resource_ids }, 'Unsubscribing from resources...');
|
|
83
|
+
// Build a resource_id → type map from the current subscription list so
|
|
84
|
+
// uninstall actions can be scoped precisely to rule vs mcp resources.
|
|
85
|
+
let idToType = new Map();
|
|
86
|
+
try {
|
|
87
|
+
const currentSubs = await client_1.apiClient.getSubscriptions({}, typedParams.user_token);
|
|
88
|
+
for (const s of currentSubs.subscriptions) {
|
|
89
|
+
idToType.set(s.id, s.type);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
catch (e) {
|
|
93
|
+
logger_1.logger.warn({ error: e.message }, 'Could not fetch subscriptions for type resolution — uninstall will emit both rule+mcp actions as fallback');
|
|
94
|
+
}
|
|
95
|
+
// Cancel server-side subscription
|
|
96
|
+
await client_1.apiClient.unsubscribe(typedParams.resource_ids, typedParams.user_token);
|
|
97
|
+
logger_1.logger.info({ count: typedParams.resource_ids.length }, 'Server-side subscriptions removed');
|
|
98
|
+
// Uninstall local files and MCP config for each resource.
|
|
99
|
+
// For Command/Skill: unregister MCP Prompt instead of deleting local files.
|
|
100
|
+
const uninstallResults = [];
|
|
101
|
+
for (const resourceId of typedParams.resource_ids) {
|
|
102
|
+
// Determine if this is a Command or Skill by checking the prompt registry.
|
|
103
|
+
// API resource IDs are UUIDs (e.g. "0ccd800f..."), NOT prefixed with "cmd-"/"skill-".
|
|
104
|
+
// Check whether any registered prompt for this user matches the resource_id.
|
|
105
|
+
const matchedPromptName = index_js_1.promptManager.promptNames(typedParams.user_token ?? '').find((name) => {
|
|
106
|
+
// Prompt names are "<type>/<resource_name>"; check by looking up the registered meta.
|
|
107
|
+
const registered = index_js_1.promptManager.getByPromptName(name, typedParams.user_token ?? '');
|
|
108
|
+
return registered?.meta?.resource_id === resourceId;
|
|
109
|
+
});
|
|
110
|
+
if (matchedPromptName) {
|
|
111
|
+
const parts = matchedPromptName.split('/');
|
|
112
|
+
const resourceType = (parts[0] ?? 'command');
|
|
113
|
+
const resourceName = parts.slice(1).join('/') || matchedPromptName;
|
|
114
|
+
index_js_1.promptManager.unregisterPrompt(resourceId, resourceType, resourceName, typedParams.user_token ?? '');
|
|
115
|
+
uninstallResults.push({ id: resourceId, removed: true, detail: `Unregistered MCP Prompt for "${resourceName}"` });
|
|
116
|
+
logger_1.logger.info({ resourceId, resourceType, matchedPromptName }, 'MCP Prompt unregistered on unsubscribe');
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
// Use the last segment of the resource ID as the search pattern
|
|
120
|
+
// e.g. "mcp-client-sdk-ai-hub-jenkins" → "jenkins"
|
|
121
|
+
// "rule-csp-elliotTest" → "elliotTest"
|
|
122
|
+
const namePart = resourceId.split('-').slice(-1)[0] ||
|
|
123
|
+
resourceId.split('-').slice(-2).join('-') ||
|
|
124
|
+
resourceId;
|
|
125
|
+
// Try full name match first (e.g. "elliotTest"), fallback to last segment
|
|
126
|
+
const patternsToTry = Array.from(new Set([
|
|
127
|
+
resourceId, // full id
|
|
128
|
+
resourceId.replace(/^(skill|cmd|rule|mcp)-[^-]+-/, ''), // strip prefix+source
|
|
129
|
+
namePart,
|
|
130
|
+
]));
|
|
131
|
+
const resolvedType = idToType.get(resourceId);
|
|
132
|
+
let uninstalled = false;
|
|
133
|
+
for (const pattern of patternsToTry) {
|
|
134
|
+
const uninstallResult = await (0, uninstall_resource_1.uninstallResource)({
|
|
135
|
+
resource_id_or_name: pattern,
|
|
136
|
+
remove_from_account: false, // already unsubscribed above
|
|
137
|
+
...(resolvedType ? { resource_type: resolvedType } : {}),
|
|
138
|
+
});
|
|
139
|
+
if (uninstallResult.success && uninstallResult.data && uninstallResult.data.removed_resources.length > 0) {
|
|
140
|
+
uninstallResults.push({ id: resourceId, removed: true, detail: `Removed local files for "${pattern}"` });
|
|
141
|
+
uninstalled = true;
|
|
142
|
+
break;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
if (!uninstalled) {
|
|
146
|
+
uninstallResults.push({ id: resourceId, removed: false, detail: 'No local files found (may not have been installed)' });
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
const removedCount = uninstallResults.filter(r => r.removed).length;
|
|
150
|
+
const notFoundCount = uninstallResults.filter(r => !r.removed).length;
|
|
151
|
+
result = {
|
|
152
|
+
action: 'unsubscribe',
|
|
153
|
+
success: true,
|
|
154
|
+
message: [
|
|
155
|
+
`Successfully unsubscribed from ${typedParams.resource_ids.length} resource${typedParams.resource_ids.length > 1 ? 's' : ''}.`,
|
|
156
|
+
removedCount > 0 ? `Removed local files for ${removedCount} resource${removedCount > 1 ? 's' : ''}.` : null,
|
|
157
|
+
notFoundCount > 0 ? `${notFoundCount} resource${notFoundCount > 1 ? 's were' : ' was'} not installed locally.` : null,
|
|
158
|
+
].filter(Boolean).join(' '),
|
|
159
|
+
sync_details: uninstallResults.map(r => ({ id: r.id, name: r.id, action: r.removed ? 'uninstalled' : 'not_found_locally' })),
|
|
160
|
+
};
|
|
161
|
+
logger_1.logger.info({ count: typedParams.resource_ids.length, removedCount }, 'Resources unsubscribed and local files cleaned up');
|
|
162
|
+
break;
|
|
163
|
+
}
|
|
164
|
+
case 'list': {
|
|
165
|
+
logger_1.logger.debug({ scope: typedParams.scope || 'all' }, 'Listing subscriptions...');
|
|
166
|
+
// Get subscriptions list
|
|
167
|
+
const subs = await client_1.apiClient.getSubscriptions({}, typedParams.user_token);
|
|
168
|
+
result = {
|
|
169
|
+
action: 'list',
|
|
170
|
+
success: true,
|
|
171
|
+
subscriptions: subs.subscriptions.map(sub => ({
|
|
172
|
+
id: sub.id,
|
|
173
|
+
name: sub.name,
|
|
174
|
+
type: sub.type,
|
|
175
|
+
subscribed_at: sub.subscribed_at,
|
|
176
|
+
})),
|
|
177
|
+
message: `Found ${subs.total} subscription${subs.total !== 1 ? 's' : ''}`,
|
|
178
|
+
};
|
|
179
|
+
logger_1.logger.info({ total: subs.total }, 'Subscriptions listed successfully');
|
|
180
|
+
break;
|
|
181
|
+
}
|
|
182
|
+
case 'batch_subscribe': {
|
|
183
|
+
// Validate resource_ids
|
|
184
|
+
if (!typedParams.resource_ids || typedParams.resource_ids.length === 0) {
|
|
185
|
+
throw (0, errors_1.createValidationError)('resource_ids', 'array', 'resource_ids is required for batch_subscribe action');
|
|
186
|
+
}
|
|
187
|
+
logger_1.logger.debug({ count: typedParams.resource_ids.length, autoSync: typedParams.auto_sync }, 'Batch subscribing to resources...');
|
|
188
|
+
const batchSubResult = await client_1.apiClient.subscribe(typedParams.resource_ids, typedParams.auto_sync, undefined, typedParams.user_token);
|
|
189
|
+
logger_1.logger.info({ count: batchSubResult.subscriptions.length }, 'Batch subscription completed');
|
|
190
|
+
// Auto-sync newly subscribed resources immediately (default: true)
|
|
191
|
+
const shouldBatchAutoSync = typedParams.auto_sync !== false;
|
|
192
|
+
let batchSyncSummary;
|
|
193
|
+
let batchSyncDetails;
|
|
194
|
+
let batchPendingSetup;
|
|
195
|
+
if (shouldBatchAutoSync && batchSubResult.subscriptions.length > 0) {
|
|
196
|
+
logger_1.logger.info({ count: batchSubResult.subscriptions.length }, 'Auto-syncing batch subscribed resources...');
|
|
197
|
+
const batchSyncResult = await (0, sync_resources_1.syncResources)({
|
|
198
|
+
mode: 'incremental',
|
|
199
|
+
scope: typedParams.scope || 'global',
|
|
200
|
+
user_token: typedParams.user_token,
|
|
201
|
+
});
|
|
202
|
+
if (batchSyncResult.success && batchSyncResult.data) {
|
|
203
|
+
const sd = batchSyncResult.data;
|
|
204
|
+
batchSyncSummary = `Auto-sync: ${sd.summary.synced} synced, ${sd.summary.cached} cached, ${sd.summary.failed} failed`;
|
|
205
|
+
batchSyncDetails = sd.details.map(d => ({ id: d.id, name: d.name, action: d.action }));
|
|
206
|
+
if (sd.pending_setup && sd.pending_setup.length > 0) {
|
|
207
|
+
batchPendingSetup = sd.pending_setup;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
else {
|
|
211
|
+
batchSyncSummary = 'Auto-sync failed — run sync_resources manually if needed';
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
result = {
|
|
215
|
+
action: 'batch_subscribe',
|
|
216
|
+
success: true,
|
|
217
|
+
subscriptions: batchSubResult.subscriptions.map(sub => ({
|
|
218
|
+
id: sub.id,
|
|
219
|
+
name: sub.name,
|
|
220
|
+
type: sub.type,
|
|
221
|
+
subscribed_at: sub.subscribed_at,
|
|
222
|
+
})),
|
|
223
|
+
message: [
|
|
224
|
+
`Successfully batch subscribed to ${batchSubResult.subscriptions.length} resource${batchSubResult.subscriptions.length > 1 ? 's' : ''}.`,
|
|
225
|
+
batchSyncSummary,
|
|
226
|
+
].filter(Boolean).join(' '),
|
|
227
|
+
...(batchSyncDetails ? { sync_details: batchSyncDetails } : {}),
|
|
228
|
+
...(batchPendingSetup ? { pending_setup: batchPendingSetup } : {}),
|
|
229
|
+
};
|
|
230
|
+
break;
|
|
231
|
+
}
|
|
232
|
+
case 'batch_unsubscribe': {
|
|
233
|
+
// Validate resource_ids
|
|
234
|
+
if (!typedParams.resource_ids || typedParams.resource_ids.length === 0) {
|
|
235
|
+
throw (0, errors_1.createValidationError)('resource_ids', 'array', 'resource_ids is required for batch_unsubscribe action');
|
|
236
|
+
}
|
|
237
|
+
logger_1.logger.debug({ count: typedParams.resource_ids.length }, 'Batch unsubscribing from resources...');
|
|
238
|
+
// Delegate entirely to the unsubscribe case for unified cleanup logic
|
|
239
|
+
return manageSubscription({ ...typedParams, action: 'unsubscribe' });
|
|
240
|
+
}
|
|
241
|
+
default: {
|
|
242
|
+
throw (0, errors_1.createValidationError)('action', 'string', `Unknown action. Must be one of: subscribe, unsubscribe, list, batch_subscribe, batch_unsubscribe`);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
const duration = Date.now() - startTime;
|
|
246
|
+
(0, logger_1.logToolCall)('manage_subscription', 'user-id', params, duration);
|
|
247
|
+
logger_1.logger.info({
|
|
248
|
+
action: typedParams.action,
|
|
249
|
+
duration,
|
|
250
|
+
}, 'manage_subscription completed successfully');
|
|
251
|
+
return {
|
|
252
|
+
success: true,
|
|
253
|
+
data: result,
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
catch (error) {
|
|
257
|
+
logger_1.logger.error({ error, action: typedParams.action }, 'manage_subscription failed');
|
|
258
|
+
return {
|
|
259
|
+
success: false,
|
|
260
|
+
error: {
|
|
261
|
+
code: error instanceof errors_1.MCPServerError ? error.code : 'UNKNOWN_ERROR',
|
|
262
|
+
message: error instanceof Error ? error.message : String(error),
|
|
263
|
+
},
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
// Tool definition for registry
|
|
268
|
+
exports.manageSubscriptionTool = {
|
|
269
|
+
name: 'manage_subscription',
|
|
270
|
+
description: 'Manage resource subscriptions (subscribe, unsubscribe, list). ' +
|
|
271
|
+
'When action is "subscribe" or "batch_subscribe", the tool automatically syncs ' +
|
|
272
|
+
'the newly subscribed resources to the local machine immediately after subscribing ' +
|
|
273
|
+
'(auto_sync defaults to true). Pass auto_sync: false only when the user explicitly ' +
|
|
274
|
+
'says they do NOT want the resource installed right now. ' +
|
|
275
|
+
'For newly subscribed Command or Skill resources that must be used immediately in the same conversation, ' +
|
|
276
|
+
'follow with `resolve_prompt_content` after sync instead of assuming Cursor will fetch the prompt body automatically.',
|
|
277
|
+
inputSchema: {
|
|
278
|
+
type: 'object',
|
|
279
|
+
properties: {
|
|
280
|
+
action: {
|
|
281
|
+
type: 'string',
|
|
282
|
+
description: 'Action to perform',
|
|
283
|
+
enum: ['subscribe', 'unsubscribe', 'list', 'batch_subscribe', 'batch_unsubscribe'],
|
|
284
|
+
},
|
|
285
|
+
resource_ids: {
|
|
286
|
+
type: 'array',
|
|
287
|
+
description: 'Resource IDs (required for subscribe/unsubscribe actions)',
|
|
288
|
+
},
|
|
289
|
+
auto_sync: {
|
|
290
|
+
type: 'boolean',
|
|
291
|
+
description: 'Whether to immediately sync (install) the subscribed resources to the local machine after subscribing. ' +
|
|
292
|
+
'Defaults to true — omit this field in normal usage. ' +
|
|
293
|
+
'Set to false only when the user explicitly says they want to subscribe but NOT install yet.',
|
|
294
|
+
default: true,
|
|
295
|
+
},
|
|
296
|
+
scope: {
|
|
297
|
+
type: 'string',
|
|
298
|
+
description: 'Installation scope',
|
|
299
|
+
enum: ['global', 'workspace'],
|
|
300
|
+
default: 'global',
|
|
301
|
+
},
|
|
302
|
+
notify: {
|
|
303
|
+
type: 'boolean',
|
|
304
|
+
description: 'Enable update notifications',
|
|
305
|
+
default: true,
|
|
306
|
+
},
|
|
307
|
+
user_token: {
|
|
308
|
+
type: 'string',
|
|
309
|
+
description: 'DO NOT set this field — it is automatically injected by the MCP server from ' +
|
|
310
|
+
'the authenticated SSE connection. The server always provides the correct token.',
|
|
311
|
+
},
|
|
312
|
+
},
|
|
313
|
+
required: ['action'],
|
|
314
|
+
},
|
|
315
|
+
handler: manageSubscription,
|
|
316
|
+
};
|
|
317
|
+
//# sourceMappingURL=manage-subscription.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manage-subscription.js","sourceRoot":"","sources":["../../src/tools/manage-subscription.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAUH,gDAgUC;AAxUD,4CAAsD;AACtD,0CAA0C;AAC1C,4CAAwE;AAExE,qDAAiD;AACjD,6DAAyD;AACz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,WAAW,EAAE,aAAa,EAAE,MAAM,EAAE,iBAAiB,EAAE,mBAAmB,CAAC;aACnF;YACD,YAAY,EAAE;gBACZ,IAAI,EAAE,OAAO;gBACb,WAAW,EAAE,2DAA2D;aACzE;YACD,SAAS,EAAE;gBACT,IAAI,EAAE,SAAS;gBACf,WAAW,EACT,yGAAyG;oBACzG,sDAAsD;oBACtD,6FAA6F;gBAC/F,OAAO,EAAE,IAAI;aACd;YACD,KAAK,EAAE;gBACL,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,oBAAoB;gBACjC,IAAI,EAAE,CAAC,QAAQ,EAAE,WAAW,CAAC;gBAC7B,OAAO,EAAE,QAAQ;aAClB;YACD,MAAM,EAAE;gBACN,IAAI,EAAE,SAAS;gBACf,WAAW,EAAE,6BAA6B;gBAC1C,OAAO,EAAE,IAAI;aACd;YACD,UAAU,EAAE;gBACV,IAAI,EAAE,QAAQ;gBACd,WAAW,EACT,8EAA8E;oBAC9E,iFAAiF;aACpF;SACF;QACD,QAAQ,EAAE,CAAC,QAAQ,CAAC;KACrB;IACD,OAAO,EAAE,kBAAkB;CAC5B,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool Registry
|
|
3
|
+
* Central registry for MCP tools
|
|
4
|
+
*/
|
|
5
|
+
import type { ToolDefinition } from '../types/tools';
|
|
6
|
+
import type { MCPToolDefinition } from '../types/mcp';
|
|
7
|
+
declare class ToolRegistry {
|
|
8
|
+
private tools;
|
|
9
|
+
/**
|
|
10
|
+
* Register a tool
|
|
11
|
+
*/
|
|
12
|
+
registerTool(tool: ToolDefinition): void;
|
|
13
|
+
/**
|
|
14
|
+
* Get a tool by name
|
|
15
|
+
*/
|
|
16
|
+
getTool(name: string): ToolDefinition | undefined;
|
|
17
|
+
/**
|
|
18
|
+
* List all registered tools
|
|
19
|
+
*/
|
|
20
|
+
listTools(): ToolDefinition[];
|
|
21
|
+
/**
|
|
22
|
+
* Get MCP tool definitions (for tools/list response)
|
|
23
|
+
*/
|
|
24
|
+
getMCPToolDefinitions(): MCPToolDefinition[];
|
|
25
|
+
/**
|
|
26
|
+
* Check if a tool exists
|
|
27
|
+
*/
|
|
28
|
+
hasTool(name: string): boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Get tool count
|
|
31
|
+
*/
|
|
32
|
+
getToolCount(): number;
|
|
33
|
+
/**
|
|
34
|
+
* Call a tool by name with arguments
|
|
35
|
+
*/
|
|
36
|
+
callTool(name: string, args: Record<string, unknown>): Promise<unknown>;
|
|
37
|
+
}
|
|
38
|
+
export declare const toolRegistry: ToolRegistry;
|
|
39
|
+
export {};
|
|
40
|
+
//# sourceMappingURL=registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/tools/registry.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAEtD,cAAM,YAAY;IAChB,OAAO,CAAC,KAAK,CAA0C;IAEvD;;OAEG;IACH,YAAY,CAAC,IAAI,EAAE,cAAc,GAAG,IAAI;IASxC;;OAEG;IACH,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,cAAc,GAAG,SAAS;IAIjD;;OAEG;IACH,SAAS,IAAI,cAAc,EAAE;IAI7B;;OAEG;IACH,qBAAqB,IAAI,iBAAiB,EAAE;IAQ5C;;OAEG;IACH,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAI9B;;OAEG;IACH,YAAY,IAAI,MAAM;IAItB;;OAEG;IACG,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC;CA2B9E;AAGD,eAAO,MAAM,YAAY,cAAqB,CAAC"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Tool Registry
|
|
4
|
+
* Central registry for MCP tools
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.toolRegistry = void 0;
|
|
8
|
+
const logger_1 = require("../utils/logger");
|
|
9
|
+
class ToolRegistry {
|
|
10
|
+
tools = new Map();
|
|
11
|
+
/**
|
|
12
|
+
* Register a tool
|
|
13
|
+
*/
|
|
14
|
+
registerTool(tool) {
|
|
15
|
+
if (this.tools.has(tool.name)) {
|
|
16
|
+
throw new Error(`Tool '${tool.name}' is already registered`);
|
|
17
|
+
}
|
|
18
|
+
this.tools.set(tool.name, tool);
|
|
19
|
+
logger_1.logger.info({ toolName: tool.name }, `Tool registered: ${tool.name}`);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Get a tool by name
|
|
23
|
+
*/
|
|
24
|
+
getTool(name) {
|
|
25
|
+
return this.tools.get(name);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* List all registered tools
|
|
29
|
+
*/
|
|
30
|
+
listTools() {
|
|
31
|
+
return Array.from(this.tools.values());
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Get MCP tool definitions (for tools/list response)
|
|
35
|
+
*/
|
|
36
|
+
getMCPToolDefinitions() {
|
|
37
|
+
return this.listTools().map((tool) => ({
|
|
38
|
+
name: tool.name,
|
|
39
|
+
description: tool.description,
|
|
40
|
+
inputSchema: tool.inputSchema,
|
|
41
|
+
}));
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Check if a tool exists
|
|
45
|
+
*/
|
|
46
|
+
hasTool(name) {
|
|
47
|
+
return this.tools.has(name);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Get tool count
|
|
51
|
+
*/
|
|
52
|
+
getToolCount() {
|
|
53
|
+
return this.tools.size;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Call a tool by name with arguments
|
|
57
|
+
*/
|
|
58
|
+
async callTool(name, args) {
|
|
59
|
+
const tool = this.getTool(name);
|
|
60
|
+
if (!tool) {
|
|
61
|
+
throw new Error(`Tool '${name}' not found`);
|
|
62
|
+
}
|
|
63
|
+
logger_1.logger.debug({ toolName: name, args }, 'Calling tool');
|
|
64
|
+
try {
|
|
65
|
+
const result = await tool.handler(args);
|
|
66
|
+
// Debug: Log the result structure
|
|
67
|
+
logger_1.logger.debug({
|
|
68
|
+
toolName: name,
|
|
69
|
+
resultType: typeof result,
|
|
70
|
+
resultKeys: result && typeof result === 'object' ? Object.keys(result) : undefined,
|
|
71
|
+
hasSuccess: result && typeof result === 'object' && 'success' in result,
|
|
72
|
+
hasData: result && typeof result === 'object' && 'data' in result,
|
|
73
|
+
hasError: result && typeof result === 'object' && 'error' in result
|
|
74
|
+
}, 'Tool execution result structure');
|
|
75
|
+
return result;
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
logger_1.logger.error({ toolName: name, error, errorType: typeof error, errorMessage: error instanceof Error ? error.message : String(error) }, 'Tool execution threw error');
|
|
79
|
+
throw error;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
// Global singleton
|
|
84
|
+
exports.toolRegistry = new ToolRegistry();
|
|
85
|
+
//# sourceMappingURL=registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/tools/registry.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,4CAAyC;AAIzC,MAAM,YAAY;IACR,KAAK,GAAgC,IAAI,GAAG,EAAE,CAAC;IAEvD;;OAEG;IACH,YAAY,CAAC,IAAoB;QAC/B,IAAI,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;YAC9B,MAAM,IAAI,KAAK,CAAC,SAAS,IAAI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without relying on Cursor to issue prompts/get.
|
|
6
|
+
*/
|
|
7
|
+
import type { ResolvePromptContentResult, ToolResult } from '../types/tools';
|
|
8
|
+
export declare function resolvePromptContent(params: unknown): Promise<ToolResult<ResolvePromptContentResult>>;
|
|
9
|
+
export declare const resolvePromptContentTool: {
|
|
10
|
+
name: string;
|
|
11
|
+
description: string;
|
|
12
|
+
inputSchema: {
|
|
13
|
+
type: "object";
|
|
14
|
+
properties: {
|
|
15
|
+
prompt_name: {
|
|
16
|
+
type: string;
|
|
17
|
+
description: string;
|
|
18
|
+
};
|
|
19
|
+
resource_id: {
|
|
20
|
+
type: string;
|
|
21
|
+
description: string;
|
|
22
|
+
};
|
|
23
|
+
user_token: {
|
|
24
|
+
type: string;
|
|
25
|
+
description: string;
|
|
26
|
+
};
|
|
27
|
+
jira_id: {
|
|
28
|
+
type: string;
|
|
29
|
+
description: string;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
handler: typeof resolvePromptContent;
|
|
34
|
+
};
|
|
35
|
+
//# sourceMappingURL=resolve-prompt-content.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve-prompt-content.d.ts","sourceRoot":"","sources":["../../src/tools/resolve-prompt-content.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,KAAK,EAEV,0BAA0B,EAC1B,UAAU,EACX,MAAM,gBAAgB,CAAC;AAExB,wBAAsB,oBAAoB,CACxC,MAAM,EAAE,OAAO,GACd,OAAO,CAAC,UAAU,CAAC,0BAA0B,CAAC,CAAC,CAgEjD;AAED,eAAO,MAAM,wBAAwB;;;;;;;;;;;;;;;;;;;;;;;;;CA6BpC,CAAC"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* resolve_prompt_content Tool
|
|
4
|
+
*
|
|
5
|
+
* Stable fallback for retrieving the fully resolved body of a dynamically
|
|
6
|
+
* subscribed Command or Skill without relying on Cursor to issue prompts/get.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.resolvePromptContentTool = void 0;
|
|
10
|
+
exports.resolvePromptContent = resolvePromptContent;
|
|
11
|
+
const logger_1 = require("../utils/logger");
|
|
12
|
+
const index_js_1 = require("../prompts/index.js");
|
|
13
|
+
async function resolvePromptContent(params) {
|
|
14
|
+
const p = params;
|
|
15
|
+
const promptName = typeof p.prompt_name === 'string' && p.prompt_name.trim() !== ''
|
|
16
|
+
? p.prompt_name.trim()
|
|
17
|
+
: undefined;
|
|
18
|
+
const resourceId = typeof p.resource_id === 'string' && p.resource_id.trim() !== ''
|
|
19
|
+
? p.resource_id.trim()
|
|
20
|
+
: undefined;
|
|
21
|
+
const userToken = typeof p.user_token === 'string' ? p.user_token : '';
|
|
22
|
+
const jiraId = typeof p.jira_id === 'string' && p.jira_id.trim() !== ''
|
|
23
|
+
? p.jira_id.trim()
|
|
24
|
+
: undefined;
|
|
25
|
+
if (!promptName && !resourceId) {
|
|
26
|
+
return {
|
|
27
|
+
success: false,
|
|
28
|
+
error: {
|
|
29
|
+
code: 'VALIDATION_ERROR',
|
|
30
|
+
message: 'Either prompt_name or resource_id is required',
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
const resolved = await index_js_1.promptManager.resolvePromptContentForInvocation({
|
|
35
|
+
promptName,
|
|
36
|
+
resourceId,
|
|
37
|
+
userToken,
|
|
38
|
+
jiraId,
|
|
39
|
+
});
|
|
40
|
+
if (!resolved) {
|
|
41
|
+
const target = promptName ?? resourceId ?? 'unknown';
|
|
42
|
+
logger_1.logger.warn({ promptName, resourceId }, 'resolve_prompt_content: prompt not found');
|
|
43
|
+
return {
|
|
44
|
+
success: false,
|
|
45
|
+
error: {
|
|
46
|
+
code: 'PROMPT_NOT_FOUND',
|
|
47
|
+
message: `Prompt "${target}" is not available. Please run sync_resources first.`,
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
logger_1.logger.info({
|
|
52
|
+
promptName: resolved.promptName,
|
|
53
|
+
resourceId: resolved.meta.resource_id,
|
|
54
|
+
contentSource: resolved.contentSource,
|
|
55
|
+
}, 'resolve_prompt_content: prompt resolved successfully');
|
|
56
|
+
return {
|
|
57
|
+
success: true,
|
|
58
|
+
data: {
|
|
59
|
+
prompt_name: resolved.promptName,
|
|
60
|
+
resource_id: resolved.meta.resource_id,
|
|
61
|
+
resource_type: resolved.meta.resource_type,
|
|
62
|
+
resource_name: resolved.meta.resource_name,
|
|
63
|
+
description: resolved.description,
|
|
64
|
+
content: resolved.content,
|
|
65
|
+
content_source: resolved.contentSource,
|
|
66
|
+
usage_tracked: Boolean(userToken),
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
exports.resolvePromptContentTool = {
|
|
71
|
+
name: 'resolve_prompt_content',
|
|
72
|
+
description: 'Retrieve the fully resolved content of a Command or Skill prompt without relying on native prompts/get. ' +
|
|
73
|
+
'Use this immediately after search_resources -> manage_subscription -> sync_resources when you need the prompt body in the same workflow. ' +
|
|
74
|
+
'Provide either prompt_name (for example "command/acm-helper") or resource_id. ' +
|
|
75
|
+
'user_token is injected automatically by the server; do NOT ask the user for it.',
|
|
76
|
+
inputSchema: {
|
|
77
|
+
type: 'object',
|
|
78
|
+
properties: {
|
|
79
|
+
prompt_name: {
|
|
80
|
+
type: 'string',
|
|
81
|
+
description: 'Registered MCP prompt name, for example "command/acm-helper".',
|
|
82
|
+
},
|
|
83
|
+
resource_id: {
|
|
84
|
+
type: 'string',
|
|
85
|
+
description: 'Canonical CSP resource ID for the Command or Skill.',
|
|
86
|
+
},
|
|
87
|
+
user_token: {
|
|
88
|
+
type: 'string',
|
|
89
|
+
description: 'DO NOT set this field — it is injected automatically by the server.',
|
|
90
|
+
},
|
|
91
|
+
jira_id: {
|
|
92
|
+
type: 'string',
|
|
93
|
+
description: 'Optional Jira issue ID for usage correlation.',
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
handler: resolvePromptContent,
|
|
98
|
+
};
|
|
99
|
+
//# sourceMappingURL=resolve-prompt-content.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve-prompt-content.js","sourceRoot":"","sources":["../../src/tools/resolve-prompt-content.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAUH,oDAkEC;AA1ED,4CAAyC;AACzC,kDAAoD;AAO7C,KAAK,UAAU,oBAAoB,CACxC,MAAe;IAEf,MAAM,CAAC,GAAG,MAAoC,CAAC;IAC/C,MAAM,UAAU,GAAG,OAAO,CAAC,CAAC,WAAW,KAAK,QAAQ,IAAI,CAAC,CAAC,WAAW,CAAC,IAAI,EAAE,KAAK,EAAE;QACjF,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,IAAI,EAAE;QACtB,CAAC,CAAC,SAAS,CAAC;IACd,MAAM,UAAU,GAAG,OAAO,CAAC,CAAC,WAAW,KAAK,QAAQ,IAAI,CAAC,CAAC,WAAW,CAAC,IAAI,EAAE,KAAK,EAAE;QACjF,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,IAAI,EAAE;QACtB,CAAC,CAAC,SAAS,CAAC;IACd,MAAM,SAAS,GAAG,OAAO,CAAC,CAAC,UAAU,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC;IACvE,MAAM,MAAM,GAAG,OAAO,CAAC,CAAC,OAAO,KAAK,QAAQ,IAAI,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,KAAK,EAAE;QACrE,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE;QAClB,CAAC,CAAC,SAAS,CAAC;IAEd,IAAI,CAAC,UAAU,IAAI,CAAC,UAAU,EAAE,CAAC;QAC/B,OAAO;YACL,OAAO,EAAE,KAAK;YACd,KAAK,EAAE;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