@likec4/mcp 1.39.0 → 1.39.1

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,5 +1,5 @@
1
1
 
2
- > @likec4/mcp@1.39.0 build /home/runner/work/likec4/likec4/packages/mcp
2
+ > @likec4/mcp@1.39.1 build /home/runner/work/likec4/likec4/packages/mcp
3
3
  > wireit
4
4
 
5
5
  Analyzing
@@ -1275,4 +1275,4 @@ Analyzing
1275
1275
  📦 ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/external.js
1276
1276
  Σ Total dist size (byte size): 2.06 MB
1277
1277
  [log]
1278
- ✅ Ran 1 script and skipped 0 in 17.6s.
1278
+ ✅ Ran 1 script and skipped 0 in 18.2s.
package/dist/index.mjs CHANGED
@@ -352,7 +352,7 @@ ${Tr(n)}`),qr.warn("Failed to register project at {uri}",{uri:e.uri.toString(),e
352
352
  ]))`;continue}else if(r[u]==="$"){i+=`($|(?=[\r
353
353
  ]))`;continue}}if(n.s&&r[u]==="."){i+=a?`${r[u]}\r
354
354
  `:`[${r[u]}\r
355
- ]`;continue}i+=r[u],r[u]==="\\"?s=!0:a&&r[u]==="]"?a=!1:!a&&r[u]==="["&&(a=!0)}try{new RegExp(i)}catch{return console.warn(`Could not convert regex pattern at ${e.currentPath.join("/")} to a flag-independent form! Falling back to the flag-ignorant source`),t.source}return i}function nH(t,e){if(e.target==="openAi"&&console.warn("Warning: OpenAI may not support records in schemas! Try an array of key-value pairs instead."),e.target==="openApi3"&&t.keyType?._def.typeName===Be.ZodEnum)return{type:"object",required:t.keyType._def.values,properties:t.keyType._def.values.reduce((r,i)=>({...r,[i]:on(t.valueType._def,{...e,currentPath:[...e.currentPath,"properties",i]})??{}}),{}),additionalProperties:e.rejectedAdditionalProperties};const n={type:"object",additionalProperties:on(t.valueType._def,{...e,currentPath:[...e.currentPath,"additionalProperties"]})??e.allowedAdditionalProperties};if(e.target==="openApi3")return n;if(t.keyType?._def.typeName===Be.ZodString&&t.keyType._def.checks?.length){const{type:r,...i}=eH(t.keyType._def,e);return{...n,propertyNames:i}}else{if(t.keyType?._def.typeName===Be.ZodEnum)return{...n,propertyNames:{enum:t.keyType._def.values}};if(t.keyType?._def.typeName===Be.ZodBranded&&t.keyType._def.type._def.typeName===Be.ZodString&&t.keyType._def.type._def.checks?.length){const{type:r,...i}=XU(t.keyType._def,e);return{...n,propertyNames:i}}}return n}function I$e(t,e){if(e.mapStrategy==="record")return nH(t,e);const n=on(t.keyType._def,{...e,currentPath:[...e.currentPath,"items","items","0"]})||{},r=on(t.valueType._def,{...e,currentPath:[...e.currentPath,"items","items","1"]})||{};return{type:"array",maxItems:125,items:{type:"array",items:[n,r],minItems:2,maxItems:2}}}function N$e(t){const e=t.values,r=Object.keys(t.values).filter(s=>typeof e[e[s]]!="number").map(s=>e[s]),i=Array.from(new Set(r.map(s=>typeof s)));return{type:i.length===1?i[0]==="string"?"string":"number":["string","number"],enum:r}}function O$e(){return{not:{}}}function L$e(t){return t.target==="openApi3"?{enum:["null"],nullable:!0}:{type:"null"}}const S1={ZodString:"string",ZodNumber:"number",ZodBigInt:"integer",ZodBoolean:"boolean",ZodNull:"null"};function M$e(t,e){if(e.target==="openApi3")return rH(t,e);const n=t.options instanceof Map?Array.from(t.options.values()):t.options;if(n.every(r=>r._def.typeName in S1&&(!r._def.checks||!r._def.checks.length))){const r=n.reduce((i,s)=>{const a=S1[s._def.typeName];return a&&!i.includes(a)?[...i,a]:i},[]);return{type:r.length>1?r:r[0]}}else if(n.every(r=>r._def.typeName==="ZodLiteral"&&!r.description)){const r=n.reduce((i,s)=>{const a=typeof s._def.value;switch(a){case"string":case"number":case"boolean":return[...i,a];case"bigint":return[...i,"integer"];case"object":if(s._def.value===null)return[...i,"null"];case"symbol":case"undefined":case"function":default:return i}},[]);if(r.length===n.length){const i=r.filter((s,a,o)=>o.indexOf(s)===a);return{type:i.length>1?i:i[0],enum:n.reduce((s,a)=>s.includes(a._def.value)?s:[...s,a._def.value],[])}}}else if(n.every(r=>r._def.typeName==="ZodEnum"))return{type:"string",enum:n.reduce((r,i)=>[...r,...i._def.values.filter(s=>!r.includes(s))],[])};return rH(t,e)}const rH=(t,e)=>{const n=(t.options instanceof Map?Array.from(t.options.values()):t.options).map((r,i)=>on(r._def,{...e,currentPath:[...e.currentPath,"anyOf",`${i}`]})).filter(r=>!!r&&(!e.strictUnions||typeof r=="object"&&Object.keys(r).length>0));return n.length?{anyOf:n}:void 0};function F$e(t,e){if(["ZodString","ZodNumber","ZodBigInt","ZodBoolean","ZodNull"].includes(t.innerType._def.typeName)&&(!t.innerType._def.checks||!t.innerType._def.checks.length))return e.target==="openApi3"?{type:S1[t.innerType._def.typeName],nullable:!0}:{type:[S1[t.innerType._def.typeName],"null"]};if(e.target==="openApi3"){const r=on(t.innerType._def,{...e,currentPath:[...e.currentPath]});return r&&"$ref"in r?{allOf:[r],nullable:!0}:r&&{...r,nullable:!0}}const n=on(t.innerType._def,{...e,currentPath:[...e.currentPath,"anyOf","0"]});return n&&{anyOf:[n,{type:"null"}]}}function B$e(t,e){const n={type:"number"};if(!t.checks)return n;for(const r of t.checks)switch(r.kind){case"int":n.type="integer",QU(n,"type",r.message,e);break;case"min":e.target==="jsonSchema7"?r.inclusive?hn(n,"minimum",r.value,r.message,e):hn(n,"exclusiveMinimum",r.value,r.message,e):(r.inclusive||(n.exclusiveMinimum=!0),hn(n,"minimum",r.value,r.message,e));break;case"max":e.target==="jsonSchema7"?r.inclusive?hn(n,"maximum",r.value,r.message,e):hn(n,"exclusiveMaximum",r.value,r.message,e):(r.inclusive||(n.exclusiveMaximum=!0),hn(n,"maximum",r.value,r.message,e));break;case"multipleOf":hn(n,"multipleOf",r.value,r.message,e);break}return n}function j$e(t,e){const n=e.target==="openAi",r={type:"object",properties:{}},i=[],s=t.shape();for(const o in s){let u=s[o];if(u===void 0||u._def===void 0)continue;let l=U$e(u);l&&n&&(u instanceof ya&&(u=u._def.innerType),u.isNullable()||(u=u.nullable()),l=!1);const c=on(u._def,{...e,currentPath:[...e.currentPath,"properties",o],propertyPath:[...e.currentPath,"properties",o]});c!==void 0&&(r.properties[o]=c,l||i.push(o))}i.length&&(r.required=i);const a=q$e(t,e);return a!==void 0&&(r.additionalProperties=a),r}function q$e(t,e){if(t.catchall._def.typeName!=="ZodNever")return on(t.catchall._def,{...e,currentPath:[...e.currentPath,"additionalProperties"]});switch(t.unknownKeys){case"passthrough":return e.allowedAdditionalProperties;case"strict":return e.rejectedAdditionalProperties;case"strip":return e.removeAdditionalStrategy==="strict"?e.allowedAdditionalProperties:e.rejectedAdditionalProperties}}function U$e(t){try{return t.isOptional()}catch{return!0}}const H$e=(t,e)=>{if(e.currentPath.toString()===e.propertyPath?.toString())return on(t.innerType._def,e);const n=on(t.innerType._def,{...e,currentPath:[...e.currentPath,"anyOf","1"]});return n?{anyOf:[{not:{}},n]}:{}},z$e=(t,e)=>{if(e.pipeStrategy==="input")return on(t.in._def,e);if(e.pipeStrategy==="output")return on(t.out._def,e);const n=on(t.in._def,{...e,currentPath:[...e.currentPath,"allOf","0"]}),r=on(t.out._def,{...e,currentPath:[...e.currentPath,"allOf",n?"1":"0"]});return{allOf:[n,r].filter(i=>i!==void 0)}};function W$e(t,e){return on(t.type._def,e)}function G$e(t,e){const r={type:"array",uniqueItems:!0,items:on(t.valueType._def,{...e,currentPath:[...e.currentPath,"items"]})};return t.minSize&&hn(r,"minItems",t.minSize.value,t.minSize.message,e),t.maxSize&&hn(r,"maxItems",t.maxSize.value,t.maxSize.message,e),r}function V$e(t,e){return t.rest?{type:"array",minItems:t.items.length,items:t.items.map((n,r)=>on(n._def,{...e,currentPath:[...e.currentPath,"items",`${r}`]})).reduce((n,r)=>r===void 0?n:[...n,r],[]),additionalItems:on(t.rest._def,{...e,currentPath:[...e.currentPath,"additionalItems"]})}:{type:"array",minItems:t.items.length,maxItems:t.items.length,items:t.items.map((n,r)=>on(n._def,{...e,currentPath:[...e.currentPath,"items",`${r}`]})).reduce((n,r)=>r===void 0?n:[...n,r],[])}}function K$e(){return{not:{}}}function Y$e(){return{}}const Z$e=(t,e)=>on(t.innerType._def,e),Q$e=(t,e,n)=>{switch(e){case Be.ZodString:return eH(t,n);case Be.ZodNumber:return B$e(t,n);case Be.ZodObject:return j$e(t,n);case Be.ZodBigInt:return w$e(t,n);case Be.ZodBoolean:return _$e();case Be.ZodDate:return JU(t,n);case Be.ZodUndefined:return K$e();case Be.ZodNull:return L$e(n);case Be.ZodArray:return E$e(t,n);case Be.ZodUnion:case Be.ZodDiscriminatedUnion:return M$e(t,n);case Be.ZodIntersection:return D$e(t,n);case Be.ZodTuple:return V$e(t,n);case Be.ZodRecord:return nH(t,n);case Be.ZodLiteral:return x$e(t,n);case Be.ZodEnum:return A$e(t);case Be.ZodNativeEnum:return N$e(t);case Be.ZodNullable:return F$e(t,n);case Be.ZodOptional:return H$e(t,n);case Be.ZodMap:return I$e(t,n);case Be.ZodSet:return G$e(t,n);case Be.ZodLazy:return()=>t.getter()._def;case Be.ZodPromise:return W$e(t,n);case Be.ZodNaN:case Be.ZodNever:return O$e();case Be.ZodEffects:return R$e(t,n);case Be.ZodAny:return b$e();case Be.ZodUnknown:return Y$e();case Be.ZodDefault:return S$e(t,n);case Be.ZodBranded:return XU(t,n);case Be.ZodReadonly:return Z$e(t,n);case Be.ZodCatch:return T$e(t,n);case Be.ZodPipeline:return z$e(t,n);case Be.ZodFunction:case Be.ZodVoid:case Be.ZodSymbol:return;default:return(r=>{})()}};function on(t,e,n=!1){const r=e.seen.get(t);if(e.override){const o=e.override?.(t,e,r,n);if(o!==g$e)return o}if(r&&!n){const o=X$e(r,e);if(o!==void 0)return o}const i={def:t,path:e.currentPath,jsonSchema:void 0};e.seen.set(t,i);const s=Q$e(t,t.typeName,e),a=typeof s=="function"?on(s(),e):s;if(a&&eIe(t,e,a),e.postProcess){const o=e.postProcess(a,t,e);return i.jsonSchema=a,o}return i.jsonSchema=a,a}const X$e=(t,e)=>{switch(e.$refStrategy){case"root":return{$ref:t.path.join("/")};case"relative":return{$ref:J$e(e.currentPath,t.path)};case"none":case"seen":return t.path.length<e.currentPath.length&&t.path.every((n,r)=>e.currentPath[r]===n)?(console.warn(`Recursive reference detected at ${e.currentPath.join("/")}! Defaulting to any`),{}):e.$refStrategy==="seen"?{}:void 0}},J$e=(t,e)=>{let n=0;for(;n<t.length&&n<e.length&&t[n]===e[n];n++);return[(t.length-n).toString(),...e.slice(n)].join("/")},eIe=(t,e,n)=>(t.description&&(n.description=t.description,e.markdownDescription&&(n.markdownDescription=t.description)),n),iH=(t,e)=>{const n=v$e(e),r=typeof e=="object"&&e.definitions?Object.entries(e.definitions).reduce((u,[l,c])=>({...u,[l]:on(c._def,{...n,currentPath:[...n.basePath,n.definitionPath,l]},!0)??{}}),{}):void 0,i=typeof e=="string"?e:e?.nameStrategy==="title"?void 0:e?.name,s=on(t._def,i===void 0?n:{...n,currentPath:[...n.basePath,n.definitionPath,i]},!1)??{},a=typeof e=="object"&&e.name!==void 0&&e.nameStrategy==="title"?e.name:void 0;a!==void 0&&(s.title=a);const o=i===void 0?r?{...s,[n.definitionPath]:r}:s:{$ref:[...n.$refStrategy==="relative"?[]:n.basePath,n.definitionPath,i].join("/"),[n.definitionPath]:{...r,[i]:s}};return n.target==="jsonSchema7"?o.$schema="http://json-schema.org/draft-07/schema#":(n.target==="jsonSchema2019-09"||n.target==="openAi")&&(o.$schema="https://json-schema.org/draft/2019-09/schema#"),n.target==="openAi"&&("anyOf"in o||"oneOf"in o||"allOf"in o||"type"in o&&Array.isArray(o.type))&&console.warn("Warning: OpenAI may not support schemas with unions as roots! Try wrapping it in an object property."),o};var JD;(function(t){t.Completable="McpCompletable"})(JD||(JD={}));class ex extends Nt{_parse(e){const{ctx:n}=this._processInputParams(e),r=n.data;return this._def.type._parse({data:r,path:n.path,parent:n})}unwrap(){return this._def.type}}ex.create=(t,e)=>new ex({type:t,typeName:JD.Completable,complete:e.complete,...tIe(e)});function tIe(t){if(!t)return{};const{errorMap:e,invalid_type_error:n,required_error:r,description:i}=t;if(e&&(n||r))throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);return e?{errorMap:e,description:i}:{errorMap:(a,o)=>{var u,l;const{message:c}=t;return a.code==="invalid_enum_value"?{message:c??o.defaultError}:typeof o.data>"u"?{message:(u=c??r)!==null&&u!==void 0?u:o.defaultError}:a.code!=="invalid_type"?{message:o.defaultError}:{message:(l=c??n)!==null&&l!==void 0?l:o.defaultError}},description:i}}class nIe{constructor(e,n){this._registeredResources={},this._registeredResourceTemplates={},this._registeredTools={},this._registeredPrompts={},this._toolHandlersInitialized=!1,this._completionHandlerInitialized=!1,this._resourceHandlersInitialized=!1,this._promptHandlersInitialized=!1,this.server=new m$e(e,n)}async connect(e){return await this.server.connect(e)}async close(){await this.server.close()}setToolRequestHandlers(){this._toolHandlersInitialized||(this.server.assertCanSetRequestHandler(nC.shape.method.value),this.server.assertCanSetRequestHandler(rC.shape.method.value),this.server.registerCapabilities({tools:{listChanged:!0}}),this.server.setRequestHandler(nC,()=>({tools:Object.entries(this._registeredTools).filter(([,e])=>e.enabled).map(([e,n])=>{const r={name:e,title:n.title,description:n.description,inputSchema:n.inputSchema?iH(n.inputSchema,{strictUnions:!0}):rIe,annotations:n.annotations};return n.outputSchema&&(r.outputSchema=iH(n.outputSchema,{strictUnions:!0})),r})})),this.server.setRequestHandler(rC,async(e,n)=>{const r=this._registeredTools[e.params.name];if(!r)throw new cr(Kn.InvalidParams,`Tool ${e.params.name} not found`);if(!r.enabled)throw new cr(Kn.InvalidParams,`Tool ${e.params.name} disabled`);let i;if(r.inputSchema){const s=await r.inputSchema.safeParseAsync(e.params.arguments);if(!s.success)throw new cr(Kn.InvalidParams,`Invalid arguments for tool ${e.params.name}: ${s.error.message}`);const a=s.data,o=r.callback;try{i=await Promise.resolve(o(a,n))}catch(u){i={content:[{type:"text",text:u instanceof Error?u.message:String(u)}],isError:!0}}}else{const s=r.callback;try{i=await Promise.resolve(s(n))}catch(a){i={content:[{type:"text",text:a instanceof Error?a.message:String(a)}],isError:!0}}}if(r.outputSchema&&!i.isError){if(!i.structuredContent)throw new cr(Kn.InvalidParams,`Tool ${e.params.name} has an output schema but no structured content was provided`);const s=await r.outputSchema.safeParseAsync(i.structuredContent);if(!s.success)throw new cr(Kn.InvalidParams,`Invalid structured content for tool ${e.params.name}: ${s.error.message}`)}return i}),this._toolHandlersInitialized=!0)}setCompletionRequestHandler(){this._completionHandlerInitialized||(this.server.assertCanSetRequestHandler(iC.shape.method.value),this.server.registerCapabilities({completions:{}}),this.server.setRequestHandler(iC,async e=>{switch(e.params.ref.type){case"ref/prompt":return this.handlePromptCompletion(e,e.params.ref);case"ref/resource":return this.handleResourceCompletion(e,e.params.ref);default:throw new cr(Kn.InvalidParams,`Invalid completion reference: ${e.params.ref}`)}}),this._completionHandlerInitialized=!0)}async handlePromptCompletion(e,n){const r=this._registeredPrompts[n.name];if(!r)throw new cr(Kn.InvalidParams,`Prompt ${n.name} not found`);if(!r.enabled)throw new cr(Kn.InvalidParams,`Prompt ${n.name} disabled`);if(!r.argsSchema)return R1;const i=r.argsSchema.shape[e.params.argument.name];if(!(i instanceof ex))return R1;const a=await i._def.complete(e.params.argument.value,e.params.context);return aH(a)}async handleResourceCompletion(e,n){const r=Object.values(this._registeredResourceTemplates).find(a=>a.resourceTemplate.uriTemplate.toString()===n.uri);if(!r){if(this._registeredResources[n.uri])return R1;throw new cr(Kn.InvalidParams,`Resource template ${e.params.ref.uri} not found`)}const i=r.resourceTemplate.completeCallback(e.params.argument.name);if(!i)return R1;const s=await i(e.params.argument.value,e.params.context);return aH(s)}setResourceRequestHandlers(){this._resourceHandlersInitialized||(this.server.assertCanSetRequestHandler(KA.shape.method.value),this.server.assertCanSetRequestHandler(YA.shape.method.value),this.server.assertCanSetRequestHandler(ZA.shape.method.value),this.server.registerCapabilities({resources:{listChanged:!0}}),this.server.setRequestHandler(KA,async(e,n)=>{const r=Object.entries(this._registeredResources).filter(([s,a])=>a.enabled).map(([s,a])=>({uri:s,name:a.name,...a.metadata})),i=[];for(const s of Object.values(this._registeredResourceTemplates)){if(!s.resourceTemplate.listCallback)continue;const a=await s.resourceTemplate.listCallback(n);for(const o of a.resources)i.push({...s.metadata,...o})}return{resources:[...r,...i]}}),this.server.setRequestHandler(YA,async()=>({resourceTemplates:Object.entries(this._registeredResourceTemplates).map(([n,r])=>({name:n,uriTemplate:r.resourceTemplate.uriTemplate.toString(),...r.metadata}))})),this.server.setRequestHandler(ZA,async(e,n)=>{const r=new URL(e.params.uri),i=this._registeredResources[r.toString()];if(i){if(!i.enabled)throw new cr(Kn.InvalidParams,`Resource ${r} disabled`);return i.readCallback(r,n)}for(const s of Object.values(this._registeredResourceTemplates)){const a=s.resourceTemplate.uriTemplate.match(r.toString());if(a)return s.readCallback(r,a,n)}throw new cr(Kn.InvalidParams,`Resource ${r} not found`)}),this.setCompletionRequestHandler(),this._resourceHandlersInitialized=!0)}setPromptRequestHandlers(){this._promptHandlersInitialized||(this.server.assertCanSetRequestHandler(QA.shape.method.value),this.server.assertCanSetRequestHandler(XA.shape.method.value),this.server.registerCapabilities({prompts:{listChanged:!0}}),this.server.setRequestHandler(QA,()=>({prompts:Object.entries(this._registeredPrompts).filter(([,e])=>e.enabled).map(([e,n])=>({name:e,title:n.title,description:n.description,arguments:n.argsSchema?sIe(n.argsSchema):void 0}))})),this.server.setRequestHandler(XA,async(e,n)=>{const r=this._registeredPrompts[e.params.name];if(!r)throw new cr(Kn.InvalidParams,`Prompt ${e.params.name} not found`);if(!r.enabled)throw new cr(Kn.InvalidParams,`Prompt ${e.params.name} disabled`);if(r.argsSchema){const i=await r.argsSchema.safeParseAsync(e.params.arguments);if(!i.success)throw new cr(Kn.InvalidParams,`Invalid arguments for prompt ${e.params.name}: ${i.error.message}`);const s=i.data,a=r.callback;return await Promise.resolve(a(s,n))}else{const i=r.callback;return await Promise.resolve(i(n))}}),this.setCompletionRequestHandler(),this._promptHandlersInitialized=!0)}resource(e,n,...r){let i;typeof r[0]=="object"&&(i=r.shift());const s=r[0];if(typeof n=="string"){if(this._registeredResources[n])throw new Error(`Resource ${n} is already registered`);const a=this._createRegisteredResource(e,void 0,n,i,s);return this.setResourceRequestHandlers(),this.sendResourceListChanged(),a}else{if(this._registeredResourceTemplates[e])throw new Error(`Resource template ${e} is already registered`);const a=this._createRegisteredResourceTemplate(e,void 0,n,i,s);return this.setResourceRequestHandlers(),this.sendResourceListChanged(),a}}registerResource(e,n,r,i){if(typeof n=="string"){if(this._registeredResources[n])throw new Error(`Resource ${n} is already registered`);const s=this._createRegisteredResource(e,r.title,n,r,i);return this.setResourceRequestHandlers(),this.sendResourceListChanged(),s}else{if(this._registeredResourceTemplates[e])throw new Error(`Resource template ${e} is already registered`);const s=this._createRegisteredResourceTemplate(e,r.title,n,r,i);return this.setResourceRequestHandlers(),this.sendResourceListChanged(),s}}_createRegisteredResource(e,n,r,i,s){const a={name:e,title:n,metadata:i,readCallback:s,enabled:!0,disable:()=>a.update({enabled:!1}),enable:()=>a.update({enabled:!0}),remove:()=>a.update({uri:null}),update:o=>{typeof o.uri<"u"&&o.uri!==r&&(delete this._registeredResources[r],o.uri&&(this._registeredResources[o.uri]=a)),typeof o.name<"u"&&(a.name=o.name),typeof o.title<"u"&&(a.title=o.title),typeof o.metadata<"u"&&(a.metadata=o.metadata),typeof o.callback<"u"&&(a.readCallback=o.callback),typeof o.enabled<"u"&&(a.enabled=o.enabled),this.sendResourceListChanged()}};return this._registeredResources[r]=a,a}_createRegisteredResourceTemplate(e,n,r,i,s){const a={resourceTemplate:r,title:n,metadata:i,readCallback:s,enabled:!0,disable:()=>a.update({enabled:!1}),enable:()=>a.update({enabled:!0}),remove:()=>a.update({name:null}),update:o=>{typeof o.name<"u"&&o.name!==e&&(delete this._registeredResourceTemplates[e],o.name&&(this._registeredResourceTemplates[o.name]=a)),typeof o.title<"u"&&(a.title=o.title),typeof o.template<"u"&&(a.resourceTemplate=o.template),typeof o.metadata<"u"&&(a.metadata=o.metadata),typeof o.callback<"u"&&(a.readCallback=o.callback),typeof o.enabled<"u"&&(a.enabled=o.enabled),this.sendResourceListChanged()}};return this._registeredResourceTemplates[e]=a,a}_createRegisteredPrompt(e,n,r,i,s){const a={title:n,description:r,argsSchema:i===void 0?void 0:Ve(i),callback:s,enabled:!0,disable:()=>a.update({enabled:!1}),enable:()=>a.update({enabled:!0}),remove:()=>a.update({name:null}),update:o=>{typeof o.name<"u"&&o.name!==e&&(delete this._registeredPrompts[e],o.name&&(this._registeredPrompts[o.name]=a)),typeof o.title<"u"&&(a.title=o.title),typeof o.description<"u"&&(a.description=o.description),typeof o.argsSchema<"u"&&(a.argsSchema=Ve(o.argsSchema)),typeof o.callback<"u"&&(a.callback=o.callback),typeof o.enabled<"u"&&(a.enabled=o.enabled),this.sendPromptListChanged()}};return this._registeredPrompts[e]=a,a}_createRegisteredTool(e,n,r,i,s,a,o){const u={title:n,description:r,inputSchema:i===void 0?void 0:Ve(i),outputSchema:s===void 0?void 0:Ve(s),annotations:a,callback:o,enabled:!0,disable:()=>u.update({enabled:!1}),enable:()=>u.update({enabled:!0}),remove:()=>u.update({name:null}),update:l=>{typeof l.name<"u"&&l.name!==e&&(delete this._registeredTools[e],l.name&&(this._registeredTools[l.name]=u)),typeof l.title<"u"&&(u.title=l.title),typeof l.description<"u"&&(u.description=l.description),typeof l.paramsSchema<"u"&&(u.inputSchema=Ve(l.paramsSchema)),typeof l.callback<"u"&&(u.callback=l.callback),typeof l.annotations<"u"&&(u.annotations=l.annotations),typeof l.enabled<"u"&&(u.enabled=l.enabled),this.sendToolListChanged()}};return this._registeredTools[e]=u,this.setToolRequestHandlers(),this.sendToolListChanged(),u}tool(e,...n){if(this._registeredTools[e])throw new Error(`Tool ${e} is already registered`);let r,i,s,a;if(typeof n[0]=="string"&&(r=n.shift()),n.length>1){const u=n[0];sH(u)?(i=n.shift(),n.length>1&&typeof n[0]=="object"&&n[0]!==null&&!sH(n[0])&&(a=n.shift())):typeof u=="object"&&u!==null&&(a=n.shift())}const o=n[0];return this._createRegisteredTool(e,void 0,r,i,s,a,o)}registerTool(e,n,r){if(this._registeredTools[e])throw new Error(`Tool ${e} is already registered`);const{title:i,description:s,inputSchema:a,outputSchema:o,annotations:u}=n;return this._createRegisteredTool(e,i,s,a,o,u,r)}prompt(e,...n){if(this._registeredPrompts[e])throw new Error(`Prompt ${e} is already registered`);let r;typeof n[0]=="string"&&(r=n.shift());let i;n.length>1&&(i=n.shift());const s=n[0],a=this._createRegisteredPrompt(e,void 0,r,i,s);return this.setPromptRequestHandlers(),this.sendPromptListChanged(),a}registerPrompt(e,n,r){if(this._registeredPrompts[e])throw new Error(`Prompt ${e} is already registered`);const{title:i,description:s,argsSchema:a}=n,o=this._createRegisteredPrompt(e,i,s,a,r);return this.setPromptRequestHandlers(),this.sendPromptListChanged(),o}isConnected(){return this.server.transport!==void 0}async sendLoggingMessage(e,n){return this.server.sendLoggingMessage(e,n)}sendResourceListChanged(){this.isConnected()&&this.server.sendResourceListChanged()}sendToolListChanged(){this.isConnected()&&this.server.sendToolListChanged()}sendPromptListChanged(){this.isConnected()&&this.server.sendPromptListChanged()}}const rIe={type:"object",properties:{}};function sH(t){return typeof t!="object"||t===null?!1:Object.keys(t).length===0||Object.values(t).some(iIe)}function iIe(t){return t!==null&&typeof t=="object"&&"parse"in t&&typeof t.parse=="function"&&"safeParse"in t&&typeof t.safeParse=="function"}function sIe(t){return Object.entries(t.shape).map(([e,n])=>({name:e,description:n.description,required:!n.isOptional()}))}function aH(t){return{completion:{values:t.slice(0,100),total:t.length,hasMore:t.length>100}}}const R1={completion:{values:[],hasMore:!1}},aIe="1.39.0",oIe={version:aIe},i0=G.object({path:G.string().describe("Path to the file"),range:G.object({start:G.object({line:G.number(),character:G.number()}),end:G.object({line:G.number(),character:G.number()})}).describe("Range in the file")}).nullable(),Hf=G.string().refine(t=>!0).optional().default(Ur.DefaultProjectId).describe('Project id (optional, will use "default" if not specified)'),s0=G.array(G.object({id:G.string().describe("View id"),title:G.string().describe("View title"),type:G.enum(["element","deployment","dynamic"]).describe("View type")})),a0=t=>[...t].map(e=>({id:e.id,title:e.titleOrId,type:e.$view._type})),o0=(t,e)=>n=>{try{const r=t.locate({projectId:e,...n});return r?{path:rn.parse(r.uri).fsPath,range:r.range}:null}catch(r){return fn.debug(`Failed to locate ${n}`,{error:r}),null}},oH=G.object({id:G.string(),title:G.string(),kind:G.string()}),uIe=G.object({type:G.enum(["direct","indirect"]).describe('Type of relationship, "direct" for direct relationships, "indirect" for relationships through nested elements'),source:oH,target:oH,kind:G.string().nullable().describe("Relationship kind"),title:G.string().nullable().describe("Relationship title"),description:G.string().nullable().describe("Relationship description"),technology:G.string().nullable().describe("Relationship technology"),tags:G.array(G.string()).describe("Relationship tags"),includedInViews:s0.describe("Views that include this relationship"),sourceLocation:i0}),lIe=Ku({name:"find-relationships",annotations:{readOnlyHint:!0,idempotentHint:!0,title:"Find relationships between two elements"},description:`
355
+ ]`;continue}i+=r[u],r[u]==="\\"?s=!0:a&&r[u]==="]"?a=!1:!a&&r[u]==="["&&(a=!0)}try{new RegExp(i)}catch{return console.warn(`Could not convert regex pattern at ${e.currentPath.join("/")} to a flag-independent form! Falling back to the flag-ignorant source`),t.source}return i}function nH(t,e){if(e.target==="openAi"&&console.warn("Warning: OpenAI may not support records in schemas! Try an array of key-value pairs instead."),e.target==="openApi3"&&t.keyType?._def.typeName===Be.ZodEnum)return{type:"object",required:t.keyType._def.values,properties:t.keyType._def.values.reduce((r,i)=>({...r,[i]:on(t.valueType._def,{...e,currentPath:[...e.currentPath,"properties",i]})??{}}),{}),additionalProperties:e.rejectedAdditionalProperties};const n={type:"object",additionalProperties:on(t.valueType._def,{...e,currentPath:[...e.currentPath,"additionalProperties"]})??e.allowedAdditionalProperties};if(e.target==="openApi3")return n;if(t.keyType?._def.typeName===Be.ZodString&&t.keyType._def.checks?.length){const{type:r,...i}=eH(t.keyType._def,e);return{...n,propertyNames:i}}else{if(t.keyType?._def.typeName===Be.ZodEnum)return{...n,propertyNames:{enum:t.keyType._def.values}};if(t.keyType?._def.typeName===Be.ZodBranded&&t.keyType._def.type._def.typeName===Be.ZodString&&t.keyType._def.type._def.checks?.length){const{type:r,...i}=XU(t.keyType._def,e);return{...n,propertyNames:i}}}return n}function I$e(t,e){if(e.mapStrategy==="record")return nH(t,e);const n=on(t.keyType._def,{...e,currentPath:[...e.currentPath,"items","items","0"]})||{},r=on(t.valueType._def,{...e,currentPath:[...e.currentPath,"items","items","1"]})||{};return{type:"array",maxItems:125,items:{type:"array",items:[n,r],minItems:2,maxItems:2}}}function N$e(t){const e=t.values,r=Object.keys(t.values).filter(s=>typeof e[e[s]]!="number").map(s=>e[s]),i=Array.from(new Set(r.map(s=>typeof s)));return{type:i.length===1?i[0]==="string"?"string":"number":["string","number"],enum:r}}function O$e(){return{not:{}}}function L$e(t){return t.target==="openApi3"?{enum:["null"],nullable:!0}:{type:"null"}}const S1={ZodString:"string",ZodNumber:"number",ZodBigInt:"integer",ZodBoolean:"boolean",ZodNull:"null"};function M$e(t,e){if(e.target==="openApi3")return rH(t,e);const n=t.options instanceof Map?Array.from(t.options.values()):t.options;if(n.every(r=>r._def.typeName in S1&&(!r._def.checks||!r._def.checks.length))){const r=n.reduce((i,s)=>{const a=S1[s._def.typeName];return a&&!i.includes(a)?[...i,a]:i},[]);return{type:r.length>1?r:r[0]}}else if(n.every(r=>r._def.typeName==="ZodLiteral"&&!r.description)){const r=n.reduce((i,s)=>{const a=typeof s._def.value;switch(a){case"string":case"number":case"boolean":return[...i,a];case"bigint":return[...i,"integer"];case"object":if(s._def.value===null)return[...i,"null"];case"symbol":case"undefined":case"function":default:return i}},[]);if(r.length===n.length){const i=r.filter((s,a,o)=>o.indexOf(s)===a);return{type:i.length>1?i:i[0],enum:n.reduce((s,a)=>s.includes(a._def.value)?s:[...s,a._def.value],[])}}}else if(n.every(r=>r._def.typeName==="ZodEnum"))return{type:"string",enum:n.reduce((r,i)=>[...r,...i._def.values.filter(s=>!r.includes(s))],[])};return rH(t,e)}const rH=(t,e)=>{const n=(t.options instanceof Map?Array.from(t.options.values()):t.options).map((r,i)=>on(r._def,{...e,currentPath:[...e.currentPath,"anyOf",`${i}`]})).filter(r=>!!r&&(!e.strictUnions||typeof r=="object"&&Object.keys(r).length>0));return n.length?{anyOf:n}:void 0};function F$e(t,e){if(["ZodString","ZodNumber","ZodBigInt","ZodBoolean","ZodNull"].includes(t.innerType._def.typeName)&&(!t.innerType._def.checks||!t.innerType._def.checks.length))return e.target==="openApi3"?{type:S1[t.innerType._def.typeName],nullable:!0}:{type:[S1[t.innerType._def.typeName],"null"]};if(e.target==="openApi3"){const r=on(t.innerType._def,{...e,currentPath:[...e.currentPath]});return r&&"$ref"in r?{allOf:[r],nullable:!0}:r&&{...r,nullable:!0}}const n=on(t.innerType._def,{...e,currentPath:[...e.currentPath,"anyOf","0"]});return n&&{anyOf:[n,{type:"null"}]}}function B$e(t,e){const n={type:"number"};if(!t.checks)return n;for(const r of t.checks)switch(r.kind){case"int":n.type="integer",QU(n,"type",r.message,e);break;case"min":e.target==="jsonSchema7"?r.inclusive?hn(n,"minimum",r.value,r.message,e):hn(n,"exclusiveMinimum",r.value,r.message,e):(r.inclusive||(n.exclusiveMinimum=!0),hn(n,"minimum",r.value,r.message,e));break;case"max":e.target==="jsonSchema7"?r.inclusive?hn(n,"maximum",r.value,r.message,e):hn(n,"exclusiveMaximum",r.value,r.message,e):(r.inclusive||(n.exclusiveMaximum=!0),hn(n,"maximum",r.value,r.message,e));break;case"multipleOf":hn(n,"multipleOf",r.value,r.message,e);break}return n}function j$e(t,e){const n=e.target==="openAi",r={type:"object",properties:{}},i=[],s=t.shape();for(const o in s){let u=s[o];if(u===void 0||u._def===void 0)continue;let l=U$e(u);l&&n&&(u instanceof ya&&(u=u._def.innerType),u.isNullable()||(u=u.nullable()),l=!1);const c=on(u._def,{...e,currentPath:[...e.currentPath,"properties",o],propertyPath:[...e.currentPath,"properties",o]});c!==void 0&&(r.properties[o]=c,l||i.push(o))}i.length&&(r.required=i);const a=q$e(t,e);return a!==void 0&&(r.additionalProperties=a),r}function q$e(t,e){if(t.catchall._def.typeName!=="ZodNever")return on(t.catchall._def,{...e,currentPath:[...e.currentPath,"additionalProperties"]});switch(t.unknownKeys){case"passthrough":return e.allowedAdditionalProperties;case"strict":return e.rejectedAdditionalProperties;case"strip":return e.removeAdditionalStrategy==="strict"?e.allowedAdditionalProperties:e.rejectedAdditionalProperties}}function U$e(t){try{return t.isOptional()}catch{return!0}}const H$e=(t,e)=>{if(e.currentPath.toString()===e.propertyPath?.toString())return on(t.innerType._def,e);const n=on(t.innerType._def,{...e,currentPath:[...e.currentPath,"anyOf","1"]});return n?{anyOf:[{not:{}},n]}:{}},z$e=(t,e)=>{if(e.pipeStrategy==="input")return on(t.in._def,e);if(e.pipeStrategy==="output")return on(t.out._def,e);const n=on(t.in._def,{...e,currentPath:[...e.currentPath,"allOf","0"]}),r=on(t.out._def,{...e,currentPath:[...e.currentPath,"allOf",n?"1":"0"]});return{allOf:[n,r].filter(i=>i!==void 0)}};function W$e(t,e){return on(t.type._def,e)}function G$e(t,e){const r={type:"array",uniqueItems:!0,items:on(t.valueType._def,{...e,currentPath:[...e.currentPath,"items"]})};return t.minSize&&hn(r,"minItems",t.minSize.value,t.minSize.message,e),t.maxSize&&hn(r,"maxItems",t.maxSize.value,t.maxSize.message,e),r}function V$e(t,e){return t.rest?{type:"array",minItems:t.items.length,items:t.items.map((n,r)=>on(n._def,{...e,currentPath:[...e.currentPath,"items",`${r}`]})).reduce((n,r)=>r===void 0?n:[...n,r],[]),additionalItems:on(t.rest._def,{...e,currentPath:[...e.currentPath,"additionalItems"]})}:{type:"array",minItems:t.items.length,maxItems:t.items.length,items:t.items.map((n,r)=>on(n._def,{...e,currentPath:[...e.currentPath,"items",`${r}`]})).reduce((n,r)=>r===void 0?n:[...n,r],[])}}function K$e(){return{not:{}}}function Y$e(){return{}}const Z$e=(t,e)=>on(t.innerType._def,e),Q$e=(t,e,n)=>{switch(e){case Be.ZodString:return eH(t,n);case Be.ZodNumber:return B$e(t,n);case Be.ZodObject:return j$e(t,n);case Be.ZodBigInt:return w$e(t,n);case Be.ZodBoolean:return _$e();case Be.ZodDate:return JU(t,n);case Be.ZodUndefined:return K$e();case Be.ZodNull:return L$e(n);case Be.ZodArray:return E$e(t,n);case Be.ZodUnion:case Be.ZodDiscriminatedUnion:return M$e(t,n);case Be.ZodIntersection:return D$e(t,n);case Be.ZodTuple:return V$e(t,n);case Be.ZodRecord:return nH(t,n);case Be.ZodLiteral:return x$e(t,n);case Be.ZodEnum:return A$e(t);case Be.ZodNativeEnum:return N$e(t);case Be.ZodNullable:return F$e(t,n);case Be.ZodOptional:return H$e(t,n);case Be.ZodMap:return I$e(t,n);case Be.ZodSet:return G$e(t,n);case Be.ZodLazy:return()=>t.getter()._def;case Be.ZodPromise:return W$e(t,n);case Be.ZodNaN:case Be.ZodNever:return O$e();case Be.ZodEffects:return R$e(t,n);case Be.ZodAny:return b$e();case Be.ZodUnknown:return Y$e();case Be.ZodDefault:return S$e(t,n);case Be.ZodBranded:return XU(t,n);case Be.ZodReadonly:return Z$e(t,n);case Be.ZodCatch:return T$e(t,n);case Be.ZodPipeline:return z$e(t,n);case Be.ZodFunction:case Be.ZodVoid:case Be.ZodSymbol:return;default:return(r=>{})()}};function on(t,e,n=!1){const r=e.seen.get(t);if(e.override){const o=e.override?.(t,e,r,n);if(o!==g$e)return o}if(r&&!n){const o=X$e(r,e);if(o!==void 0)return o}const i={def:t,path:e.currentPath,jsonSchema:void 0};e.seen.set(t,i);const s=Q$e(t,t.typeName,e),a=typeof s=="function"?on(s(),e):s;if(a&&eIe(t,e,a),e.postProcess){const o=e.postProcess(a,t,e);return i.jsonSchema=a,o}return i.jsonSchema=a,a}const X$e=(t,e)=>{switch(e.$refStrategy){case"root":return{$ref:t.path.join("/")};case"relative":return{$ref:J$e(e.currentPath,t.path)};case"none":case"seen":return t.path.length<e.currentPath.length&&t.path.every((n,r)=>e.currentPath[r]===n)?(console.warn(`Recursive reference detected at ${e.currentPath.join("/")}! Defaulting to any`),{}):e.$refStrategy==="seen"?{}:void 0}},J$e=(t,e)=>{let n=0;for(;n<t.length&&n<e.length&&t[n]===e[n];n++);return[(t.length-n).toString(),...e.slice(n)].join("/")},eIe=(t,e,n)=>(t.description&&(n.description=t.description,e.markdownDescription&&(n.markdownDescription=t.description)),n),iH=(t,e)=>{const n=v$e(e),r=typeof e=="object"&&e.definitions?Object.entries(e.definitions).reduce((u,[l,c])=>({...u,[l]:on(c._def,{...n,currentPath:[...n.basePath,n.definitionPath,l]},!0)??{}}),{}):void 0,i=typeof e=="string"?e:e?.nameStrategy==="title"?void 0:e?.name,s=on(t._def,i===void 0?n:{...n,currentPath:[...n.basePath,n.definitionPath,i]},!1)??{},a=typeof e=="object"&&e.name!==void 0&&e.nameStrategy==="title"?e.name:void 0;a!==void 0&&(s.title=a);const o=i===void 0?r?{...s,[n.definitionPath]:r}:s:{$ref:[...n.$refStrategy==="relative"?[]:n.basePath,n.definitionPath,i].join("/"),[n.definitionPath]:{...r,[i]:s}};return n.target==="jsonSchema7"?o.$schema="http://json-schema.org/draft-07/schema#":(n.target==="jsonSchema2019-09"||n.target==="openAi")&&(o.$schema="https://json-schema.org/draft/2019-09/schema#"),n.target==="openAi"&&("anyOf"in o||"oneOf"in o||"allOf"in o||"type"in o&&Array.isArray(o.type))&&console.warn("Warning: OpenAI may not support schemas with unions as roots! Try wrapping it in an object property."),o};var JD;(function(t){t.Completable="McpCompletable"})(JD||(JD={}));class ex extends Nt{_parse(e){const{ctx:n}=this._processInputParams(e),r=n.data;return this._def.type._parse({data:r,path:n.path,parent:n})}unwrap(){return this._def.type}}ex.create=(t,e)=>new ex({type:t,typeName:JD.Completable,complete:e.complete,...tIe(e)});function tIe(t){if(!t)return{};const{errorMap:e,invalid_type_error:n,required_error:r,description:i}=t;if(e&&(n||r))throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);return e?{errorMap:e,description:i}:{errorMap:(a,o)=>{var u,l;const{message:c}=t;return a.code==="invalid_enum_value"?{message:c??o.defaultError}:typeof o.data>"u"?{message:(u=c??r)!==null&&u!==void 0?u:o.defaultError}:a.code!=="invalid_type"?{message:o.defaultError}:{message:(l=c??n)!==null&&l!==void 0?l:o.defaultError}},description:i}}class nIe{constructor(e,n){this._registeredResources={},this._registeredResourceTemplates={},this._registeredTools={},this._registeredPrompts={},this._toolHandlersInitialized=!1,this._completionHandlerInitialized=!1,this._resourceHandlersInitialized=!1,this._promptHandlersInitialized=!1,this.server=new m$e(e,n)}async connect(e){return await this.server.connect(e)}async close(){await this.server.close()}setToolRequestHandlers(){this._toolHandlersInitialized||(this.server.assertCanSetRequestHandler(nC.shape.method.value),this.server.assertCanSetRequestHandler(rC.shape.method.value),this.server.registerCapabilities({tools:{listChanged:!0}}),this.server.setRequestHandler(nC,()=>({tools:Object.entries(this._registeredTools).filter(([,e])=>e.enabled).map(([e,n])=>{const r={name:e,title:n.title,description:n.description,inputSchema:n.inputSchema?iH(n.inputSchema,{strictUnions:!0}):rIe,annotations:n.annotations};return n.outputSchema&&(r.outputSchema=iH(n.outputSchema,{strictUnions:!0})),r})})),this.server.setRequestHandler(rC,async(e,n)=>{const r=this._registeredTools[e.params.name];if(!r)throw new cr(Kn.InvalidParams,`Tool ${e.params.name} not found`);if(!r.enabled)throw new cr(Kn.InvalidParams,`Tool ${e.params.name} disabled`);let i;if(r.inputSchema){const s=await r.inputSchema.safeParseAsync(e.params.arguments);if(!s.success)throw new cr(Kn.InvalidParams,`Invalid arguments for tool ${e.params.name}: ${s.error.message}`);const a=s.data,o=r.callback;try{i=await Promise.resolve(o(a,n))}catch(u){i={content:[{type:"text",text:u instanceof Error?u.message:String(u)}],isError:!0}}}else{const s=r.callback;try{i=await Promise.resolve(s(n))}catch(a){i={content:[{type:"text",text:a instanceof Error?a.message:String(a)}],isError:!0}}}if(r.outputSchema&&!i.isError){if(!i.structuredContent)throw new cr(Kn.InvalidParams,`Tool ${e.params.name} has an output schema but no structured content was provided`);const s=await r.outputSchema.safeParseAsync(i.structuredContent);if(!s.success)throw new cr(Kn.InvalidParams,`Invalid structured content for tool ${e.params.name}: ${s.error.message}`)}return i}),this._toolHandlersInitialized=!0)}setCompletionRequestHandler(){this._completionHandlerInitialized||(this.server.assertCanSetRequestHandler(iC.shape.method.value),this.server.registerCapabilities({completions:{}}),this.server.setRequestHandler(iC,async e=>{switch(e.params.ref.type){case"ref/prompt":return this.handlePromptCompletion(e,e.params.ref);case"ref/resource":return this.handleResourceCompletion(e,e.params.ref);default:throw new cr(Kn.InvalidParams,`Invalid completion reference: ${e.params.ref}`)}}),this._completionHandlerInitialized=!0)}async handlePromptCompletion(e,n){const r=this._registeredPrompts[n.name];if(!r)throw new cr(Kn.InvalidParams,`Prompt ${n.name} not found`);if(!r.enabled)throw new cr(Kn.InvalidParams,`Prompt ${n.name} disabled`);if(!r.argsSchema)return R1;const i=r.argsSchema.shape[e.params.argument.name];if(!(i instanceof ex))return R1;const a=await i._def.complete(e.params.argument.value,e.params.context);return aH(a)}async handleResourceCompletion(e,n){const r=Object.values(this._registeredResourceTemplates).find(a=>a.resourceTemplate.uriTemplate.toString()===n.uri);if(!r){if(this._registeredResources[n.uri])return R1;throw new cr(Kn.InvalidParams,`Resource template ${e.params.ref.uri} not found`)}const i=r.resourceTemplate.completeCallback(e.params.argument.name);if(!i)return R1;const s=await i(e.params.argument.value,e.params.context);return aH(s)}setResourceRequestHandlers(){this._resourceHandlersInitialized||(this.server.assertCanSetRequestHandler(KA.shape.method.value),this.server.assertCanSetRequestHandler(YA.shape.method.value),this.server.assertCanSetRequestHandler(ZA.shape.method.value),this.server.registerCapabilities({resources:{listChanged:!0}}),this.server.setRequestHandler(KA,async(e,n)=>{const r=Object.entries(this._registeredResources).filter(([s,a])=>a.enabled).map(([s,a])=>({uri:s,name:a.name,...a.metadata})),i=[];for(const s of Object.values(this._registeredResourceTemplates)){if(!s.resourceTemplate.listCallback)continue;const a=await s.resourceTemplate.listCallback(n);for(const o of a.resources)i.push({...s.metadata,...o})}return{resources:[...r,...i]}}),this.server.setRequestHandler(YA,async()=>({resourceTemplates:Object.entries(this._registeredResourceTemplates).map(([n,r])=>({name:n,uriTemplate:r.resourceTemplate.uriTemplate.toString(),...r.metadata}))})),this.server.setRequestHandler(ZA,async(e,n)=>{const r=new URL(e.params.uri),i=this._registeredResources[r.toString()];if(i){if(!i.enabled)throw new cr(Kn.InvalidParams,`Resource ${r} disabled`);return i.readCallback(r,n)}for(const s of Object.values(this._registeredResourceTemplates)){const a=s.resourceTemplate.uriTemplate.match(r.toString());if(a)return s.readCallback(r,a,n)}throw new cr(Kn.InvalidParams,`Resource ${r} not found`)}),this.setCompletionRequestHandler(),this._resourceHandlersInitialized=!0)}setPromptRequestHandlers(){this._promptHandlersInitialized||(this.server.assertCanSetRequestHandler(QA.shape.method.value),this.server.assertCanSetRequestHandler(XA.shape.method.value),this.server.registerCapabilities({prompts:{listChanged:!0}}),this.server.setRequestHandler(QA,()=>({prompts:Object.entries(this._registeredPrompts).filter(([,e])=>e.enabled).map(([e,n])=>({name:e,title:n.title,description:n.description,arguments:n.argsSchema?sIe(n.argsSchema):void 0}))})),this.server.setRequestHandler(XA,async(e,n)=>{const r=this._registeredPrompts[e.params.name];if(!r)throw new cr(Kn.InvalidParams,`Prompt ${e.params.name} not found`);if(!r.enabled)throw new cr(Kn.InvalidParams,`Prompt ${e.params.name} disabled`);if(r.argsSchema){const i=await r.argsSchema.safeParseAsync(e.params.arguments);if(!i.success)throw new cr(Kn.InvalidParams,`Invalid arguments for prompt ${e.params.name}: ${i.error.message}`);const s=i.data,a=r.callback;return await Promise.resolve(a(s,n))}else{const i=r.callback;return await Promise.resolve(i(n))}}),this.setCompletionRequestHandler(),this._promptHandlersInitialized=!0)}resource(e,n,...r){let i;typeof r[0]=="object"&&(i=r.shift());const s=r[0];if(typeof n=="string"){if(this._registeredResources[n])throw new Error(`Resource ${n} is already registered`);const a=this._createRegisteredResource(e,void 0,n,i,s);return this.setResourceRequestHandlers(),this.sendResourceListChanged(),a}else{if(this._registeredResourceTemplates[e])throw new Error(`Resource template ${e} is already registered`);const a=this._createRegisteredResourceTemplate(e,void 0,n,i,s);return this.setResourceRequestHandlers(),this.sendResourceListChanged(),a}}registerResource(e,n,r,i){if(typeof n=="string"){if(this._registeredResources[n])throw new Error(`Resource ${n} is already registered`);const s=this._createRegisteredResource(e,r.title,n,r,i);return this.setResourceRequestHandlers(),this.sendResourceListChanged(),s}else{if(this._registeredResourceTemplates[e])throw new Error(`Resource template ${e} is already registered`);const s=this._createRegisteredResourceTemplate(e,r.title,n,r,i);return this.setResourceRequestHandlers(),this.sendResourceListChanged(),s}}_createRegisteredResource(e,n,r,i,s){const a={name:e,title:n,metadata:i,readCallback:s,enabled:!0,disable:()=>a.update({enabled:!1}),enable:()=>a.update({enabled:!0}),remove:()=>a.update({uri:null}),update:o=>{typeof o.uri<"u"&&o.uri!==r&&(delete this._registeredResources[r],o.uri&&(this._registeredResources[o.uri]=a)),typeof o.name<"u"&&(a.name=o.name),typeof o.title<"u"&&(a.title=o.title),typeof o.metadata<"u"&&(a.metadata=o.metadata),typeof o.callback<"u"&&(a.readCallback=o.callback),typeof o.enabled<"u"&&(a.enabled=o.enabled),this.sendResourceListChanged()}};return this._registeredResources[r]=a,a}_createRegisteredResourceTemplate(e,n,r,i,s){const a={resourceTemplate:r,title:n,metadata:i,readCallback:s,enabled:!0,disable:()=>a.update({enabled:!1}),enable:()=>a.update({enabled:!0}),remove:()=>a.update({name:null}),update:o=>{typeof o.name<"u"&&o.name!==e&&(delete this._registeredResourceTemplates[e],o.name&&(this._registeredResourceTemplates[o.name]=a)),typeof o.title<"u"&&(a.title=o.title),typeof o.template<"u"&&(a.resourceTemplate=o.template),typeof o.metadata<"u"&&(a.metadata=o.metadata),typeof o.callback<"u"&&(a.readCallback=o.callback),typeof o.enabled<"u"&&(a.enabled=o.enabled),this.sendResourceListChanged()}};return this._registeredResourceTemplates[e]=a,a}_createRegisteredPrompt(e,n,r,i,s){const a={title:n,description:r,argsSchema:i===void 0?void 0:Ve(i),callback:s,enabled:!0,disable:()=>a.update({enabled:!1}),enable:()=>a.update({enabled:!0}),remove:()=>a.update({name:null}),update:o=>{typeof o.name<"u"&&o.name!==e&&(delete this._registeredPrompts[e],o.name&&(this._registeredPrompts[o.name]=a)),typeof o.title<"u"&&(a.title=o.title),typeof o.description<"u"&&(a.description=o.description),typeof o.argsSchema<"u"&&(a.argsSchema=Ve(o.argsSchema)),typeof o.callback<"u"&&(a.callback=o.callback),typeof o.enabled<"u"&&(a.enabled=o.enabled),this.sendPromptListChanged()}};return this._registeredPrompts[e]=a,a}_createRegisteredTool(e,n,r,i,s,a,o){const u={title:n,description:r,inputSchema:i===void 0?void 0:Ve(i),outputSchema:s===void 0?void 0:Ve(s),annotations:a,callback:o,enabled:!0,disable:()=>u.update({enabled:!1}),enable:()=>u.update({enabled:!0}),remove:()=>u.update({name:null}),update:l=>{typeof l.name<"u"&&l.name!==e&&(delete this._registeredTools[e],l.name&&(this._registeredTools[l.name]=u)),typeof l.title<"u"&&(u.title=l.title),typeof l.description<"u"&&(u.description=l.description),typeof l.paramsSchema<"u"&&(u.inputSchema=Ve(l.paramsSchema)),typeof l.callback<"u"&&(u.callback=l.callback),typeof l.annotations<"u"&&(u.annotations=l.annotations),typeof l.enabled<"u"&&(u.enabled=l.enabled),this.sendToolListChanged()}};return this._registeredTools[e]=u,this.setToolRequestHandlers(),this.sendToolListChanged(),u}tool(e,...n){if(this._registeredTools[e])throw new Error(`Tool ${e} is already registered`);let r,i,s,a;if(typeof n[0]=="string"&&(r=n.shift()),n.length>1){const u=n[0];sH(u)?(i=n.shift(),n.length>1&&typeof n[0]=="object"&&n[0]!==null&&!sH(n[0])&&(a=n.shift())):typeof u=="object"&&u!==null&&(a=n.shift())}const o=n[0];return this._createRegisteredTool(e,void 0,r,i,s,a,o)}registerTool(e,n,r){if(this._registeredTools[e])throw new Error(`Tool ${e} is already registered`);const{title:i,description:s,inputSchema:a,outputSchema:o,annotations:u}=n;return this._createRegisteredTool(e,i,s,a,o,u,r)}prompt(e,...n){if(this._registeredPrompts[e])throw new Error(`Prompt ${e} is already registered`);let r;typeof n[0]=="string"&&(r=n.shift());let i;n.length>1&&(i=n.shift());const s=n[0],a=this._createRegisteredPrompt(e,void 0,r,i,s);return this.setPromptRequestHandlers(),this.sendPromptListChanged(),a}registerPrompt(e,n,r){if(this._registeredPrompts[e])throw new Error(`Prompt ${e} is already registered`);const{title:i,description:s,argsSchema:a}=n,o=this._createRegisteredPrompt(e,i,s,a,r);return this.setPromptRequestHandlers(),this.sendPromptListChanged(),o}isConnected(){return this.server.transport!==void 0}async sendLoggingMessage(e,n){return this.server.sendLoggingMessage(e,n)}sendResourceListChanged(){this.isConnected()&&this.server.sendResourceListChanged()}sendToolListChanged(){this.isConnected()&&this.server.sendToolListChanged()}sendPromptListChanged(){this.isConnected()&&this.server.sendPromptListChanged()}}const rIe={type:"object",properties:{}};function sH(t){return typeof t!="object"||t===null?!1:Object.keys(t).length===0||Object.values(t).some(iIe)}function iIe(t){return t!==null&&typeof t=="object"&&"parse"in t&&typeof t.parse=="function"&&"safeParse"in t&&typeof t.safeParse=="function"}function sIe(t){return Object.entries(t.shape).map(([e,n])=>({name:e,description:n.description,required:!n.isOptional()}))}function aH(t){return{completion:{values:t.slice(0,100),total:t.length,hasMore:t.length>100}}}const R1={completion:{values:[],hasMore:!1}},aIe="1.39.1",oIe={version:aIe},i0=G.object({path:G.string().describe("Path to the file"),range:G.object({start:G.object({line:G.number(),character:G.number()}),end:G.object({line:G.number(),character:G.number()})}).describe("Range in the file")}).nullable(),Hf=G.string().refine(t=>!0).optional().default(Ur.DefaultProjectId).describe('Project id (optional, will use "default" if not specified)'),s0=G.array(G.object({id:G.string().describe("View id"),title:G.string().describe("View title"),type:G.enum(["element","deployment","dynamic"]).describe("View type")})),a0=t=>[...t].map(e=>({id:e.id,title:e.titleOrId,type:e.$view._type})),o0=(t,e)=>n=>{try{const r=t.locate({projectId:e,...n});return r?{path:rn.parse(r.uri).fsPath,range:r.range}:null}catch(r){return fn.debug(`Failed to locate ${n}`,{error:r}),null}},oH=G.object({id:G.string(),title:G.string(),kind:G.string()}),uIe=G.object({type:G.enum(["direct","indirect"]).describe('Type of relationship, "direct" for direct relationships, "indirect" for relationships through nested elements'),source:oH,target:oH,kind:G.string().nullable().describe("Relationship kind"),title:G.string().nullable().describe("Relationship title"),description:G.string().nullable().describe("Relationship description"),technology:G.string().nullable().describe("Relationship technology"),tags:G.array(G.string()).describe("Relationship tags"),includedInViews:s0.describe("Views that include this relationship"),sourceLocation:i0}),lIe=Ku({name:"find-relationships",annotations:{readOnlyHint:!0,idempotentHint:!0,title:"Find relationships between two elements"},description:`
356
356
  Find relationships between two LikeC4 elements within a project.
357
357
 
358
358
  What it does:
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.39.0",
5
+ "version": "1.39.1",
6
6
  "bugs": "https://github.com/likec4/likec4/issues",
7
7
  "homepage": "https://likec4.dev",
8
8
  "author": "Denis Davydkov <denis@davydkov.com>",
@@ -64,10 +64,10 @@
64
64
  "vscode-uri": "3.1.0",
65
65
  "wireit": "0.14.12",
66
66
  "zod": "3.25.76",
67
- "@likec4/core": "1.39.0",
68
- "@likec4/language-server": "1.39.0",
69
- "@likec4/log": "1.39.0",
70
- "@likec4/tsconfig": "1.39.0"
67
+ "@likec4/core": "1.39.1",
68
+ "@likec4/language-server": "1.39.1",
69
+ "@likec4/log": "1.39.1",
70
+ "@likec4/tsconfig": "1.39.1"
71
71
  },
72
72
  "scripts": {
73
73
  "typecheck": "tsc -b --verbose",