@likec4/mcp 1.59.2 → 1.59.3

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.
@@ -1,7 +1,27 @@
1
- import{configureLanguageServerLogger as e}from"@likec4/language-server";import{fromWorkspace as t}from"@likec4/language-services/node";import{defu as n}from"defu";import{resolve as r}from"node:path";import{isDevelopment as i}from"std-env";import a from"tinyrainbow";import{createContext as o}from"unctx";import{StdioServerTransport as s}from"@modelcontextprotocol/sdk/server/stdio.js";import{hasProp as c,invariant as l}from"@likec4/core";import{loggable as u,logger as d}from"@likec4/log";import{isEmptyish as f,keys as p,pipe as m,piped as h,prop as g}from"remeda";import{McpServer as _,ResourceTemplate as v}from"@modelcontextprotocol/sdk/server/mcp.js";import{completable as y}from"@modelcontextprotocol/sdk/server/completable.js";import*as b from"zod/v3";import{enhanceLayoutWithAI as x}from"@likec4/layouts/ai";import{URI as S}from"vscode-uri";import{isDeploymentNodeModel as C,modelConnection as w}from"@likec4/core/model";import{ifilter as T,invariant as E,isSameHierarchy as D}from"@likec4/core/utils";import{MemoryEventStore as O,StreamableHTTPTransport as k}from"@hono/mcp";import{serve as A}from"@hono/node-server";import{Hono as j}from"hono";import{cors as ee}from"hono/cors";var M=Object.defineProperty,__name=(e,t)=>M(e,`name`,{value:t,configurable:!0});const N=o(),P=o();function useLanguageServices(){return P.use()}function setMcpServerCtx(e){return e?N.set(e,!0):N.unset(),e}function setLanguageServicesCtx(e){return e?P.set(e,!0):P.unset(),e}const F=d.getChild(`mcp`);function likec4Tool(e){return t=>n=>{let{name:r,description:i,...a}=e,o={description:i?.trim()??``,...a};return n.registerTool(r,o,async(...e)=>{let n=useLanguageServices();F.debug(`Calling tool {name}, args: {args}`,{name:r,args:e});try{let r=await t.apply(null,[n,...e]);return typeof r==`string`?{content:[{type:`text`,text:r}]}:f(o.outputSchema)?c(r,`content`)?r:{content:[{type:`text`,text:JSON.stringify(r)}]}:{content:[],structuredContent:r}}catch(e){return F.error(`Tool ${r} failed`,{err:e}),{content:[{type:`text`,text:u(e)}],isError:!0}}}),n}}var I=`1.59.2`;function applySemanticLayoutPrompt(e){let t=useLanguageServices();return e.registerPrompt(`apply_semantic_layout`,{title:`Prepare prompt for applying semantic layout to a likec4 view`,argsSchema:{projectId:y(b.string().describe(`Project id (optional, will use "default" if not specified)`),(e=``)=>t.projects().filter(t=>t.id.startsWith(e)).map(g(`id`))),viewId:y(b.string().describe(`View ID`),async(n=``,r)=>{let i=r?.arguments?.projectId??t.projectsManager.default.id,a=await t.computedModel(i);return a?Array.from(a.views()).filter(e=>e.id.startsWith(n)).map(g(`id`)):(await e.sendLoggingMessage({level:`warning`,data:`Completing viewId for project ${i} with input value "${n}", model not found`}),[])})}},async({viewId:e,projectId:t},n)=>({messages:[{role:`user`,content:{type:`text`,text:["Call `apply-semantic-layout` tool from `likec4` MCP with these arguments:","projectId: `"+t+"`","viewId: `"+e+"`"].join(`
2
- `)}}]})),e}function projectResource(e){let t=useLanguageServices();return e.registerResource(`likec4-project`,new v(`likec4://project/{projectId}`,{list:async()=>({resources:t.projects().map(e=>({uri:`likec4://project/${encodeURIComponent(e.id)}`,name:e.title}))}),complete:{projectId:e=>{if(!e)return t.projects().map(g(`id`));let n=e.toLowerCase();return t.projects().filter(e=>e.id.toLowerCase().includes(n)).map(g(`id`))}}}),{description:`LikeC4 project resource`,mimeType:`application/json`},async(e,{projectId:n})=>{if(!n)return{contents:[]};let r=typeof n==`string`?[n]:n;return{contents:t.projects().filter(e=>r.includes(e.id)).map(e=>({uri:`likec4://project/${encodeURIComponent(e.id)}`,text:JSON.stringify({id:e.id,title:e.title,folder:e.folder.fsPath})}))}}),e}const L=b.object({name:b.string().describe(`Project identifier`),title:b.string().optional().describe(`Human-readable project title`),contactPerson:b.string().optional().describe(`Maintainer contact information`),metadata:b.record(b.string(),b.unknown()).optional().describe(`Custom project metadata as key-value pairs`),extends:b.union([b.string(),b.array(b.string())]).optional().describe(`Style inheritance paths`),exclude:b.array(b.string()).optional().describe(`File exclusion patterns`),include:b.object({paths:b.array(b.string()).describe(`Include paths`),maxDepth:b.number().describe(`Maximum directory depth`),fileThreshold:b.number().describe(`File threshold`)}).optional().describe(`Include configuration`),manualLayouts:b.object({outDir:b.string().describe(`Output directory for manual layouts`)}).optional().describe(`Manual layouts configuration`),styles:b.object({hasTheme:b.boolean().describe(`Whether theme customization is defined`),hasDefaults:b.boolean().describe(`Whether default style values are defined`),hasCustomCss:b.boolean().describe(`Whether custom CSS is defined`)}).optional().describe(`Simplified styles configuration (boolean flags)`)});function serializeConfig(e){let t={name:e.name};return e.title!=null&&(t.title=e.title),e.contactPerson!=null&&(t.contactPerson=e.contactPerson),e.metadata&&(t.metadata=e.metadata),e.extends&&(t.extends=e.extends),e.exclude&&(t.exclude=e.exclude),e.include&&(t.include={paths:e.include.paths||[],maxDepth:e.include.maxDepth??3,fileThreshold:e.include.fileThreshold??30}),e.manualLayouts&&(t.manualLayouts={outDir:e.manualLayouts.outDir??`.likec4`}),e.styles&&(t.styles={hasTheme:!!e.styles.theme,hasDefaults:!!e.styles.defaults,hasCustomCss:!!e.styles.customCss}),t}const R=b.object({id:b.string().describe(`Element id (FQN)`),name:b.string().describe(`Element name`),kind:b.string().describe(`Element kind`),title:b.string(),tags:b.array(b.string()),metadata:b.record(b.union([b.string(),b.array(b.string())])),includedInViews:b.array(b.object({id:b.string().describe(`View id`),title:b.string().describe(`View title`),type:b.enum([`element`,`deployment`,`dynamic`]).describe(`View type`)})).describe(`Views that include this element`)});function serializeElement(e){return{id:e.id,name:e.name,kind:e.kind,title:e.title,tags:[...e.tags],metadata:e.getMetadata(),includedInViews:includedInViews(e.views())}}function traverseGraph(e,t,n,r,i,a){l(e.findElement(t),`Element "${t}" not found`);let o=new Set,s={},c=0,u=!1,d=[{elementId:t,depth:0}];for(;d.length>0;){let{elementId:t,depth:l}=d.shift();if(l>i||o.has(t))continue;if(o.size>=a){u=!0;break}let f=e.findElement(t);if(!f)continue;o.add(t),c=Math.max(c,l);let p=(n===`incoming`?[...f.incoming(r)]:[...f.outgoing(r)]).map(e=>{let t={elementId:n===`incoming`?e.source.id:e.target.id};return e.title&&(t.relationshipLabel=e.title),e.technology&&(t.technology=e.technology),t});s[t]={...serializeElement(f),neighbors:p,depth:l};for(let e of p)o.has(e.elementId)||d.push({elementId:e.elementId,depth:l+1})}for(let e of Object.values(s))e.neighbors=e.neighbors.filter(e=>e.elementId in s);return{target:t,totalNodes:o.size,maxDepth:c,truncated:u,nodes:s}}const z=b.object({path:b.string().describe(`Path to the file`),range:b.object({start:b.object({line:b.number(),character:b.number()}),end:b.object({line:b.number(),character:b.number()})}).describe(`Range in the file`)}).nullable(),B=b.string().refine(e=>!0).default(`default`).describe(`Project id (optional, will use "default" if not specified)`),V=b.array(b.object({id:b.string().describe(`View id`),title:b.string().describe(`View title`),type:b.enum([`element`,`deployment`,`dynamic`]).describe(`View type`)})),includedInViews=e=>[...e].map(e=>({id:e.id,title:e.titleOrId,type:e.$view._type})),mkLocate=(e,t)=>n=>{try{let r=e.locate({projectId:t,...n});return r?{path:S.parse(r.uri).fsPath,range:r.range}:null}catch(e){return F.debug(`Failed to locate {params}`,{error:e,params:n}),null}};function toolError(e){return{isError:!0,content:[{type:`text`,text:e}]}}function applySemanticLayoutTool(e){let t=useLanguageServices();return e.registerTool(`apply-semantic-layout`,{description:`Apply semantic layout to the likec4 view`,inputSchema:{projectId:y(b.string().default(`default`).describe(`Project id (optional, will use "default" if not specified)`),(e=``)=>t.projects().filter(t=>t.id.startsWith(e)).map(g(`id`))),viewId:y(b.string().describe(`View ID to apply semantic layout to`),async(e,n)=>{let r=n?.arguments?.projectId??t.projectsManager.default.id,i=await t.computedModel(r);if(!i)return[];let a=e??``;return Array.from(i.views()).filter(e=>e.id.startsWith(a)).map(g(`id`))})},outputSchema:{reasoning:b.string().describe(`Reasoning behind the layout changes`),snapshotUri:b.string().nullish().describe(`Where snapshot was saved (after applying layout)`)}},async(n,r)=>{let i=t.projectsManager.ensureProjectId(n.projectId);i!==n.projectId&&await e.sendLoggingMessage({level:`notice`,data:`Using project "${i}" instead of "${n.projectId}"`},r.sessionId);let a=await t.computedModel(i),o=a.findView(n.viewId);if(!o)return toolError(`View "${n.viewId}" not found in project "${i}"`);let s=await x(o.$view,{name:`MCP`,async sendRequest({systemPrompt:e,userPrompt:t,diagram:n}){let i=await r.sendRequest({method:`sampling/createMessage`,params:{maxTokens:2e4,includeContext:`none`,systemPrompt:e,messages:[{role:`user`,content:{type:`text`,text:t+`
1
+ import{configureLanguageServerLogger as e}from"@likec4/language-server";import{fromSources as t,fromWorkspace as n}from"@likec4/language-services/node";import{defu as r}from"defu";import{relative as i,resolve as a,sep as s}from"node:path";import{isDevelopment as c}from"std-env";import l from"tinyrainbow";import{createContext as u}from"unctx";import{StdioServerTransport as f}from"@modelcontextprotocol/sdk/server/stdio.js";import{hasProp as p,invariant as m}from"@likec4/core";import{loggable as h,logger as g}from"@likec4/log";import{isEmptyish as _,keys as v,pipe as y,piped as b,prop as x}from"remeda";import{McpServer as S,ResourceTemplate as C}from"@modelcontextprotocol/sdk/server/mcp.js";import{completable as w}from"@modelcontextprotocol/sdk/server/completable.js";import*as T from"zod/v3";import{RESOURCE_MIME_TYPE as E,registerAppResource as D,registerAppTool as O}from"@modelcontextprotocol/ext-apps/server";import{existsSync as k,readFileSync as A}from"node:fs";import{fileURLToPath as j}from"node:url";import{URI as M}from"vscode-uri";import{enhanceLayoutWithAI as ee}from"@likec4/layouts/ai";import{isDeploymentNodeModel as N,modelConnection as te}from"@likec4/core/model";import{ifilter as P,invariant as F,isSameHierarchy as I}from"@likec4/core/utils";import{randomUUID as L}from"node:crypto";import{MemoryEventStore as R,StreamableHTTPTransport as z}from"@hono/mcp";import{serve as B}from"@hono/node-server";import{Hono as ne}from"hono";import{cors as re}from"hono/cors";var ie=Object.defineProperty,__name=(e,t)=>ie(e,`name`,{value:t,configurable:!0});const V=u(),H=u();function useLanguageServices(){return H.use()}function setMcpServerCtx(e){return e?V.set(e,!0):V.unset(),e}function setLanguageServicesCtx(e){return e?H.set(e,!0):H.unset(),e}const U=g.getChild(`mcp`);function likec4Tool(e){return t=>n=>{let{name:r,description:i,...a}=e,s={description:i?.trim()??``,...a};return n.registerTool(r,s,async(...e)=>{let n=useLanguageServices();U.debug(`Calling tool {name}, args: {args}`,{name:r,args:e});try{let r=await t.apply(null,[n,...e]);return typeof r==`string`?{content:[{type:`text`,text:r}]}:_(s.outputSchema)?p(r,`content`)?r:{content:[{type:`text`,text:JSON.stringify(r)}]}:{content:[],structuredContent:r}}catch(e){return U.error(`Tool ${r} failed`,{err:e}),{content:[{type:`text`,text:h(e)}],isError:!0}}}),n}}var W=`1.59.3`;function applySemanticLayoutPrompt(e){let t=useLanguageServices();return e.registerPrompt(`apply_semantic_layout`,{title:`Prepare prompt for applying semantic layout to a likec4 view`,argsSchema:{projectId:w(T.string().describe(`Project id (optional, will use "default" if not specified)`),(e=``)=>t.projects().filter(t=>t.id.startsWith(e)).map(x(`id`))),viewId:w(T.string().describe(`View ID`),async(n=``,r)=>{let i=r?.arguments?.projectId??t.projectsManager.default.id,a=await t.computedModel(i);return a?Array.from(a.views()).filter(e=>e.id.startsWith(n)).map(x(`id`)):(await e.sendLoggingMessage({level:`warning`,data:`Completing viewId for project ${i} with input value "${n}", model not found`}),[])})}},async({viewId:e,projectId:t},n)=>({messages:[{role:`user`,content:{type:`text`,text:["Call `apply-semantic-layout` tool from `likec4` MCP with these arguments:","projectId: `"+t+"`","viewId: `"+e+"`"].join(`
2
+ `)}}]})),e}function projectResource(e){let t=useLanguageServices();return e.registerResource(`likec4-project`,new C(`likec4://project/{projectId}`,{list:async()=>({resources:t.projects().map(e=>({uri:`likec4://project/${encodeURIComponent(e.id)}`,name:e.title}))}),complete:{projectId:e=>{if(!e)return t.projects().map(x(`id`));let n=e.toLowerCase();return t.projects().filter(e=>e.id.toLowerCase().includes(n)).map(x(`id`))}}}),{description:`LikeC4 project resource`,mimeType:`application/json`},async(e,{projectId:n})=>{if(!n)return{contents:[]};let r=typeof n==`string`?[n]:n;return{contents:t.projects().filter(e=>r.includes(e.id)).map(e=>({uri:`likec4://project/${encodeURIComponent(e.id)}`,text:JSON.stringify({id:e.id,title:e.title,folder:e.folder.fsPath})}))}}),e}function readDistAsset(e){let t=[new URL(`../dist/${e}`,import.meta.url),new URL(`../../dist/${e}`,import.meta.url)];for(let e of t){let t=j(e);if(k(t))return A(t,`utf-8`)}throw Error(`Could not locate dist asset '${e}'; tried: ${t.map(String).join(`, `)}`)}function readRenderViewClientBundle(){return readDistAsset(`app/render-view-client.js`)}function readRenderViewClientStyles(){return readDistAsset(`app/render-view-client.css`)}const G=T.object({name:T.string().describe(`Project identifier`),title:T.string().optional().describe(`Human-readable project title`),contactPerson:T.string().optional().describe(`Maintainer contact information`),metadata:T.record(T.string(),T.unknown()).optional().describe(`Custom project metadata as key-value pairs`),extends:T.union([T.string(),T.array(T.string())]).optional().describe(`Style inheritance paths`),exclude:T.array(T.string()).optional().describe(`File exclusion patterns`),include:T.object({paths:T.array(T.string()).describe(`Include paths`),maxDepth:T.number().describe(`Maximum directory depth`),fileThreshold:T.number().describe(`File threshold`)}).optional().describe(`Include configuration`),manualLayouts:T.object({outDir:T.string().describe(`Output directory for manual layouts`)}).optional().describe(`Manual layouts configuration`),styles:T.object({hasTheme:T.boolean().describe(`Whether theme customization is defined`),hasDefaults:T.boolean().describe(`Whether default style values are defined`),hasCustomCss:T.boolean().describe(`Whether custom CSS is defined`)}).optional().describe(`Simplified styles configuration (boolean flags)`)});function serializeConfig(e){let t={name:e.name};return e.title!=null&&(t.title=e.title),e.contactPerson!=null&&(t.contactPerson=e.contactPerson),e.metadata&&(t.metadata=e.metadata),e.extends&&(t.extends=e.extends),e.exclude&&(t.exclude=e.exclude),e.include&&(t.include={paths:e.include.paths||[],maxDepth:e.include.maxDepth??3,fileThreshold:e.include.fileThreshold??30}),e.manualLayouts&&(t.manualLayouts={outDir:e.manualLayouts.outDir??`.likec4`}),e.styles&&(t.styles={hasTheme:!!e.styles.theme,hasDefaults:!!e.styles.defaults,hasCustomCss:!!e.styles.customCss}),t}const K=T.object({id:T.string().describe(`Element id (FQN)`),name:T.string().describe(`Element name`),kind:T.string().describe(`Element kind`),title:T.string(),tags:T.array(T.string()),metadata:T.record(T.union([T.string(),T.array(T.string())])),includedInViews:T.array(T.object({id:T.string().describe(`View id`),title:T.string().describe(`View title`),type:T.enum([`element`,`deployment`,`dynamic`]).describe(`View type`)})).describe(`Views that include this element`)});function serializeElement(e){return{id:e.id,name:e.name,kind:e.kind,title:e.title,tags:[...e.tags],metadata:e.getMetadata(),includedInViews:includedInViews(e.views())}}function traverseGraph(e,t,n,r,i,a){let s=e.findElement(t);m(s,`Element "${t}" not found`);let c=new Set,l={},u=0,f=!1,p=[{elementId:t,depth:0}];for(;p.length>0;){let{elementId:t,depth:s}=p.shift();if(s>i||c.has(t))continue;if(c.size>=a){f=!0;break}let m=e.findElement(t);if(!m)continue;c.add(t),u=Math.max(u,s);let h=(n===`incoming`?[...m.incoming(r)]:[...m.outgoing(r)]).map(e=>{let t={elementId:n===`incoming`?e.source.id:e.target.id};return e.title&&(t.relationshipLabel=e.title),e.technology&&(t.technology=e.technology),t});l[t]={...serializeElement(m),neighbors:h,depth:s};for(let e of h)c.has(e.elementId)||p.push({elementId:e.elementId,depth:s+1})}for(let e of Object.values(l))e.neighbors=e.neighbors.filter(e=>e.elementId in l);return{target:t,totalNodes:c.size,maxDepth:u,truncated:f,nodes:l}}const q=T.object({path:T.string().describe(`Path to the file`),range:T.object({start:T.object({line:T.number(),character:T.number()}),end:T.object({line:T.number(),character:T.number()})}).describe(`Range in the file`)}).nullable(),J=T.string().refine(e=>!0).default(`default`).describe(`Project id (optional, will use "default" if not specified)`),Y=T.array(T.object({id:T.string().describe(`View id`),title:T.string().describe(`View title`),type:T.enum([`element`,`deployment`,`dynamic`]).describe(`View type`)})),includedInViews=e=>[...e].map(e=>({id:e.id,title:e.titleOrId,type:e.$view._type})),mkLocate=(e,t)=>n=>{try{let r=e.locate({projectId:t,...n});return r?{path:M.parse(r.uri).fsPath,range:r.range}:null}catch(e){return U.debug(`Failed to locate {params}`,{error:e,params:n}),null}};function toolError(e){return{isError:!0,content:[{type:`text`,text:e}]}}function buildRenderPayload(e){return{id:e.viewId,title:e.title,project:e.projectId,view:e.layoutedView,model:{...e.modelData,views:{[e.viewId]:e.layoutedView}}}}const X=`ui://likec4/render-view.html`;function renderViewTool(e){return O(e,`render-view`,{title:`Render View`,description:`Renders a LikeC4 view as an interactive diagram (pan/zoom/fit) inline in the chat.
3
3
 
4
- `+n}}]}},b.object({content:b.object({type:b.literal(`text`),text:b.string()})}));return i.content.type===`text`?i.content.text:JSON.stringify(i.content)}},r.signal);if(!s)return await e.sendLoggingMessage({level:`error`,data:`Failed to generate layout hints`},r.sessionId),toolError(`Failed to generate layout hints`);await e.sendLoggingMessage({level:`info`,data:`Applying semantic layout...`},r.sessionId);let c=await t.views.layouter.aiLayout({view:o.$view,styles:a.$styles},s),l=await t.editor.applyChange({change:{op:`save-view-snapshot`,layout:c.diagram},viewId:o.id,projectId:i});return await e.sendLoggingMessage({level:`info`,data:`Layout applied successfully`},r.sessionId),{content:[],structuredContent:{reasoning:s.reasoning,...!!l.location&&{snapshotUri:l.location.uri.toString()}}}}),e}const H=R.extend({description:b.string().nullable().describe(`Element description`),technology:b.string().nullable().describe(`Element technology`),shape:b.string().describe(`Rendered shape`),color:b.string().describe(`Rendered color`),children:b.array(b.string()).describe(`Direct child element ids`),incomingCount:b.number().describe(`Number of incoming relationships`),outgoingCount:b.number().describe(`Number of outgoing relationships`)}),U=likec4Tool({name:`batch-read-elements`,description:`
4
+ Request:
5
+ - viewId: string — view id (name)
6
+ - project: string (optional) — project id. Defaults to "default" if omitted.
7
+
8
+ Use this when the user wants to *see* a view. Use "read-view" instead when only the view's structure (nodes/edges) is needed.`,inputSchema:{viewId:T.string().describe(`View id (name)`),project:J},outputSchema:{id:T.string(),title:T.string(),project:T.string(),view:T.record(T.string(),T.unknown()).describe(`Full layouted view (nodes, edges, bounds), consumed by the paired render-view UI`),model:T.record(T.string(),T.unknown()).describe(`Layouted model data (specification, elements, relations, deployments), scoped to this view only. Consumed by the paired UI to build a LikeC4Model for LikeC4ModelProvider — LikeC4Diagram requires one in context.`)},annotations:{readOnlyHint:!0,idempotentHint:!0,title:`Render view`},_meta:{ui:{resourceUri:X}}},async e=>{let t=useLanguageServices(),n=t.projectsManager.ensureProjectId(e.project),r=await t.layoutedModel(n),i=r.findView(e.viewId);if(!i)return toolError(`View with ID '${e.viewId}' not found in project ${n}`);if(!i.isLayouted())return toolError(`View '${e.viewId}' has no layout`);let a=i.$layouted,s=i.title??i.id;return{content:[{type:`text`,text:`Rendered view "${s}"`}],structuredContent:buildRenderPayload({projectId:n,viewId:i.id,title:s,layoutedView:a,modelData:r.$data})}}),e}function renderHtml(e,t){return`<!doctype html>
9
+ <html>
10
+ <head>
11
+ <meta charset="utf-8" />
12
+ <style>${t}</style>
13
+ <style>
14
+ html, body { margin: 0; padding: 0; height: 100%; overflow: hidden; }
15
+ #root { width: 100%; height: 100%; }
16
+ </style>
17
+ </head>
18
+ <body>
19
+ <div id="root"></div>
20
+ <script>${e}<\/script>
21
+ </body>
22
+ </html>`}function renderViewResource(e){return D(e,`Render View UI`,X,{description:`Interactive diagram UI for the render-view MCP App tool.`},async()=>({contents:[{uri:X,mimeType:E,text:renderHtml(readRenderViewClientBundle(),readRenderViewClientStyles())}]})),e}function applySemanticLayoutTool(e){let t=useLanguageServices();return e.registerTool(`apply-semantic-layout`,{description:`Apply semantic layout to the likec4 view`,inputSchema:{projectId:w(T.string().default(`default`).describe(`Project id (optional, will use "default" if not specified)`),(e=``)=>t.projects().filter(t=>t.id.startsWith(e)).map(x(`id`))),viewId:w(T.string().describe(`View ID to apply semantic layout to`),async(e,n)=>{let r=n?.arguments?.projectId??t.projectsManager.default.id,i=await t.computedModel(r);if(!i)return[];let a=e??``;return Array.from(i.views()).filter(e=>e.id.startsWith(a)).map(x(`id`))})},outputSchema:{reasoning:T.string().describe(`Reasoning behind the layout changes`),snapshotUri:T.string().nullish().describe(`Where snapshot was saved (after applying layout)`)}},async(n,r)=>{let i=t.projectsManager.ensureProjectId(n.projectId);i!==n.projectId&&await e.sendLoggingMessage({level:`notice`,data:`Using project "${i}" instead of "${n.projectId}"`},r.sessionId);let a=await t.computedModel(i),s=a.findView(n.viewId);if(!s)return toolError(`View "${n.viewId}" not found in project "${i}"`);let c=await ee(s.$view,{name:`MCP`,async sendRequest({systemPrompt:e,userPrompt:t,diagram:n}){let i=await r.sendRequest({method:`sampling/createMessage`,params:{maxTokens:2e4,includeContext:`none`,systemPrompt:e,messages:[{role:`user`,content:{type:`text`,text:t+`
23
+
24
+ `+n}}]}},T.object({content:T.object({type:T.literal(`text`),text:T.string()})}));return i.content.type===`text`?i.content.text:JSON.stringify(i.content)}},r.signal);if(!c)return await e.sendLoggingMessage({level:`error`,data:`Failed to generate layout hints`},r.sessionId),toolError(`Failed to generate layout hints`);await e.sendLoggingMessage({level:`info`,data:`Applying semantic layout...`},r.sessionId);let l=await t.views.layouter.aiLayout({view:s.$view,styles:a.$styles},c),u=await t.editor.applyChange({change:{op:`save-view-snapshot`,layout:l.diagram},viewId:s.id,projectId:i});return await e.sendLoggingMessage({level:`info`,data:`Layout applied successfully`},r.sessionId),{content:[],structuredContent:{reasoning:c.reasoning,...!!u.location&&{snapshotUri:u.location.uri.toString()}}}}),e}const ae=K.extend({description:T.string().nullable().describe(`Element description`),technology:T.string().nullable().describe(`Element technology`),shape:T.string().describe(`Rendered shape`),color:T.string().describe(`Rendered color`),children:T.array(T.string()).describe(`Direct child element ids`),incomingCount:T.number().describe(`Number of incoming relationships`),outgoingCount:T.number().describe(`Number of outgoing relationships`)}),oe=likec4Tool({name:`batch-read-elements`,description:`
5
25
  Read details of multiple elements in a single call, reducing round-trips.
6
26
  Returns a compact summary for each element including metadata, description, technology, shape, children, and relationship counts.
7
27
 
@@ -63,7 +83,7 @@ Example response:
63
83
  ],
64
84
  "notFound": []
65
85
  }
66
- `,annotations:{readOnlyHint:!0,idempotentHint:!0,title:`Batch read elements`},inputSchema:{ids:b.array(b.string()).min(1).max(50).describe(`Array of element ids (FQNs) to read (max 50)`),project:B},outputSchema:{elements:b.array(H),notFound:b.array(b.string()).describe(`Element ids that were not found`)}})(async(e,t)=>{l(t.ids.length<=50,`Maximum 50 element ids per call`);let n=e.projectsManager.ensureProjectId(t.project),r=await e.computedModel(n),i=[],a=[];for(let e of t.ids){let t=r.findElement(e);if(!t){a.push(e);continue}i.push({...serializeElement(t),description:t.description.text,technology:t.technology,shape:t.shape,color:t.color,children:[...t.children()].map(e=>e.id),incomingCount:t.allIncoming.size,outgoingCount:t.allOutgoing.size})}return{elements:i,notFound:a}}),W=b.object({id:b.string(),kind:b.string(),title:b.string(),description:b.string().nullable(),technology:b.string().nullable(),shape:b.string(),color:b.string()}),G=b.object({element1:W,element2:W,propertyDiffs:b.array(b.object({property:b.string().describe(`Property name`),element1Value:b.string().nullable().describe(`Value in element1`),element2Value:b.string().nullable().describe(`Value in element2`)})).describe(`Properties that differ between the two elements`),tags:b.object({onlyInElement1:b.array(b.string()).describe(`Tags present only in element1`),onlyInElement2:b.array(b.string()).describe(`Tags present only in element2`),common:b.array(b.string()).describe(`Tags present in both elements`)}),metadata:b.object({onlyInElement1:b.record(b.union([b.string(),b.array(b.string())])).describe(`Metadata keys only in element1`),onlyInElement2:b.record(b.union([b.string(),b.array(b.string())])).describe(`Metadata keys only in element2`),different:b.array(b.object({key:b.string(),element1Value:b.union([b.string(),b.array(b.string())]),element2Value:b.union([b.string(),b.array(b.string())])})).describe(`Metadata keys present in both but with different values`),common:b.record(b.union([b.string(),b.array(b.string())])).describe(`Metadata keys with identical values in both`)}),relationships:b.object({incomingOnlyElement1:b.number().describe(`Count of unique source elements sending to element1 only`),incomingOnlyElement2:b.number().describe(`Count of unique source elements sending to element2 only`),incomingShared:b.number().describe(`Count of unique source elements sending to both`),outgoingOnlyElement1:b.number().describe(`Count of unique target elements receiving from element1 only`),outgoingOnlyElement2:b.number().describe(`Count of unique target elements receiving from element2 only`),outgoingShared:b.number().describe(`Count of unique target elements receiving from both`)})}),K=likec4Tool({name:`element-diff`,description:`
86
+ `,annotations:{readOnlyHint:!0,idempotentHint:!0,title:`Batch read elements`},inputSchema:{ids:T.array(T.string()).min(1).max(50).describe(`Array of element ids (FQNs) to read (max 50)`),project:J},outputSchema:{elements:T.array(ae),notFound:T.array(T.string()).describe(`Element ids that were not found`)}})(async(e,t)=>{m(t.ids.length<=50,`Maximum 50 element ids per call`);let n=e.projectsManager.ensureProjectId(t.project),r=await e.computedModel(n),i=[],a=[];for(let e of t.ids){let t=r.findElement(e);if(!t){a.push(e);continue}i.push({...serializeElement(t),description:t.description.text,technology:t.technology,shape:t.shape,color:t.color,children:[...t.children()].map(e=>e.id),incomingCount:t.allIncoming.size,outgoingCount:t.allOutgoing.size})}return{elements:i,notFound:a}}),Z=T.object({id:T.string(),kind:T.string(),title:T.string(),description:T.string().nullable(),technology:T.string().nullable(),shape:T.string(),color:T.string()}),se=T.object({element1:Z,element2:Z,propertyDiffs:T.array(T.object({property:T.string().describe(`Property name`),element1Value:T.string().nullable().describe(`Value in element1`),element2Value:T.string().nullable().describe(`Value in element2`)})).describe(`Properties that differ between the two elements`),tags:T.object({onlyInElement1:T.array(T.string()).describe(`Tags present only in element1`),onlyInElement2:T.array(T.string()).describe(`Tags present only in element2`),common:T.array(T.string()).describe(`Tags present in both elements`)}),metadata:T.object({onlyInElement1:T.record(T.union([T.string(),T.array(T.string())])).describe(`Metadata keys only in element1`),onlyInElement2:T.record(T.union([T.string(),T.array(T.string())])).describe(`Metadata keys only in element2`),different:T.array(T.object({key:T.string(),element1Value:T.union([T.string(),T.array(T.string())]),element2Value:T.union([T.string(),T.array(T.string())])})).describe(`Metadata keys present in both but with different values`),common:T.record(T.union([T.string(),T.array(T.string())])).describe(`Metadata keys with identical values in both`)}),relationships:T.object({incomingOnlyElement1:T.number().describe(`Count of unique source elements sending to element1 only`),incomingOnlyElement2:T.number().describe(`Count of unique source elements sending to element2 only`),incomingShared:T.number().describe(`Count of unique source elements sending to both`),outgoingOnlyElement1:T.number().describe(`Count of unique target elements receiving from element1 only`),outgoingOnlyElement2:T.number().describe(`Count of unique target elements receiving from element2 only`),outgoingShared:T.number().describe(`Count of unique target elements receiving from both`)})}),ce=likec4Tool({name:`element-diff`,description:`
67
87
  Compare two elements side-by-side, showing differences in properties, tags, metadata, and relationships.
68
88
 
69
89
  Request:
@@ -123,7 +143,7 @@ Example response:
123
143
  "outgoingShared": 2
124
144
  }
125
145
  }
126
- `,annotations:{readOnlyHint:!0,idempotentHint:!0,title:`Compare two elements`},inputSchema:{element1Id:b.string().describe(`First element id (FQN)`),element2Id:b.string().describe(`Second element id (FQN)`),project:B},outputSchema:G.shape})(async(e,t)=>{let n=e.projectsManager.ensureProjectId(t.project),r=await e.computedModel(n),i=r.findElement(t.element1Id);l(i,`Element "${t.element1Id}" not found in project "${n}"`);let a=r.findElement(t.element2Id);l(a,`Element "${t.element2Id}" not found in project "${n}"`);let o=[],s=[{name:`kind`,get:e=>e.kind},{name:`title`,get:e=>e.title},{name:`description`,get:e=>e.description.text},{name:`technology`,get:e=>e.technology},{name:`shape`,get:e=>e.shape},{name:`color`,get:e=>e.color}];for(let e of s){let t=e.get(i),n=e.get(a);t!==n&&o.push({property:e.name,element1Value:t,element2Value:n})}let c=new Set(i.tags),u=new Set(a.tags),d=[],f=[],p=[];for(let e of c)u.has(e)?d.push(e):f.push(e);for(let e of u)c.has(e)||p.push(e);let m=i.getMetadata(),h=a.getMetadata(),g=new Set([...Object.keys(m),...Object.keys(h)]),_={},v={},y=[],b={};for(let e of g){let t=m[e],n=h[e];t!==void 0&&n===void 0?_[e]=t:t===void 0&&n!==void 0?v[e]=n:t!==void 0&&n!==void 0&&(JSON.stringify(t)===JSON.stringify(n)?b[e]=t:y.push({key:e,element1Value:t,element2Value:n}))}let x=new Set([...i.incoming()].map(e=>e.source.id)),S=new Set([...a.incoming()].map(e=>e.source.id)),C=new Set([...i.outgoing()].map(e=>e.target.id)),w=new Set([...a.outgoing()].map(e=>e.target.id)),T=0,E=0,D=0;for(let e of x)S.has(e)?T++:E++;for(let e of S)x.has(e)||D++;let O=0,k=0,A=0;for(let e of C)w.has(e)?O++:k++;for(let e of w)C.has(e)||A++;return{element1:{id:i.id,kind:i.kind,title:i.title,description:i.description.text,technology:i.technology,shape:i.shape,color:i.color},element2:{id:a.id,kind:a.kind,title:a.title,description:a.description.text,technology:a.technology,shape:a.shape,color:a.color},propertyDiffs:o,tags:{onlyInElement1:f,onlyInElement2:p,common:d},metadata:{onlyInElement1:_,onlyInElement2:v,different:y,common:b},relationships:{incomingOnlyElement1:E,incomingOnlyElement2:D,incomingShared:T,outgoingOnlyElement1:k,outgoingOnlyElement2:A,outgoingShared:O}}}),q=likec4Tool({name:`find-relationship-paths`,description:`
146
+ `,annotations:{readOnlyHint:!0,idempotentHint:!0,title:`Compare two elements`},inputSchema:{element1Id:T.string().describe(`First element id (FQN)`),element2Id:T.string().describe(`Second element id (FQN)`),project:J},outputSchema:se.shape})(async(e,t)=>{let n=e.projectsManager.ensureProjectId(t.project),r=await e.computedModel(n),i=r.findElement(t.element1Id);m(i,`Element "${t.element1Id}" not found in project "${n}"`);let a=r.findElement(t.element2Id);m(a,`Element "${t.element2Id}" not found in project "${n}"`);let s=[],c=[{name:`kind`,get:e=>e.kind},{name:`title`,get:e=>e.title},{name:`description`,get:e=>e.description.text},{name:`technology`,get:e=>e.technology},{name:`shape`,get:e=>e.shape},{name:`color`,get:e=>e.color}];for(let e of c){let t=e.get(i),n=e.get(a);t!==n&&s.push({property:e.name,element1Value:t,element2Value:n})}let l=new Set(i.tags),u=new Set(a.tags),f=[],p=[],h=[];for(let e of l)u.has(e)?f.push(e):p.push(e);for(let e of u)l.has(e)||h.push(e);let g=i.getMetadata(),_=a.getMetadata(),v=new Set([...Object.keys(g),...Object.keys(_)]),y={},b={},x=[],S={};for(let e of v){let t=g[e],n=_[e];t!==void 0&&n===void 0?y[e]=t:t===void 0&&n!==void 0?b[e]=n:t!==void 0&&n!==void 0&&(JSON.stringify(t)===JSON.stringify(n)?S[e]=t:x.push({key:e,element1Value:t,element2Value:n}))}let C=new Set([...i.incoming()].map(e=>e.source.id)),w=new Set([...a.incoming()].map(e=>e.source.id)),T=new Set([...i.outgoing()].map(e=>e.target.id)),E=new Set([...a.outgoing()].map(e=>e.target.id)),D=0,O=0,k=0;for(let e of C)w.has(e)?D++:O++;for(let e of w)C.has(e)||k++;let A=0,j=0,M=0;for(let e of T)E.has(e)?A++:j++;for(let e of E)T.has(e)||M++;return{element1:{id:i.id,kind:i.kind,title:i.title,description:i.description.text,technology:i.technology,shape:i.shape,color:i.color},element2:{id:a.id,kind:a.kind,title:a.title,description:a.description.text,technology:a.technology,shape:a.shape,color:a.color},propertyDiffs:s,tags:{onlyInElement1:p,onlyInElement2:h,common:f},metadata:{onlyInElement1:y,onlyInElement2:b,different:x,common:S},relationships:{incomingOnlyElement1:O,incomingOnlyElement2:k,incomingShared:D,outgoingOnlyElement1:j,outgoingOnlyElement2:M,outgoingShared:A}}}),le=likec4Tool({name:`find-relationship-paths`,description:`
127
147
  Discover all paths (chains of relationships) between two elements, supporting multi-hop traversal.
128
148
 
129
149
  Request:
@@ -212,7 +232,7 @@ Example response:
212
232
  }
213
233
  ]
214
234
  }
215
- `,annotations:{readOnlyHint:!0,idempotentHint:!0,title:`Find relationship paths`},inputSchema:{sourceId:b.string().describe(`Source element FQN`),targetId:b.string().describe(`Target element FQN`),maxDepth:b.number().int().min(1).max(5).optional().default(3).describe(`Maximum path length (default: 3, max: 5)`),includeIndirect:b.boolean().optional().default(!1).describe(`Include indirect (implied) relationships through nested elements (default: false)`),project:B},outputSchema:{paths:b.array(b.object({length:b.number().describe(`Number of hops in the path`),steps:b.array(b.object({source:b.string().describe(`Source element FQN`),target:b.string().describe(`Target element FQN`),relationship:b.object({kind:b.string().nullable().describe(`Relationship kind`),title:b.string().nullable().describe(`Relationship title`),description:b.string().nullable().describe(`Relationship description`),technology:b.string().nullable().describe(`Relationship technology`),tags:b.array(b.string()).describe(`Relationship tags`)})})).describe(`Ordered sequence of relationships in the path`)}))}})(async(e,t)=>{let n=e.projectsManager.ensureProjectId(t.project),r=await e.computedModel(n),i=r.findElement(t.sourceId);l(i,`Source element "${t.sourceId}" not found in project "${n}"`);let a=r.findElement(t.targetId);l(a,`Target element "${t.targetId}" not found in project "${n}"`),l(i.id!==a.id,`Source and target must be different elements`);let o=t.maxDepth,s=t.includeIndirect?`all`:`direct`,c=[{elementId:i.id,path:[],visited:new Set([i.id])}],u=[];for(;c.length>0&&u.length<100;){let e=c.shift();if(e.path.length>=o)continue;let t=r.findElement(e.elementId);if(t)for(let n of t.outgoing(s)){let t=n.target.id;if(t===a.id){let t={source:n.source.id,target:n.target.id,relationship:{kind:n.kind,title:n.title,description:n.description.text,technology:n.technology,tags:[...n.tags]}};if(u.push({length:e.path.length+1,steps:[...e.path,t]}),u.length>=100)break;continue}if(e.visited.has(t))continue;let r={source:n.source.id,target:n.target.id,relationship:{kind:n.kind,title:n.title,description:n.description.text,technology:n.technology,tags:[...n.tags]}};c.push({elementId:t,path:[...e.path,r],visited:new Set([...e.visited,t])})}}return u.sort((e,t)=>e.length-t.length),{paths:u}}),J=b.object({id:b.string(),title:b.string(),kind:b.string()}),Y=b.object({type:b.enum([`direct`,`indirect`]).describe(`Type of relationship, "direct" for direct relationships, "indirect" for relationships through nested elements`),source:J,target:J,kind:b.string().nullable().describe(`Relationship kind`),title:b.string().nullable().describe(`Relationship title`),description:b.string().nullable().describe(`Relationship description`),technology:b.string().nullable().describe(`Relationship technology`),tags:b.array(b.string()).describe(`Relationship tags`),includedInViews:V.describe(`Views that include this relationship`),sourceLocation:z}),X=likec4Tool({name:`find-relationships`,annotations:{readOnlyHint:!0,idempotentHint:!0,title:`Find relationships between two elements`},description:`
235
+ `,annotations:{readOnlyHint:!0,idempotentHint:!0,title:`Find relationship paths`},inputSchema:{sourceId:T.string().describe(`Source element FQN`),targetId:T.string().describe(`Target element FQN`),maxDepth:T.number().int().min(1).max(5).optional().default(3).describe(`Maximum path length (default: 3, max: 5)`),includeIndirect:T.boolean().optional().default(!1).describe(`Include indirect (implied) relationships through nested elements (default: false)`),project:J},outputSchema:{paths:T.array(T.object({length:T.number().describe(`Number of hops in the path`),steps:T.array(T.object({source:T.string().describe(`Source element FQN`),target:T.string().describe(`Target element FQN`),relationship:T.object({kind:T.string().nullable().describe(`Relationship kind`),title:T.string().nullable().describe(`Relationship title`),description:T.string().nullable().describe(`Relationship description`),technology:T.string().nullable().describe(`Relationship technology`),tags:T.array(T.string()).describe(`Relationship tags`)})})).describe(`Ordered sequence of relationships in the path`)}))}})(async(e,t)=>{let n=e.projectsManager.ensureProjectId(t.project),r=await e.computedModel(n),i=r.findElement(t.sourceId);m(i,`Source element "${t.sourceId}" not found in project "${n}"`);let a=r.findElement(t.targetId);m(a,`Target element "${t.targetId}" not found in project "${n}"`),m(i.id!==a.id,`Source and target must be different elements`);let s=t.maxDepth,c=t.includeIndirect?`all`:`direct`,l=[{elementId:i.id,path:[],visited:new Set([i.id])}],u=[];for(;l.length>0&&u.length<100;){let e=l.shift();if(e.path.length>=s)continue;let t=r.findElement(e.elementId);if(t)for(let n of t.outgoing(c)){let t=n.target.id;if(t===a.id){let t={source:n.source.id,target:n.target.id,relationship:{kind:n.kind,title:n.title,description:n.description.text,technology:n.technology,tags:[...n.tags]}};if(u.push({length:e.path.length+1,steps:[...e.path,t]}),u.length>=100)break;continue}if(e.visited.has(t))continue;let r={source:n.source.id,target:n.target.id,relationship:{kind:n.kind,title:n.title,description:n.description.text,technology:n.technology,tags:[...n.tags]}};l.push({elementId:t,path:[...e.path,r],visited:new Set([...e.visited,t])})}}return u.sort((e,t)=>e.length-t.length),{paths:u}}),Q=T.object({id:T.string(),title:T.string(),kind:T.string()}),ue=T.object({type:T.enum([`direct`,`indirect`]).describe(`Type of relationship, "direct" for direct relationships, "indirect" for relationships through nested elements`),source:Q,target:Q,kind:T.string().nullable().describe(`Relationship kind`),title:T.string().nullable().describe(`Relationship title`),description:T.string().nullable().describe(`Relationship description`),technology:T.string().nullable().describe(`Relationship technology`),tags:T.array(T.string()).describe(`Relationship tags`),includedInViews:Y.describe(`Views that include this relationship`),sourceLocation:q}),de=likec4Tool({name:`find-relationships`,annotations:{readOnlyHint:!0,idempotentHint:!0,title:`Find relationships between two elements`},description:`
216
236
  Find relationships between two LikeC4 elements within a project.
217
237
 
218
238
  What it does:
@@ -283,7 +303,7 @@ Response:
283
303
  }
284
304
  ]
285
305
  }
286
- `,inputSchema:{element1:b.string().describe(`Element ID (FQN)`),element2:b.string().describe(`Element ID (FQN)`),project:B},outputSchema:{found:b.array(Y)}})(async(e,t)=>{let n=e.projectsManager.ensureProjectId(t.project);if(D(t.element1,t.element2))throw Error(`No relationships possible between parent-child`);let r=[],i=await e.computedModel(n),a=i.findElement(t.element1);E(a,`Element "${t.element1}" not found in project "${n}"`);let o=i.findElement(t.element2);E(o,`Element "${t.element2}" not found in project "${n}"`);let s=mkLocate(e,n),c=w.findConnection(a,o,`both`).flatMap(e=>[...e.relations]);for(let e of c){let t=e.source===a&&e.target===o||e.source===o&&e.target===a;r.push({type:t?`direct`:`indirect`,source:{id:e.source.id,title:e.source.title,kind:e.source.kind},target:{id:e.target.id,title:e.target.title,kind:e.target.kind},kind:e.kind,title:e.title,description:e.description.text,technology:e.technology,tags:[...e.tags],includedInViews:includedInViews(e.views()),sourceLocation:s({relation:e.id})})}return{found:r}}),Z=likec4Tool({name:`list-projects`,description:`
306
+ `,inputSchema:{element1:T.string().describe(`Element ID (FQN)`),element2:T.string().describe(`Element ID (FQN)`),project:J},outputSchema:{found:T.array(ue)}})(async(e,t)=>{let n=e.projectsManager.ensureProjectId(t.project);if(I(t.element1,t.element2))throw Error(`No relationships possible between parent-child`);let r=[],i=await e.computedModel(n),a=i.findElement(t.element1);F(a,`Element "${t.element1}" not found in project "${n}"`);let s=i.findElement(t.element2);F(s,`Element "${t.element2}" not found in project "${n}"`);let c=mkLocate(e,n),l=te.findConnection(a,s,`both`).flatMap(e=>[...e.relations]);for(let e of l){let t=e.source===a&&e.target===s||e.source===s&&e.target===a;r.push({type:t?`direct`:`indirect`,source:{id:e.source.id,title:e.source.title,kind:e.source.kind},target:{id:e.target.id,title:e.target.title,kind:e.target.kind},kind:e.kind,title:e.title,description:e.description.text,technology:e.technology,tags:[...e.tags],includedInViews:includedInViews(e.views()),sourceLocation:c({relation:e.id})})}return{found:r}}),fe=likec4Tool({name:`list-projects`,description:`
287
307
  List LikeC4 projects discoverable in the current workspace.
288
308
 
289
309
  Request:
@@ -316,7 +336,20 @@ Example response:
316
336
  }
317
337
  ]
