@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,142 @@
|
|
|
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
|
+
import { ActionDispatcher, ClientSessionManager, RequestAction, ResponseAction } from '@eclipse-glsp/server';
|
|
17
|
+
import { CallToolResult, GetPromptResult, ReadResourceResult } from '@modelcontextprotocol/sdk/types';
|
|
18
|
+
/**
|
|
19
|
+
* **Note on terminology** — "session" in this file always refers to a **GLSP client session**
|
|
20
|
+
* (one open diagram, tracked by core's `ClientSessionManager`). It is unrelated to the
|
|
21
|
+
* **MCP session** concept used in {@link mcp-session.ts} and {@link mcp-http-transport.ts}
|
|
22
|
+
* (one MCP client connection to the HTTP endpoint). The two have independent lifetimes — see
|
|
23
|
+
* the docstring at the top of `mcp-session.ts` for the full disambiguation.
|
|
24
|
+
*
|
|
25
|
+
* Diagram-scope handler bases ({@link AbstractMcpDiagramToolHandler} et al.) inject their per-session
|
|
26
|
+
* services directly per GLSP session. The launcher's dispatcher resolves the
|
|
27
|
+
* {@link McpDiagramScopedInput.sessionId} input field via `ClientSessionManager` to route a
|
|
28
|
+
* tool/resource/prompt call to the right per-session handler instance.
|
|
29
|
+
*/
|
|
30
|
+
/** Result returned from `tools/call`. Aliased so handler signatures read in GLSP terms. */
|
|
31
|
+
export type McpToolResult = CallToolResult;
|
|
32
|
+
/** Result returned from `resources/read`. Aliased so handler signatures read in GLSP terms. */
|
|
33
|
+
export type McpResourceResult = ReadResourceResult;
|
|
34
|
+
/** Result returned from `prompts/get`. Aliased so handler signatures read in GLSP terms. */
|
|
35
|
+
export type McpPromptResult = GetPromptResult;
|
|
36
|
+
/** One content part of a {@link McpToolResult}. Tool results are an array of these. */
|
|
37
|
+
export type McpToolResultContent = CallToolResult['content'][number];
|
|
38
|
+
/** One content part of a {@link McpResourceResult}. Resource reads are an array of these. */
|
|
39
|
+
export type McpResourceResultContent = ReadResourceResult['contents'][number];
|
|
40
|
+
/**
|
|
41
|
+
* Single-content body returned by a session-scope resource handler. The base wraps it with
|
|
42
|
+
* `uri` + the handler's declared `mimeType` to produce the SDK `ReadResourceResult`.
|
|
43
|
+
*
|
|
44
|
+
* `structured` is dual-emit overflow used only when the resource is exposed as a tool
|
|
45
|
+
* (`toolAlternativeInputSchema` set) AND the handler also declares `toolAlternativeOutputSchema`.
|
|
46
|
+
* The framework forwards it to `CallToolResult.structuredContent`. Resource-protocol reads ignore
|
|
47
|
+
* it — the spec has no equivalent slot on `ReadResourceResult`.
|
|
48
|
+
*/
|
|
49
|
+
export type McpResourceContent = ({
|
|
50
|
+
text: string;
|
|
51
|
+
} | {
|
|
52
|
+
blob: string;
|
|
53
|
+
}) & {
|
|
54
|
+
structured?: McpStructuredContent;
|
|
55
|
+
};
|
|
56
|
+
/** Structured payload for `CallToolResult.structuredContent`. The MCP spec requires an object. */
|
|
57
|
+
export interface McpStructuredContent {
|
|
58
|
+
[key: string]: unknown;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Throw inside `createResult` to surface an expected, user-facing error to the MCP client.
|
|
62
|
+
* The base class catches it and emits an `isError: true` result. Unexpected errors
|
|
63
|
+
* (non-`McpToolError`) are logged and their extracted message is surfaced too.
|
|
64
|
+
*
|
|
65
|
+
* Use one of the named subclasses (`McpMissingParamError`, `McpSessionNotFoundError`,
|
|
66
|
+
* `McpReadOnlyError`, `McpElementsNotFoundError`, `McpRequestTimeoutError`) where they fit;
|
|
67
|
+
* otherwise throw `new McpToolError('context-specific message')`.
|
|
68
|
+
*/
|
|
69
|
+
export declare class McpToolError extends Error {
|
|
70
|
+
readonly cause?: unknown | undefined;
|
|
71
|
+
constructor(message: string, cause?: unknown | undefined);
|
|
72
|
+
}
|
|
73
|
+
/** Thrown when a required input parameter is missing or empty. */
|
|
74
|
+
export declare class McpMissingParamError extends McpToolError {
|
|
75
|
+
readonly paramName: string;
|
|
76
|
+
constructor(paramName: string);
|
|
77
|
+
}
|
|
78
|
+
/** Thrown when no GLSP client session matches the provided id. */
|
|
79
|
+
export declare class McpSessionNotFoundError extends McpToolError {
|
|
80
|
+
readonly sessionId: string;
|
|
81
|
+
constructor(sessionId: string);
|
|
82
|
+
}
|
|
83
|
+
/** Thrown when a write-style operation targets a read-only model. */
|
|
84
|
+
export declare class McpReadOnlyError extends McpToolError {
|
|
85
|
+
constructor();
|
|
86
|
+
}
|
|
87
|
+
/** Thrown by handlers that look up elements by id and find some absent from the model. */
|
|
88
|
+
export declare class McpElementsNotFoundError extends McpToolError {
|
|
89
|
+
readonly missingIds: readonly string[];
|
|
90
|
+
constructor(missingIds: readonly string[]);
|
|
91
|
+
}
|
|
92
|
+
/** Thrown when a request/response round-trip (`ActionDispatcher.requestUntil`) exceeds its timeout. */
|
|
93
|
+
export declare class McpRequestTimeoutError extends McpToolError {
|
|
94
|
+
readonly operation: string;
|
|
95
|
+
readonly timeoutMs: number;
|
|
96
|
+
constructor(operation: string, timeoutMs: number);
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Catch `McpToolError` thrown by pre-handler routing (e.g. `requireDiagramToolHandler`) and
|
|
100
|
+
* convert it to an `isError: true` tool result. Without this, those throws surface as
|
|
101
|
+
* JSON-RPC `-32603` instead of a self-correctable tool error.
|
|
102
|
+
*/
|
|
103
|
+
export declare function runWithToolErrorEnvelope(producer: () => Promise<CallToolResult>): Promise<CallToolResult>;
|
|
104
|
+
/** Stable codes surfaced in `CallToolResult.structuredContent.code` so the LLM can self-correct on a known taxonomy. */
|
|
105
|
+
export declare const McpToolErrorCodes: {
|
|
106
|
+
/** GLSP session disposed mid-call (server shutdown or session disposal). */
|
|
107
|
+
readonly SessionDisposed: "session-disposed";
|
|
108
|
+
};
|
|
109
|
+
export type McpToolErrorCode = (typeof McpToolErrorCodes)[keyof typeof McpToolErrorCodes];
|
|
110
|
+
/** True when `err` is a GLSP-session-disposed rejection from the action dispatcher's dispose hooks. */
|
|
111
|
+
export declare function isSessionDisposedError(err: unknown): boolean;
|
|
112
|
+
/** Resolve a known `McpToolErrorCode` for an error, or `undefined` if it is generic. */
|
|
113
|
+
export declare function errorCodeFor(err: unknown): McpToolErrorCode | undefined;
|
|
114
|
+
/** Build an `isError: true` tool result, attaching `structuredContent: { code }` when known. */
|
|
115
|
+
export declare function toolErrorResult(message: string, code?: McpToolErrorCode): CallToolResult;
|
|
116
|
+
/** Returns a useful message for a value caught from a `throw`. */
|
|
117
|
+
export declare function extractErrorMessage(error: unknown): string;
|
|
118
|
+
/**
|
|
119
|
+
* Dispatch a request action and await its response, surfacing failures uniformly.
|
|
120
|
+
*
|
|
121
|
+
* The `ActionDispatcher.requestUntil` API today returns `undefined` on timeout (default
|
|
122
|
+
* `rejectOnTimeout: false`) and throws when the client emits a `RejectAction`. Handlers
|
|
123
|
+
* that consume it have to branch on both. This helper consolidates that branching:
|
|
124
|
+
*
|
|
125
|
+
* - On client-side `RejectAction` → throws `McpToolError` with `${label} failed: <inner>`.
|
|
126
|
+
* - On timeout (undefined return) → throws `McpRequestTimeoutError(label, timeoutMs)`.
|
|
127
|
+
* - Otherwise → returns the typed response.
|
|
128
|
+
*
|
|
129
|
+
* Prefer the base-class methods (`OperationMcpDiagramToolHandler.requestAction` /
|
|
130
|
+
* `AbstractMcpDiagramResourceHandler.requestAction`) over calling this directly — they default
|
|
131
|
+
* the label to the handler's `name` field and pass `this.actionDispatcher`. This free
|
|
132
|
+
* function is the canonical implementation behind both.
|
|
133
|
+
*/
|
|
134
|
+
export declare function requestActionOrFail<R extends ResponseAction>(dispatcher: ActionDispatcher, request: RequestAction<R>, timeoutMs: number, label: string): Promise<R>;
|
|
135
|
+
/**
|
|
136
|
+
* Pick a target session for server-scope handlers (e.g. prompts) where `sessionId` is optional.
|
|
137
|
+
* Resolution: explicit id (validated to exist) → single open session → throw with the available
|
|
138
|
+
* ids when ambiguous, throw when none open. Keeps user-invoked entry points like slash-command
|
|
139
|
+
* prompts ergonomic in the common single-diagram case while staying explicit when not.
|
|
140
|
+
*/
|
|
141
|
+
export declare function resolveActiveSessionId(clientSessionManager: ClientSessionManager, explicitSessionId: string | undefined): string;
|
|
142
|
+
//# sourceMappingURL=mcp-handler-shared.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-handler-shared.d.ts","sourceRoot":"","sources":["../../src/server/mcp-handler-shared.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;kFAckF;AAElF,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC7G,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AAEtG;;;;;;;;;;;GAWG;AAIH,2FAA2F;AAC3F,MAAM,MAAM,aAAa,GAAG,cAAc,CAAC;AAC3C,+FAA+F;AAC/F,MAAM,MAAM,iBAAiB,GAAG,kBAAkB,CAAC;AACnD,4FAA4F;AAC5F,MAAM,MAAM,eAAe,GAAG,eAAe,CAAC;AAC9C,uFAAuF;AACvF,MAAM,MAAM,oBAAoB,GAAG,cAAc,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC;AACrE,6FAA6F;AAC7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C,cAAc,CAAC,GAAG,OAAO,CAAC,cAAc,CAAC,CAS/G;AAED,wHAAwH;AACxH,eAAO,MAAM,iBAAiB;IAC1B,4EAA4E;;CAEtE,CAAC;AACX,MAAM,MAAM,gBAAgB,GAAG,CAAC,OAAO,iBAAiB,CAAC,CAAC,MAAM,OAAO,iBAAiB,CAAC,CAAC;AAE1F,uGAAuG;AACvG,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAK5D;AAED,wFAAwF;AACxF,wBAAgB,YAAY,CAAC,GAAG,EAAE,OAAO,GAAG,gBAAgB,GAAG,SAAS,CAKvE;AAED,gGAAgG;AAChG,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,gBAAgB,GAAG,cAAc,CAMxF;AAED,kEAAkE;AAClE,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAQ1D;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,mBAAmB,CAAC,CAAC,SAAS,cAAc,EAC9D,UAAU,EAAE,gBAAgB,EAC5B,OAAO,EAAE,aAAa,CAAC,CAAC,CAAC,EACzB,SAAS,EAAE,MAAM,EACjB,KAAK,EAAE,MAAM,GACd,OAAO,CAAC,CAAC,CAAC,CAeZ;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,oBAAoB,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAgBhI"}
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/********************************************************************************
|
|
3
|
+
* Copyright (c) 2025-2026 EclipseSource and others.
|
|
4
|
+
*
|
|
5
|
+
* This program and the accompanying materials are made available under the
|
|
6
|
+
* terms of the Eclipse Public License v. 2.0 which is available at
|
|
7
|
+
* http://www.eclipse.org/legal/epl-2.0.
|
|
8
|
+
*
|
|
9
|
+
* This Source Code may also be made available under the following Secondary
|
|
10
|
+
* Licenses when the conditions for such availability set forth in the Eclipse
|
|
11
|
+
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
12
|
+
* with the GNU Classpath Exception which is available at
|
|
13
|
+
* https://www.gnu.org/software/classpath/license.html.
|
|
14
|
+
*
|
|
15
|
+
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
|
16
|
+
********************************************************************************/
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.McpToolErrorCodes = exports.McpRequestTimeoutError = exports.McpElementsNotFoundError = exports.McpReadOnlyError = exports.McpSessionNotFoundError = exports.McpMissingParamError = exports.McpToolError = void 0;
|
|
19
|
+
exports.runWithToolErrorEnvelope = runWithToolErrorEnvelope;
|
|
20
|
+
exports.isSessionDisposedError = isSessionDisposedError;
|
|
21
|
+
exports.errorCodeFor = errorCodeFor;
|
|
22
|
+
exports.toolErrorResult = toolErrorResult;
|
|
23
|
+
exports.extractErrorMessage = extractErrorMessage;
|
|
24
|
+
exports.requestActionOrFail = requestActionOrFail;
|
|
25
|
+
exports.resolveActiveSessionId = resolveActiveSessionId;
|
|
26
|
+
// ─── Errors ──────────────────────────────────────────────────────────────────
|
|
27
|
+
/**
|
|
28
|
+
* Throw inside `createResult` to surface an expected, user-facing error to the MCP client.
|
|
29
|
+
* The base class catches it and emits an `isError: true` result. Unexpected errors
|
|
30
|
+
* (non-`McpToolError`) are logged and their extracted message is surfaced too.
|
|
31
|
+
*
|
|
32
|
+
* Use one of the named subclasses (`McpMissingParamError`, `McpSessionNotFoundError`,
|
|
33
|
+
* `McpReadOnlyError`, `McpElementsNotFoundError`, `McpRequestTimeoutError`) where they fit;
|
|
34
|
+
* otherwise throw `new McpToolError('context-specific message')`.
|
|
35
|
+
*/
|
|
36
|
+
class McpToolError extends Error {
|
|
37
|
+
constructor(message, cause) {
|
|
38
|
+
super(message);
|
|
39
|
+
this.cause = cause;
|
|
40
|
+
this.name = 'McpToolError';
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.McpToolError = McpToolError;
|
|
44
|
+
/** Thrown when a required input parameter is missing or empty. */
|
|
45
|
+
class McpMissingParamError extends McpToolError {
|
|
46
|
+
constructor(paramName) {
|
|
47
|
+
super(`No '${paramName}' provided.`);
|
|
48
|
+
this.paramName = paramName;
|
|
49
|
+
this.name = 'McpMissingParamError';
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
exports.McpMissingParamError = McpMissingParamError;
|
|
53
|
+
/** Thrown when no GLSP client session matches the provided id. */
|
|
54
|
+
class McpSessionNotFoundError extends McpToolError {
|
|
55
|
+
constructor(sessionId) {
|
|
56
|
+
super(`Session not found: ${sessionId}`);
|
|
57
|
+
this.sessionId = sessionId;
|
|
58
|
+
this.name = 'McpSessionNotFoundError';
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
exports.McpSessionNotFoundError = McpSessionNotFoundError;
|
|
62
|
+
/** Thrown when a write-style operation targets a read-only model. */
|
|
63
|
+
class McpReadOnlyError extends McpToolError {
|
|
64
|
+
constructor() {
|
|
65
|
+
super('Model is read-only.');
|
|
66
|
+
this.name = 'McpReadOnlyError';
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
exports.McpReadOnlyError = McpReadOnlyError;
|
|
70
|
+
/** Thrown by handlers that look up elements by id and find some absent from the model. */
|
|
71
|
+
class McpElementsNotFoundError extends McpToolError {
|
|
72
|
+
constructor(missingIds) {
|
|
73
|
+
super(`Element(s) not found: ${missingIds.join(', ')}`);
|
|
74
|
+
this.missingIds = missingIds;
|
|
75
|
+
this.name = 'McpElementsNotFoundError';
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
exports.McpElementsNotFoundError = McpElementsNotFoundError;
|
|
79
|
+
/** Thrown when a request/response round-trip (`ActionDispatcher.requestUntil`) exceeds its timeout. */
|
|
80
|
+
class McpRequestTimeoutError extends McpToolError {
|
|
81
|
+
constructor(operation, timeoutMs) {
|
|
82
|
+
super(`${operation} timed out after ${timeoutMs}ms.`);
|
|
83
|
+
this.operation = operation;
|
|
84
|
+
this.timeoutMs = timeoutMs;
|
|
85
|
+
this.name = 'McpRequestTimeoutError';
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
exports.McpRequestTimeoutError = McpRequestTimeoutError;
|
|
89
|
+
// ─── Helpers ─────────────────────────────────────────────────────────────────
|
|
90
|
+
/**
|
|
91
|
+
* Catch `McpToolError` thrown by pre-handler routing (e.g. `requireDiagramToolHandler`) and
|
|
92
|
+
* convert it to an `isError: true` tool result. Without this, those throws surface as
|
|
93
|
+
* JSON-RPC `-32603` instead of a self-correctable tool error.
|
|
94
|
+
*/
|
|
95
|
+
async function runWithToolErrorEnvelope(producer) {
|
|
96
|
+
try {
|
|
97
|
+
return await producer();
|
|
98
|
+
}
|
|
99
|
+
catch (err) {
|
|
100
|
+
if (err instanceof McpToolError) {
|
|
101
|
+
return toolErrorResult(err.message, errorCodeFor(err));
|
|
102
|
+
}
|
|
103
|
+
throw err;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
/** Stable codes surfaced in `CallToolResult.structuredContent.code` so the LLM can self-correct on a known taxonomy. */
|
|
107
|
+
exports.McpToolErrorCodes = {
|
|
108
|
+
/** GLSP session disposed mid-call (server shutdown or session disposal). */
|
|
109
|
+
SessionDisposed: 'session-disposed'
|
|
110
|
+
};
|
|
111
|
+
/** True when `err` is a GLSP-session-disposed rejection from the action dispatcher's dispose hooks. */
|
|
112
|
+
function isSessionDisposedError(err) {
|
|
113
|
+
if (!(err instanceof Error)) {
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
return /ActionDispatcher disposed|cancelled: dispatcher disposed/.test(err.message);
|
|
117
|
+
}
|
|
118
|
+
/** Resolve a known `McpToolErrorCode` for an error, or `undefined` if it is generic. */
|
|
119
|
+
function errorCodeFor(err) {
|
|
120
|
+
if (isSessionDisposedError(err)) {
|
|
121
|
+
return exports.McpToolErrorCodes.SessionDisposed;
|
|
122
|
+
}
|
|
123
|
+
return undefined;
|
|
124
|
+
}
|
|
125
|
+
/** Build an `isError: true` tool result, attaching `structuredContent: { code }` when known. */
|
|
126
|
+
function toolErrorResult(message, code) {
|
|
127
|
+
return {
|
|
128
|
+
isError: true,
|
|
129
|
+
content: [{ type: 'text', text: message }],
|
|
130
|
+
...(code ? { structuredContent: { code } } : {})
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
/** Returns a useful message for a value caught from a `throw`. */
|
|
134
|
+
function extractErrorMessage(error) {
|
|
135
|
+
if (error instanceof Error) {
|
|
136
|
+
return error.message;
|
|
137
|
+
}
|
|
138
|
+
if (typeof error === 'string') {
|
|
139
|
+
return error;
|
|
140
|
+
}
|
|
141
|
+
return String(error);
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Dispatch a request action and await its response, surfacing failures uniformly.
|
|
145
|
+
*
|
|
146
|
+
* The `ActionDispatcher.requestUntil` API today returns `undefined` on timeout (default
|
|
147
|
+
* `rejectOnTimeout: false`) and throws when the client emits a `RejectAction`. Handlers
|
|
148
|
+
* that consume it have to branch on both. This helper consolidates that branching:
|
|
149
|
+
*
|
|
150
|
+
* - On client-side `RejectAction` → throws `McpToolError` with `${label} failed: <inner>`.
|
|
151
|
+
* - On timeout (undefined return) → throws `McpRequestTimeoutError(label, timeoutMs)`.
|
|
152
|
+
* - Otherwise → returns the typed response.
|
|
153
|
+
*
|
|
154
|
+
* Prefer the base-class methods (`OperationMcpDiagramToolHandler.requestAction` /
|
|
155
|
+
* `AbstractMcpDiagramResourceHandler.requestAction`) over calling this directly — they default
|
|
156
|
+
* the label to the handler's `name` field and pass `this.actionDispatcher`. This free
|
|
157
|
+
* function is the canonical implementation behind both.
|
|
158
|
+
*/
|
|
159
|
+
async function requestActionOrFail(dispatcher, request, timeoutMs, label) {
|
|
160
|
+
let response;
|
|
161
|
+
try {
|
|
162
|
+
response = await dispatcher.requestUntil(request, timeoutMs);
|
|
163
|
+
}
|
|
164
|
+
catch (err) {
|
|
165
|
+
// Preserve the original rejection error as `cause` so adopters whose `RejectAction`
|
|
166
|
+
// sets `detail` (which core flattens into the message via `${message}: ${detail}`) can
|
|
167
|
+
// still inspect the underlying object — both for diagnostic logging and for an LLM
|
|
168
|
+
// surface that wants to disambiguate transient vs. permanent failures.
|
|
169
|
+
throw new McpToolError(`${label} failed: ${extractErrorMessage(err)}`, err);
|
|
170
|
+
}
|
|
171
|
+
if (!response) {
|
|
172
|
+
throw new McpRequestTimeoutError(label, timeoutMs);
|
|
173
|
+
}
|
|
174
|
+
return response;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Pick a target session for server-scope handlers (e.g. prompts) where `sessionId` is optional.
|
|
178
|
+
* Resolution: explicit id (validated to exist) → single open session → throw with the available
|
|
179
|
+
* ids when ambiguous, throw when none open. Keeps user-invoked entry points like slash-command
|
|
180
|
+
* prompts ergonomic in the common single-diagram case while staying explicit when not.
|
|
181
|
+
*/
|
|
182
|
+
function resolveActiveSessionId(clientSessionManager, explicitSessionId) {
|
|
183
|
+
const sessions = clientSessionManager.getSessions();
|
|
184
|
+
if (explicitSessionId) {
|
|
185
|
+
if (!sessions.some(session => session.id === explicitSessionId)) {
|
|
186
|
+
throw new McpToolError(`Unknown sessionId: ${explicitSessionId}`);
|
|
187
|
+
}
|
|
188
|
+
return explicitSessionId;
|
|
189
|
+
}
|
|
190
|
+
if (sessions.length === 0) {
|
|
191
|
+
throw new McpToolError('No open diagram sessions to target.');
|
|
192
|
+
}
|
|
193
|
+
if (sessions.length === 1) {
|
|
194
|
+
return sessions[0].id;
|
|
195
|
+
}
|
|
196
|
+
const ids = sessions.map(session => `'${session.id}'`).join(', ');
|
|
197
|
+
throw new McpToolError(`Multiple sessions open (${ids}); pass \`sessionId\` to disambiguate.`);
|
|
198
|
+
}
|
|
199
|
+
//# sourceMappingURL=mcp-handler-shared.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{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iBAAqC;IACpH,MAAM,QAAQ,GAAG,oBAAoB,CAAC,WAAW,EAAE,CAAC;IACpD,IAAI,iBAAiB,EAAE,CAAC;QACpB,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC,EAAE,KAAK,iBAAiB,CAAC,EAAE,CAAC;YAC9D,MAAM,IAAI,YAAY,CAAC,sBAAsB,iBAAiB,EAAE,CAAC,CAAC;QACtE,CAAC;QACD,OAAO,iBAAiB,CAAC;IAC7B,CAAC;IACD,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACxB,MAAM,IAAI,YAAY,CAAC,qCAAqC,CAAC,CAAC;IAClE,CAAC;IACD,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACxB,OAAO,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IAC1B,CAAC;IACD,MAAM,GAAG,GAAG,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,IAAI,OAAO,CAAC,EAAE,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAClE,MAAM,IAAI,YAAY,CAAC,2BAA2B,GAAG,wCAAwC,CAAC,CAAC;AACnG,CAAC"}
|
|
@@ -0,0 +1,93 @@
|
|
|
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
|
+
import { Deferred, Disposable, Emitter, Logger } from '@eclipse-glsp/server';
|
|
17
|
+
import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';
|
|
18
|
+
import type { Express } from 'express';
|
|
19
|
+
import * as express from 'express';
|
|
20
|
+
import * as http from 'http';
|
|
21
|
+
import { AddressInfo } from 'net';
|
|
22
|
+
import { McpServerOptions } from './mcp-options';
|
|
23
|
+
import type { FullMcpServerConfiguration } from './mcp-server-launcher';
|
|
24
|
+
import { McpSession } from './mcp-session';
|
|
25
|
+
/**
|
|
26
|
+
* Where this transport can be reached. Network transports populate `url`;
|
|
27
|
+
* future in-process or stdio transports would leave it undefined.
|
|
28
|
+
*/
|
|
29
|
+
export interface TransportEndpoint {
|
|
30
|
+
url?: string;
|
|
31
|
+
headers?: Record<string, string>;
|
|
32
|
+
}
|
|
33
|
+
export declare class McpHttpTransport implements Disposable {
|
|
34
|
+
protected logger: Logger;
|
|
35
|
+
protected _app?: Express;
|
|
36
|
+
protected _server?: http.Server;
|
|
37
|
+
protected _addressInfo: Deferred<AddressInfo>;
|
|
38
|
+
protected sessions: Map<string, StreamableHTTPServerTransport>;
|
|
39
|
+
protected onSessionInitializedEmitter: Emitter<McpSession>;
|
|
40
|
+
onSessionInitialized: import("@eclipse-glsp/server").Event<McpSession>;
|
|
41
|
+
protected onSessionClosedEmitter: Emitter<string>;
|
|
42
|
+
onSessionClosed: import("@eclipse-glsp/server").Event<string>;
|
|
43
|
+
protected serverOptions: McpServerOptions;
|
|
44
|
+
constructor(logger: Logger);
|
|
45
|
+
get app(): Express | undefined;
|
|
46
|
+
get server(): http.Server | undefined;
|
|
47
|
+
getAddress(): Promise<AddressInfo>;
|
|
48
|
+
start(config: FullMcpServerConfiguration): Promise<TransportEndpoint>;
|
|
49
|
+
/**
|
|
50
|
+
* Translate a pre-listen failure into an actionable error and reject the address-info
|
|
51
|
+
* deferred so `start()` propagates it to the caller. `EADDRINUSE` gets a tailored hint
|
|
52
|
+
* about overriding via `mcpServer.port`; other codes pass through unchanged.
|
|
53
|
+
*/
|
|
54
|
+
protected handleListenError(err: NodeJS.ErrnoException, host: string, port: number): void;
|
|
55
|
+
/**
|
|
56
|
+
* Hook for subclasses to register middleware on the Express app before the MCP routes
|
|
57
|
+
* are mounted. Called once during {@link start}, after the app is created and before
|
|
58
|
+
* `POST` / `GET` / `DELETE` handlers are added.
|
|
59
|
+
*
|
|
60
|
+
* Default behavior: install an Origin allowlist if one is configured. Host-header
|
|
61
|
+
* validation is already wired by the SDK's `createMcpExpressApp` (using the same
|
|
62
|
+
* `allowedHosts` we forward in {@link start}); we don't duplicate it here. Subclasses
|
|
63
|
+
* that override SHOULD `super.configureExpressApp(app)` to keep the origin gate in place;
|
|
64
|
+
* pre-existing security middleware can run before or after by calling super at the
|
|
65
|
+
* appropriate point.
|
|
66
|
+
*/
|
|
67
|
+
protected configureExpressApp(app: Express): void;
|
|
68
|
+
/**
|
|
69
|
+
* Validate the `MCP-Protocol-Version` header per the Streamable HTTP transport spec.
|
|
70
|
+
* Initialize POSTs negotiate the version in the body — the header isn't expected there.
|
|
71
|
+
* For every other request: absent header → pass through (the spec mandates the server
|
|
72
|
+
* default to `2025-03-26`); present-but-unsupported → respond `400` with a JSON-RPC error
|
|
73
|
+
* envelope so the client knows which versions to retry with.
|
|
74
|
+
*/
|
|
75
|
+
protected validateProtocolVersionHeader(req: express.Request, res: express.Response, next: express.NextFunction): void;
|
|
76
|
+
protected toServerUrl({ address, family, port }: AddressInfo, route: string, protocol?: string): string;
|
|
77
|
+
protected listening(): void;
|
|
78
|
+
protected handlePostRequest(req: express.Request, res: express.Response): Promise<void>;
|
|
79
|
+
/**
|
|
80
|
+
* Handle GET requests for SSE streams (using built-in support from StreamableHTTP)
|
|
81
|
+
*/
|
|
82
|
+
protected handleGetRequest(req: express.Request, res: express.Response): Promise<void>;
|
|
83
|
+
/**
|
|
84
|
+
* Handle DELETE requests for session termination (according to MCP spec).
|
|
85
|
+
*/
|
|
86
|
+
protected handleDeleteRequest(req: express.Request, res: express.Response): Promise<void>;
|
|
87
|
+
protected getOrCreateClient(req: express.Request, res: express.Response): StreamableHTTPServerTransport | undefined;
|
|
88
|
+
protected getClient(req: express.Request, res: express.Response): StreamableHTTPServerTransport | undefined;
|
|
89
|
+
protected createClient(): StreamableHTTPServerTransport;
|
|
90
|
+
protected closeClient(sessionId?: string): void;
|
|
91
|
+
dispose(): void;
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=mcp-http-transport.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-http-transport.d.ts","sourceRoot":"","sources":["../../src/server/mcp-http-transport.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;kFAckF;AAElF,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAE7E,OAAO,EAAE,6BAA6B,EAAE,MAAM,oDAAoD,CAAC;AAEnG,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AACnC,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAE7B,OAAO,EAAE,WAAW,EAAE,MAAM,KAAK,CAAC;AAGlC,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,uBAAuB,CAAC;AACxE,OAAO,EAAE,UAAU,EAA+B,MAAM,eAAe,CAAC;AAExE;;;GAGG;AACH,MAAM,WAAW,iBAAiB;IAC9B,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACpC;AAED,qBACa,gBAAi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