@decaf-ts/mcp-server 1.1.0 → 1.2.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.
Files changed (45) hide show
  1. package/dist/assets/code/patterns/builder.enc +0 -0
  2. package/dist/assets/prompts/agent/agent.enc +0 -0
  3. package/dist/assets/prompts/agent/init.enc +0 -0
  4. package/dist/assets/prompts/constitution_commands.enc +0 -0
  5. package/dist/assets/prompts/documentation/class.enc +0 -0
  6. package/dist/assets/prompts/documentation/constant.enc +0 -0
  7. package/dist/assets/prompts/documentation/decorator.enc +0 -0
  8. package/dist/assets/prompts/documentation/file.enc +0 -0
  9. package/dist/assets/prompts/documentation/function.enc +0 -0
  10. package/dist/assets/prompts/documentation/interface.enc +0 -0
  11. package/dist/assets/prompts/documentation/iterate.enc +0 -0
  12. package/dist/assets/prompts/documentation/module.enc +0 -0
  13. package/dist/assets/prompts/documentation/prefix.enc +0 -0
  14. package/dist/assets/prompts/documentation/repo.enc +0 -0
  15. package/dist/assets/prompts/documentation/suffix.enc +0 -0
  16. package/dist/assets/prompts/git_commands.enc +0 -0
  17. package/dist/assets/prompts/jira/operational_prompts.enc +0 -0
  18. package/dist/assets/prompts/jira/system_prompt.enc +0 -0
  19. package/dist/assets/prompts/mode_commands.enc +0 -0
  20. package/dist/assets/prompts/plan_commands.enc +0 -0
  21. package/dist/assets/prompts/repository/readme.enc +0 -0
  22. package/dist/assets/prompts/repository/release_notes.enc +0 -0
  23. package/dist/assets/prompts/repository/setup.enc +0 -0
  24. package/dist/assets/prompts/specification_commands.enc +0 -0
  25. package/dist/assets/prompts/startup_command.enc +0 -0
  26. package/dist/assets/prompts/task_commands.enc +0 -0
  27. package/dist/assets/prompts/tests/coverage.enc +0 -0
  28. package/dist/assets/templates/AGENTS.enc +0 -0
  29. package/dist/assets/templates/agents_template.enc +0 -0
  30. package/dist/assets/templates/constitution_template.enc +0 -0
  31. package/dist/assets/templates/decaf/context/logCtx.enc +0 -0
  32. package/dist/assets/templates/decaf/services/client_based_service.enc +0 -0
  33. package/dist/assets/templates/decaf/services/model_service.enc +0 -0
  34. package/dist/assets/templates/decaf/services/service.enc +0 -0
  35. package/dist/assets/templates/decaf_guidelines.enc +0 -0
  36. package/dist/assets/templates/instructions_template.enc +0 -0
  37. package/dist/assets/templates/jira_templates.enc +0 -0
  38. package/dist/assets/templates/plan_template.enc +0 -0
  39. package/dist/assets/templates/specification_template.enc +0 -0
  40. package/dist/assets/templates/task_template.enc +0 -0
  41. package/dist/mcp-server.cjs +1 -1
  42. package/dist/mcp-server.cjs.map +1 -1
  43. package/dist/mcp-server.js +1 -1
  44. package/dist/mcp-server.js.map +1 -1
  45. package/package.json +5 -1
Binary file
Binary file
Binary file
@@ -1,3 +1,3 @@
1
1
  #!/usr/bin/env node
