From 11e550beba48a7caec35baca287b5964dd250538 Mon Sep 17 00:00:00 2001 From: Garry Trinder Date: Wed, 23 Apr 2025 16:20:25 +0100 Subject: [PATCH] Add Dev Proxy MCP Server. Closes #244 Closes #244 --- CHANGELOG.md | 5 +++++ README.md | 7 +++++-- package-lock.json | 10 +++++----- package.json | 10 ++++++++-- src/extension.ts | 9 ++++++--- src/mcp.ts | 21 +++++++++++++++++++++ 6 files changed, 50 insertions(+), 12 deletions(-) create mode 100644 src/mcp.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index 54a97b6..02bf2a7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [0.25.0] - Unreleased +### Added: + +- MCP Server: Dev Proxy + ### Changed: - Snippets: Updated all snippets to use `v0.29.0` schema @@ -44,6 +48,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Command: `dev-proxy-toolkit.restart` - Restart Dev Proxy - Snippets: `devproxy-plugin-typespec-generator` - TypeSpecGeneratorPlugin instance - Snippets: `devproxy-plugin-typespec-generator-config` - TypeSpecGeneratorPlugin config section +- MCP Server: Dev Proxy ### Changed: diff --git a/README.md b/README.md index e6cd018..ceeea6e 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,11 @@ Shown when the active document is a Dev Proxy configuration file - Start recording - Stop recording +### MCP Server + +- Tool: Find Dev Proxy documentation +- Tool: Get the installed Dev Proxy version + ### Notifications - Not installed @@ -70,8 +75,6 @@ Shown when the active document is a Dev Proxy configuration file ### Snippets -| Prefix | Description | -| ------ | ----------- | | Prefix | Description | | ------ | ----------- | | `devproxy-config-file` | Dev Proxy config file | diff --git a/package-lock.json b/package-lock.json index f1cac6a..4a6b9c4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,7 +15,7 @@ "@types/mocha": "^10.0.9", "@types/node": "^20.11.17", "@types/sinon": "^17.0.3", - "@types/vscode": "^1.89.0", + "@types/vscode": "^1.101.0", "@typescript-eslint/eslint-plugin": "^6.21.0", "@typescript-eslint/parser": "^6.21.0", "@vscode/test-cli": "^0.0.10", @@ -30,7 +30,7 @@ "webpack-cli": "^5.1.4" }, "engines": { - "vscode": "^1.89.0" + "vscode": "^1.101.0" } }, "node_modules/@babel/code-frame": { @@ -600,9 +600,9 @@ "license": "MIT" }, "node_modules/@types/vscode": { - "version": "1.95.0", - "resolved": "https://registry.npmjs.org/@types/vscode/-/vscode-1.95.0.tgz", - "integrity": "sha512-0LBD8TEiNbet3NvWsmn59zLzOFu/txSlGxnv5yAFHCrhG9WvAnR3IvfHzMOs2aeWqgvNjq9pO99IUw8d3n+unw==", + "version": "1.101.0", + "resolved": "https://registry.npmjs.org/@types/vscode/-/vscode-1.101.0.tgz", + "integrity": "sha512-ZWf0IWa+NGegdW3iU42AcDTFHWW7fApLdkdnBqwYEtHVIBGbTu0ZNQKP/kX3Ds/uMJXIMQNAojHR4vexCEEz5Q==", "dev": true, "license": "MIT" }, diff --git a/package.json b/package.json index ad5e261..886d926 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "version": "0.25.0", "publisher": "garrytrinder", "engines": { - "vscode": "^1.89.0" + "vscode": "^1.101.0" }, "categories": [ "Snippets", @@ -85,6 +85,12 @@ "enablement": "!isDevProxyRunning" } ], + "mcpServerDefinitionProviders": [ + { + "id": "devproxymcp", + "label": "Dev Proxy" + } + ], "menus": { "editor/title": [ { @@ -186,7 +192,7 @@ "@types/mocha": "^10.0.9", "@types/node": "^20.11.17", "@types/sinon": "^17.0.3", - "@types/vscode": "^1.89.0", + "@types/vscode": "^1.101.0", "@typescript-eslint/eslint-plugin": "^6.21.0", "@typescript-eslint/parser": "^6.21.0", "@vscode/test-cli": "^0.0.10", diff --git a/src/extension.ts b/src/extension.ts index e586f95..4943639 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -7,20 +7,23 @@ import { createStatusBar, statusBarLoop, updateStatusBar } from './statusbar'; import { registerCodeActions } from './codeactions'; import { updateGlobalState } from './state'; import { VersionPreference } from './enums'; +import { registerMcpServer } from './mcp'; export const activate = async (context: vscode.ExtensionContext): Promise => { + const configuration = vscode.workspace.getConfiguration('dev-proxy-toolkit'); const versionPreference = configuration.get('version') as VersionPreference; - + const statusBar = createStatusBar(context); await updateGlobalState(context, versionPreference); - + const collection = vscode.languages.createDiagnosticCollection('dev-proxy-toolkit'); - + registerDocumentListeners(context, collection); registerCodeActions(context); registerCodeLens(context); registerCommands(context, configuration); + registerMcpServer(context); const notification = handleStartNotification(context); processNotification(notification); diff --git a/src/mcp.ts b/src/mcp.ts new file mode 100644 index 0000000..6f6c8d4 --- /dev/null +++ b/src/mcp.ts @@ -0,0 +1,21 @@ +import * as vscode from 'vscode'; + +export const registerMcpServer = (context: vscode.ExtensionContext) => { + const didChangeEmitter = new vscode.EventEmitter(); + + context.subscriptions.push( + vscode.lm.registerMcpServerDefinitionProvider('devproxymcp', { + onDidChangeMcpServerDefinitions: didChangeEmitter.event, + provideMcpServerDefinitions: async () => { + const server: vscode.McpStdioServerDefinition = { + label: 'Dev Proxy', + command: 'npx', + args: ['-y', '@devproxy/mcp'], + env: {}, + }; + + return [server]; + }, + }), + ); +};