@elliotding/ai-agent-mcp 0.1.25 → 0.1.26

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 (237) hide show
  1. package/package.json +4 -1
  2. package/.prompt-cache/cmd-cmd-client-sdk-ai-hub-generate-testcase.md +0 -101
  3. package/.prompt-cache/cmd-cmd-client-sdk-ai-hub-submit_zct_job.md +0 -158
  4. package/.prompt-cache/skill-skill-client-sdk-ai-hub-analyze-conf-status.md +0 -311
  5. package/.prompt-cache/skill-skill-client-sdk-ai-hub-analyze-sdk-log.md +0 -64
  6. package/.prompt-cache/skill-skill-client-sdk-ai-hub-analyze-zmb-log-errors.md +0 -84
  7. package/ai-resource-telemetry.json +0 -40
  8. package/dist/api/cached-client.d.ts +0 -48
  9. package/dist/api/cached-client.d.ts.map +0 -1
  10. package/dist/api/cached-client.js +0 -126
  11. package/dist/api/cached-client.js.map +0 -1
  12. package/dist/api/client.d.ts +0 -281
  13. package/dist/api/client.d.ts.map +0 -1
  14. package/dist/api/client.js +0 -371
  15. package/dist/api/client.js.map +0 -1
  16. package/dist/auth/index.d.ts +0 -8
  17. package/dist/auth/index.d.ts.map +0 -1
  18. package/dist/auth/index.js +0 -26
  19. package/dist/auth/index.js.map +0 -1
  20. package/dist/auth/middleware.d.ts +0 -36
  21. package/dist/auth/middleware.d.ts.map +0 -1
  22. package/dist/auth/middleware.js +0 -194
  23. package/dist/auth/middleware.js.map +0 -1
  24. package/dist/auth/permissions.d.ts +0 -60
  25. package/dist/auth/permissions.d.ts.map +0 -1
  26. package/dist/auth/permissions.js +0 -262
  27. package/dist/auth/permissions.js.map +0 -1
  28. package/dist/auth/token-validator.d.ts +0 -52
  29. package/dist/auth/token-validator.d.ts.map +0 -1
  30. package/dist/auth/token-validator.js +0 -215
  31. package/dist/auth/token-validator.js.map +0 -1
  32. package/dist/cache/cache-manager.d.ts +0 -49
  33. package/dist/cache/cache-manager.d.ts.map +0 -1
  34. package/dist/cache/cache-manager.js +0 -191
  35. package/dist/cache/cache-manager.js.map +0 -1
  36. package/dist/cache/index.d.ts +0 -6
  37. package/dist/cache/index.d.ts.map +0 -1
  38. package/dist/cache/index.js +0 -12
  39. package/dist/cache/index.js.map +0 -1
  40. package/dist/cache/redis-client.d.ts +0 -45
  41. package/dist/cache/redis-client.d.ts.map +0 -1
  42. package/dist/cache/redis-client.js +0 -210
  43. package/dist/cache/redis-client.js.map +0 -1
  44. package/dist/config/constants.d.ts +0 -28
  45. package/dist/config/constants.d.ts.map +0 -1
  46. package/dist/config/constants.js +0 -31
  47. package/dist/config/constants.js.map +0 -1
  48. package/dist/config/index.d.ts +0 -71
  49. package/dist/config/index.d.ts.map +0 -1
  50. package/dist/config/index.js +0 -190
  51. package/dist/config/index.js.map +0 -1
  52. package/dist/filesystem/manager.d.ts +0 -45
  53. package/dist/filesystem/manager.d.ts.map +0 -1
  54. package/dist/filesystem/manager.js +0 -246
  55. package/dist/filesystem/manager.js.map +0 -1
  56. package/dist/git/multi-source-manager.d.ts +0 -78
  57. package/dist/git/multi-source-manager.d.ts.map +0 -1
  58. package/dist/git/multi-source-manager.js +0 -577
  59. package/dist/git/multi-source-manager.js.map +0 -1
  60. package/dist/git/operations.d.ts +0 -27
  61. package/dist/git/operations.d.ts.map +0 -1
  62. package/dist/git/operations.js +0 -83
  63. package/dist/git/operations.js.map +0 -1
  64. package/dist/index.d.ts +0 -6
  65. package/dist/index.d.ts.map +0 -1
  66. package/dist/index.js +0 -122
  67. package/dist/index.js.map +0 -1
  68. package/dist/monitoring/health.d.ts +0 -35
  69. package/dist/monitoring/health.d.ts.map +0 -1
  70. package/dist/monitoring/health.js +0 -105
  71. package/dist/monitoring/health.js.map +0 -1
  72. package/dist/prompts/cache.d.ts +0 -69
  73. package/dist/prompts/cache.d.ts.map +0 -1
  74. package/dist/prompts/cache.js +0 -163
  75. package/dist/prompts/cache.js.map +0 -1
  76. package/dist/prompts/generator.d.ts +0 -49
  77. package/dist/prompts/generator.d.ts.map +0 -1
  78. package/dist/prompts/generator.js +0 -160
  79. package/dist/prompts/generator.js.map +0 -1
  80. package/dist/prompts/index.d.ts +0 -13
  81. package/dist/prompts/index.d.ts.map +0 -1
  82. package/dist/prompts/index.js +0 -24
  83. package/dist/prompts/index.js.map +0 -1
  84. package/dist/prompts/manager.d.ts +0 -207
  85. package/dist/prompts/manager.d.ts.map +0 -1
  86. package/dist/prompts/manager.js +0 -566
  87. package/dist/prompts/manager.js.map +0 -1
  88. package/dist/resources/index.d.ts +0 -6
  89. package/dist/resources/index.d.ts.map +0 -1
  90. package/dist/resources/index.js +0 -10
  91. package/dist/resources/index.js.map +0 -1
  92. package/dist/resources/loader.d.ts +0 -88
  93. package/dist/resources/loader.d.ts.map +0 -1
  94. package/dist/resources/loader.js +0 -492
  95. package/dist/resources/loader.js.map +0 -1
  96. package/dist/server/http.d.ts +0 -57
  97. package/dist/server/http.d.ts.map +0 -1
  98. package/dist/server/http.js +0 -435
  99. package/dist/server/http.js.map +0 -1
  100. package/dist/server.d.ts +0 -13
  101. package/dist/server.d.ts.map +0 -1
  102. package/dist/server.js +0 -201
  103. package/dist/server.js.map +0 -1
  104. package/dist/session/manager.d.ts +0 -91
  105. package/dist/session/manager.d.ts.map +0 -1
  106. package/dist/session/manager.js +0 -251
  107. package/dist/session/manager.js.map +0 -1
  108. package/dist/telemetry/index.d.ts +0 -3
  109. package/dist/telemetry/index.d.ts.map +0 -1
  110. package/dist/telemetry/index.js +0 -7
  111. package/dist/telemetry/index.js.map +0 -1
  112. package/dist/telemetry/manager.d.ts +0 -151
  113. package/dist/telemetry/manager.d.ts.map +0 -1
  114. package/dist/telemetry/manager.js +0 -367
  115. package/dist/telemetry/manager.js.map +0 -1
  116. package/dist/tools/index.d.ts +0 -13
  117. package/dist/tools/index.d.ts.map +0 -1
  118. package/dist/tools/index.js +0 -29
  119. package/dist/tools/index.js.map +0 -1
  120. package/dist/tools/manage-subscription.d.ts +0 -47
  121. package/dist/tools/manage-subscription.d.ts.map +0 -1
  122. package/dist/tools/manage-subscription.js +0 -317
  123. package/dist/tools/manage-subscription.js.map +0 -1
  124. package/dist/tools/registry.d.ts +0 -40
  125. package/dist/tools/registry.d.ts.map +0 -1
  126. package/dist/tools/registry.js +0 -85
  127. package/dist/tools/registry.js.map +0 -1
  128. package/dist/tools/resolve-prompt-content.d.ts +0 -35
  129. package/dist/tools/resolve-prompt-content.d.ts.map +0 -1
  130. package/dist/tools/resolve-prompt-content.js +0 -99
  131. package/dist/tools/resolve-prompt-content.js.map +0 -1
  132. package/dist/tools/search-resources.d.ts +0 -35
  133. package/dist/tools/search-resources.d.ts.map +0 -1
  134. package/dist/tools/search-resources.js +0 -159
  135. package/dist/tools/search-resources.js.map +0 -1
  136. package/dist/tools/sync-resources.d.ts +0 -54
  137. package/dist/tools/sync-resources.d.ts.map +0 -1
  138. package/dist/tools/sync-resources.js +0 -735
  139. package/dist/tools/sync-resources.js.map +0 -1
  140. package/dist/tools/track-usage.d.ts +0 -63
  141. package/dist/tools/track-usage.d.ts.map +0 -1
  142. package/dist/tools/track-usage.js +0 -90
  143. package/dist/tools/track-usage.js.map +0 -1
  144. package/dist/tools/uninstall-resource.d.ts +0 -30
  145. package/dist/tools/uninstall-resource.d.ts.map +0 -1
  146. package/dist/tools/uninstall-resource.js +0 -174
  147. package/dist/tools/uninstall-resource.js.map +0 -1
  148. package/dist/tools/upload-resource.d.ts +0 -81
  149. package/dist/tools/upload-resource.d.ts.map +0 -1
  150. package/dist/tools/upload-resource.js +0 -393
  151. package/dist/tools/upload-resource.js.map +0 -1
  152. package/dist/transport/sse.d.ts +0 -29
  153. package/dist/transport/sse.d.ts.map +0 -1
  154. package/dist/transport/sse.js +0 -271
  155. package/dist/transport/sse.js.map +0 -1
  156. package/dist/types/errors.d.ts +0 -60
  157. package/dist/types/errors.d.ts.map +0 -1
  158. package/dist/types/errors.js +0 -112
  159. package/dist/types/errors.js.map +0 -1
  160. package/dist/types/index.d.ts +0 -7
  161. package/dist/types/index.d.ts.map +0 -1
  162. package/dist/types/index.js +0 -23
  163. package/dist/types/index.js.map +0 -1
  164. package/dist/types/mcp.d.ts +0 -50
  165. package/dist/types/mcp.d.ts.map +0 -1
  166. package/dist/types/mcp.js +0 -6
  167. package/dist/types/mcp.js.map +0 -1
  168. package/dist/types/resources.d.ts +0 -109
  169. package/dist/types/resources.d.ts.map +0 -1
  170. package/dist/types/resources.js +0 -7
  171. package/dist/types/resources.js.map +0 -1
  172. package/dist/types/tools.d.ts +0 -253
  173. package/dist/types/tools.d.ts.map +0 -1
  174. package/dist/types/tools.js +0 -6
  175. package/dist/types/tools.js.map +0 -1
  176. package/dist/utils/cursor-paths.d.ts +0 -84
  177. package/dist/utils/cursor-paths.d.ts.map +0 -1
  178. package/dist/utils/cursor-paths.js +0 -166
  179. package/dist/utils/cursor-paths.js.map +0 -1
  180. package/dist/utils/log-cleaner.d.ts +0 -18
  181. package/dist/utils/log-cleaner.d.ts.map +0 -1
  182. package/dist/utils/log-cleaner.js +0 -112
  183. package/dist/utils/log-cleaner.js.map +0 -1
  184. package/dist/utils/logger.d.ts +0 -59
  185. package/dist/utils/logger.d.ts.map +0 -1
  186. package/dist/utils/logger.js +0 -292
  187. package/dist/utils/logger.js.map +0 -1
  188. package/dist/utils/validation.d.ts +0 -58
  189. package/dist/utils/validation.d.ts.map +0 -1
  190. package/dist/utils/validation.js +0 -214
  191. package/dist/utils/validation.js.map +0 -1
  192. package/src/api/cached-client.ts +0 -144
  193. package/src/api/client.ts +0 -697
  194. package/src/auth/index.ts +0 -11
  195. package/src/auth/middleware.ts +0 -244
  196. package/src/auth/permissions.ts +0 -323
  197. package/src/auth/token-validator.ts +0 -292
  198. package/src/cache/cache-manager.ts +0 -243
  199. package/src/cache/index.ts +0 -6
  200. package/src/cache/redis-client.ts +0 -249
  201. package/src/config/constants.ts +0 -33
  202. package/src/config/index.ts +0 -269
  203. package/src/filesystem/manager.ts +0 -235
  204. package/src/git/multi-source-manager.ts +0 -654
  205. package/src/git/operations.ts +0 -93
  206. package/src/index.ts +0 -157
  207. package/src/monitoring/health.ts +0 -132
  208. package/src/prompts/cache.ts +0 -140
  209. package/src/prompts/generator.ts +0 -143
  210. package/src/prompts/index.ts +0 -20
  211. package/src/prompts/manager.ts +0 -718
  212. package/src/resources/index.ts +0 -13
  213. package/src/resources/loader.ts +0 -563
  214. package/src/server/http.ts +0 -549
  215. package/src/server.ts +0 -206
  216. package/src/session/manager.ts +0 -296
  217. package/src/telemetry/index.ts +0 -10
  218. package/src/telemetry/manager.ts +0 -419
  219. package/src/tools/index.ts +0 -13
  220. package/src/tools/manage-subscription.ts +0 -388
  221. package/src/tools/registry.ts +0 -97
  222. package/src/tools/resolve-prompt-content.ts +0 -113
  223. package/src/tools/search-resources.ts +0 -185
  224. package/src/tools/sync-resources.ts +0 -829
  225. package/src/tools/track-usage.ts +0 -113
  226. package/src/tools/uninstall-resource.ts +0 -199
  227. package/src/tools/upload-resource.ts +0 -431
  228. package/src/transport/sse.ts +0 -308
  229. package/src/types/errors.ts +0 -146
  230. package/src/types/index.ts +0 -7
  231. package/src/types/mcp.ts +0 -61
  232. package/src/types/resources.ts +0 -141
  233. package/src/types/tools.ts +0 -305
  234. package/src/utils/cursor-paths.ts +0 -135
  235. package/src/utils/log-cleaner.ts +0 -92
  236. package/src/utils/logger.ts +0 -333
  237. package/src/utils/validation.ts +0 -262
