Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions tools/Mcp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,23 @@ This MCP server is designed to work with Azure PowerShell module development wor

## Usage

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

Simple add this mcp server to your user `settings.json` in VsCode to include:

```json
"mcp": {
"servers": {
"az-pwsh-mcp-server": {
"type": "stdio",
"command": "sh",
"args": ["-c", "npm install && npm run fresh"],
"cwd": "./azure-powershell/tools/Mcp",
},
}
}
```

### As an MCP Server

The server runs on stdio and can be integrated with MCP-compatible clients:
Expand Down
3 changes: 2 additions & 1 deletion tools/Mcp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
},
"scripts": {
"build": "tsc",
"start": "node build/index.js"
"start": "node build/index.js",
"fresh": "npm run build && npm run start"
},
"files": [
"build"
Expand Down
16 changes: 12 additions & 4 deletions tools/Mcp/src/CodegenServer.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import { z } from "zod";
import { toolParameterSchema, toolSchema } from "./types.js";
import specs from "./specs/Specs.json" assert { type: "json" };
import responses from "./specs/responses.json" assert { type: "json" };
import { responseSchema, toolParameterSchema, toolSchema } from "./types.js";
import { toolServices } from "./services/toolServices.js";

import { readFileSync } from "fs";
import path from "path";
import { fileURLToPath } from "url";

const __dirname = path.dirname(fileURLToPath(import.meta.url));
const srcPath = path.resolve(__dirname, "..", "src");

const specs = JSON.parse(readFileSync(path.join(srcPath, "specs/specs.json"), "utf-8"));
const responses = JSON.parse(readFileSync(path.join(srcPath, "specs/responses.json"), "utf-8"));

export class CodegenServer {
private static _instance: CodegenServer;
private _mcp: McpServer;
Expand Down Expand Up @@ -76,7 +84,7 @@ export class CodegenServer {
}

initResponses() {
responses?.forEach(response => {
(responses as responseSchema[])?.forEach((response: responseSchema) => {
this._responses.set(response.name, response.text);
});
}
Expand Down
2 changes: 1 addition & 1 deletion tools/Mcp/src/services/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export async function getExamplesFromSpecs(workingDirectory: string): Promise<st

const list = await response.json();
for (const ex of list) {
if (!exampleSet.has(ex.dowwnload_url)) {
if (!exampleSet.has(ex.download_url)) {
const exResponse = await fetch(ex.download_url);
if (!exResponse.ok) {
console.warn(`Invalid file at ${ex.download_url}`);
Expand Down
8 changes: 7 additions & 1 deletion tools/Mcp/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export type toolParameterSchema = {
name: string;
type: string;
description: string;
type: string;
}

export type toolSchema = {
Expand All @@ -11,6 +11,12 @@ export type toolSchema = {
callbackName: string;
}

export type responseSchema = {
name: string;
type: string;
text: string;
}

export type yamlContent = {
[key: string]: any;
}
Expand Down
Loading