Skip to content

[MCP] Async -> Sync Execution for server commands. #28133

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: dev/mcp-server
Choose a base branch
from

Conversation

notyashhh
Copy link
Member

@notyashhh notyashhh commented Jul 4, 2025

Description

Mandatory Checklist

  • SHOULD update ChangeLog.md file(s) appropriately
    • Update src/{{SERVICE}}/{{SERVICE}}/ChangeLog.md.
      • A snippet outlining the change(s) made in the PR should be written under the ## Upcoming Release header in the past tense.
    • Should not change ChangeLog.md if no new release is required, such as fixing test case only.
  • SHOULD regenerate markdown help files if there is cmdlet API change. Instruction
  • SHOULD have proper test coverage for changes in pull request.
  • SHOULD NOT adjust version of module manually in pull request

@Copilot Copilot AI review requested due to automatic review settings July 4, 2025 05:07
Copy link

Thanks for your contribution! The pull request validation has started. Please revisit this comment for updated status.

@notyashhh notyashhh changed the base branch from main to dev/mcp-server July 4, 2025 05:07
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces a new Model Context Protocol (MCP) server under tools/Mcp to support synchronous execution of server commands for Azure PowerShell code generation using AutoRest.

  • Sets up the TypeScript project (tsconfig.json, package.json) and adds necessary dependencies.
  • Implements the core MCP server (CodegenServer.ts, index.ts) with tool registration based on JSON specs.
  • Adds utility functions (utils.ts), tool service handlers (toolServices.ts), and tool specifications/responses (specs.json, responses.json).

Reviewed Changes

Copilot reviewed 11 out of 15 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tools/Mcp/tsconfig.json Configures compiler options for the TypeScript project.
tools/Mcp/package.json Defines project metadata, dependencies, and build scripts.
tools/Mcp/src/CodegenServer.ts Implements MCP server initialization and tool registration.
tools/Mcp/src/index.ts Entry point that starts and connects the MCP server.
tools/Mcp/src/services/utils.ts Provides file, YAML, and HTTP utilities for tool operations.
tools/Mcp/src/services/toolServices.ts Contains implementations of MCP tool handlers.
tools/Mcp/src/specs/specs.json Defines tool schemas and callback names used by the server.
tools/Mcp/src/specs/responses.json Provides response templates for each tool.
tools/Mcp/src/types.ts Declares TypeScript types for schemas and directives.
tools/Mcp/README.md Documents installation, usage, and features of the MCP server.
Files not reviewed (1)
  • tools/Mcp/package-lock.json: Language not supported
Comments suppressed due to low confidence (7)

tools/Mcp/src/services/utils.ts:7

  • [nitpick] The parameter name path shadows the imported path module. Consider renaming it to directory or cwd to avoid confusion.
const _pwshCD = (path: string): string => { return `pwsh -Command "$path = resolve-path ${path} | Set-Location"` }

tools/Mcp/src/specs/responses.json:24

  • Spelling error: "Fulfil" should be "Fulfill".
        "type": "tool",

tools/Mcp/src/services/utils.ts:24

  • There's an extraneous trailing double quote at the end of the command string, which will break execution. Remove the final ".
    const genBuildCommand = `${_pwshCD(workingDirectory)}; ${_autorest}; ${_pwshBuild};"`;

tools/Mcp/src/services/utils.ts:11

  • The testYaml function appears to be a leftover utility and is not used elsewhere. Consider removing it or moving it to a dedicated test file.
function testYaml() {

tools/Mcp/src/services/utils.ts:197

  • The testCase function is hardcoded to a local path and unused. Remove it or refactor it into a proper test suite.
export async function testCase() {

tools/Mcp/src/services/toolServices.ts:5

  • The get import from 'http' is unused. Consider removing this import.
import { get } from 'http';

tools/Mcp/src/CodegenServer.ts:106

  • Typo in the description: "such a formal" should read "such as formal" for clarity.
            { name: z.string().describe("Name of the person to greet"), style: z.string().describe("The style of greeting, such a formal, excited, or casual. If not specified casual will be used")}, 

@notyashhh notyashhh self-assigned this Jul 4, 2025
@notyashhh notyashhh requested a review from VeryEarly July 4, 2025 05:13
@@ -105,14 +105,14 @@ export const createExamplesFromSpecs = async <Args extends ZodRawShape>(args: Ar
const workingDirectory = z.string().parse(Object.values(args)[0]);
const examplePath = path.join(workingDirectory, "examples");
const exampleSpecsPath = await utils.getExamplesFromSpecs(workingDirectory);
return [examplePath, exampleSpecsPath];
return [exampleSpecsPath, examplePath];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the reason reversing these 2 responses? There is a certain order in the response string

Copy link
Member Author

@notyashhh notyashhh Jul 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are the wrong way around in the output prompt. It should be swapped because that aligns with the response template.

Screenshot 2025-07-04 at 5 31 11 PM

@@ -0,0 +1,92 @@
# Execution rules
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This prompt doesn't look like part of this mcp server, this is a VSCode prompt. We can make it some kind of test case but not part of this product

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah this is just for reference not a part of the tool...can be removed later if required.

@@ -16,11 +16,11 @@ const responses = JSON.parse(readFileSync(path.join(srcPath, "specs/responses.js

export class CodegenServer {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all changes in this file looks ai generated and haven't really done anything, please revert them all

Copy link
Member Author

@notyashhh notyashhh Jul 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Havent changed anything here,

  1. Renamed _mcp -> _server (which sounds correct...)
  2. moved initTools & initPrompts to the bottom of the file (since they are using other helper fuctions)
  3. renamed initResponses -> readResponses (since its not intializing anything, just importing Responses...)
  4. Added some comments

const exampleFileName = path.join(exampleSpecsPath, `${ex.name}.json`);
fs.writeFileSync(exampleFileName, JSON.stringify(exJson, null, 2), 'utf8');
const exampleFileName = path.join(exampleSpecsPath, `${ex.name}`);
await fs.promises.writeFile(exampleFileName, JSON.stringify(exJson, null, 2), 'utf8');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the purpose of this change? does sync method not working in some scenario?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without this change, control returns to LLM instantly.
The LLM tries to create examples/tests while the module still hasn't even generated.

This change ensures control execution stays on the same thread.
So the execution progresses in an orderly way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants