Skip to content

Commit 1537fcb

Browse files
committed
fix(angular-mcp-server): proper error handling
1 parent 73fd3ad commit 1537fcb

File tree

2 files changed

+4
-23
lines changed

2 files changed

+4
-23
lines changed

packages/angular-mcp-server/src/lib/tools/ds/component/get-ds-component-data.tool.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ function getAllFilesInDirectory(dirPath: string): string[] {
6969
}
7070
}
7171
} catch {
72-
// Ignore directories that can't be read
72+
return;
7373
}
7474
}
7575

@@ -91,14 +91,13 @@ function findStoriesFiles(componentPath: string): string[] {
9191
const fullPath = path.join(componentPath, item);
9292
const stat = fs.statSync(fullPath);
9393

94-
// Only look for .stories.ts files directly in the component folder, not in subdirectories
9594
if (stat.isFile() && item.endsWith('.stories.ts')) {
9695
storiesFiles.push(fullPath);
9796
}
9897
}
9998
}
10099
} catch {
101-
// Ignore directories that can't be read
100+
return storiesFiles;
102101
}
103102

104103
return storiesFiles;
@@ -113,23 +112,19 @@ export const getDsComponentDataHandler = createHandler<
113112
try {
114113
validateComponentName(componentName);
115114

116-
// Determine which sections to include
117115
const includeAll = sections.includes('all');
118116
const includeImplementation = includeAll || sections.includes('implementation');
119117
const includeDocumentation = includeAll || sections.includes('documentation');
120118
const includeStories = includeAll || sections.includes('stories');
121119

122-
// Get component paths info
123120
const pathsInfo = getComponentPathsInfo(componentName, uiRoot, cwd);
124121

125-
// Get all implementation files in src directory (if requested)
126122
let implementationFiles: string[] = [];
127123
if (includeImplementation) {
128124
const srcFiles = getAllFilesInDirectory(pathsInfo.srcPath);
129125
implementationFiles = srcFiles.map((file) => `file://${file}`);
130126
}
131127

132-
// Get documentation paths (if requested)
133128
const documentationFiles: string[] = [];
134129
if (includeDocumentation) {
135130
const docsBasePath = resolveCrossPlatformPath(cwd, storybookDocsRoot);
@@ -143,7 +138,6 @@ export const getDsComponentDataHandler = createHandler<
143138
}
144139
}
145140

146-
// Get stories files (if requested)
147141
let storiesFilePaths: string[] = [];
148142
if (includeStories) {
149143
const docsBasePath = resolveCrossPlatformPath(cwd, storybookDocsRoot);
@@ -169,7 +163,6 @@ export const getDsComponentDataHandler = createHandler<
169163
(result) => {
170164
const messages: string[] = [];
171165

172-
// Implementation section (only show if it has content or was explicitly requested)
173166
if (result.implementation && result.implementation.length > 0) {
174167
messages.push('Implementation');
175168
messages.push('');
@@ -179,7 +172,6 @@ export const getDsComponentDataHandler = createHandler<
179172
messages.push('');
180173
}
181174

182-
// Documentation section (only show if it has content or was explicitly requested)
183175
if (result.documentation && result.documentation.length > 0) {
184176
messages.push('Documentation');
185177
messages.push('');
@@ -189,7 +181,6 @@ export const getDsComponentDataHandler = createHandler<
189181
messages.push('');
190182
}
191183

192-
// Stories section (only show if it has content or was explicitly requested)
193184
if (result.stories && result.stories.length > 0) {
194185
messages.push('Stories');
195186
messages.push('');
@@ -199,7 +190,6 @@ export const getDsComponentDataHandler = createHandler<
199190
messages.push('');
200191
}
201192

202-
// Import path section (always show if available)
203193
if (result.importPath) {
204194
messages.push('Import path');
205195
messages.push('');

packages/angular-mcp-server/src/lib/tools/ds/component/list-ds-components.tool.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ function getAllFilesInDirectory(dirPath: string): string[] {
6262
}
6363
}
6464
} catch {
65-
// Ignore directories that can't be read
65+
return;
6666
}
6767
}
6868

@@ -98,14 +98,13 @@ function findStoriesFiles(componentPath: string): string[] {
9898
const fullPath = path.join(componentPath, item);
9999
const stat = fs.statSync(fullPath);
100100

101-
// Only look for .stories.ts files directly in the component folder, not in subdirectories
102101
if (stat.isFile() && item.endsWith('.stories.ts')) {
103102
storiesFiles.push(fullPath);
104103
}
105104
}
106105
}
107106
} catch {
108-
// Ignore directories that can't be read
107+
return storiesFiles;
109108
}
110109

111110
return storiesFiles;
@@ -128,7 +127,6 @@ export const listDsComponentsHandler = createHandler<
128127
throw new Error(`Components directory not found: ${uiRoot}`);
129128
}
130129

131-
// Scan for component folders
132130
const entries = fs.readdirSync(componentsBasePath, { withFileTypes: true });
133131
const componentFolders = entries
134132
.filter((entry) => entry.isDirectory())
@@ -141,28 +139,23 @@ export const listDsComponentsHandler = createHandler<
141139
const components: DsComponentInfo[] = [];
142140
const docsBasePath = resolveCrossPlatformPath(cwd, storybookDocsRoot);
143141

144-
// Determine which sections to include
145142
const includeAll = sections.includes('all');
146143
const includeImplementation = includeAll || sections.includes('implementation');
147144
const includeDocumentation = includeAll || sections.includes('documentation');
148145
const includeStories = includeAll || sections.includes('stories');
149146

150147
for (const folderName of componentFolders) {
151148
try {
152-
// Convert folder name to component name (e.g., 'badge' -> 'DsBadge')
153149
const componentName = kebabCaseToPascalCase(folderName);
154150

155-
// Get component paths info
156151
const pathsInfo = getComponentPathsInfo(componentName, uiRoot, cwd);
157152

158-
// Get all implementation files in src directory (if requested)
159153
let implementationFiles: string[] = [];
160154
if (includeImplementation) {
161155
const srcFiles = getAllFilesInDirectory(pathsInfo.srcPath);
162156
implementationFiles = srcFiles.map((file) => `file://${file}`);
163157
}
164158

165-
// Get documentation paths (if requested)
166159
const documentationFiles: string[] = [];
167160
if (includeDocumentation) {
168161
const docPaths = getComponentDocPathsForName(docsBasePath, componentName);
@@ -175,7 +168,6 @@ export const listDsComponentsHandler = createHandler<
175168
}
176169
}
177170

178-
// Get stories files (if requested)
179171
let storiesFilePaths: string[] = [];
180172
if (includeStories) {
181173
const storiesComponentFolderPath = path.join(docsBasePath, folderName);
@@ -192,7 +184,6 @@ export const listDsComponentsHandler = createHandler<
192184
importPath: pathsInfo.importPath,
193185
});
194186
} catch (ctx) {
195-
// Skip components that have issues but continue with others
196187
console.warn(`Warning: Skipped component '${folderName}': ${(ctx as Error).message}`);
197188
}
198189
}

0 commit comments

Comments
 (0)