@eclipse-glsp/server-mcp 2.7.0-next.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +642 -0
- package/README.md +57 -0
- package/lib/index.d.ts +23 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +41 -0
- package/lib/index.js.map +1 -0
- package/lib/prompts/handlers/describe-diagram-mcp-prompt-handler.d.ts +43 -0
- package/lib/prompts/handlers/describe-diagram-mcp-prompt-handler.d.ts.map +1 -0
- package/lib/prompts/handlers/describe-diagram-mcp-prompt-handler.js +96 -0
- package/lib/prompts/handlers/describe-diagram-mcp-prompt-handler.js.map +1 -0
- package/lib/prompts/handlers/suggest-improvements-mcp-prompt-handler.d.ts +43 -0
- package/lib/prompts/handlers/suggest-improvements-mcp-prompt-handler.d.ts.map +1 -0
- package/lib/prompts/handlers/suggest-improvements-mcp-prompt-handler.js +95 -0
- package/lib/prompts/handlers/suggest-improvements-mcp-prompt-handler.js.map +1 -0
- package/lib/prompts/index.d.ts +18 -0
- package/lib/prompts/index.d.ts.map +1 -0
- package/lib/prompts/index.js +34 -0
- package/lib/prompts/index.js.map +1 -0
- package/lib/resources/handlers/diagram-png-mcp-resource-handler.d.ts +81 -0
- package/lib/resources/handlers/diagram-png-mcp-resource-handler.d.ts.map +1 -0
- package/lib/resources/handlers/diagram-png-mcp-resource-handler.js +174 -0
- package/lib/resources/handlers/diagram-png-mcp-resource-handler.js.map +1 -0
- package/lib/resources/handlers/diagram-svg-mcp-resource-handler.d.ts +52 -0
- package/lib/resources/handlers/diagram-svg-mcp-resource-handler.d.ts.map +1 -0
- package/lib/resources/handlers/diagram-svg-mcp-resource-handler.js +96 -0
- package/lib/resources/handlers/diagram-svg-mcp-resource-handler.js.map +1 -0
- package/lib/resources/index.d.ts +20 -0
- package/lib/resources/index.d.ts.map +1 -0
- package/lib/resources/index.js +36 -0
- package/lib/resources/index.js.map +1 -0
- package/lib/resources/services/element-types-provider.d.ts +65 -0
- package/lib/resources/services/element-types-provider.d.ts.map +1 -0
- package/lib/resources/services/element-types-provider.js +81 -0
- package/lib/resources/services/element-types-provider.js.map +1 -0
- package/lib/resources/services/mcp-model-serializer.d.ts +78 -0
- package/lib/resources/services/mcp-model-serializer.d.ts.map +1 -0
- package/lib/resources/services/mcp-model-serializer.js +188 -0
- package/lib/resources/services/mcp-model-serializer.js.map +1 -0
- package/lib/server/glsp-mcp-server.d.ts +82 -0
- package/lib/server/glsp-mcp-server.d.ts.map +1 -0
- package/lib/server/glsp-mcp-server.js +140 -0
- package/lib/server/glsp-mcp-server.js.map +1 -0
- package/lib/server/index.d.ts +37 -0
- package/lib/server/index.d.ts.map +1 -0
- package/lib/server/index.js +57 -0
- package/lib/server/index.js.map +1 -0
- package/lib/server/lru-event-store.d.ts +53 -0
- package/lib/server/lru-event-store.d.ts.map +1 -0
- package/lib/server/lru-event-store.js +100 -0
- package/lib/server/lru-event-store.js.map +1 -0
- package/lib/server/mcp-diagram-handler-dispatcher.d.ts +144 -0
- package/lib/server/mcp-diagram-handler-dispatcher.d.ts.map +1 -0
- package/lib/server/mcp-diagram-handler-dispatcher.js +382 -0
- package/lib/server/mcp-diagram-handler-dispatcher.js.map +1 -0
- package/lib/server/mcp-diagram-module.d.ts +123 -0
- package/lib/server/mcp-diagram-module.d.ts.map +1 -0
- package/lib/server/mcp-diagram-module.js +186 -0
- package/lib/server/mcp-diagram-module.js.map +1 -0
- package/lib/server/mcp-diagram-prompt-handler-registry.d.ts +33 -0
- package/lib/server/mcp-diagram-prompt-handler-registry.d.ts.map +1 -0
- package/lib/server/mcp-diagram-prompt-handler-registry.js +76 -0
- package/lib/server/mcp-diagram-prompt-handler-registry.js.map +1 -0
- package/lib/server/mcp-diagram-resource-handler-registry.d.ts +35 -0
- package/lib/server/mcp-diagram-resource-handler-registry.d.ts.map +1 -0
- package/lib/server/mcp-diagram-resource-handler-registry.js +94 -0
- package/lib/server/mcp-diagram-resource-handler-registry.js.map +1 -0
- package/lib/server/mcp-diagram-tool-handler-registry.d.ts +57 -0
- package/lib/server/mcp-diagram-tool-handler-registry.d.ts.map +1 -0
- package/lib/server/mcp-diagram-tool-handler-registry.js +111 -0
- package/lib/server/mcp-diagram-tool-handler-registry.js.map +1 -0
- package/lib/server/mcp-handler-shared.d.ts +142 -0
- package/lib/server/mcp-handler-shared.d.ts.map +1 -0
- package/lib/server/mcp-handler-shared.js +199 -0
- package/lib/server/mcp-handler-shared.js.map +1 -0
- package/lib/server/mcp-http-transport.d.ts +93 -0
- package/lib/server/mcp-http-transport.d.ts.map +1 -0
- package/lib/server/mcp-http-transport.js +350 -0
- package/lib/server/mcp-http-transport.js.map +1 -0
- package/lib/server/mcp-id-alias-service.d.ts +70 -0
- package/lib/server/mcp-id-alias-service.d.ts.map +1 -0
- package/lib/server/mcp-id-alias-service.js +85 -0
- package/lib/server/mcp-id-alias-service.js.map +1 -0
- package/lib/server/mcp-input-schemas.d.ts +73 -0
- package/lib/server/mcp-input-schemas.d.ts.map +1 -0
- package/lib/server/mcp-input-schemas.js +67 -0
- package/lib/server/mcp-input-schemas.js.map +1 -0
- package/lib/server/mcp-label-provider.d.ts +45 -0
- package/lib/server/mcp-label-provider.d.ts.map +1 -0
- package/lib/server/mcp-label-provider.js +42 -0
- package/lib/server/mcp-label-provider.js.map +1 -0
- package/lib/server/mcp-log-level-registry.d.ts +54 -0
- package/lib/server/mcp-log-level-registry.d.ts.map +1 -0
- package/lib/server/mcp-log-level-registry.js +80 -0
- package/lib/server/mcp-log-level-registry.js.map +1 -0
- package/lib/server/mcp-logger.d.ts +59 -0
- package/lib/server/mcp-logger.d.ts.map +1 -0
- package/lib/server/mcp-logger.js +104 -0
- package/lib/server/mcp-logger.js.map +1 -0
- package/lib/server/mcp-mime-types.d.ts +28 -0
- package/lib/server/mcp-mime-types.d.ts.map +1 -0
- package/lib/server/mcp-mime-types.js +18 -0
- package/lib/server/mcp-mime-types.js.map +1 -0
- package/lib/server/mcp-options.d.ts +39 -0
- package/lib/server/mcp-options.d.ts.map +1 -0
- package/lib/server/mcp-options.js +53 -0
- package/lib/server/mcp-options.js.map +1 -0
- package/lib/server/mcp-progress-reporter.d.ts +48 -0
- package/lib/server/mcp-progress-reporter.d.ts.map +1 -0
- package/lib/server/mcp-progress-reporter.js +66 -0
- package/lib/server/mcp-progress-reporter.js.map +1 -0
- package/lib/server/mcp-prompt-handler.d.ts +120 -0
- package/lib/server/mcp-prompt-handler.d.ts.map +1 -0
- package/lib/server/mcp-prompt-handler.js +131 -0
- package/lib/server/mcp-prompt-handler.js.map +1 -0
- package/lib/server/mcp-request-context.d.ts +37 -0
- package/lib/server/mcp-request-context.d.ts.map +1 -0
- package/lib/server/mcp-request-context.js +37 -0
- package/lib/server/mcp-request-context.js.map +1 -0
- package/lib/server/mcp-resource-handler.d.ts +212 -0
- package/lib/server/mcp-resource-handler.d.ts.map +1 -0
- package/lib/server/mcp-resource-handler.js +298 -0
- package/lib/server/mcp-resource-handler.js.map +1 -0
- package/lib/server/mcp-server-launcher.d.ts +143 -0
- package/lib/server/mcp-server-launcher.d.ts.map +1 -0
- package/lib/server/mcp-server-launcher.js +355 -0
- package/lib/server/mcp-server-launcher.js.map +1 -0
- package/lib/server/mcp-server-module.d.ts +143 -0
- package/lib/server/mcp-server-module.d.ts.map +1 -0
- package/lib/server/mcp-server-module.js +249 -0
- package/lib/server/mcp-server-module.js.map +1 -0
- package/lib/server/mcp-session.d.ts +44 -0
- package/lib/server/mcp-session.d.ts.map +1 -0
- package/lib/server/mcp-session.js +18 -0
- package/lib/server/mcp-session.js.map +1 -0
- package/lib/server/mcp-tool-handler.d.ts +259 -0
- package/lib/server/mcp-tool-handler.d.ts.map +1 -0
- package/lib/server/mcp-tool-handler.js +355 -0
- package/lib/server/mcp-tool-handler.js.map +1 -0
- package/lib/tools/handlers/count-elements-mcp-tool-handler.d.ts +46 -0
- package/lib/tools/handlers/count-elements-mcp-tool-handler.d.ts.map +1 -0
- package/lib/tools/handlers/count-elements-mcp-tool-handler.js +76 -0
- package/lib/tools/handlers/count-elements-mcp-tool-handler.js.map +1 -0
- package/lib/tools/handlers/create-edges-mcp-tool-handler.d.ts +112 -0
- package/lib/tools/handlers/create-edges-mcp-tool-handler.d.ts.map +1 -0
- package/lib/tools/handlers/create-edges-mcp-tool-handler.js +190 -0
- package/lib/tools/handlers/create-edges-mcp-tool-handler.js.map +1 -0
- package/lib/tools/handlers/create-nodes-mcp-tool-handler.d.ts +81 -0
- package/lib/tools/handlers/create-nodes-mcp-tool-handler.d.ts.map +1 -0
- package/lib/tools/handlers/create-nodes-mcp-tool-handler.js +123 -0
- package/lib/tools/handlers/create-nodes-mcp-tool-handler.js.map +1 -0
- package/lib/tools/handlers/delete-elements-mcp-tool-handler.d.ts +52 -0
- package/lib/tools/handlers/delete-elements-mcp-tool-handler.d.ts.map +1 -0
- package/lib/tools/handlers/delete-elements-mcp-tool-handler.js +73 -0
- package/lib/tools/handlers/delete-elements-mcp-tool-handler.js.map +1 -0
- package/lib/tools/handlers/diagram-model-mcp-tool-handler.d.ts +59 -0
- package/lib/tools/handlers/diagram-model-mcp-tool-handler.d.ts.map +1 -0
- package/lib/tools/handlers/diagram-model-mcp-tool-handler.js +78 -0
- package/lib/tools/handlers/diagram-model-mcp-tool-handler.js.map +1 -0
- package/lib/tools/handlers/element-types-mcp-tool-handler.d.ts +97 -0
- package/lib/tools/handlers/element-types-mcp-tool-handler.d.ts.map +1 -0
- package/lib/tools/handlers/element-types-mcp-tool-handler.js +155 -0
- package/lib/tools/handlers/element-types-mcp-tool-handler.js.map +1 -0
- package/lib/tools/handlers/get-selection-mcp-tool-handler.d.ts +43 -0
- package/lib/tools/handlers/get-selection-mcp-tool-handler.d.ts.map +1 -0
- package/lib/tools/handlers/get-selection-mcp-tool-handler.js +68 -0
- package/lib/tools/handlers/get-selection-mcp-tool-handler.js.map +1 -0
- package/lib/tools/handlers/layout-mcp-tool-handler.d.ts +43 -0
- package/lib/tools/handlers/layout-mcp-tool-handler.d.ts.map +1 -0
- package/lib/tools/handlers/layout-mcp-tool-handler.js +71 -0
- package/lib/tools/handlers/layout-mcp-tool-handler.js.map +1 -0
- package/lib/tools/handlers/modify-edges-mcp-tool-handler.d.ts +78 -0
- package/lib/tools/handlers/modify-edges-mcp-tool-handler.d.ts.map +1 -0
- package/lib/tools/handlers/modify-edges-mcp-tool-handler.js +136 -0
- package/lib/tools/handlers/modify-edges-mcp-tool-handler.js.map +1 -0
- package/lib/tools/handlers/modify-nodes-mcp-tool-handler.d.ts +92 -0
- package/lib/tools/handlers/modify-nodes-mcp-tool-handler.d.ts.map +1 -0
- package/lib/tools/handlers/modify-nodes-mcp-tool-handler.js +125 -0
- package/lib/tools/handlers/modify-nodes-mcp-tool-handler.js.map +1 -0
- package/lib/tools/handlers/query-elements-mcp-tool-handler.d.ts +102 -0
- package/lib/tools/handlers/query-elements-mcp-tool-handler.d.ts.map +1 -0
- package/lib/tools/handlers/query-elements-mcp-tool-handler.js +158 -0
- package/lib/tools/handlers/query-elements-mcp-tool-handler.js.map +1 -0
- package/lib/tools/handlers/redo-mcp-tool-handler.d.ts +45 -0
- package/lib/tools/handlers/redo-mcp-tool-handler.d.ts.map +1 -0
- package/lib/tools/handlers/redo-mcp-tool-handler.js +73 -0
- package/lib/tools/handlers/redo-mcp-tool-handler.js.map +1 -0
- package/lib/tools/handlers/save-model-mcp-tool-handler.d.ts +55 -0
- package/lib/tools/handlers/save-model-mcp-tool-handler.d.ts.map +1 -0
- package/lib/tools/handlers/save-model-mcp-tool-handler.js +91 -0
- package/lib/tools/handlers/save-model-mcp-tool-handler.js.map +1 -0
- package/lib/tools/handlers/session-info-mcp-tool-handler.d.ts +65 -0
- package/lib/tools/handlers/session-info-mcp-tool-handler.d.ts.map +1 -0
- package/lib/tools/handlers/session-info-mcp-tool-handler.js +108 -0
- package/lib/tools/handlers/session-info-mcp-tool-handler.js.map +1 -0
- package/lib/tools/handlers/set-selection-mcp-tool-handler.d.ts +60 -0
- package/lib/tools/handlers/set-selection-mcp-tool-handler.d.ts.map +1 -0
- package/lib/tools/handlers/set-selection-mcp-tool-handler.js +103 -0
- package/lib/tools/handlers/set-selection-mcp-tool-handler.js.map +1 -0
- package/lib/tools/handlers/set-view-mcp-tool-handler.d.ts +110 -0
- package/lib/tools/handlers/set-view-mcp-tool-handler.d.ts.map +1 -0
- package/lib/tools/handlers/set-view-mcp-tool-handler.js +142 -0
- package/lib/tools/handlers/set-view-mcp-tool-handler.js.map +1 -0
- package/lib/tools/handlers/undo-mcp-tool-handler.d.ts +45 -0
- package/lib/tools/handlers/undo-mcp-tool-handler.d.ts.map +1 -0
- package/lib/tools/handlers/undo-mcp-tool-handler.js +74 -0
- package/lib/tools/handlers/undo-mcp-tool-handler.js.map +1 -0
- package/lib/tools/handlers/validate-diagram-mcp-tool-handler.d.ts +66 -0
- package/lib/tools/handlers/validate-diagram-mcp-tool-handler.d.ts.map +1 -0
- package/lib/tools/handlers/validate-diagram-mcp-tool-handler.js +0 -0
- package/lib/tools/handlers/validate-diagram-mcp-tool-handler.js.map +1 -0
- package/lib/tools/index.d.ts +34 -0
- package/lib/tools/index.d.ts.map +1 -0
- package/lib/tools/index.js +50 -0
- package/lib/tools/index.js.map +1 -0
- package/lib/util/index.d.ts +18 -0
- package/lib/util/index.d.ts.map +1 -0
- package/lib/util/index.js +34 -0
- package/lib/util/index.js.map +1 -0
- package/lib/util/markdown-util.d.ts +20 -0
- package/lib/util/markdown-util.d.ts.map +1 -0
- package/lib/util/markdown-util.js +45 -0
- package/lib/util/markdown-util.js.map +1 -0
- package/lib/util/mcp-util.d.ts +22 -0
- package/lib/util/mcp-util.d.ts.map +1 -0
- package/lib/util/mcp-util.js +29 -0
- package/lib/util/mcp-util.js.map +1 -0
- package/package.json +63 -0
- package/src/index.ts +24 -0
- package/src/prompts/handlers/describe-diagram-mcp-prompt-handler.ts +89 -0
- package/src/prompts/handlers/suggest-improvements-mcp-prompt-handler.ts +86 -0
- package/src/prompts/index.ts +18 -0
- package/src/resources/handlers/diagram-png-mcp-resource-handler.ts +181 -0
- package/src/resources/handlers/diagram-svg-mcp-resource-handler.ts +89 -0
- package/src/resources/index.ts +20 -0
- package/src/resources/services/element-types-provider.ts +105 -0
- package/src/resources/services/mcp-model-serializer.ts +211 -0
- package/src/server/glsp-mcp-server.spec.ts +73 -0
- package/src/server/glsp-mcp-server.ts +196 -0
- package/src/server/index.ts +42 -0
- package/src/server/lru-event-store.spec.ts +121 -0
- package/src/server/lru-event-store.ts +112 -0
- package/src/server/mcp-diagram-handler-dispatcher.spec.ts +231 -0
- package/src/server/mcp-diagram-handler-dispatcher.ts +459 -0
- package/src/server/mcp-diagram-module.ts +248 -0
- package/src/server/mcp-diagram-prompt-handler-registry.ts +59 -0
- package/src/server/mcp-diagram-resource-handler-registry.ts +73 -0
- package/src/server/mcp-diagram-tool-handler-registry.ts +97 -0
- package/src/server/mcp-handler-shared.spec.ts +53 -0
- package/src/server/mcp-handler-shared.ts +247 -0
- package/src/server/mcp-http-transport-e2e.spec.ts +151 -0
- package/src/server/mcp-http-transport.spec.ts +385 -0
- package/src/server/mcp-http-transport.ts +368 -0
- package/src/server/mcp-id-alias-service.spec.ts +106 -0
- package/src/server/mcp-id-alias-service.ts +104 -0
- package/src/server/mcp-input-schemas.ts +82 -0
- package/src/server/mcp-label-provider.ts +52 -0
- package/src/server/mcp-log-level-registry.spec.ts +75 -0
- package/src/server/mcp-log-level-registry.ts +90 -0
- package/src/server/mcp-logger.spec.ts +227 -0
- package/src/server/mcp-logger.ts +91 -0
- package/src/server/mcp-mime-types.ts +31 -0
- package/src/server/mcp-options.ts +43 -0
- package/src/server/mcp-progress-reporter.spec.ts +93 -0
- package/src/server/mcp-progress-reporter.ts +67 -0
- package/src/server/mcp-prompt-handler.ts +157 -0
- package/src/server/mcp-request-context.ts +39 -0
- package/src/server/mcp-resource-handler.ts +389 -0
- package/src/server/mcp-server-launcher.spec.ts +173 -0
- package/src/server/mcp-server-launcher.ts +369 -0
- package/src/server/mcp-server-module.ts +287 -0
- package/src/server/mcp-session.ts +45 -0
- package/src/server/mcp-tool-handler.spec.ts +182 -0
- package/src/server/mcp-tool-handler.ts +431 -0
- package/src/server/raw-http.spec.ts +59 -0
- package/src/tools/handlers/count-elements-mcp-tool-handler.spec.ts +99 -0
- package/src/tools/handlers/count-elements-mcp-tool-handler.ts +66 -0
- package/src/tools/handlers/create-edges-mcp-tool-handler.spec.ts +196 -0
- package/src/tools/handlers/create-edges-mcp-tool-handler.ts +205 -0
- package/src/tools/handlers/create-nodes-mcp-tool-handler.spec.ts +197 -0
- package/src/tools/handlers/create-nodes-mcp-tool-handler.ts +131 -0
- package/src/tools/handlers/delete-elements-mcp-tool-handler.ts +73 -0
- package/src/tools/handlers/diagram-model-mcp-tool-handler.ts +66 -0
- package/src/tools/handlers/element-types-mcp-tool-handler.ts +151 -0
- package/src/tools/handlers/get-selection-mcp-tool-handler.ts +54 -0
- package/src/tools/handlers/layout-mcp-tool-handler.ts +56 -0
- package/src/tools/handlers/modify-edges-mcp-tool-handler.ts +148 -0
- package/src/tools/handlers/modify-nodes-mcp-tool-handler.ts +140 -0
- package/src/tools/handlers/query-elements-mcp-tool-handler.spec.ts +210 -0
- package/src/tools/handlers/query-elements-mcp-tool-handler.ts +161 -0
- package/src/tools/handlers/redo-mcp-tool-handler.ts +62 -0
- package/src/tools/handlers/save-model-mcp-tool-handler.ts +71 -0
- package/src/tools/handlers/session-info-mcp-tool-handler.spec.ts +152 -0
- package/src/tools/handlers/session-info-mcp-tool-handler.ts +97 -0
- package/src/tools/handlers/set-selection-mcp-tool-handler.spec.ts +118 -0
- package/src/tools/handlers/set-selection-mcp-tool-handler.ts +90 -0
- package/src/tools/handlers/set-view-mcp-tool-handler.ts +162 -0
- package/src/tools/handlers/undo-mcp-tool-handler.ts +61 -0
- package/src/tools/handlers/validate-diagram-mcp-tool-handler.ts +0 -0
- package/src/tools/index.ts +34 -0
- package/src/tools/tool-annotations.spec.ts +141 -0
- package/src/util/index.ts +18 -0
- package/src/util/markdown-util.ts +44 -0
- package/src/util/mcp-util.ts +25 -0
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/********************************************************************************
|
|
2
|
+
* Copyright (c) 2026 EclipseSource and others.
|
|
3
|
+
*
|
|
4
|
+
* This program and the accompanying materials are made available under the
|
|
5
|
+
* terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
* http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
*
|
|
8
|
+
* This Source Code may also be made available under the following Secondary
|
|
9
|
+
* Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
* with the GNU Classpath Exception which is available at
|
|
12
|
+
* https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
*
|
|
14
|
+
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
|
15
|
+
********************************************************************************/
|
|
16
|
+
|
|
17
|
+
import { ServerNotification } from '@modelcontextprotocol/sdk/types.js';
|
|
18
|
+
import { expect } from 'chai';
|
|
19
|
+
import { McpProgressReporter } from './mcp-progress-reporter';
|
|
20
|
+
import { McpRequestExtra, mcpRequestContext } from './mcp-request-context';
|
|
21
|
+
|
|
22
|
+
function buildExtra(progressToken?: string | number): { extra: McpRequestExtra; sent: ServerNotification[] } {
|
|
23
|
+
const sent: ServerNotification[] = [];
|
|
24
|
+
const extra = {
|
|
25
|
+
sendNotification: async (n: ServerNotification) => {
|
|
26
|
+
sent.push(n);
|
|
27
|
+
},
|
|
28
|
+
_meta: progressToken === undefined ? undefined : { progressToken }
|
|
29
|
+
} as unknown as McpRequestExtra;
|
|
30
|
+
return { extra, sent };
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
describe('McpProgressReporter', () => {
|
|
34
|
+
it('no-ops inside a request that has no progressToken (client did not opt in)', async () => {
|
|
35
|
+
const reporter = new McpProgressReporter();
|
|
36
|
+
const { extra, sent } = buildExtra(undefined);
|
|
37
|
+
|
|
38
|
+
await mcpRequestContext.run(extra, async () => {
|
|
39
|
+
await reporter.emit({ progress: 0, message: 'starting' });
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
expect(sent).to.have.lengthOf(0);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('emits notifications/progress when the request carries a progressToken', async () => {
|
|
46
|
+
const reporter = new McpProgressReporter();
|
|
47
|
+
const { extra, sent } = buildExtra('tok-42');
|
|
48
|
+
|
|
49
|
+
await mcpRequestContext.run(extra, async () => {
|
|
50
|
+
await reporter.emit({ progress: 0, message: 'starting' });
|
|
51
|
+
await reporter.emit({ progress: 1, total: 3, message: 'step 1/3' });
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
expect(sent).to.have.lengthOf(2);
|
|
55
|
+
expect(sent[0]).to.deep.equal({
|
|
56
|
+
method: 'notifications/progress',
|
|
57
|
+
params: { progressToken: 'tok-42', progress: 0, message: 'starting' }
|
|
58
|
+
});
|
|
59
|
+
expect(sent[1]).to.deep.equal({
|
|
60
|
+
method: 'notifications/progress',
|
|
61
|
+
params: { progressToken: 'tok-42', progress: 1, total: 3, message: 'step 1/3' }
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('accepts numeric progress tokens', async () => {
|
|
66
|
+
const reporter = new McpProgressReporter();
|
|
67
|
+
const { extra, sent } = buildExtra(7);
|
|
68
|
+
|
|
69
|
+
await mcpRequestContext.run(extra, async () => {
|
|
70
|
+
await reporter.emit({ progress: 0 });
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
expect(sent).to.have.lengthOf(1);
|
|
74
|
+
expect(sent[0].params).to.deep.equal({ progressToken: 7, progress: 0 });
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it('swallows transport failures so a broken send never breaks the producing tool', async () => {
|
|
78
|
+
const reporter = new McpProgressReporter();
|
|
79
|
+
const failingExtra = {
|
|
80
|
+
sendNotification: async () => {
|
|
81
|
+
throw new Error('transport closed');
|
|
82
|
+
},
|
|
83
|
+
_meta: { progressToken: 'tok-1' }
|
|
84
|
+
} as unknown as McpRequestExtra;
|
|
85
|
+
|
|
86
|
+
await mcpRequestContext.run(failingExtra, async () => {
|
|
87
|
+
// Must complete without throwing. If we re-threw, every PNG export would hard-fail
|
|
88
|
+
// when the client's SSE stream blipped — the opposite of progress reporting being
|
|
89
|
+
// a UX nicety.
|
|
90
|
+
await reporter.emit({ progress: 0, message: 'starting' });
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
});
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/********************************************************************************
|
|
2
|
+
* Copyright (c) 2026 EclipseSource and others.
|
|
3
|
+
*
|
|
4
|
+
* This program and the accompanying materials are made available under the
|
|
5
|
+
* terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
* http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
*
|
|
8
|
+
* This Source Code may also be made available under the following Secondary
|
|
9
|
+
* Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
* with the GNU Classpath Exception which is available at
|
|
12
|
+
* https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
*
|
|
14
|
+
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
|
15
|
+
********************************************************************************/
|
|
16
|
+
|
|
17
|
+
import { injectable } from 'inversify';
|
|
18
|
+
import { mcpRequestContext } from './mcp-request-context';
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Per-call shape of a `notifications/progress` emission. Mirrors the SDK's
|
|
22
|
+
* `ProgressNotificationParams` minus the `progressToken` field (the reporter pulls that from
|
|
23
|
+
* the active request context — the caller's job is just to describe the progress beat).
|
|
24
|
+
*/
|
|
25
|
+
export interface McpProgressBeat {
|
|
26
|
+
/** Monotonic progress count. Spec is loose; convention: increment from 0 toward `total` if known, or use seconds-elapsed otherwise. */
|
|
27
|
+
progress: number;
|
|
28
|
+
/** Total when known (e.g. number of nodes to process). Omit when bounded only by a timeout. */
|
|
29
|
+
total?: number;
|
|
30
|
+
/** Short user-facing description; surfaces in compatible clients' UI. */
|
|
31
|
+
message?: string;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Emits `notifications/progress` to the connected MCP client when the active request carries a
|
|
36
|
+
* `progressToken` in its `_meta`. Built on the same {@link mcpRequestContext} as
|
|
37
|
+
* {@link McpLogger}; handlers don't need to thread `extra` through their own signatures.
|
|
38
|
+
*
|
|
39
|
+
* Behaviour:
|
|
40
|
+
* - Outside a request context (init, background): no-op.
|
|
41
|
+
* - Inside a request context with no `progressToken` (client didn't opt in): no-op.
|
|
42
|
+
* Universally supported per spec — clients that don't render progress simply omit the token.
|
|
43
|
+
* - Failures to deliver are swallowed: a broken transport must not break the producing tool.
|
|
44
|
+
*
|
|
45
|
+
* Shared across MCP clients on the same GLSP session; per-client routing is handled by the
|
|
46
|
+
* active `mcpRequestContext` frame.
|
|
47
|
+
*
|
|
48
|
+
* @experimental
|
|
49
|
+
*/
|
|
50
|
+
@injectable()
|
|
51
|
+
export class McpProgressReporter {
|
|
52
|
+
async emit(beat: McpProgressBeat): Promise<void> {
|
|
53
|
+
const extra = mcpRequestContext.getStore();
|
|
54
|
+
const progressToken = extra?._meta?.progressToken;
|
|
55
|
+
if (extra === undefined || progressToken === undefined) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
try {
|
|
59
|
+
await extra.sendNotification({
|
|
60
|
+
method: 'notifications/progress',
|
|
61
|
+
params: { progressToken, ...beat }
|
|
62
|
+
});
|
|
63
|
+
} catch {
|
|
64
|
+
// Fire-and-forget — never propagate transport errors into tool execution.
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/********************************************************************************
|
|
2
|
+
* Copyright (c) 2025-2026 EclipseSource and others.
|
|
3
|
+
*
|
|
4
|
+
* This program and the accompanying materials are made available under the
|
|
5
|
+
* terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
* http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
*
|
|
8
|
+
* This Source Code may also be made available under the following Secondary
|
|
9
|
+
* Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
* with the GNU Classpath Exception which is available at
|
|
12
|
+
* https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
*
|
|
14
|
+
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
|
15
|
+
********************************************************************************/
|
|
16
|
+
|
|
17
|
+
import { ClientId, Logger, MaybePromise, ModelState } from '@eclipse-glsp/server';
|
|
18
|
+
import { inject, injectable, interfaces } from 'inversify';
|
|
19
|
+
import { ZodObject, ZodRawShape } from 'zod/v4';
|
|
20
|
+
import { GLSPMcpServer } from './glsp-mcp-server';
|
|
21
|
+
import { McpPromptResult, McpToolError, extractErrorMessage } from './mcp-handler-shared';
|
|
22
|
+
import { McpIdAliasService } from './mcp-id-alias-service';
|
|
23
|
+
import { McpDiagramScopedInput } from './mcp-input-schemas';
|
|
24
|
+
import { mcpRequestContext } from './mcp-request-context';
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Multi-binding key for **server-scope** prompt handlers — singletons that don't target a
|
|
28
|
+
* specific GLSP client session. Diagram-scope prompts (one instance per open diagram) use the
|
|
29
|
+
* separate {@link McpDiagramPromptHandlerConstructor} multi-binding instead.
|
|
30
|
+
*
|
|
31
|
+
* Prompts are LLM-facing message templates the AI client may invoke. No prompts ship by default;
|
|
32
|
+
* the surface exists for adopters.
|
|
33
|
+
*
|
|
34
|
+
* @experimental
|
|
35
|
+
*/
|
|
36
|
+
export interface McpPromptHandler {
|
|
37
|
+
/** Prompt identifier exposed to the MCP client; matches the abstract base's field. */
|
|
38
|
+
readonly name: string;
|
|
39
|
+
registerPrompt(server: GLSPMcpServer): void;
|
|
40
|
+
/** Tool names this prompt's text references via `${OtherHandler.NAME}`; default: empty. */
|
|
41
|
+
referencedToolNames(): string[];
|
|
42
|
+
}
|
|
43
|
+
export const McpPromptHandler = Symbol('McpPromptHandler');
|
|
44
|
+
|
|
45
|
+
/** Shared infrastructure for both server- and diagram-scope prompt handlers. */
|
|
46
|
+
@injectable()
|
|
47
|
+
abstract class BaseMcpPromptHandler {
|
|
48
|
+
@inject(Logger) protected logger: Logger;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Prompt identifier exposed to the MCP client. Also used to reference this prompt from
|
|
52
|
+
* other handlers' prompt or description text — wire via `static readonly NAME = '…'` and
|
|
53
|
+
* `readonly name = ClassName.NAME` so those cross-references survive renames.
|
|
54
|
+
*/
|
|
55
|
+
abstract readonly name: string;
|
|
56
|
+
/** LLM-facing explanation surfaced in the prompt catalog. Keep concise — clients pass this verbatim to the model. */
|
|
57
|
+
abstract readonly description: string;
|
|
58
|
+
/** Adopter writes `z.object({ ... })`; the base passes `.shape` to the SDK. */
|
|
59
|
+
abstract readonly argsSchema: ZodObject<ZodRawShape>;
|
|
60
|
+
/** Optional human-friendly display name for UIs that render a friendlier label than `name`. */
|
|
61
|
+
readonly title?: string;
|
|
62
|
+
|
|
63
|
+
/** SDK-facing registration config; consumed by both registration paths. */
|
|
64
|
+
toRegistrationConfig(): { title?: string; description: string; argsSchema: ZodRawShape } {
|
|
65
|
+
return { title: this.title, description: this.description, argsSchema: this.argsSchema.shape };
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Optional list of tool names this prompt's text refers to via `${OtherHandler.NAME}`
|
|
70
|
+
* substitutions. Default: empty. Override in concrete subclasses to declare references so
|
|
71
|
+
* the launcher can warn at registration time when an adopter unbinds a referenced tool —
|
|
72
|
+
* the prompt would otherwise still register and silently produce text pointing at a tool
|
|
73
|
+
* that no longer exists. Pure declarative metadata; never invoked at request time.
|
|
74
|
+
*/
|
|
75
|
+
referencedToolNames(): string[] {
|
|
76
|
+
return [];
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Catches `McpToolError` (→ surfaced as a `user`-role assistant message) and unexpected
|
|
81
|
+
* errors (→ logged + extracted message). Errors map to a single text-content message so
|
|
82
|
+
* the LLM sees the failure in the prompt response.
|
|
83
|
+
*/
|
|
84
|
+
protected async execute(producer: () => MaybePromise<McpPromptResult>): Promise<McpPromptResult> {
|
|
85
|
+
try {
|
|
86
|
+
return await producer();
|
|
87
|
+
} catch (err: unknown) {
|
|
88
|
+
if (err instanceof McpToolError) {
|
|
89
|
+
return this.errorResult(err.message);
|
|
90
|
+
}
|
|
91
|
+
const message = extractErrorMessage(err);
|
|
92
|
+
this.logger.error(`Unexpected error in prompt '${this.name}': ${message}`, err);
|
|
93
|
+
return this.errorResult(message);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
protected errorResult(message: string): McpPromptResult {
|
|
98
|
+
return { messages: [{ role: 'user', content: { type: 'text', text: message } }] };
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Server-scope prompt base — for prompts that don't target a specific GLSP client session
|
|
104
|
+
* (e.g., a prompt that summarizes the system's state). Bound under {@link McpPromptHandler};
|
|
105
|
+
* the launcher invokes `registerPrompt(server)` once per MCP session.
|
|
106
|
+
*
|
|
107
|
+
* @experimental
|
|
108
|
+
*/
|
|
109
|
+
@injectable()
|
|
110
|
+
export abstract class AbstractMcpPromptHandler<T = Record<string, unknown>> extends BaseMcpPromptHandler implements McpPromptHandler {
|
|
111
|
+
/** Throw {@link McpToolError} for expected errors; the base wraps. */
|
|
112
|
+
protected abstract createResult(args: T): MaybePromise<McpPromptResult>;
|
|
113
|
+
|
|
114
|
+
registerPrompt(server: GLSPMcpServer): void {
|
|
115
|
+
server.registerPrompt(this.name, this.toRegistrationConfig(), async (args, extra) =>
|
|
116
|
+
mcpRequestContext.run(extra, () => this.execute(() => this.createResult(args as T)))
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Diagram-scope prompt base — for prompts whose argument schema carries a `sessionId`
|
|
123
|
+
* (e.g., a `describe-diagram` prompt for one open diagram).
|
|
124
|
+
*
|
|
125
|
+
* The launcher's dispatcher resolves `args.sessionId` to the right GLSP session and invokes
|
|
126
|
+
* {@link handle} on this session's per-instance handler. From the handler's perspective the
|
|
127
|
+
* session is implicit — `this.clientId`, `this.modelState`, `this.aliasService` (and any
|
|
128
|
+
* adopter `@inject(...)` fields) all resolve to that GLSP session's container.
|
|
129
|
+
*
|
|
130
|
+
* @experimental
|
|
131
|
+
*/
|
|
132
|
+
@injectable()
|
|
133
|
+
export abstract class AbstractMcpDiagramPromptHandler<
|
|
134
|
+
T extends McpDiagramScopedInput = McpDiagramScopedInput
|
|
135
|
+
> extends BaseMcpPromptHandler {
|
|
136
|
+
@inject(ClientId) protected clientId: string;
|
|
137
|
+
@inject(ModelState) protected modelState: ModelState;
|
|
138
|
+
@inject(McpIdAliasService) protected aliasService: McpIdAliasService;
|
|
139
|
+
|
|
140
|
+
/** Throw {@link McpToolError} for expected errors; the base wraps. */
|
|
141
|
+
protected abstract createResult(args: T): MaybePromise<McpPromptResult>;
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Public dispatch entry point invoked by {@link McpServerLauncher}'s SDK callback.
|
|
145
|
+
*/
|
|
146
|
+
handle(args: T): Promise<McpPromptResult> {
|
|
147
|
+
return this.execute(() => this.createResult(args));
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Multi-binding identifier for diagram-scope prompt handler constructors. See
|
|
153
|
+
* {@link McpDiagramToolHandlerConstructor} for the lifecycle pattern — same shape, applied to
|
|
154
|
+
* prompt handlers.
|
|
155
|
+
*/
|
|
156
|
+
export type McpDiagramPromptHandlerConstructor = interfaces.Newable<AbstractMcpDiagramPromptHandler<any>>;
|
|
157
|
+
export const McpDiagramPromptHandlerConstructor = Symbol('McpDiagramPromptHandlerConstructor');
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/********************************************************************************
|
|
2
|
+
* Copyright (c) 2026 EclipseSource and others.
|
|
3
|
+
*
|
|
4
|
+
* This program and the accompanying materials are made available under the
|
|
5
|
+
* terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
* http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
*
|
|
8
|
+
* This Source Code may also be made available under the following Secondary
|
|
9
|
+
* Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
* with the GNU Classpath Exception which is available at
|
|
12
|
+
* https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
*
|
|
14
|
+
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
|
15
|
+
********************************************************************************/
|
|
16
|
+
|
|
17
|
+
import { RequestHandlerExtra } from '@modelcontextprotocol/sdk/shared/protocol.js';
|
|
18
|
+
import { ServerNotification, ServerRequest } from '@modelcontextprotocol/sdk/types.js';
|
|
19
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
20
|
+
|
|
21
|
+
export type McpRequestExtra = RequestHandlerExtra<ServerRequest, ServerNotification>;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Module-level `AsyncLocalStorage` carrying the SDK's per-request `extra` (notification sender,
|
|
25
|
+
* progress token, request id, session id) for the duration of a tool/resource/prompt callback.
|
|
26
|
+
*
|
|
27
|
+
* The handler bases (tool / resource / prompt) wrap each registered SDK callback in
|
|
28
|
+
* `mcpRequestContext.run(extra, () => …)`. Anything inside the handler — and any await chain
|
|
29
|
+
* branching off it — can read the active context via {@link mcpRequestContext.getStore}.
|
|
30
|
+
*
|
|
31
|
+
* This lets {@link McpLogger} forward logs to the MCP client without every handler having to
|
|
32
|
+
* thread `extra` through its own signature, and lets future progress-emission code (P1f / PNG
|
|
33
|
+
* export) reach the same channel from inside `requestUntil` chains.
|
|
34
|
+
*
|
|
35
|
+
* Concurrent requests on the same MCP session each get their own AsyncLocalStorage frame —
|
|
36
|
+
* no cross-talk. Code that runs OUTSIDE a request (init contributions, background timers)
|
|
37
|
+
* sees `undefined` from `getStore()`.
|
|
38
|
+
*/
|
|
39
|
+
export const mcpRequestContext = new AsyncLocalStorage<McpRequestExtra>();
|