@@ -1,388 +0,0 @@
1
- /**
2
- * manage_subscription Tool
3
- * Manage resource subscriptions
4
- */
5
-
6
- import { logger, logToolCall } from '../utils/logger';
7
- import { apiClient } from '../api/client';
8
- import { MCPServerError, createValidationError } from '../types/errors';
9
- import type { ManageSubscriptionParams, ManageSubscriptionResult, ToolResult } from '../types/tools';
10
- import { syncResources } from './sync-resources';
11
- import { uninstallResource } from './uninstall-resource';
12
- import { promptManager } from '../prompts/index.js';
13
-
14
- export async function manageSubscription(params: unknown): Promise<ToolResult<ManageSubscriptionResult>> {
15
- const startTime = Date.now();
16
-
17
- // Type assertion for params
18
- const typedParams = params as ManageSubscriptionParams;
19
-
20
- logger.info({ tool: 'manage_subscription', params }, 'manage_subscription called');
21
-
22
- try {
23
- let result: ManageSubscriptionResult;
24
-
25
- switch (typedParams.action) {
26
- case 'subscribe': {
27
- // Validate resource_ids
28
- if (!typedParams.resource_ids || typedParams.resource_ids.length === 0) {
29
- throw createValidationError(
30
- 'resource_ids',
31
- 'array',
32
- 'resource_ids is required for subscribe action'
33
- );
34
- }
35
-
36
- logger.debug({ resourceIds: typedParams.resource_ids, autoSync: typedParams.auto_sync }, 'Subscribing to resources...');
37
-
38
- // Subscribe to resources
39
- const subResult = await apiClient.subscribe(
40
- typedParams.resource_ids,
41
- typedParams.auto_sync,
42
- undefined,
43
- typedParams.user_token
44
- );
45
-
46
- logger.info({ count: subResult.subscriptions.length }, 'Resources subscribed successfully');
47
-
48
- // Auto-sync newly subscribed resources immediately (default: true)
49
- const shouldAutoSync = typedParams.auto_sync !== false;
50
- let syncSummary: string | undefined;
51
- let syncDetails: Array<{ id: string; name: string; action: string }> | undefined;
52
- let pendingSetup: unknown[] | undefined;
53
-
54
- if (shouldAutoSync && subResult.subscriptions.length > 0) {
55
- logger.info({ resourceIds: typedParams.resource_ids }, 'Auto-syncing newly subscribed resources...');
56
- const syncResult = await syncResources({
57
- mode: 'incremental',
58
- scope: typedParams.scope || 'global',
59
- user_token: typedParams.user_token,
60
- });
61
- if (syncResult.success && syncResult.data) {
62
- const sd = syncResult.data;
63
- syncSummary = `Auto-sync: ${sd.summary.synced} synced, ${sd.summary.cached} cached, ${sd.summary.failed} failed`;
64
- syncDetails = sd.details.map(d => ({ id: d.id, name: d.name, action: d.action }));
65
- if (sd.pending_setup && sd.pending_setup.length > 0) {
66
- pendingSetup = sd.pending_setup;
67
- }
68
- logger.info({ summary: sd.summary }, 'Auto-sync after subscribe completed');
69
- } else {
70
- logger.warn({ error: syncResult.error }, 'Auto-sync after subscribe failed, subscription still recorded');
71
- syncSummary = 'Auto-sync failed — run sync_resources manually if needed';
72
- }
73
- }
74
-
75
- result = {
76
- action: 'subscribe',
77
- success: true,
78
- subscriptions: subResult.subscriptions.map(sub => ({
79
- id: sub.id,
80
- name: sub.name,
81
- type: sub.type,
82
- subscribed_at: sub.subscribed_at,
83
- })),
84
- message: [
85
- `Successfully subscribed to ${subResult.subscriptions.length} resource${subResult.subscriptions.length > 1 ? 's' : ''}.`,
86
- syncSummary,
87
- '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.',
88
- ].filter(Boolean).join(' '),
89
- ...(syncDetails ? { sync_details: syncDetails } : {}),
90
- ...(pendingSetup ? { pending_setup: pendingSetup } : {}),
91
- };
92
- break;
93
- }
94
-
95
- case 'unsubscribe': {
96
- // Validate resource_ids
97
- if (!typedParams.resource_ids || typedParams.resource_ids.length === 0) {
98
- throw createValidationError(
99
- 'resource_ids',
100
- 'array',
101
- 'resource_ids is required for unsubscribe action'
102
- );
103
- }
104
-
105
- logger.debug({ resourceIds: typedParams.resource_ids }, 'Unsubscribing from resources...');
106
-
107
- // Build a resource_id → type map from the current subscription list so
108
- // uninstall actions can be scoped precisely to rule vs mcp resources.
109
- let idToType: Map<string, string> = new Map();
110
- try {
111
- const currentSubs = await apiClient.getSubscriptions({}, typedParams.user_token);
112
- for (const s of currentSubs.subscriptions) {
113
- idToType.set(s.id, s.type);
114
- }
115
- } catch (e) {
116
- logger.warn({ error: (e as Error).message }, 'Could not fetch subscriptions for type resolution — uninstall will emit both rule+mcp actions as fallback');
117
- }
118
-
119
- // Cancel server-side subscription
120
- await apiClient.unsubscribe(typedParams.resource_ids, typedParams.user_token);
121
- logger.info({ count: typedParams.resource_ids.length }, 'Server-side subscriptions removed');
122
-
123
- // Uninstall local files and MCP config for each resource.
124
- // For Command/Skill: unregister MCP Prompt instead of deleting local files.
125
- const uninstallResults: Array<{ id: string; removed: boolean; detail: string }> = [];
126
- for (const resourceId of typedParams.resource_ids) {
127
- // Determine if this is a Command or Skill by checking the prompt registry.
128
- // API resource IDs are UUIDs (e.g. "0ccd800f..."), NOT prefixed with "cmd-"/"skill-".
129
- // Check whether any registered prompt for this user matches the resource_id.
130
- const matchedPromptName = promptManager.promptNames(typedParams.user_token ?? '').find(
131
- (name) => {
132
- // Prompt names are "<type>/<resource_name>"; check by looking up the registered meta.
133
- const registered = promptManager.getByPromptName(name, typedParams.user_token ?? '');
134
- return registered?.meta?.resource_id === resourceId;
135
- },
136
- );
137
- if (matchedPromptName) {
138
- const parts = matchedPromptName.split('/');
139
- const resourceType = (parts[0] ?? 'command') as 'command' | 'skill';
140
- const resourceName = parts.slice(1).join('/') || matchedPromptName;
141
- promptManager.unregisterPrompt(resourceId, resourceType, resourceName, typedParams.user_token ?? '');
142
- uninstallResults.push({ id: resourceId, removed: true, detail: `Unregistered MCP Prompt for "${resourceName}"` });
143
- logger.info({ resourceId, resourceType, matchedPromptName }, 'MCP Prompt unregistered on unsubscribe');
144
- continue;
145
- }
146
- // Use the last segment of the resource ID as the search pattern
147
- // e.g. "mcp-client-sdk-ai-hub-jenkins" → "jenkins"
148
- // "rule-csp-elliotTest" → "elliotTest"
149
- const namePart = resourceId.split('-').slice(-1)[0] ||
150
- resourceId.split('-').slice(-2).join('-') ||
151
- resourceId;
152
-
153
- // Try full name match first (e.g. "elliotTest"), fallback to last segment
154
- const patternsToTry = Array.from(new Set([
155
- resourceId, // full id
156
- resourceId.replace(/^(skill|cmd|rule|mcp)-[^-]+-/, ''), // strip prefix+source
157
- namePart,
158
- ]));
159
-
160
- const resolvedType = idToType.get(resourceId) as 'rule' | 'mcp' | undefined;
161
- let uninstalled = false;
162
- for (const pattern of patternsToTry) {
163
- const uninstallResult = await uninstallResource({
164
- resource_id_or_name: pattern,
165
- remove_from_account: false, // already unsubscribed above
166
- ...(resolvedType ? { resource_type: resolvedType } : {}),
167
- });
168
- if (uninstallResult.success && uninstallResult.data && uninstallResult.data.removed_resources.length > 0) {
169
- uninstallResults.push({ id: resourceId, removed: true, detail: `Removed local files for "${pattern}"` });
170
- uninstalled = true;
171
- break;
172
- }
173
- }
174
- if (!uninstalled) {
175
- uninstallResults.push({ id: resourceId, removed: false, detail: 'No local files found (may not have been installed)' });
176
- }
177
- }
178
-
179
- const removedCount = uninstallResults.filter(r => r.removed).length;
180
- const notFoundCount = uninstallResults.filter(r => !r.removed).length;
181
-
182
- result = {
183
- action: 'unsubscribe',
184
- success: true,
185
- message: [
186
- `Successfully unsubscribed from ${typedParams.resource_ids.length} resource${typedParams.resource_ids.length > 1 ? 's' : ''}.`,
187
- removedCount > 0 ? `Removed local files for ${removedCount} resource${removedCount > 1 ? 's' : ''}.` : null,
188
- notFoundCount > 0 ? `${notFoundCount} resource${notFoundCount > 1 ? 's were' : ' was'} not installed locally.` : null,
189
- ].filter(Boolean).join(' '),
190
- sync_details: uninstallResults.map(r => ({ id: r.id, name: r.id, action: r.removed ? 'uninstalled' : 'not_found_locally' })),
191
- };
192
-
193
- logger.info({ count: typedParams.resource_ids.length, removedCount }, 'Resources unsubscribed and local files cleaned up');
194
- break;
195
- }
196
-
197
- case 'list': {
198
- logger.debug({ scope: typedParams.scope || 'all' }, 'Listing subscriptions...');
199
-
200
- // Get subscriptions list
201
- const subs = await apiClient.getSubscriptions({}, typedParams.user_token);
202
-
203
- result = {
204
- action: 'list',
205
- success: true,
206
- subscriptions: subs.subscriptions.map(sub => ({
207
- id: sub.id,
208
- name: sub.name,
209
- type: sub.type,
210
- subscribed_at: sub.subscribed_at,
211
- })),
212
- message: `Found ${subs.total} subscription${subs.total !== 1 ? 's' : ''}`,
213
- };
214
-
215
- logger.info({ total: subs.total }, 'Subscriptions listed successfully');
216
- break;
217
- }
218
-
219
- case 'batch_subscribe': {
220
- // Validate resource_ids
221
- if (!typedParams.resource_ids || typedParams.resource_ids.length === 0) {
222
- throw createValidationError(
223
- 'resource_ids',
224
- 'array',
225
- 'resource_ids is required for batch_subscribe action'
226
- );
227
- }
228
-
229
- logger.debug({ count: typedParams.resource_ids.length, autoSync: typedParams.auto_sync }, 'Batch subscribing to resources...');
230
-
231
- const batchSubResult = await apiClient.subscribe(
232
- typedParams.resource_ids,
233
- typedParams.auto_sync,
234
- undefined,
235
- typedParams.user_token
236
- );
237
-
238
- logger.info({ count: batchSubResult.subscriptions.length }, 'Batch subscription completed');
239
-
240
- // Auto-sync newly subscribed resources immediately (default: true)
241
- const shouldBatchAutoSync = typedParams.auto_sync !== false;
242
- let batchSyncSummary: string | undefined;
243
- let batchSyncDetails: Array<{ id: string; name: string; action: string }> | undefined;
244
- let batchPendingSetup: unknown[] | undefined;
245
-
246
- if (shouldBatchAutoSync && batchSubResult.subscriptions.length > 0) {
247
- logger.info({ count: batchSubResult.subscriptions.length }, 'Auto-syncing batch subscribed resources...');
248
- const batchSyncResult = await syncResources({
249
- mode: 'incremental',
250
- scope: typedParams.scope || 'global',
251
- user_token: typedParams.user_token,
252
- });
253
- if (batchSyncResult.success && batchSyncResult.data) {
254
- const sd = batchSyncResult.data;
255
- batchSyncSummary = `Auto-sync: ${sd.summary.synced} synced, ${sd.summary.cached} cached, ${sd.summary.failed} failed`;
256
- batchSyncDetails = sd.details.map(d => ({ id: d.id, name: d.name, action: d.action }));
257
- if (sd.pending_setup && sd.pending_setup.length > 0) {
258
- batchPendingSetup = sd.pending_setup;
259
- }
260
- } else {
261
- batchSyncSummary = 'Auto-sync failed — run sync_resources manually if needed';
262
- }
263
- }
264
-
265
- result = {
266
- action: 'batch_subscribe',
267
- success: true,
268
- subscriptions: batchSubResult.subscriptions.map(sub => ({
269
- id: sub.id,
270
- name: sub.name,
271
- type: sub.type,
272
- subscribed_at: sub.subscribed_at,
273
- })),
274
- message: [
275
- `Successfully batch subscribed to ${batchSubResult.subscriptions.length} resource${batchSubResult.subscriptions.length > 1 ? 's' : ''}.`,
276
- batchSyncSummary,
277
- ].filter(Boolean).join(' '),
278
- ...(batchSyncDetails ? { sync_details: batchSyncDetails } : {}),
279
- ...(batchPendingSetup ? { pending_setup: batchPendingSetup } : {}),
280
- };
281
- break;
282
- }
283
-
284
- case 'batch_unsubscribe': {
285
- // Validate resource_ids
286
- if (!typedParams.resource_ids || typedParams.resource_ids.length === 0) {
287
- throw createValidationError(
288
- 'resource_ids',
289
- 'array',
290
- 'resource_ids is required for batch_unsubscribe action'
291
- );
292
- }
293
-
294
- logger.debug({ count: typedParams.resource_ids.length }, 'Batch unsubscribing from resources...');
295
-
296
- // Delegate entirely to the unsubscribe case for unified cleanup logic
297
- return manageSubscription({ ...typedParams, action: 'unsubscribe' });
298
- }
299
-
300
- default: {
301
- throw createValidationError(
302
- 'action',
303
- 'string',
304
- `Unknown action. Must be one of: subscribe, unsubscribe, list, batch_subscribe, batch_unsubscribe`
305
- );
306
- }
307
- }
308
-
309
- const duration = Date.now() - startTime;
310
- logToolCall('manage_subscription', 'user-id', params as Record<string, unknown>, duration);
311
-
312
- logger.info(
313
- {
314
- action: typedParams.action,
315
- duration,
316
- },
317
- 'manage_subscription completed successfully'
318
- );
319
-
320
- return {
321
- success: true,
322
- data: result,
323
- };
324
- } catch (error) {
325
- logger.error({ error, action: typedParams.action }, 'manage_subscription failed');
326
- return {
327
- success: false,
328
- error: {
329
- code: error instanceof MCPServerError ? error.code : 'UNKNOWN_ERROR',
330
- message: error instanceof Error ? error.message : String(error),
331
- },
332
- };
333
- }
334
- }
335
-
336
- // Tool definition for registry
337
- export const manageSubscriptionTool = {
338
- name: 'manage_subscription',
339
- description:
340
- 'Manage resource subscriptions (subscribe, unsubscribe, list). ' +
341
- 'When action is "subscribe" or "batch_subscribe", the tool automatically syncs ' +
342
- 'the newly subscribed resources to the local machine immediately after subscribing ' +
343
- '(auto_sync defaults to true). Pass auto_sync: false only when the user explicitly ' +
344
- 'says they do NOT want the resource installed right now. ' +
345
- 'For newly subscribed Command or Skill resources that must be used immediately in the same conversation, ' +
346
- 'follow with `resolve_prompt_content` after sync instead of assuming Cursor will fetch the prompt body automatically.',
347
- inputSchema: {
348
- type: 'object' as const,
349
- properties: {
350
- action: {
351
- type: 'string',
352
- description: 'Action to perform',
353
- enum: ['subscribe', 'unsubscribe', 'list', 'batch_subscribe', 'batch_unsubscribe'],
354
- },
355
- resource_ids: {
356
- type: 'array',
357
- description: 'Resource IDs (required for subscribe/unsubscribe actions)',
358
- },
359
- auto_sync: {
360
- type: 'boolean',
361
- description:
362
- 'Whether to immediately sync (install) the subscribed resources to the local machine after subscribing. ' +
363
- 'Defaults to true — omit this field in normal usage. ' +
364
- 'Set to false only when the user explicitly says they want to subscribe but NOT install yet.',
365
- default: true,
366
- },
367
- scope: {
368
- type: 'string',
369
- description: 'Installation scope',
370
- enum: ['global', 'workspace'],
371
- default: 'global',
372
- },
373
- notify: {
374
- type: 'boolean',
375
- description: 'Enable update notifications',
376
- default: true,
377
- },
378
- user_token: {
379
- type: 'string',
380
- description:
381
- 'DO NOT set this field — it is automatically injected by the MCP server from ' +
382
- 'the authenticated SSE connection. The server always provides the correct token.',
383
- },
384
- },
385
- required: ['action'],
386
- },
387
- handler: manageSubscription,
388
- };
@@ -1,97 +0,0 @@
1
- /**
2
- * Tool Registry
3
- * Central registry for MCP tools
4
- */
5
-
6
- import { logger } from '../utils/logger';
7
- import type { ToolDefinition } from '../types/tools';
8
- import type { MCPToolDefinition } from '../types/mcp';
9
-
10
- class ToolRegistry {
11
- private tools: Map<string, ToolDefinition> = new Map();
12
-
13
- /**
14
- * Register a tool
15
- */
16
- registerTool(tool: ToolDefinition): void {
17
- if (this.tools.has(tool.name)) {
18
- throw new Error(`Tool '${tool.name}' is already registered`);
19
- }
20
-
21
- this.tools.set(tool.name, tool);
22
- logger.info({ toolName: tool.name }, `Tool registered: ${tool.name}`);
23
- }
24
-
25
- /**
26
- * Get a tool by name
27
- */
28
- getTool(name: string): ToolDefinition | undefined {
29
- return this.tools.get(name);
30
- }
31
-
32
- /**
33
- * List all registered tools
34
- */
35
- listTools(): ToolDefinition[] {
36
- return Array.from(this.tools.values());
37
- }
38
-
39
- /**
40
- * Get MCP tool definitions (for tools/list response)
41
- */
42
- getMCPToolDefinitions(): MCPToolDefinition[] {
43
- return this.listTools().map((tool) => ({
44
- name: tool.name,
45
- description: tool.description,
46
- inputSchema: tool.inputSchema,
47
- }));
48
- }
49
-
50
- /**
51
- * Check if a tool exists
52
- */
53
- hasTool(name: string): boolean {
54
- return this.tools.has(name);
55
- }
56
-
57
- /**
58
- * Get tool count
59
- */
60
- getToolCount(): number {
61
- return this.tools.size;
62
- }
63
-
64
- /**
65
- * Call a tool by name with arguments
66
- */
67
- async callTool(name: string, args: Record<string, unknown>): Promise<unknown> {
68
- const tool = this.getTool(name);
69
- if (!tool) {
70
- throw new Error(`Tool '${name}' not found`);
71
- }
72
-
73
- logger.debug({ toolName: name, args }, 'Calling tool');
74
-
75
- try {
76
- const result = await tool.handler(args);
77
-
78
- // Debug: Log the result structure
79
- logger.debug({
80
- toolName: name,
81
- resultType: typeof result,
82
- resultKeys: result && typeof result === 'object' ? Object.keys(result) : undefined,
83
- hasSuccess: result && typeof result === 'object' && 'success' in result,
84
- hasData: result && typeof result === 'object' && 'data' in result,
85
- hasError: result && typeof result === 'object' && 'error' in result
86
- }, 'Tool execution result structure');
87
-
88
- return result;
89
- } catch (error) {
90
- logger.error({ toolName: name, error, errorType: typeof error, errorMessage: error instanceof Error ? error.message : String(error) }, 'Tool execution threw error');
91
- throw error;
92
- }
93
- }
94
- }
95
-
96
- // Global singleton
97
- export const toolRegistry = new ToolRegistry();
@@ -1,113 +0,0 @@
1
- /**
2
- * resolve_prompt_content Tool
3
- *
4
- * Stable fallback for retrieving the fully resolved body of a dynamically
5
- * subscribed Command or Skill without relying on Cursor to issue prompts/get.
6
- */
7
-
8
- import { logger } from '../utils/logger';
9
- import { promptManager } from '../prompts/index.js';
10
- import type {
11
- ResolvePromptContentParams,
12
- ResolvePromptContentResult,
13
- ToolResult,
14
- } from '../types/tools';
15
-
16
- export async function resolvePromptContent(
17
- params: unknown,
18
- ): Promise<ToolResult<ResolvePromptContentResult>> {
19
- const p = params as ResolvePromptContentParams;
20
- const promptName = typeof p.prompt_name === 'string' && p.prompt_name.trim() !== ''
21
- ? p.prompt_name.trim()
22
- : undefined;
23
- const resourceId = typeof p.resource_id === 'string' && p.resource_id.trim() !== ''
24
- ? p.resource_id.trim()
25
- : undefined;
26
- const userToken = typeof p.user_token === 'string' ? p.user_token : '';
27
- const jiraId = typeof p.jira_id === 'string' && p.jira_id.trim() !== ''
28
- ? p.jira_id.trim()
29
- : undefined;
30
-
31
- if (!promptName && !resourceId) {
32
- return {
33
- success: false,
34
- error: {
35
- code: 'VALIDATION_ERROR',
36
- message: 'Either prompt_name or resource_id is required',
37
- },
38
- };
39
- }
40
-
41
- const resolved = await promptManager.resolvePromptContentForInvocation({
42
- promptName,
43
- resourceId,
44
- userToken,
45
- jiraId,
46
- });
47
-
48
- if (!resolved) {
49
- const target = promptName ?? resourceId ?? 'unknown';
50
- logger.warn({ promptName, resourceId }, 'resolve_prompt_content: prompt not found');
51
- return {
52
- success: false,
53
- error: {
54
- code: 'PROMPT_NOT_FOUND',
55
- message: `Prompt "${target}" is not available. Please run sync_resources first.`,
56
- },
57
- };
58
- }
59
-
60
- logger.info(
61
- {
62
- promptName: resolved.promptName,
63
- resourceId: resolved.meta.resource_id,
64
- contentSource: resolved.contentSource,
65
- },
66
- 'resolve_prompt_content: prompt resolved successfully',
67
- );
68
-
69
- return {
70
- success: true,
71
- data: {
72
- prompt_name: resolved.promptName,
73
- resource_id: resolved.meta.resource_id,
74
- resource_type: resolved.meta.resource_type,
75
- resource_name: resolved.meta.resource_name,
76
- description: resolved.description,
77
- content: resolved.content,
78
- content_source: resolved.contentSource,
79
- usage_tracked: Boolean(userToken),
80
- },
81
- };
82
- }
83
-
84
- export const resolvePromptContentTool = {
85
- name: 'resolve_prompt_content',
86
- description:
87
- 'Retrieve the fully resolved content of a Command or Skill prompt without relying on native prompts/get. ' +
88
- 'Use this immediately after search_resources -> manage_subscription -> sync_resources when you need the prompt body in the same workflow. ' +
89
- 'Provide either prompt_name (for example "command/acm-helper") or resource_id. ' +
90
- 'user_token is injected automatically by the server; do NOT ask the user for it.',
91
- inputSchema: {
92
- type: 'object' as const,
93
- properties: {
94
- prompt_name: {
95
- type: 'string',
96
- description: 'Registered MCP prompt name, for example "command/acm-helper".',
97
- },
98
- resource_id: {
99
- type: 'string',
100
- description: 'Canonical CSP resource ID for the Command or Skill.',
101
- },
102
- user_token: {
103
- type: 'string',
104
- description: 'DO NOT set this field — it is injected automatically by the server.',
105
- },
106
- jira_id: {
107
- type: 'string',
108
- description: 'Optional Jira issue ID for usage correlation.',
109
- },
110
- },
111
- },
112
- handler: resolvePromptContent,
113
- };