2
- var e,t;e=this,t=function(e,t,r,s,i,n,o,a,c,d,l,p,u,m,h,g,f,y){"use strict";function b(e){var t=Object.create(null);return e&&Object.keys(e).forEach(r=>{if("default"!==r){var s=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,s.get?s:{enumerable:!0,get:()=>e[r]})}}),t.default=e,Object.freeze(t)}var v=b(r),S=b(s);const w=["\x1b[38;5;215m","\x1b[38;5;209m","\x1b[38;5;205m","\x1b[38;5;210m","\x1b[38;5;217m","\x1b[38;5;216m","\x1b[38;5;224m","\x1b[38;5;230m","\x1b[38;5;230m"];var j,I,_,z,T;(e=>{e[e.NONE=0]="NONE",e[e.BASIC=1]="BASIC",e[e.ADVANCED=2]="ADVANCED",e[e.HIGH=3]="HIGH"})(j||(j={})),(e=>{e[e.NONE=0]="NONE",e[e.LOW=1]="LOW",e[e.MEDIUM=2]="MEDIUM",e[e.HIGH=3]="HIGH"})(I||(I={})),(e=>{e[e.FREE=0]="FREE",e[e.LOW=1]="LOW",e[e.MEDIUM=2]="MEDIUM",e[e.HIGH=3]="HIGH"})(_||(_={}));class E extends n.Model{get log(){return this._log||(this._log=e.Logging.for(this)),this._log}constructor(e){super(e)}logFor(e){const{sessionId:t,requestId:r,authInfo:s}=e||{};let i="string"==typeof t&&t.length>0?this.log.for(t):this.log;return s&&s.clientId&&(i=i.for(s.clientId)),r&&(i=i.for(r.toString())),i}setDescription(e){return this.description=e,this}getDescription(){return this.description}setName(e){return this.name=e,this}getName(){return this.name}setTitle(e){return this.title=e,this}}i.__decorate([n.required(),i.__metadata("design:type",String)],E.prototype,"description",void 0),i.__decorate([n.required(),i.__metadata("design:type",String)],E.prototype,"name",void 0),i.__decorate([n.required(),i.__metadata("design:type",String)],E.prototype,"title",void 0);class O extends E{constructor(e){super(e),this.reasoning=j.NONE,this.effort=I.NONE,this.cost=_.FREE}setReasoning(e){return this.reasoning=e,this}setEffort(e){return this.effort=e,this}setCost(e){return this.cost=e,this}}function x(e){if(!e)return;let t=e,r=t&&t._def;for(;r&&"ZodObject"!==r.typeName;){if("ZodEffects"===r.typeName&&r.schema)t=r.schema;else if("ZodOptional"===r.typeName&&r.innerType)t=r.innerType;else if("ZodDefault"===r.typeName&&r.innerType)t=r.innerType;else if("ZodNullable"===r.typeName&&r.innerType)t=r.innerType;else{if(!r.schema)return;t=r.schema}r=t&&t._def}return r&&"ZodObject"===r.typeName?r:void 0}function A(e,t="schema"){if(x(e))return e;if(e&&"object"==typeof e){const t=e.def&&"object"==typeof e.def?e.def:void 0,r=t&&(t.shape||"object"===t.type)&&t.shape||("object"===e.type?e.shape:void 0)||(t&&"object"===t.type?{}:void 0);if(t||"object"===e.type||r){const e={};if(r&&"object"==typeof r)for(const[t,s]of Object.entries(r))e[t]=H(s)?s:o.z.any();return o.z.object(e)}}throw Error(`Registration error: provided a non-canonical ${t}. Export a ZodObject (z.object(...)).`)}function N(e){if(!e)return;if(e&&"object"==typeof e&&!e._def)return e.def&&"object"==typeof e.def&&e.def.shape?e.def.shape:e;const t=x(e);return t?"function"==typeof t.shape?t.shape():t.shape||void 0:void 0}function H(e){return!(!e||"object"!=typeof e||!e._def)}i.__decorate([n.required(),i.__metadata("design:type",Number)],O.prototype,"reasoning",void 0),i.__decorate([n.required(),i.__metadata("design:type",Number)],O.prototype,"effort",void 0),i.__decorate([n.required(),i.__metadata("design:type",Number)],O.prototype,"cost",void 0),(e=>{e.ASSETS="assets"})(z||(z={})),(e=>{e.PROMPT="prompts",e.DOCUMENTATION="documentation",e.CODE="code"})(T||(T={}));const C=Buffer.from("DCAF1","ascii");function k(e){let t=e;for(;;){const e=v.join(t,"lib","assets");if(S.existsSync(e))return e;const r=v.join(t,"src","assets");if(S.existsSync(r))return r;const s=v.join(t,"assets");if(S.existsSync(s))return s;const i=v.dirname(t);if(i===t)break;t=i}}function D(){const e=process.env.DECAF_ASSET_DIR||process.env.MCP_ASSET_DIR||process.env.ASSET_DIR||"";if(e&&S.existsSync(e))return e;const t=process.argv?.[1];if(t){const e=k(v.dirname(t));if(e)return e}const r=[process.cwd(),process.env.INIT_CWD].filter(Boolean);for(const e of r){const t=k(e);if(t)return t}return v.join(process.cwd(),"assets")}let P=class extends e.LoggedClass{constructor(e){super(),this.basePath=e||D()}listAssets(...e){const t=v.join(this.basePath,...e);return S.readdirSync(t)}listPrompts(){return this.listAssets(T.PROMPT)}getAsset(e,t="md",...r){const s=v.join(this.basePath,...r),i=(e,t=!1)=>{try{return t?(e=>{if(e.length<C.length+16+12+16)throw Error("Invalid prompt payload (too short)");if(!e.subarray(0,C.length).equals(C))throw Error("Invalid prompt payload (bad magic)");const t=process.env.ENCRYPTION_KEY||"";if(!t)throw Error("Missing encryption key. Set ENCRYPTION_KEY to load obfuscated assets.");let r=C.length;const s=e.subarray(r,r+16);r+=16;const i=e.subarray(r,r+12);r+=12;const n=e.subarray(r,r+16);r+=16;const o=e.subarray(r),a=((e,t)=>l.scryptSync(e,t,32))(t,s),c=l.createDecipheriv("aes-256-gcm",a,i);c.setAuthTag(n);const d=Buffer.concat([c.update(o),c.final()]);return p.gunzipSync(d)})(S.readFileSync(e)).toString("utf-8"):S.readFileSync(e,"utf-8")}catch(e){if("ENOENT"===e.code)return null;throw e}},n=i(v.join(s,`${e}.${t}`),"enc"===t);if(null!==n)return n;const o=i(v.join(s,e+".enc"),!0);if(null!==o)return o;throw Error("Asset not found: "+v.join(s,`${e}.${t}`))}getAllAssets(e,...t){return this.listAssets(e,...t).reduce((r,s)=>{const i=v.extname(s),n=v.basename(s,i),o=i.replace(/^\./,"")||void 0;return r[n]=this.getAsset(n,o??void 0,e,...t),r},{})}toPromptDef(e){const t=e=>"number"==typeof e?e:"string"==typeof e?(e=>{switch(e){case"none":return j.NONE;case"basic":return j.BASIC;case"advanced":return j.ADVANCED;case"high":return j.HIGH;case"medium":return I.MEDIUM;case"low":return _.LOW;case"free":return _.FREE;default:throw new d.InternalError("Cannon convert unknown level "+e)}})(e.toLowerCase()):j.NONE;return e.effort=t(e.effort),e.reasoning=t(e.reasoning),e.cost=t(e.cost),e}getPrompt(t,...r){const s=this.getAsset(e.toSnakeCase(t),"json",T.PROMPT,...r);let i;try{i=JSON.parse(s)}catch(e){throw new d.SerializationError(`Failed to parse prompt ${t} in categories ${r}: ${e}`)}return this.toPromptDef(i)}getAllPrompts(...e){const t=this.getAllAssets(T.PROMPT,...e);return Object.entries(t).reduce((t,[r,s])=>{try{t[r]=JSON.parse(s)}catch(t){throw new d.SerializationError(`Failed to parse prompt ${r} in categories ${e}: ${t}`)}return t},t)}};P=i.__decorate([a.injectable(),i.__metadata("design:paramtypes",[String])],P);class J extends O{constructor(e){super(e)}setCb(e){return this.cb=e,this}setArgsSchema(e){return this.argsSchema=e,this}static get builder(){return new J}static patchPrompt(t,r,s,i){const n=(r=Array.isArray(r)?r:Object.keys(r)).filter(e=>!Object.prototype.hasOwnProperty.call(s,e));if(n.length)throw new d.ValidationError("Missing replacements for placeholders: "+n.join(", "));i&&(i.verbose("Patching prompt with placeholders: "+JSON.stringify(r)),i.debug("Values: "+JSON.stringify(s)));const o=r.reduce((e,t)=>(e[t]=s[t],e),{});return e.sf(t,o)}patchPrompt(e,t,r,s){return J.patchPrompt(e,t,r,s||this.log.for(this.patchPrompt))}build(e,t){const r=this.log.for(this.build),s=this.hasErrors();if(s)throw new d.ValidationError(s.toString());try{this.argsSchema&&A(this.argsSchema,"argsSchema");const r=N(this.argsSchema);return e.registerPrompt(this.name,{title:this.title,description:this.description,argsSchema:r},async(e,r)=>{const s=this.logFor(r);e=Object.assign({},t,e||{}),s.verbose(`Executing prompt ${this.name} with args: ${JSON.stringify(e)}`),e._meta=Object.assign(e._meta||{},{usage:{reasoning:this.reasoning,effort:this.effort,cost:this.cost}});const i=await Promise.resolve(this.cb(e,r));return s.verbose(`Prompt ${this.name} executed successfully.`),s.debug("Prompt execution meta: "+JSON.stringify(i._meta)),i})}catch(e){throw r.error("Failed to register prompt "+(this.name||this.constructor.name),e),e}}}i.__decorate([a.inject(P),i.__metadata("design:type",P)],J.prototype,"assets",void 0),i.__decorate([n.required(),i.__metadata("design:type",Object)],J.prototype,"cb",void 0),i.__decorate([n.required(),i.__metadata("design:type",o.ZodObject)],J.prototype,"argsSchema",void 0),i.__decorate([c.prop(),i.__metadata("design:type",Object)],J.prototype,"placeholders",void 0);class q extends J{setCategory(e){return this.promptCategory=e,this}addPrefix(e){return this.prefixes=this.prefixes||[],this.prefixes.push(e),this}addSuffix(e){return this.suffixes=this.suffixes||[],this.suffixes.push(e),this}constructor(e){super(e)}build(e){const t=this.assets.getPrompt(this.name,this.promptCategory);n.Model.fromObject(this,t);const r=new Set((c.Metadata.properties(q)||[]).filter(e=>!["assets","promptCategory","prefixes","suffixes"].includes(e)));["cb","argsSchema"].forEach(e=>r.add(e));const s=this.hasErrors(...Array.from(r));if(s)throw new d.ValidationError(s.toString());const i=(this.prefixes||[]).map(e=>this.assets.getPrompt(e,this.promptCategory)),a=(this.suffixes||[]).map(e=>this.assets.getPrompt(e,this.promptCategory)),l=[...new Set([...t.placeholders,...i.map(e=>e.placeholders||[]),...a.map(e=>e.placeholders||[])].flat())].reduce((e,t)=>(e[t]=o.z.string().describe("The description for "+t),e),{});return this.setArgsSchema(o.z.object(l)),this.setCb((e,t)=>{const r=this.logFor(t).for(q).for(this.promptCategory).for(this.name);function s(e=[]){return Array.isArray(e)?e:Object.keys(e)}const i=(this.prefixes||[]).map(e=>this.assets.getPrompt(e,this.promptCategory)),n=(this.suffixes||[]).map(e=>this.assets.getPrompt(e,this.promptCategory)),o=this.assets.getPrompt(this.name,this.promptCategory),a=[...new Set([...i.map(e=>s(e.placeholders)).flat(),...n.map(e=>s(e.placeholders)).flat(),...s(o.placeholders).flat()])];return{messages:[{role:"user",content:{type:"text",text:this.patchPrompt([...i.map(e=>e.prompt),o.prompt,...n.map(e=>e.prompt)].join("\n\n"),a,e,r)}}],_meta:{}}}),super.build(e)}setReasoning(e){throw new d.InternalError("Named prompt builders don't require callback")}setEffort(e){throw new d.InternalError("Named prompt builders don't require callback")}setCost(e){throw new d.InternalError("Named prompt builders don't require callback")}setDescription(e){throw new d.InternalError("Named prompt builders don't require callback")}setTitle(e){throw new d.InternalError("Named prompt builders don't require callback")}static get builder(){return new q}}i.__decorate([n.required(),i.__metadata("design:type",String)],q.prototype,"promptCategory",void 0),i.__decorate([n.list(String),n.minlength(1),i.__metadata("design:type",Array)],q.prototype,"prefixes",void 0),i.__decorate([n.minlength(1),n.list(String),i.__metadata("design:type",Array)],q.prototype,"suffixes",void 0);const M=J.builder.setName("example.prompt").setTitle("Example prompt").setDescription("Example prompt for testing").setArgsSchema(o.z.object({message:o.z.string().optional()})).setCb(async e=>{const t=e.message??"default";return{messages:[{role:"assistant",content:{type:"text",text:t}}],content:[],structuredContent:{message:t},result:{message:t}}}),R=J.builder.setName("interactive.jsdoc").setTitle("Interactive JSDoc prompt").setDescription("Interactive prompt for jogging JSDoc helpers").setArgsSchema(o.z.object({gist:o.z.string().optional()})).setCb(async e=>{const t=e.gist??"interactive jsdoc response";return{messages:[{role:"assistant",content:{type:"text",text:t}}],content:[],structuredContent:{message:t},result:{message:t}}}),$=Object.assign(R,{name:R.getName()});var L;function F(e,t=[],r=[]){const s=q.builder.setCategory(L.DOCS).setName(e);return["prefix",...t].forEach(e=>s.addPrefix(e)),["suffix",...r].forEach(e=>s.addSuffix(e)),s}(e=>{e.DOCS="documentation",e.CODE="code"})(L||(L={}));const W=[F("class"),F("constant"),F("decorator"),F("function"),F("module"),F("file"),F("repo",[],["iterate"])],B=o.z.object({className:o.z.string().describe("the class name to turn into a builder")}),U=[M,$,...W,J.builder.setName("ts.code.dp.builder").setTitle("Typescript builder design patter prompt").setDescription("for a class, with a defined set of properties, scafold a builder design pattern").setArgsSchema(B).setReasoning(j.BASIC).setCb((t,r)=>(t.className=e.toPascalCase(t.className),{messages:[{role:"user",content:{type:"text",text:`You're a senior TypeScript developer writing typescript code.You're a senior TypeScript developer writing typescript code.\nTransform the selected class into a builder design pattern implementation in Typescript.\nuse @decaf-ts validation decorators to enforce the validation of your builder.\n\n- must extend the Model Class from @decaf-ts/decorator-validation;\n- each property must be marked as protected;\n- each property must have a setter method that returns 'this' for chaining;\n- the build() method must validate the properties using hasErrors() method from Model class;\n- if validation fails, throw an error with the validation errors;\n- if validation passes, return an instance of the original class with the set properties;\n- optionally (but do so by default) add the static builder and from methods from the example;\n- if the clasee already follows the pattern but has properties without decoration or without setters, simple add them;\n\nexample:\n\noriginal class:\n\`\`\`typescript\nexport class ${t.className} {\n description!: string;\n name!: string = "default name";\n title!: string;\n age?: string;\n dateOfBirth!: Date;\n}}\n\`\`\` \n\nresulting builder pattern implementation:\n\`\`\`typescript\nexport class ${t.className}Builder extends Model {\n\n @minlength(10\n @required()\n protected description!: string;\n \n @required()\n protected name!: string = "default value;\n \n @required()\n protected title!: string;\n \n @min(18)\n protected age?: string;\n \n @date()\n protected dateOfBirth!: Date;\n\n protected constructor(arg?: ModelArg<${t.className}Builder>>) {\n super(arg);\n Model.fromModel(this, arg);\n }\n\n setDescription(value: string) {\n this.description = value;\n return this;\n }\n\n setName(value: string) {\n this.name = value;\n return this;\n }\n\n setTitle(value: string) {\n this.title = value;\n return this;\n }\n setAge(value: number) {\n this.age = value;\n return this;\n }\n setDate(value: Date) {\n this.age = value;\n return this;\n }\n \n build(...args: any[]): ${t.className}Builder | Promise<${t.className}Builder> {\n const errs = this.hasErrors();\n if (errs) throw new Error(errs.toString());\n \n return // code that builds OBJ here\n }\n \n static get builder(): ${t.className}Builder {\n return new ${t.className}Builder(); // static method to get a new builder instance\n }\n \n static from<K extends keyof ${t.className}Builder>(obj: K, ${t.className}Builder[K]): ${t.className}Builder {\n return new ${t.className}Builder(); // static method to create a builder from an object\n }\n}\n\`\`\` \n\n`}}],_meta:{}}))];class K extends O{setAnnotations(e){return this.annotations=Object.assign(this.annotations,e),this}setCb(e){return this.cb=e,this}setInputSchema(e){return this.inputSchema=e,this}setOutputSchema(e){return this.outputSchema=e,this}constructor(e){super(e),this.annotations={readOnlyHint:!0,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1}}static get builder(){return new K}build(t){const r=this.hasErrors();if(r)throw Error(r.toString());try{this.inputSchema&&A(this.inputSchema,"inputSchema"),this.outputSchema&&A(this.outputSchema,"outputSchema");const e=N(this.inputSchema),r=N(this.outputSchema);return t.registerTool(this.name,{title:this.title,description:this.description,inputSchema:e,outputSchema:r,annotations:this.annotations,_meta:{usage:{reasoning:this.reasoning,effort:this.effort,cost:this.cost}}},async(e,t)=>{const r=this.logFor(t);r.verbose(`Executing tool ${this.name} with args: ${JSON.stringify(e)}`),t._meta=Object.assign(t._meta||{},{usage:{reasoning:this.reasoning,effort:this.effort,cost:this.cost}});const s=await Promise.resolve(this.cb(e,t));return r.verbose(`Tool ${this.name} executed successfully.`),r.debug("Tool execution meta: "+JSON.stringify(s._meta)),s})}catch(t){const r=t?.message||t+"";if("string"==typeof r&&r.includes("already registered"))return e.Logging.for(this).warn(`Tool ${this.name} already registered - skipping duplicate registration`),{name:this.name};throw e.Logging.for(this).error("Error building tool",t),t}}}i.__decorate([n.required(),i.__metadata("design:type",Object)],K.prototype,"annotations",void 0),i.__decorate([n.required(),i.__metadata("design:type",Object)],K.prototype,"cb",void 0),i.__decorate([n.required(),i.__metadata("design:type",Function)],K.prototype,"inputSchema",void 0);const V=K.builder.setName("example.tool").setTitle("Example tool").setDescription("A smoke tool used for quick testing").setInputSchema(o.z.object({})).setCb(async()=>({content:[{type:"text",text:"example tool ok"}],result:{status:"ok"}}));Object.assign(V,{name:V.getName()});const G=K.builder.setName("file.summarizer").setTitle("File summarizer").setDescription("Summaries files for quick previews").setInputSchema(o.z.object({filePath:o.z.string().optional()})).setCb(async()=>({content:[{type:"text",text:"file summary stub"}],result:{summary:"file summary stub"}}));Object.assign(G,{name:G.getName()});const Y="##VERSION##";c.Metadata.registerLibrary("##PACKAGE##",Y),u.config({path:v.resolve(__dirname,"../../.env")});const Z={mcpId:"decaf",name:"decaf-ts mcp server",title:"Decaf-TS MCP Server",description:"Provides precise coding assistance for the decaf-ts framework",version:Y,websiteUrl:"https://decaf-ts.github.io",repositoryUrl:"https://github.com/decaf-ts/mcp-server",license:"AGPL-3.0",workingDir:process.cwd(),assetDir:D(),contacts:[{name:"Decaf-TS",url:"https://decaf-ts.github.io"}],tags:"server,official,decaf-ts",metadata:{},icons:[{src:"workdocs/assets/favicon.svg",mimeType:"image/svg+xml",sizes:"any"}],jira:{host:process.env.JIRA__HOST||"decaf-ts.atlassian.net",email:process.env.JIRA__EMAIL||"",apiKey:process.env.JIRA__API_KEY||process.env.JIRA__APIKEY||""},level:e.LogLevel.error},Q=e.LoggedEnvironment.accumulate(Z);function X(e){if(!e)return{code:"jira_error",message:"Unknown Jira error",details:{raw:e}};const t=e?.status??e?.statusCode??e?.response?.status??e?.response?.statusCode,r="number"==typeof t?t:Number(t)||void 0,s=e?.response?.data??e?.data??e?.response?.body??e?.body,i=[];"string"==typeof e?.message&&i.push(e.message),((e,t)=>{e&&(Array.isArray(e.errorMessages)&&e.errorMessages.forEach(e=>"string"==typeof e&&t.push(e)),"string"==typeof e.errorMessage&&t.push(e.errorMessage),e.errorCollection&&Array.isArray(e.errorCollection.errors)&&e.errorCollection.errors.forEach(e=>{"string"==typeof e?t.push(e):e&&"string"==typeof e.message&&t.push(e.message)}),e?.errors&&"object"==typeof e.errors&&Object.values(e.errors).forEach(e=>{"string"==typeof e?t.push(e):"string"==typeof e?.message&&t.push(e.message)}))})(s,i);const n=r?`Jira API error (${r})`:"Jira API error",o=i.length>0?i.join(" | "):n;return{code:r?"jira_"+r:e?.code??"jira_error",message:o,details:{httpStatus:r,body:s,raw:e}}}e.Logging.setConfig(Q);const ee=o.z.object({issueId:o.z.string().min(1),deleteSubtasks:o.z.boolean().optional().default(!0)}),te={name:"jira.issue-delete",inputSchema:ee,runTool:async(e,t)=>{try{const r=ee.parse(t),s=e.issues??e.issue??e,i=s?.delete??s?.deleteIssue;if("function"!=typeof i)throw Error("jira client delete endpoint is not available");return await i.call(s,{issueId:r.issueId,deleteSubtasks:r.deleteSubtasks}),{success:!0,message:`Issue ${t.issueId} deleted successfully`}}catch(e){throw X(e)}}},re=o.z.object({issueId:o.z.string().min(1),expand:o.z.string().optional(),fields:o.z.array(o.z.string()).optional(),properties:o.z.array(o.z.string()).optional()}),se={name:"jira.issue-read",inputSchema:re,runTool:async(e,t)=>{try{const r=re.parse(t),s={issueIdOrKey:r.issueId};r.expand&&(s.expand=r.expand),r.fields&&(s.fields=r.fields),r.properties&&(s.properties=r.properties);const i=await e.issues.get(s);return i?.data??i}catch(e){throw X(e)}}},ie=o.z.object({issueId:o.z.string().min(1),transitionId:o.z.union([o.z.string(),o.z.number()]),fields:o.z.record(o.z.any()).optional(),update:o.z.record(o.z.array(o.z.object({set:o.z.any().optional(),add:o.z.any().optional(),remove:o.z.any().optional()}))).optional(),comment:o.z.string().optional()}),ne={name:"jira.issue-transition",inputSchema:ie,runTool:async(e,t)=>{try{const r=ie.parse(t),s={id:r.transitionId};r.fields&&(s.fields=r.fields),r.update&&(s.update=r.update),r.comment&&(s.comment={body:r.comment});const i=await e.issues.transition({issueId:r.issueId,transition:s});return i?.data??i}catch(e){throw X(e)}}},oe=o.z.object({issueId:o.z.string().min(1),fields:o.z.record(o.z.any()).optional(),update:o.z.record(o.z.array(o.z.object({set:o.z.any().optional(),add:o.z.any().optional(),remove:o.z.any().optional(),edit:o.z.any().optional()}))).optional(),properties:o.z.array(o.z.any()).optional(),notifyUsers:o.z.boolean().optional().default(!0),issueTemplateId:o.z.string().optional(),overrideScreenSecurity:o.z.boolean().optional().default(!1),overrideEditableFlag:o.z.boolean().optional().default(!1)}),ae={name:"jira.issue-update",inputSchema:oe,runTool:async(e,t)=>{try{const r=oe.parse(t),s={issueId:r.issueId};r.fields&&(s.fields=r.fields),r.update&&(s.update=r.update),r.properties&&(s.properties=r.properties),void 0!==r.notifyUsers&&(s.notifyUsers=r.notifyUsers),r.issueTemplateId&&(s.issueTemplateId=r.issueTemplateId),void 0!==r.overrideScreenSecurity&&(s.overrideScreenSecurity=r.overrideScreenSecurity),void 0!==r.overrideEditableFlag&&(s.overrideEditableFlag=r.overrideEditableFlag);const i=await e.issues.update(s);return i?.data??i}catch(e){throw X(e)}}},ce=o.z.object({issueId:o.z.string().min(1),assignee:o.z.union([o.z.string(),o.z.object({accountId:o.z.string().min(1)}),o.z.object({accountType:o.z.string().min(1)})])}),de={name:"jira.assign-issue",inputSchema:ce,runTool:async(e,t)=>{try{const r=ce.parse(t);let s;s="string"==typeof r.assignee?{accountId:r.assignee}:r.assignee;const i=await e.issues.assign({issueId:r.issueId,assignee:s});return i?.data??i}catch(e){throw X(e)}}},le=o.z.object({issueId:o.z.string().min(1)}),pe={name:"jira.unassign-issue",inputSchema:le,runTool:async(e,t)=>{try{const r=le.parse(t),s=await e.issues.assign({issueId:r.issueId,assignee:{accountId:"-1"}});return s?.data??s}catch(e){throw X(e)}}},ue=o.z.object({issueId:o.z.string().min(1),body:o.z.string().min(1),visibility:o.z.object({type:o.z.enum(["role","group"]),value:o.z.string().min(1)}).optional()}),me={name:"jira.comment-add",inputSchema:ue,runTool:async(e,t)=>{try{const r=ue.parse(t),s={body:r.body};r.visibility&&(s.visibility=r.visibility);const i=await e.issues.addComment({issueId:r.issueId,comment:s});return i?.data??i}catch(e){throw X(e)}}},he=o.z.object({issueId:o.z.string().min(1),start:o.z.number().optional().default(0),maxResults:o.z.number().optional().default(50),orderBy:o.z.string().optional(),expand:o.z.string().optional()}),ge={name:"jira.comment-list",inputSchema:he,runTool:async(e,t)=>{try{const r=he.parse(t),s=await e.issues.getComments({issueId:r.issueId,start:r.start,maxResults:r.maxResults,orderBy:r.orderBy,expand:r.expand});return s?.data??s}catch(e){throw X(e)}}},fe=o.z.object({link:o.z.object({relationship:o.z.enum(["Blocks","Relates to","Duplicates","Is blocked by","Is related to","Is duplicated by","Causes","Is caused by","Clone","Required","Work on","Split","Roll up"]),inwardIssue:o.z.object({id:o.z.string().optional(),key:o.z.string().optional()}),outwardIssue:o.z.object({id:o.z.string().optional(),key:o.z.string().optional()}),comment:o.z.object({body:o.z.string().optional(),visibility:o.z.object({type:o.z.enum(["role","group"]),value:o.z.string().min(1)}).optional()}).optional()})}),ye={name:"jira.link-create",inputSchema:fe,runTool:async(e,t)=>{try{const r=fe.parse(t).link,s={relationship:r.relationship,inwardIssue:r.inwardIssue.id||r.inwardIssue.key,outwardIssue:r.outwardIssue.id||r.outwardIssue.key};r.comment&&(r.comment.body&&(s.comment=r.comment.body),r.comment.visibility&&(s.visibility=r.comment.visibility));const i=await e.issues.link(s);return i?.data??i}catch(e){throw X(e)}}},be=o.z.object({issueId:o.z.string().min(1),file:o.z.string().min(1),mimeType:o.z.string().optional(),comment:o.z.string().optional()}),ve={name:"jira.attach",inputSchema:be,runTool:async(e,t)=>{try{const i=be.parse(t),n=r.resolve(i.file),o=await s.promises.readFile(n),a=r.basename(n),c=await e.issues.addAttachment({issueId:i.issueId,file:{name:a,content:o,mimeType:i.mimeType??"application/octet-stream"},comment:i.comment});return c?.data??c}catch(e){if(e&&e.code&&"string"==typeof e.code&&["ENOENT","EACCES"].includes(e.code))throw Error("Attachment file error: "+e.message);throw X(e)}}},Se=o.z.object({issueId:o.z.string().min(1)}),we={name:"jira.attachment-list",inputSchema:Se,runTool:async(e,t)=>{try{const r=Se.parse(t),s=await e.issues.getAttachments({issueId:r.issueId});return s?.data??s}catch(e){throw X(e)}}},je=o.z.object({issueId:o.z.string().min(1),attachmentId:o.z.string().min(1)}),Ie={name:"jira.attachment-delete",inputSchema:je,runTool:async(e,t)=>{try{const r=je.parse(t);return await e.issues.deleteAttachment({issueId:r.issueId,attachmentId:r.attachmentId}),{success:!0,message:`Attachment ${t.attachmentId} deleted successfully`}}catch(e){throw X(e)}}},_e=o.z.object({issueId:o.z.string().min(1),timeSpent:o.z.string().min(1),comment:o.z.string().optional(),author:o.z.object({accountId:o.z.string().min(1)}).optional(),startingOn:o.z.string().optional(),artifact:o.z.string().optional()}),ze={name:"jira.worklog-add",inputSchema:_e,runTool:async(e,t)=>{try{const r=_e.parse(t),s={timeSpent:r.timeSpent};r.comment&&(s.comment=r.comment),r.author&&(s.author=r.author),r.startingOn&&(s.started=r.startingOn),r.artifact&&(s.artifact=r.artifact);const i=await e.issues.addWorklog({issueId:r.issueId,...s});return i?.data??i}catch(e){throw X(e)}}},Te={[se.name]:{title:"Jira Issue Read",description:"Read a Jira issue with expandable fields and properties",annotations:{readOnlyHint:!0,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1}},[ae.name]:{title:"Jira Issue Update",description:"Update a Jira issue using fields, update ops, and property toggles",annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!1,openWorldHint:!0}},[te.name]:{title:"Jira Issue Delete",description:"Delete a Jira issue and optionally remove its subtasks",annotations:{readOnlyHint:!1,destructiveHint:!0,idempotentHint:!1,openWorldHint:!0}},[ne.name]:{title:"Jira Issue Transition",description:"Transition a Jira issue while optionally adding a comment",annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!1,openWorldHint:!0}},[de.name]:{title:"Jira Issue Assign",description:"Assign a Jira issue to a user or account",annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!1,openWorldHint:!0}},[pe.name]:{title:"Jira Issue Unassign",description:"Unassign the current owner from a Jira issue",annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!1,openWorldHint:!0}},[me.name]:{title:"Jira Comment Add",description:"Add a comment to a Jira issue with optional visibility",annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!1,openWorldHint:!0}},[ge.name]:{title:"Jira Comment List",description:"List comments on a Jira issue with pagination support",annotations:{readOnlyHint:!0,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1}},[ye.name]:{title:"Jira Link Create",description:"Create an issue link relationship with optional comment",annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!1,openWorldHint:!0}},[ve.name]:{title:"Jira Attachment Add",description:"Attach a local file to a Jira issue",annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!1,openWorldHint:!0}},[we.name]:{title:"Jira Attachment List",description:"List attachments on a Jira issue",annotations:{readOnlyHint:!0,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1}},[Ie.name]:{title:"Jira Attachment Delete",description:"Delete an attachment from a Jira issue",annotations:{readOnlyHint:!1,destructiveHint:!0,idempotentHint:!1,openWorldHint:!0}},[ze.name]:{title:"Jira Worklog Add",description:"Log time spent on a Jira issue",annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!1,openWorldHint:!0}}};async function Ee(t){const r=e.Logging.for(Ee);let s;try{s=(()=>{let e;try{const t=require("jira.js");e=t?.Version3Client||t.default?.Version3Client||t.default||t}catch(e){throw Error("Unable to require 'jira.js' \u2014 ensure it is installed as a dependency: "+e)}const t=Q.jira.host,r=Q.jira.email,s=Q.jira.apiKey;if(!t||!r||!s)throw Error("Jira credentials missing. Define JIRA__HOST, JIRA__EMAIL, and JIRA__APIKEY via the Environment abstraction before registering Jira tools.");return new e({host:t,authentication:{basic:{email:r,apiToken:s}}})})()}catch(e){return void r.warn("Skipping Jira tool registration; unable to create Jira client",{error:e})}const i=[se,ae,te,ne,de,pe,me,ge,ye,ve,we,Ie,ze];for(const e of i){const i=Te[e.name];if(i)try{await t.registerTool(e.name,{title:i.title,description:i.description,inputSchema:N(e.inputSchema),annotations:i.annotations},async t=>e.runTool(s,t)),r.info("Registered Jira tool "+e.name)}catch(t){r.error("Failed to register Jira tool "+e.name,{error:t})}}}async function Oe(t){await(async e=>{e.registerTool("decaf.server-info",{title:"Decaf MCP Server Info",description:"Return server metadata, version, and registered prompt names for diagnostics.",inputSchema:{},outputSchema:void 0,annotations:{readOnlyHint:!0,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1}},async()=>{const e=U.map(e=>e.getName()).sort();return{content:[{type:"text",text:["Name: "+Q.name,"Title: "+Q.title,"Version: "+Q.version,"Prompts: "+(e.join(", ")||"<none>")].join("\n")}]}})})(t);const r=e.Logging.for(Oe);try{await Ee(t)}catch(e){r.error("Failed to register Jira tools",e)}}class xe extends E{setCb(e){return this.cb=e,this}setConfig(e){return this.config=e,this}setUriOtTemplate(e){return this.uriOrTemplate=e,this}constructor(e){super(e)}static get builder(){return new xe}build(t){const r=this.hasErrors();if(r)throw Error(r.toString());try{const e="string"==typeof this.uriOrTemplate&&this.uriOrTemplate.includes("{")?new h.ResourceTemplate(new m.UriTemplate(this.uriOrTemplate),{list:void 0}):this.uriOrTemplate,r=Object.assign(this.config,{_meta:{}}),s=async(e,t)=>{const r=this.logFor(t);r.verbose(`Requesting resource ${this.name} from ${e.toString()}`);const s=await Promise.resolve(this.cb(e,t));return r.verbose(`Resource ${this.name} retrieved successfully.`),r.debug("Resource retrieval meta: "+JSON.stringify(s._meta)),s};return t.resource(this.name,e,r,s)}catch(t){throw e.Logging.for(this).error("Error registering resource "+this.name,t),t}}}i.__decorate([n.required(),i.__metadata("design:type",String)],xe.prototype,"uriOrTemplate",void 0),i.__decorate([n.required(),i.__metadata("design:type",Function)],xe.prototype,"cb",void 0),i.__decorate([n.required(),i.__metadata("design:type",Object)],xe.prototype,"config",void 0);const Ae=v.join(process.cwd(),"src/assets"),Ne=v.join(Ae,"templates"),He=v.join(Ae,"prompts");class Ce extends e.MiniLogger{log(t,r,s,i){const n=this.config("level");e.NumericLogLevels[n],e.NumericLogLevels[t]}}const ke=(e,t,...r)=>{const s=(e=>{if("string"==typeof e)return e;if(!e)return"unknown";if("function"==typeof e)return e.name||"unknown";if("object"==typeof e&&"constructor"in e){const t=e.constructor;if(t&&t.name)return t.name}return"unknown"})(e);return new Ce(s,t)},De=new WeakMap;class Pe extends e.LoggedClass{get client(){const e=De.get(this);if(!e)throw Error("Mcp server requires Mcp client");return e}constructor(){super()}async load(){const e=this.log.for(this.load);for(const t of U)try{e.info("loading prompt "+t.getName());const r=t.build(this.client);e.verbose(`Loaded prompt ${r.title} from ${t.getName()} definition`)}catch(r){e.error("Failed to load prompt "+t.getName(),r)}try{await Oe(this.client),e.verbose("Registered built-in tools")}catch(t){e.error("Failed to register tools",t)}try{await(async(e,t)=>{t.info("Registering agent templates as resources...");const r=S.readdirSync(Ne).filter(e=>e.endsWith(".md"));for(const s of r){const r=v.basename(s,".md"),i=v.join(Ne,s),n=xe.builder.setName(r).setTitle("Template: "+r).setDescription("Resource template for "+r).setUriOtTemplate("file:///"+i).setConfig({mimeType:"text/markdown",description:"Template for "+r}).setCb(async e=>{const t=S.readFileSync(e.pathname,"utf8");return{contents:[{uri:e.toString(),text:t,mimeType:"text/markdown"}],_meta:{}}});try{n.build(e),t.info("Registered template: "+r)}catch(e){t.error(`Failed to register template ${r}:`,e)}}t.info("Registering agent prompts...");const s=S.readdirSync(He).filter(e=>e.endsWith(".md"));for(const r of s){const s=v.basename(r,".md"),i=v.join(He,r),n=S.readFileSync(i,"utf8"),a=J.builder.setName(s).setTitle("Prompt: "+s).setDescription("Dynamic prompt for "+s).setArgsSchema(o.z.object({})).setCb(async e=>({messages:[{role:"user",content:{type:"text",text:n}}],_meta:{}}));try{a.build(e),t.info("Registered prompt: "+s)}catch(e){t.error(`Failed to register prompt ${s}:`,e)}}})(this.client,e),e.verbose("Registered agent-specific assets")}catch(t){e.error("Failed to register agent assets",t)}}async boot(r="stdio"){let s=this.log;this.log.for(this.boot).info("McpServer booting..."),((r=e.Logging.get())=>{let s;try{s=(()=>{let e,t=__dirname;try{for(;t&&t!==v.parse(t).root;){const r=v.join(t,"node_modules");if(S.existsSync(r)&&S.statSync(r).isDirectory()){e=r;break}const s=v.dirname(t);if(s===t)break;t=s}}catch{}const r=[];if(e){const t=v.join(e,"@decaf-ts");try{if(S.existsSync(t)&&S.statSync(t).isDirectory()){const e=S.readdirSync(t);for(const s of e){const e=v.join(t,s);try{const t=v.join(e,"workdocs","assets","slogans.json");if(S.existsSync(t)&&S.statSync(t).isFile()){const e=S.readFileSync(t,"utf-8"),s=JSON.parse(e);if(Array.isArray(s))for(const e of s)"string"==typeof e&&e.trim().length>0&&r.push(e.trim())}}catch{}}}}catch{}}return 0===r.length?"Decaf: strongly brewed TypeScript.":r[Math.floor(Math.random()*r.length)]})()}catch{s="Decaf: strongly brewed TypeScript."}const i="# \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \n# ( ( \u2591\u2592\u2593\u2588\u2593\u2592\u2591\u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591\u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591\u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \n# ) ) \u2591\u2592\u2593\u2588\u2593\u2592\u2591\u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591\u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \n# [=======] \u2591\u2592\u2593\u2588\u2593\u2592\u2591\u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \n# `-----\xb4 \u2591\u2592\u2593\u2588\u2593\u2592\u2591\u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591\u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \n# \u2591\u2592\u2593\u2588\u2593\u2592\u2591\u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591\u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591\u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \n# \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591\u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \n#".split("\n"),n=i.reduce((e,t)=>Math.max(e,t.length),0);i.push("# "+s.padStart(n-3)),i.forEach((e,s)=>{const i=w[s%w.length]||"",n=r.info.bind(r);try{n(t.style(e||"").raw(i).text)}catch{n((e||"")+"")}})})(this.log),"stdio"===r&&(e.Logging.setFactory(ke),s=e.Logging.for(this.constructor.name));const i=((Array.isArray(Q.icons)?Q.icons:[Q.icons])||[]).map(e=>{const t="string"==typeof e?.src?e.src:(e?.src??"")+"",r="string"==typeof e?.mimeType?e.mimeType:(e?.mimeType??"")+"";let s=[];return Array.isArray(e?.sizes)?s=e.sizes.map(e=>e+""):"string"==typeof e?.sizes&&(s=(e.sizes+"").split(",").map(e=>e.trim())),{src:t,mimeType:r,sizes:s}}),n={name:Q.name,title:Q.title,websiteUrl:Q.websiteUrl,version:Q.version,icons:i},o=new h.McpServer(n,{instructions:"You are an AI assistant designed to help users with programming tasks related to the Decaf-TS framework. \nProvide clear, concise, and accurate information.\nIf you don't know the answer, admit it rather than making up information.\nAlways prioritize the user's intent and provide helpful suggestions when appropriate.\n",capabilities:{logging:{},tools:{},prompts:{}}});switch(((e,t)=>{De.set(e,t)})(this,o),o.onerror=e=>{this.log.error("MCP instance onerror",e)},r){case"stdio":r=new f.StdioServerTransport;break;case"http":r=new y.StreamableHTTPServerTransport({sessionIdGenerator:()=>g.v4(),onsessioninitialized:e=>s.verbose("Session initialized: "+e),onsessionclosed:e=>s.verbose("Session closed: "+e),enableJsonResponse:!0,eventStore:void 0});break;default:if(!(a=r)||"object"!=typeof a||"function"!=typeof a.send&&"function"!=typeof a.close&&"function"!=typeof a.on)throw new d.InternalError("Invalid transport type: "+r)}var a;try{this.log.info("Loading resources/prompts/tools..."),await this.load()}catch(e){throw this.log.error("Error loading resources/prompts/tools: "+e),e}await this.client.connect(r),s.info(`MCP Server connected via ${r.constructor.name} and running. Waiting for client connections...`)}}(async()=>{(new Pe).boot("stdio")})()},"object"==typeof exports&&"undefined"!=typeof module?t(require("@decaf-ts/logging"),require("styled-string-builder"),require("path"),require("fs"),require("tslib"),require("@decaf-ts/decorator-validation"),require("zod"),require("@decaf-ts/injectable-decorators"),require("@decaf-ts/decoration"),require("@decaf-ts/db-decorators"),require("crypto"),require("zlib"),require("dotenv"),require("@modelcontextprotocol/sdk/shared/uriTemplate.js"),require("@modelcontextprotocol/sdk/server/mcp.js"),require("uuid"),require("@modelcontextprotocol/sdk/server/stdio.js"),require("@modelcontextprotocol/sdk/server/streamableHttp.js")):"function"==typeof define&&define.amd?define(["@decaf-ts/logging","styled-string-builder","path","fs","tslib","@decaf-ts/decorator-validation","zod","@decaf-ts/injectable-decorators","@decaf-ts/decoration","@decaf-ts/db-decorators","crypto","zlib","dotenv","@modelcontextprotocol/sdk/shared/uriTemplate.js","@modelcontextprotocol/sdk/server/mcp.js","uuid","@modelcontextprotocol/sdk/server/stdio.js","@modelcontextprotocol/sdk/server/streamableHttp.js"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).decafTsLogging,e.styledStringBuilder,e.path,e.fs,e.tslib,e.decafTsDecoratorValidation,e.zod,e.decafTsInjectableDecorators,e.decafTsDecoration,e.decafTsDbDecorators,e.crypto,e.zlib,e.dotenv,e.uriTemplate_js,e.mcp_js,e.uuid,e.stdio_js,e.streamableHttp_js);
2
+ var e,t;e=this,t=function(e,t,r,s,n,i,o,a,c,l,p,d,u,m,h,f,g,y,b,v,w,S,j){"use strict";function x(e){var t=Object.create(null);return e&&Object.keys(e).forEach(r=>{if("default"!==r){var s=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,s.get?s:{enumerable:!0,get:()=>e[r]})}}),t.default=e,Object.freeze(t)}var I=x(t),_=x(r);class z extends s.MiniLogger{log(e,t,r,n){const i=this.config("level");s.NumericLogLevels[i],s.NumericLogLevels[e]}}const E=(e,t,...r)=>{const s=(e=>{if("string"==typeof e)return e;if(!e)return"unknown";if("function"==typeof e)return e.name||"unknown";if("object"==typeof e&&"constructor"in e){const t=e.constructor;if(t&&t.name)return t.name}return"unknown"})(e);return new z(s,t)},T=["\x1b[38;5;215m","\x1b[38;5;209m","\x1b[38;5;205m","\x1b[38;5;210m","\x1b[38;5;217m","\x1b[38;5;216m","\x1b[38;5;224m","\x1b[38;5;230m","\x1b[38;5;230m"];var k,A,O,N,C;(e=>{e[e.NONE=0]="NONE",e[e.BASIC=1]="BASIC",e[e.ADVANCED=2]="ADVANCED",e[e.HIGH=3]="HIGH"})(k||(k={})),(e=>{e[e.NONE=0]="NONE",e[e.LOW=1]="LOW",e[e.MEDIUM=2]="MEDIUM",e[e.HIGH=3]="HIGH"})(A||(A={})),(e=>{e[e.FREE=0]="FREE",e[e.LOW=1]="LOW",e[e.MEDIUM=2]="MEDIUM",e[e.HIGH=3]="HIGH"})(O||(O={}));class H extends o.Model{get log(){return this._log||(this._log=s.Logging.for(this)),this._log}constructor(e){super(e)}logFor(e){const{sessionId:t,requestId:r,authInfo:s}=e||{};let n="string"==typeof t&&t.length>0?this.log.for(t):this.log;return s&&s.clientId&&(n=n.for(s.clientId)),r&&(n=n.for(r.toString())),n}setDescription(e){return this.description=e,this}getDescription(){return this.description}setName(e){return this.name=e,this}getName(){return this.name}setTitle(e){return this.title=e,this}}i.__decorate([o.required(),i.__metadata("design:type",String)],H.prototype,"description",void 0),i.__decorate([o.required(),i.__metadata("design:type",String)],H.prototype,"name",void 0),i.__decorate([o.required(),i.__metadata("design:type",String)],H.prototype,"title",void 0);class D extends H{constructor(e){super(e),this.reasoning=k.NONE,this.effort=A.NONE,this.cost=O.FREE}setReasoning(e){return this.reasoning=e,this}setEffort(e){return this.effort=e,this}setCost(e){return this.cost=e,this}}function J(e){if(!e)return;let t=e,r=t&&t._def;for(;r&&"ZodObject"!==r.typeName;){if("ZodEffects"===r.typeName&&r.schema)t=r.schema;else if("ZodOptional"===r.typeName&&r.innerType)t=r.innerType;else if("ZodDefault"===r.typeName&&r.innerType)t=r.innerType;else if("ZodNullable"===r.typeName&&r.innerType)t=r.innerType;else{if(!r.schema)return;t=r.schema}r=t&&t._def}return r&&"ZodObject"===r.typeName?r:void 0}function q(e,t="schema"){if(J(e))return e;if(e&&"object"==typeof e){const t=e.def&&"object"==typeof e.def?e.def:void 0,r=t&&(t.shape||"object"===t.type)&&t.shape||("object"===e.type?e.shape:void 0)||(t&&"object"===t.type?{}:void 0);if(t||"object"===e.type||r){const e={};if(r&&"object"==typeof r)for(const[t,s]of Object.entries(r))e[t]=M(s)?s:a.z.any();return a.z.object(e)}}throw Error(`Registration error: provided a non-canonical ${t}. Export a ZodObject (z.object(...)).`)}function P(e){if(!e)return;if(e&&"object"==typeof e&&!e._def)return e.def&&"object"==typeof e.def&&e.def.shape?e.def.shape:e;const t=J(e);return t?"function"==typeof t.shape?t.shape():t.shape||void 0:void 0}function M(e){return!(!e||"object"!=typeof e||!e._def)}i.__decorate([o.required(),i.__metadata("design:type",Number)],D.prototype,"reasoning",void 0),i.__decorate([o.required(),i.__metadata("design:type",Number)],D.prototype,"effort",void 0),i.__decorate([o.required(),i.__metadata("design:type",Number)],D.prototype,"cost",void 0),(e=>{e.ASSETS="assets"})(N||(N={})),(e=>{e.PROMPT="prompts",e.DOCUMENTATION="documentation",e.CODE="code"})(C||(C={}));const R=Buffer.from("DCAF1","ascii");function $(e){let t=e;for(;;){const e=_.join(t,"lib","assets");if(I.existsSync(e))return e;const r=_.join(t,"src","assets");if(I.existsSync(r))return r;const s=_.join(t,"assets");if(I.existsSync(s))return s;const n=_.dirname(t);if(n===t)break;t=n}}function L(){const e=process.env.DECAF_ASSET_DIR||process.env.MCP_ASSET_DIR||process.env.ASSET_DIR||"";if(e&&I.existsSync(e))return e;const t=process.argv?.[1];if(t){const e=$(_.dirname(t));if(e)return e}const r=[process.cwd(),process.env.INIT_CWD].filter(Boolean);for(const e of r){const t=$(e);if(t)return t}return _.join(process.cwd(),"assets")}let F=class extends s.LoggedClass{constructor(e){super(),this.basePath=e||L()}listAssets(...e){const t=_.join(this.basePath,...e);return I.readdirSync(t)}listPrompts(){return this.listAssets(C.PROMPT)}getAsset(e,t="md",...r){const s=_.join(this.basePath,...r),n=(e,t=!1)=>{try{return t?(e=>{if(e.length<R.length+16+12+16)throw Error("Invalid prompt payload (too short)");if(!e.subarray(0,R.length).equals(R))throw Error("Invalid prompt payload (bad magic)");const t=process.env.ENCRYPTION_KEY||"";if(!t)throw Error("Missing encryption key. Set ENCRYPTION_KEY to load obfuscated assets.");let r=R.length;const s=e.subarray(r,r+16);r+=16;const n=e.subarray(r,r+12);r+=12;const i=e.subarray(r,r+16);r+=16;const o=e.subarray(r),a=((e,t)=>d.scryptSync(e,t,32))(t,s),c=d.createDecipheriv("aes-256-gcm",a,n);c.setAuthTag(i);const l=Buffer.concat([c.update(o),c.final()]);return u.gunzipSync(l)})(I.readFileSync(e)).toString("utf-8"):I.readFileSync(e,"utf-8")}catch(e){if("ENOENT"===e.code)return null;throw e}},i=n(_.join(s,`${e}.${t}`),"enc"===t);if(null!==i)return i;const o=n(_.join(s,e+".enc"),!0);if(null!==o)return o;throw Error("Asset not found: "+_.join(s,`${e}.${t}`))}getAllAssets(e,...t){return this.listAssets(e,...t).reduce((r,s)=>{const n=_.extname(s),i=_.basename(s,n),o=n.replace(/^\./,"")||void 0;return r[i]=this.getAsset(i,o??void 0,e,...t),r},{})}toPromptDef(e){const t=e=>"number"==typeof e?e:"string"==typeof e?(e=>{switch(e){case"none":return k.NONE;case"basic":return k.BASIC;case"advanced":return k.ADVANCED;case"high":return k.HIGH;case"medium":return A.MEDIUM;case"low":return O.LOW;case"free":return O.FREE;default:throw new p.InternalError("Cannon convert unknown level "+e)}})(e.toLowerCase()):k.NONE;return e.effort=t(e.effort),e.reasoning=t(e.reasoning),e.cost=t(e.cost),e}getPrompt(e,...t){const r=this.getAsset(s.toSnakeCase(e),"json",C.PROMPT,...t);let n;try{n=JSON.parse(r)}catch(r){throw new p.SerializationError(`Failed to parse prompt ${e} in categories ${t}: ${r}`)}return this.toPromptDef(n)}getAllPrompts(...e){const t=this.getAllAssets(C.PROMPT,...e);return Object.entries(t).reduce((t,[r,s])=>{try{t[r]=JSON.parse(s)}catch(t){throw new p.SerializationError(`Failed to parse prompt ${r} in categories ${e}: ${t}`)}return t},t)}};F=i.__decorate([c.injectable(),i.__metadata("design:paramtypes",[String])],F);class B extends D{constructor(e){super(e)}setCb(e){return this.cb=e,this}setArgsSchema(e){return this.argsSchema=e,this}static get builder(){return new B}static patchPrompt(e,t,r,n){const i=(t=Array.isArray(t)?t:Object.keys(t)).filter(e=>!Object.prototype.hasOwnProperty.call(r,e));if(i.length)throw new p.ValidationError("Missing replacements for placeholders: "+i.join(", "));n&&(n.verbose("Patching prompt with placeholders: "+JSON.stringify(t)),n.debug("Values: "+JSON.stringify(r)));const o=t.reduce((e,t)=>(e[t]=r[t],e),{});return s.sf(e,o)}patchPrompt(e,t,r,s){return B.patchPrompt(e,t,r,s||this.log.for(this.patchPrompt))}build(e,t){const r=this.log.for(this.build),s=this.hasErrors();if(s)throw new p.ValidationError(s.toString());try{this.argsSchema&&q(this.argsSchema,"argsSchema");const r=P(this.argsSchema);return e.registerPrompt(this.name,{title:this.title,description:this.description,argsSchema:r},async(e,r)=>{const s=this.logFor(r);e=Object.assign({},t,e||{}),s.verbose(`Executing prompt ${this.name} with args: ${JSON.stringify(e)}`),e._meta=Object.assign(e._meta||{},{usage:{reasoning:this.reasoning,effort:this.effort,cost:this.cost}});const n=await Promise.resolve(this.cb(e,r));return s.verbose(`Prompt ${this.name} executed successfully.`),s.debug("Prompt execution meta: "+JSON.stringify(n._meta)),n})}catch(e){throw r.error("Failed to register prompt "+(this.name||this.constructor.name),e),e}}}i.__decorate([c.inject(F),i.__metadata("design:type",F)],B.prototype,"assets",void 0),i.__decorate([o.required(),i.__metadata("design:type",Object)],B.prototype,"cb",void 0),i.__decorate([o.required(),i.__metadata("design:type",a.ZodObject)],B.prototype,"argsSchema",void 0),i.__decorate([l.prop(),i.__metadata("design:type",Object)],B.prototype,"placeholders",void 0);class W extends B{setCategory(e){return this.promptCategory=e,this}addPrefix(e){return this.prefixes=this.prefixes||[],this.prefixes.push(e),this}addSuffix(e){return this.suffixes=this.suffixes||[],this.suffixes.push(e),this}constructor(e){super(e)}build(e){const t=this.assets.getPrompt(this.name,this.promptCategory);o.Model.fromObject(this,t);const r=new Set((l.Metadata.properties(W)||[]).filter(e=>!["assets","promptCategory","prefixes","suffixes"].includes(e)));["cb","argsSchema"].forEach(e=>r.add(e));const s=this.hasErrors(...Array.from(r));if(s)throw new p.ValidationError(s.toString());const n=(this.prefixes||[]).map(e=>this.assets.getPrompt(e,this.promptCategory)),i=(this.suffixes||[]).map(e=>this.assets.getPrompt(e,this.promptCategory)),c=[...new Set([...t.placeholders,...n.map(e=>e.placeholders||[]),...i.map(e=>e.placeholders||[])].flat())].reduce((e,t)=>(e[t]=a.z.string().describe("The description for "+t),e),{});return this.setArgsSchema(a.z.object(c)),this.setCb((e,t)=>{const r=this.logFor(t).for(W).for(this.promptCategory).for(this.name);function s(e=[]){return Array.isArray(e)?e:Object.keys(e)}const n=(this.prefixes||[]).map(e=>this.assets.getPrompt(e,this.promptCategory)),i=(this.suffixes||[]).map(e=>this.assets.getPrompt(e,this.promptCategory)),o=this.assets.getPrompt(this.name,this.promptCategory),a=[...new Set([...n.map(e=>s(e.placeholders)).flat(),...i.map(e=>s(e.placeholders)).flat(),...s(o.placeholders).flat()])];return{messages:[{role:"user",content:{type:"text",text:this.patchPrompt([...n.map(e=>e.prompt),o.prompt,...i.map(e=>e.prompt)].join("\n\n"),a,e,r)}}],_meta:{}}}),super.build(e)}setReasoning(e){throw new p.InternalError("Named prompt builders don't require callback")}setEffort(e){throw new p.InternalError("Named prompt builders don't require callback")}setCost(e){throw new p.InternalError("Named prompt builders don't require callback")}setDescription(e){throw new p.InternalError("Named prompt builders don't require callback")}setTitle(e){throw new p.InternalError("Named prompt builders don't require callback")}static get builder(){return new W}}i.__decorate([o.required(),i.__metadata("design:type",String)],W.prototype,"promptCategory",void 0),i.__decorate([o.list(String),o.minlength(1),i.__metadata("design:type",Array)],W.prototype,"prefixes",void 0),i.__decorate([o.minlength(1),o.list(String),i.__metadata("design:type",Array)],W.prototype,"suffixes",void 0);const U=B.builder.setName("example.prompt").setTitle("Example prompt").setDescription("Example prompt for testing").setArgsSchema(a.z.object({message:a.z.string().optional()})).setCb(async e=>{const t=e.message??"default";return{messages:[{role:"assistant",content:{type:"text",text:t}}],content:[],structuredContent:{message:t},result:{message:t}}}),K=B.builder.setName("interactive.jsdoc").setTitle("Interactive JSDoc prompt").setDescription("Interactive prompt for jogging JSDoc helpers").setArgsSchema(a.z.object({gist:a.z.string().optional()})).setCb(async e=>{const t=e.gist??"interactive jsdoc response";return{messages:[{role:"assistant",content:{type:"text",text:t}}],content:[],structuredContent:{message:t},result:{message:t}}}),Y=Object.assign(K,{name:K.getName()});var V;function G(e,t=[],r=[]){const s=W.builder.setCategory(V.DOCS).setName(e);return["prefix",...t].forEach(e=>s.addPrefix(e)),["suffix",...r].forEach(e=>s.addSuffix(e)),s}(e=>{e.DOCS="documentation",e.CODE="code"})(V||(V={}));const Z=[G("class"),G("constant"),G("decorator"),G("function"),G("module"),G("file"),G("repo",[],["iterate"])],Q=a.z.object({className:a.z.string().describe("the class name to turn into a builder")}),X=[U,Y,...Z,B.builder.setName("ts.code.dp.builder").setTitle("Typescript builder design patter prompt").setDescription("for a class, with a defined set of properties, scafold a builder design pattern").setArgsSchema(Q).setReasoning(k.BASIC).setCb((e,t)=>(e.className=s.toPascalCase(e.className),{messages:[{role:"user",content:{type:"text",text:`You're a senior TypeScript developer writing typescript code.You're a senior TypeScript developer writing typescript code.\nTransform the selected class into a builder design pattern implementation in Typescript.\nuse @decaf-ts validation decorators to enforce the validation of your builder.\n\n- must extend the Model Class from @decaf-ts/decorator-validation;\n- each property must be marked as protected;\n- each property must have a setter method that returns 'this' for chaining;\n- the build() method must validate the properties using hasErrors() method from Model class;\n- if validation fails, throw an error with the validation errors;\n- if validation passes, return an instance of the original class with the set properties;\n- optionally (but do so by default) add the static builder and from methods from the example;\n- if the clasee already follows the pattern but has properties without decoration or without setters, simple add them;\n\nexample:\n\noriginal class:\n\`\`\`typescript\nexport class ${e.className} {\n description!: string;\n name!: string = "default name";\n title!: string;\n age?: string;\n dateOfBirth!: Date;\n}}\n\`\`\` \n\nresulting builder pattern implementation:\n\`\`\`typescript\nexport class ${e.className}Builder extends Model {\n\n @minlength(10\n @required()\n protected description!: string;\n \n @required()\n protected name!: string = "default value;\n \n @required()\n protected title!: string;\n \n @min(18)\n protected age?: string;\n \n @date()\n protected dateOfBirth!: Date;\n\n protected constructor(arg?: ModelArg<${e.className}Builder>>) {\n super(arg);\n Model.fromModel(this, arg);\n }\n\n setDescription(value: string) {\n this.description = value;\n return this;\n }\n\n setName(value: string) {\n this.name = value;\n return this;\n }\n\n setTitle(value: string) {\n this.title = value;\n return this;\n }\n setAge(value: number) {\n this.age = value;\n return this;\n }\n setDate(value: Date) {\n this.age = value;\n return this;\n }\n \n build(...args: any[]): ${e.className}Builder | Promise<${e.className}Builder> {\n const errs = this.hasErrors();\n if (errs) throw new Error(errs.toString());\n \n return // code that builds OBJ here\n }\n \n static get builder(): ${e.className}Builder {\n return new ${e.className}Builder(); // static method to get a new builder instance\n }\n \n static from<K extends keyof ${e.className}Builder>(obj: K, ${e.className}Builder[K]): ${e.className}Builder {\n return new ${e.className}Builder(); // static method to create a builder from an object\n }\n}\n\`\`\` \n\n`}}],_meta:{}}))];class ee extends D{setAnnotations(e){return this.annotations=Object.assign(this.annotations,e),this}setCb(e){return this.cb=e,this}setInputSchema(e){return this.inputSchema=e,this}setOutputSchema(e){return this.outputSchema=e,this}constructor(e){super(e),this.annotations={readOnlyHint:!0,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1}}static get builder(){return new ee}build(e){const t=this.hasErrors();if(t)throw Error(t.toString());try{this.inputSchema&&q(this.inputSchema,"inputSchema"),this.outputSchema&&q(this.outputSchema,"outputSchema");const t=P(this.inputSchema),r=P(this.outputSchema);return e.registerTool(this.name,{title:this.title,description:this.description,inputSchema:t,outputSchema:r,annotations:this.annotations,_meta:{usage:{reasoning:this.reasoning,effort:this.effort,cost:this.cost}}},async(e,t)=>{const r=this.logFor(t);r.verbose(`Executing tool ${this.name} with args: ${JSON.stringify(e)}`),t._meta=Object.assign(t._meta||{},{usage:{reasoning:this.reasoning,effort:this.effort,cost:this.cost}});const s=await Promise.resolve(this.cb(e,t));return r.verbose(`Tool ${this.name} executed successfully.`),r.debug("Tool execution meta: "+JSON.stringify(s._meta)),s})}catch(e){const t=e?.message||e+"";if("string"==typeof t&&t.includes("already registered"))return s.Logging.for(this).warn(`Tool ${this.name} already registered - skipping duplicate registration`),{name:this.name};throw s.Logging.for(this).error("Error building tool",e),e}}}i.__decorate([o.required(),i.__metadata("design:type",Object)],ee.prototype,"annotations",void 0),i.__decorate([o.required(),i.__metadata("design:type",Object)],ee.prototype,"cb",void 0),i.__decorate([o.required(),i.__metadata("design:type",Function)],ee.prototype,"inputSchema",void 0);const te=ee.builder.setName("example.tool").setTitle("Example tool").setDescription("A smoke tool used for quick testing").setInputSchema(a.z.object({})).setCb(async()=>({content:[{type:"text",text:"example tool ok"}],result:{status:"ok"}}));Object.assign(te,{name:te.getName()});const re=ee.builder.setName("file.summarizer").setTitle("File summarizer").setDescription("Summaries files for quick previews").setInputSchema(a.z.object({filePath:a.z.string().optional()})).setCb(async()=>({content:[{type:"text",text:"file summary stub"}],result:{summary:"file summary stub"}}));Object.assign(re,{name:re.getName()});const se="##VERSION##";l.Metadata.registerLibrary("##PACKAGE##",se),m.config({path:_.resolve(__dirname,"../../.env")});const ne={mcpId:"decaf",name:"decaf-ts mcp server",title:"Decaf-TS MCP Server",description:"Provides precise coding assistance for the decaf-ts framework",version:se,websiteUrl:"https://decaf-ts.github.io",repositoryUrl:"https://github.com/decaf-ts/mcp-server",license:"AGPL-3.0",workingDir:process.cwd(),assetDir:L(),contacts:[{name:"Decaf-TS",url:"https://decaf-ts.github.io"}],tags:"server,official,decaf-ts",metadata:{},icons:[{src:"workdocs/assets/favicon.svg",mimeType:"image/svg+xml",sizes:"any"}],jira:{host:process.env.JIRA__HOST||"decaf-ts.atlassian.net",email:process.env.JIRA__EMAIL||"",apiKey:process.env.JIRA__API_KEY||process.env.JIRA__APIKEY||"",projectKey:process.env.JIRA__PROJECT_KEY||void 0,issueType:process.env.JIRA__ISSUE_TYPE||void 0,parentIssue:process.env.JIRA__PARENT_ISSUE||void 0},level:s.LogLevel.error},ie=s.LoggedEnvironment.accumulate(ne);function oe(){const{host:e,email:t,apiKey:r,projectKey:s,issueType:n}=ie.jira;return{host:e?.trim(),email:t?.trim(),apiKey:r?.trim(),projectKey:s?.trim(),issueType:n?.trim(),parentIssue:ie.jira.parentIssue?.trim()}}function ae(){const e=oe();return[{name:"JIRA__HOST",required:!0,description:"Atlassian host (e.g. decaf-ts.atlassian.net) where your Jira instance is hosted.",value:e.host},{name:"JIRA__EMAIL",required:!0,description:"Email address of the Jira account that has API access.",value:e.email},{name:"JIRA__API_KEY",required:!0,description:"API token created in your Atlassian profile (a.k.a. APIKEY alias) for authenticating requests.",sensitive:!0,value:e.apiKey},{name:"JIRA__PROJECT_KEY",required:!1,description:"Default Jira project key (e.g. DECAF) used when an issue creation request omits a project.",value:e.projectKey},{name:"JIRA__ISSUE_TYPE",required:!1,description:"Default Jira issue type (e.g. Task, Bug) used when creating issues without an explicit type.",value:e.issueType},{name:"JIRA__PARENT_ISSUE",required:!1,description:"Default parent issue key (e.g. DECAF-123) applied when a child issue is created without an explicit parent.",value:e.parentIssue}]}function ce(e){const t=e.value?((e,t)=>{if(e)return t?"<configured>":e})(e.value,e.sensitive):"not set",r=e.required?"(required)":"(optional)";return`\u2022 ${e.name} ${r}: ${e.description} Current state: ${t}.`}s.Logging.setConfig(ie);class le extends Error{constructor(e){const t=ae(),r=(e=>{const t=ae();return`${e.length?`Missing Jira credentials: ${e.map(e=>e.name).join(", ")}.`:"Jira credentials are configured."}\n\nThis setup uses the following environment variables:\n${t.map(ce).join("\n")}`})(e);super(r),this.name="MissingJiraEnvironmentError",this.descriptors=t,this.missing=e,"function"==typeof Error.captureStackTrace&&Error.captureStackTrace(this,le)}}function pe(e){if(!e)return{code:"jira_error",message:"Unknown Jira error",details:{raw:e}};const t=e?.status??e?.statusCode??e?.response?.status??e?.response?.statusCode,r="number"==typeof t?t:Number(t)||void 0,s=e?.response?.data??e?.data??e?.response?.body??e?.body,n=[];"string"==typeof e?.message&&n.push(e.message),((e,t)=>{e&&(Array.isArray(e.errorMessages)&&e.errorMessages.forEach(e=>"string"==typeof e&&t.push(e)),"string"==typeof e.errorMessage&&t.push(e.errorMessage),e.errorCollection&&Array.isArray(e.errorCollection.errors)&&e.errorCollection.errors.forEach(e=>{"string"==typeof e?t.push(e):e&&"string"==typeof e.message&&t.push(e.message)}),e?.errors&&"object"==typeof e.errors&&Object.values(e.errors).forEach(e=>{"string"==typeof e?t.push(e):"string"==typeof e?.message&&t.push(e.message)}))})(s,n);const i=r?`Jira API error (${r})`:"Jira API error",o=n.length>0?n.join(" | "):i;return{code:r?"jira_"+r:e?.code??"jira_error",message:o,details:{httpStatus:r,body:s,raw:e}}}const de=a.z.object({issueId:a.z.string().min(1),deleteSubtasks:a.z.boolean().optional().default(!0)}),ue={name:"jira.issue-delete",inputSchema:de,runTool:async(e,t)=>{try{const r=de.parse(t),s=e.issues??e.issue??e,n=s?.delete??s?.deleteIssue;if("function"!=typeof n)throw Error("jira client delete endpoint is not available");return await n.call(s,{issueId:r.issueId,deleteSubtasks:r.deleteSubtasks}),{success:!0,message:`Issue ${t.issueId} deleted successfully`}}catch(e){throw pe(e)}}},me=a.z.object({issueId:a.z.string().min(1),expand:a.z.string().optional(),fields:a.z.array(a.z.string()).optional(),properties:a.z.array(a.z.string()).optional()}),he={name:"jira.issue-read",inputSchema:me,runTool:async(e,t)=>{try{const r=me.parse(t),s={issueIdOrKey:r.issueId};r.expand&&(s.expand=r.expand),r.fields&&(s.fields=r.fields),r.properties&&(s.properties=r.properties);const n=await e.issues.get(s);return n?.data??n}catch(e){throw pe(e)}}};function fe(e,t,r){const s=((e.url??"")+"").match(/^(attachment|jira-attachment):(.+)$/i);if(!s)return null;const n=s[2],i=r.resolveAttachment?.(n);return i?{type:"block",node:{type:"mediaSingle",attrs:{layout:"center"},content:[{type:"media",attrs:{type:"file",id:i.id,collection:i.collection??"attachments"}}]}}:null}function ge(e,t){if(!e)return[];if(!t.enableAtMentions&&!t.enableEmojiShortcodes)return[{type:"text",text:e}];let r=0;const s=[],n=/(^|[^A-Za-z0-9_])@([A-Za-z0-9._-]{1,64})/g,i=/:([a-z0-9_+-]{1,64}):/gi;for(;r<e.length;){const o=be(t.enableAtMentions?ye(n,e,r):null,t.enableEmojiShortcodes?ye(i,e,r):null);if(!o){s.push({type:"text",text:e.slice(r)});break}if(o.index>r&&s.push({type:"text",text:e.slice(r,o.index)}),"mention"===o.kind){const{full:e,groups:n}=o,i=n[0]??"",a=n[1]??"";i&&s.push({type:"text",text:i});const c=t.resolveMention?.(a);c?s.push({type:"mention",attrs:{id:c.id,text:c.text}}):s.push({type:"text",text:"@"+a}),r=o.index+e.length;continue}if("emoji"===o.kind){const{full:e,groups:n}=o,i=`:${n[0]}:`,a=t.resolveEmoji?.(i);s.push({type:"emoji",attrs:a?{shortName:a.shortName,text:a.text}:{shortName:i}}),r=o.index+e.length;continue}}return(e=>{const t=[];for(const r of e){const e=t[t.length-1];"text"!==r.type||"text"!==e?.type||e.marks||r.marks?t.push(r):e.text=(e.text??"")+(r.text??"")}return t})(s)}function ye(e,t,r){e.lastIndex=r;const s=e.exec(t);if(!s)return null;const n=e.source.includes("@")?"mention":"emoji";return{index:s.index,full:s[0],groups:s.slice(1),kind:n}}function be(e,t){return e?t&&e.index>t.index?t:e:t}function ve(e){const t=(e.children??[])[0];return"text"===t?.type?(t.value??"")+"":"paragraph"===t?.type?((t.children??[]).map(e=>"text"===e.type?(e.value??"")+"":"").join("")||"")+"":""}function we(e){const t=((e??"")+"").toLowerCase().trim();return t?"info"===t||"note"===t||"success"===t||"warning"===t||"error"===t?t:"danger"===t?"error":null:null}function Se(e){const t=((e??"")+"").toLowerCase().trim();return!t||"neutral"!==t&&"green"!==t&&"yellow"!==t&&"red"!==t&&"blue"!==t&&"purple"!==t?null:t}function je(e,t){const r=[];for(const s of e??[])if(s?.type)if("text"!==s.type)if("strong"!==s.type)if("emphasis"!==s.type)if("delete"!==s.type)if("inlineCode"!==s.type)if("break"!==s.type){if("link"===s.type){const e=(s.url??"")+"",n=Ie(s.children??[],e),i=fe(s,0,t);if(i){"inline"===i.type?r.push(i.node):r.push({type:"text",text:n,marks:[{type:"link",attrs:{href:e}}]});continue}if(t.enableSmartCards&&_e(n,e)){r.push({type:"inlineCard",attrs:{url:e}});continue}r.push({type:"text",text:n,marks:[{type:"link",attrs:{href:e}}]});continue}if("textDirective"===s.type&&"status"===s.name){const e=ve(s)||"Status",t=Se(s.attributes?.color)??"neutral";r.push({type:"status",attrs:{text:e,color:t}});continue}if("textDirective"===s.type&&"emoji"===s.name){const e=ze(s);r.push(Ee(e,t));continue}}else r.push({type:"hardBreak"});else r.push({type:"text",text:(s.value??"")+"",marks:[{type:"code"}]});else r.push(...xe(je(s.children??[],t),{type:"strike"}));else r.push(...xe(je(s.children??[],t),{type:"em"}));else r.push(...xe(je(s.children??[],t),{type:"strong"}));else r.push(...ge((s.value??"")+"",t));return r.filter(e=>!("text"===e.type&&""===(e.text??"")))}function xe(e,t){return e.map(e=>{if("text"!==e.type)return e;const r=e.marks?[...e.marks,t]:[t];return{...e,marks:r}})}function Ie(e,t){const r=[];for(const t of e??[])"text"===t.type||"inlineCode"===t.type?r.push((t.value??"")+""):"emphasis"!==t.type&&"strong"!==t.type&&"delete"!==t.type||r.push(Ie(t.children??[],""));return r.join("")||t}function _e(e,t){const r=(e??"").trim(),s=(t??"").trim();return r===s&&/^https?:\/\//i.test(s)}function ze(e){return(e.children??[]).map(e=>"text"===e.type?(e.value??"")+"":"").join("").trim()||""}function Ee(e,t){const r=e.startsWith(":")?e:`:${e}:`,s=t.resolveEmoji?.(r);return s?{type:"emoji",attrs:{shortName:s.shortName,text:s.text}}:{type:"emoji",attrs:{shortName:r}}}function Te(e){return e?"string"==typeof e?e:"text"===e.type||"inlineCode"===e.type?(e.value??"")+"":Array.isArray(e.children)?e.children.map(Te).join(""):"":""}function ke(e,t){if(!e?.type)return null;if((e=>"containerDirective"===e?.type&&"panel"===e?.name)(e))return((e,t)=>{const r=e.attributes??{},s=we(r.type)??"info",n="string"==typeof r.title?r.title:void 0,i=(e.children??[]).map(e=>ke(e,t)).flat().filter(Boolean);return{type:"panel",attrs:{panelType:s,...n?{panelType:s,title:n}:{panelType:s}},content:i.length?i:[{type:"paragraph",content:[]}]}})(e,t);switch(e.type){case"heading":return{type:"heading",attrs:{level:Oe(e.depth??1,1,6)},content:je(e.children??[],t)};case"paragraph":return(e=>{const t=e.children??[];if(1!==t.length)return null;const r=t[0];if("image"!==r?.type)return null;const s=(r.url??"")+"";return s?{type:"mediaSingle",attrs:{layout:"center"},content:[{type:"media",attrs:{type:"external",url:s}}]}:null})(e)||{type:"paragraph",content:je(e.children??[],t)};case"blockquote":return{type:"blockquote",content:(e.children??[]).map(e=>ke(e,t)).flat().filter(Boolean)};case"list":return((e,t)=>t.enableTaskLists&&(e.children??[]).some(e=>"boolean"==typeof e.checked)?((e,t)=>{const r=[];let s=0;for(const n of e.children??[]){if("boolean"!=typeof n.checked)continue;s+=1;const e=(n.children??[]).map(e=>ke(e,t)).flat().filter(Boolean);r.push({type:"taskItem",attrs:{localId:"task-"+s,state:n.checked?"DONE":"TODO"},content:e.length?e:[{type:"paragraph",content:[]}]})}return{type:"taskList",content:r}})(e,t):{type:e.ordered?"orderedList":"bulletList",content:(e.children??[]).map(e=>((e,t)=>{const r=(e.children??[]).map(e=>ke(e,t)).flat().filter(Boolean);return{type:"listItem",content:r.length?r:[{type:"paragraph",content:[]}]}})(e,t))})(e,t);case"code":{const r=((e,t)=>{const r=(e??"").toString().trim().toLowerCase();return r?t.enableMermaid&&"mermaid"===r?"mermaid":(e=>{const t=e.trim().toLowerCase();return{js:"javascript",javascript:"javascript",jsx:"javascript",ts:"typescript",typescript:"typescript",tsx:"typescript",py:"python",python:"python",rb:"ruby",ruby:"ruby",sh:"bash",bash:"bash",zsh:"bash",shell:"bash",yml:"yaml",yaml:"yaml",json:"json",toml:"toml",xml:"xml",html:"html",css:"css",scss:"scss",sql:"sql",go:"go",rust:"rust",java:"java",c:"c",cpp:"cpp","c++":"cpp",cs:"csharp",csharp:"csharp",php:"php",kotlin:"kotlin",swift:"swift",md:"markdown",markdown:"markdown",graphql:"graphql",gql:"graphql",dockerfile:"docker",makefile:"make",ini:"ini"}[t]??t})(r):null})(e.lang,t);return{type:"codeBlock",attrs:{language:r},content:[{type:"text",text:(e.value??"")+""}]}}case"thematicBreak":return{type:"rule"};case"table":return((e,t)=>({type:"table",content:(e.children??[]).map((e,r)=>({type:"tableRow",content:(e.children??[]).map(e=>({type:0===r?"tableHeader":"tableCell",content:[{type:"paragraph",content:je(e.children??[],t)}]}))}))}))(e,t);case"leafDirective":return"status"===e.name?(e=>{const t=Se((e.attributes??{}).color)??"neutral";return{type:"paragraph",content:[{type:"status",attrs:{text:ve(e)||"Status",color:t}}]}})(e):"panel"===e.name?((e,t)=>{const r=e.attributes??{},s=we(r.type)??"info",n="string"==typeof r.title?r.title:void 0;return{type:"panel",attrs:{panelType:s,...n?{title:n}:{}},content:[{type:"paragraph",content:je([{type:"text",value:ve(e)}],t)}]}})(e,t):Ae(e,t);default:return Ae(e,t)}}function Ae(e,t){if("drop"===t.unknownNodeStrategy)return null;const r=Te(e);return r?{type:"paragraph",content:[{type:"text",text:r}]}:null}function Oe(e,t,r){const s=Number.isFinite(e)?Math.trunc(e):t;return Math.max(t,Math.min(r,s))}const Ne={resolveMention:void 0,resolveAttachment:void 0,resolveEmoji:void 0,enableSmartCards:!0,enableMermaid:!0,enableEmojiShortcodes:!0,enableAtMentions:!0,enableTaskLists:!0,unknownNodeStrategy:"text"};function Ce(e,t={}){const r={...Ne,...t},s=e??"",n=h.unified().use(y).use(g).use(f),i=n.parse(s),o=n.runSync(i);return He(o),((e,t)=>{const r=[];for(const s of e.children??[]){const e=ke(s,t);e&&(Array.isArray(e)?r.push(...e):r.push(e))}return((e,t)=>{if(!t.enableSmartCards)return e;const r=e.content.map(e=>(e=>{if("paragraph"!==e.type)return e;const t=e.content??[];if(1!==t.length)return e;const r=t[0];if("inlineCard"!==r?.type)return e;const s=r.attrs?.url;return s?[{type:"blockCard",attrs:{url:s}}]:e})(e)).flat();return{...e,content:r}})({version:1,type:"doc",content:r},t)})(o,r)}function He(e){if(!e||!Array.isArray(e.children))return;const t=[];for(const r of e.children)"definition"!==r?.type&&("html"!==r?.type?(He(r),t.push(r)):t.push({type:"text",value:(r.value??"")+""}));e.children=t}const De=a.z.object({issueId:a.z.string().min(1),transitionId:a.z.union([a.z.string(),a.z.number()]),fields:a.z.record(a.z.any()).optional(),update:a.z.record(a.z.array(a.z.object({set:a.z.any().optional(),add:a.z.any().optional(),remove:a.z.any().optional()}))).optional(),comment:a.z.string().optional()}),Je={name:"jira.issue-transition",inputSchema:De,runTool:async(e,t)=>{try{const r=De.parse(t),s={id:r.transitionId};r.fields&&(s.fields=r.fields),r.update&&(s.update=r.update),r.comment&&(s.comment={body:Ce(r.comment)});const n=await e.issues.transition({issueId:r.issueId,transition:s});return n?.data??n}catch(e){throw pe(e)}}},qe=a.z.object({issueId:a.z.string().min(1),fields:a.z.record(a.z.any()).optional(),update:a.z.record(a.z.array(a.z.object({set:a.z.any().optional(),add:a.z.any().optional(),remove:a.z.any().optional(),edit:a.z.any().optional()}))).optional(),properties:a.z.array(a.z.any()).optional(),notifyUsers:a.z.boolean().optional().default(!0),issueTemplateId:a.z.string().optional(),overrideScreenSecurity:a.z.boolean().optional().default(!1),overrideEditableFlag:a.z.boolean().optional().default(!1)}),Pe={name:"jira.issue-update",inputSchema:qe,runTool:async(e,t)=>{try{const r=qe.parse(t),s={issueId:r.issueId};r.fields&&(s.fields=r.fields),r.update&&(s.update=r.update),r.properties&&(s.properties=r.properties),void 0!==r.notifyUsers&&(s.notifyUsers=r.notifyUsers),r.issueTemplateId&&(s.issueTemplateId=r.issueTemplateId),void 0!==r.overrideScreenSecurity&&(s.overrideScreenSecurity=r.overrideScreenSecurity),void 0!==r.overrideEditableFlag&&(s.overrideEditableFlag=r.overrideEditableFlag);const n=await e.issues.update(s);return n?.data??n}catch(e){throw pe(e)}}},Me=a.z.object({issueId:a.z.string().min(1),assignee:a.z.union([a.z.string(),a.z.object({accountId:a.z.string().min(1)}),a.z.object({accountType:a.z.string().min(1)})])}),Re={name:"jira.assign-issue",inputSchema:Me,runTool:async(e,t)=>{try{const r=Me.parse(t);let s;s="string"==typeof r.assignee?{accountId:r.assignee}:r.assignee;const n=await e.issues.assign({issueId:r.issueId,assignee:s});return n?.data??n}catch(e){throw pe(e)}}},$e=a.z.object({issueId:a.z.string().min(1)}),Le={name:"jira.unassign-issue",inputSchema:$e,runTool:async(e,t)=>{try{const r=$e.parse(t),s=await e.issues.assign({issueId:r.issueId,assignee:{accountId:"-1"}});return s?.data??s}catch(e){throw pe(e)}}},Fe=a.z.object({issueId:a.z.string().min(1),body:a.z.string().min(1),visibility:a.z.object({type:a.z.enum(["role","group"]),value:a.z.string().min(1)}).optional()}),Be={name:"jira.comment-add",inputSchema:Fe,runTool:async(e,t)=>{try{const r=Fe.parse(t),s={body:Ce(r.body)};r.visibility&&(s.visibility=r.visibility);const n=await e.issues.addComment({issueId:r.issueId,comment:s});return n?.data??n}catch(e){throw pe(e)}}},We=a.z.object({issueId:a.z.string().min(1),start:a.z.number().optional().default(0),maxResults:a.z.number().optional().default(50),orderBy:a.z.string().optional(),expand:a.z.string().optional()}),Ue={name:"jira.comment-list",inputSchema:We,runTool:async(e,t)=>{try{const r=We.parse(t),s=await e.issues.getComments({issueId:r.issueId,start:r.start,maxResults:r.maxResults,orderBy:r.orderBy,expand:r.expand});return s?.data??s}catch(e){throw pe(e)}}},Ke=a.z.object({link:a.z.object({relationship:a.z.enum(["Blocks","Relates to","Duplicates","Is blocked by","Is related to","Is duplicated by","Causes","Is caused by","Clone","Required","Work on","Split","Roll up"]),inwardIssue:a.z.object({id:a.z.string().optional(),key:a.z.string().optional()}),outwardIssue:a.z.object({id:a.z.string().optional(),key:a.z.string().optional()}),comment:a.z.object({body:a.z.string().optional(),visibility:a.z.object({type:a.z.enum(["role","group"]),value:a.z.string().min(1)}).optional()}).optional()})}),Ye={name:"jira.link-create",inputSchema:Ke,runTool:async(e,t)=>{try{const r=Ke.parse(t).link,s={relationship:r.relationship,inwardIssue:r.inwardIssue.id||r.inwardIssue.key,outwardIssue:r.outwardIssue.id||r.outwardIssue.key};r.comment&&(r.comment.body&&(s.comment=Ce(r.comment.body)),r.comment.visibility&&(s.visibility=r.comment.visibility));const n=await e.issues.link(s);return n?.data??n}catch(e){throw pe(e)}}},Ve=a.z.object({issueId:a.z.string().min(1),file:a.z.string().min(1),mimeType:a.z.string().optional(),comment:a.z.string().optional()}),Ge={name:"jira.attach",inputSchema:Ve,runTool:async(e,s)=>{try{const n=Ve.parse(s),i=r.resolve(n.file),o=await t.promises.readFile(i),a=r.basename(i),c=await e.issues.addAttachment({issueId:n.issueId,file:{name:a,content:o,mimeType:n.mimeType??"application/octet-stream"},comment:n.comment});return c?.data??c}catch(e){if(e&&e.code&&"string"==typeof e.code&&["ENOENT","EACCES"].includes(e.code))throw Error("Attachment file error: "+e.message);throw pe(e)}}},Ze=a.z.object({issueId:a.z.string().min(1)}),Qe={name:"jira.attachment-list",inputSchema:Ze,runTool:async(e,t)=>{try{const r=Ze.parse(t),s=await e.issues.getAttachments({issueId:r.issueId});return s?.data??s}catch(e){throw pe(e)}}},Xe=a.z.object({issueId:a.z.string().min(1),attachmentId:a.z.string().min(1)}),et={name:"jira.attachment-delete",inputSchema:Xe,runTool:async(e,t)=>{try{const r=Xe.parse(t);return await e.issues.deleteAttachment({issueId:r.issueId,attachmentId:r.attachmentId}),{success:!0,message:`Attachment ${t.attachmentId} deleted successfully`}}catch(e){throw pe(e)}}},tt=a.z.object({issueId:a.z.string().min(1),timeSpent:a.z.string().min(1),comment:a.z.string().optional(),author:a.z.object({accountId:a.z.string().min(1)}).optional(),startingOn:a.z.string().optional(),artifact:a.z.string().optional()}),rt={name:"jira.worklog-add",inputSchema:tt,runTool:async(e,t)=>{try{const r=tt.parse(t),s={timeSpent:r.timeSpent};r.comment&&(s.comment=r.comment),r.author&&(s.author=r.author),r.startingOn&&(s.started=r.startingOn),r.artifact&&(s.artifact=r.artifact);const n=await e.issues.addWorklog({issueId:r.issueId,...s});return n?.data??n}catch(e){throw pe(e)}}},st={[he.name]:{title:"Jira Issue Read",description:"Read a Jira issue with expandable fields and properties",annotations:{readOnlyHint:!0,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1}},[Pe.name]:{title:"Jira Issue Update",description:"Update a Jira issue using fields, update ops, and property toggles",annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!1,openWorldHint:!0}},[ue.name]:{title:"Jira Issue Delete",description:"Delete a Jira issue and optionally remove its subtasks",annotations:{readOnlyHint:!1,destructiveHint:!0,idempotentHint:!1,openWorldHint:!0}},[Je.name]:{title:"Jira Issue Transition",description:"Transition a Jira issue while optionally adding a comment",annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!1,openWorldHint:!0}},[Re.name]:{title:"Jira Issue Assign",description:"Assign a Jira issue to a user or account",annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!1,openWorldHint:!0}},[Le.name]:{title:"Jira Issue Unassign",description:"Unassign the current owner from a Jira issue",annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!1,openWorldHint:!0}},[Be.name]:{title:"Jira Comment Add",description:"Add a comment to a Jira issue with optional visibility",annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!1,openWorldHint:!0}},[Ue.name]:{title:"Jira Comment List",description:"List comments on a Jira issue with pagination support",annotations:{readOnlyHint:!0,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1}},[Ye.name]:{title:"Jira Link Create",description:"Create an issue link relationship with optional comment",annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!1,openWorldHint:!0}},[Ge.name]:{title:"Jira Attachment Add",description:"Attach a local file to a Jira issue",annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!1,openWorldHint:!0}},[Qe.name]:{title:"Jira Attachment List",description:"List attachments on a Jira issue",annotations:{readOnlyHint:!0,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1}},[et.name]:{title:"Jira Attachment Delete",description:"Delete an attachment from a Jira issue",annotations:{readOnlyHint:!1,destructiveHint:!0,idempotentHint:!1,openWorldHint:!0}},[rt.name]:{title:"Jira Worklog Add",description:"Log time spent on a Jira issue",annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!1,openWorldHint:!0}}};async function nt(e){const t=s.Logging.for(nt);let r,n=null;try{r=(()=>{let e;try{const t=require("jira.js");e=t?.Version3Client||t.default?.Version3Client||t.default||t}catch(e){throw Error("Unable to require 'jira.js' \u2014 ensure it is installed as a dependency: "+e)}const{host:t,email:r,apiKey:s}=(()=>{const e=oe(),t=ae().filter(e=>e.required&&!e.value);if(t.length>0)throw new le(t);return{host:e.host,email:e.email,apiKey:e.apiKey}})();return new e({host:t,authentication:{basic:{email:r,apiToken:s}}})})()}catch(e){if(!(e instanceof le))return void t.warn("Skipping Jira tool registration; unable to create Jira client",{error:e});n=e,t.warn("Registering Jira tools without credentials; each tool will report configuration requirements.",{error:e})}const i=[he,Pe,ue,Je,Re,Le,Be,Ue,Ye,Ge,Qe,et,rt];for(const s of i){const i=st[s.name];if(i)try{await e.registerTool(s.name,{title:i.title,description:i.description,inputSchema:P(s.inputSchema),annotations:i.annotations},async e=>{if(!r)throw n??Error("Jira client unavailable because credentials could not be loaded.");return s.runTool(r,e)}),t.info("Registered Jira tool "+s.name)}catch(e){t.error("Failed to register Jira tool "+s.name,{error:e})}}}async function it(e){await(async e=>{e.registerTool("decaf.server-info",{title:"Decaf MCP Server Info",description:"Return server metadata, version, and registered prompt names for diagnostics.",inputSchema:{},outputSchema:void 0,annotations:{readOnlyHint:!0,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1}},async()=>{const e=X.map(e=>e.getName()).sort();return{content:[{type:"text",text:["Name: "+ie.name,"Title: "+ie.title,"Version: "+ie.version,"Prompts: "+(e.join(", ")||"<none>")].join("\n")}]}})})(e);const t=s.Logging.for(it);try{await nt(e)}catch(e){t.error("Failed to register Jira tools",e)}}class ot extends H{setCb(e){return this.cb=e,this}setConfig(e){return this.config=e,this}setUriOtTemplate(e){return this.uriOrTemplate=e,this}constructor(e){super(e)}static get builder(){return new ot}build(e){const t=this.hasErrors();if(t)throw Error(t.toString());try{const t="string"==typeof this.uriOrTemplate&&this.uriOrTemplate.includes("{")?new v.ResourceTemplate(new b.UriTemplate(this.uriOrTemplate),{list:void 0}):this.uriOrTemplate,r=Object.assign(this.config,{_meta:{}}),s=async(e,t)=>{const r=this.logFor(t);r.verbose(`Requesting resource ${this.name} from ${e.toString()}`);const s=await Promise.resolve(this.cb(e,t));return r.verbose(`Resource ${this.name} retrieved successfully.`),r.debug("Resource retrieval meta: "+JSON.stringify(s._meta)),s};return e.resource(this.name,t,r,s)}catch(e){throw s.Logging.for(this).error("Error registering resource "+this.name,e),e}}}i.__decorate([o.required(),i.__metadata("design:type",String)],ot.prototype,"uriOrTemplate",void 0),i.__decorate([o.required(),i.__metadata("design:type",Function)],ot.prototype,"cb",void 0),i.__decorate([o.required(),i.__metadata("design:type",Object)],ot.prototype,"config",void 0);const at=_.join(process.cwd(),"src/assets"),ct=_.join(at,"templates"),lt=_.join(at,"prompts"),pt=new WeakMap;class dt extends s.LoggedClass{get client(){const e=pt.get(this);if(!e)throw Error("Mcp server requires Mcp client");return e}constructor(){super()}async load(){const e=this.log.for(this.load);for(const t of X)try{e.info("loading prompt "+t.getName());const r=t.build(this.client);e.verbose(`Loaded prompt ${r.title} from ${t.getName()} definition`)}catch(r){e.error("Failed to load prompt "+t.getName(),r)}try{await it(this.client),e.verbose("Registered built-in tools")}catch(t){e.error("Failed to register tools",t)}try{await(async(e,t)=>{t.info("Registering agent templates as resources...");const r=I.readdirSync(ct).filter(e=>e.endsWith(".md"));for(const s of r){const r=_.basename(s,".md"),n=_.join(ct,s),i=ot.builder.setName(r).setTitle("Template: "+r).setDescription("Resource template for "+r).setUriOtTemplate("file:///"+n).setConfig({mimeType:"text/markdown",description:"Template for "+r}).setCb(async e=>{const t=I.readFileSync(e.pathname,"utf8");return{contents:[{uri:e.toString(),text:t,mimeType:"text/markdown"}],_meta:{}}});try{i.build(e),t.info("Registered template: "+r)}catch(e){t.error(`Failed to register template ${r}:`,e)}}t.info("Registering agent prompts...");const s=I.readdirSync(lt).filter(e=>e.endsWith(".md"));for(const r of s){const s=_.basename(r,".md"),n=_.join(lt,r),i=I.readFileSync(n,"utf8"),o=B.builder.setName(s).setTitle("Prompt: "+s).setDescription("Dynamic prompt for "+s).setArgsSchema(a.z.object({})).setCb(async e=>({messages:[{role:"user",content:{type:"text",text:i}}],_meta:{}}));try{o.build(e),t.info("Registered prompt: "+s)}catch(e){t.error(`Failed to register prompt ${s}:`,e)}}})(this.client,e),e.verbose("Registered agent-specific assets")}catch(t){e.error("Failed to register agent assets",t)}}async boot(e="stdio"){let t=this.log;this.log.for(this.boot).info("McpServer booting..."),((e=s.Logging.get())=>{let t;try{t=(()=>{let e,t=__dirname;try{for(;t&&t!==_.parse(t).root;){const r=_.join(t,"node_modules");if(I.existsSync(r)&&I.statSync(r).isDirectory()){e=r;break}const s=_.dirname(t);if(s===t)break;t=s}}catch{}const r=[];if(e){const t=_.join(e,"@decaf-ts");try{if(I.existsSync(t)&&I.statSync(t).isDirectory()){const e=I.readdirSync(t);for(const s of e){const e=_.join(t,s);try{const t=_.join(e,"workdocs","assets","slogans.json");if(I.existsSync(t)&&I.statSync(t).isFile()){const e=I.readFileSync(t,"utf-8"),s=JSON.parse(e);if(Array.isArray(s))for(const e of s)"string"==typeof e&&e.trim().length>0&&r.push(e.trim())}}catch{}}}}catch{}}return 0===r.length?"Decaf: strongly brewed TypeScript.":r[Math.floor(Math.random()*r.length)]})()}catch{t="Decaf: strongly brewed TypeScript."}const r="# \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \n# ( ( \u2591\u2592\u2593\u2588\u2593\u2592\u2591\u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591\u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591\u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \n# ) ) \u2591\u2592\u2593\u2588\u2593\u2592\u2591\u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591\u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \n# [=======] \u2591\u2592\u2593\u2588\u2593\u2592\u2591\u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \n# `-----\xb4 \u2591\u2592\u2593\u2588\u2593\u2592\u2591\u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591\u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \n# \u2591\u2592\u2593\u2588\u2593\u2592\u2591\u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591\u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591\u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \n# \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591\u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \n#".split("\n"),i=r.reduce((e,t)=>Math.max(e,t.length),0);r.push("# "+t.padStart(i-3)),r.forEach((t,r)=>{const s=T[r%T.length]||"",i=e.info.bind(e);try{i(n.style(t||"").raw(s).text)}catch{i((t||"")+"")}})})(this.log),"stdio"===e&&(s.Logging.setFactory(E),t=s.Logging.for(this.constructor.name));const r=((Array.isArray(ie.icons)?ie.icons:[ie.icons])||[]).map(e=>{const t="string"==typeof e?.src?e.src:(e?.src??"")+"",r="string"==typeof e?.mimeType?e.mimeType:(e?.mimeType??"")+"";let s=[];return Array.isArray(e?.sizes)?s=e.sizes.map(e=>e+""):"string"==typeof e?.sizes&&(s=(e.sizes+"").split(",").map(e=>e.trim())),{src:t,mimeType:r,sizes:s}}),i={name:ie.name,title:ie.title,websiteUrl:ie.websiteUrl,version:ie.version,icons:r},o=new v.McpServer(i,{instructions:"You are an AI assistant designed to help users with programming tasks related to the Decaf-TS framework. \nProvide clear, concise, and accurate information.\nIf you don't know the answer, admit it rather than making up information.\nAlways prioritize the user's intent and provide helpful suggestions when appropriate.\n",capabilities:{logging:{},tools:{},prompts:{}}});switch(((e,t)=>{pt.set(e,t)})(this,o),o.onerror=e=>{this.log.error("MCP instance onerror",e)},e){case"stdio":e=new S.StdioServerTransport;break;case"http":e=new j.StreamableHTTPServerTransport({sessionIdGenerator:()=>w.v4(),onsessioninitialized:e=>t.verbose("Session initialized: "+e),onsessionclosed:e=>t.verbose("Session closed: "+e),enableJsonResponse:!0,eventStore:void 0});break;default:if(!(a=e)||"object"!=typeof a||"function"!=typeof a.send&&"function"!=typeof a.close&&"function"!=typeof a.on)throw new p.InternalError("Invalid transport type: "+e)}var a;try{this.log.info("Loading resources/prompts/tools..."),await this.load()}catch(e){throw this.log.error("Error loading resources/prompts/tools: "+e),e}await this.client.connect(e),t.info(`MCP Server connected via ${e.constructor.name} and running. Waiting for client connections...`)}}const ut=(new e.Command).command("start").option("--transport [String]","transport mode","stdio").description("starts decaf's mcp server").action(async e=>{const s=JSON.parse(t.readFileSync(r.join(process.cwd(),"package.json"),"utf-8")),n=s.version,{transport:i}=e,o=(new z).for("mcp-server");if("stdio"!==i)throw Error("Unsupported transport mode: "+i);return o.info("Transport stdio"),o.debug(`running with options: ${JSON.stringify(e)} for ${s.name} version ${n}`),(new dt).boot(i)});(new e.Command).command("md-to-ast").description("pipes markdown to jira ast: `cat file.md` | npx decaf-mcp md-to-ast > ast.json").action(async e=>{const n=JSON.parse(t.readFileSync(r.join(process.cwd(),"package.json"),"utf-8")),i=n.version;s.Logging.for("md-to-ast").debug(`running with options: ${JSON.stringify(e)} for ${n.name} version ${i}`);const o=Ce(await(async()=>{const e=[];for await(const t of process.stdin)e.push(Buffer.from(t));return Buffer.concat(e).toString("utf8")})(),{resolveMention:e=>({id:e,text:"@"+e}),resolveAttachment:e=>({id:e,collection:"attachments"})});process.stdout.write(JSON.stringify(o,null,2)+"\n")});const mt=(new e.Command).name("mcp-server").command("mcp-server").description("decaf mcp server and agentic functionality");mt.addCommand(ut),mt.parse(process.argv)},"object"==typeof exports&&"undefined"!=typeof module?t(require("commander"),require("fs"),require("path"),require("@decaf-ts/logging"),require("styled-string-builder"),require("tslib"),require("@decaf-ts/decorator-validation"),require("zod"),require("@decaf-ts/injectable-decorators"),require("@decaf-ts/decoration"),require("@decaf-ts/db-decorators"),require("crypto"),require("zlib"),require("dotenv"),require("unified"),require("remark-directive"),require("remark-gfm"),require("remark-parse"),require("@modelcontextprotocol/sdk/shared/uriTemplate.js"),require("@modelcontextprotocol/sdk/server/mcp.js"),require("uuid"),require("@modelcontextprotocol/sdk/server/stdio.js"),require("@modelcontextprotocol/sdk/server/streamableHttp.js")):"function"==typeof define&&define.amd?define(["commander","fs","path","@decaf-ts/logging","styled-string-builder","tslib","@decaf-ts/decorator-validation","zod","@decaf-ts/injectable-decorators","@decaf-ts/decoration","@decaf-ts/db-decorators","crypto","zlib","dotenv","unified","remark-directive","remark-gfm","remark-parse","@modelcontextprotocol/sdk/shared/uriTemplate.js","@modelcontextprotocol/sdk/server/mcp.js","uuid","@modelcontextprotocol/sdk/server/stdio.js","@modelcontextprotocol/sdk/server/streamableHttp.js"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).commander,e.fs,e.path,e.decafTsLogging,e.styledStringBuilder,e.tslib,e.decafTsDecoratorValidation,e.zod,e.decafTsInjectableDecorators,e.decafTsDecoration,e.decafTsDbDecorators,e.crypto,e.zlib,e.dotenv,e.unified,e.remarkDirective,e.remarkGfm,e.remarkParse,e.uriTemplate_js,e.mcp_js,e.uuid,e.stdio_js,e.streamableHttp_js);
3
3
  //# sourceMappingURL=mcp-server.cjs.map