318
338
  }
319
- `,annotations:{readOnlyHint:!0,idempotentHint:!0,title:`List projects`},inputSchema:{},outputSchema:{projects:b.array(b.object({id:b.string(),title:b.string(),folder:b.string(),sources:b.array(b.string())}))}})(async e=>({projects:e.projects().map(e=>({id:e.id,title:e.title,folder:e.folder.fsPath,sources:e.documents.map(e=>e.fsPath)}))})),Q=b.enum([`exact`,`contains`,`exists`]),te=likec4Tool({name:`query-by-metadata`,description:`
339
+ `,annotations:{readOnlyHint:!0,idempotentHint:!0,title:`List projects`},inputSchema:{},outputSchema:{projects:T.array(T.object({id:T.string(),title:T.string(),folder:T.string(),sources:T.array(T.string())}))}})(async e=>({projects:e.projects().map(e=>({id:e.id,title:e.title,folder:e.folder.fsPath,sources:e.documents.map(e=>e.fsPath)}))}));function _usingCtx(){var e=typeof SuppressedError==`function`?SuppressedError:function(e,t){var n=Error();return n.name=`SuppressedError`,n.error=e,n.suppressed=t,n},t={},n=[];function using(e,t){if(t!=null){if(Object(t)!==t)throw TypeError(`using declarations can only be used with objects, functions, null, or undefined.`);if(e)var r=t[Symbol.asyncDispose||Symbol.for(`Symbol.asyncDispose`)];if(r===void 0&&(r=t[Symbol.dispose||Symbol.for(`Symbol.dispose`)],e))var i=r;if(typeof r!=`function`)throw TypeError(`Object is not disposable.`);i&&(r=function o(){try{i.call(t)}catch(e){return Promise.reject(e)}}),n.push({v:t,d:r,a:e})}else e&&n.push({d:t,a:e});return t}return{e:t,u:using.bind(null,!1),a:using.bind(null,!0),d:function d(){var r,i=this.e,a=0;function next(){for(;r=n.pop();)try{if(!r.a&&a===1)return a=0,n.push(r),Promise.resolve().then(next);if(r.d){var e=r.d.call(r.v);if(r.a)return a|=2,Promise.resolve(e).then(next,err)}else a|=1}catch(e){return err(e)}if(a===1)return i===t?Promise.resolve():Promise.reject(i);if(i!==t)throw i}function err(n){return i=i===t?n:new e(n,i),next()}return next()}}}const pe=/^\s*view\s+([A-Za-z_][\w-]*)/;function extractViewId(e){let t=pe.exec(e);return t?t[1]:null}function wrapAsViewsBlock(e){return`views {\n${e}\n}\n`}function toPortablePath(e){return e.split(s).join(`/`)}function toVirtualSourcePath(e,t,n){let r=toPortablePath(i(e,t));return r===``||r.startsWith(`..`)?n:r}function formatDiagnostics(e){return e.map(e=>`- line ${e.range.start.line+1}, column ${e.range.start.character+1}: ${e.message}`).join(`
340
+ `)}function previewViewTool(e){return O(e,`preview-view`,{title:`Preview View`,description:`Renders a preview of a LikeC4 view defined by DSL text, in the context of an existing project's real elements — without saving anything to disk.
341
+
342
+ Request:
343
+ - dsl: string — a single \`view <id> ... { ... }\` definition. It must reference elements that already exist in the target project.
344
+ - project: string (optional) — project id. Defaults to "default" if omitted.
345
+
346
+ Behavior:
347
+ - The view id must be new (not already present in the project). If the view id matches an existing view, an error is returned — use a different id, or use "render-view" to render an existing view.
348
+ - The view is rendered as a draft alongside the project's real elements.
349
+
350
+ Note: preview styling may not exactly match the real project (custom theme/style extensions aren't applied to the preview). Only \`view <id> ...\` (element view) declarations are recognized for id-detection — a \`dynamic view <id> {...}\` or \`deployment view <id> {...}\` will fail with a generic "could not find a \`view <id>\`" error instead.
351
+
352
+ Use "preview-view" to iterate on a new view definition before creating it for real. Use "render-view" to render a view that's already saved.`,inputSchema:{dsl:T.string().describe("A single `view <id> ... { ... }` LikeC4 DSL definition"),project:J},outputSchema:{id:T.string(),title:T.string(),project:T.string(),view:T.record(T.string(),T.unknown()),model:T.record(T.string(),T.unknown())},annotations:{readOnlyHint:!0,idempotentHint:!0,title:`Preview view`},_meta:{ui:{resourceUri:X}}},async e=>{try{var n=_usingCtx();let r=useLanguageServices(),i=r.projectsManager.ensureProjectId(e.project),a=extractViewId(e.dsl);if(!a)return toolError("Could not find a `view <id> ...` declaration at the start of `dsl`. Example: `view myView of someElement { include * }`");let s=r.project(i);if((await r.computedModel(i))?.findView(a))return toolError(`View "${a}" already exists in the project. Use a different view id for the preview, or use "render-view" to render the existing view.`);let c={};for(let[e,t]of s.documents.entries()){let n=toVirtualSourcePath(s.folder.fsPath,t.fsPath,`seed-${e}.c4`);c[n]=r.documentText(t.toString())??``}let l=`${L()}.c4`;c[l]=wrapAsViewsBlock(e.dsl);let u=n.a(await t(c,{printErrors:!1,throwIfInvalid:!1})),f=u.getErrors();if(f.length>0)return toolError(`Failed to build preview:\n${formatDiagnostics(f)}`);let p=await u.computedModel(),m=p.findView(a);if(!m)return toolError(`View "${a}" was not found after building the preview.`);let h=await u.viewsService.layoutView({viewId:m.id,projectId:i});if(!h)return toolError(`Failed to layout preview view "${a}".`);let g=m.title??m.id;return{content:[{type:`text`,text:`Rendered preview of view "${g}"`}],structuredContent:buildRenderPayload({projectId:i,viewId:m.id,title:g,layoutedView:h.diagram,modelData:p.$data})}}catch(e){n.e=e}finally{await n.d()}}),e}const me=T.enum([`exact`,`contains`,`exists`]),he=likec4Tool({name:`query-by-metadata`,description:`
320
353
  Search elements and deployment nodes by metadata key-value pairs with flexible matching modes.
321
354
 
322
355
  Request:
@@ -382,7 +415,7 @@ Example response:
382
415
  }
383
416
  ]
384
417
  }
385
- `,annotations:{readOnlyHint:!0,idempotentHint:!0,title:`Query by metadata`},inputSchema:{key:b.string().describe(`Metadata key to filter by`),value:b.string().optional().describe(`Metadata value to match (ignored for exists mode)`),matchMode:Q.optional().default(`exact`).describe(`Matching mode`),project:B},outputSchema:{results:b.array(R.extend({matchedValue:b.string().describe(`The metadata value that matched`)}))}})(async(e,t)=>{let n=e.projectsManager.ensureProjectId(t.project),r=await e.computedModel(n),i=t.matchMode,a=[],matches=(e,t,n)=>{let r=Array.isArray(e)?e:[e];switch(n){case`exists`:return!0;case`exact`:return t!==void 0&&r.some(e=>e===t);case`contains`:{if(t===void 0)return!1;let e=t.toLowerCase();return r.some(t=>t.toLowerCase().includes(e))}default:return!1}},getMatchedValue=(e,t,n)=>{let r=Array.isArray(e)?e:[e];if(n===`exists`||t===void 0)return r[0]||``;if(n===`exact`)return r.find(e=>e===t)||r[0]||``;if(n===`contains`){let e=t.toLowerCase();return r.find(t=>t.toLowerCase().includes(e))||r[0]||``}return r[0]||``};for(let e of r.elements()){if(a.length>=50)break;let n=e.getMetadata();if(t.key in n){let r=n[t.key];r!==void 0&&matches(r,t.value,i)&&a.push({...serializeElement(e),matchedValue:getMatchedValue(r,t.value,i)})}}if(a.length<50)for(let e of r.deployment.elements()){if(a.length>=50)break;let n=e.getMetadata();if(t.key in n){let r=n[t.key];r!==void 0&&matches(r,t.value,i)&&a.push({...serializeElement(e),matchedValue:getMatchedValue(r,t.value,i)})}}return{results:a}}),ne=likec4Tool({name:`query-by-tag-pattern`,description:`
418
+ `,annotations:{readOnlyHint:!0,idempotentHint:!0,title:`Query by metadata`},inputSchema:{key:T.string().describe(`Metadata key to filter by`),value:T.string().optional().describe(`Metadata value to match (ignored for exists mode)`),matchMode:me.optional().default(`exact`).describe(`Matching mode`),project:J},outputSchema:{results:T.array(K.extend({matchedValue:T.string().describe(`The metadata value that matched`)}))}})(async(e,t)=>{let n=e.projectsManager.ensureProjectId(t.project),r=await e.computedModel(n),i=t.matchMode,a=[],matches=(e,t,n)=>{let r=Array.isArray(e)?e:[e];switch(n){case`exists`:return!0;case`exact`:return t!==void 0&&r.some(e=>e===t);case`contains`:{if(t===void 0)return!1;let e=t.toLowerCase();return r.some(t=>t.toLowerCase().includes(e))}default:return!1}},getMatchedValue=(e,t,n)=>{let r=Array.isArray(e)?e:[e];if(n===`exists`||t===void 0)return r[0]||``;if(n===`exact`)return r.find(e=>e===t)||r[0]||``;if(n===`contains`){let e=t.toLowerCase();return r.find(t=>t.toLowerCase().includes(e))||r[0]||``}return r[0]||``};for(let e of r.elements()){if(a.length>=50)break;let n=e.getMetadata();if(t.key in n){let r=n[t.key];r!==void 0&&matches(r,t.value,i)&&a.push({...serializeElement(e),matchedValue:getMatchedValue(r,t.value,i)})}}if(a.length<50)for(let e of r.deployment.elements()){if(a.length>=50)break;let n=e.getMetadata();if(t.key in n){let r=n[t.key];r!==void 0&&matches(r,t.value,i)&&a.push({...serializeElement(e),matchedValue:getMatchedValue(r,t.value,i)})}}return{results:a}}),ge=likec4Tool({name:`query-by-tag-pattern`,description:`
386
419
  Search elements by tag patterns using prefix or substring matching.
387
420
  Useful for tag taxonomies with structured naming conventions (e.g., "schedule_*", "*_asil_*").
388
421
 
@@ -437,7 +470,7 @@ Example response:
437
470
  "truncated": false,
438
471
  "matchedTagValues": ["target_asil_qm", "target_asil_asil_b", "target_asil_qm__tbc"]
439
472
  }
440
- `,annotations:{readOnlyHint:!0,idempotentHint:!0,title:`Query by tag pattern`},inputSchema:{pattern:b.string().min(1).describe(`Tag pattern to match`),matchMode:b.enum([`prefix`,`contains`,`suffix`]).optional().default(`prefix`).describe(`Pattern matching mode (default: prefix)`),project:B},outputSchema:{results:b.array(R.extend({matchedTags:b.array(b.string()).describe(`Tags that matched the pattern`)})),truncated:b.boolean().describe(`True if results were truncated`),matchedTagValues:b.array(b.string()).describe(`All unique tag values matching the pattern across all elements`)}})(async(e,t)=>{let n=e.projectsManager.ensureProjectId(t.project),r=await e.computedModel(n),i=t.pattern.toLowerCase(),matchesTag=e=>{let n=e.toLowerCase();switch(t.matchMode){case`prefix`:return n.startsWith(i);case`contains`:return n.includes(i);case`suffix`:return n.endsWith(i)}},a=[],o=!1,s=new Set;for(let e of r.elements()){let t=[...e.tags].filter(matchesTag);if(t.length>0){if(t.forEach(e=>s.add(e)),a.length>=50){o=!0;continue}a.push({...serializeElement(e),matchedTags:t})}}for(let e of r.deployment.elements()){if(!C(e))continue;let t=[...e.tags].filter(matchesTag);if(t.length>0){if(t.forEach(e=>s.add(e)),a.length>=50){o=!0;continue}a.push({...serializeElement(e),matchedTags:t})}}return{results:a,truncated:o,matchedTagValues:[...s].sort((e,t)=>e.localeCompare(t))}}),re=likec4Tool({name:`query-by-tags`,description:`
473
+ `,annotations:{readOnlyHint:!0,idempotentHint:!0,title:`Query by tag pattern`},inputSchema:{pattern:T.string().min(1).describe(`Tag pattern to match`),matchMode:T.enum([`prefix`,`contains`,`suffix`]).optional().default(`prefix`).describe(`Pattern matching mode (default: prefix)`),project:J},outputSchema:{results:T.array(K.extend({matchedTags:T.array(T.string()).describe(`Tags that matched the pattern`)})),truncated:T.boolean().describe(`True if results were truncated`),matchedTagValues:T.array(T.string()).describe(`All unique tag values matching the pattern across all elements`)}})(async(e,t)=>{let n=e.projectsManager.ensureProjectId(t.project),r=await e.computedModel(n),i=t.pattern.toLowerCase(),matchesTag=e=>{let n=e.toLowerCase();switch(t.matchMode){case`prefix`:return n.startsWith(i);case`contains`:return n.includes(i);case`suffix`:return n.endsWith(i)}},a=[],s=!1,c=new Set;for(let e of r.elements()){let t=[...e.tags].filter(matchesTag);if(t.length>0){if(t.forEach(e=>c.add(e)),a.length>=50){s=!0;continue}a.push({...serializeElement(e),matchedTags:t})}}for(let e of r.deployment.elements()){if(!N(e))continue;let t=[...e.tags].filter(matchesTag);if(t.length>0){if(t.forEach(e=>c.add(e)),a.length>=50){s=!0;continue}a.push({...serializeElement(e),matchedTags:t})}}return{results:a,truncated:s,matchedTagValues:[...c].sort((e,t)=>e.localeCompare(t))}}),_e=likec4Tool({name:`query-by-tags`,description:`
441
474
  Advanced tag filtering with boolean logic (AND, OR, NOT).
442
475
 
443
476
  Request:
@@ -501,7 +534,7 @@ Example response:
501
534
  }
502
535
  ]
503
536
  }
504
- `,annotations:{readOnlyHint:!0,idempotentHint:!0,title:`Query by tags`},inputSchema:{allOf:b.array(b.string()).optional().describe(`Element must have ALL these tags (AND)`),anyOf:b.array(b.string()).optional().describe(`Element must have ANY of these tags (OR)`),noneOf:b.array(b.string()).optional().describe(`Element must have NONE of these tags (NOT)`),project:B},outputSchema:{results:b.array(R),truncated:b.boolean().describe(`True if results were truncated due to exceeding the 50-result limit`)}})(async(e,t)=>{l(t.allOf&&t.allOf.length>0||t.anyOf&&t.anyOf.length>0||t.noneOf&&t.noneOf.length>0,`At least one condition (allOf, anyOf, or noneOf) must be specified with at least one tag`);let n=e.projectsManager.ensureProjectId(t.project),r=await e.computedModel(n),i=[],a=!1,matchesTags=e=>{let n=e instanceof Set?e:new Set(e);return!(t.allOf&&t.allOf.length>0&&!t.allOf.every(e=>n.has(e))||t.anyOf&&t.anyOf.length>0&&!t.anyOf.some(e=>n.has(e))||t.noneOf&&t.noneOf.length>0&&t.noneOf.some(e=>n.has(e)))};for(let e of r.elements()){if(i.length>=50){a=!0;break}matchesTags(e.tags)&&i.push(serializeElement(e))}if(!a)for(let e of r.deployment.elements()){if(i.length>=50){a=!0;break}C(e)&&matchesTags(e.tags)&&i.push(serializeElement(e))}return{results:i,truncated:a}}),ie=b.enum([`ancestors`,`descendants`,`siblings`,`children`,`parent`,`incomers`,`outgoers`]),ae=likec4Tool({name:`query-graph`,description:`
537
+ `,annotations:{readOnlyHint:!0,idempotentHint:!0,title:`Query by tags`},inputSchema:{allOf:T.array(T.string()).optional().describe(`Element must have ALL these tags (AND)`),anyOf:T.array(T.string()).optional().describe(`Element must have ANY of these tags (OR)`),noneOf:T.array(T.string()).optional().describe(`Element must have NONE of these tags (NOT)`),project:J},outputSchema:{results:T.array(K),truncated:T.boolean().describe(`True if results were truncated due to exceeding the 50-result limit`)}})(async(e,t)=>{m(t.allOf&&t.allOf.length>0||t.anyOf&&t.anyOf.length>0||t.noneOf&&t.noneOf.length>0,`At least one condition (allOf, anyOf, or noneOf) must be specified with at least one tag`);let n=e.projectsManager.ensureProjectId(t.project),r=await e.computedModel(n),i=[],a=!1,matchesTags=e=>{let n=e instanceof Set?e:new Set(e);return!(t.allOf&&t.allOf.length>0&&!t.allOf.every(e=>n.has(e))||t.anyOf&&t.anyOf.length>0&&!t.anyOf.some(e=>n.has(e))||t.noneOf&&t.noneOf.length>0&&t.noneOf.some(e=>n.has(e)))};for(let e of r.elements()){if(i.length>=50){a=!0;break}matchesTags(e.tags)&&i.push(serializeElement(e))}if(!a)for(let e of r.deployment.elements()){if(i.length>=50){a=!0;break}N(e)&&matchesTags(e.tags)&&i.push(serializeElement(e))}return{results:i,truncated:a}}),ve=T.enum([`ancestors`,`descendants`,`siblings`,`children`,`parent`,`incomers`,`outgoers`]),ye=likec4Tool({name:`query-graph`,description:`
505
538
  Query element hierarchy and relationships in the architecture graph.
506
539
 
507
540
  Request:
@@ -573,7 +606,7 @@ Example response:
573
606
  ],
574
607
  "truncated": false
575
608
  }
576
- `,annotations:{readOnlyHint:!0,idempotentHint:!0,title:`Query element graph`},inputSchema:{elementId:b.string().describe(`Element id (FQN) to query`),queryType:ie.describe(`Type of graph query`),includeIndirect:b.boolean().optional().default(!0).describe(`For incomers/outgoers: include indirect relationships (default: true)`),project:B},outputSchema:{results:b.array(R),truncated:b.boolean().describe(`True if results were truncated due to exceeding maximum limit`)}})(async(e,t)=>{let n=e.projectsManager.ensureProjectId(t.project),r=(await e.computedModel(n)).findElement(t.elementId);l(r,`Element "${t.elementId}" not found in project "${n}"`);let i=[],a=!1;switch(t.queryType){case`ancestors`:for(let e of r.ancestors()){if(i.length>=100){a=!0;break}i.push(serializeElement(e))}break;case`descendants`:for(let e of r.descendants()){if(i.length>=100){a=!0;break}i.push(serializeElement(e))}break;case`siblings`:for(let e of r.siblings()){if(i.length>=100){a=!0;break}i.push(serializeElement(e))}break;case`children`:for(let e of r.children()){if(i.length>=100){a=!0;break}i.push(serializeElement(e))}break;case`parent`:{let e=r.parent;e&&i.push(serializeElement(e));break}case`incomers`:{let e=t.includeIndirect?`all`:`direct`;for(let t of r.incomers(e)){if(i.length>=100){a=!0;break}i.push(serializeElement(t))}break}case`outgoers`:{let e=t.includeIndirect?`all`:`direct`;for(let t of r.outgoers(e)){if(i.length>=100){a=!0;break}i.push(serializeElement(t))}break}}return{results:i,truncated:a}}),oe=b.object({elementId:b.string().describe(`ID of the incoming element`),relationshipLabel:b.string().optional().describe(`Label on the relationship`),technology:b.string().optional().describe(`Technology specified on the relationship`)}),se=likec4Tool({name:`query-incomers-graph`,description:`
609
+ `,annotations:{readOnlyHint:!0,idempotentHint:!0,title:`Query element graph`},inputSchema:{elementId:T.string().describe(`Element id (FQN) to query`),queryType:ve.describe(`Type of graph query`),includeIndirect:T.boolean().optional().default(!0).describe(`For incomers/outgoers: include indirect relationships (default: true)`),project:J},outputSchema:{results:T.array(K),truncated:T.boolean().describe(`True if results were truncated due to exceeding maximum limit`)}})(async(e,t)=>{let n=e.projectsManager.ensureProjectId(t.project),r=(await e.computedModel(n)).findElement(t.elementId);m(r,`Element "${t.elementId}" not found in project "${n}"`);let i=[],a=!1;switch(t.queryType){case`ancestors`:for(let e of r.ancestors()){if(i.length>=100){a=!0;break}i.push(serializeElement(e))}break;case`descendants`:for(let e of r.descendants()){if(i.length>=100){a=!0;break}i.push(serializeElement(e))}break;case`siblings`:for(let e of r.siblings()){if(i.length>=100){a=!0;break}i.push(serializeElement(e))}break;case`children`:for(let e of r.children()){if(i.length>=100){a=!0;break}i.push(serializeElement(e))}break;case`parent`:{let e=r.parent;e&&i.push(serializeElement(e));break}case`incomers`:{let e=t.includeIndirect?`all`:`direct`;for(let t of r.incomers(e)){if(i.length>=100){a=!0;break}i.push(serializeElement(t))}break}case`outgoers`:{let e=t.includeIndirect?`all`:`direct`;for(let t of r.outgoers(e)){if(i.length>=100){a=!0;break}i.push(serializeElement(t))}break}}return{results:i,truncated:a}}),be=T.object({elementId:T.string().describe(`ID of the incoming element`),relationshipLabel:T.string().optional().describe(`Label on the relationship`),technology:T.string().optional().describe(`Technology specified on the relationship`)}),xe=likec4Tool({name:`query-incomers-graph`,description:`
577
610
  Query the complete graph of all elements that provide input to the target element (recursive incomers/producers).
578
611
 
579
612
  This tool performs a breadth-first traversal to discover all upstream dependencies - elements that directly or
@@ -630,7 +663,7 @@ Notes:
630
663
  Example:
631
664
  For a database element, this returns all services, APIs, and components that write to it,
632
665
  plus all their dependencies, recursively up to maxDepth levels.
633
- `,annotations:{readOnlyHint:!0,idempotentHint:!0,title:`Query complete incomers graph`},inputSchema:{elementId:b.string().describe(`Target element id (FQN) to query incomers for`),includeIndirect:b.boolean().optional().default(!0).describe(`Include indirect relationships through nested elements (default: true)`),maxDepth:b.number().int().positive().max(50).optional().default(10).describe(`Maximum traversal depth (default: 10, max: 50)`),maxNodes:b.number().int().positive().max(2e3).optional().default(200).describe(`Maximum number of nodes to return (default: 200, max: 2000)`),project:B},outputSchema:{target:b.string().describe(`Target element id`),totalNodes:b.number().describe(`Total number of nodes in the graph`),maxDepth:b.number().describe(`Maximum depth reached`),truncated:b.boolean().describe(`True if result was truncated due to maxNodes limit`),nodes:b.record(R.extend({incomers:b.array(oe).describe(`Incoming relationships with details`),depth:b.number().describe(`Distance from target element (0 = target)`)}))}})(async(e,t)=>{let n=e.projectsManager.ensureProjectId(t.project),r=await e.computedModel(n);l(r.findElement(t.elementId),`Element "${t.elementId}" not found in project "${n}"`);let i=t.includeIndirect?`all`:`direct`,a=traverseGraph(r,t.elementId,`incoming`,i,t.maxDepth,t.maxNodes),o={};for(let[e,t]of Object.entries(a.nodes)){let{neighbors:n,...r}=t;o[e]={...r,incomers:n}}return{target:a.target,totalNodes:a.totalNodes,maxDepth:a.maxDepth,truncated:a.truncated,nodes:o}}),ce=b.object({elementId:b.string().describe(`ID of the outgoing element`),relationshipLabel:b.string().optional().describe(`Label on the relationship`),technology:b.string().optional().describe(`Technology specified on the relationship`)}),le=likec4Tool({name:`query-outgoers-graph`,description:`
666
+ `,annotations:{readOnlyHint:!0,idempotentHint:!0,title:`Query complete incomers graph`},inputSchema:{elementId:T.string().describe(`Target element id (FQN) to query incomers for`),includeIndirect:T.boolean().optional().default(!0).describe(`Include indirect relationships through nested elements (default: true)`),maxDepth:T.number().int().positive().max(50).optional().default(10).describe(`Maximum traversal depth (default: 10, max: 50)`),maxNodes:T.number().int().positive().max(2e3).optional().default(200).describe(`Maximum number of nodes to return (default: 200, max: 2000)`),project:J},outputSchema:{target:T.string().describe(`Target element id`),totalNodes:T.number().describe(`Total number of nodes in the graph`),maxDepth:T.number().describe(`Maximum depth reached`),truncated:T.boolean().describe(`True if result was truncated due to maxNodes limit`),nodes:T.record(K.extend({incomers:T.array(be).describe(`Incoming relationships with details`),depth:T.number().describe(`Distance from target element (0 = target)`)}))}})(async(e,t)=>{let n=e.projectsManager.ensureProjectId(t.project),r=await e.computedModel(n),i=r.findElement(t.elementId);m(i,`Element "${t.elementId}" not found in project "${n}"`);let a=t.includeIndirect?`all`:`direct`,s=traverseGraph(r,t.elementId,`incoming`,a,t.maxDepth,t.maxNodes),c={};for(let[e,t]of Object.entries(s.nodes)){let{neighbors:n,...r}=t;c[e]={...r,incomers:n}}return{target:s.target,totalNodes:s.totalNodes,maxDepth:s.maxDepth,truncated:s.truncated,nodes:c}}),Se=T.object({elementId:T.string().describe(`ID of the outgoing element`),relationshipLabel:T.string().optional().describe(`Label on the relationship`),technology:T.string().optional().describe(`Technology specified on the relationship`)}),$=likec4Tool({name:`query-outgoers-graph`,description:`
634
667
  Query the complete graph of all elements that receive output from the target element (recursive outgoers/consumers).
635
668
 
636
669
  This tool performs a breadth-first traversal to discover all downstream dependencies - elements that directly or
@@ -687,7 +720,7 @@ Notes:
687
720
  Example:
688
721
  For an API service, this returns all clients, services, and systems that consume its output,
689
722
  plus all their consumers, recursively up to maxDepth levels.
690
- `,annotations:{readOnlyHint:!0,idempotentHint:!0,title:`Query complete outgoers graph`},inputSchema:{elementId:b.string().describe(`Target element id (FQN) to query outgoers for`),includeIndirect:b.boolean().optional().default(!0).describe(`Include indirect relationships through nested elements (default: true)`),maxDepth:b.number().int().positive().max(50).optional().default(10).describe(`Maximum traversal depth (default: 10, max: 50)`),maxNodes:b.number().int().positive().max(2e3).optional().default(200).describe(`Maximum number of nodes to return (default: 200, max: 2000)`),project:B},outputSchema:{target:b.string().describe(`Target element id`),totalNodes:b.number().describe(`Total number of nodes in the graph`),maxDepth:b.number().describe(`Maximum depth reached`),truncated:b.boolean().describe(`True if result was truncated due to maxNodes limit`),nodes:b.record(R.extend({outgoers:b.array(ce).describe(`Outgoing relationships with details`),depth:b.number().describe(`Distance from target element (0 = target)`)}))}})(async(e,t)=>{let n=e.projectsManager.ensureProjectId(t.project),r=await e.computedModel(n);l(r.findElement(t.elementId),`Element "${t.elementId}" not found in project "${n}"`);let i=t.includeIndirect?`all`:`direct`,a=traverseGraph(r,t.elementId,`outgoing`,i,t.maxDepth,t.maxNodes),o={};for(let[e,t]of Object.entries(a.nodes)){let{neighbors:n,...r}=t;o[e]={...r,outgoers:n}}return{target:a.target,totalNodes:a.totalNodes,maxDepth:a.maxDepth,truncated:a.truncated,nodes:o}}),ue=likec4Tool({name:`read-deployment`,description:`
723
+ `,annotations:{readOnlyHint:!0,idempotentHint:!0,title:`Query complete outgoers graph`},inputSchema:{elementId:T.string().describe(`Target element id (FQN) to query outgoers for`),includeIndirect:T.boolean().optional().default(!0).describe(`Include indirect relationships through nested elements (default: true)`),maxDepth:T.number().int().positive().max(50).optional().default(10).describe(`Maximum traversal depth (default: 10, max: 50)`),maxNodes:T.number().int().positive().max(2e3).optional().default(200).describe(`Maximum number of nodes to return (default: 200, max: 2000)`),project:J},outputSchema:{target:T.string().describe(`Target element id`),totalNodes:T.number().describe(`Total number of nodes in the graph`),maxDepth:T.number().describe(`Maximum depth reached`),truncated:T.boolean().describe(`True if result was truncated due to maxNodes limit`),nodes:T.record(K.extend({outgoers:T.array(Se).describe(`Outgoing relationships with details`),depth:T.number().describe(`Distance from target element (0 = target)`)}))}})(async(e,t)=>{let n=e.projectsManager.ensureProjectId(t.project),r=await e.computedModel(n),i=r.findElement(t.elementId);m(i,`Element "${t.elementId}" not found in project "${n}"`);let a=t.includeIndirect?`all`:`direct`,s=traverseGraph(r,t.elementId,`outgoing`,a,t.maxDepth,t.maxNodes),c={};for(let[e,t]of Object.entries(s.nodes)){let{neighbors:n,...r}=t;c[e]={...r,outgoers:n}}return{target:s.target,totalNodes:s.totalNodes,maxDepth:s.maxDepth,truncated:s.truncated,nodes:c}}),Ce=likec4Tool({name:`read-deployment`,description:`
691
724
  Read details about a deployment node or a deployed instance in a LikeC4 project.
692
725
 
693
726
  What it does:
@@ -752,7 +785,7 @@ Example response (deployed instance):
752
785
  "range": { "start": { "line": 10, "character": 0 }, "end": { "line": 25, "character": 0 } }
753
786
  }
754
787
  }
755
- `,annotations:{readOnlyHint:!0,idempotentHint:!0,title:`Read deployment entity`},inputSchema:{id:b.string().describe(`Deployment id (FQN)`),project:B},outputSchema:{type:b.enum([`deployment-node`,`deployed-instance`]),id:b.string().describe(`Deployment id (FQN)`),kind:b.string().describe(`Deployment node kind, or element kind for deployed instances`),name:b.string(),title:b.string(),description:b.string().nullable(),technology:b.string().nullable(),tags:b.array(b.string()),project:b.string(),metadata:b.record(b.union([b.string(),b.array(b.string())])),links:b.array(b.object({title:b.string().nullable().describe(`Optional link title`),url:b.string().describe(`Link URL`),relative:b.string().nullable().describe(`Relative path (if URL is relative to workspace root)`)})).describe(`External links associated with this deployment entity`),shape:b.string(),color:b.string(),children:b.array(b.string()).describe(`Children of this deployment node (Array of Deployment ids)`),includedInViews:V.describe(`Views that include this deployment node`),instanceof:b.object({id:b.string().describe(`Element ID (FQN)`),title:b.string(),kind:b.string()}).nullable().describe(`If type is "deployed-instance", the referenced element`),sourceLocation:z}})(async(e,t)=>{let n=e.projectsManager.ensureProjectId(t.project),r=(await e.computedModel(n)).deployment.findElement(t.id);l(r,`Deployment entity "${t.id}" not found in project "${n}"`);let i=mkLocate(e,n);return{type:r.isInstance()?`deployed-instance`:`deployment-node`,id:r.id,name:r.name,kind:r.kind,title:r.title,description:r.description.text,technology:r.technology,tags:[...r.tags],project:n,metadata:r.getMetadata(),links:(r.links??[]).map(e=>({title:e.title??null,url:e.url,relative:e.relative??null})),shape:r.shape,color:r.color,children:r.isInstance()?[]:[...r.children()].map(e=>e.id),includedInViews:includedInViews(r.views()),instanceof:r.isInstance()?{id:r.element.id,title:r.element.title,kind:r.element.kind}:null,sourceLocation:i({deployment:r.id})}}),de=likec4Tool({name:`read-element`,description:`
788
+ `,annotations:{readOnlyHint:!0,idempotentHint:!0,title:`Read deployment entity`},inputSchema:{id:T.string().describe(`Deployment id (FQN)`),project:J},outputSchema:{type:T.enum([`deployment-node`,`deployed-instance`]),id:T.string().describe(`Deployment id (FQN)`),kind:T.string().describe(`Deployment node kind, or element kind for deployed instances`),name:T.string(),title:T.string(),description:T.string().nullable(),technology:T.string().nullable(),tags:T.array(T.string()),project:T.string(),metadata:T.record(T.union([T.string(),T.array(T.string())])),links:T.array(T.object({title:T.string().nullable().describe(`Optional link title`),url:T.string().describe(`Link URL`),relative:T.string().nullable().describe(`Relative path (if URL is relative to workspace root)`)})).describe(`External links associated with this deployment entity`),shape:T.string(),color:T.string(),children:T.array(T.string()).describe(`Children of this deployment node (Array of Deployment ids)`),includedInViews:Y.describe(`Views that include this deployment node`),instanceof:T.object({id:T.string().describe(`Element ID (FQN)`),title:T.string(),kind:T.string()}).nullable().describe(`If type is "deployed-instance", the referenced element`),sourceLocation:q}})(async(e,t)=>{let n=e.projectsManager.ensureProjectId(t.project),r=(await e.computedModel(n)).deployment.findElement(t.id);m(r,`Deployment entity "${t.id}" not found in project "${n}"`);let i=mkLocate(e,n);return{type:r.isInstance()?`deployed-instance`:`deployment-node`,id:r.id,name:r.name,kind:r.kind,title:r.title,description:r.description.text,technology:r.technology,tags:[...r.tags],project:n,metadata:r.getMetadata(),links:(r.links??[]).map(e=>({title:e.title??null,url:e.url,relative:e.relative??null})),shape:r.shape,color:r.color,children:r.isInstance()?[]:[...r.children()].map(e=>e.id),includedInViews:includedInViews(r.views()),instanceof:r.isInstance()?{id:r.element.id,title:r.element.title,kind:r.element.kind}:null,sourceLocation:i({deployment:r.id})}}),we=likec4Tool({name:`read-element`,description:`
756
789
  Read detailed information about a LikeC4 element.
757
790
 
758
791
  Request:
@@ -839,7 +872,7 @@ Example response:
839
872
  "range": { "start": { "line": 10, "character": 0 }, "end": { "line": 25, "character": 0 } }
840
873
  }
841
874
  }
842
- `,annotations:{readOnlyHint:!0,idempotentHint:!0,title:`Read element`},inputSchema:{id:b.string().describe(`Element id (FQN)`),project:B},outputSchema:{id:b.string().describe(`Element id (FQN)`),kind:b.string().describe(`Element kind`),name:b.string().describe(`Element name`),title:b.string(),description:b.string().nullable(),technology:b.string().nullable(),tags:b.array(b.string()),project:b.string(),metadata:b.record(b.union([b.string(),b.array(b.string())])),links:b.array(b.object({title:b.string().nullable().describe(`Optional link title`),url:b.string().describe(`Link URL`),relative:b.string().nullable().describe(`Relative path (if URL is relative to workspace root)`)})).describe(`External links associated with this element`),shape:b.string(),color:b.string(),children:b.array(b.string()).describe(`Children of this element (Array of FQNs)`),defaultView:b.string().nullable().describe(`Name of the default view of this element`),includedInViews:V.describe(`Views that include this element`),relationships:b.object({incoming:b.array(b.object({source:b.object({id:b.string(),title:b.string(),kind:b.string()}).describe(`Source element of this relationship`),kind:b.string().nullable().describe(`Relationship kind`),target:b.string().describe(`Target element id (FQN), either this element or nested element, if relationship is indirect`),title:b.string().nullable().describe(`Relationship title`),description:b.string().nullable().describe(`Relationship description`),technology:b.string().nullable().describe(`Relationship technology`),tags:b.array(b.string()).describe(`Relationship tags`)})).describe(`Incoming relationships of this element (direct and indirect, incoming to nested elements)`),outgoing:b.array(b.object({source:b.string().describe(`Source element id (FQN), either this element or nested element, if relationship is indirect`),target:b.object({id:b.string(),title:b.string(),kind:b.string()}).describe(`Target element of this relationship`),kind:b.string().nullable().describe(`Relationship kind`),title:b.string().nullable().describe(`Relationship title`),description:b.string().nullable().describe(`Relationship description`),technology:b.string().nullable().describe(`Relationship technology`),tags:b.array(b.string()).describe(`Relationship tags`)})).describe(`Outgoing relationships of this element (direct and indirect, outgoing from nested elements)`)}).describe(`Relationships of this element`),deployedInstances:b.array(b.string()).describe(`Deployed instances of this element (Array of Deployment FQNs)`),sourceLocation:z}})(async(e,t)=>{let n=e.projectsManager.ensureProjectId(t.project),r=(await e.computedModel(n)).findElement(t.id);l(r,`Element "${t.id}" not found in project "${n}"`);let i=mkLocate(e,n);return{id:r.id,name:r.name,kind:r.kind,title:r.title,description:r.description.text,technology:r.technology,tags:[...r.tags],project:n,metadata:r.getMetadata(),links:(r.links??[]).map(e=>({title:e.title??null,url:e.url,relative:e.relative??null})),shape:r.shape,color:r.color,children:[...r.children()].map(e=>e.id),defaultView:r.defaultView?.id||null,includedInViews:includedInViews(r.views()),relationships:{incoming:[...r.incoming()].map(e=>({source:{id:e.source.id,title:e.source.title,kind:e.source.kind},kind:e.kind,target:e.target.id,title:e.title,description:e.description.text,technology:e.technology,tags:[...e.tags]})),outgoing:[...r.outgoing()].map(e=>({source:e.source.id,target:{id:e.target.id,title:e.target.title,kind:e.target.kind},kind:e.kind,title:e.title,description:e.description.text,technology:e.technology,tags:[...e.tags]}))},deployedInstances:[...r.deployments()].map(e=>e.id),sourceLocation:i({element:r.id})}}),$=likec4Tool({name:`read-project-summary`,annotations:{readOnlyHint:!0,idempotentHint:!0,title:`Read project summary`},description:`
875
+ `,annotations:{readOnlyHint:!0,idempotentHint:!0,title:`Read element`},inputSchema:{id:T.string().describe(`Element id (FQN)`),project:J},outputSchema:{id:T.string().describe(`Element id (FQN)`),kind:T.string().describe(`Element kind`),name:T.string().describe(`Element name`),title:T.string(),description:T.string().nullable(),technology:T.string().nullable(),tags:T.array(T.string()),project:T.string(),metadata:T.record(T.union([T.string(),T.array(T.string())])),links:T.array(T.object({title:T.string().nullable().describe(`Optional link title`),url:T.string().describe(`Link URL`),relative:T.string().nullable().describe(`Relative path (if URL is relative to workspace root)`)})).describe(`External links associated with this element`),shape:T.string(),color:T.string(),children:T.array(T.string()).describe(`Children of this element (Array of FQNs)`),defaultView:T.string().nullable().describe(`Name of the default view of this element`),includedInViews:Y.describe(`Views that include this element`),relationships:T.object({incoming:T.array(T.object({source:T.object({id:T.string(),title:T.string(),kind:T.string()}).describe(`Source element of this relationship`),kind:T.string().nullable().describe(`Relationship kind`),target:T.string().describe(`Target element id (FQN), either this element or nested element, if relationship is indirect`),title:T.string().nullable().describe(`Relationship title`),description:T.string().nullable().describe(`Relationship description`),technology:T.string().nullable().describe(`Relationship technology`),tags:T.array(T.string()).describe(`Relationship tags`)})).describe(`Incoming relationships of this element (direct and indirect, incoming to nested elements)`),outgoing:T.array(T.object({source:T.string().describe(`Source element id (FQN), either this element or nested element, if relationship is indirect`),target:T.object({id:T.string(),title:T.string(),kind:T.string()}).describe(`Target element of this relationship`),kind:T.string().nullable().describe(`Relationship kind`),title:T.string().nullable().describe(`Relationship title`),description:T.string().nullable().describe(`Relationship description`),technology:T.string().nullable().describe(`Relationship technology`),tags:T.array(T.string()).describe(`Relationship tags`)})).describe(`Outgoing relationships of this element (direct and indirect, outgoing from nested elements)`)}).describe(`Relationships of this element`),deployedInstances:T.array(T.string()).describe(`Deployed instances of this element (Array of Deployment FQNs)`),sourceLocation:q}})(async(e,t)=>{let n=e.projectsManager.ensureProjectId(t.project),r=(await e.computedModel(n)).findElement(t.id);m(r,`Element "${t.id}" not found in project "${n}"`);let i=mkLocate(e,n);return{id:r.id,name:r.name,kind:r.kind,title:r.title,description:r.description.text,technology:r.technology,tags:[...r.tags],project:n,metadata:r.getMetadata(),links:(r.links??[]).map(e=>({title:e.title??null,url:e.url,relative:e.relative??null})),shape:r.shape,color:r.color,children:[...r.children()].map(e=>e.id),defaultView:r.defaultView?.id||null,includedInViews:includedInViews(r.views()),relationships:{incoming:[...r.incoming()].map(e=>({source:{id:e.source.id,title:e.source.title,kind:e.source.kind},kind:e.kind,target:e.target.id,title:e.title,description:e.description.text,technology:e.technology,tags:[...e.tags]})),outgoing:[...r.outgoing()].map(e=>({source:e.source.id,target:{id:e.target.id,title:e.target.title,kind:e.target.kind},kind:e.kind,title:e.title,description:e.description.text,technology:e.technology,tags:[...e.tags]}))},deployedInstances:[...r.deployments()].map(e=>e.id),sourceLocation:i({element:r.id})}}),Te=likec4Tool({name:`read-project-summary`,annotations:{readOnlyHint:!0,idempotentHint:!0,title:`Read project summary`},description:`
843
876
  Request:
844
877
  - project: string (optional) — project id. Defaults to "default" if omitted.
845
878
 
@@ -930,7 +963,7 @@ Example response:
930
963
  }
931
964
  ]
932
965
  }
933
- `,inputSchema:{project:B},outputSchema:{title:b.string(),folder:b.string(),sources:b.array(b.string()),config:L.describe(`Project configuration`),specification:b.object({elementKinds:b.array(b.string()),relationshipKinds:b.array(b.string()),deploymentKinds:b.array(b.string()),tags:b.array(b.string()),metadataKeys:b.array(b.string())}),elements:b.array(b.object({id:b.string(),kind:b.string(),title:b.string(),tags:b.array(b.string())})).describe(`List of elements in the project`),deployments:b.array(b.discriminatedUnion(`type`,[b.object({type:b.literal(`deployment-node`),id:b.string().describe(`Node ID`),kind:b.string().describe(`Deployment node kind`),title:b.string().describe(`Node title`),tags:b.array(b.string())}),b.object({type:b.literal(`deployed-instance`),id:b.string().describe(`Node ID`),title:b.string().describe(`Node title`),tags:b.array(b.string()),referencedElementId:b.string().describe(`Element ID (FQN)`)})])).describe(`List of deployment nodes and deployed instances in the project`),views:b.array(b.object({id:b.string(),title:b.string(),type:b.enum([`element`,`deployment`,`dynamic`])}))}})(async(e,t)=>{let n=e.projectsManager.ensureProjectId(t.project),r=e.project(n),i=await e.computedModel(n);return{title:r.title,folder:r.folder.fsPath,sources:r.documents?.map(e=>e.fsPath)??[],config:serializeConfig(r.config),specification:{elementKinds:p(i.specification.elements),relationshipKinds:p(i.specification.relationships),deploymentKinds:p(i.specification.deployments),tags:[...i.tags],metadataKeys:i.specification.metadataKeys??[]},elements:[...i.elements()].filter(e=>!e.imported).map(e=>({id:e.id,kind:e.kind,title:e.title,tags:[...e.tags]})),deployments:[...i.deployment.elements()].map(e=>e.isInstance()?{type:`deployed-instance`,id:e.id,title:e.title,tags:[...e.tags],referencedElementId:e.element.id}:{type:`deployment-node`,id:e.id,kind:e.kind,title:e.title,tags:[...e.tags]}),views:[...i.views()].map(e=>({id:e.id,title:e.titleOrId,type:e.$view._type}))}}),modelRef=e=>e.hasElement()?e.element.id:e.hasDeployment()?e.deployment.id:null,fe=b.discriminatedUnion(`type`,[b.object({type:b.literal(`element`),id:b.string().describe(`Node ID`),elementId:b.string().describe(`Element ID (FQN)`),kind:b.string().describe(`Element kind`),title:b.string().describe(`Node title`),description:b.string().nullable(),technology:b.string().nullable(),children:b.array(b.string()).describe(`Children nodes, array of node IDs`),shape:b.string().describe(`Rendered shape`),color:b.string().describe(`Rendered color`),tags:b.array(b.string())}),b.object({type:b.literal(`deployment-node`),id:b.string().describe(`Node ID`),deploymentId:b.string().describe(`Deployment entity ID (FQN)`),kind:b.string().describe(`Deployment kind`),title:b.string().describe(`Node title`),description:b.string().nullable(),technology:b.string().nullable(),children:b.array(b.string()).describe(`Children nodes, array of node IDs`),shape:b.string().describe(`Rendered shape`),color:b.string().describe(`Rendered color`),tags:b.array(b.string())}),b.object({type:b.literal(`deployed-instance`),id:b.string().describe(`Node ID`),deploymentId:b.string().describe(`Deployment entity ID (FQN)`),title:b.string().describe(`Node title`),description:b.string().nullable(),technology:b.string().nullable(),referencedElement:b.object({id:b.string().describe(`Element ID (FQN)`),kind:b.string().describe(`Element kind`),title:b.string().describe(`Element title`)}),shape:b.string().describe(`Rendered shape`),color:b.string().describe(`Rendered color`),tags:b.array(b.string())})]),pe=likec4Tool({name:`read-view`,description:`
966
+ `,inputSchema:{project:J},outputSchema:{title:T.string(),folder:T.string(),sources:T.array(T.string()),config:G.describe(`Project configuration`),specification:T.object({elementKinds:T.array(T.string()),relationshipKinds:T.array(T.string()),deploymentKinds:T.array(T.string()),tags:T.array(T.string()),metadataKeys:T.array(T.string())}),elements:T.array(T.object({id:T.string(),kind:T.string(),title:T.string(),tags:T.array(T.string())})).describe(`List of elements in the project`),deployments:T.array(T.discriminatedUnion(`type`,[T.object({type:T.literal(`deployment-node`),id:T.string().describe(`Node ID`),kind:T.string().describe(`Deployment node kind`),title:T.string().describe(`Node title`),tags:T.array(T.string())}),T.object({type:T.literal(`deployed-instance`),id:T.string().describe(`Node ID`),title:T.string().describe(`Node title`),tags:T.array(T.string()),referencedElementId:T.string().describe(`Element ID (FQN)`)})])).describe(`List of deployment nodes and deployed instances in the project`),views:T.array(T.object({id:T.string(),title:T.string(),type:T.enum([`element`,`deployment`,`dynamic`])}))}})(async(e,t)=>{let n=e.projectsManager.ensureProjectId(t.project),r=e.project(n),i=await e.computedModel(n);return{title:r.title,folder:r.folder.fsPath,sources:r.documents?.map(e=>e.fsPath)??[],config:serializeConfig(r.config),specification:{elementKinds:v(i.specification.elements),relationshipKinds:v(i.specification.relationships),deploymentKinds:v(i.specification.deployments),tags:[...i.tags],metadataKeys:i.specification.metadataKeys??[]},elements:[...i.elements()].filter(e=>!e.imported).map(e=>({id:e.id,kind:e.kind,title:e.title,tags:[...e.tags]})),deployments:[...i.deployment.elements()].map(e=>e.isInstance()?{type:`deployed-instance`,id:e.id,title:e.title,tags:[...e.tags],referencedElementId:e.element.id}:{type:`deployment-node`,id:e.id,kind:e.kind,title:e.title,tags:[...e.tags]}),views:[...i.views()].map(e=>({id:e.id,title:e.titleOrId,type:e.$view._type}))}}),modelRef=e=>e.hasElement()?e.element.id:e.hasDeployment()?e.deployment.id:null,Ee=T.discriminatedUnion(`type`,[T.object({type:T.literal(`element`),id:T.string().describe(`Node ID`),elementId:T.string().describe(`Element ID (FQN)`),kind:T.string().describe(`Element kind`),title:T.string().describe(`Node title`),description:T.string().nullable(),technology:T.string().nullable(),children:T.array(T.string()).describe(`Children nodes, array of node IDs`),shape:T.string().describe(`Rendered shape`),color:T.string().describe(`Rendered color`),tags:T.array(T.string())}),T.object({type:T.literal(`deployment-node`),id:T.string().describe(`Node ID`),deploymentId:T.string().describe(`Deployment entity ID (FQN)`),kind:T.string().describe(`Deployment kind`),title:T.string().describe(`Node title`),description:T.string().nullable(),technology:T.string().nullable(),children:T.array(T.string()).describe(`Children nodes, array of node IDs`),shape:T.string().describe(`Rendered shape`),color:T.string().describe(`Rendered color`),tags:T.array(T.string())}),T.object({type:T.literal(`deployed-instance`),id:T.string().describe(`Node ID`),deploymentId:T.string().describe(`Deployment entity ID (FQN)`),title:T.string().describe(`Node title`),description:T.string().nullable(),technology:T.string().nullable(),referencedElement:T.object({id:T.string().describe(`Element ID (FQN)`),kind:T.string().describe(`Element kind`),title:T.string().describe(`Element title`)}),shape:T.string().describe(`Rendered shape`),color:T.string().describe(`Rendered color`),tags:T.array(T.string())})]),De=likec4Tool({name:`read-view`,description:`
934
967
  Read detailed information about a LikeC4 view.
935
968
 
936
969
  Request:
@@ -978,7 +1011,7 @@ Example response:
978
1011
  "range": { "start": { "line": 10, "character": 0 }, "end": { "line": 30, "character": 0 } }
979
1012
  }
980
1013
  }
981
- `,annotations:{readOnlyHint:!0,idempotentHint:!0,title:`Read view`},inputSchema:{viewId:b.string().describe(`View id (name)`),project:B},outputSchema:{id:b.string(),type:b.enum([`element`,`deployment`,`dynamic`]).describe(`View type`),title:b.string(),description:b.string().nullable(),tags:b.array(b.string()),project:b.string(),nodes:b.array(fe),edges:b.array(b.object({source:b.string().describe(`Source node`),target:b.string().describe(`Target node`),label:b.string().nullable(),description:b.string().nullable(),technology:b.string().nullable(),tags:b.array(b.string())})).describe(`Edge represents relationship between nodes`),sourceLocation:z}})(async(e,t)=>{let n=e.projectsManager.ensureProjectId(t.project),r=e.project(n),i=(await e.computedModel(n)).findView(t.viewId);if(!i)throw Error(`View with ID '${t.viewId}' not found in project ${r.id}`);let a=mkLocate(e,r.id);return{id:i.id,type:i.$view._type,title:i.title??i.id,description:i.description.text,tags:[...i.tags],project:r.id,nodes:[...i.nodes()].flatMap(e=>{let t={id:e.id,title:e.title,description:e.description.text,technology:e.technology,shape:e.shape,color:e.color,tags:[...e.tags]};return e.hasDeployedInstance()?{...t,type:`deployed-instance`,deploymentId:e.deployment.id,referencedElement:{id:e.deployment.element.id,kind:e.deployment.element.kind,title:e.deployment.element.title}}:e.hasDeployment()?{...t,type:`deployment-node`,kind:e.deployment.kind,deploymentId:e.deployment.id,children:[...e.children()].map(e=>e.id)}:e.hasElement()?{...t,type:`element`,elementId:e.element.id,kind:e.element.kind,children:[...e.children()].flatMap(e=>modelRef(e)??[])}:[]}),edges:[...i.edges()].map(e=>({source:e.source.id,target:e.target.id,label:e.label,description:e.description.text,technology:e.technology,tags:[...e.tags]})),sourceLocation:a({view:i.id})}}),me=b.array(b.discriminatedUnion(`type`,[b.object({type:b.literal(`element`),project:b.string().describe(`Project ID`),id:b.string().describe(`Element ID (FQN)`),name:b.string().describe(`Element name`),kind:b.string(),title:b.string(),technology:b.string().nullable(),shape:b.string(),includedInViews:V,metadata:b.record(b.union([b.string(),b.array(b.string())])),tags:b.array(b.string())}),b.object({type:b.literal(`deployment-node`),project:b.string().describe(`Project ID`),id:b.string().describe(`Deployment ID (FQN)`),name:b.string().describe(`Deployment name`),kind:b.string(),title:b.string(),technology:b.string().nullable(),shape:b.string(),includedInViews:V,metadata:b.record(b.union([b.string(),b.array(b.string())])),tags:b.array(b.string())})])),he=likec4Tool({name:`search-element`,annotations:{readOnlyHint:!0,idempotentHint:!0,title:`Search elements`},description:`
1014
+ `,annotations:{readOnlyHint:!0,idempotentHint:!0,title:`Read view`},inputSchema:{viewId:T.string().describe(`View id (name)`),project:J},outputSchema:{id:T.string(),type:T.enum([`element`,`deployment`,`dynamic`]).describe(`View type`),title:T.string(),description:T.string().nullable(),tags:T.array(T.string()),project:T.string(),nodes:T.array(Ee),edges:T.array(T.object({source:T.string().describe(`Source node`),target:T.string().describe(`Target node`),label:T.string().nullable(),description:T.string().nullable(),technology:T.string().nullable(),tags:T.array(T.string())})).describe(`Edge represents relationship between nodes`),sourceLocation:q}})(async(e,t)=>{let n=e.projectsManager.ensureProjectId(t.project),r=e.project(n),i=(await e.computedModel(n)).findView(t.viewId);if(!i)throw Error(`View with ID '${t.viewId}' not found in project ${r.id}`);let a=mkLocate(e,r.id);return{id:i.id,type:i.$view._type,title:i.title??i.id,description:i.description.text,tags:[...i.tags],project:r.id,nodes:[...i.nodes()].flatMap(e=>{let t={id:e.id,title:e.title,description:e.description.text,technology:e.technology,shape:e.shape,color:e.color,tags:[...e.tags]};return e.hasDeployedInstance()?{...t,type:`deployed-instance`,deploymentId:e.deployment.id,referencedElement:{id:e.deployment.element.id,kind:e.deployment.element.kind,title:e.deployment.element.title}}:e.hasDeployment()?{...t,type:`deployment-node`,kind:e.deployment.kind,deploymentId:e.deployment.id,children:[...e.children()].map(e=>e.id)}:e.hasElement()?{...t,type:`element`,elementId:e.element.id,kind:e.element.kind,children:[...e.children()].flatMap(e=>modelRef(e)??[])}:[]}),edges:[...i.edges()].map(e=>({source:e.source.id,target:e.target.id,label:e.label,description:e.description.text,technology:e.technology,tags:[...e.tags]})),sourceLocation:a({view:i.id})}}),Oe=T.array(T.discriminatedUnion(`type`,[T.object({type:T.literal(`element`),project:T.string().describe(`Project ID`),id:T.string().describe(`Element ID (FQN)`),name:T.string().describe(`Element name`),kind:T.string(),title:T.string(),technology:T.string().nullable(),shape:T.string(),includedInViews:Y,metadata:T.record(T.union([T.string(),T.array(T.string())])),tags:T.array(T.string())}),T.object({type:T.literal(`deployment-node`),project:T.string().describe(`Project ID`),id:T.string().describe(`Deployment ID (FQN)`),name:T.string().describe(`Deployment name`),kind:T.string(),title:T.string(),technology:T.string().nullable(),shape:T.string(),includedInViews:Y,metadata:T.record(T.union([T.string(),T.array(T.string())])),tags:T.array(T.string())})])),ke=likec4Tool({name:`search-element`,annotations:{readOnlyHint:!0,idempotentHint:!0,title:`Search elements`},description:`
982
1015
  Search LikeC4 elements and deployment nodes across all projects.
983
1016
 
984
1017
  Query syntax (case-insensitive):
@@ -1033,7 +1066,7 @@ Example response:
1033
1066
  }
1034
1067
  ]
1035
1068
  }
1036
- `,inputSchema:{search:b.string().min(2,`Search must be at least 2 characters long`)},outputSchema:{total:b.number(),found:me}})(async(e,t)=>{let n=e.projects(),r=[],i=t.search.toLowerCase(),predicate;i.startsWith(`kind:`)?(i=i.slice(5),F.debug(`search by kind: {search}`,{search:i}),predicate=e=>e.kind.toLowerCase()===i):i.startsWith(`shape:`)?(i=i.slice(6),F.debug(`search by shape: {search}`,{search:i}),predicate=e=>e.shape.toLowerCase()===i):i.startsWith(`meta:`)?(i=i.slice(5),F.debug(`search by metadata: {search}`,{search:i}),predicate=e=>!!e.getMetadata(i)):i.startsWith(`#`)?(i=i.slice(1),F.debug(`search by tag: {search}`,{search:i}),predicate=e=>e.tags.some(e=>e.toLowerCase().includes(i))):(F.debug(`search by id/title: {search}`,{search:i}),predicate=e=>e.id.toLowerCase().includes(i)||e.title.toLowerCase().includes(i));for(let t of n)try{let n=await e.computedModel(t.id);for(let e of T(n.elements(),e=>!e.imported&&predicate(e)))r.push({type:`element`,project:t.id,id:e.id,name:e.name,kind:e.kind,title:e.title,technology:e.technology,shape:e.shape,tags:[...e.tags],metadata:e.getMetadata(),includedInViews:includedInViews(e.views())});for(let e of T(n.deployment.nodes(),predicate))r.push({type:`deployment-node`,project:t.id,id:e.id,name:e.name,kind:e.kind,title:e.title,technology:e.technology,shape:e.shape,tags:[...e.tags],metadata:e.getMetadata(),includedInViews:includedInViews(e.views())})}catch(e){F.error(`Error searching in project ${t.id}:`,{error:e})}return{total:r.length,found:r.slice(0,20)}}),ge=b.object({id:b.string().describe(`Element id (FQN)`),name:b.string().describe(`Element name`),kind:b.string().describe(`Element kind`),title:b.string().describe(`Human-readable title`),depth:b.number().describe(`Depth relative to the root element (1 = direct child)`),tags:b.array(b.string()).describe(`Assigned tags`),metadata:b.record(b.union([b.string(),b.array(b.string())])).describe(`Element metadata`),childCount:b.number().describe(`Number of direct children`),incomingCount:b.number().describe(`Number of incoming relationships`),outgoingCount:b.number().describe(`Number of outgoing relationships`)}),_e=likec4Tool({name:`subgraph-summary`,description:`
1069
+ `,inputSchema:{search:T.string().min(2,`Search must be at least 2 characters long`)},outputSchema:{total:T.number(),found:Oe}})(async(e,t)=>{let n=e.projects(),r=[],i=t.search.toLowerCase(),predicate;i.startsWith(`kind:`)?(i=i.slice(5),U.debug(`search by kind: {search}`,{search:i}),predicate=e=>e.kind.toLowerCase()===i):i.startsWith(`shape:`)?(i=i.slice(6),U.debug(`search by shape: {search}`,{search:i}),predicate=e=>e.shape.toLowerCase()===i):i.startsWith(`meta:`)?(i=i.slice(5),U.debug(`search by metadata: {search}`,{search:i}),predicate=e=>!!e.getMetadata(i)):i.startsWith(`#`)?(i=i.slice(1),U.debug(`search by tag: {search}`,{search:i}),predicate=e=>e.tags.some(e=>e.toLowerCase().includes(i))):(U.debug(`search by id/title: {search}`,{search:i}),predicate=e=>e.id.toLowerCase().includes(i)||e.title.toLowerCase().includes(i));for(let t of n)try{let n=await e.computedModel(t.id);for(let e of P(n.elements(),e=>!e.imported&&predicate(e)))r.push({type:`element`,project:t.id,id:e.id,name:e.name,kind:e.kind,title:e.title,technology:e.technology,shape:e.shape,tags:[...e.tags],metadata:e.getMetadata(),includedInViews:includedInViews(e.views())});for(let e of P(n.deployment.nodes(),predicate))r.push({type:`deployment-node`,project:t.id,id:e.id,name:e.name,kind:e.kind,title:e.title,technology:e.technology,shape:e.shape,tags:[...e.tags],metadata:e.getMetadata(),includedInViews:includedInViews(e.views())})}catch(e){U.error(`Error searching in project ${t.id}:`,{error:e})}return{total:r.length,found:r.slice(0,20)}}),Ae=T.object({id:T.string().describe(`Element id (FQN)`),name:T.string().describe(`Element name`),kind:T.string().describe(`Element kind`),title:T.string().describe(`Human-readable title`),depth:T.number().describe(`Depth relative to the root element (1 = direct child)`),tags:T.array(T.string()).describe(`Assigned tags`),metadata:T.record(T.union([T.string(),T.array(T.string())])).describe(`Element metadata`),childCount:T.number().describe(`Number of direct children`),incomingCount:T.number().describe(`Number of incoming relationships`),outgoingCount:T.number().describe(`Number of outgoing relationships`)}),je=likec4Tool({name:`subgraph-summary`,description:`
1037
1070
  Get a compact, table-friendly summary of all descendants of a parent element.
1038
1071
  Returns each descendant with its depth, metadata, tags, and relationship counts in a single call.
1039
1072
  Much more efficient than calling read-element for each descendant individually.
@@ -1099,7 +1132,7 @@ Example response:
1099
1132
  "truncated": false,
1100
1133
  "truncatedByDepth": false
1101
1134
  }
1102
- `,annotations:{readOnlyHint:!0,idempotentHint:!0,title:`Subgraph summary`},inputSchema:{elementId:b.string().describe(`Parent element id (FQN) whose descendants to summarize`),maxDepth:b.number().int().min(1).max(20).optional().default(10).describe(`Maximum depth of descendants to include (default: 10, max: 20)`),metadataKeys:b.array(b.string()).optional().describe(`If provided, only include these metadata keys in the response`),project:B},outputSchema:{root:b.object({id:b.string(),kind:b.string(),title:b.string(),childCount:b.number()}),descendants:b.array(ge),totalDescendants:b.number().describe(`Total number of descendants found`),truncated:b.boolean().describe(`True if results were truncated due to exceeding the limit`),truncatedByDepth:b.boolean().describe(`True if deeper descendants exist beyond maxDepth`)}})(async(e,t)=>{let n=e.projectsManager.ensureProjectId(t.project),r=(await e.computedModel(n)).findElement(t.elementId);l(r,`Element "${t.elementId}" not found in project "${n}"`);let i=t.maxDepth,a=t.metadataKeys,o=[],s=0,c=!1,u=!1,d=[],f=[...r.children()];for(let e of f)d.push({element:e,depth:1});for(;d.length>0;){let{element:e,depth:t}=d.shift();if(t>i){u=!0;continue}s++;let n=[...e.children()];if(o.length<200){let r=e.getMetadata(),i=a?Object.fromEntries(a.filter(e=>e in r).map(e=>[e,r[e]])):r;o.push({id:e.id,name:e.name,kind:e.kind,title:e.title,depth:t,tags:[...e.tags],metadata:i,childCount:n.length,incomingCount:[...e.incoming()].length,outgoingCount:[...e.outgoing()].length})}else c=!0;for(let e of n)d.push({element:e,depth:t+1})}return{root:{id:r.id,kind:r.kind,title:r.title,childCount:f.length},descendants:o,totalDescendants:s,truncated:c,truncatedByDepth:u}});function createMCPServer(e){let t=new _({name:`LikeC4`,version:I},{instructions:`LikeC4 MCP – query and navigate LikeC4 models.
1135
+ `,annotations:{readOnlyHint:!0,idempotentHint:!0,title:`Subgraph summary`},inputSchema:{elementId:T.string().describe(`Parent element id (FQN) whose descendants to summarize`),maxDepth:T.number().int().min(1).max(20).optional().default(10).describe(`Maximum depth of descendants to include (default: 10, max: 20)`),metadataKeys:T.array(T.string()).optional().describe(`If provided, only include these metadata keys in the response`),project:J},outputSchema:{root:T.object({id:T.string(),kind:T.string(),title:T.string(),childCount:T.number()}),descendants:T.array(Ae),totalDescendants:T.number().describe(`Total number of descendants found`),truncated:T.boolean().describe(`True if results were truncated due to exceeding the limit`),truncatedByDepth:T.boolean().describe(`True if deeper descendants exist beyond maxDepth`)}})(async(e,t)=>{let n=e.projectsManager.ensureProjectId(t.project),r=(await e.computedModel(n)).findElement(t.elementId);m(r,`Element "${t.elementId}" not found in project "${n}"`);let i=t.maxDepth,a=t.metadataKeys,s=[],c=0,l=!1,u=!1,f=[],p=[...r.children()];for(let e of p)f.push({element:e,depth:1});for(;f.length>0;){let{element:e,depth:t}=f.shift();if(t>i){u=!0;continue}c++;let n=[...e.children()];if(s.length<200){let r=e.getMetadata(),i=a?Object.fromEntries(a.filter(e=>e in r).map(e=>[e,r[e]])):r;s.push({id:e.id,name:e.name,kind:e.kind,title:e.title,depth:t,tags:[...e.tags],metadata:i,childCount:n.length,incomingCount:[...e.incoming()].length,outgoingCount:[...e.outgoing()].length})}else l=!0;for(let e of n)f.push({element:e,depth:t+1})}return{root:{id:r.id,kind:r.kind,title:r.title,childCount:p.length},descendants:s,totalDescendants:c,truncated:l,truncatedByDepth:u}});function createMCPServer(e){let t=new S({name:`LikeC4`,version:W},{instructions:`LikeC4 MCP – query and navigate LikeC4 models.
1103
1136
 
1104
1137
  Conventions:
1105
1138
  - All tools are read-only and idempotent.
@@ -1112,6 +1145,8 @@ Available tools:
1112
1145
  - read-element — Full element details including relationships, includedInViews, deployedInstances, metadata and sourceLocation. Input: { id, project? }.
1113
1146
  - read-deployment — Details of a deployment node or deployed instance. Input: { id, project? }.
1114
1147
  - read-view — Full view details (nodes/edges) and sourceLocation. Input: { viewId, project? }.
1148
+ - render-view — Renders a view as an interactive diagram (pan/zoom/fit) inline in chat, for hosts that support MCP Apps. Input: { viewId, project? }.
1149
+ - preview-view — Renders a preview of a LikeC4 view defined by DSL text, in the context of an existing project's real elements, without saving to disk. The view id must be new: if it already exists, the tool returns an error and asks for a different id. Input: { dsl, project? }.
1115
1150
  - find-relationships — Direct and indirect relationships between two elements in a project. Input: { element1, element2, project? }.
1116
1151
  - query-graph — Query element hierarchy (ancestors, descendants, siblings, children, parent) and relationships (incomers, outgoers). Input: { elementId, queryType, includeIndirect?, project? }.
1117
1152
  - query-incomers-graph — Get complete graph of all upstream dependencies/producers (recursive incomers). Much more efficient than repeated query-graph calls. Input: { elementId, includeIndirect?, maxDepth?, maxNodes?, project? }.
@@ -1132,4 +1167,4 @@ Instructions:
1132
1167
  - If response returns "sourceLocation", provide link to this location in the editor
1133
1168
 
1134
1169
  Full documentation: https://likec4.dev/llms-full.txt
1135
- `,enforceStrictCapabilities:!0,capabilities:{completions:{},tools:{},logging:{},prompts:{},resources:{}}});return t.server.onerror=e=>{d.error(u(e))},m(t,setMcpServerCtx,Z,$,de,ue,pe,he,X,q,h(ae,se,le,te,re,ne),h(U,K,_e),h(applySemanticLayoutPrompt,applySemanticLayoutTool),projectResource)}var StdioLikeC4MCPServer=class{services;options;transport=void 0;_mcp=void 0;constructor(e,t={}){this.services=e,this.options=t}get mcp(){if(!this._mcp)throw Error(`MCP server is not started`);return this._mcp}get isStarted(){return this.transport!==void 0}get port(){return NaN}async dispose(){await this.stop()}async start(){if(!this.transport){F.info(`Starting MCP stdio server`),this._mcp=createMCPServer(this.services),setMcpServerCtx(this._mcp),this.transport=new s(this.options.stdin,this.options.stdout);try{await this._mcp.connect(this.transport)}catch(e){throw await this.stop(),e}F.info(`LikeC4 MCP Server running on stdio`)}}async stop(){if(this.transport)try{F.info(`Stopping MCP stdio server`),await this.transport.close(),this._mcp&&await this._mcp.close()}finally{this._mcp=void 0,this.transport=void 0,setMcpServerCtx(void 0)}}};async function createHonoApp(e){let t=new j;t.use(`*`,ee({origin:`*`,allowHeaders:[`Content-Type`,`mcp-session-id`,`Last-Event-ID`,`mcp-protocol-version`],exposeHeaders:[`mcp-session-id`,`mcp-protocol-version`]})),t.get(`/health`,e=>e.json({status:`ok`}));let n=e();setMcpServerCtx(n);let r=new k({eventStore:new O({})});return t.all(`/mcp`,async e=>(n.isConnected()||await n.connect(r),await r.handleRequest(e))),t.notFound(e=>(F.debug(`${e.req.method} ${e.req.url} not found`),e.json({jsonrpc:`2.0`,error:{code:-32e3,message:`Method not found.`},id:null},{status:404}))),t.onError((e,t)=>(F.error(u(e)),t.json({jsonrpc:`2.0`,error:{code:-32603,message:`Internal server error`},id:null},{status:500}))),t}async function startServer(e){let{factory:t,port:n}=e,r=await createHonoApp(t);return new Promise((e,t)=>{let i=A({fetch:r.fetch,hostname:`0.0.0.0`,port:n}).prependOnceListener(`error`,t).prependOnceListener(`listening`,()=>{i.removeListener(`error`,t),e(i.unref())})})}var StreamableLikeC4MCPServer=class{services;_port;server=void 0;constructor(e,t=33335){this.services=e,this._port=t}get mcp(){throw Error(`StreamableLikeC4MCPServer has access to McpServer only during the request`)}get isStarted(){return this.server?.listening===!0}get port(){return this._port}async dispose(){await this.stop()}async start(e=this._port){if(this.server){if(this.port===e)return;await this.stop()}F.info(`Starting MCP server on port {port}`,{port:e}),this._port=e,this.server=await startServer({factory:()=>createMCPServer(this.services),port:e}),F.info(`MCP server ready at http://0.0.0.0:{port}/mcp`,{port:e})}stop(){let e=this.server;return e?(F.info(`Stopping MCP server`),this.server=void 0,setMcpServerCtx(void 0),new Promise(t=>{e.close(e=>{e?F.error(`Failed to stop MCP server`,{err:e}):F.info(`MCP server stopped`),t()})})):(F.info(`MCP server is not running, nothing to stop`),Promise.resolve())}};async function initLikeC4MCP(o){let s=n(o,{workspacePath:`.`,mcp:`stdio`,graphviz:`wasm`,watch:!0,throwIfInvalid:!1,configureLogger:!0});s.configureLogger&&(e({useStdErr:s.mcp===`stdio`,colors:a.isColorSupported&&s.mcp!==`stdio`,logLevel:i?`debug`:`info`}),process.on(`uncaughtException`,e=>{F.error(`uncaughtException`,{err:e})}),process.on(`unhandledRejection`,e=>{F.error(`unhandledRejection`,{err:e})}));let c=r(s.workspacePath);F.info`Loading LikeC4 from workspace: ${c}`;let l=await t(c,{graphviz:s.graphviz,manualLayouts:!0,configureLogger:!1,watch:s.watch,throwIfInvalid:s.throwIfInvalid}),u=setLanguageServicesCtx(l.languageServices);return{server:s.mcp===`stdio`?new StdioLikeC4MCPServer(u,s.stdio):new StreamableLikeC4MCPServer(u,s.mcp.port),likec4:l}}async function startLikeC4MCP(e){let t=e?.mcp===void 0||e.mcp===`stdio`?e?.stdio?.stdin??process.stdin:void 0,n,r=!1,i=t?t.readableEnded||t.destroyed:!1,a,cleanup=async()=>{let e=n;e&&(a??=(async()=>{try{await e.server.stop()}finally{try{await e.likec4.dispose()}finally{setLanguageServicesCtx(void 0)}}})(),await a)};function stopObservingStdin(){t&&(t.off(`end`,onStdinClosed),t.off(`close`,onStdinClosed))}function onStdinClosed(){i=!0,stopObservingStdin(),r&&cleanup().catch(e=>{F.error(`Failed to stop MCP stdio server after stdin closed`,{err:e})})}t&&!i&&(t.once(`end`,onStdinClosed),t.once(`close`,onStdinClosed),i=t.readableEnded||t.destroyed);try{if(n=await initLikeC4MCP(e),n.server instanceof StdioLikeC4MCPServer){if(i)return stopObservingStdin(),await cleanup(),n;await n.server.start(),r=!0,i&&await cleanup()}else await n.server.start();return n}catch(e){if(stopObservingStdin(),n)try{await cleanup()}catch(e){F.error(`Failed to clean up MCP stdio server after start error`,{err:e})}throw e}}export{__name as i,startLikeC4MCP as n,F as r,initLikeC4MCP as t};
1170
+ `,enforceStrictCapabilities:!0,capabilities:{completions:{},tools:{},logging:{},prompts:{},resources:{}}});return t.server.onerror=e=>{g.error(h(e))},y(t,setMcpServerCtx,fe,Te,we,Ce,De,ke,de,le,b(ye,xe,$,he,_e,ge),b(oe,ce,je),b(applySemanticLayoutPrompt,applySemanticLayoutTool,renderViewTool,previewViewTool),b(projectResource,renderViewResource))}var StdioLikeC4MCPServer=class{services;options;transport=void 0;_mcp=void 0;constructor(e,t={}){this.services=e,this.options=t}get mcp(){if(!this._mcp)throw Error(`MCP server is not started`);return this._mcp}get isStarted(){return this.transport!==void 0}get port(){return NaN}async dispose(){await this.stop()}async start(){if(!this.transport){U.info(`Starting MCP stdio server`),this._mcp=createMCPServer(this.services),setMcpServerCtx(this._mcp),this.transport=new f(this.options.stdin,this.options.stdout);try{await this._mcp.connect(this.transport)}catch(e){throw await this.stop(),e}U.info(`LikeC4 MCP Server running on stdio`)}}async stop(){if(this.transport)try{U.info(`Stopping MCP stdio server`),await this.transport.close(),this._mcp&&await this._mcp.close()}finally{this._mcp=void 0,this.transport=void 0,setMcpServerCtx(void 0)}}};async function createHonoApp(e){let t=new ne;t.use(`*`,re({origin:`*`,allowHeaders:[`Content-Type`,`mcp-session-id`,`Last-Event-ID`,`mcp-protocol-version`],exposeHeaders:[`mcp-session-id`,`mcp-protocol-version`]})),t.get(`/health`,e=>e.json({status:`ok`}));let n=e();setMcpServerCtx(n);let r=new z({eventStore:new R({})});return t.all(`/mcp`,async e=>(n.isConnected()||await n.connect(r),await r.handleRequest(e))),t.notFound(e=>(U.debug(`${e.req.method} ${e.req.url} not found`),e.json({jsonrpc:`2.0`,error:{code:-32e3,message:`Method not found.`},id:null},{status:404}))),t.onError((e,t)=>(U.error(h(e)),t.json({jsonrpc:`2.0`,error:{code:-32603,message:`Internal server error`},id:null},{status:500}))),t}async function startServer(e){let{factory:t,port:n}=e,r=await createHonoApp(t);return new Promise((e,t)=>{let i=B({fetch:r.fetch,hostname:`0.0.0.0`,port:n}).prependOnceListener(`error`,t).prependOnceListener(`listening`,()=>{i.removeListener(`error`,t),e(i.unref())})})}var StreamableLikeC4MCPServer=class{services;_port;server=void 0;constructor(e,t=33335){this.services=e,this._port=t}get mcp(){throw Error(`StreamableLikeC4MCPServer has access to McpServer only during the request`)}get isStarted(){return this.server?.listening===!0}get port(){return this._port}async dispose(){await this.stop()}async start(e=this._port){if(this.server){if(this.port===e)return;await this.stop()}U.info(`Starting MCP server on port {port}`,{port:e}),this._port=e,this.server=await startServer({factory:()=>createMCPServer(this.services),port:e}),U.info(`MCP server ready at http://0.0.0.0:{port}/mcp`,{port:e})}stop(){let e=this.server;return e?(U.info(`Stopping MCP server`),this.server=void 0,setMcpServerCtx(void 0),new Promise(t=>{e.close(e=>{e?U.error(`Failed to stop MCP server`,{err:e}):U.info(`MCP server stopped`),t()})})):(U.info(`MCP server is not running, nothing to stop`),Promise.resolve())}};async function initLikeC4MCP(t){let i=r(t,{workspacePath:`.`,mcp:`stdio`,graphviz:`wasm`,watch:!0,throwIfInvalid:!1,configureLogger:!0});i.configureLogger&&(e({useStdErr:i.mcp===`stdio`,colors:l.isColorSupported&&i.mcp!==`stdio`,logLevel:c?`debug`:`info`}),process.on(`uncaughtException`,e=>{U.error(`uncaughtException`,{err:e})}),process.on(`unhandledRejection`,e=>{U.error(`unhandledRejection`,{err:e})}));let s=a(i.workspacePath);U.info`Loading LikeC4 from workspace: ${s}`;let u=await n(s,{graphviz:i.graphviz,manualLayouts:!0,configureLogger:!1,watch:i.watch,throwIfInvalid:i.throwIfInvalid}),f=setLanguageServicesCtx(u.languageServices);return{server:i.mcp===`stdio`?new StdioLikeC4MCPServer(f,i.stdio):new StreamableLikeC4MCPServer(f,i.mcp.port),likec4:u}}async function startLikeC4MCP(e){let t=e?.mcp===void 0||e.mcp===`stdio`?e?.stdio?.stdin??process.stdin:void 0,n,r=!1,i=t?t.readableEnded||t.destroyed:!1,a,cleanup=async()=>{let e=n;e&&(a??=(async()=>{try{await e.server.stop()}finally{try{await e.likec4.dispose()}finally{setLanguageServicesCtx(void 0)}}})(),await a)};function stopObservingStdin(){t&&(t.off(`end`,onStdinClosed),t.off(`close`,onStdinClosed))}function onStdinClosed(){i=!0,stopObservingStdin(),r&&cleanup().catch(e=>{U.error(`Failed to stop MCP stdio server after stdin closed`,{err:e})})}t&&!i&&(t.once(`end`,onStdinClosed),t.once(`close`,onStdinClosed),i=t.readableEnded||t.destroyed);try{if(n=await initLikeC4MCP(e),n.server instanceof StdioLikeC4MCPServer){if(i)return stopObservingStdin(),await cleanup(),n;await n.server.start(),r=!0,i&&await cleanup()}else await n.server.start();return n}catch(e){if(stopObservingStdin(),n)try{await cleanup()}catch(e){U.error(`Failed to clean up MCP stdio server after start error`,{err:e})}throw e}}export{__name as i,startLikeC4MCP as n,U as r,initLikeC4MCP as t};
package/dist/cli.mjs CHANGED
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- import{n as e,r as t}from"./chunks/src.mjs";import{resolve as n}from"node:path";import{defineCommand as r,runMain as i}from"citty";i(r({meta:{name:`likec4-mcp-server`,description:`LikeC4 MCP server`},args:{stdio:{type:`boolean`,description:`use stdio transport (default)`,required:!1},http:{type:`boolean`,description:`use streamable http transport`,required:!1},port:{type:`string`,description:`change http port`,valueHint:`number`,required:!1},graphviz:{type:`enum`,options:[`binary`,`wasm`],description:`use binary or wasm graphviz`,default:`wasm`,required:!1},watch:{type:`boolean`,description:`disable watch for changes`,default:!0,required:!1},workspace:{type:`positional`,description:`change workspace, can be set by LIKEC4_WORKSPACE env`,valueHint:`directory`,required:!1,default:process.env.LIKEC4_WORKSPACE||`.`}},setup({args:e}){if(e.stdio&&(e.http||e.port))throw Error(`stdio and http are mutually exclusive`)},async run({args:r}){let i=r.stdio||!r.http&&!r.port,a=r.port?parseInt(r.port):33335,o=n(r.workspace||`.`);r.watch&&t.warn`watch for changes enabled, use ${`--no-watch`} to consume less resources`,await e({workspacePath:o,graphviz:r.graphviz,mcp:i?`stdio`:{port:a},configureLogger:!0,watch:r.watch})}})).catch(e=>{t.error(e),process.exit(1)});
2
+ import{n as e,r as t}from"./chunks/src.mjs";import{resolve as n}from"node:path";import{defineCommand as r,runMain as i}from"citty";const a=r({meta:{name:`likec4-mcp-server`,description:`LikeC4 MCP server`},args:{stdio:{type:`boolean`,description:`use stdio transport (default)`,required:!1},http:{type:`boolean`,description:`use streamable http transport`,required:!1},port:{type:`string`,description:`change http port`,valueHint:`number`,required:!1},graphviz:{type:`enum`,options:[`binary`,`wasm`],description:`use binary or wasm graphviz`,default:`wasm`,required:!1},watch:{type:`boolean`,description:`disable watch for changes`,default:!0,required:!1},workspace:{type:`positional`,description:`change workspace, can be set by LIKEC4_WORKSPACE env`,valueHint:`directory`,required:!1,default:process.env.LIKEC4_WORKSPACE||`.`}},setup({args:e}){if(e.stdio&&(e.http||e.port))throw Error(`stdio and http are mutually exclusive`)},async run({args:r}){let i=r.stdio||!r.http&&!r.port,a=r.port?parseInt(r.port):33335,o=n(r.workspace||`.`);r.watch&&t.warn`watch for changes enabled, use ${`--no-watch`} to consume less resources`,await e({workspacePath:o,graphviz:r.graphviz,mcp:i?`stdio`:{port:a},configureLogger:!0,watch:r.watch})}});i(a).catch(e=>{t.error(e),process.exit(1)});export{};
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@likec4/mcp",
3
3
  "description": "Model Context Protocol server for LikeC4",
4
4
  "license": "MIT",
5
- "version": "1.59.2",
5
+ "version": "1.59.3",
6
6
  "bugs": "https://github.com/likec4/likec4/issues",
7
7
  "homepage": "https://likec4.dev",
8
8
  "author": "Denis Davydkov <denis@davydkov.com>",
@@ -41,40 +41,48 @@
41
41
  "server"
42
42
  ],
