@utaba/ucm-mcp-server 1.0.0

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 (80) hide show
  1. package/LICENSE +29 -0
  2. package/README.md +79 -0
  3. package/dist/clients/UcmApiClient.d.ts +53 -0
  4. package/dist/clients/UcmApiClient.js +297 -0
  5. package/dist/index.d.ts +3 -0
  6. package/dist/index.js +68 -0
  7. package/dist/interfaces/ILogger.d.ts +8 -0
  8. package/dist/interfaces/ILogger.js +4 -0
  9. package/dist/interfaces/IMcpTool.d.ts +7 -0
  10. package/dist/interfaces/IMcpTool.js +3 -0
  11. package/dist/logging/ConsoleLogger.d.ts +16 -0
  12. package/dist/logging/ConsoleLogger.js +45 -0
  13. package/dist/logging/LoggerFactory.d.ts +9 -0
  14. package/dist/logging/LoggerFactory.js +12 -0
  15. package/dist/server/McpConfig.d.ts +26 -0
  16. package/dist/server/McpConfig.js +93 -0
  17. package/dist/server/McpHandler.d.ts +12 -0
  18. package/dist/server/McpHandler.js +69 -0
  19. package/dist/server/McpServer.d.ts +15 -0
  20. package/dist/server/McpServer.js +49 -0
  21. package/dist/server/ToolRegistry.d.ts +22 -0
  22. package/dist/server/ToolRegistry.js +85 -0
  23. package/dist/tools/artifacts/GetArtifactController.d.ts +34 -0
  24. package/dist/tools/artifacts/GetArtifactController.js +397 -0
  25. package/dist/tools/artifacts/GetLatestController.d.ts +39 -0
  26. package/dist/tools/artifacts/GetLatestController.js +469 -0
  27. package/dist/tools/artifacts/ListVersionsController.d.ts +43 -0
  28. package/dist/tools/artifacts/ListVersionsController.js +530 -0
  29. package/dist/tools/artifacts/PublishArtifactController.d.ts +37 -0
  30. package/dist/tools/artifacts/PublishArtifactController.js +605 -0
  31. package/dist/tools/base/BaseToolController.d.ts +16 -0
  32. package/dist/tools/base/BaseToolController.js +32 -0
  33. package/dist/tools/core/DeleteArtifactTool.d.ts +11 -0
  34. package/dist/tools/core/DeleteArtifactTool.js +82 -0
  35. package/dist/tools/core/GetArtifactTool.d.ts +13 -0
  36. package/dist/tools/core/GetArtifactTool.js +125 -0
  37. package/dist/tools/core/GetArtifactVersionsTool.d.ts +11 -0
  38. package/dist/tools/core/GetArtifactVersionsTool.js +63 -0
  39. package/dist/tools/core/GetChunkTool.d.ts +11 -0
  40. package/dist/tools/core/GetChunkTool.js +56 -0
  41. package/dist/tools/core/ListArtifactsTool.d.ts +11 -0
  42. package/dist/tools/core/ListArtifactsTool.js +84 -0
  43. package/dist/tools/core/PublishArtifactFromFileTool.d.ts +15 -0
  44. package/dist/tools/core/PublishArtifactFromFileTool.js +256 -0
  45. package/dist/tools/core/PublishArtifactTool.d.ts +13 -0
  46. package/dist/tools/core/PublishArtifactTool.js +197 -0
  47. package/dist/tools/discovery/BrowseCategoriesController.d.ts +25 -0
  48. package/dist/tools/discovery/BrowseCategoriesController.js +400 -0
  49. package/dist/tools/discovery/FindByPurposeController.d.ts +12 -0
  50. package/dist/tools/discovery/FindByPurposeController.js +131 -0
  51. package/dist/tools/discovery/ListAuthorsController.d.ts +20 -0
  52. package/dist/tools/discovery/ListAuthorsController.js +274 -0
  53. package/dist/tools/discovery/SearchArtifactsController.d.ts +14 -0
  54. package/dist/tools/discovery/SearchArtifactsController.js +226 -0
  55. package/dist/tools/list/ListNamespaceController.d.ts +1 -0
  56. package/dist/tools/list/ListNamespaceController.js +8 -0
  57. package/dist/tools/navigation/ExploreNamespaceController.d.ts +35 -0
  58. package/dist/tools/navigation/ExploreNamespaceController.js +548 -0
  59. package/dist/tools/utility/AuthorIndexTool.d.ts +11 -0
  60. package/dist/tools/utility/AuthorIndexTool.js +48 -0
  61. package/dist/tools/utility/HealthCheckController.d.ts +11 -0
  62. package/dist/tools/utility/HealthCheckController.js +56 -0
  63. package/dist/tools/utility/ListRepositoriesTool.d.ts +11 -0
  64. package/dist/tools/utility/ListRepositoriesTool.js +70 -0
  65. package/dist/tools/utility/QuickstartTool.d.ts +11 -0
  66. package/dist/tools/utility/QuickstartTool.js +36 -0
  67. package/dist/tools/utility/ValidatePathController.d.ts +30 -0
  68. package/dist/tools/utility/ValidatePathController.js +465 -0
  69. package/dist/types/UcmApiTypes.d.ts +40 -0
  70. package/dist/types/UcmApiTypes.js +4 -0
  71. package/dist/utils/McpErrorHandler.d.ts +25 -0
  72. package/dist/utils/McpErrorHandler.js +67 -0
  73. package/dist/utils/PathUtils.d.ts +61 -0
  74. package/dist/utils/PathUtils.js +178 -0
  75. package/dist/utils/ResponseChunker.d.ts +25 -0
  76. package/dist/utils/ResponseChunker.js +79 -0
  77. package/dist/utils/ValidationUtils.d.ts +10 -0
  78. package/dist/utils/ValidationUtils.js +50 -0
  79. package/package.json +37 -0
  80. package/package.json.backup +37 -0
