@eclipse-glsp-examples/workflow-server-bundled 2.8.0-next.6 → 2.8.0-next.7
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/package.json
CHANGED
package/wf-glsp-server-node.js
CHANGED
|
@@ -243,7 +243,7 @@ data:
|
|
|
243
243
|
`;return l&&(g+=`id: ${l}
|
|
244
244
|
`),g+=`data: ${JSON.stringify(u)}
|
|
245
245
|
|
|
246
|
-
`,n.enqueue(s.encode(g)),!0}catch(g){return this.onerror?.(g),!1}}handleUnsupportedRequest(){return this.onerror?.(new Error("Method not allowed.")),new Response(JSON.stringify({jsonrpc:"2.0",error:{code:-32e3,message:"Method not allowed."},id:null}),{status:405,headers:{Allow:"GET, POST, DELETE","Content-Type":"application/json"}})}async handlePostRequest(n,s){try{let u=n.headers.get("accept");if(!u?.includes("application/json")||!u.includes("text/event-stream"))return this.onerror?.(new Error("Not Acceptable: Client must accept both application/json and text/event-stream")),this.createJsonErrorResponse(406,-32e3,"Not Acceptable: Client must accept both application/json and text/event-stream");let l=n.headers.get("content-type");if(!l||!l.includes("application/json"))return this.onerror?.(new Error("Unsupported Media Type: Content-Type must be application/json")),this.createJsonErrorResponse(415,-32e3,"Unsupported Media Type: Content-Type must be application/json");let g={headers:Object.fromEntries(n.headers.entries()),url:new URL(n.url)},v;if(s?.parsedBody!==void 0)v=s.parsedBody;else try{v=await n.json()}catch{return this.onerror?.(new Error("Parse error: Invalid JSON")),this.createJsonErrorResponse(400,-32700,"Parse error: Invalid JSON")}let w;try{Array.isArray(v)?w=v.map(xe=>bp.JSONRPCMessageSchema.parse(xe)):w=[bp.JSONRPCMessageSchema.parse(v)]}catch{return this.onerror?.(new Error("Parse error: Invalid JSON-RPC message")),this.createJsonErrorResponse(400,-32700,"Parse error: Invalid JSON-RPC message")}let M=w.some(bp.isInitializeRequest);if(M){if(this._initialized&&this.sessionId!==void 0)return this.onerror?.(new Error("Invalid Request: Server already initialized")),this.createJsonErrorResponse(400,-32600,"Invalid Request: Server already initialized");if(w.length>1)return this.onerror?.(new Error("Invalid Request: Only one initialization request is allowed")),this.createJsonErrorResponse(400,-32600,"Invalid Request: Only one initialization request is allowed");this.sessionId=this.sessionIdGenerator?.(),this._initialized=!0,this.sessionId&&this._onsessioninitialized&&await Promise.resolve(this._onsessioninitialized(this.sessionId))}if(!M){let xe=this.validateSession(n);if(xe)return xe;let Ye=this.validateProtocolVersion(n);if(Ye)return Ye}if(!w.some(bp.isJSONRPCRequest)){for(let xe of w)this.onmessage?.(xe,{authInfo:s?.authInfo,requestInfo:g});return new Response(null,{status:202})}let R=crypto.randomUUID(),z=w.find(xe=>(0,bp.isInitializeRequest)(xe)),K=z?z.params.protocolVersion:n.headers.get("mcp-protocol-version")??bp.DEFAULT_NEGOTIATED_PROTOCOL_VERSION;if(this._enableJsonResponse)return new Promise(xe=>{this._streamMapping.set(R,{resolveJson:xe,cleanup:r(()=>{this._streamMapping.delete(R)},"cleanup")});for(let Ye of w)(0,bp.isJSONRPCRequest)(Ye)&&this._requestToStreamMapping.set(Ye.id,R);for(let Ye of w)this.onmessage?.(Ye,{authInfo:s?.authInfo,requestInfo:g})});let ie=new TextEncoder,ne,me=new ReadableStream({start:r(xe=>{ne=xe},"start"),cancel:r(()=>{this._streamMapping.delete(R)},"cancel")}),ke={"Content-Type":"text/event-stream","Cache-Control":"no-cache",Connection:"keep-alive"};this.sessionId!==void 0&&(ke["mcp-session-id"]=this.sessionId);for(let xe of w)(0,bp.isJSONRPCRequest)(xe)&&(this._streamMapping.set(R,{controller:ne,encoder:ie,cleanup:r(()=>{this._streamMapping.delete(R);try{ne.close()}catch{}},"cleanup")}),this._requestToStreamMapping.set(xe.id,R));await this.writePrimingEvent(ne,ie,R,K);for(let xe of w){let Ye,Ke;(0,bp.isJSONRPCRequest)(xe)&&this._eventStore&&K>="2025-11-25"&&(Ye=r(()=>{this.closeSSEStream(xe.id)},"closeSSEStream"),Ke=r(()=>{this.closeStandaloneSSEStream()},"closeStandaloneSSEStream")),this.onmessage?.(xe,{authInfo:s?.authInfo,requestInfo:g,closeSSEStream:Ye,closeStandaloneSSEStream:Ke})}return new Response(me,{status:200,headers:ke})}catch(u){return this.onerror?.(u),this.createJsonErrorResponse(400,-32700,"Parse error",{data:String(u)})}}async handleDeleteRequest(n){let s=this.validateSession(n);if(s)return s;let u=this.validateProtocolVersion(n);return u||(await Promise.resolve(this._onsessionclosed?.(this.sessionId)),await this.close(),new Response(null,{status:200}))}validateSession(n){if(this.sessionIdGenerator===void 0)return;if(!this._initialized)return this.onerror?.(new Error("Bad Request: Server not initialized")),this.createJsonErrorResponse(400,-32e3,"Bad Request: Server not initialized");let s=n.headers.get("mcp-session-id");if(!s)return this.onerror?.(new Error("Bad Request: Mcp-Session-Id header is required")),this.createJsonErrorResponse(400,-32e3,"Bad Request: Mcp-Session-Id header is required");if(s!==this.sessionId)return this.onerror?.(new Error("Session not found")),this.createJsonErrorResponse(404,-32001,"Session not found")}validateProtocolVersion(n){let s=n.headers.get("mcp-protocol-version");if(s!==null&&!bp.SUPPORTED_PROTOCOL_VERSIONS.includes(s))return this.onerror?.(new Error(`Bad Request: Unsupported protocol version: ${s} (supported versions: ${bp.SUPPORTED_PROTOCOL_VERSIONS.join(", ")})`)),this.createJsonErrorResponse(400,-32e3,`Bad Request: Unsupported protocol version: ${s} (supported versions: ${bp.SUPPORTED_PROTOCOL_VERSIONS.join(", ")})`)}async close(){this._streamMapping.forEach(({cleanup:n})=>{n()}),this._streamMapping.clear(),this._requestResponseMap.clear(),this.onclose?.()}closeSSEStream(n){let s=this._requestToStreamMapping.get(n);if(!s)return;let u=this._streamMapping.get(s);u&&u.cleanup()}closeStandaloneSSEStream(){let n=this._streamMapping.get(this._standaloneSseStreamId);n&&n.cleanup()}async send(n,s){let u=s?.relatedRequestId;if(((0,bp.isJSONRPCResultResponse)(n)||(0,bp.isJSONRPCErrorResponse)(n))&&(u=n.id),u===void 0){if((0,bp.isJSONRPCResultResponse)(n)||(0,bp.isJSONRPCErrorResponse)(n))throw new Error("Cannot send a response on a standalone SSE stream unless resuming a previous client request");let v;this._eventStore&&(v=await this._eventStore.storeEvent(this._standaloneSseStreamId,n));let w=this._streamMapping.get(this._standaloneSseStreamId);if(w===void 0)return;w.controller&&w.encoder&&this.writeSSEEvent(w.controller,w.encoder,n,v);return}let l=this._requestToStreamMapping.get(u);if(!l)throw new Error(`No connection established for request ID: ${String(u)}`);let g=this._streamMapping.get(l);if(!this._enableJsonResponse&&g?.controller&&g?.encoder){let v;this._eventStore&&(v=await this._eventStore.storeEvent(l,n)),this.writeSSEEvent(g.controller,g.encoder,n,v)}if((0,bp.isJSONRPCResultResponse)(n)||(0,bp.isJSONRPCErrorResponse)(n)){this._requestResponseMap.set(u,n);let v=Array.from(this._requestToStreamMapping.entries()).filter(([M,A])=>A===l).map(([M])=>M);if(v.every(M=>this._requestResponseMap.has(M))){if(!g)throw new Error(`No connection established for request ID: ${String(u)}`);if(this._enableJsonResponse&&g.resolveJson){let M={"Content-Type":"application/json"};this.sessionId!==void 0&&(M["mcp-session-id"]=this.sessionId);let A=v.map(R=>this._requestResponseMap.get(R));A.length===1?g.resolveJson(new Response(JSON.stringify(A[0]),{status:200,headers:M})):g.resolveJson(new Response(JSON.stringify(A),{status:200,headers:M}))}else g.cleanup();for(let M of v)this._requestResponseMap.delete(M),this._requestToStreamMapping.delete(M)}}}};Jye.WebStandardStreamableHTTPServerTransport=vYe});var Vbn=x((p6i,bRr)=>{bRr.exports={name:"@eclipse-glsp/server-mcp",version:"2.8.0-next.6",description:"Model Context Protocol (MCP) server for the GLSP TypeScript server \u2014 runs on Node, browser, and Fetch-API runtimes",keywords:["eclipse","graphics","diagram","modeling","visualization","glsp","diagram editor","mcp"],homepage:"https://www.eclipse.org/glsp/",bugs:"https://github.com/eclipse-glsp/glsp/issues",repository:{type:"git",url:"https://github.com/eclipse-glsp/glsp-server-node.git"},license:"(EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0)",author:{name:"Eclipse GLSP"},contributors:[{name:"Eclipse GLSP Project",email:"glsp-dev@eclipse.org",url:"https://projects.eclipse.org/projects/ecd.glsp"}],main:"lib/node/index",browser:{"lib/node/index":"./lib/browser/index"},types:"lib/common/index",files:["lib","src","node.js","node.d.ts","browser.js","browser.d.ts","common.js","common.d.ts","!**/*.spec.ts","!**/*.spec.tsx","!**/test/**"],scripts:{build:"tsc -b",clean:"rimraf lib *.tsbuildinfo coverage","generate:index":"glsp generateIndex src/browser src/common src/node -f -s",lint:"eslint --ext .ts,.tsx ./src",prepublishOnly:"pnpm build"},dependencies:{"@eclipse-glsp/server":"workspace:*","@hono/node-server":"^1.19.9","@modelcontextprotocol/sdk":"^1.29.0",zod:"^4.0.0"},peerDependencies:{inversify:"^6.1.3","reflect-metadata":"^0.2.2"},publishConfig:{access:"public"}}});var Vye=x(b1=>{"use strict";var vRr=b1&&b1.__decorate||function(o,n,s,u){var l=arguments.length,g=l<3?n:u===null?u=Object.getOwnPropertyDescriptor(n,s):u,v;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")g=Reflect.decorate(o,n,s,u);else for(var w=o.length-1;w>=0;w--)(v=o[w])&&(g=(l<3?v(g):l>3?v(n,s,g):v(n,s))||g);return l>3&&g&&Object.defineProperty(n,s,g),g},wRr=b1&&b1.__metadata||function(o,n){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(o,n)},wYe=b1&&b1.__param||function(o,n){return function(s,u){n(s,u,o)}};Object.defineProperty(b1,"__esModule",{value:!0});b1.DefaultGLSPMcpServer=b1.GLSPMcpServerFactory=b1.GLSPMcpServer=void 0;var yRr=Kr(),_Rr=RQ(),yYe=Tk(),Kye=en();b1.GLSPMcpServer=Symbol("GLSPMcpServer");var SRr=3e4,ERr=5e3;b1.GLSPMcpServerFactory=Symbol("GLSPMcpServerFactory");var _Ye=class{static{r(this,"DefaultGLSPMcpServer")}constructor(n,s,u){this.mcpServer=n,this.options=s,this.logger=u,this.tools=new Map,this.resources=new Map,this.prompts=new Map;let{tools:l,resources:g,prompts:v}=this;this.registerTool=new Proxy(n.registerTool.bind(n),{apply(w,M,A){let R=Reflect.apply(w,M,A);return typeof A[0]=="string"&&l.set(A[0],R),R}}),this.registerResource=new Proxy(n.registerResource.bind(n),{apply(w,M,A){let R=Reflect.apply(w,M,A);return typeof A[0]=="string"&&g.set(A[0],R),R}}),this.registerPrompt=new Proxy(n.registerPrompt.bind(n),{apply(w,M,A){let R=Reflect.apply(w,M,A);return typeof A[0]=="string"&&v.set(A[0],R),R}})}sendLoggingMessage(...n){return this.mcpServer.sendLoggingMessage(...n)}async connect(...n){await this.mcpServer.connect(...n),this.keepAliveTimer=setInterval(()=>this.ping().catch(u=>{(!(u instanceof yYe.McpError)||u.code!==yYe.ErrorCode.RequestTimeout)&&this.logger.debug("MCP keep-alive ping failed:",u)}),SRr);let s=this.keepAliveTimer.unref;typeof s=="function"&&s.call(this.keepAliveTimer)}isConnected(){return this.mcpServer.isConnected()}async ping(){await this.mcpServer.server.request({method:"ping"},yYe.EmptyResultSchema,{timeout:ERr})}listTools(){return[...this.tools.values()]}hasTool(n){return this.tools.has(n)}listResources(){return[...this.resources.values()]}listPrompts(){return[...this.prompts.values()]}getRawServer(){return this.mcpServer}dispose(){this.keepAliveTimer&&(clearInterval(this.keepAliveTimer),this.keepAliveTimer=void 0),this.mcpServer.close()}};b1.DefaultGLSPMcpServer=_Ye;b1.DefaultGLSPMcpServer=_Ye=vRr([(0,Kye.injectable)(),wYe(0,(0,Kye.unmanaged)()),wYe(1,(0,Kye.unmanaged)()),wYe(2,(0,Kye.unmanaged)()),wRr("design:paramtypes",[_Rr.McpServer,Object,yRr.Logger])],_Ye)});var Xye=x(Wye=>{"use strict";Object.defineProperty(Wye,"__esModule",{value:!0});Wye.LruEventStore=void 0;var SYe=class o{static{r(this,"LruEventStore")}static{this.DEFAULT_LIMIT=1e4}constructor(n=o.DEFAULT_LIMIT,s){if(this.events=new Map,n<1)throw new Error(`LruEventStore limit must be >= 1, got ${n}`);this.limit=n,this.logger=s}get size(){return this.events.size}async storeEvent(n,s){let u=`${n}_${Date.now()}_${Math.random().toString(36).substring(2,10)}`;if(this.events.set(u,{streamId:n,message:s}),this.events.size>this.limit){let l=this.events.keys().next().value;l!==void 0&&this.events.delete(l)}return u}async replayEventsAfter(n,{send:s}){if(!n)return"";if(!this.events.has(n))return this.logger?.warn(`[LruEventStore] Replay miss for last-event-id '${n}'. Cap is ${this.limit}; consider increasing \`eventStoreLimit\` if this fires under normal load.`),"";let u=n.split("_")[0];if(!u)return"";let l=!1;for(let[g,{streamId:v,message:w}]of this.events)if(v===u){if(g===n){l=!0;continue}l&&await s(g,w)}return u}};Wye.LruEventStore=SYe});var Yye=x(v1=>{"use strict";var DQ=v1&&v1.__decorate||function(o,n,s,u){var l=arguments.length,g=l<3?n:u===null?u=Object.getOwnPropertyDescriptor(n,s):u,v;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")g=Reflect.decorate(o,n,s,u);else for(var w=o.length-1;w>=0;w--)(v=o[w])&&(g=(l<3?v(g):l>3?v(n,s,g):v(n,s))||g);return l>3&&g&&Object.defineProperty(n,s,g),g},EYe=v1&&v1.__metadata||function(o,n){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(o,n)};Object.defineProperty(v1,"__esModule",{value:!0});v1.McpDiagramPromptHandlerRegistryInitializer=v1.McpDiagramPromptHandlerRegistry=v1.McpDiagramPromptHandlerFactory=void 0;var ORr=Kr(),Iz=en(),PRr=sI();v1.McpDiagramPromptHandlerFactory=Symbol("McpDiagramPromptHandlerFactory");var $Q=class extends ORr.Registry{static{r(this,"McpDiagramPromptHandlerRegistry")}registerHandler(n){return this.register(n.name,n)}};v1.McpDiagramPromptHandlerRegistry=$Q;v1.McpDiagramPromptHandlerRegistry=$Q=DQ([(0,Iz.injectable)()],$Q);var Az=class{static{r(this,"McpDiagramPromptHandlerRegistryInitializer")}constructor(){this.constructors=[]}initialize(n){for(let s of this.constructors)try{this.registry.registerHandler(this.factory(s))}catch(u){throw new Error(`Failed to instantiate MCP diagram prompt handler '${s.name}': ${u.message}. Check your DiagramModule bindings.`)}}};v1.McpDiagramPromptHandlerRegistryInitializer=Az;DQ([(0,Iz.inject)(v1.McpDiagramPromptHandlerFactory),EYe("design:type",Function)],Az.prototype,"factory",void 0);DQ([(0,Iz.inject)(PRr.McpDiagramPromptHandlerConstructor),(0,Iz.optional)(),EYe("design:type",Array)],Az.prototype,"constructors",void 0);DQ([(0,Iz.inject)($Q),EYe("design:type",$Q)],Az.prototype,"registry",void 0);v1.McpDiagramPromptHandlerRegistryInitializer=Az=DQ([(0,Iz.injectable)()],Az)});var yI=x(ig=>{"use strict";var wI=ig&&ig.__decorate||function(o,n,s,u){var l=arguments.length,g=l<3?n:u===null?u=Object.getOwnPropertyDescriptor(n,s):u,v;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")g=Reflect.decorate(o,n,s,u);else for(var w=o.length-1;w>=0;w--)(v=o[w])&&(g=(l<3?v(g):l>3?v(n,s,g):v(n,s))||g);return l>3&&g&&Object.defineProperty(n,s,g),g},Cz=ig&&ig.__metadata||function(o,n){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(o,n)};Object.defineProperty(ig,"__esModule",{value:!0});ig.McpDiagramResourceHandlerConstructor=ig.AbstractMcpDiagramResourceHandler=ig.AbstractMcpResourceHandler=ig.McpResourceHandler=void 0;ig.toParams=Xbn;var NQ=Kr(),jRr=RQ(),_3=en(),OYe=Zd(),MRr=NN(),Wbn=iI();ig.McpResourceHandler=Symbol("McpResourceHandler");var kz=class{static{r(this,"BaseMcpResourceHandler")}constructor(){this.requestContext=new Wbn.NoopMcpRequestContext}toAnnotations(){if(!(this.audience===void 0&&this.priority===void 0&&this.lastModified===void 0))return{...this.audience!==void 0?{audience:this.audience}:{},...this.priority!==void 0?{priority:this.priority}:{},...this.lastModified!==void 0?{lastModified:this.lastModified}:{}}}uriTemplate(){return typeof this.uri=="string"?this.uri:this.uri.template}expandUriTemplate(n){return this.uriTemplate().replace(/\{(\w+)\}/g,(s,u)=>{let l=n[u];return l===void 0?s:encodeURIComponent(l)})}async execute(n){try{return{ok:!0,body:await n()}}catch(s){if(s instanceof OYe.McpToolError)return{ok:!1,message:s.message};let u=(0,OYe.extractErrorMessage)(s);return this.logger.error(`Unexpected error in resource '${this.name}': ${u}`,s),{ok:!1,message:u}}}toResourceResult(n,s){return s.ok?{contents:["text"in s.body?{uri:n,mimeType:this.mimeType,text:s.body.text}:{uri:n,mimeType:this.mimeType,blob:s.body.blob}],isError:!1}:{contents:[{uri:n,mimeType:"text/plain",text:s.message}],isError:!0}}toToolResult(n){if(!n.ok)return{isError:!0,content:[{type:"text",text:n.message}]};let s=n.body.structured,u="text"in n.body?{isError:!1,content:[{type:"text",text:n.body.text}]}:{isError:!1,content:[{type:"image",data:n.body.blob,mimeType:this.mimeType}]};return s?{...u,structuredContent:s}:u}buildResourceTemplate(n){return new jRr.ResourceTemplate(n,{list:this.list?async s=>this.requestContext.run(s,()=>this.list()):void 0,complete:this.complete?.()})}};wI([(0,_3.inject)(Wbn.McpRequestContext),(0,_3.optional)(),Cz("design:type",Object)],kz.prototype,"requestContext",void 0);wI([(0,_3.inject)(NQ.Logger),Cz("design:type",NQ.Logger)],kz.prototype,"logger",void 0);kz=wI([(0,_3.injectable)()],kz);var PYe=class extends kz{static{r(this,"AbstractMcpResourceHandler")}registerResource(n){let s=this.toAnnotations(),u={title:this.title,description:this.description,mimeType:this.mimeType,...s?{annotations:s}:{}};if(typeof this.uri=="string"){let l=this.uri;n.registerResource(this.name,l,u,async(g,v)=>this.requestContext.run(v,async()=>this.toResourceResult(l,await this.execute(()=>this.createResult({})))))}else n.registerResource(this.name,this.buildResourceTemplate(this.uri.template),u,async(l,g,v)=>this.requestContext.run(v,async()=>this.toResourceResult(l.toString(),await this.execute(()=>this.createResult(Xbn(g))))))}registerToolAlternative(n){this.toolAlternativeInputSchema&&this.doRegisterToolAlternative(n)}doRegisterToolAlternative(n){let s=this.toolAlternativeInputSchema;n.registerTool(this.name,{title:this.title,description:this.description,inputSchema:s.strict(),outputSchema:this.toolAlternativeOutputSchema},async(u,l)=>this.requestContext.run(l,async()=>this.toToolResult(await this.execute(()=>this.createResult(u)))))}};ig.AbstractMcpResourceHandler=PYe;ig.AbstractMcpResourceHandler=PYe=wI([(0,_3.injectable)()],PYe);var v9=class extends kz{static{r(this,"AbstractMcpDiagramResourceHandler")}requestAction(n,s,u=this.name){return(0,OYe.requestActionOrFail)(this.actionDispatcher,n,s,u)}canRegister(){return!0}list(){return{resources:[this.toListingEntry()]}}complete(){return this.uriTemplate().includes("{sessionId}")?{sessionId:r(async()=>[this.clientId],"sessionId")}:{}}toListingEntry(){let n=this.toAnnotations();return{uri:this.expandUriTemplate({sessionId:this.clientId}),name:`${this.title??this.name}: ${this.clientId}`,description:this.description,mimeType:this.mimeType,...n?{annotations:n}:{}}}async handleRead(n,s){return this.toResourceResult(n,await this.execute(()=>this.createResult(s)))}async handleAsTool(n){return this.toToolResult(await this.execute(()=>this.createResult(n)))}glspSessionScopedComplete(){let n=this.complete?.()??{},s=this.clientId,u=typeof this.uri=="object"&&this.uri.template.includes("{sessionId}"),l={};for(let[g,v]of Object.entries(n))l[g]=g==="sessionId"||!u?v:async(w,M)=>M?.arguments?.sessionId===s?v(w,M):[];return l}};ig.AbstractMcpDiagramResourceHandler=v9;wI([(0,_3.inject)(NQ.ClientId),Cz("design:type",String)],v9.prototype,"clientId",void 0);wI([(0,_3.inject)(NQ.ModelState),Cz("design:type",Object)],v9.prototype,"modelState",void 0);wI([(0,_3.inject)(MRr.McpIdAliasService),Cz("design:type",Object)],v9.prototype,"aliasService",void 0);wI([(0,_3.inject)(NQ.ActionDispatcher),Cz("design:type",Object)],v9.prototype,"actionDispatcher",void 0);ig.AbstractMcpDiagramResourceHandler=v9=wI([(0,_3.injectable)()],v9);function Xbn(o){let n={};for(let[s,u]of Object.entries(o))n[s]=Array.isArray(u)?u[0]??"":u;return n}r(Xbn,"toParams");ig.McpDiagramResourceHandlerConstructor=Symbol("McpDiagramResourceHandlerConstructor")});var Qye=x(w1=>{"use strict";var w9=w1&&w1.__decorate||function(o,n,s,u){var l=arguments.length,g=l<3?n:u===null?u=Object.getOwnPropertyDescriptor(n,s):u,v;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")g=Reflect.decorate(o,n,s,u);else for(var w=o.length-1;w>=0;w--)(v=o[w])&&(g=(l<3?v(g):l>3?v(n,s,g):v(n,s))||g);return l>3&&g&&Object.defineProperty(n,s,g),g},LQ=w1&&w1.__metadata||function(o,n){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(o,n)};Object.defineProperty(w1,"__esModule",{value:!0});w1.McpDiagramResourceHandlerRegistryInitializer=w1.McpDiagramResourceHandlerRegistry=w1.McpDiagramResourceHandlerFactory=void 0;var xQ=Kr(),Bk=en(),TRr=yI();w1.McpDiagramResourceHandlerFactory=Symbol("McpDiagramResourceHandlerFactory");var qQ=class extends xQ.Registry{static{r(this,"McpDiagramResourceHandlerRegistry")}registerHandler(n){return this.register(n.name,n)}};w1.McpDiagramResourceHandlerRegistry=qQ;w1.McpDiagramResourceHandlerRegistry=qQ=w9([(0,Bk.injectable)()],qQ);var Uk=class{static{r(this,"McpDiagramResourceHandlerRegistryInitializer")}constructor(){this.constructors=[]}initialize(n){let s=this.clientId===xQ.TEMPORARY_CLIENT_ID;for(let u of this.constructors){let l;try{l=this.factory(u)}catch(g){throw new Error(`Failed to instantiate MCP diagram resource handler '${u.name}': ${g.message}. Check your DiagramModule bindings.`)}if(!l.canRegister()){s||this.logger.debug(`Skipping MCP diagram resource handler '${l.name}': canRegister() returned false.`);continue}this.registry.registerHandler(l)}}};w1.McpDiagramResourceHandlerRegistryInitializer=Uk;w9([(0,Bk.inject)(w1.McpDiagramResourceHandlerFactory),LQ("design:type",Function)],Uk.prototype,"factory",void 0);w9([(0,Bk.inject)(TRr.McpDiagramResourceHandlerConstructor),(0,Bk.optional)(),LQ("design:type",Array)],Uk.prototype,"constructors",void 0);w9([(0,Bk.inject)(qQ),LQ("design:type",qQ)],Uk.prototype,"registry",void 0);w9([(0,Bk.inject)(xQ.ClientId),LQ("design:type",String)],Uk.prototype,"clientId",void 0);w9([(0,Bk.inject)(xQ.Logger),LQ("design:type",xQ.Logger)],Uk.prototype,"logger",void 0);w1.McpDiagramResourceHandlerRegistryInitializer=Uk=w9([(0,Bk.injectable)()],Uk)});var e_e=x(y1=>{"use strict";var y9=y1&&y1.__decorate||function(o,n,s,u){var l=arguments.length,g=l<3?n:u===null?u=Object.getOwnPropertyDescriptor(n,s):u,v;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")g=Reflect.decorate(o,n,s,u);else for(var w=o.length-1;w>=0;w--)(v=o[w])&&(g=(l<3?v(g):l>3?v(n,s,g):v(n,s))||g);return l>3&&g&&Object.defineProperty(n,s,g),g},BQ=y1&&y1.__metadata||function(o,n){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(o,n)};Object.defineProperty(y1,"__esModule",{value:!0});y1.McpDiagramToolHandlerRegistryInitializer=y1.McpDiagramToolHandlerRegistry=y1.McpDiagramToolHandlerFactory=void 0;var FQ=Kr(),Gk=en(),IRr=rl();y1.McpDiagramToolHandlerFactory=Symbol("McpDiagramToolHandlerFactory");var zQ=class extends FQ.Registry{static{r(this,"McpDiagramToolHandlerRegistry")}registerHandler(n){return this.register(n.name,n)}};y1.McpDiagramToolHandlerRegistry=zQ;y1.McpDiagramToolHandlerRegistry=zQ=y9([(0,Gk.injectable)()],zQ);var Zk=class{static{r(this,"McpDiagramToolHandlerRegistryInitializer")}constructor(){this.constructors=[]}initialize(n){let s=this.clientId===FQ.TEMPORARY_CLIENT_ID;for(let u of this.constructors){let l;try{l=this.factory(u)}catch(g){throw new Error(`Failed to instantiate MCP diagram tool handler '${u.name}': ${g.message}. Check your DiagramModule bindings.`)}if(!l.canRegister()){s||this.logger.debug(`Skipping MCP diagram tool handler '${l.name}': canRegister() returned false.`);continue}this.registry.registerHandler(l)}}};y1.McpDiagramToolHandlerRegistryInitializer=Zk;y9([(0,Gk.inject)(y1.McpDiagramToolHandlerFactory),BQ("design:type",Function)],Zk.prototype,"factory",void 0);y9([(0,Gk.inject)(IRr.McpDiagramToolHandlerConstructor),(0,Gk.optional)(),BQ("design:type",Array)],Zk.prototype,"constructors",void 0);y9([(0,Gk.inject)(zQ),BQ("design:type",zQ)],Zk.prototype,"registry",void 0);y9([(0,Gk.inject)(FQ.ClientId),BQ("design:type",String)],Zk.prototype,"clientId",void 0);y9([(0,Gk.inject)(FQ.Logger),BQ("design:type",FQ.Logger)],Zk.prototype,"logger",void 0);y1.McpDiagramToolHandlerRegistryInitializer=Zk=y9([(0,Gk.injectable)()],Zk)});var t_e=x(F2=>{"use strict";var Rz=F2&&F2.__decorate||function(o,n,s,u){var l=arguments.length,g=l<3?n:u===null?u=Object.getOwnPropertyDescriptor(n,s):u,v;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")g=Reflect.decorate(o,n,s,u);else for(var w=o.length-1;w>=0;w--)(v=o[w])&&(g=(l<3?v(g):l>3?v(n,s,g):v(n,s))||g);return l>3&&g&&Object.defineProperty(n,s,g),g},UQ=F2&&F2.__metadata||function(o,n){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(o,n)};Object.defineProperty(F2,"__esModule",{value:!0});F2.DefaultMcpDiagramHandlerDispatcher=F2.McpDiagramHandlerDispatcher=void 0;var _9=Kr(),ARr=RQ(),Jk=en(),kRr=Yye(),Ybn=Qye(),CRr=e_e(),Hk=Zd(),RRr=sI(),e0n=iI(),Qbn=yI(),$Rr=rl();F2.McpDiagramHandlerDispatcher=Symbol("McpDiagramHandlerDispatcher");var Kk=class{static{r(this,"DefaultMcpDiagramHandlerDispatcher")}constructor(){this.requestContext=new e0n.NoopMcpRequestContext,this.diagramCatalogs=[]}harvest(){if(this.diagramCatalogs.length>0)return;let n=[],s=(0,_9.createClientSessionModule)({clientId:_9.TEMPORARY_CLIENT_ID,glspClient:{process:r(()=>{},"process")},clientActionKinds:[]});for(let[u,l]of this.diagramModules){let g=this.serverContainer.createChild();g.load(...l,s);let v=jYe(g,$Rr.McpDiagramToolHandlerConstructor),w=jYe(g,Qbn.McpDiagramResourceHandlerConstructor),M=jYe(g,RRr.McpDiagramPromptHandlerConstructor);g.unbindAll(),n.push({diagramType:u,toolConstructors:v,resourceConstructors:w,promptConstructors:M})}this.diagramCatalogs=n}hasDiagramTools(){return this.diagramCatalogs.some(n=>n.toolConstructors.length>0)}hasDiagramResources(){return this.diagramCatalogs.some(n=>n.resourceConstructors.length>0)}hasDiagramPrompts(){return this.diagramCatalogs.some(n=>n.promptConstructors.length>0)}registerAll(n,s){this.registerDiagramScopeTools(n),this.registerDiagramScopeResources(n,s),this.registerDiagramScopePrompts(n)}registerDiagramScopeTools(n){let s=new Map;for(let u of this.diagramCatalogs)for(let l of u.toolConstructors){let g=new l,v={description:g.description,inputKeys:Object.keys(g.inputSchema?.shape??{}).sort().join(","),diagramType:u.diagramType},w=s.get(g.name);if(w){(w.description!==v.description||w.inputKeys!==v.inputKeys)&&this.logger.warn(`Diagram-scope tool '${g.name}' is registered by multiple diagram types with diverging schemas: first registered by '${w.diagramType}', shadowed registration from '${u.diagramType}' is silently dropped. Either align schemas (description + inputSchema.shape keys must match) or pick distinct tool names.`);continue}s.set(g.name,v),n.registerTool(g.name,g.toRegistrationConfig(),(M,A)=>this.requestContext.run(A,()=>this.dispatchDiagramTool(g.name,M)))}}registerDiagramScopeResources(n,s){let u=new Set;for(let l of this.diagramCatalogs)for(let g of l.resourceConstructors){let v=new g;u.has(v.name)||(u.add(v.name),s?this.registerOneDiagramResource(n,v):v.toolAlternativeInputSchema&&this.registerOneDiagramResourceAsTool(n,v))}}registerOneDiagramResource(n,s){let u=s.name,l=s.toAnnotations(),g={title:s.title,description:s.description,mimeType:s.mimeType,...l?{annotations:l}:{}};if(typeof s.uri=="string"){let v=s.uri;n.registerResource(u,v,g,(w,M)=>this.requestContext.run(M,()=>this.dispatchStaticDiagramRead(u,v)))}else{let v=this.buildAggregatingResourceTemplate(s.uri.template,u);n.registerResource(u,v,g,(w,M,A)=>this.requestContext.run(A,()=>this.dispatchTemplatedDiagramRead(u,w,M)))}}registerOneDiagramResourceAsTool(n,s){let u=s.name,l=s.toolAlternativeInputSchema;n.registerTool(u,{title:s.title,description:s.description,inputSchema:l.strict(),outputSchema:s.toolAlternativeOutputSchema},(g,v)=>this.requestContext.run(v,()=>this.dispatchDiagramResourceAsTool(u,g)))}registerDiagramScopePrompts(n){let s=new Set;for(let u of this.diagramCatalogs)for(let l of u.promptConstructors){let g=new l;s.has(g.name)||(s.add(g.name),n.registerPrompt(g.name,g.toRegistrationConfig(),(v,w)=>this.requestContext.run(w,()=>this.dispatchDiagramPrompt(g.name,v))))}}buildAggregatingResourceTemplate(n,s){return new ARr.ResourceTemplate(n,{list:r(u=>this.requestContext.run(u,()=>this.aggregateList(s)),"list"),complete:this.buildAggregatedCompleters(s)})}async aggregateList(n){let s=[],u=new Set;for(let l of this.clientSessionManager.getSessions().map(g=>g.id)){let v=await this.findDiagramResourceHandler(n,l)?.list?.();if(v)for(let w of v.resources)u.has(w.uri)||(u.add(w.uri),s.push(w))}return{resources:s}}buildAggregatedCompleters(n){let s=this.collectCompleterVariableNames(n),u={};for(let l of s)u[l]=async(g,v)=>{let w=new Set;for(let M of this.clientSessionManager.getSessions().map(A=>A.id)){let A=this.findDiagramResourceHandler(n,M);if(!A)continue;let z=A.glspSessionScopedComplete()[l];if(!z)continue;(await z(g,v)).forEach(ie=>w.add(ie))}return[...w]};return u}collectCompleterVariableNames(n){let s=new Set;for(let u of this.diagramCatalogs)for(let l of u.resourceConstructors){let g=new l;g.name===n&&Object.keys(g.complete?.()??{}).forEach(v=>s.add(v))}return s}dispatchDiagramTool(n,s){return(0,Hk.runWithToolErrorEnvelope)(async()=>this.requireDiagramToolHandler(n,s).handle(s))}dispatchStaticDiagramRead(n,s){let u=this.clientSessionManager.getSessions()[0]?.id;if(!u)throw new Hk.McpToolError(`No open GLSP session can serve resource '${n}'.`);return this.requireDiagramResourceHandler(n,u).handleRead(s,{sessionId:u})}dispatchTemplatedDiagramRead(n,s,u){let l=(0,Qbn.toParams)(u);return this.requireDiagramResourceHandler(n,l.sessionId).handleRead(s.toString(),l)}dispatchDiagramResourceAsTool(n,s){return(0,Hk.runWithToolErrorEnvelope)(async()=>this.requireDiagramResourceHandler(n,this.extractSessionId(s)).handleAsTool(s))}dispatchDiagramPrompt(n,s){return this.requireDiagramPromptHandler(n,s).handle(s)}extractSessionId(n){return n.sessionId}requireDiagramToolHandler(n,s){let u=this.requireGlspSession(this.extractSessionId(s)),g=u.container.get(CRr.McpDiagramToolHandlerRegistry).get(n);if(!g)throw new Hk.McpToolError(`No tool handler '${n}' registered for diagram type '${u.diagramType}'.`);return g}requireDiagramResourceHandler(n,s){let u=this.requireGlspSession(s),g=u.container.get(Ybn.McpDiagramResourceHandlerRegistry).get(n);if(!g)throw new Hk.McpToolError(`No resource handler '${n}' registered for diagram type '${u.diagramType}'.`);return g}findDiagramResourceHandler(n,s){let u=this.clientSessionManager.getSession(s);if(u)return u.container.get(Ybn.McpDiagramResourceHandlerRegistry).get(n)}requireDiagramPromptHandler(n,s){let u=this.requireGlspSession(this.extractSessionId(s)),g=u.container.get(kRr.McpDiagramPromptHandlerRegistry).get(n);if(!g)throw new Hk.McpToolError(`No prompt handler '${n}' registered for diagram type '${u.diagramType}'.`);return g}requireGlspSession(n){if(!n)throw new Hk.McpMissingParamError("sessionId");let s=this.clientSessionManager.getSession(n);if(!s)throw new Hk.McpSessionNotFoundError(n);return s}reset(){this.diagramCatalogs=[]}};F2.DefaultMcpDiagramHandlerDispatcher=Kk;Rz([(0,Jk.inject)(e0n.McpRequestContext),(0,Jk.optional)(),UQ("design:type",Object)],Kk.prototype,"requestContext",void 0);Rz([(0,Jk.inject)(_9.InjectionContainer),UQ("design:type",Jk.Container)],Kk.prototype,"serverContainer",void 0);Rz([(0,Jk.inject)(_9.DiagramModules),UQ("design:type",Map)],Kk.prototype,"diagramModules",void 0);Rz([(0,Jk.inject)(_9.ClientSessionManager),UQ("design:type",Object)],Kk.prototype,"clientSessionManager",void 0);Rz([(0,Jk.inject)(_9.Logger),UQ("design:type",_9.Logger)],Kk.prototype,"logger",void 0);F2.DefaultMcpDiagramHandlerDispatcher=Kk=Rz([(0,Jk.injectable)()],Kk);function jYe(o,n){return o.isBound(n)?o.get(n):[]}r(jYe,"getConstructorList")});var GQ=x(S3=>{"use strict";var DRr=S3&&S3.__decorate||function(o,n,s,u){var l=arguments.length,g=l<3?n:u===null?u=Object.getOwnPropertyDescriptor(n,s):u,v;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")g=Reflect.decorate(o,n,s,u);else for(var w=o.length-1;w>=0;w--)(v=o[w])&&(g=(l<3?v(g):l>3?v(n,s,g):v(n,s))||g);return l>3&&g&&Object.defineProperty(n,s,g),g},n_e;Object.defineProperty(S3,"__esModule",{value:!0});S3.DefaultMcpLogLevelRegistry=S3.McpLogLevelRegistry=void 0;S3.passesLogThreshold=xRr;var NRr=en();S3.McpLogLevelRegistry=Symbol("McpLogLevelRegistry");var t0n={emergency:0,alert:1,critical:2,error:3,warning:4,notice:5,info:6,debug:7};function xRr(o,n){return t0n[o]<=t0n[n]}r(xRr,"passesLogThreshold");var MYe=class{static{r(this,"DefaultMcpLogLevelRegistry")}constructor(){this.levels=new Map}static{n_e=this}static{this.DEFAULT_LEVEL="debug"}setLevel(n,s){this.levels.set(n,s)}getLevel(n){return n===void 0?n_e.DEFAULT_LEVEL:this.levels.get(n)??n_e.DEFAULT_LEVEL}clear(n){this.levels.delete(n)}};S3.DefaultMcpLogLevelRegistry=MYe;S3.DefaultMcpLogLevelRegistry=MYe=n_e=DRr([(0,NRr.injectable)()],MYe)});var r_e=x(_I=>{"use strict";var qRr=_I&&_I.__decorate||function(o,n,s,u){var l=arguments.length,g=l<3?n:u===null?u=Object.getOwnPropertyDescriptor(n,s):u,v;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")g=Reflect.decorate(o,n,s,u);else for(var w=o.length-1;w>=0;w--)(v=o[w])&&(g=(l<3?v(g):l>3?v(n,s,g):v(n,s))||g);return l>3&&g&&Object.defineProperty(n,s,g),g};Object.defineProperty(_I,"__esModule",{value:!0});_I.McpServerDefaults=_I.McpServerOptions=void 0;var LRr=en(),TYe=class{static{r(this,"McpServerOptions")}constructor(){this.values={}}};_I.McpServerOptions=TYe;_I.McpServerOptions=TYe=qRr([(0,LRr.injectable)()],TYe);_I.McpServerDefaults=Symbol("McpServerDefaults")});var o_e=x(zv=>{"use strict";var z2=zv&&zv.__decorate||function(o,n,s,u){var l=arguments.length,g=l<3?n:u===null?u=Object.getOwnPropertyDescriptor(n,s):u,v;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")g=Reflect.decorate(o,n,s,u);else for(var w=o.length-1;w>=0;w--)(v=o[w])&&(g=(l<3?v(g):l>3?v(n,s,g):v(n,s))||g);return l>3&&g&&Object.defineProperty(n,s,g),g},O3=zv&&zv.__metadata||function(o,n){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(o,n)};Object.defineProperty(zv,"__esModule",{value:!0});zv.AbstractMcpServerLauncher=zv.SERVER_VERSION=void 0;zv.pickInitOptions=n0n;var E3=Kr(),FRr=RQ(),zRr=Kbn(),i_e=Tk(),o0=en(),BRr=Vbn(),URr=Vye(),GRr=Xye(),ZRr=t_e(),HRr=GQ(),IYe=r_e(),JRr=sI(),KRr=yI(),VRr=rl();zv.SERVER_VERSION=BRr.version;function n0n(o){let{dataMode:n,agentPersona:s,eventStoreLimit:u}=o,l={};return n!==void 0&&(l.dataMode=n),s!==void 0&&(l.agentPersona=s),u!==void 0&&(l.eventStoreLimit=u),l}r(n0n,"pickInitOptions");var WRr=null,Fv=class{static{r(this,"AbstractMcpServerLauncher")}constructor(){this.toolHandlers=[],this.resourceHandlers=[],this.promptHandlers=[],this.toDispose=new E3.DisposableCollection,this.sessions=new Map,this.sessionServers=new Map,this.onSessionInitializedEmitter=new E3.Emitter,this.onSessionInitialized=this.onSessionInitializedEmitter.event,this.onSessionClosedEmitter=new E3.Emitter,this.onSessionClosed=this.onSessionClosedEmitter.event}async initializeServer(n,s,u){let l=E3.McpInitializeParameters.getServerConfig(s);if(!l)return u;if(this.serverConfig)return this.serverUrl?E3.McpInitializeResult.attachServer(u,{name:this.serverConfig.name,url:this.serverUrl}):u;let{port:g=0,route:v="/mcp",name:w="glsp",options:M={}}=l,A={...this.mcpDefaults,...n0n(M)};this.mcpOptions.values=A;let R=A.host??"127.0.0.1",z={port:g,host:R,route:v,name:w,options:A};this.dispatcher.harvest(),this.installResourceListChangedNotifier();let K=await this.bindTransport(z);return this.serverConfig=z,this.serverUrl=K.url,this.logger.info(`MCP server '${z.name}' is ready to accept new client requests on: ${this.serverUrl??"(no network endpoint)"}`),K.url?E3.McpInitializeResult.attachServer(u,{name:z.name,url:K.url,headers:K.headers}):u}serverShutDown(n){this.dispose()}dispose(){let n=Array.from(this.sessions.values()).map(s=>s.close().catch(u=>this.logger.warn(`Error closing MCP session ${s.sessionId}: ${u}`)));this.sessions.clear(),this.sessionServers.forEach(s=>s.dispose()),this.sessionServers.clear(),Promise.allSettled(n).then(()=>{this.toDispose.dispose(),this.toDispose.clear()}),this.serverUrl=void 0,this.serverConfig=void 0,this.dispatcher.reset()}async handleRequest(n,s){let u=new URL(n.url),l=this.serverConfig?.route??"/mcp";if(u.pathname!==l)return new Response("Not Found",{status:404});if(n.method!=="POST"&&n.method!=="GET"&&n.method!=="DELETE")return new Response("Method Not Allowed",{status:405,headers:{Allow:"POST, GET, DELETE"}});let g=this.validateHostHeader(n);if(g)return g;let v;n.method==="POST"&&(v=await n.clone().json().catch(()=>{}));let w=n.method==="POST"&&(0,i_e.isInitializeRequest)(v),M=this.validateProtocolVersionHeader(n,w);if(M)return M;let A=this.resolveTransport(n,w);if(A instanceof Response)return A;try{return await A.handleRequest(n,{parsedBody:v,authInfo:s?.authInfo})}catch(R){let z=R instanceof Error?R.message:String(R);return this.logger.error("Error handling MCP request:",R),this.jsonRpcErrorResponse(500,-32603,`Internal server error: ${z}`)}}getRequestHandler(){return(n,s)=>this.handleRequest(n,s)}resolveTransport(n,s){let u=n.headers.get("mcp-session-id")??void 0;if(s&&!u)return this.createTransport();if(!u)return this.jsonRpcErrorResponse(400,-32e3,"Bad Request: No valid session ID provided");let l=this.sessions.get(u);return l||this.jsonRpcErrorResponse(404,-32001,"Session not found")}validateProtocolVersionHeader(n,s){if(s)return;let u=n.headers.get("mcp-protocol-version")??void 0;if(u!==void 0&&!i_e.SUPPORTED_PROTOCOL_VERSIONS.includes(u))return this.jsonRpcErrorResponse(400,-32e3,`Unsupported MCP-Protocol-Version: '${u}'. Supported versions: ${i_e.SUPPORTED_PROTOCOL_VERSIONS.join(", ")}.`)}validateHostHeader(n){let s=this.mcpOptions.values.allowedHosts;if(!s||s.length===0)return;let u=n.headers.get("host");if(!u)return this.jsonRpcErrorResponse(403,-32e3,"Missing Host header");let l;try{l=new URL(`http://${u}`).hostname}catch{return this.jsonRpcErrorResponse(403,-32e3,`Invalid Host header: ${u}`)}if(!s.includes(l))return this.jsonRpcErrorResponse(403,-32e3,`Invalid Host: ${l}`)}createTransport(){let n=this.mcpOptions.values.allowedOrigins,s=new zRr.WebStandardStreamableHTTPServerTransport({sessionIdGenerator:r(()=>globalThis.crypto.randomUUID(),"sessionIdGenerator"),eventStore:new GRr.LruEventStore(this.mcpOptions.values.eventStoreLimit,this.logger),allowedOrigins:n,enableDnsRebindingProtection:(n?.length??0)>0,onsessioninitialized:r(u=>{this.logger.info(`MCP session initialized with ID: ${u}`),this.sessions.set(u,s),this.serverConfig&&this.attachServerToSession(s,this.serverConfig),this.onSessionInitializedEmitter.fire(s)},"onsessioninitialized"),onsessionclosed:r(u=>this.closeSession(u),"onsessionclosed")});return s.onclose=()=>this.closeSession(s.sessionId),s.onerror=u=>this.logger.error(`MCP transport error (session ${s.sessionId??"<pre-init>"}):`,u),s}attachServerToSession(n,s){let u=n.sessionId;if(!u)return;let l=this.createGlspMcpServer(s);this.sessionServers.set(u,l),this.registerLogLevelHandler(l,u),l.connect(n)}closeSession(n){if(!n)return;let s=this.sessions.delete(n),u=this.sessionServers.get(n);u&&(this.sessionServers.delete(n),this.logLevelRegistry.clear(n),u.dispose()),s&&(this.logger.info(`MCP session closed: ${n}`),this.onSessionClosedEmitter.fire(n))}installResourceListChangedNotifier(){if(!this.dispatcher.hasDiagramResources())return;let n={sessionCreated:r(()=>this.broadcastResourceListChanged(),"sessionCreated"),sessionDisposed:r(()=>this.broadcastResourceListChanged(),"sessionDisposed")};this.clientSessionManager.addListener(n),this.toDispose.push(E3.Disposable.create(()=>this.clientSessionManager.removeListener(n)))}broadcastResourceListChanged(){for(let n of this.sessionServers.values())n.getRawServer().server.sendResourceListChanged().catch(s=>this.logger.debug("sendResourceListChanged failed:",s))}registerLogLevelHandler(n,s){n.getRawServer().server.setRequestHandler(i_e.SetLevelRequestSchema,async u=>(this.logLevelRegistry.setLevel(s,u.params.level),{}))}createGlspMcpServer({name:n,options:s}){let u=s.dataMode==="resources",l=new FRr.McpServer({name:n,version:zv.SERVER_VERSION},{capabilities:this.buildCapabilities(u),instructions:s.agentPersona}),g=this.glspMcpServerFactory(l,s);return this.registerHandlers(g,u),g}buildCapabilities(n){let s=this.toolHandlers.length>0,u=this.promptHandlers.length>0,l=this.resourceHandlers.length>0,g=this.dispatcher.hasDiagramTools(),v=this.dispatcher.hasDiagramPrompts(),w=this.dispatcher.hasDiagramResources(),M=l||w;return{logging:{},...s||g||!n&&M?{tools:{listChanged:!1}}:{},...n&&M?{resources:{listChanged:w}}:{},...u||v?{prompts:{listChanged:!1}}:{}}}registerHandlers(n,s){this.toolHandlers.forEach(u=>u.registerTool(n)),this.promptHandlers.forEach(u=>u.registerPrompt(n)),s?this.resourceHandlers.forEach(u=>u.registerResource(n)):this.resourceHandlers.forEach(u=>u.registerToolAlternative?.(n)),this.dispatcher.registerAll(n,s),this.validatePromptToolReferences(n)}validatePromptToolReferences(n){for(let s of this.promptHandlers){let u=s.referencedToolNames().filter(l=>!n.hasTool(l));u.length>0&&this.logger.warn(`Prompt '${s.name}' references unbound tool(s): ${u.join(", ")}. The prompt will still register but its text points at tools the LLM cannot invoke.`)}}jsonRpcErrorResponse(n,s,u){return new Response(JSON.stringify({jsonrpc:"2.0",error:{code:s,message:u},id:WRr}),{status:n,headers:{"Content-Type":"application/json"}})}};zv.AbstractMcpServerLauncher=Fv;z2([(0,o0.inject)(E3.Logger),O3("design:type",E3.Logger)],Fv.prototype,"logger",void 0);z2([(0,o0.inject)(IYe.McpServerOptions),O3("design:type",IYe.McpServerOptions)],Fv.prototype,"mcpOptions",void 0);z2([(0,o0.inject)(IYe.McpServerDefaults),O3("design:type",Object)],Fv.prototype,"mcpDefaults",void 0);z2([(0,o0.inject)(URr.GLSPMcpServerFactory),O3("design:type",Function)],Fv.prototype,"glspMcpServerFactory",void 0);z2([(0,o0.inject)(ZRr.McpDiagramHandlerDispatcher),O3("design:type",Object)],Fv.prototype,"dispatcher",void 0);z2([(0,o0.inject)(HRr.McpLogLevelRegistry),O3("design:type",Object)],Fv.prototype,"logLevelRegistry",void 0);z2([(0,o0.inject)(E3.ClientSessionManager),O3("design:type",Object)],Fv.prototype,"clientSessionManager",void 0);z2([(0,o0.multiInject)(VRr.McpToolHandler),(0,o0.optional)(),O3("design:type",Array)],Fv.prototype,"toolHandlers",void 0);z2([(0,o0.multiInject)(KRr.McpResourceHandler),(0,o0.optional)(),O3("design:type",Array)],Fv.prototype,"resourceHandlers",void 0);z2([(0,o0.multiInject)(JRr.McpPromptHandler),(0,o0.optional)(),O3("design:type",Array)],Fv.prototype,"promptHandlers",void 0);zv.AbstractMcpServerLauncher=Fv=z2([(0,o0.injectable)()],Fv)});var a_e=x(SI=>{"use strict";var s_e=SI&&SI.__decorate||function(o,n,s,u){var l=arguments.length,g=l<3?n:u===null?u=Object.getOwnPropertyDescriptor(n,s):u,v;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")g=Reflect.decorate(o,n,s,u);else for(var w=o.length-1;w>=0;w--)(v=o[w])&&(g=(l<3?v(g):l>3?v(n,s,g):v(n,s))||g);return l>3&&g&&Object.defineProperty(n,s,g),g},AYe=SI&&SI.__metadata||function(o,n){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(o,n)};Object.defineProperty(SI,"__esModule",{value:!0});SI.McpLogger=void 0;var r0n=Kr(),ZQ=en(),i0n=GQ(),o0n=iI(),$z=class{static{r(this,"McpLogger")}constructor(){this.requestContext=new o0n.NoopMcpRequestContext}info(n,...s){this.glspLogger.info(n,...s),this.notify("info",n)}warn(n,...s){this.glspLogger.warn(n,...s),this.notify("warning",n)}error(n,...s){this.glspLogger.error(n,...s),this.notify("error",n)}debug(n,...s){this.glspLogger.debug(n,...s),this.notify("debug",n)}notify(n,s){let u=this.requestContext.getStore();if(!u)return;let l=this.levelRegistry.getLevel(u.sessionId);(0,i0n.passesLogThreshold)(n,l)&&u.sendNotification({method:"notifications/message",params:{level:n,data:s}}).catch(()=>{})}};SI.McpLogger=$z;s_e([(0,ZQ.inject)(o0n.McpRequestContext),(0,ZQ.optional)(),AYe("design:type",Object)],$z.prototype,"requestContext",void 0);s_e([(0,ZQ.inject)(r0n.Logger),AYe("design:type",r0n.Logger)],$z.prototype,"glspLogger",void 0);s_e([(0,ZQ.inject)(i0n.McpLogLevelRegistry),AYe("design:type",Object)],$z.prototype,"levelRegistry",void 0);SI.McpLogger=$z=s_e([(0,ZQ.injectable)()],$z)});var HQ=x(EI=>{"use strict";var s0n=EI&&EI.__decorate||function(o,n,s,u){var l=arguments.length,g=l<3?n:u===null?u=Object.getOwnPropertyDescriptor(n,s):u,v;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")g=Reflect.decorate(o,n,s,u);else for(var w=o.length-1;w>=0;w--)(v=o[w])&&(g=(l<3?v(g):l>3?v(n,s,g):v(n,s))||g);return l>3&&g&&Object.defineProperty(n,s,g),g},XRr=EI&&EI.__metadata||function(o,n){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(o,n)};Object.defineProperty(EI,"__esModule",{value:!0});EI.McpProgressReporter=void 0;var kYe=en(),a0n=iI(),c_e=class{static{r(this,"McpProgressReporter")}constructor(){this.requestContext=new a0n.NoopMcpRequestContext}async emit(n){let s=this.requestContext.getStore(),u=s?._meta?.progressToken;if(!(s===void 0||u===void 0))try{await s.sendNotification({method:"notifications/progress",params:{progressToken:u,...n}})}catch{}}};EI.McpProgressReporter=c_e;s0n([(0,kYe.inject)(a0n.McpRequestContext),(0,kYe.optional)(),XRr("design:type",Object)],c_e.prototype,"requestContext",void 0);EI.McpProgressReporter=c_e=s0n([(0,kYe.injectable)()],c_e)});var $Ye=x(vp=>{"use strict";var c0n=vp&&vp.__decorate||function(o,n,s,u){var l=arguments.length,g=l<3?n:u===null?u=Object.getOwnPropertyDescriptor(n,s):u,v;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")g=Reflect.decorate(o,n,s,u);else for(var w=o.length-1;w>=0;w--)(v=o[w])&&(g=(l<3?v(g):l>3?v(n,s,g):v(n,s))||g);return l>3&&g&&Object.defineProperty(n,s,g),g},YRr=vp&&vp.__metadata||function(o,n){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(o,n)},CYe;Object.defineProperty(vp,"__esModule",{value:!0});vp.SessionInfoMcpToolHandler=vp.SessionInfoOutputSchema=vp.SessionInfoRowSchema=vp.SessionInfoInputSchema=void 0;var RYe=Kr(),u0n=en(),P3=tl(),QRr=Zd(),e$r=rl();vp.SessionInfoInputSchema=P3.object({sessionId:P3.string().optional().describe("Optional filter \u2014 returns only the matching session, or throws if unknown. Omit to list all sessions.")});vp.SessionInfoRowSchema=P3.object({sessionId:P3.string(),diagramType:P3.string(),sourceUri:P3.string(),readOnly:P3.boolean(),dirty:P3.boolean().describe("True when the diagram has unsaved changes \u2014 call `save-model` to persist.")});vp.SessionInfoOutputSchema=P3.object({sessions:P3.array(vp.SessionInfoRowSchema)});var u_e=class extends e$r.AbstractMcpToolHandler{static{r(this,"SessionInfoMcpToolHandler")}constructor(){super(...arguments),this.name=CYe.NAME,this.title="GLSP Session Info",this.description="Report info on the active GLSP client sessions: session id, diagram type, source uri, and read-only status. Pass `sessionId` to retrieve a single session's entry; omit it to list every active session. Useful as a discovery tool \u2014 most other diagram-scoped tools take the `sessionId` returned here.",this.inputSchema=vp.SessionInfoInputSchema,this.outputSchema=vp.SessionInfoOutputSchema}static{CYe=this}static{this.NAME="session-info"}createResult({sessionId:n}){let u=(n!==void 0?this.singleSession(n):this.clientSessionManager.getSessions()).map(l=>this.buildSessionRow(l));return this.success(this.summarizeSessions(u),{sessions:u})}buildSessionRow(n){let s=n.container.get(RYe.ModelState),u=n.container.get(RYe.CommandStack);return{sessionId:n.id,diagramType:n.diagramType,sourceUri:s.sourceUri??"",readOnly:s.isReadonly,dirty:u.isDirty}}summarizeSessions(n){if(n.length===0)return"No active sessions.";let s=n.map(u=>{let l=[u.readOnly?"read-only":void 0,u.dirty?"dirty":void 0].filter(Boolean),g=l.length>0?`, ${l.join(", ")}`:"";return`- ${u.sessionId} (${u.diagramType}${g})`});return`${n.length} session(s); full details in structuredContent.
|
|
246
|
+
`,n.enqueue(s.encode(g)),!0}catch(g){return this.onerror?.(g),!1}}handleUnsupportedRequest(){return this.onerror?.(new Error("Method not allowed.")),new Response(JSON.stringify({jsonrpc:"2.0",error:{code:-32e3,message:"Method not allowed."},id:null}),{status:405,headers:{Allow:"GET, POST, DELETE","Content-Type":"application/json"}})}async handlePostRequest(n,s){try{let u=n.headers.get("accept");if(!u?.includes("application/json")||!u.includes("text/event-stream"))return this.onerror?.(new Error("Not Acceptable: Client must accept both application/json and text/event-stream")),this.createJsonErrorResponse(406,-32e3,"Not Acceptable: Client must accept both application/json and text/event-stream");let l=n.headers.get("content-type");if(!l||!l.includes("application/json"))return this.onerror?.(new Error("Unsupported Media Type: Content-Type must be application/json")),this.createJsonErrorResponse(415,-32e3,"Unsupported Media Type: Content-Type must be application/json");let g={headers:Object.fromEntries(n.headers.entries()),url:new URL(n.url)},v;if(s?.parsedBody!==void 0)v=s.parsedBody;else try{v=await n.json()}catch{return this.onerror?.(new Error("Parse error: Invalid JSON")),this.createJsonErrorResponse(400,-32700,"Parse error: Invalid JSON")}let w;try{Array.isArray(v)?w=v.map(xe=>bp.JSONRPCMessageSchema.parse(xe)):w=[bp.JSONRPCMessageSchema.parse(v)]}catch{return this.onerror?.(new Error("Parse error: Invalid JSON-RPC message")),this.createJsonErrorResponse(400,-32700,"Parse error: Invalid JSON-RPC message")}let M=w.some(bp.isInitializeRequest);if(M){if(this._initialized&&this.sessionId!==void 0)return this.onerror?.(new Error("Invalid Request: Server already initialized")),this.createJsonErrorResponse(400,-32600,"Invalid Request: Server already initialized");if(w.length>1)return this.onerror?.(new Error("Invalid Request: Only one initialization request is allowed")),this.createJsonErrorResponse(400,-32600,"Invalid Request: Only one initialization request is allowed");this.sessionId=this.sessionIdGenerator?.(),this._initialized=!0,this.sessionId&&this._onsessioninitialized&&await Promise.resolve(this._onsessioninitialized(this.sessionId))}if(!M){let xe=this.validateSession(n);if(xe)return xe;let Ye=this.validateProtocolVersion(n);if(Ye)return Ye}if(!w.some(bp.isJSONRPCRequest)){for(let xe of w)this.onmessage?.(xe,{authInfo:s?.authInfo,requestInfo:g});return new Response(null,{status:202})}let R=crypto.randomUUID(),z=w.find(xe=>(0,bp.isInitializeRequest)(xe)),K=z?z.params.protocolVersion:n.headers.get("mcp-protocol-version")??bp.DEFAULT_NEGOTIATED_PROTOCOL_VERSION;if(this._enableJsonResponse)return new Promise(xe=>{this._streamMapping.set(R,{resolveJson:xe,cleanup:r(()=>{this._streamMapping.delete(R)},"cleanup")});for(let Ye of w)(0,bp.isJSONRPCRequest)(Ye)&&this._requestToStreamMapping.set(Ye.id,R);for(let Ye of w)this.onmessage?.(Ye,{authInfo:s?.authInfo,requestInfo:g})});let ie=new TextEncoder,ne,me=new ReadableStream({start:r(xe=>{ne=xe},"start"),cancel:r(()=>{this._streamMapping.delete(R)},"cancel")}),ke={"Content-Type":"text/event-stream","Cache-Control":"no-cache",Connection:"keep-alive"};this.sessionId!==void 0&&(ke["mcp-session-id"]=this.sessionId);for(let xe of w)(0,bp.isJSONRPCRequest)(xe)&&(this._streamMapping.set(R,{controller:ne,encoder:ie,cleanup:r(()=>{this._streamMapping.delete(R);try{ne.close()}catch{}},"cleanup")}),this._requestToStreamMapping.set(xe.id,R));await this.writePrimingEvent(ne,ie,R,K);for(let xe of w){let Ye,Ke;(0,bp.isJSONRPCRequest)(xe)&&this._eventStore&&K>="2025-11-25"&&(Ye=r(()=>{this.closeSSEStream(xe.id)},"closeSSEStream"),Ke=r(()=>{this.closeStandaloneSSEStream()},"closeStandaloneSSEStream")),this.onmessage?.(xe,{authInfo:s?.authInfo,requestInfo:g,closeSSEStream:Ye,closeStandaloneSSEStream:Ke})}return new Response(me,{status:200,headers:ke})}catch(u){return this.onerror?.(u),this.createJsonErrorResponse(400,-32700,"Parse error",{data:String(u)})}}async handleDeleteRequest(n){let s=this.validateSession(n);if(s)return s;let u=this.validateProtocolVersion(n);return u||(await Promise.resolve(this._onsessionclosed?.(this.sessionId)),await this.close(),new Response(null,{status:200}))}validateSession(n){if(this.sessionIdGenerator===void 0)return;if(!this._initialized)return this.onerror?.(new Error("Bad Request: Server not initialized")),this.createJsonErrorResponse(400,-32e3,"Bad Request: Server not initialized");let s=n.headers.get("mcp-session-id");if(!s)return this.onerror?.(new Error("Bad Request: Mcp-Session-Id header is required")),this.createJsonErrorResponse(400,-32e3,"Bad Request: Mcp-Session-Id header is required");if(s!==this.sessionId)return this.onerror?.(new Error("Session not found")),this.createJsonErrorResponse(404,-32001,"Session not found")}validateProtocolVersion(n){let s=n.headers.get("mcp-protocol-version");if(s!==null&&!bp.SUPPORTED_PROTOCOL_VERSIONS.includes(s))return this.onerror?.(new Error(`Bad Request: Unsupported protocol version: ${s} (supported versions: ${bp.SUPPORTED_PROTOCOL_VERSIONS.join(", ")})`)),this.createJsonErrorResponse(400,-32e3,`Bad Request: Unsupported protocol version: ${s} (supported versions: ${bp.SUPPORTED_PROTOCOL_VERSIONS.join(", ")})`)}async close(){this._streamMapping.forEach(({cleanup:n})=>{n()}),this._streamMapping.clear(),this._requestResponseMap.clear(),this.onclose?.()}closeSSEStream(n){let s=this._requestToStreamMapping.get(n);if(!s)return;let u=this._streamMapping.get(s);u&&u.cleanup()}closeStandaloneSSEStream(){let n=this._streamMapping.get(this._standaloneSseStreamId);n&&n.cleanup()}async send(n,s){let u=s?.relatedRequestId;if(((0,bp.isJSONRPCResultResponse)(n)||(0,bp.isJSONRPCErrorResponse)(n))&&(u=n.id),u===void 0){if((0,bp.isJSONRPCResultResponse)(n)||(0,bp.isJSONRPCErrorResponse)(n))throw new Error("Cannot send a response on a standalone SSE stream unless resuming a previous client request");let v;this._eventStore&&(v=await this._eventStore.storeEvent(this._standaloneSseStreamId,n));let w=this._streamMapping.get(this._standaloneSseStreamId);if(w===void 0)return;w.controller&&w.encoder&&this.writeSSEEvent(w.controller,w.encoder,n,v);return}let l=this._requestToStreamMapping.get(u);if(!l)throw new Error(`No connection established for request ID: ${String(u)}`);let g=this._streamMapping.get(l);if(!this._enableJsonResponse&&g?.controller&&g?.encoder){let v;this._eventStore&&(v=await this._eventStore.storeEvent(l,n)),this.writeSSEEvent(g.controller,g.encoder,n,v)}if((0,bp.isJSONRPCResultResponse)(n)||(0,bp.isJSONRPCErrorResponse)(n)){this._requestResponseMap.set(u,n);let v=Array.from(this._requestToStreamMapping.entries()).filter(([M,A])=>A===l).map(([M])=>M);if(v.every(M=>this._requestResponseMap.has(M))){if(!g)throw new Error(`No connection established for request ID: ${String(u)}`);if(this._enableJsonResponse&&g.resolveJson){let M={"Content-Type":"application/json"};this.sessionId!==void 0&&(M["mcp-session-id"]=this.sessionId);let A=v.map(R=>this._requestResponseMap.get(R));A.length===1?g.resolveJson(new Response(JSON.stringify(A[0]),{status:200,headers:M})):g.resolveJson(new Response(JSON.stringify(A),{status:200,headers:M}))}else g.cleanup();for(let M of v)this._requestResponseMap.delete(M),this._requestToStreamMapping.delete(M)}}}};Jye.WebStandardStreamableHTTPServerTransport=vYe});var Vbn=x((p6i,bRr)=>{bRr.exports={name:"@eclipse-glsp/server-mcp",version:"2.8.0-next.7",description:"Model Context Protocol (MCP) server for the GLSP TypeScript server \u2014 runs on Node, browser, and Fetch-API runtimes",keywords:["eclipse","graphics","diagram","modeling","visualization","glsp","diagram editor","mcp"],homepage:"https://www.eclipse.org/glsp/",bugs:"https://github.com/eclipse-glsp/glsp/issues",repository:{type:"git",url:"https://github.com/eclipse-glsp/glsp-server-node.git"},license:"(EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0)",author:{name:"Eclipse GLSP"},contributors:[{name:"Eclipse GLSP Project",email:"glsp-dev@eclipse.org",url:"https://projects.eclipse.org/projects/ecd.glsp"}],main:"lib/node/index",browser:{"lib/node/index":"./lib/browser/index"},types:"lib/common/index",files:["lib","src","node.js","node.d.ts","browser.js","browser.d.ts","common.js","common.d.ts","!**/*.spec.ts","!**/*.spec.tsx","!**/test/**"],scripts:{build:"tsc -b",clean:"rimraf lib *.tsbuildinfo coverage","generate:index":"glsp generateIndex src/browser src/common src/node -f -s",lint:"eslint --ext .ts,.tsx ./src",prepublishOnly:"pnpm build"},dependencies:{"@eclipse-glsp/server":"workspace:*","@hono/node-server":"^1.19.9","@modelcontextprotocol/sdk":"^1.29.0",zod:"^4.0.0"},peerDependencies:{inversify:"^6.1.3","reflect-metadata":"^0.2.2"},publishConfig:{access:"public"}}});var Vye=x(b1=>{"use strict";var vRr=b1&&b1.__decorate||function(o,n,s,u){var l=arguments.length,g=l<3?n:u===null?u=Object.getOwnPropertyDescriptor(n,s):u,v;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")g=Reflect.decorate(o,n,s,u);else for(var w=o.length-1;w>=0;w--)(v=o[w])&&(g=(l<3?v(g):l>3?v(n,s,g):v(n,s))||g);return l>3&&g&&Object.defineProperty(n,s,g),g},wRr=b1&&b1.__metadata||function(o,n){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(o,n)},wYe=b1&&b1.__param||function(o,n){return function(s,u){n(s,u,o)}};Object.defineProperty(b1,"__esModule",{value:!0});b1.DefaultGLSPMcpServer=b1.GLSPMcpServerFactory=b1.GLSPMcpServer=void 0;var yRr=Kr(),_Rr=RQ(),yYe=Tk(),Kye=en();b1.GLSPMcpServer=Symbol("GLSPMcpServer");var SRr=3e4,ERr=5e3;b1.GLSPMcpServerFactory=Symbol("GLSPMcpServerFactory");var _Ye=class{static{r(this,"DefaultGLSPMcpServer")}constructor(n,s,u){this.mcpServer=n,this.options=s,this.logger=u,this.tools=new Map,this.resources=new Map,this.prompts=new Map;let{tools:l,resources:g,prompts:v}=this;this.registerTool=new Proxy(n.registerTool.bind(n),{apply(w,M,A){let R=Reflect.apply(w,M,A);return typeof A[0]=="string"&&l.set(A[0],R),R}}),this.registerResource=new Proxy(n.registerResource.bind(n),{apply(w,M,A){let R=Reflect.apply(w,M,A);return typeof A[0]=="string"&&g.set(A[0],R),R}}),this.registerPrompt=new Proxy(n.registerPrompt.bind(n),{apply(w,M,A){let R=Reflect.apply(w,M,A);return typeof A[0]=="string"&&v.set(A[0],R),R}})}sendLoggingMessage(...n){return this.mcpServer.sendLoggingMessage(...n)}async connect(...n){await this.mcpServer.connect(...n),this.keepAliveTimer=setInterval(()=>this.ping().catch(u=>{(!(u instanceof yYe.McpError)||u.code!==yYe.ErrorCode.RequestTimeout)&&this.logger.debug("MCP keep-alive ping failed:",u)}),SRr);let s=this.keepAliveTimer.unref;typeof s=="function"&&s.call(this.keepAliveTimer)}isConnected(){return this.mcpServer.isConnected()}async ping(){await this.mcpServer.server.request({method:"ping"},yYe.EmptyResultSchema,{timeout:ERr})}listTools(){return[...this.tools.values()]}hasTool(n){return this.tools.has(n)}listResources(){return[...this.resources.values()]}listPrompts(){return[...this.prompts.values()]}getRawServer(){return this.mcpServer}dispose(){this.keepAliveTimer&&(clearInterval(this.keepAliveTimer),this.keepAliveTimer=void 0),this.mcpServer.close()}};b1.DefaultGLSPMcpServer=_Ye;b1.DefaultGLSPMcpServer=_Ye=vRr([(0,Kye.injectable)(),wYe(0,(0,Kye.unmanaged)()),wYe(1,(0,Kye.unmanaged)()),wYe(2,(0,Kye.unmanaged)()),wRr("design:paramtypes",[_Rr.McpServer,Object,yRr.Logger])],_Ye)});var Xye=x(Wye=>{"use strict";Object.defineProperty(Wye,"__esModule",{value:!0});Wye.LruEventStore=void 0;var SYe=class o{static{r(this,"LruEventStore")}static{this.DEFAULT_LIMIT=1e4}constructor(n=o.DEFAULT_LIMIT,s){if(this.events=new Map,n<1)throw new Error(`LruEventStore limit must be >= 1, got ${n}`);this.limit=n,this.logger=s}get size(){return this.events.size}async storeEvent(n,s){let u=`${n}_${Date.now()}_${Math.random().toString(36).substring(2,10)}`;if(this.events.set(u,{streamId:n,message:s}),this.events.size>this.limit){let l=this.events.keys().next().value;l!==void 0&&this.events.delete(l)}return u}async replayEventsAfter(n,{send:s}){if(!n)return"";if(!this.events.has(n))return this.logger?.warn(`[LruEventStore] Replay miss for last-event-id '${n}'. Cap is ${this.limit}; consider increasing \`eventStoreLimit\` if this fires under normal load.`),"";let u=n.split("_")[0];if(!u)return"";let l=!1;for(let[g,{streamId:v,message:w}]of this.events)if(v===u){if(g===n){l=!0;continue}l&&await s(g,w)}return u}};Wye.LruEventStore=SYe});var Yye=x(v1=>{"use strict";var DQ=v1&&v1.__decorate||function(o,n,s,u){var l=arguments.length,g=l<3?n:u===null?u=Object.getOwnPropertyDescriptor(n,s):u,v;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")g=Reflect.decorate(o,n,s,u);else for(var w=o.length-1;w>=0;w--)(v=o[w])&&(g=(l<3?v(g):l>3?v(n,s,g):v(n,s))||g);return l>3&&g&&Object.defineProperty(n,s,g),g},EYe=v1&&v1.__metadata||function(o,n){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(o,n)};Object.defineProperty(v1,"__esModule",{value:!0});v1.McpDiagramPromptHandlerRegistryInitializer=v1.McpDiagramPromptHandlerRegistry=v1.McpDiagramPromptHandlerFactory=void 0;var ORr=Kr(),Iz=en(),PRr=sI();v1.McpDiagramPromptHandlerFactory=Symbol("McpDiagramPromptHandlerFactory");var $Q=class extends ORr.Registry{static{r(this,"McpDiagramPromptHandlerRegistry")}registerHandler(n){return this.register(n.name,n)}};v1.McpDiagramPromptHandlerRegistry=$Q;v1.McpDiagramPromptHandlerRegistry=$Q=DQ([(0,Iz.injectable)()],$Q);var Az=class{static{r(this,"McpDiagramPromptHandlerRegistryInitializer")}constructor(){this.constructors=[]}initialize(n){for(let s of this.constructors)try{this.registry.registerHandler(this.factory(s))}catch(u){throw new Error(`Failed to instantiate MCP diagram prompt handler '${s.name}': ${u.message}. Check your DiagramModule bindings.`)}}};v1.McpDiagramPromptHandlerRegistryInitializer=Az;DQ([(0,Iz.inject)(v1.McpDiagramPromptHandlerFactory),EYe("design:type",Function)],Az.prototype,"factory",void 0);DQ([(0,Iz.inject)(PRr.McpDiagramPromptHandlerConstructor),(0,Iz.optional)(),EYe("design:type",Array)],Az.prototype,"constructors",void 0);DQ([(0,Iz.inject)($Q),EYe("design:type",$Q)],Az.prototype,"registry",void 0);v1.McpDiagramPromptHandlerRegistryInitializer=Az=DQ([(0,Iz.injectable)()],Az)});var yI=x(ig=>{"use strict";var wI=ig&&ig.__decorate||function(o,n,s,u){var l=arguments.length,g=l<3?n:u===null?u=Object.getOwnPropertyDescriptor(n,s):u,v;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")g=Reflect.decorate(o,n,s,u);else for(var w=o.length-1;w>=0;w--)(v=o[w])&&(g=(l<3?v(g):l>3?v(n,s,g):v(n,s))||g);return l>3&&g&&Object.defineProperty(n,s,g),g},Cz=ig&&ig.__metadata||function(o,n){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(o,n)};Object.defineProperty(ig,"__esModule",{value:!0});ig.McpDiagramResourceHandlerConstructor=ig.AbstractMcpDiagramResourceHandler=ig.AbstractMcpResourceHandler=ig.McpResourceHandler=void 0;ig.toParams=Xbn;var NQ=Kr(),jRr=RQ(),_3=en(),OYe=Zd(),MRr=NN(),Wbn=iI();ig.McpResourceHandler=Symbol("McpResourceHandler");var kz=class{static{r(this,"BaseMcpResourceHandler")}constructor(){this.requestContext=new Wbn.NoopMcpRequestContext}toAnnotations(){if(!(this.audience===void 0&&this.priority===void 0&&this.lastModified===void 0))return{...this.audience!==void 0?{audience:this.audience}:{},...this.priority!==void 0?{priority:this.priority}:{},...this.lastModified!==void 0?{lastModified:this.lastModified}:{}}}uriTemplate(){return typeof this.uri=="string"?this.uri:this.uri.template}expandUriTemplate(n){return this.uriTemplate().replace(/\{(\w+)\}/g,(s,u)=>{let l=n[u];return l===void 0?s:encodeURIComponent(l)})}async execute(n){try{return{ok:!0,body:await n()}}catch(s){if(s instanceof OYe.McpToolError)return{ok:!1,message:s.message};let u=(0,OYe.extractErrorMessage)(s);return this.logger.error(`Unexpected error in resource '${this.name}': ${u}`,s),{ok:!1,message:u}}}toResourceResult(n,s){return s.ok?{contents:["text"in s.body?{uri:n,mimeType:this.mimeType,text:s.body.text}:{uri:n,mimeType:this.mimeType,blob:s.body.blob}],isError:!1}:{contents:[{uri:n,mimeType:"text/plain",text:s.message}],isError:!0}}toToolResult(n){if(!n.ok)return{isError:!0,content:[{type:"text",text:n.message}]};let s=n.body.structured,u="text"in n.body?{isError:!1,content:[{type:"text",text:n.body.text}]}:{isError:!1,content:[{type:"image",data:n.body.blob,mimeType:this.mimeType}]};return s?{...u,structuredContent:s}:u}buildResourceTemplate(n){return new jRr.ResourceTemplate(n,{list:this.list?async s=>this.requestContext.run(s,()=>this.list()):void 0,complete:this.complete?.()})}};wI([(0,_3.inject)(Wbn.McpRequestContext),(0,_3.optional)(),Cz("design:type",Object)],kz.prototype,"requestContext",void 0);wI([(0,_3.inject)(NQ.Logger),Cz("design:type",NQ.Logger)],kz.prototype,"logger",void 0);kz=wI([(0,_3.injectable)()],kz);var PYe=class extends kz{static{r(this,"AbstractMcpResourceHandler")}registerResource(n){let s=this.toAnnotations(),u={title:this.title,description:this.description,mimeType:this.mimeType,...s?{annotations:s}:{}};if(typeof this.uri=="string"){let l=this.uri;n.registerResource(this.name,l,u,async(g,v)=>this.requestContext.run(v,async()=>this.toResourceResult(l,await this.execute(()=>this.createResult({})))))}else n.registerResource(this.name,this.buildResourceTemplate(this.uri.template),u,async(l,g,v)=>this.requestContext.run(v,async()=>this.toResourceResult(l.toString(),await this.execute(()=>this.createResult(Xbn(g))))))}registerToolAlternative(n){this.toolAlternativeInputSchema&&this.doRegisterToolAlternative(n)}doRegisterToolAlternative(n){let s=this.toolAlternativeInputSchema;n.registerTool(this.name,{title:this.title,description:this.description,inputSchema:s.strict(),outputSchema:this.toolAlternativeOutputSchema},async(u,l)=>this.requestContext.run(l,async()=>this.toToolResult(await this.execute(()=>this.createResult(u)))))}};ig.AbstractMcpResourceHandler=PYe;ig.AbstractMcpResourceHandler=PYe=wI([(0,_3.injectable)()],PYe);var v9=class extends kz{static{r(this,"AbstractMcpDiagramResourceHandler")}requestAction(n,s,u=this.name){return(0,OYe.requestActionOrFail)(this.actionDispatcher,n,s,u)}canRegister(){return!0}list(){return{resources:[this.toListingEntry()]}}complete(){return this.uriTemplate().includes("{sessionId}")?{sessionId:r(async()=>[this.clientId],"sessionId")}:{}}toListingEntry(){let n=this.toAnnotations();return{uri:this.expandUriTemplate({sessionId:this.clientId}),name:`${this.title??this.name}: ${this.clientId}`,description:this.description,mimeType:this.mimeType,...n?{annotations:n}:{}}}async handleRead(n,s){return this.toResourceResult(n,await this.execute(()=>this.createResult(s)))}async handleAsTool(n){return this.toToolResult(await this.execute(()=>this.createResult(n)))}glspSessionScopedComplete(){let n=this.complete?.()??{},s=this.clientId,u=typeof this.uri=="object"&&this.uri.template.includes("{sessionId}"),l={};for(let[g,v]of Object.entries(n))l[g]=g==="sessionId"||!u?v:async(w,M)=>M?.arguments?.sessionId===s?v(w,M):[];return l}};ig.AbstractMcpDiagramResourceHandler=v9;wI([(0,_3.inject)(NQ.ClientId),Cz("design:type",String)],v9.prototype,"clientId",void 0);wI([(0,_3.inject)(NQ.ModelState),Cz("design:type",Object)],v9.prototype,"modelState",void 0);wI([(0,_3.inject)(MRr.McpIdAliasService),Cz("design:type",Object)],v9.prototype,"aliasService",void 0);wI([(0,_3.inject)(NQ.ActionDispatcher),Cz("design:type",Object)],v9.prototype,"actionDispatcher",void 0);ig.AbstractMcpDiagramResourceHandler=v9=wI([(0,_3.injectable)()],v9);function Xbn(o){let n={};for(let[s,u]of Object.entries(o))n[s]=Array.isArray(u)?u[0]??"":u;return n}r(Xbn,"toParams");ig.McpDiagramResourceHandlerConstructor=Symbol("McpDiagramResourceHandlerConstructor")});var Qye=x(w1=>{"use strict";var w9=w1&&w1.__decorate||function(o,n,s,u){var l=arguments.length,g=l<3?n:u===null?u=Object.getOwnPropertyDescriptor(n,s):u,v;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")g=Reflect.decorate(o,n,s,u);else for(var w=o.length-1;w>=0;w--)(v=o[w])&&(g=(l<3?v(g):l>3?v(n,s,g):v(n,s))||g);return l>3&&g&&Object.defineProperty(n,s,g),g},LQ=w1&&w1.__metadata||function(o,n){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(o,n)};Object.defineProperty(w1,"__esModule",{value:!0});w1.McpDiagramResourceHandlerRegistryInitializer=w1.McpDiagramResourceHandlerRegistry=w1.McpDiagramResourceHandlerFactory=void 0;var xQ=Kr(),Bk=en(),TRr=yI();w1.McpDiagramResourceHandlerFactory=Symbol("McpDiagramResourceHandlerFactory");var qQ=class extends xQ.Registry{static{r(this,"McpDiagramResourceHandlerRegistry")}registerHandler(n){return this.register(n.name,n)}};w1.McpDiagramResourceHandlerRegistry=qQ;w1.McpDiagramResourceHandlerRegistry=qQ=w9([(0,Bk.injectable)()],qQ);var Uk=class{static{r(this,"McpDiagramResourceHandlerRegistryInitializer")}constructor(){this.constructors=[]}initialize(n){let s=this.clientId===xQ.TEMPORARY_CLIENT_ID;for(let u of this.constructors){let l;try{l=this.factory(u)}catch(g){throw new Error(`Failed to instantiate MCP diagram resource handler '${u.name}': ${g.message}. Check your DiagramModule bindings.`)}if(!l.canRegister()){s||this.logger.debug(`Skipping MCP diagram resource handler '${l.name}': canRegister() returned false.`);continue}this.registry.registerHandler(l)}}};w1.McpDiagramResourceHandlerRegistryInitializer=Uk;w9([(0,Bk.inject)(w1.McpDiagramResourceHandlerFactory),LQ("design:type",Function)],Uk.prototype,"factory",void 0);w9([(0,Bk.inject)(TRr.McpDiagramResourceHandlerConstructor),(0,Bk.optional)(),LQ("design:type",Array)],Uk.prototype,"constructors",void 0);w9([(0,Bk.inject)(qQ),LQ("design:type",qQ)],Uk.prototype,"registry",void 0);w9([(0,Bk.inject)(xQ.ClientId),LQ("design:type",String)],Uk.prototype,"clientId",void 0);w9([(0,Bk.inject)(xQ.Logger),LQ("design:type",xQ.Logger)],Uk.prototype,"logger",void 0);w1.McpDiagramResourceHandlerRegistryInitializer=Uk=w9([(0,Bk.injectable)()],Uk)});var e_e=x(y1=>{"use strict";var y9=y1&&y1.__decorate||function(o,n,s,u){var l=arguments.length,g=l<3?n:u===null?u=Object.getOwnPropertyDescriptor(n,s):u,v;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")g=Reflect.decorate(o,n,s,u);else for(var w=o.length-1;w>=0;w--)(v=o[w])&&(g=(l<3?v(g):l>3?v(n,s,g):v(n,s))||g);return l>3&&g&&Object.defineProperty(n,s,g),g},BQ=y1&&y1.__metadata||function(o,n){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(o,n)};Object.defineProperty(y1,"__esModule",{value:!0});y1.McpDiagramToolHandlerRegistryInitializer=y1.McpDiagramToolHandlerRegistry=y1.McpDiagramToolHandlerFactory=void 0;var FQ=Kr(),Gk=en(),IRr=rl();y1.McpDiagramToolHandlerFactory=Symbol("McpDiagramToolHandlerFactory");var zQ=class extends FQ.Registry{static{r(this,"McpDiagramToolHandlerRegistry")}registerHandler(n){return this.register(n.name,n)}};y1.McpDiagramToolHandlerRegistry=zQ;y1.McpDiagramToolHandlerRegistry=zQ=y9([(0,Gk.injectable)()],zQ);var Zk=class{static{r(this,"McpDiagramToolHandlerRegistryInitializer")}constructor(){this.constructors=[]}initialize(n){let s=this.clientId===FQ.TEMPORARY_CLIENT_ID;for(let u of this.constructors){let l;try{l=this.factory(u)}catch(g){throw new Error(`Failed to instantiate MCP diagram tool handler '${u.name}': ${g.message}. Check your DiagramModule bindings.`)}if(!l.canRegister()){s||this.logger.debug(`Skipping MCP diagram tool handler '${l.name}': canRegister() returned false.`);continue}this.registry.registerHandler(l)}}};y1.McpDiagramToolHandlerRegistryInitializer=Zk;y9([(0,Gk.inject)(y1.McpDiagramToolHandlerFactory),BQ("design:type",Function)],Zk.prototype,"factory",void 0);y9([(0,Gk.inject)(IRr.McpDiagramToolHandlerConstructor),(0,Gk.optional)(),BQ("design:type",Array)],Zk.prototype,"constructors",void 0);y9([(0,Gk.inject)(zQ),BQ("design:type",zQ)],Zk.prototype,"registry",void 0);y9([(0,Gk.inject)(FQ.ClientId),BQ("design:type",String)],Zk.prototype,"clientId",void 0);y9([(0,Gk.inject)(FQ.Logger),BQ("design:type",FQ.Logger)],Zk.prototype,"logger",void 0);y1.McpDiagramToolHandlerRegistryInitializer=Zk=y9([(0,Gk.injectable)()],Zk)});var t_e=x(F2=>{"use strict";var Rz=F2&&F2.__decorate||function(o,n,s,u){var l=arguments.length,g=l<3?n:u===null?u=Object.getOwnPropertyDescriptor(n,s):u,v;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")g=Reflect.decorate(o,n,s,u);else for(var w=o.length-1;w>=0;w--)(v=o[w])&&(g=(l<3?v(g):l>3?v(n,s,g):v(n,s))||g);return l>3&&g&&Object.defineProperty(n,s,g),g},UQ=F2&&F2.__metadata||function(o,n){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(o,n)};Object.defineProperty(F2,"__esModule",{value:!0});F2.DefaultMcpDiagramHandlerDispatcher=F2.McpDiagramHandlerDispatcher=void 0;var _9=Kr(),ARr=RQ(),Jk=en(),kRr=Yye(),Ybn=Qye(),CRr=e_e(),Hk=Zd(),RRr=sI(),e0n=iI(),Qbn=yI(),$Rr=rl();F2.McpDiagramHandlerDispatcher=Symbol("McpDiagramHandlerDispatcher");var Kk=class{static{r(this,"DefaultMcpDiagramHandlerDispatcher")}constructor(){this.requestContext=new e0n.NoopMcpRequestContext,this.diagramCatalogs=[]}harvest(){if(this.diagramCatalogs.length>0)return;let n=[],s=(0,_9.createClientSessionModule)({clientId:_9.TEMPORARY_CLIENT_ID,glspClient:{process:r(()=>{},"process")},clientActionKinds:[]});for(let[u,l]of this.diagramModules){let g=this.serverContainer.createChild();g.load(...l,s);let v=jYe(g,$Rr.McpDiagramToolHandlerConstructor),w=jYe(g,Qbn.McpDiagramResourceHandlerConstructor),M=jYe(g,RRr.McpDiagramPromptHandlerConstructor);g.unbindAll(),n.push({diagramType:u,toolConstructors:v,resourceConstructors:w,promptConstructors:M})}this.diagramCatalogs=n}hasDiagramTools(){return this.diagramCatalogs.some(n=>n.toolConstructors.length>0)}hasDiagramResources(){return this.diagramCatalogs.some(n=>n.resourceConstructors.length>0)}hasDiagramPrompts(){return this.diagramCatalogs.some(n=>n.promptConstructors.length>0)}registerAll(n,s){this.registerDiagramScopeTools(n),this.registerDiagramScopeResources(n,s),this.registerDiagramScopePrompts(n)}registerDiagramScopeTools(n){let s=new Map;for(let u of this.diagramCatalogs)for(let l of u.toolConstructors){let g=new l,v={description:g.description,inputKeys:Object.keys(g.inputSchema?.shape??{}).sort().join(","),diagramType:u.diagramType},w=s.get(g.name);if(w){(w.description!==v.description||w.inputKeys!==v.inputKeys)&&this.logger.warn(`Diagram-scope tool '${g.name}' is registered by multiple diagram types with diverging schemas: first registered by '${w.diagramType}', shadowed registration from '${u.diagramType}' is silently dropped. Either align schemas (description + inputSchema.shape keys must match) or pick distinct tool names.`);continue}s.set(g.name,v),n.registerTool(g.name,g.toRegistrationConfig(),(M,A)=>this.requestContext.run(A,()=>this.dispatchDiagramTool(g.name,M)))}}registerDiagramScopeResources(n,s){let u=new Set;for(let l of this.diagramCatalogs)for(let g of l.resourceConstructors){let v=new g;u.has(v.name)||(u.add(v.name),s?this.registerOneDiagramResource(n,v):v.toolAlternativeInputSchema&&this.registerOneDiagramResourceAsTool(n,v))}}registerOneDiagramResource(n,s){let u=s.name,l=s.toAnnotations(),g={title:s.title,description:s.description,mimeType:s.mimeType,...l?{annotations:l}:{}};if(typeof s.uri=="string"){let v=s.uri;n.registerResource(u,v,g,(w,M)=>this.requestContext.run(M,()=>this.dispatchStaticDiagramRead(u,v)))}else{let v=this.buildAggregatingResourceTemplate(s.uri.template,u);n.registerResource(u,v,g,(w,M,A)=>this.requestContext.run(A,()=>this.dispatchTemplatedDiagramRead(u,w,M)))}}registerOneDiagramResourceAsTool(n,s){let u=s.name,l=s.toolAlternativeInputSchema;n.registerTool(u,{title:s.title,description:s.description,inputSchema:l.strict(),outputSchema:s.toolAlternativeOutputSchema},(g,v)=>this.requestContext.run(v,()=>this.dispatchDiagramResourceAsTool(u,g)))}registerDiagramScopePrompts(n){let s=new Set;for(let u of this.diagramCatalogs)for(let l of u.promptConstructors){let g=new l;s.has(g.name)||(s.add(g.name),n.registerPrompt(g.name,g.toRegistrationConfig(),(v,w)=>this.requestContext.run(w,()=>this.dispatchDiagramPrompt(g.name,v))))}}buildAggregatingResourceTemplate(n,s){return new ARr.ResourceTemplate(n,{list:r(u=>this.requestContext.run(u,()=>this.aggregateList(s)),"list"),complete:this.buildAggregatedCompleters(s)})}async aggregateList(n){let s=[],u=new Set;for(let l of this.clientSessionManager.getSessions().map(g=>g.id)){let v=await this.findDiagramResourceHandler(n,l)?.list?.();if(v)for(let w of v.resources)u.has(w.uri)||(u.add(w.uri),s.push(w))}return{resources:s}}buildAggregatedCompleters(n){let s=this.collectCompleterVariableNames(n),u={};for(let l of s)u[l]=async(g,v)=>{let w=new Set;for(let M of this.clientSessionManager.getSessions().map(A=>A.id)){let A=this.findDiagramResourceHandler(n,M);if(!A)continue;let z=A.glspSessionScopedComplete()[l];if(!z)continue;(await z(g,v)).forEach(ie=>w.add(ie))}return[...w]};return u}collectCompleterVariableNames(n){let s=new Set;for(let u of this.diagramCatalogs)for(let l of u.resourceConstructors){let g=new l;g.name===n&&Object.keys(g.complete?.()??{}).forEach(v=>s.add(v))}return s}dispatchDiagramTool(n,s){return(0,Hk.runWithToolErrorEnvelope)(async()=>this.requireDiagramToolHandler(n,s).handle(s))}dispatchStaticDiagramRead(n,s){let u=this.clientSessionManager.getSessions()[0]?.id;if(!u)throw new Hk.McpToolError(`No open GLSP session can serve resource '${n}'.`);return this.requireDiagramResourceHandler(n,u).handleRead(s,{sessionId:u})}dispatchTemplatedDiagramRead(n,s,u){let l=(0,Qbn.toParams)(u);return this.requireDiagramResourceHandler(n,l.sessionId).handleRead(s.toString(),l)}dispatchDiagramResourceAsTool(n,s){return(0,Hk.runWithToolErrorEnvelope)(async()=>this.requireDiagramResourceHandler(n,this.extractSessionId(s)).handleAsTool(s))}dispatchDiagramPrompt(n,s){return this.requireDiagramPromptHandler(n,s).handle(s)}extractSessionId(n){return n.sessionId}requireDiagramToolHandler(n,s){let u=this.requireGlspSession(this.extractSessionId(s)),g=u.container.get(CRr.McpDiagramToolHandlerRegistry).get(n);if(!g)throw new Hk.McpToolError(`No tool handler '${n}' registered for diagram type '${u.diagramType}'.`);return g}requireDiagramResourceHandler(n,s){let u=this.requireGlspSession(s),g=u.container.get(Ybn.McpDiagramResourceHandlerRegistry).get(n);if(!g)throw new Hk.McpToolError(`No resource handler '${n}' registered for diagram type '${u.diagramType}'.`);return g}findDiagramResourceHandler(n,s){let u=this.clientSessionManager.getSession(s);if(u)return u.container.get(Ybn.McpDiagramResourceHandlerRegistry).get(n)}requireDiagramPromptHandler(n,s){let u=this.requireGlspSession(this.extractSessionId(s)),g=u.container.get(kRr.McpDiagramPromptHandlerRegistry).get(n);if(!g)throw new Hk.McpToolError(`No prompt handler '${n}' registered for diagram type '${u.diagramType}'.`);return g}requireGlspSession(n){if(!n)throw new Hk.McpMissingParamError("sessionId");let s=this.clientSessionManager.getSession(n);if(!s)throw new Hk.McpSessionNotFoundError(n);return s}reset(){this.diagramCatalogs=[]}};F2.DefaultMcpDiagramHandlerDispatcher=Kk;Rz([(0,Jk.inject)(e0n.McpRequestContext),(0,Jk.optional)(),UQ("design:type",Object)],Kk.prototype,"requestContext",void 0);Rz([(0,Jk.inject)(_9.InjectionContainer),UQ("design:type",Jk.Container)],Kk.prototype,"serverContainer",void 0);Rz([(0,Jk.inject)(_9.DiagramModules),UQ("design:type",Map)],Kk.prototype,"diagramModules",void 0);Rz([(0,Jk.inject)(_9.ClientSessionManager),UQ("design:type",Object)],Kk.prototype,"clientSessionManager",void 0);Rz([(0,Jk.inject)(_9.Logger),UQ("design:type",_9.Logger)],Kk.prototype,"logger",void 0);F2.DefaultMcpDiagramHandlerDispatcher=Kk=Rz([(0,Jk.injectable)()],Kk);function jYe(o,n){return o.isBound(n)?o.get(n):[]}r(jYe,"getConstructorList")});var GQ=x(S3=>{"use strict";var DRr=S3&&S3.__decorate||function(o,n,s,u){var l=arguments.length,g=l<3?n:u===null?u=Object.getOwnPropertyDescriptor(n,s):u,v;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")g=Reflect.decorate(o,n,s,u);else for(var w=o.length-1;w>=0;w--)(v=o[w])&&(g=(l<3?v(g):l>3?v(n,s,g):v(n,s))||g);return l>3&&g&&Object.defineProperty(n,s,g),g},n_e;Object.defineProperty(S3,"__esModule",{value:!0});S3.DefaultMcpLogLevelRegistry=S3.McpLogLevelRegistry=void 0;S3.passesLogThreshold=xRr;var NRr=en();S3.McpLogLevelRegistry=Symbol("McpLogLevelRegistry");var t0n={emergency:0,alert:1,critical:2,error:3,warning:4,notice:5,info:6,debug:7};function xRr(o,n){return t0n[o]<=t0n[n]}r(xRr,"passesLogThreshold");var MYe=class{static{r(this,"DefaultMcpLogLevelRegistry")}constructor(){this.levels=new Map}static{n_e=this}static{this.DEFAULT_LEVEL="debug"}setLevel(n,s){this.levels.set(n,s)}getLevel(n){return n===void 0?n_e.DEFAULT_LEVEL:this.levels.get(n)??n_e.DEFAULT_LEVEL}clear(n){this.levels.delete(n)}};S3.DefaultMcpLogLevelRegistry=MYe;S3.DefaultMcpLogLevelRegistry=MYe=n_e=DRr([(0,NRr.injectable)()],MYe)});var r_e=x(_I=>{"use strict";var qRr=_I&&_I.__decorate||function(o,n,s,u){var l=arguments.length,g=l<3?n:u===null?u=Object.getOwnPropertyDescriptor(n,s):u,v;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")g=Reflect.decorate(o,n,s,u);else for(var w=o.length-1;w>=0;w--)(v=o[w])&&(g=(l<3?v(g):l>3?v(n,s,g):v(n,s))||g);return l>3&&g&&Object.defineProperty(n,s,g),g};Object.defineProperty(_I,"__esModule",{value:!0});_I.McpServerDefaults=_I.McpServerOptions=void 0;var LRr=en(),TYe=class{static{r(this,"McpServerOptions")}constructor(){this.values={}}};_I.McpServerOptions=TYe;_I.McpServerOptions=TYe=qRr([(0,LRr.injectable)()],TYe);_I.McpServerDefaults=Symbol("McpServerDefaults")});var o_e=x(zv=>{"use strict";var z2=zv&&zv.__decorate||function(o,n,s,u){var l=arguments.length,g=l<3?n:u===null?u=Object.getOwnPropertyDescriptor(n,s):u,v;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")g=Reflect.decorate(o,n,s,u);else for(var w=o.length-1;w>=0;w--)(v=o[w])&&(g=(l<3?v(g):l>3?v(n,s,g):v(n,s))||g);return l>3&&g&&Object.defineProperty(n,s,g),g},O3=zv&&zv.__metadata||function(o,n){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(o,n)};Object.defineProperty(zv,"__esModule",{value:!0});zv.AbstractMcpServerLauncher=zv.SERVER_VERSION=void 0;zv.pickInitOptions=n0n;var E3=Kr(),FRr=RQ(),zRr=Kbn(),i_e=Tk(),o0=en(),BRr=Vbn(),URr=Vye(),GRr=Xye(),ZRr=t_e(),HRr=GQ(),IYe=r_e(),JRr=sI(),KRr=yI(),VRr=rl();zv.SERVER_VERSION=BRr.version;function n0n(o){let{dataMode:n,agentPersona:s,eventStoreLimit:u}=o,l={};return n!==void 0&&(l.dataMode=n),s!==void 0&&(l.agentPersona=s),u!==void 0&&(l.eventStoreLimit=u),l}r(n0n,"pickInitOptions");var WRr=null,Fv=class{static{r(this,"AbstractMcpServerLauncher")}constructor(){this.toolHandlers=[],this.resourceHandlers=[],this.promptHandlers=[],this.toDispose=new E3.DisposableCollection,this.sessions=new Map,this.sessionServers=new Map,this.onSessionInitializedEmitter=new E3.Emitter,this.onSessionInitialized=this.onSessionInitializedEmitter.event,this.onSessionClosedEmitter=new E3.Emitter,this.onSessionClosed=this.onSessionClosedEmitter.event}async initializeServer(n,s,u){let l=E3.McpInitializeParameters.getServerConfig(s);if(!l)return u;if(this.serverConfig)return this.serverUrl?E3.McpInitializeResult.attachServer(u,{name:this.serverConfig.name,url:this.serverUrl}):u;let{port:g=0,route:v="/mcp",name:w="glsp",options:M={}}=l,A={...this.mcpDefaults,...n0n(M)};this.mcpOptions.values=A;let R=A.host??"127.0.0.1",z={port:g,host:R,route:v,name:w,options:A};this.dispatcher.harvest(),this.installResourceListChangedNotifier();let K=await this.bindTransport(z);return this.serverConfig=z,this.serverUrl=K.url,this.logger.info(`MCP server '${z.name}' is ready to accept new client requests on: ${this.serverUrl??"(no network endpoint)"}`),K.url?E3.McpInitializeResult.attachServer(u,{name:z.name,url:K.url,headers:K.headers}):u}serverShutDown(n){this.dispose()}dispose(){let n=Array.from(this.sessions.values()).map(s=>s.close().catch(u=>this.logger.warn(`Error closing MCP session ${s.sessionId}: ${u}`)));this.sessions.clear(),this.sessionServers.forEach(s=>s.dispose()),this.sessionServers.clear(),Promise.allSettled(n).then(()=>{this.toDispose.dispose(),this.toDispose.clear()}),this.serverUrl=void 0,this.serverConfig=void 0,this.dispatcher.reset()}async handleRequest(n,s){let u=new URL(n.url),l=this.serverConfig?.route??"/mcp";if(u.pathname!==l)return new Response("Not Found",{status:404});if(n.method!=="POST"&&n.method!=="GET"&&n.method!=="DELETE")return new Response("Method Not Allowed",{status:405,headers:{Allow:"POST, GET, DELETE"}});let g=this.validateHostHeader(n);if(g)return g;let v;n.method==="POST"&&(v=await n.clone().json().catch(()=>{}));let w=n.method==="POST"&&(0,i_e.isInitializeRequest)(v),M=this.validateProtocolVersionHeader(n,w);if(M)return M;let A=this.resolveTransport(n,w);if(A instanceof Response)return A;try{return await A.handleRequest(n,{parsedBody:v,authInfo:s?.authInfo})}catch(R){let z=R instanceof Error?R.message:String(R);return this.logger.error("Error handling MCP request:",R),this.jsonRpcErrorResponse(500,-32603,`Internal server error: ${z}`)}}getRequestHandler(){return(n,s)=>this.handleRequest(n,s)}resolveTransport(n,s){let u=n.headers.get("mcp-session-id")??void 0;if(s&&!u)return this.createTransport();if(!u)return this.jsonRpcErrorResponse(400,-32e3,"Bad Request: No valid session ID provided");let l=this.sessions.get(u);return l||this.jsonRpcErrorResponse(404,-32001,"Session not found")}validateProtocolVersionHeader(n,s){if(s)return;let u=n.headers.get("mcp-protocol-version")??void 0;if(u!==void 0&&!i_e.SUPPORTED_PROTOCOL_VERSIONS.includes(u))return this.jsonRpcErrorResponse(400,-32e3,`Unsupported MCP-Protocol-Version: '${u}'. Supported versions: ${i_e.SUPPORTED_PROTOCOL_VERSIONS.join(", ")}.`)}validateHostHeader(n){let s=this.mcpOptions.values.allowedHosts;if(!s||s.length===0)return;let u=n.headers.get("host");if(!u)return this.jsonRpcErrorResponse(403,-32e3,"Missing Host header");let l;try{l=new URL(`http://${u}`).hostname}catch{return this.jsonRpcErrorResponse(403,-32e3,`Invalid Host header: ${u}`)}if(!s.includes(l))return this.jsonRpcErrorResponse(403,-32e3,`Invalid Host: ${l}`)}createTransport(){let n=this.mcpOptions.values.allowedOrigins,s=new zRr.WebStandardStreamableHTTPServerTransport({sessionIdGenerator:r(()=>globalThis.crypto.randomUUID(),"sessionIdGenerator"),eventStore:new GRr.LruEventStore(this.mcpOptions.values.eventStoreLimit,this.logger),allowedOrigins:n,enableDnsRebindingProtection:(n?.length??0)>0,onsessioninitialized:r(u=>{this.logger.info(`MCP session initialized with ID: ${u}`),this.sessions.set(u,s),this.serverConfig&&this.attachServerToSession(s,this.serverConfig),this.onSessionInitializedEmitter.fire(s)},"onsessioninitialized"),onsessionclosed:r(u=>this.closeSession(u),"onsessionclosed")});return s.onclose=()=>this.closeSession(s.sessionId),s.onerror=u=>this.logger.error(`MCP transport error (session ${s.sessionId??"<pre-init>"}):`,u),s}attachServerToSession(n,s){let u=n.sessionId;if(!u)return;let l=this.createGlspMcpServer(s);this.sessionServers.set(u,l),this.registerLogLevelHandler(l,u),l.connect(n)}closeSession(n){if(!n)return;let s=this.sessions.delete(n),u=this.sessionServers.get(n);u&&(this.sessionServers.delete(n),this.logLevelRegistry.clear(n),u.dispose()),s&&(this.logger.info(`MCP session closed: ${n}`),this.onSessionClosedEmitter.fire(n))}installResourceListChangedNotifier(){if(!this.dispatcher.hasDiagramResources())return;let n={sessionCreated:r(()=>this.broadcastResourceListChanged(),"sessionCreated"),sessionDisposed:r(()=>this.broadcastResourceListChanged(),"sessionDisposed")};this.clientSessionManager.addListener(n),this.toDispose.push(E3.Disposable.create(()=>this.clientSessionManager.removeListener(n)))}broadcastResourceListChanged(){for(let n of this.sessionServers.values())n.getRawServer().server.sendResourceListChanged().catch(s=>this.logger.debug("sendResourceListChanged failed:",s))}registerLogLevelHandler(n,s){n.getRawServer().server.setRequestHandler(i_e.SetLevelRequestSchema,async u=>(this.logLevelRegistry.setLevel(s,u.params.level),{}))}createGlspMcpServer({name:n,options:s}){let u=s.dataMode==="resources",l=new FRr.McpServer({name:n,version:zv.SERVER_VERSION},{capabilities:this.buildCapabilities(u),instructions:s.agentPersona}),g=this.glspMcpServerFactory(l,s);return this.registerHandlers(g,u),g}buildCapabilities(n){let s=this.toolHandlers.length>0,u=this.promptHandlers.length>0,l=this.resourceHandlers.length>0,g=this.dispatcher.hasDiagramTools(),v=this.dispatcher.hasDiagramPrompts(),w=this.dispatcher.hasDiagramResources(),M=l||w;return{logging:{},...s||g||!n&&M?{tools:{listChanged:!1}}:{},...n&&M?{resources:{listChanged:w}}:{},...u||v?{prompts:{listChanged:!1}}:{}}}registerHandlers(n,s){this.toolHandlers.forEach(u=>u.registerTool(n)),this.promptHandlers.forEach(u=>u.registerPrompt(n)),s?this.resourceHandlers.forEach(u=>u.registerResource(n)):this.resourceHandlers.forEach(u=>u.registerToolAlternative?.(n)),this.dispatcher.registerAll(n,s),this.validatePromptToolReferences(n)}validatePromptToolReferences(n){for(let s of this.promptHandlers){let u=s.referencedToolNames().filter(l=>!n.hasTool(l));u.length>0&&this.logger.warn(`Prompt '${s.name}' references unbound tool(s): ${u.join(", ")}. The prompt will still register but its text points at tools the LLM cannot invoke.`)}}jsonRpcErrorResponse(n,s,u){return new Response(JSON.stringify({jsonrpc:"2.0",error:{code:s,message:u},id:WRr}),{status:n,headers:{"Content-Type":"application/json"}})}};zv.AbstractMcpServerLauncher=Fv;z2([(0,o0.inject)(E3.Logger),O3("design:type",E3.Logger)],Fv.prototype,"logger",void 0);z2([(0,o0.inject)(IYe.McpServerOptions),O3("design:type",IYe.McpServerOptions)],Fv.prototype,"mcpOptions",void 0);z2([(0,o0.inject)(IYe.McpServerDefaults),O3("design:type",Object)],Fv.prototype,"mcpDefaults",void 0);z2([(0,o0.inject)(URr.GLSPMcpServerFactory),O3("design:type",Function)],Fv.prototype,"glspMcpServerFactory",void 0);z2([(0,o0.inject)(ZRr.McpDiagramHandlerDispatcher),O3("design:type",Object)],Fv.prototype,"dispatcher",void 0);z2([(0,o0.inject)(HRr.McpLogLevelRegistry),O3("design:type",Object)],Fv.prototype,"logLevelRegistry",void 0);z2([(0,o0.inject)(E3.ClientSessionManager),O3("design:type",Object)],Fv.prototype,"clientSessionManager",void 0);z2([(0,o0.multiInject)(VRr.McpToolHandler),(0,o0.optional)(),O3("design:type",Array)],Fv.prototype,"toolHandlers",void 0);z2([(0,o0.multiInject)(KRr.McpResourceHandler),(0,o0.optional)(),O3("design:type",Array)],Fv.prototype,"resourceHandlers",void 0);z2([(0,o0.multiInject)(JRr.McpPromptHandler),(0,o0.optional)(),O3("design:type",Array)],Fv.prototype,"promptHandlers",void 0);zv.AbstractMcpServerLauncher=Fv=z2([(0,o0.injectable)()],Fv)});var a_e=x(SI=>{"use strict";var s_e=SI&&SI.__decorate||function(o,n,s,u){var l=arguments.length,g=l<3?n:u===null?u=Object.getOwnPropertyDescriptor(n,s):u,v;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")g=Reflect.decorate(o,n,s,u);else for(var w=o.length-1;w>=0;w--)(v=o[w])&&(g=(l<3?v(g):l>3?v(n,s,g):v(n,s))||g);return l>3&&g&&Object.defineProperty(n,s,g),g},AYe=SI&&SI.__metadata||function(o,n){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(o,n)};Object.defineProperty(SI,"__esModule",{value:!0});SI.McpLogger=void 0;var r0n=Kr(),ZQ=en(),i0n=GQ(),o0n=iI(),$z=class{static{r(this,"McpLogger")}constructor(){this.requestContext=new o0n.NoopMcpRequestContext}info(n,...s){this.glspLogger.info(n,...s),this.notify("info",n)}warn(n,...s){this.glspLogger.warn(n,...s),this.notify("warning",n)}error(n,...s){this.glspLogger.error(n,...s),this.notify("error",n)}debug(n,...s){this.glspLogger.debug(n,...s),this.notify("debug",n)}notify(n,s){let u=this.requestContext.getStore();if(!u)return;let l=this.levelRegistry.getLevel(u.sessionId);(0,i0n.passesLogThreshold)(n,l)&&u.sendNotification({method:"notifications/message",params:{level:n,data:s}}).catch(()=>{})}};SI.McpLogger=$z;s_e([(0,ZQ.inject)(o0n.McpRequestContext),(0,ZQ.optional)(),AYe("design:type",Object)],$z.prototype,"requestContext",void 0);s_e([(0,ZQ.inject)(r0n.Logger),AYe("design:type",r0n.Logger)],$z.prototype,"glspLogger",void 0);s_e([(0,ZQ.inject)(i0n.McpLogLevelRegistry),AYe("design:type",Object)],$z.prototype,"levelRegistry",void 0);SI.McpLogger=$z=s_e([(0,ZQ.injectable)()],$z)});var HQ=x(EI=>{"use strict";var s0n=EI&&EI.__decorate||function(o,n,s,u){var l=arguments.length,g=l<3?n:u===null?u=Object.getOwnPropertyDescriptor(n,s):u,v;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")g=Reflect.decorate(o,n,s,u);else for(var w=o.length-1;w>=0;w--)(v=o[w])&&(g=(l<3?v(g):l>3?v(n,s,g):v(n,s))||g);return l>3&&g&&Object.defineProperty(n,s,g),g},XRr=EI&&EI.__metadata||function(o,n){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(o,n)};Object.defineProperty(EI,"__esModule",{value:!0});EI.McpProgressReporter=void 0;var kYe=en(),a0n=iI(),c_e=class{static{r(this,"McpProgressReporter")}constructor(){this.requestContext=new a0n.NoopMcpRequestContext}async emit(n){let s=this.requestContext.getStore(),u=s?._meta?.progressToken;if(!(s===void 0||u===void 0))try{await s.sendNotification({method:"notifications/progress",params:{progressToken:u,...n}})}catch{}}};EI.McpProgressReporter=c_e;s0n([(0,kYe.inject)(a0n.McpRequestContext),(0,kYe.optional)(),XRr("design:type",Object)],c_e.prototype,"requestContext",void 0);EI.McpProgressReporter=c_e=s0n([(0,kYe.injectable)()],c_e)});var $Ye=x(vp=>{"use strict";var c0n=vp&&vp.__decorate||function(o,n,s,u){var l=arguments.length,g=l<3?n:u===null?u=Object.getOwnPropertyDescriptor(n,s):u,v;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")g=Reflect.decorate(o,n,s,u);else for(var w=o.length-1;w>=0;w--)(v=o[w])&&(g=(l<3?v(g):l>3?v(n,s,g):v(n,s))||g);return l>3&&g&&Object.defineProperty(n,s,g),g},YRr=vp&&vp.__metadata||function(o,n){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(o,n)},CYe;Object.defineProperty(vp,"__esModule",{value:!0});vp.SessionInfoMcpToolHandler=vp.SessionInfoOutputSchema=vp.SessionInfoRowSchema=vp.SessionInfoInputSchema=void 0;var RYe=Kr(),u0n=en(),P3=tl(),QRr=Zd(),e$r=rl();vp.SessionInfoInputSchema=P3.object({sessionId:P3.string().optional().describe("Optional filter \u2014 returns only the matching session, or throws if unknown. Omit to list all sessions.")});vp.SessionInfoRowSchema=P3.object({sessionId:P3.string(),diagramType:P3.string(),sourceUri:P3.string(),readOnly:P3.boolean(),dirty:P3.boolean().describe("True when the diagram has unsaved changes \u2014 call `save-model` to persist.")});vp.SessionInfoOutputSchema=P3.object({sessions:P3.array(vp.SessionInfoRowSchema)});var u_e=class extends e$r.AbstractMcpToolHandler{static{r(this,"SessionInfoMcpToolHandler")}constructor(){super(...arguments),this.name=CYe.NAME,this.title="GLSP Session Info",this.description="Report info on the active GLSP client sessions: session id, diagram type, source uri, and read-only status. Pass `sessionId` to retrieve a single session's entry; omit it to list every active session. Useful as a discovery tool \u2014 most other diagram-scoped tools take the `sessionId` returned here.",this.inputSchema=vp.SessionInfoInputSchema,this.outputSchema=vp.SessionInfoOutputSchema}static{CYe=this}static{this.NAME="session-info"}createResult({sessionId:n}){let u=(n!==void 0?this.singleSession(n):this.clientSessionManager.getSessions()).map(l=>this.buildSessionRow(l));return this.success(this.summarizeSessions(u),{sessions:u})}buildSessionRow(n){let s=n.container.get(RYe.ModelState),u=n.container.get(RYe.CommandStack);return{sessionId:n.id,diagramType:n.diagramType,sourceUri:s.sourceUri??"",readOnly:s.isReadonly,dirty:u.isDirty}}summarizeSessions(n){if(n.length===0)return"No active sessions.";let s=n.map(u=>{let l=[u.readOnly?"read-only":void 0,u.dirty?"dirty":void 0].filter(Boolean),g=l.length>0?`, ${l.join(", ")}`:"";return`- ${u.sessionId} (${u.diagramType}${g})`});return`${n.length} session(s); full details in structuredContent.
|
|
247
247
|
${s.join(`
|
|
248
248
|
`)}`}singleSession(n){let s=this.clientSessionManager.getSession(n);if(!s)throw new QRr.McpToolError(`Unknown sessionId: ${n}`);return[s]}};vp.SessionInfoMcpToolHandler=u_e;c0n([(0,u0n.inject)(RYe.ClientSessionManager),YRr("design:type",Object)],u_e.prototype,"clientSessionManager",void 0);vp.SessionInfoMcpToolHandler=u_e=CYe=c0n([(0,u0n.injectable)()],u_e)});var qYe=x(B2=>{"use strict";Object.defineProperty(B2,"__esModule",{value:!0});B2.AbstractMcpServerModule=B2.McpHandlerMultiBinding=B2.DEFAULT_MCP_OPTIONS=B2.DEFAULT_AGENT_PERSONA=void 0;var s0=Kr(),t$r=pVe(),n$r=vVe(),DYe=o_e(),l0n=Vye(),r$r=Xye(),f0n=t_e(),d0n=GQ(),h0n=a_e(),NYe=r_e(),p0n=HQ(),i$r=sI(),o$r=iI(),s$r=yI(),a$r=rl(),c$r=Uve(),u$r=$Ye();B2.DEFAULT_AGENT_PERSONA=`
|
|
249
249
|
You are the GLSP Modeling Agent. Your primary goal is to assist in the creation and modification of graphical models using the
|