43
43
  "dependencies": {
44
- "@hono/mcp": "^0.3.1",
45
- "@hono/node-server": "^2.0.10",
44
+ "@hono/mcp": "^0.3.2",
45
+ "@hono/node-server": "^2.1.1",
46
46
  "@hpcc-js/wasm-graphviz": "1.22.2",
47
+ "@likec4/config": "1.59.3",
48
+ "@likec4/core": "1.59.3",
49
+ "@likec4/language-server": "1.59.3",
50
+ "@likec4/language-services": "1.59.3",
51
+ "@likec4/layouts": "1.59.3",
52
+ "@likec4/log": "1.59.3",
53
+ "@likec4/diagram": "1.59.3",
47
54
  "@modelcontextprotocol/sdk": "^1.29.0",
55
+ "@modelcontextprotocol/ext-apps": "^1.7.4",
56
+ "@mantine/core": "9.6.0",
48
57
  "bundle-require": "^5.1.0",
49
58
  "citty": "^0.2.2",
50
59
  "defu": "^6.1.7",
51
60
  "esbuild": "0.28.1",
52
- "hono": "^4.12.31",
53
- "remeda": "^2.37.0",
61
+ "hono": "^4.13.5",
62
+ "remeda": "^2.45.0",
63
+ "react": "19.2.8",
64
+ "react-dom": "19.2.8",
54
65
  "std-env": "^4.1.0",
55
- "tinyrainbow": "^3.1.0",
66
+ "tinyrainbow": "^3.1.1",
56
67
  "unctx": "^2.5.0",
57
68
  "vscode-uri": "3.1.0",
58
- "zod": "^4.4.3",
59
- "@likec4/config": "1.59.2",
60
- "@likec4/language-services": "1.59.2",
61
- "@likec4/language-server": "1.59.2",
62
- "@likec4/log": "1.59.2",
63
- "@likec4/core": "1.59.2",
64
- "@likec4/layouts": "1.59.2"
69
+ "vscode-languageserver-types": "3.17.5",
70
+ "zod": "^4.4.3"
65
71
  },
66
72
  "devDependencies": {
73
+ "@likec4/devops": "1.59.3",
74
+ "@likec4/tsconfig": "1.59.3",
67
75
  "@types/node": "~22.19.19",
68
- "@vitest/ui": "4.1.9",
76
+ "@types/react": "19.2.18",
77
+ "@types/react-dom": "19.2.5",
78
+ "@vitest/ui": "4.1.11",
69
79
  "langium": "3.5.0",
70
80
  "tsdown": "^0.22.9",
71
81
  "tsx": "4.22.5",
72
- "turbo": "2.10.5",
82
+ "turbo": "2.10.12",
73
83
  "typescript": "6.0.3",
74
84
  "type-fest": "^4.41.0",
75
- "vitest": "4.1.9",
76
- "@likec4/devops": "1.59.2",
77
- "@likec4/tsconfig": "1.59.2"
85
+ "vitest": "4.1.11"
78
86
  },
79
87
  "scripts": {
80
88
  "typecheck": "tsc -b --verbose",