@@ -0,0 +1,256 @@
1
+ import { BaseToolController } from '../base/BaseToolController.js';
2
+ import { parsePath } from '../../utils/PathUtils.js';
3
+ import { McpError, McpErrorCode } from '../../utils/McpErrorHandler.js';
4
+ import { readFileSync, existsSync, statSync } from 'fs';
5
+ import { fileURLToPath } from 'url';
6
+ export class PublishArtifactFromFileTool extends BaseToolController {
7
+ constructor(ucmClient, logger, publishingAuthorId) {
8
+ super(ucmClient, logger, publishingAuthorId);
9
+ }
10
+ get name() {
11
+ return 'mcp_ucm_publish_artifact_fromfile';
12
+ }
13
+ get description() {
14
+ return 'Create or update UCM artifacts from a file URI. Supports versioning. PREFERRED METHOD: Use this tool for file-based content as it is much faster and more efficient. Pass the local file path as a file:// URI (e.g., "file:///path/to/file.txt").';
15
+ }
16
+ get inputSchema() {
17
+ return {
18
+ type: 'object',
19
+ properties: {
20
+ path: {
21
+ type: 'string',
22
+ description: `Artifact namespace path (e.g., "${this.publishingAuthorId || '1234567890'}/main/commands/user")`,
23
+ minLength: 1,
24
+ maxLength: 200
25
+ },
26
+ filename: {
27
+ type: 'string',
28
+ description: 'Filename with extension (e.g., "CreateUserCommand.ts")',
29
+ minLength: 1,
30
+ maxLength: 100
31
+ },
32
+ fileUri: {
33
+ type: 'string',
34
+ description: 'File URI pointing to the content file (e.g., "file:///tmp/large-file.txt"). Use local file paths converted to file:// URIs.',
35
+ minLength: 1
36
+ },
37
+ description: {
38
+ type: 'string',
39
+ description: 'Optional description of the artifact'
40
+ },
41
+ version: {
42
+ type: 'string',
43
+ description: 'Semantic version (e.g., "1.0.0") - optional, defaults to 1.0.0 for new artifacts'
44
+ },
45
+ technology: {
46
+ type: 'string',
47
+ description: 'Technology stack (e.g., "typescript", "python"). Optional and will attempt to auto-detect'
48
+ },
49
+ mimeType: {
50
+ type: 'string',
51
+ description: 'MIME type (auto-detected if not provided)'
52
+ }
53
+ },
54
+ required: ['path', 'filename', 'fileUri']
55
+ };
56
+ }
57
+ async handleExecute(params) {
58
+ const { path, filename, fileUri, description, version, technology, mimeType } = params;
59
+ this.logger.debug('PublishArtifactFromFileTool', `Publishing artifact from file: ${fileUri}`, '', {
60
+ path: `${path}/${filename}`,
61
+ version: version
62
+ });
63
+ try {
64
+ // Parse and validate the file URI
65
+ const filePath = this.parseFileUri(fileUri);
66
+ // Read the file content
67
+ const content = this.readFileContent(filePath);
68
+ this.logger.debug('PublishArtifactFromFileTool', `File read successfully: ${filePath}`, '', {
69
+ size: content.length
70
+ });
71
+ // Parse the path to extract components
72
+ const pathComponents = parsePath(path);
73
+ // Validate path components exist including repository
74
+ if (!pathComponents.author || !pathComponents.repository || !pathComponents.category || !pathComponents.subcategory) {
75
+ throw new McpError(McpErrorCode.InvalidParams, `Path must contain author, repository, category, and subcategory (e.g., "${this.publishingAuthorId || '1234567890'}/main/commands/user")`);
76
+ }
77
+ // Validate repository is 'main' for MVP
78
+ if (pathComponents.repository !== 'main') {
79
+ throw new McpError(McpErrorCode.InvalidParams, `Repository must be 'main' for MVP. Received: "${pathComponents.repository}"`);
80
+ }
81
+ // Prepare the publish data - new API expects content in body and metadata in query params
82
+ const publishData = {
83
+ content, // Raw text content from file
84
+ queryParams: {
85
+ filename,
86
+ version: version ? version.replace(/^v/, '') : undefined, // Remove v prefix if present, undefined if not provided
87
+ description: description,
88
+ technology: technology,
89
+ mimeType: mimeType || this.detectMimeType(filename)
90
+ }
91
+ };
92
+ // Always use POST endpoint - the API will detect create vs update automatically
93
+ const result = await this.ucmClient.publishArtifact(pathComponents.author, pathComponents.repository, pathComponents.category, pathComponents.subcategory, publishData);
94
+ // Handle response structure - API might return wrapped in 'data' or direct
95
+ const artifactData = result.data || result;
96
+ // Build successful response
97
+ const response = {
98
+ success: true,
99
+ artifact: {
100
+ id: artifactData.id,
101
+ namespace: `${pathComponents.author}/${pathComponents.repository}/${pathComponents.category}/${pathComponents.subcategory}`,
102
+ filename,
103
+ version: publishData.queryParams.version,
104
+ name: filename, // Use filename as name, matching what the API does
105
+ description: description,
106
+ author: pathComponents.author,
107
+ technology: technology,
108
+ fileSize: content.length,
109
+ mimeType: publishData.queryParams.mimeType,
110
+ createdAt: artifactData.createdAt,
111
+ publishedAt: artifactData.publishedAt,
112
+ sourceFile: filePath
113
+ },
114
+ links: {
115
+ self: `/api/v1/authors/${pathComponents.author}/${pathComponents.repository}/${pathComponents.category}/${pathComponents.subcategory}/${filename}`,
116
+ download: `/api/v1/files/${pathComponents.author}/${pathComponents.repository}/${pathComponents.category}/${pathComponents.subcategory}/${filename}`,
117
+ versions: `/api/v1/authors/${pathComponents.author}/${pathComponents.repository}/${pathComponents.category}/${pathComponents.subcategory}/${filename}/versions`
118
+ }
119
+ };
120
+ this.logger.info('PublishArtifactFromFileTool', `Artifact published successfully from file: ${filePath}`, '', {
121
+ path: `${path}/${filename}`,
122
+ version: publishData.queryParams.version,
123
+ size: content.length,
124
+ id: artifactData.id
125
+ });
126
+ return response;
127
+ }
128
+ catch (error) {
129
+ this.logger.error('PublishArtifactFromFileTool', `Failed to publish artifact from file: ${fileUri}`, '', error);
130
+ // Enhanced error handling for publish operations
131
+ const errorMessage = error instanceof Error ? error.message : String(error);
132
+ // Handle ENOENT errors that might come from the API or filesystem
133
+ if (errorMessage?.includes('ENOENT') || errorMessage?.includes('no such file or directory')) {
134
+ throw new McpError(McpErrorCode.InvalidParams, `File not found: The specified file "${fileUri}" does not exist. Please verify:
135
+ 1. The file path is correct and complete
136
+ 2. The file exists at the specified location
137
+ 3. You have permission to access the file
138
+ 4. The file URI uses the correct format: file:///full/path/to/file.ext`);
139
+ }
140
+ if (errorMessage?.includes('already exists')) {
141
+ throw new McpError(McpErrorCode.InvalidParams, 'Artifact version already exists. The API automatically handles updates to existing artifacts.');
142
+ }
143
+ if (errorMessage?.includes('Author not found')) {
144
+ let authorCustomMessage = '';
145
+ if (this.publishingAuthorId) {
146
+ authorCustomMessage = `Did you mean '${this.publishingAuthorId}'`;
147
+ }
148
+ throw new McpError(McpErrorCode.InvalidParams, `Author '${parsePath(path).author}' not found. ${authorCustomMessage}`);
149
+ }
150
+ if (errorMessage?.includes('technology') && errorMessage?.includes('required')) {
151
+ throw new McpError(McpErrorCode.InvalidParams, `This namespace with category "${parsePath(path).category}" requires a technology to be specified. Please provide the technology parameter (e.g., "typescript", "python", "nextjs").`);
152
+ }
153
+ if (errorMessage?.includes('Invalid namespace format')) {
154
+ throw new McpError(McpErrorCode.InvalidParams, `Invalid namespace format: "${path}". The namespace must follow the pattern "${this.publishingAuthorId || 'author'}/repository/category/subcategory" where repository is 'main' (for MVP) and category is one of: commands, services, patterns, implementations, contracts, guidance, project. Example: "utaba/main/commands/user"`);
155
+ }
156
+ throw error;
157
+ }
158
+ }
159
+ validateParams(params) {
160
+ super.validateParams(params);
161
+ const { fileUri, version } = params;
162
+ // Validate file URI
163
+ if (!fileUri || typeof fileUri !== 'string') {
164
+ throw new McpError(McpErrorCode.InvalidParams, 'fileUri is required and must be a string');
165
+ }
166
+ // Validate file URI format
167
+ if (!fileUri.startsWith('file://')) {
168
+ throw new McpError(McpErrorCode.InvalidParams, 'fileUri must be a valid file URI starting with "file://"');
169
+ }
170
+ // Validate version format if provided
171
+ if (version && version.length > 0) {
172
+ const versionPattern = /^v?[0-9]+\.[0-9]+\.[0-9]+$/;
173
+ if (!versionPattern.test(version)) {
174
+ throw new McpError(McpErrorCode.InvalidParams, 'version must follow semantic versioning format (e.g., "1.0.0" or "v1.0.0")');
175
+ }
176
+ }
177
+ }
178
+ parseFileUri(fileUri) {
179
+ try {
180
+ // Convert file URI to file path
181
+ const filePath = fileURLToPath(fileUri);
182
+ // Security check - ensure file is accessible and not attempting path traversal
183
+ if (filePath.includes('..') || filePath.includes('~')) {
184
+ throw new McpError(McpErrorCode.InvalidParams, 'File path contains invalid characters or path traversal attempts');
185
+ }
186
+ return filePath;
187
+ }
188
+ catch (error) {
189
+ throw new McpError(McpErrorCode.InvalidParams, `Invalid file URI: ${fileUri}. Must be a valid file:// URI.`);
190
+ }
191
+ }
192
+ readFileContent(filePath) {
193
+ try {
194
+ // Check if file exists
195
+ if (!existsSync(filePath)) {
196
+ throw new McpError(McpErrorCode.InvalidParams, `File not found: ${filePath}. Please verify the file path is correct and the file exists.`);
197
+ }
198
+ // Check file size (maintain reasonable limit for memory usage)
199
+ const stats = statSync(filePath);
200
+ const maxFileSize = 100 * 1024 * 1024; // 100MB limit
201
+ if (stats.size > maxFileSize) {
202
+ throw new McpError(McpErrorCode.InvalidParams, `File size (${stats.size} bytes) exceeds maximum limit of ${maxFileSize} bytes`);
203
+ }
204
+ // Read file content
205
+ const content = readFileSync(filePath, 'utf8');
206
+ return content;
207
+ }
208
+ catch (error) {
209
+ if (error instanceof McpError) {
210
+ throw error;
211
+ }
212
+ // Handle specific filesystem errors with AI-friendly messages
213
+ if (error instanceof Error) {
214
+ if (error.message.includes('ENOENT') || error.message.includes('no such file or directory')) {
215
+ throw new McpError(McpErrorCode.InvalidParams, `File not found: ${filePath}. The file does not exist at the specified path. Please check that:
216
+ 1. The file path is correct
217
+ 2. The file has not been moved or deleted
218
+ 3. You have permission to access the file
219
+ 4. The path uses forward slashes (/), not backslashes (\\)`);
220
+ }
221
+ if (error.message.includes('EACCES') || error.message.includes('permission denied')) {
222
+ throw new McpError(McpErrorCode.InvalidParams, `Permission denied: Cannot read file ${filePath}. Please check file permissions.`);
223
+ }
224
+ if (error.message.includes('EISDIR') || error.message.includes('illegal operation on a directory')) {
225
+ throw new McpError(McpErrorCode.InvalidParams, `Invalid file path: ${filePath} is a directory, not a file. Please specify the full path to a file.`);
226
+ }
227
+ }
228
+ throw new McpError(McpErrorCode.InternalError, `Failed to read file: ${error instanceof Error ? error.message : String(error)}`);
229
+ }
230
+ }
231
+ detectMimeType(filename) {
232
+ const ext = filename.split('.').pop()?.toLowerCase();
233
+ const mimeTypes = {
234
+ 'ts': 'application/typescript',
235
+ 'js': 'application/javascript',
236
+ 'json': 'application/json',
237
+ 'md': 'text/markdown',
238
+ 'txt': 'text/plain',
239
+ 'yaml': 'text/yaml',
240
+ 'yml': 'text/yaml',
241
+ 'html': 'text/html',
242
+ 'css': 'text/css',
243
+ 'py': 'text/x-python',
244
+ 'java': 'text/x-java',
245
+ 'cs': 'text/x-csharp',
246
+ 'go': 'text/x-go',
247
+ 'rs': 'text/x-rust',
248
+ 'cpp': 'text/x-c++',
249
+ 'c': 'text/x-c',
250
+ 'sh': 'text/x-shellscript',
251
+ 'xml': 'application/xml'
252
+ };
253
+ return mimeTypes[ext || ''] || 'text/plain';
254
+ }
255
+ }
256
+ //# sourceMappingURL=PublishArtifactFromFileTool.js.map
@@ -0,0 +1,13 @@
1
+ import { BaseToolController } from '../base/BaseToolController.js';
2
+ import { UcmApiClient } from '../../clients/UcmApiClient.js';
3
+ import { ILogger } from '../../interfaces/ILogger.js';
4
+ export declare class PublishArtifactTool extends BaseToolController {
5
+ constructor(ucmClient: UcmApiClient, logger: ILogger, publishingAuthorId?: string);
6
+ get name(): string;
7
+ get description(): string;
8
+ get inputSchema(): any;
9
+ protected handleExecute(params: any): Promise<any>;
10
+ protected validateParams(params: any): void;
11
+ private detectMimeType;
12
+ }
13
+ //# sourceMappingURL=PublishArtifactTool.d.ts.map
@@ -0,0 +1,197 @@
1
+ import { BaseToolController } from '../base/BaseToolController.js';
2
+ import { parsePath } from '../../utils/PathUtils.js';
3
+ import { McpError, McpErrorCode } from '../../utils/McpErrorHandler.js';
4
+ export class PublishArtifactTool extends BaseToolController {
5
+ constructor(ucmClient, logger, publishingAuthorId) {
6
+ super(ucmClient, logger, publishingAuthorId);
7
+ }
8
+ get name() {
9
+ return 'mcp_ucm_publish_artifact';
10
+ }
11
+ get description() {
12
+ return 'Create or update UCM artifacts with content and metadata. Supports versioning and automatic conflict detection. The API automatically detects whether to create or update based on existing artifacts. NOTE: Only use this tool for small data - use mcp_ucm_publish_artifact_fromfile for files as it is much faster and more efficient.';
13
+ }
14
+ get inputSchema() {
15
+ return {
16
+ type: 'object',
17
+ properties: {
18
+ path: {
19
+ type: 'string',
20
+ description: `Artifact namespace path (e.g., "${this.publishingAuthorId || '1234567890'}/main/commands/user")`,
21
+ minLength: 1,
22
+ maxLength: 200
23
+ },
24
+ filename: {
25
+ type: 'string',
26
+ description: 'Filename with extension (e.g., "CreateUserCommand.ts")',
27
+ minLength: 1,
28
+ maxLength: 100
29
+ },
30
+ content: {
31
+ type: 'string',
32
+ description: 'The artifact content as text',
33
+ minLength: 1
34
+ },
35
+ description: {
36
+ type: 'string',
37
+ description: 'Optional description of the artifact'
38
+ },
39
+ version: {
40
+ type: 'string',
41
+ description: 'Semantic version (e.g., "1.0.0") - optional, defaults to 1.0.0 for new artifacts'
42
+ },
43
+ technology: {
44
+ type: 'string',
45
+ description: 'Technology stack (e.g., "typescript", "python"). Optional - only required for certain categories like "implementations"'
46
+ },
47
+ mimeType: {
48
+ type: 'string',
49
+ description: 'MIME type (auto-detected if not provided)'
50
+ }
51
+ },
52
+ required: ['path', 'filename', 'content']
53
+ };
54
+ }
55
+ async handleExecute(params) {
56
+ const { path, filename, content, description, version, technology, mimeType } = params;
57
+ this.logger.debug('PublishArtifactTool', `Publishing artifact: ${path}/${filename}`, '', {
58
+ version: version,
59
+ size: content.length
60
+ });
61
+ try {
62
+ // Parse the path to extract components
63
+ const pathComponents = parsePath(path);
64
+ // Validate path components exist including repository
65
+ if (!pathComponents.author || !pathComponents.repository || !pathComponents.category || !pathComponents.subcategory) {
66
+ throw new McpError(McpErrorCode.InvalidParams, 'Path must contain author, repository, category, and subcategory (e.g., "utaba/main/commands/user")');
67
+ }
68
+ // Validate repository is 'main' for MVP
69
+ if (pathComponents.repository !== 'main') {
70
+ throw new McpError(McpErrorCode.InvalidParams, `Repository must be 'main' for MVP. Received: "${pathComponents.repository}"`);
71
+ }
72
+ // Prepare the publish data - new API expects content in body and metadata in query params
73
+ const publishData = {
74
+ content, // Raw text content
75
+ queryParams: {
76
+ filename,
77
+ version: version ? version.replace(/^v/, '') : undefined, // Remove v prefix if present, undefined if not provided
78
+ description: description,
79
+ technology: technology,
80
+ mimeType: mimeType || this.detectMimeType(filename)
81
+ }
82
+ };
83
+ // Always use POST endpoint - the API will detect create vs update automatically
84
+ const result = await this.ucmClient.publishArtifact(pathComponents.author, pathComponents.repository, pathComponents.category, pathComponents.subcategory, publishData);
85
+ // Handle response structure - API might return wrapped in 'data' or direct
86
+ const artifactData = result.data || result;
87
+ // Build successful response
88
+ const response = {
89
+ success: true,
90
+ artifact: {
91
+ id: artifactData.id,
92
+ namespace: `${pathComponents.author}/${pathComponents.repository}/${pathComponents.category}/${pathComponents.subcategory}`,
93
+ filename,
94
+ version: publishData.queryParams.version,
95
+ name: filename, // Use filename as name, matching what the API does
96
+ description: description,
97
+ author: pathComponents.author,
98
+ technology: technology,
99
+ fileSize: content.length,
100
+ mimeType: publishData.queryParams.mimeType,
101
+ createdAt: artifactData.createdAt,
102
+ publishedAt: artifactData.publishedAt
103
+ },
104
+ links: {
105
+ self: `/api/v1/authors/${pathComponents.author}/${pathComponents.repository}/${pathComponents.category}/${pathComponents.subcategory}/${filename}`,
106
+ download: `/api/v1/files/${pathComponents.author}/${pathComponents.repository}/${pathComponents.category}/${pathComponents.subcategory}/${filename}`,
107
+ versions: `/api/v1/authors/${pathComponents.author}/${pathComponents.repository}/${pathComponents.category}/${pathComponents.subcategory}/${filename}/versions`
108
+ }
109
+ };
110
+ this.logger.info('PublishArtifactTool', `Artifact published successfully: ${path}/${filename}`, '', {
111
+ version: publishData.queryParams.version,
112
+ size: content.length,
113
+ id: artifactData.id
114
+ });
115
+ return response;
116
+ }
117
+ catch (error) {
118
+ this.logger.error('PublishArtifactTool', `Failed to publish artifact: ${path}/${filename}`, '', error);
119
+ // Enhanced error handling for publish operations
120
+ const errorMessage = error instanceof Error ? error.message : String(error);
121
+ // if (errorMessage?.includes('Version is required')) {
122
+ // throw new McpError(
123
+ // McpErrorCode.InvalidParams,
124
+ // 'Version is required in metadata.version field'
125
+ // );
126
+ // }
127
+ if (errorMessage?.includes('already exists')) {
128
+ throw new McpError(McpErrorCode.InvalidParams, 'Artifact version already exists. The API automatically handles updates to existing artifacts.');
129
+ }
130
+ if (errorMessage?.includes('Author not found')) {
131
+ let authorCustomMessage = '';
132
+ if (this.publishingAuthorId) {
133
+ authorCustomMessage = `Did you mean '${this.publishingAuthorId}'`;
134
+ }
135
+ throw new McpError(McpErrorCode.InvalidParams, `Author '${parsePath(path).author}' not found. ${authorCustomMessage}`);
136
+ }
137
+ if (errorMessage?.includes('technology') && errorMessage?.includes('required')) {
138
+ throw new McpError(McpErrorCode.InvalidParams, `This namespace with category "${parsePath(path).category}" requires a technology to be specified. Please provide the technology parameter (e.g., "typescript", "python", "nextjs").`);
139
+ }
140
+ // Handle ENOENT errors that might come from the API
141
+ if (errorMessage?.includes('ENOENT') || errorMessage?.includes('no such file or directory')) {
142
+ throw new McpError(McpErrorCode.InvalidParams, `Resource not found. This error typically occurs when:
143
+ 1. A required file or directory is missing
144
+ 2. The namespace path is incorrect
145
+ 3. The UCM server cannot access required resources
146
+ Please verify your input parameters and try again.`);
147
+ }
148
+ if (errorMessage?.includes('Invalid namespace format')) {
149
+ throw new McpError(McpErrorCode.InvalidParams, `Invalid namespace format: "${path}". The namespace must follow the pattern "${this.publishingAuthorId || 'author'}/repository/category/subcategory" where repository is 'main' (for MVP) and category is one of: commands, services, patterns, implementations, contracts, guidance, project. Example: "utaba/main/commands/user"`);
150
+ }
151
+ throw error;
152
+ }
153
+ }
154
+ validateParams(params) {
155
+ super.validateParams(params);
156
+ const { content, version } = params;
157
+ // Validate version format if provided
158
+ if (version && version.length > 0) {
159
+ const versionPattern = /^v?[0-9]+\.[0-9]+\.[0-9]+$/;
160
+ if (!versionPattern.test(version)) {
161
+ throw new McpError(McpErrorCode.InvalidParams, 'version must follow semantic versioning format (e.g., "1.0.0" or "v1.0.0")');
162
+ }
163
+ }
164
+ // Validate content
165
+ if (!content || typeof content !== 'string') {
166
+ throw new McpError(McpErrorCode.InvalidParams, 'content is required and must be a string');
167
+ }
168
+ if (content.length > 10 * 1024 * 1024) { // 10MB limit
169
+ throw new McpError(McpErrorCode.InvalidParams, 'content size exceeds 10MB limit');
170
+ }
171
+ }
172
+ detectMimeType(filename) {
173
+ const ext = filename.split('.').pop()?.toLowerCase();
174
+ const mimeTypes = {
175
+ 'ts': 'application/typescript',
176
+ 'js': 'application/javascript',
177
+ 'json': 'application/json',
178
+ 'md': 'text/markdown',
179
+ 'txt': 'text/plain',
180
+ 'yaml': 'text/yaml',
181
+ 'yml': 'text/yaml',
182
+ 'html': 'text/html',
183
+ 'css': 'text/css',
184
+ 'py': 'text/x-python',
185
+ 'java': 'text/x-java',
186
+ 'cs': 'text/x-csharp',
187
+ 'go': 'text/x-go',
188
+ 'rs': 'text/x-rust',
189
+ 'cpp': 'text/x-c++',
190
+ 'c': 'text/x-c',
191
+ 'sh': 'text/x-shellscript',
192
+ 'xml': 'application/xml'
193
+ };
194
+ return mimeTypes[ext || ''] || 'text/plain';
195
+ }
196
+ }
197
+ //# sourceMappingURL=PublishArtifactTool.js.map
@@ -0,0 +1,25 @@
1
+ import { BaseToolController } from '../base/BaseToolController.js';
2
+ import { UcmApiClient } from '../../clients/UcmApiClient.js';
3
+ import { ILogger } from '../../interfaces/ILogger.js';
4
+ export declare class BrowseCategoriesController extends BaseToolController {
5
+ constructor(ucmClient: UcmApiClient, logger: ILogger);
6
+ get name(): string;
7
+ get description(): string;
8
+ get inputSchema(): any;
9
+ protected handleExecute(params: any): Promise<any>;
10
+ private getAuthorCategories;
11
+ private getAllCategories;
12
+ private groupByCategory;
13
+ private groupByAuthor;
14
+ private groupByTechnology;
15
+ private processCategories;
16
+ private addCounts;
17
+ private addPreviews;
18
+ private filterEmptyCategories;
19
+ private hasContent;
20
+ private getPreviewArtifacts;
21
+ private sortCategories;
22
+ private getCategoryDescription;
23
+ private buildNavigationHints;
24
+ }
25
+ //# sourceMappingURL=BrowseCategoriesController.d.ts.map