Skip to content

Commit c40f6c8

Browse files
committed
fix(angular-mcp-server): format errors fix
1 parent 1537fcb commit c40f6c8

File tree

2 files changed

+78
-40
lines changed

2 files changed

+78
-40
lines changed

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

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
import { ToolSchemaOptions } from '@push-based/models';
2-
import { createHandler, BaseHandlerOptions } from '../shared/utils/handler-helpers.js';
32
import {
4-
COMMON_ANNOTATIONS,
5-
} from '../shared/models/schema-helpers.js';
3+
createHandler,
4+
BaseHandlerOptions,
5+
} from '../shared/utils/handler-helpers.js';
6+
import { COMMON_ANNOTATIONS } from '../shared/models/schema-helpers.js';
67
import { getComponentPathsInfo } from './utils/paths-helpers.js';
78
import { getComponentDocPathsForName } from './utils/doc-helpers.js';
8-
import { validateComponentName, componentNameToKebabCase } from '../shared/utils/component-validation.js';
9+
import {
10+
validateComponentName,
11+
componentNameToKebabCase,
12+
} from '../shared/utils/component-validation.js';
913
import { resolveCrossPlatformPath } from '../shared/utils/cross-platform-path.js';
1014
import * as fs from 'fs';
1115
import * as path from 'path';
@@ -31,15 +35,17 @@ export const getDsComponentDataToolSchema: ToolSchemaOptions = {
3135
properties: {
3236
componentName: {
3337
type: 'string',
34-
description: 'The class name of the component to get data for (e.g., DsBadge)',
38+
description:
39+
'The class name of the component to get data for (e.g., DsBadge)',
3540
},
3641
sections: {
3742
type: 'array',
3843
items: {
3944
type: 'string',
4045
enum: ['implementation', 'documentation', 'stories', 'all'],
4146
},
42-
description: 'Sections to include in the response. Options: "implementation", "documentation", "stories", "all". Defaults to ["all"] if not specified.',
47+
description:
48+
'Sections to include in the response. Options: "implementation", "documentation", "stories", "all". Defaults to ["all"] if not specified.',
4349
default: ['all'],
4450
},
4551
},
@@ -82,15 +88,15 @@ function getAllFilesInDirectory(dirPath: string): string[] {
8288

8389
function findStoriesFiles(componentPath: string): string[] {
8490
const storiesFiles: string[] = [];
85-
91+
8692
try {
8793
if (fs.existsSync(componentPath)) {
8894
const items = fs.readdirSync(componentPath);
89-
95+
9096
for (const item of items) {
9197
const fullPath = path.join(componentPath, item);
9298
const stat = fs.statSync(fullPath);
93-
99+
94100
if (stat.isFile() && item.endsWith('.stories.ts')) {
95101
storiesFiles.push(fullPath);
96102
}
@@ -99,7 +105,7 @@ function findStoriesFiles(componentPath: string): string[] {
99105
} catch {
100106
return storiesFiles;
101107
}
102-
108+
103109
return storiesFiles;
104110
}
105111

@@ -108,13 +114,18 @@ export const getDsComponentDataHandler = createHandler<
108114
DsComponentData
109115
>(
110116
getDsComponentDataToolSchema.name,
111-
async ({ componentName, sections = ['all'] }, { cwd, uiRoot, storybookDocsRoot }) => {
117+
async (
118+
{ componentName, sections = ['all'] },
119+
{ cwd, uiRoot, storybookDocsRoot },
120+
) => {
112121
try {
113122
validateComponentName(componentName);
114123

115124
const includeAll = sections.includes('all');
116-
const includeImplementation = includeAll || sections.includes('implementation');
117-
const includeDocumentation = includeAll || sections.includes('documentation');
125+
const includeImplementation =
126+
includeAll || sections.includes('implementation');
127+
const includeDocumentation =
128+
includeAll || sections.includes('documentation');
118129
const includeStories = includeAll || sections.includes('stories');
119130

120131
const pathsInfo = getComponentPathsInfo(componentName, uiRoot, cwd);
@@ -128,7 +139,10 @@ export const getDsComponentDataHandler = createHandler<
128139
const documentationFiles: string[] = [];
129140
if (includeDocumentation) {
130141
const docsBasePath = resolveCrossPlatformPath(cwd, storybookDocsRoot);
131-
const docPaths = getComponentDocPathsForName(docsBasePath, componentName);
142+
const docPaths = getComponentDocPathsForName(
143+
docsBasePath,
144+
componentName,
145+
);
132146

133147
if (fs.existsSync(docPaths.paths.api)) {
134148
documentationFiles.push(`file://${docPaths.paths.api}`);
@@ -142,7 +156,10 @@ export const getDsComponentDataHandler = createHandler<
142156
if (includeStories) {
143157
const docsBasePath = resolveCrossPlatformPath(cwd, storybookDocsRoot);
144158
const componentFolderName = componentNameToKebabCase(componentName);
145-
const storiesComponentFolderPath = path.join(docsBasePath, componentFolderName);
159+
const storiesComponentFolderPath = path.join(
160+
docsBasePath,
161+
componentFolderName,
162+
);
146163
const storiesFiles = findStoriesFiles(storiesComponentFolderPath);
147164
storiesFilePaths = storiesFiles.map((file) => `file://${file}`);
148165
}

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

Lines changed: 46 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import { ToolSchemaOptions } from '@push-based/models';
2-
import { createHandler, BaseHandlerOptions } from '../shared/utils/handler-helpers.js';
2+
import {
3+
createHandler,
4+
BaseHandlerOptions,
5+
} from '../shared/utils/handler-helpers.js';
36
import { COMMON_ANNOTATIONS } from '../shared/models/schema-helpers.js';
47
import { getComponentPathsInfo } from './utils/paths-helpers.js';
58
import { getComponentDocPathsForName } from './utils/doc-helpers.js';
@@ -32,7 +35,8 @@ export const listDsComponentsToolSchema: ToolSchemaOptions = {
3235
type: 'string',
3336
enum: ['implementation', 'documentation', 'stories', 'all'],
3437
},
35-
description: 'Sections to include in the response. Options: "implementation", "documentation", "stories", "all". Defaults to ["all"] if not specified.',
38+
description:
39+
'Sections to include in the response. Options: "implementation", "documentation", "stories", "all". Defaults to ["all"] if not specified.',
3640
default: ['all'],
3741
},
3842
},
@@ -74,30 +78,37 @@ function getAllFilesInDirectory(dirPath: string): string[] {
7478
}
7579

7680
function kebabCaseToPascalCase(kebabCase: string): string {
77-
return 'Ds' + kebabCase
78-
.split('-')
79-
.map((part) => part.charAt(0).toUpperCase() + part.slice(1))
80-
.join('');
81+
return (
82+
'Ds' +
83+
kebabCase
84+
.split('-')
85+
.map((part) => part.charAt(0).toUpperCase() + part.slice(1))
86+
.join('')
87+
);
8188
}
8289

8390
function isValidComponentFolder(folderPath: string): boolean {
8491
const packageJsonPath = path.join(folderPath, 'package.json');
8592
const srcPath = path.join(folderPath, 'src');
86-
87-
return fs.existsSync(packageJsonPath) && fs.existsSync(srcPath) && fs.statSync(srcPath).isDirectory();
93+
94+
return (
95+
fs.existsSync(packageJsonPath) &&
96+
fs.existsSync(srcPath) &&
97+
fs.statSync(srcPath).isDirectory()
98+
);
8899
}
89100

90101
function findStoriesFiles(componentPath: string): string[] {
91102
const storiesFiles: string[] = [];
92-
103+
93104
try {
94105
if (fs.existsSync(componentPath)) {
95106
const items = fs.readdirSync(componentPath);
96-
107+
97108
for (const item of items) {
98109
const fullPath = path.join(componentPath, item);
99110
const stat = fs.statSync(fullPath);
100-
111+
101112
if (stat.isFile() && item.endsWith('.stories.ts')) {
102113
storiesFiles.push(fullPath);
103114
}
@@ -106,7 +117,7 @@ function findStoriesFiles(componentPath: string): string[] {
106117
} catch {
107118
return storiesFiles;
108119
}
109-
120+
110121
return storiesFiles;
111122
}
112123

@@ -122,12 +133,14 @@ export const listDsComponentsHandler = createHandler<
122133
}
123134

124135
const componentsBasePath = resolveCrossPlatformPath(cwd, uiRoot);
125-
136+
126137
if (!fs.existsSync(componentsBasePath)) {
127138
throw new Error(`Components directory not found: ${uiRoot}`);
128139
}
129140

130-
const entries = fs.readdirSync(componentsBasePath, { withFileTypes: true });
141+
const entries = fs.readdirSync(componentsBasePath, {
142+
withFileTypes: true,
143+
});
131144
const componentFolders = entries
132145
.filter((entry) => entry.isDirectory())
133146
.map((entry) => entry.name)
@@ -140,14 +153,16 @@ export const listDsComponentsHandler = createHandler<
140153
const docsBasePath = resolveCrossPlatformPath(cwd, storybookDocsRoot);
141154

142155
const includeAll = sections.includes('all');
143-
const includeImplementation = includeAll || sections.includes('implementation');
144-
const includeDocumentation = includeAll || sections.includes('documentation');
156+
const includeImplementation =
157+
includeAll || sections.includes('implementation');
158+
const includeDocumentation =
159+
includeAll || sections.includes('documentation');
145160
const includeStories = includeAll || sections.includes('stories');
146161

147162
for (const folderName of componentFolders) {
148163
try {
149164
const componentName = kebabCaseToPascalCase(folderName);
150-
165+
151166
const pathsInfo = getComponentPathsInfo(componentName, uiRoot, cwd);
152167

153168
let implementationFiles: string[] = [];
@@ -158,8 +173,11 @@ export const listDsComponentsHandler = createHandler<
158173

159174
const documentationFiles: string[] = [];
160175
if (includeDocumentation) {
161-
const docPaths = getComponentDocPathsForName(docsBasePath, componentName);
162-
176+
const docPaths = getComponentDocPathsForName(
177+
docsBasePath,
178+
componentName,
179+
);
180+
163181
if (fs.existsSync(docPaths.paths.api)) {
164182
documentationFiles.push(`file://${docPaths.paths.api}`);
165183
}
@@ -170,7 +188,10 @@ export const listDsComponentsHandler = createHandler<
170188

171189
let storiesFilePaths: string[] = [];
172190
if (includeStories) {
173-
const storiesComponentFolderPath = path.join(docsBasePath, folderName);
191+
const storiesComponentFolderPath = path.join(
192+
docsBasePath,
193+
folderName,
194+
);
174195
const storiesFiles = findStoriesFiles(storiesComponentFolderPath);
175196
storiesFilePaths = storiesFiles.map((file) => `file://${file}`);
176197
}
@@ -184,21 +205,21 @@ export const listDsComponentsHandler = createHandler<
184205
importPath: pathsInfo.importPath,
185206
});
186207
} catch (ctx) {
187-
console.warn(`Warning: Skipped component '${folderName}': ${(ctx as Error).message}`);
208+
console.warn(
209+
`Warning: Skipped component '${folderName}': ${(ctx as Error).message}`,
210+
);
188211
}
189212
}
190213

191214
return components;
192215
} catch (ctx) {
193-
throw new Error(
194-
`Error listing DS components: ${(ctx as Error).message}`,
195-
);
216+
throw new Error(`Error listing DS components: ${(ctx as Error).message}`);
196217
}
197218
},
198219
(components) => {
199220
const response = {
200221
totalComponents: components?.length || 0,
201-
components: components || []
222+
components: components || [],
202223
};
203224

204225
return [JSON.stringify(response, null, 2)];

0 commit comments

Comments
 (0)