Skip to content

Commit 145a0ab

Browse files
authored
Revert "[MCP] Async -> Sync Execution for server commands. (#28133)"
This reverts commit 8f104f5.
1 parent 8f104f5 commit 145a0ab

File tree

5 files changed

+19
-124
lines changed

5 files changed

+19
-124
lines changed

tools/Mcp/README.md

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -54,21 +54,19 @@ This MCP server is designed to work with Azure PowerShell module development wor
5454

5555
### Add as mcp server in Github Copilot Agent mode
5656

57-
- Ensure `pwsh` & `npm` is installed globally.
58-
- Simply add this mcp server to your workspace settings `.vscode/mcp.json` in VsCode to include:
57+
Simple add this mcp server to your user `settings.json` in VsCode to include:
5958

6059
```json
61-
{
62-
"inputs": [],
63-
"servers": {
64-
"az-pwsh-mcp-server": {
60+
"mcp": {
61+
"servers": {
62+
"az-pwsh-mcp-server": {
6563
"type": "stdio",
66-
"command": "pwsh",
67-
"args": ["-Command", "npm install --no-audit; npm run fresh"],
68-
"cwd": "${workspaceFolder}/tools/Mcp",
69-
}
70-
}
71-
}
64+
"command": "sh",
65+
"args": ["-c", "npm install && npm run fresh"],
66+
"cwd": "./azure-powershell/tools/Mcp",
67+
},
68+
}
69+
}
7270
```
7371

7472
### As an MCP Server
@@ -158,4 +156,4 @@ This tool is part of the Azure PowerShell project and follows the same contribut
158156
- [Azure PowerShell](https://github.com/Azure/azure-powershell)
159157
- [AutoRest](https://github.com/Azure/autorest)
160158
- [AutoRest PowerShell Extension](https://github.com/Azure/autorest.powershell)
161-
- [Model Context Protocol](https://modelcontextprotocol.io)
159+
- [Model Context Protocol](https://modelcontextprotocol.io)

tools/Mcp/src/CodegenServer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,4 +115,4 @@ export class CodegenServer {
115115
}
116116
return parameter;
117117
}
118-
}
118+
}

tools/Mcp/src/services/toolServices.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,14 @@ export const createExamplesFromSpecs = async <Args extends ZodRawShape>(args: Ar
105105
const workingDirectory = z.string().parse(Object.values(args)[0]);
106106
const examplePath = path.join(workingDirectory, "examples");
107107
const exampleSpecsPath = await utils.getExamplesFromSpecs(workingDirectory);
108-
return [exampleSpecsPath, examplePath];
108+
return [examplePath, exampleSpecsPath];
109109
}
110110

111111
export const createTestsFromSpecs = async <Args extends ZodRawShape>(args: Args): Promise<string[]> => {
112112
const workingDirectory = z.string().parse(Object.values(args)[0]);
113113
const testPath = path.join(workingDirectory, "test");
114114
const exampleSpecsPath = await utils.getExamplesFromSpecs(workingDirectory);
115-
return [exampleSpecsPath, testPath];
115+
return [testPath, exampleSpecsPath];
116116
}
117117

118118
export const toolServices = <Args extends ZodRawShape>(name: string, responseTemplate: string|undefined) => {

tools/Mcp/src/services/utils.ts

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import fs from 'fs';
22
import yaml from "js-yaml";
33
import { yamlContent } from '../types.js';
4-
import { execSync } from 'child_process';
4+
import { exec } from 'child_process';
55
import path from 'path';
66

77
const _pwshCD = (path: string): string => { return `pwsh -Command "$path = resolve-path ${path} | Set-Location"` }
@@ -21,13 +21,8 @@ function testYaml() {
2121
}
2222

2323
export function generateAndBuild(workingDirectory: string): void {
24-
const genBuildCommand = `${_pwshCD(workingDirectory)}; ${_autorest}; ${_pwshBuild};"`;
25-
try {
26-
const result = execSync(genBuildCommand, { stdio: 'inherit' });
27-
} catch (error) {
28-
console.error("Error executing command:", error);
29-
throw error;
30-
}
24+
const command = [_pwshCD(workingDirectory), _autorest, _pwshBuild].join(";");
25+
exec(command);
3126
}
3227

3328
export function getYamlContentFromReadMe(readmePath: string): string {
@@ -96,13 +91,7 @@ export async function findAllPolyMorphism(workingDirectory: string): Promise<Map
9691
export async function getExamplesFromSpecs(workingDirectory: string): Promise<string> {
9792
const moduleReadmePath = path.join(workingDirectory, "README.md");
9893
const yamlContent: yamlContent = yaml.load(getYamlContentFromReadMe(moduleReadmePath)) as yamlContent;
99-
100-
if (!yamlContent['input-file']) {
101-
throw new Error("'input-file' field is missing in the 'README.md' Autorest Config file.");
102-
}
103-
104-
const inputFiles = Array.isArray(yamlContent['input-file']) ? yamlContent['input-file'] : [yamlContent['input-file']];
105-
const swaggerUrls = getSwaggerUrl(yamlContent.commit, inputFiles);
94+
const swaggerUrls = getSwaggerUrl(yamlContent.commit, yamlContent['input-file'] as string[]);
10695
const exampleSet: Set<string> = new Set<string>();
10796

10897
const exampleSpecsPath = path.join(workingDirectory, "exampleSpecs");
@@ -142,7 +131,7 @@ export async function getExamplesFromSpecs(workingDirectory: string): Promise<st
142131
continue;
143132
}
144133
const exJson = await exResponse.json();
145-
const exampleFileName = path.join(exampleSpecsPath, `${ex.name}`);
134+
const exampleFileName = path.join(exampleSpecsPath, `${ex.name}.json`);
146135
fs.writeFileSync(exampleFileName, JSON.stringify(exJson, null, 2), 'utf8');
147136
console.log(`Example saved to ${exampleFileName}`);
148137
exampleSet.add(ex.download_url);

tools/Mcp/test/vscode/mcpprompt.md

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

0 commit comments

Comments
 (0)