Skip to content

Commit 89e98bf

Browse files
authored
refactor: standardize tool response format and update dependencies (#8)
* refactor: standardize tool response format and update dependencies * refactor: simplify path handling and improve tool responses
1 parent 626e08e commit 89e98bf

18 files changed

+369
-290
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ MCP collection for the [umi](https://github.com/umijs/umi) framework.
3030
- `umi-version`, Show the version of the umi project.
3131
- `umi-route-list`, List all routes of the umi project. (Based on the appData under `.umi` directory)
3232
- `umi-appdata-list`, List detailed app data of the umi project. (Based on the appData under `.umi` directory)
33-
- `umi-changelog`, Show the changelog of the umi and @umijs/max.
3433

3534
## Usage
3635

package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,21 @@
3535
"license": "MIT",
3636
"devDependencies": {
3737
"@modelcontextprotocol/inspector": "^0.8.2",
38-
"@modelcontextprotocol/sdk": "^1.9.0",
38+
"@modelcontextprotocol/sdk": "^1.10.2",
3939
"@trivago/prettier-plugin-sort-imports": "^5.2.2",
40-
"@types/node": "^22.14.0",
40+
"@types/node": "^22.15.2",
4141
"@types/resolve": "^1.20.6",
4242
"@types/yargs-parser": "^21.0.3",
43-
"@umijs/tools": "^0.1.34",
44-
"fastmcp": "^1.21.0",
43+
"@umijs/tools": "^0.1.36",
44+
"fastmcp": "^1.22.4",
4545
"prettier": "^3.5.3",
4646
"resolve": "^1.22.10",
47-
"takumi": "^0.0.7",
47+
"takumi": "^0.0.15",
4848
"tsx": "^4.19.3",
4949
"typescript": "^5.8.3",
50-
"vitest": "^3.1.1",
50+
"vitest": "^3.1.2",
5151
"yargs-parser": "^21.1.1",
52-
"zod": "^3.24.2"
52+
"zod": "^3.24.3"
5353
},
5454
"volta": {
5555
"node": "22.11.0",

pnpm-lock.yaml

Lines changed: 188 additions & 187 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,4 @@ export function registerTools(toolContext: ToolContext) {
2424
umiLint(toolContext);
2525
umiRouteList(toolContext);
2626
umiAppdataList(toolContext);
27-
// umiChangelog(toolContext); // Temporarily commented out as not needed
2827
}

src/parse.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export function parse(root: string) {
2222
`It is not a umi or @umijs/max or @alipay/bigfish project: ${root}`,
2323
);
2424
}
25-
const binPath = (() => {
25+
const getBinPath = () => {
2626
try {
2727
if (isUmi) {
2828
return resolve.sync('umi/bin/umi.js', { basedir: root });
@@ -32,9 +32,22 @@ export function parse(root: string) {
3232
}
3333
return resolve.sync('@alipay/bigfish/bin/bigfish.js', { basedir: root });
3434
} catch (e) {
35+
const binDir = path.join(root, 'node_modules', '.bin');
36+
if (fs.existsSync(binDir)) {
37+
if (isUmi && fs.existsSync(path.join(binDir, 'umi'))) {
38+
return path.join(binDir, 'umi');
39+
}
40+
if (isMax && fs.existsSync(path.join(binDir, 'max'))) {
41+
return path.join(binDir, 'max');
42+
}
43+
if (fs.existsSync(path.join(binDir, 'bigfish'))) {
44+
return path.join(binDir, 'bigfish');
45+
}
46+
}
3547
throw new UserError(`Failed to resolve bin path: ${e}`);
3648
}
37-
})();
49+
};
50+
const binPath = getBinPath();
3851
const binName = (() => {
3952
if (isUmi) {
4053
return 'umi';

src/path.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ function winJoin(...args: string[]) {
1313
return winPath(join(...args));
1414
}
1515

16-
export function getPaths(cwd: string, frameworkName: string) {
16+
export function getPaths(cwd: string) {
1717
const src = winJoin(cwd, 'src');
1818
const absSrcPath = existsSync(src) && statSync(src).isDirectory() ? src : cwd;
19-
const absTmpPath = winJoin(absSrcPath, `.${frameworkName}`);
19+
const absTmpPath = winJoin(absSrcPath, '.umi');
2020
return {
2121
absSrcPath,
2222
absTmpPath,

src/tools/umi-appdata-list.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@ export const umiAppdataList = async ({
1717
parameters: z.object({}),
1818
execute: async (): Promise<any> => {
1919
try {
20-
const { absTmpPath } = getPaths(root, frameworkName);
21-
22-
if (!existsSync(absTmpPath)) {
20+
const { absTmpPath } = getPaths(root);
21+
if (
22+
!existsSync(absTmpPath) ||
23+
!existsSync(`${absTmpPath}/appData.json`)
24+
) {
2325
const { binPath } = parse(root);
2426
execSync(`${binPath} setup`, { cwd: root });
2527
}
@@ -30,18 +32,17 @@ export const umiAppdataList = async ({
3032
`${appDataPath} is not exist, please upgrade to the latest version of ${frameworkName}`,
3133
);
3234
const appDataJson = JSON.parse(readFileSync(appDataPath, 'utf-8'));
33-
return {
34-
success: true,
35-
data: {
36-
type: 'text',
37-
text: JSON.stringify(appDataJson, null, 2),
38-
},
35+
const summary = {
36+
structure: Object.keys(appDataJson),
37+
totalSize: JSON.stringify(appDataJson).length,
38+
moreInfo: 'see src/.umi/appData.json',
3939
};
40-
} catch (error: any) {
4140
return {
42-
success: false,
43-
data: error.message || 'Failed to list app data',
41+
type: 'text',
42+
text: JSON.stringify(summary, null, 2),
4443
};
44+
} catch (error: any) {
45+
return error.message || 'Failed to list app data';
4546
}
4647
},
4748
});

src/tools/umi-build.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,14 @@ export const umiBuild = async ({
5050
cwd: root,
5151
timeout: 5 * 60000,
5252
});
53-
return { success: true, data: result.toString() };
53+
return {
54+
type: 'text',
55+
text: result.toString()
56+
};
5457
} catch (error: any) {
5558
return {
56-
success: false,
57-
data: `Build failed. Please check the error message above.\n${error.message || error}`,
59+
type: 'text',
60+
text: `Build failed. Please check the error message above.\n${error.message || error}`,
5861
};
5962
}
6063
},

src/tools/umi-changelog.ts

Lines changed: 0 additions & 31 deletions
This file was deleted.

src/tools/umi-config.ts

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,15 @@ export const umiConfig = async ({
1616
try {
1717
const { binPath } = parse(root);
1818
const result = execSync(`${binPath} config list`, { cwd: root });
19-
return { success: true, data: result.toString() };
19+
return {
20+
type: 'text',
21+
text: result.toString()
22+
};
2023
} catch (error: any) {
21-
return { success: false, data: error.message || 'Failed to list config' };
24+
return {
25+
type: 'text',
26+
text: error.message || 'Failed to list config'
27+
};
2228
}
2329
},
2430
});
@@ -33,9 +39,15 @@ export const umiConfig = async ({
3339
try {
3440
const { binPath } = parse(root);
3541
const result = execSync(`${binPath} config get ${key}`, { cwd: root });
36-
return { success: true, data: result.toString() };
42+
return {
43+
type: 'text',
44+
text: result.toString()
45+
};
3746
} catch (error: any) {
38-
return { success: false, data: error.message || `Failed to get config key ${key}` };
47+
return {
48+
type: 'text',
49+
text: error.message || `Failed to get config key ${key}`
50+
};
3951
}
4052
},
4153
});
@@ -53,9 +65,15 @@ export const umiConfig = async ({
5365
const result = execSync(`${binPath} config set ${key} ${value}`, {
5466
cwd: root,
5567
});
56-
return { success: true, data: result.toString() };
68+
return {
69+
type: 'text',
70+
text: result.toString()
71+
};
5772
} catch (error: any) {
58-
return { success: false, data: error.message || `Failed to set config key ${key}` };
73+
return {
74+
type: 'text',
75+
text: error.message || `Failed to set config key ${key}`
76+
};
5977
}
6078
},
6179
});
@@ -72,9 +90,15 @@ export const umiConfig = async ({
7290
const result = execSync(`${binPath} config remove ${key}`, {
7391
cwd: root,
7492
});
75-
return { success: true, data: result.toString() };
93+
return {
94+
type: 'text',
95+
text: result.toString()
96+
};
7697
} catch (error: any) {
77-
return { success: false, data: error.message || `Failed to remove config key ${key}` };
98+
return {
99+
type: 'text',
100+
text: error.message || `Failed to remove config key ${key}`
101+
};
78102
}
79103
},
80104
});

0 commit comments

Comments
 (0)