@decaf-ts/mcp-server 1.2.6 → 1.2.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/code/patterns/builder.enc +0 -0
- package/dist/assets/prompts/agent/agent.enc +0 -0
- package/dist/assets/prompts/agent/init.enc +0 -0
- package/dist/assets/prompts/constitution_commands.enc +0 -0
- package/dist/assets/prompts/documentation/class.enc +0 -0
- package/dist/assets/prompts/documentation/constant.enc +0 -0
- package/dist/assets/prompts/documentation/decorator.enc +0 -0
- package/dist/assets/prompts/documentation/file.enc +0 -0
- package/dist/assets/prompts/documentation/function.enc +0 -0
- package/dist/assets/prompts/documentation/interface.enc +0 -0
- package/dist/assets/prompts/documentation/iterate.enc +0 -0
- package/dist/assets/prompts/documentation/module.enc +0 -0
- package/dist/assets/prompts/documentation/prefix.enc +0 -0
- package/dist/assets/prompts/documentation/repo.enc +0 -0
- package/dist/assets/prompts/documentation/suffix.enc +0 -0
- package/dist/assets/prompts/git_commands.enc +0 -0
- package/dist/assets/prompts/jira/operational_prompts.enc +0 -0
- package/dist/assets/prompts/jira/system_prompt.enc +0 -0
- package/dist/assets/prompts/mode_commands.enc +0 -0
- package/dist/assets/prompts/plan_commands.enc +0 -0
- package/dist/assets/prompts/repository/readme.enc +0 -0
- package/dist/assets/prompts/repository/release_notes.enc +0 -0
- package/dist/assets/prompts/repository/setup.enc +0 -0
- package/dist/assets/prompts/specification_commands.enc +0 -0
- package/dist/assets/prompts/startup_command.enc +0 -0
- package/dist/assets/prompts/task_commands.enc +0 -0
- package/dist/assets/prompts/tests/coverage.enc +0 -0
- package/dist/assets/templates/AGENTS.enc +0 -0
- package/dist/assets/templates/agents_template.enc +0 -0
- package/dist/assets/templates/constitution_template.enc +0 -0
- package/dist/assets/templates/decaf/context/logCtx.enc +0 -0
- package/dist/assets/templates/decaf/services/client_based_service.enc +0 -0
- package/dist/assets/templates/decaf/services/model_service.enc +3 -2
- package/dist/assets/templates/decaf/services/service.enc +0 -0
- package/dist/assets/templates/decaf_guidelines.enc +1 -1
- package/dist/assets/templates/instructions_template.enc +0 -0
- package/dist/assets/templates/jira_templates.enc +0 -0
- package/dist/assets/templates/plan_template.enc +0 -0
- package/dist/assets/templates/specification_template.enc +0 -0
- package/dist/assets/templates/task_template.enc +0 -0
- package/dist/mcp-server.cjs +1 -1
- package/dist/mcp-server.cjs.map +1 -1
- package/dist/mcp-server.js +1 -1
- package/dist/mcp-server.js.map +1 -1
- package/package.json +1 -1
package/dist/mcp-server.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{Command as t}from"commander";import*as e from"fs";import r,{promises as s}from"fs";import*as n from"path";import i from"path";import{MiniLogger as o,NumericLogLevels as a,Logging as c,LoggedClass as p,toSnakeCase as l,sf as u,toPascalCase as d,LogLevel as m,LoggedEnvironment as h}from"@decaf-ts/logging";import{style as f}from"styled-string-builder";import{__decorate as y,__metadata as g}from"tslib";import{required as b,Model as v,list as w,minlength as S}from"@decaf-ts/decorator-validation";import{z as j,ZodObject as x}from"zod";import{injectable as I,inject as A}from"@decaf-ts/injectable-decorators";import{prop as E,Metadata as k}from"@decaf-ts/decoration";import{InternalError as T,SerializationError as N,ValidationError as O}from"@decaf-ts/db-decorators";import C from"crypto";import H from"zlib";import{unified as J}from"unified";import _ from"remark-directive";import D from"remark-gfm";import P from"remark-parse";import{UriTemplate as R}from"@modelcontextprotocol/sdk/shared/uriTemplate.js";import{ResourceTemplate as $,McpServer as M}from"@modelcontextprotocol/sdk/server/mcp.js";import{v4 as F}from"uuid";import{StdioServerTransport as q}from"@modelcontextprotocol/sdk/server/stdio.js";import{StreamableHTTPServerTransport as B}from"@modelcontextprotocol/sdk/server/streamableHttp.js";class W extends o{log(t,e,r,s){const n=this.config("level");a[n],a[t]}}const L=(t,e,...r)=>{const s=(t=>{if("string"==typeof t)return t;if(!t)return"unknown";if("function"==typeof t)return t.name||"unknown";if("object"==typeof t&&"constructor"in t){const e=t.constructor;if(e&&e.name)return e.name}return"unknown"})(t);return new W(s,e)},U=["\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,z,Y,G,Z;(t=>{t[t.NONE=0]="NONE",t[t.BASIC=1]="BASIC",t[t.ADVANCED=2]="ADVANCED",t[t.HIGH=3]="HIGH"})(K||(K={})),(t=>{t[t.NONE=0]="NONE",t[t.LOW=1]="LOW",t[t.MEDIUM=2]="MEDIUM",t[t.HIGH=3]="HIGH"})(z||(z={})),(t=>{t[t.FREE=0]="FREE",t[t.LOW=1]="LOW",t[t.MEDIUM=2]="MEDIUM",t[t.HIGH=3]="HIGH"})(Y||(Y={}));class V extends v{get log(){return this._log||(this._log=c.for(this)),this._log}constructor(t){super(t)}logFor(t){const{sessionId:e,requestId:r,authInfo:s}=t||{};let n="string"==typeof e&&e.length>0?this.log.for(e):this.log;return s&&s.clientId&&(n=n.for(s.clientId)),r&&(n=n.for(r.toString())),n}setDescription(t){return this.description=t,this}getDescription(){return this.description}setName(t){return this.name=t,this}getName(){return this.name}setTitle(t){return this.title=t,this}}y([b(),g("design:type",String)],V.prototype,"description",void 0),y([b(),g("design:type",String)],V.prototype,"name",void 0),y([b(),g("design:type",String)],V.prototype,"title",void 0);class Q extends V{constructor(t){super(t),this.reasoning=K.NONE,this.effort=z.NONE,this.cost=Y.FREE}setReasoning(t){return this.reasoning=t,this}setEffort(t){return this.effort=t,this}setCost(t){return this.cost=t,this}}function X(t){if(!t)return;let e=t,r=e&&e._def;for(;r&&"ZodObject"!==r.typeName;){if("ZodEffects"===r.typeName&&r.schema)e=r.schema;else if("ZodOptional"===r.typeName&&r.innerType)e=r.innerType;else if("ZodDefault"===r.typeName&&r.innerType)e=r.innerType;else if("ZodNullable"===r.typeName&&r.innerType)e=r.innerType;else{if(!r.schema)return;e=r.schema}r=e&&e._def}return r&&"ZodObject"===r.typeName?r:void 0}function tt(t,e="schema"){if(X(t))return t;if(t&&"object"==typeof t){const e=t.def&&"object"==typeof t.def?t.def:void 0,r=e&&(e.shape||"object"===e.type)&&e.shape||("object"===t.type?t.shape:void 0)||(e&&"object"===e.type?{}:void 0);if(e||"object"===t.type||r){const t={};if(r&&"object"==typeof r)for(const[e,s]of Object.entries(r))t[e]=rt(s)?s:j.any();return j.object(t)}}throw Error(`Registration error: provided a non-canonical ${e}. Export a ZodObject (z.object(...)).`)}function et(t){if(!t)return;if(t&&"object"==typeof t&&!t._def)return t.def&&"object"==typeof t.def&&t.def.shape?t.def.shape:t;const e=X(t);return e?"function"==typeof e.shape?e.shape():e.shape||void 0:void 0}function rt(t){return!(!t||"object"!=typeof t||!t._def)}y([b(),g("design:type",Number)],Q.prototype,"reasoning",void 0),y([b(),g("design:type",Number)],Q.prototype,"effort",void 0),y([b(),g("design:type",Number)],Q.prototype,"cost",void 0),(t=>{t.ASSETS="assets"})(G||(G={})),(t=>{t.PROMPT="prompts",t.DOCUMENTATION="documentation",t.CODE="code"})(Z||(Z={}));const st=Buffer.from("DCAF1","ascii");function nt(t){let r=t;for(;;){const t=n.join(r,"lib","assets");if(e.existsSync(t))return t;const s=n.join(r,"src","assets");if(e.existsSync(s))return s;const i=n.join(r,"assets");if(e.existsSync(i))return i;const o=n.dirname(r);if(o===r)break;r=o}}function it(){const t=process.env.DECAF_ASSET_DIR||process.env.MCP_ASSET_DIR||process.env.ASSET_DIR||"";if(t&&e.existsSync(t))return t;const r=nt(__dirname);if(r)return r;const s=process.argv?.[1];if(s){const t=nt(n.dirname(s));if(t)return t}const i=[process.cwd(),process.env.INIT_CWD].filter(Boolean);for(const t of i){const e=nt(t);if(e)return e}return n.join(process.cwd(),"assets")}let ot=class extends p{constructor(t){super(),this.basePath=t||it()}listAssets(...t){const r=n.join(this.basePath,...t);return e.readdirSync(r)}listPrompts(){return this.listAssets(Z.PROMPT)}getAsset(t,r="md",...s){const i=n.join(this.basePath,...s),o=(t,r=!1)=>{try{return r?(t=>{if(t.length<st.length+16+12+16)throw Error("Invalid prompt payload (too short)");if(!t.subarray(0,st.length).equals(st))throw Error("Invalid prompt payload (bad magic)");const e=process.env.ENCRYPTION_KEY||"";if(!e)throw Error("Missing encryption key. Set ENCRYPTION_KEY to load obfuscated assets.");let r=st.length;const s=t.subarray(r,r+16);r+=16;const n=t.subarray(r,r+12);r+=12;const i=t.subarray(r,r+16);r+=16;const o=t.subarray(r),a=((t,e)=>C.scryptSync(t,e,32))(e,s),c=C.createDecipheriv("aes-256-gcm",a,n);c.setAuthTag(i);const p=Buffer.concat([c.update(o),c.final()]);return H.gunzipSync(p)})(e.readFileSync(t)).toString("utf-8"):e.readFileSync(t,"utf-8")}catch(t){if("ENOENT"===t.code)return null;throw t}},a=o(n.join(i,`${t}.${r}`),"enc"===r);if(null!==a)return a;const c=o(n.join(i,t+".enc"),!0);if(null!==c)return c;throw Error("Asset not found: "+n.join(i,`${t}.${r}`))}getAllAssets(t,...e){return this.listAssets(t,...e).reduce((r,s)=>{const i=n.extname(s),o=n.basename(s,i),a=i.replace(/^\./,"")||void 0;return r[o]=this.getAsset(o,a??void 0,t,...e),r},{})}toPromptDef(t){const e=t=>"number"==typeof t?t:"string"==typeof t?(t=>{switch(t){case"none":return K.NONE;case"basic":return K.BASIC;case"advanced":return K.ADVANCED;case"high":return K.HIGH;case"medium":return z.MEDIUM;case"low":return Y.LOW;case"free":return Y.FREE;default:throw new T("Cannon convert unknown level "+t)}})(t.toLowerCase()):K.NONE;return t.effort=e(t.effort),t.reasoning=e(t.reasoning),t.cost=e(t.cost),t}getPrompt(t,...e){const r=this.getAsset(l(t),"json",Z.PROMPT,...e);let s;try{s=JSON.parse(r)}catch(r){throw new N(`Failed to parse prompt ${t} in categories ${e}: ${r}`)}return this.toPromptDef(s)}getAllPrompts(...t){const e=this.getAllAssets(Z.PROMPT,...t);return Object.entries(e).reduce((e,[r,s])=>{try{e[r]=JSON.parse(s)}catch(e){throw new N(`Failed to parse prompt ${r} in categories ${t}: ${e}`)}return e},e)}};ot=y([I(),g("design:paramtypes",[String])],ot);class at extends Q{constructor(t){super(t)}setCb(t){return this.cb=t,this}setArgsSchema(t){return this.argsSchema=t,this}static get builder(){return new at}static patchPrompt(t,e,r,s){const n=(e=Array.isArray(e)?e:Object.keys(e)).filter(t=>!Object.prototype.hasOwnProperty.call(r,t));if(n.length)throw new O("Missing replacements for placeholders: "+n.join(", "));s&&(s.verbose("Patching prompt with placeholders: "+JSON.stringify(e)),s.debug("Values: "+JSON.stringify(r)));const i=e.reduce((t,e)=>(t[e]=r[e],t),{});return u(t,i)}patchPrompt(t,e,r,s){return at.patchPrompt(t,e,r,s||this.log.for(this.patchPrompt))}build(t,e){const r=this.log.for(this.build),s=this.hasErrors();if(s)throw new O(s.toString());try{this.argsSchema&&tt(this.argsSchema,"argsSchema");const r=et(this.argsSchema);return t.registerPrompt(this.name,{title:this.title,description:this.description,argsSchema:r},async(t,r)=>{const s=this.logFor(r);t=Object.assign({},e,t||{}),s.verbose(`Executing prompt ${this.name} with args: ${JSON.stringify(t)}`),t._meta=Object.assign(t._meta||{},{usage:{reasoning:this.reasoning,effort:this.effort,cost:this.cost}});const n=await Promise.resolve(this.cb(t,r));return s.verbose(`Prompt ${this.name} executed successfully.`),s.debug("Prompt execution meta: "+JSON.stringify(n._meta)),n})}catch(t){throw r.error("Failed to register prompt "+(this.name||this.constructor.name),t),t}}}y([A(ot),g("design:type",ot)],at.prototype,"assets",void 0),y([b(),g("design:type",Object)],at.prototype,"cb",void 0),y([b(),g("design:type",x)],at.prototype,"argsSchema",void 0),y([E(),g("design:type",Object)],at.prototype,"placeholders",void 0);class ct extends at{setCategory(t){return this.promptCategory=t,this}addPrefix(t){return this.prefixes=this.prefixes||[],this.prefixes.push(t),this}addSuffix(t){return this.suffixes=this.suffixes||[],this.suffixes.push(t),this}constructor(t){super(t)}build(t){const e=this.assets.getPrompt(this.name,this.promptCategory);v.fromObject(this,e);const r=new Set((k.properties(ct)||[]).filter(t=>!["assets","promptCategory","prefixes","suffixes"].includes(t)));["cb","argsSchema"].forEach(t=>r.add(t));const s=this.hasErrors(...Array.from(r));if(s)throw new O(s.toString());const n=(this.prefixes||[]).map(t=>this.assets.getPrompt(t,this.promptCategory)),i=(this.suffixes||[]).map(t=>this.assets.getPrompt(t,this.promptCategory)),o=[...new Set([...e.placeholders,...n.map(t=>t.placeholders||[]),...i.map(t=>t.placeholders||[])].flat())].reduce((t,e)=>(t[e]=j.string().describe("The description for "+e),t),{});return this.setArgsSchema(j.object(o)),this.setCb((t,e)=>{const r=this.logFor(e).for(ct).for(this.promptCategory).for(this.name);function s(t=[]){return Array.isArray(t)?t:Object.keys(t)}const n=(this.prefixes||[]).map(t=>this.assets.getPrompt(t,this.promptCategory)),i=(this.suffixes||[]).map(t=>this.assets.getPrompt(t,this.promptCategory)),o=this.assets.getPrompt(this.name,this.promptCategory),a=[...new Set([...n.map(t=>s(t.placeholders)).flat(),...i.map(t=>s(t.placeholders)).flat(),...s(o.placeholders).flat()])];return{messages:[{role:"user",content:{type:"text",text:this.patchPrompt([...n.map(t=>t.prompt),o.prompt,...i.map(t=>t.prompt)].join("\n\n"),a,t,r)}}],_meta:{}}}),super.build(t)}setReasoning(t){throw new T("Named prompt builders don't require callback")}setEffort(t){throw new T("Named prompt builders don't require callback")}setCost(t){throw new T("Named prompt builders don't require callback")}setDescription(t){throw new T("Named prompt builders don't require callback")}setTitle(t){throw new T("Named prompt builders don't require callback")}static get builder(){return new ct}}y([b(),g("design:type",String)],ct.prototype,"promptCategory",void 0),y([w(String),S(1),g("design:type",Array)],ct.prototype,"prefixes",void 0),y([S(1),w(String),g("design:type",Array)],ct.prototype,"suffixes",void 0);const pt=at.builder.setName("example.prompt").setTitle("Example prompt").setDescription("Example prompt for testing").setArgsSchema(j.object({message:j.string().optional()})).setCb(async t=>{const e=t.message??"default";return{messages:[{role:"assistant",content:{type:"text",text:e}}],content:[],structuredContent:{message:e},result:{message:e}}}),lt=at.builder.setName("interactive.jsdoc").setTitle("Interactive JSDoc prompt").setDescription("Interactive prompt for jogging JSDoc helpers").setArgsSchema(j.object({gist:j.string().optional()})).setCb(async t=>{const e=t.gist??"interactive jsdoc response";return{messages:[{role:"assistant",content:{type:"text",text:e}}],content:[],structuredContent:{message:e},result:{message:e}}}),ut=Object.assign(lt,{name:lt.getName()});var dt;function mt(t,e=[],r=[]){const s=ct.builder.setCategory(dt.DOCS).setName(t);return["prefix",...e].forEach(t=>s.addPrefix(t)),["suffix",...r].forEach(t=>s.addSuffix(t)),s}(t=>{t.DOCS="documentation",t.CODE="code"})(dt||(dt={}));const ht=[mt("class"),mt("constant"),mt("decorator"),mt("function"),mt("module"),mt("file"),mt("repo",[],["iterate"])],ft=j.object({className:j.string().describe("the class name to turn into a builder")}),yt=[pt,ut,...ht,at.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(ft).setReasoning(K.BASIC).setCb((t,e)=>(t.className=d(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 gt extends Q{setAnnotations(t){return this.annotations=Object.assign(this.annotations,t),this}setCb(t){return this.cb=t,this}setInputSchema(t){return this.inputSchema=t,this}setOutputSchema(t){return this.outputSchema=t,this}constructor(t){super(t),this.annotations={readOnlyHint:!0,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1}}static get builder(){return new gt}build(t){const e=this.hasErrors();if(e)throw Error(e.toString());try{this.inputSchema&&tt(this.inputSchema,"inputSchema"),this.outputSchema&&tt(this.outputSchema,"outputSchema");const e=et(this.inputSchema),r=et(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(t,e)=>{const r=this.logFor(e);r.verbose(`Executing tool ${this.name} with args: ${JSON.stringify(t)}`),e._meta=Object.assign(e._meta||{},{usage:{reasoning:this.reasoning,effort:this.effort,cost:this.cost}});const s=await Promise.resolve(this.cb(t,e));return r.verbose(`Tool ${this.name} executed successfully.`),r.debug("Tool execution meta: "+JSON.stringify(s._meta)),s})}catch(t){const e=t?.message||t+"";if("string"==typeof e&&e.includes("already registered"))return c.for(this).warn(`Tool ${this.name} already registered - skipping duplicate registration`),{name:this.name};throw c.for(this).error("Error building tool",t),t}}}y([b(),g("design:type",Object)],gt.prototype,"annotations",void 0),y([b(),g("design:type",Object)],gt.prototype,"cb",void 0),y([b(),g("design:type",Function)],gt.prototype,"inputSchema",void 0);const bt=gt.builder.setName("example.tool").setTitle("Example tool").setDescription("A smoke tool used for quick testing").setInputSchema(j.object({})).setCb(async()=>({content:[{type:"text",text:"example tool ok"}],result:{status:"ok"}}));Object.assign(bt,{name:bt.getName()});const vt=gt.builder.setName("file.summarizer").setTitle("File summarizer").setDescription("Summaries files for quick previews").setInputSchema(j.object({filePath:j.string().optional()})).setCb(async()=>({content:[{type:"text",text:"file summary stub"}],result:{summary:"file summary stub"}}));Object.assign(vt,{name:vt.getName()});const wt="##VERSION##";k.registerLibrary("##PACKAGE##",wt);const St={mcpId:"decaf",name:"decaf-ts mcp server",title:"Decaf-TS MCP Server",description:"Provides precise coding assistance for the decaf-ts framework",version:wt,websiteUrl:"https://decaf-ts.github.io",repositoryUrl:"https://github.com/decaf-ts/mcp-server",license:"AGPL-3.0",workingDir:process.cwd(),assetDir:it(),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:m.error},jt=h.accumulate(St);function xt(){const{host:t,email:e,apiKey:r,projectKey:s,issueType:n}=jt.jira;return{host:t?.trim(),email:e?.trim(),apiKey:r?.trim(),projectKey:s?.trim(),issueType:n?.trim(),parentIssue:jt.jira.parentIssue?.trim()}}function It(){const t=xt();return[{name:"JIRA__HOST",required:!0,description:"Atlassian host (e.g. decaf-ts.atlassian.net) where your Jira instance is hosted.",value:t.host},{name:"JIRA__EMAIL",required:!0,description:"Email address of the Jira account that has API access.",value:t.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:t.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:t.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:t.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:t.parentIssue}]}function At(t){const e=t.value?((t,e)=>{if(t)return e?"<configured>":t})(t.value,t.sensitive):"not set",r=t.required?"(required)":"(optional)";return`\u2022 ${t.name} ${r}: ${t.description} Current state: ${e}.`}c.setConfig(jt);class Et extends Error{constructor(t){const e=It(),r=(t=>{const e=It();return`${t.length?`Missing Jira credentials: ${t.map(t=>t.name).join(", ")}.`:"Jira credentials are configured."}\n\nThis setup uses the following environment variables:\n${e.map(At).join("\n")}`})(t);super(r),this.name="MissingJiraEnvironmentError",this.descriptors=e,this.missing=t,"function"==typeof Error.captureStackTrace&&Error.captureStackTrace(this,Et)}}function kt(t){if(!t)return{code:"jira_error",message:"Unknown Jira error",details:{raw:t}};const e=t?.status??t?.statusCode??t?.response?.status??t?.response?.statusCode,r="number"==typeof e?e:Number(e)||void 0,s=t?.response?.data??t?.data??t?.response?.body??t?.body,n=[];"string"==typeof t?.message&&n.push(t.message),((t,e)=>{t&&(Array.isArray(t.errorMessages)&&t.errorMessages.forEach(t=>"string"==typeof t&&e.push(t)),"string"==typeof t.errorMessage&&e.push(t.errorMessage),t.errorCollection&&Array.isArray(t.errorCollection.errors)&&t.errorCollection.errors.forEach(t=>{"string"==typeof t?e.push(t):t&&"string"==typeof t.message&&e.push(t.message)}),t?.errors&&"object"==typeof t.errors&&Object.values(t.errors).forEach(t=>{"string"==typeof t?e.push(t):"string"==typeof t?.message&&e.push(t.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:t?.code??"jira_error",message:o,details:{httpStatus:r,body:s,raw:t}}}const Tt=j.object({issueId:j.string().min(1),deleteSubtasks:j.boolean().optional().default(!0)}),Nt={name:"jira.issue-delete",inputSchema:Tt,runTool:async(t,e)=>{try{const r=Tt.parse(e),s=t.issues??t.issue??t,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 ${e.issueId} deleted successfully`}}catch(t){throw kt(t)}}},Ot=j.object({issueId:j.string().min(1),expand:j.string().optional(),fields:j.array(j.string()).optional(),properties:j.array(j.string()).optional()}),Ct={name:"jira.issue-read",inputSchema:Ot,runTool:async(t,e)=>{try{const r=Ot.parse(e),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 t.issues.get(s);return n?.data??n}catch(t){throw kt(t)}}};function Ht(t,e,r){const s=((t.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 Jt(t,e){if(!t)return[];if(!e.enableAtMentions&&!e.enableEmojiShortcodes)return[{type:"text",text:t}];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<t.length;){const o=Dt(e.enableAtMentions?_t(n,t,r):null,e.enableEmojiShortcodes?_t(i,t,r):null);if(!o){s.push({type:"text",text:t.slice(r)});break}if(o.index>r&&s.push({type:"text",text:t.slice(r,o.index)}),"mention"===o.kind){const{full:t,groups:n}=o,i=n[0]??"",a=n[1]??"";i&&s.push({type:"text",text:i});const c=e.resolveMention?.(a);c?s.push({type:"mention",attrs:{id:c.id,text:c.text}}):s.push({type:"text",text:"@"+a}),r=o.index+t.length;continue}if("emoji"===o.kind){const{full:t,groups:n}=o,i=`:${n[0]}:`,a=e.resolveEmoji?.(i);s.push({type:"emoji",attrs:a?{shortName:a.shortName,text:a.text}:{shortName:i}}),r=o.index+t.length;continue}}return(t=>{const e=[];for(const r of t){const t=e[e.length-1];"text"!==r.type||"text"!==t?.type||t.marks||r.marks?e.push(r):t.text=(t.text??"")+(r.text??"")}return e})(s)}function _t(t,e,r){t.lastIndex=r;const s=t.exec(e);if(!s)return null;const n=t.source.includes("@")?"mention":"emoji";return{index:s.index,full:s[0],groups:s.slice(1),kind:n}}function Dt(t,e){return t?e&&t.index>e.index?e:t:e}function Pt(t){const e=(t.children??[])[0];return"text"===e?.type?(e.value??"")+"":"paragraph"===e?.type?((e.children??[]).map(t=>"text"===t.type?(t.value??"")+"":"").join("")||"")+"":""}function Rt(t){const e=((t??"")+"").toLowerCase().trim();return e?"info"===e||"note"===e||"success"===e||"warning"===e||"error"===e?e:"danger"===e?"error":null:null}function $t(t){const e=((t??"")+"").toLowerCase().trim();return!e||"neutral"!==e&&"green"!==e&&"yellow"!==e&&"red"!==e&&"blue"!==e&&"purple"!==e?null:e}function Mt(t,e){const r=[];for(const s of t??[])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 t=(s.url??"")+"",n=qt(s.children??[],t),i=Ht(s,0,e);if(i){"inline"===i.type?r.push(i.node):r.push({type:"text",text:n,marks:[{type:"link",attrs:{href:t}}]});continue}if(e.enableSmartCards&&Bt(n,t)){r.push({type:"inlineCard",attrs:{url:t}});continue}r.push({type:"text",text:n,marks:[{type:"link",attrs:{href:t}}]});continue}if("textDirective"===s.type&&"status"===s.name){const t=Pt(s)||"Status",e=$t(s.attributes?.color)??"neutral";r.push({type:"status",attrs:{text:t,color:e}});continue}if("textDirective"===s.type&&"emoji"===s.name){const t=Wt(s);r.push(Lt(t,e));continue}}else r.push({type:"hardBreak"});else r.push({type:"text",text:(s.value??"")+"",marks:[{type:"code"}]});else r.push(...Ft(Mt(s.children??[],e),{type:"strike"}));else r.push(...Ft(Mt(s.children??[],e),{type:"em"}));else r.push(...Ft(Mt(s.children??[],e),{type:"strong"}));else r.push(...Jt((s.value??"")+"",e));return r.filter(t=>!("text"===t.type&&""===(t.text??"")))}function Ft(t,e){return t.map(t=>{if("text"!==t.type)return t;const r=t.marks?[...t.marks,e]:[e];return{...t,marks:r}})}function qt(t,e){const r=[];for(const e of t??[])"text"===e.type||"inlineCode"===e.type?r.push((e.value??"")+""):"emphasis"!==e.type&&"strong"!==e.type&&"delete"!==e.type||r.push(qt(e.children??[],""));return r.join("")||e}function Bt(t,e){const r=(t??"").trim(),s=(e??"").trim();return r===s&&/^https?:\/\//i.test(s)}function Wt(t){return(t.children??[]).map(t=>"text"===t.type?(t.value??"")+"":"").join("").trim()||""}function Lt(t,e){const r=t.startsWith(":")?t:`:${t}:`,s=e.resolveEmoji?.(r);return s?{type:"emoji",attrs:{shortName:s.shortName,text:s.text}}:{type:"emoji",attrs:{shortName:r}}}function Ut(t){return t?"string"==typeof t?t:"text"===t.type||"inlineCode"===t.type?(t.value??"")+"":Array.isArray(t.children)?t.children.map(Ut).join(""):"":""}function Kt(t,e){if(!t?.type)return null;if((t=>"containerDirective"===t?.type&&"panel"===t?.name)(t))return((t,e)=>{const r=t.attributes??{},s=Rt(r.type)??"info",n="string"==typeof r.title?r.title:void 0,i=(t.children??[]).map(t=>Kt(t,e)).flat().filter(Boolean);return{type:"panel",attrs:{panelType:s,...n?{panelType:s,title:n}:{panelType:s}},content:i.length?i:[{type:"paragraph",content:[]}]}})(t,e);switch(t.type){case"heading":return{type:"heading",attrs:{level:Yt(t.depth??1,1,6)},content:Mt(t.children??[],e)};case"paragraph":return(t=>{const e=t.children??[];if(1!==e.length)return null;const r=e[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})(t)||{type:"paragraph",content:Mt(t.children??[],e)};case"blockquote":return{type:"blockquote",content:(t.children??[]).map(t=>Kt(t,e)).flat().filter(Boolean)};case"list":return((t,e)=>e.enableTaskLists&&(t.children??[]).some(t=>"boolean"==typeof t.checked)?((t,e)=>{const r=[];let s=0;for(const n of t.children??[]){if("boolean"!=typeof n.checked)continue;s+=1;const t=(n.children??[]).map(t=>Kt(t,e)).flat().filter(Boolean);r.push({type:"taskItem",attrs:{localId:"task-"+s,state:n.checked?"DONE":"TODO"},content:t.length?t:[{type:"paragraph",content:[]}]})}return{type:"taskList",content:r}})(t,e):{type:t.ordered?"orderedList":"bulletList",content:(t.children??[]).map(t=>((t,e)=>{const r=(t.children??[]).map(t=>Kt(t,e)).flat().filter(Boolean);return{type:"listItem",content:r.length?r:[{type:"paragraph",content:[]}]}})(t,e))})(t,e);case"code":{const r=((t,e)=>{const r=(t??"").toString().trim().toLowerCase();return r?e.enableMermaid&&"mermaid"===r?"mermaid":(t=>{const e=t.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"}[e]??e})(r):null})(t.lang,e);return{type:"codeBlock",attrs:{language:r},content:[{type:"text",text:(t.value??"")+""}]}}case"thematicBreak":return{type:"rule"};case"table":return((t,e)=>({type:"table",content:(t.children??[]).map((t,r)=>({type:"tableRow",content:(t.children??[]).map(t=>({type:0===r?"tableHeader":"tableCell",content:[{type:"paragraph",content:Mt(t.children??[],e)}]}))}))}))(t,e);case"leafDirective":return"status"===t.name?(t=>{const e=$t((t.attributes??{}).color)??"neutral";return{type:"paragraph",content:[{type:"status",attrs:{text:Pt(t)||"Status",color:e}}]}})(t):"panel"===t.name?((t,e)=>{const r=t.attributes??{},s=Rt(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:Mt([{type:"text",value:Pt(t)}],e)}]}})(t,e):zt(t,e);default:return zt(t,e)}}function zt(t,e){if("drop"===e.unknownNodeStrategy)return null;const r=Ut(t);return r?{type:"paragraph",content:[{type:"text",text:r}]}:null}function Yt(t,e,r){const s=Number.isFinite(t)?Math.trunc(t):e;return Math.max(e,Math.min(r,s))}const Gt={resolveMention:void 0,resolveAttachment:void 0,resolveEmoji:void 0,enableSmartCards:!0,enableMermaid:!0,enableEmojiShortcodes:!0,enableAtMentions:!0,enableTaskLists:!0,unknownNodeStrategy:"text"};function Zt(t,e={}){const r={...Gt,...e},s=t??"",n=J().use(P).use(D).use(_),i=n.parse(s),o=n.runSync(i);return Vt(o),((t,e)=>{const r=[];for(const s of t.children??[]){const t=Kt(s,e);t&&(Array.isArray(t)?r.push(...t):r.push(t))}return((t,e)=>{if(!e.enableSmartCards)return t;const r=t.content.map(t=>(t=>{if("paragraph"!==t.type)return t;const e=t.content??[];if(1!==e.length)return t;const r=e[0];if("inlineCard"!==r?.type)return t;const s=r.attrs?.url;return s?[{type:"blockCard",attrs:{url:s}}]:t})(t)).flat();return{...t,content:r}})({version:1,type:"doc",content:r},e)})(o,r)}function Vt(t){if(!t||!Array.isArray(t.children))return;const e=[];for(const r of t.children)"definition"!==r?.type&&("html"!==r?.type?(Vt(r),e.push(r)):e.push({type:"text",value:(r.value??"")+""}));t.children=e}const Qt=j.object({issueId:j.string().min(1),transitionId:j.union([j.string(),j.number()]),fields:j.record(j.any()).optional(),update:j.record(j.array(j.object({set:j.any().optional(),add:j.any().optional(),remove:j.any().optional()}))).optional(),comment:j.string().optional()}),Xt={name:"jira.issue-transition",inputSchema:Qt,runTool:async(t,e)=>{try{const r=Qt.parse(e),s={id:r.transitionId};r.fields&&(s.fields=r.fields),r.update&&(s.update=r.update),r.comment&&(s.comment={body:Zt(r.comment)});const n=await t.issues.transition({issueId:r.issueId,transition:s});return n?.data??n}catch(t){throw kt(t)}}},te=j.object({issueId:j.string().min(1),fields:j.record(j.any()).optional(),update:j.record(j.array(j.object({set:j.any().optional(),add:j.any().optional(),remove:j.any().optional(),edit:j.any().optional()}))).optional(),properties:j.array(j.any()).optional(),notifyUsers:j.boolean().optional().default(!0),issueTemplateId:j.string().optional(),overrideScreenSecurity:j.boolean().optional().default(!1),overrideEditableFlag:j.boolean().optional().default(!1)}),ee={name:"jira.issue-update",inputSchema:te,runTool:async(t,e)=>{try{const r=te.parse(e),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 t.issues.update(s);return n?.data??n}catch(t){throw kt(t)}}},re=j.object({issueId:j.string().min(1),assignee:j.union([j.string(),j.object({accountId:j.string().min(1)}),j.object({accountType:j.string().min(1)})])}),se={name:"jira.assign-issue",inputSchema:re,runTool:async(t,e)=>{try{const r=re.parse(e);let s;s="string"==typeof r.assignee?{accountId:r.assignee}:r.assignee;const n=await t.issues.assign({issueId:r.issueId,assignee:s});return n?.data??n}catch(t){throw kt(t)}}},ne=j.object({issueId:j.string().min(1)}),ie={name:"jira.unassign-issue",inputSchema:ne,runTool:async(t,e)=>{try{const r=ne.parse(e),s=await t.issues.assign({issueId:r.issueId,assignee:{accountId:"-1"}});return s?.data??s}catch(t){throw kt(t)}}},oe=j.object({issueId:j.string().min(1),body:j.string().min(1),visibility:j.object({type:j.enum(["role","group"]),value:j.string().min(1)}).optional()}),ae={name:"jira.comment-add",inputSchema:oe,runTool:async(t,e)=>{try{const r=oe.parse(e),s={body:Zt(r.body)};r.visibility&&(s.visibility=r.visibility);const n=await t.issues.addComment({issueId:r.issueId,comment:s});return n?.data??n}catch(t){throw kt(t)}}},ce=j.object({issueId:j.string().min(1),start:j.number().optional().default(0),maxResults:j.number().optional().default(50),orderBy:j.string().optional(),expand:j.string().optional()}),pe={name:"jira.comment-list",inputSchema:ce,runTool:async(t,e)=>{try{const r=ce.parse(e),s=await t.issues.getComments({issueId:r.issueId,start:r.start,maxResults:r.maxResults,orderBy:r.orderBy,expand:r.expand});return s?.data??s}catch(t){throw kt(t)}}},le=j.object({link:j.object({relationship:j.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:j.object({id:j.string().optional(),key:j.string().optional()}),outwardIssue:j.object({id:j.string().optional(),key:j.string().optional()}),comment:j.object({body:j.string().optional(),visibility:j.object({type:j.enum(["role","group"]),value:j.string().min(1)}).optional()}).optional()})}),ue={name:"jira.link-create",inputSchema:le,runTool:async(t,e)=>{try{const r=le.parse(e).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=Zt(r.comment.body)),r.comment.visibility&&(s.visibility=r.comment.visibility));const n=await t.issues.link(s);return n?.data??n}catch(t){throw kt(t)}}},de=j.object({issueId:j.string().min(1),file:j.string().min(1),mimeType:j.string().optional(),comment:j.string().optional()}),me={name:"jira.attach",inputSchema:de,runTool:async(t,e)=>{try{const r=de.parse(e),n=i.resolve(r.file),o=await s.readFile(n),a=i.basename(n),c=await t.issues.addAttachment({issueId:r.issueId,file:{name:a,content:o,mimeType:r.mimeType??"application/octet-stream"},comment:r.comment});return c?.data??c}catch(t){if(t&&t.code&&"string"==typeof t.code&&["ENOENT","EACCES"].includes(t.code))throw Error("Attachment file error: "+t.message);throw kt(t)}}},he=j.object({issueId:j.string().min(1)}),fe={name:"jira.attachment-list",inputSchema:he,runTool:async(t,e)=>{try{const r=he.parse(e),s=await t.issues.getAttachments({issueId:r.issueId});return s?.data??s}catch(t){throw kt(t)}}},ye=j.object({issueId:j.string().min(1),attachmentId:j.string().min(1)}),ge={name:"jira.attachment-delete",inputSchema:ye,runTool:async(t,e)=>{try{const r=ye.parse(e);return await t.issues.deleteAttachment({issueId:r.issueId,attachmentId:r.attachmentId}),{success:!0,message:`Attachment ${e.attachmentId} deleted successfully`}}catch(t){throw kt(t)}}},be=j.object({issueId:j.string().min(1),timeSpent:j.string().min(1),comment:j.string().optional(),author:j.object({accountId:j.string().min(1)}).optional(),startingOn:j.string().optional(),artifact:j.string().optional()}),ve={name:"jira.worklog-add",inputSchema:be,runTool:async(t,e)=>{try{const r=be.parse(e),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 t.issues.addWorklog({issueId:r.issueId,...s});return n?.data??n}catch(t){throw kt(t)}}},we={[Ct.name]:{title:"Jira Issue Read",description:"Read a Jira issue with expandable fields and properties",annotations:{readOnlyHint:!0,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1}},[ee.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}},[Nt.name]:{title:"Jira Issue Delete",description:"Delete a Jira issue and optionally remove its subtasks",annotations:{readOnlyHint:!1,destructiveHint:!0,idempotentHint:!1,openWorldHint:!0}},[Xt.name]:{title:"Jira Issue Transition",description:"Transition a Jira issue while optionally adding a comment",annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!1,openWorldHint:!0}},[se.name]:{title:"Jira Issue Assign",description:"Assign a Jira issue to a user or account",annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!1,openWorldHint:!0}},[ie.name]:{title:"Jira Issue Unassign",description:"Unassign the current owner from a Jira issue",annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!1,openWorldHint:!0}},[ae.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}},[pe.name]:{title:"Jira Comment List",description:"List comments on a Jira issue with pagination support",annotations:{readOnlyHint:!0,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1}},[ue.name]:{title:"Jira Link Create",description:"Create an issue link relationship with optional comment",annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!1,openWorldHint:!0}},[me.name]:{title:"Jira Attachment Add",description:"Attach a local file to a Jira issue",annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!1,openWorldHint:!0}},[fe.name]:{title:"Jira Attachment List",description:"List attachments on a Jira issue",annotations:{readOnlyHint:!0,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1}},[ge.name]:{title:"Jira Attachment Delete",description:"Delete an attachment from a Jira issue",annotations:{readOnlyHint:!1,destructiveHint:!0,idempotentHint:!1,openWorldHint:!0}},[ve.name]:{title:"Jira Worklog Add",description:"Log time spent on a Jira issue",annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!1,openWorldHint:!0}}};async function Se(t){const e=c.for(Se);let r,s=null;try{r=(()=>{let t;try{const e=require("jira.js");t=e?.Version3Client||e.default?.Version3Client||e.default||e}catch(t){throw Error("Unable to require 'jira.js' \u2014 ensure it is installed as a dependency: "+t)}const{host:e,email:r,apiKey:s}=(()=>{const t=xt(),e=It().filter(t=>t.required&&!t.value);if(e.length>0)throw new Et(e);return{host:t.host,email:t.email,apiKey:t.apiKey}})();return new t({host:e,authentication:{basic:{email:r,apiToken:s}}})})()}catch(t){if(!(t instanceof Et))return void e.warn("Skipping Jira tool registration; unable to create Jira client",{error:t});s=t,e.warn("Registering Jira tools without credentials; each tool will report configuration requirements.",{error:t})}const n=[Ct,ee,Nt,Xt,se,ie,ae,pe,ue,me,fe,ge,ve];for(const i of n){const n=we[i.name];if(n)try{await t.registerTool(i.name,{title:n.title,description:n.description,inputSchema:et(i.inputSchema),annotations:n.annotations},async t=>{if(!r)throw s??Error("Jira client unavailable because credentials could not be loaded.");return i.runTool(r,t)}),e.info("Registered Jira tool "+i.name)}catch(t){e.error("Failed to register Jira tool "+i.name,{error:t})}}}async function je(t){await(async t=>{t.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 t=yt.map(t=>t.getName()).sort();return{content:[{type:"text",text:["Name: "+jt.name,"Title: "+jt.title,"Version: "+jt.version,"Prompts: "+(t.join(", ")||"<none>")].join("\n")}]}})})(t);const e=c.for(je);try{await Se(t)}catch(t){e.error("Failed to register Jira tools",t)}}class xe extends V{setCb(t){return this.cb=t,this}setConfig(t){return this.config=t,this}setUriOtTemplate(t){return this.uriOrTemplate=t,this}constructor(t){super(t)}static get builder(){return new xe}build(t){const e=this.hasErrors();if(e)throw Error(e.toString());try{const e="string"==typeof this.uriOrTemplate&&this.uriOrTemplate.includes("{")?new $(new R(this.uriOrTemplate),{list:void 0}):this.uriOrTemplate,r=Object.assign(this.config,{_meta:{}}),s=async(t,e)=>{const r=this.logFor(e);r.verbose(`Requesting resource ${this.name} from ${t.toString()}`);const s=await Promise.resolve(this.cb(t,e));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 c.for(this).error("Error registering resource "+this.name,t),t}}}y([b(),g("design:type",String)],xe.prototype,"uriOrTemplate",void 0),y([b(),g("design:type",Function)],xe.prototype,"cb",void 0),y([b(),g("design:type",Object)],xe.prototype,"config",void 0);const Ie=it()??n.join(__dirname,"..","assets"),Ae=n.join(Ie,"templates"),Ee=n.join(Ie,"prompts"),ke=new WeakMap;class Te extends p{get client(){const t=ke.get(this);if(!t)throw Error("Mcp server requires Mcp client");return t}constructor(){super()}async load(){const t=this.log.for(this.load);for(const e of yt)try{t.info("loading prompt "+e.getName());const r=e.build(this.client);t.verbose(`Loaded prompt ${r.title} from ${e.getName()} definition`)}catch(r){t.error("Failed to load prompt "+e.getName(),r)}try{await je(this.client),t.verbose("Registered built-in tools")}catch(e){t.error("Failed to register tools",e)}try{await(async(t,r)=>{r.info("Registering agent templates as resources...");const s=e.readdirSync(Ae).filter(t=>t.endsWith(".md"));for(const i of s){const s=n.basename(i,".md"),o=n.join(Ae,i),a=xe.builder.setName(s).setTitle("Template: "+s).setDescription("Resource template for "+s).setUriOtTemplate("file:///"+o).setConfig({mimeType:"text/markdown",description:"Template for "+s}).setCb(async t=>{const r=e.readFileSync(t.pathname,"utf8");return{contents:[{uri:t.toString(),text:r,mimeType:"text/markdown"}],_meta:{}}});try{a.build(t),r.info("Registered template: "+s)}catch(t){r.error(`Failed to register template ${s}:`,t)}}r.info("Registering agent prompts...");const i=e.readdirSync(Ee).filter(t=>t.endsWith(".md"));for(const s of i){const i=n.basename(s,".md"),o=n.join(Ee,s),a=e.readFileSync(o,"utf8"),c=at.builder.setName(i).setTitle("Prompt: "+i).setDescription("Dynamic prompt for "+i).setArgsSchema(j.object({})).setCb(async t=>({messages:[{role:"user",content:{type:"text",text:a}}],_meta:{}}));try{c.build(t),r.info("Registered prompt: "+i)}catch(t){r.error(`Failed to register prompt ${i}:`,t)}}})(this.client,t),t.verbose("Registered agent-specific assets")}catch(e){t.error("Failed to register agent assets",e)}}async boot(t="stdio"){let r=this.log;this.log.for(this.boot).info("McpServer booting..."),((t=c.get())=>{let r;try{r=(()=>{let t,r=__dirname;try{for(;r&&r!==n.parse(r).root;){const s=n.join(r,"node_modules");if(e.existsSync(s)&&e.statSync(s).isDirectory()){t=s;break}const i=n.dirname(r);if(i===r)break;r=i}}catch{}const s=[];if(t){const r=n.join(t,"@decaf-ts");try{if(e.existsSync(r)&&e.statSync(r).isDirectory()){const t=e.readdirSync(r);for(const i of t){const t=n.join(r,i);try{const r=n.join(t,"workdocs","assets","slogans.json");if(e.existsSync(r)&&e.statSync(r).isFile()){const t=e.readFileSync(r,"utf-8"),n=JSON.parse(t);if(Array.isArray(n))for(const t of n)"string"==typeof t&&t.trim().length>0&&s.push(t.trim())}}catch{}}}}catch{}}return 0===s.length?"Decaf: strongly brewed TypeScript.":s[Math.floor(Math.random()*s.length)]})()}catch{r="Decaf: strongly brewed TypeScript."}const s="# \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=s.reduce((t,e)=>Math.max(t,e.length),0);s.push("# "+r.padStart(i-3)),s.forEach((e,r)=>{const s=U[r%U.length]||"",n=t.info.bind(t);try{n(f(e||"").raw(s).text)}catch{n((e||"")+"")}})})(this.log),"stdio"===t&&(c.setFactory(L),r=c.for(this.constructor.name));const s=((Array.isArray(jt.icons)?jt.icons:[jt.icons])||[]).map(t=>{const e="string"==typeof t?.src?t.src:(t?.src??"")+"",r="string"==typeof t?.mimeType?t.mimeType:(t?.mimeType??"")+"";let s=[];return Array.isArray(t?.sizes)?s=t.sizes.map(t=>t+""):"string"==typeof t?.sizes&&(s=(t.sizes+"").split(",").map(t=>t.trim())),{src:e,mimeType:r,sizes:s}}),i={name:jt.name,title:jt.title,websiteUrl:jt.websiteUrl,version:jt.version,icons:s},o=new M(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(((t,e)=>{ke.set(t,e)})(this,o),o.onerror=t=>{this.log.error("MCP instance onerror",t)},t){case"stdio":t=new q;break;case"http":t=new B({sessionIdGenerator:()=>F(),onsessioninitialized:t=>r.verbose("Session initialized: "+t),onsessionclosed:t=>r.verbose("Session closed: "+t),enableJsonResponse:!0,eventStore:void 0});break;default:if(!(a=t)||"object"!=typeof a||"function"!=typeof a.send&&"function"!=typeof a.close&&"function"!=typeof a.on)throw new T("Invalid transport type: "+t)}var a;try{this.log.info("Loading resources/prompts/tools..."),await this.load()}catch(t){throw this.log.error("Error loading resources/prompts/tools: "+t),t}await this.client.connect(t),r.info(`MCP Server connected via ${t.constructor.name} and running. Waiting for client connections...`)}}const Ne=(new t).command("start").option("--transport [String]","transport mode","stdio").description("starts decaf's mcp server").action(async t=>{const e=JSON.parse(r.readFileSync(i.join(process.cwd(),"package.json"),"utf-8")),s=e.version,{transport:n}=t,o=(new W).for("mcp-server");if("stdio"!==n)throw Error("Unsupported transport mode: "+n);return o.info("Transport stdio"),o.debug(`running with options: ${JSON.stringify(t)} for ${e.name} version ${s}`),(new Te).boot(n)});(new t).command("md-to-ast").description("pipes markdown to jira ast: `cat file.md` | npx decaf-mcp md-to-ast > ast.json").action(async t=>{const e=JSON.parse(r.readFileSync(i.join(process.cwd(),"package.json"),"utf-8")),s=e.version;c.for("md-to-ast").debug(`running with options: ${JSON.stringify(t)} for ${e.name} version ${s}`);const n=Zt(await(async()=>{const t=[];for await(const e of process.stdin)t.push(Buffer.from(e));return Buffer.concat(t).toString("utf8")})(),{resolveMention:t=>({id:t,text:"@"+t}),resolveAttachment:t=>({id:t,collection:"attachments"})});process.stdout.write(JSON.stringify(n,null,2)+"\n")});const Oe=(new t).name("mcp-server").command("mcp-server").description("decaf mcp server and agentic functionality");Oe.addCommand(Ne),Oe.parse(process.argv);
|
|
1
|
+
import{Command as t}from"commander";import*as e from"fs";import r,{promises as s}from"fs";import{MiniLogger as n,NumericLogLevels as i,Logging as o,LoggedClass as a,toSnakeCase as c,sf as p,toPascalCase as l,LogLevel as u,LoggedEnvironment as d}from"@decaf-ts/logging";import{style as m}from"styled-string-builder";import*as h from"path";import f from"path";import{__decorate as y,__metadata as g}from"tslib";import{required as b,Model as v,list as w,minlength as S}from"@decaf-ts/decorator-validation";import{z as j,ZodObject as x}from"zod";import{injectable as I,inject as k}from"@decaf-ts/injectable-decorators";import{prop as A,Metadata as E}from"@decaf-ts/decoration";import{InternalError as T,SerializationError as N,ValidationError as O}from"@decaf-ts/db-decorators";import C from"crypto";import H from"zlib";import{fileURLToPath as J}from"url";import{unified as _}from"unified";import D from"remark-directive";import P from"remark-gfm";import R from"remark-parse";import{UriTemplate as $}from"@modelcontextprotocol/sdk/shared/uriTemplate.js";import{ResourceTemplate as M,McpServer as F}from"@modelcontextprotocol/sdk/server/mcp.js";import{v4 as q}from"uuid";import{StdioServerTransport as B}from"@modelcontextprotocol/sdk/server/stdio.js";import{StreamableHTTPServerTransport as W}from"@modelcontextprotocol/sdk/server/streamableHttp.js";class L extends n{log(t,e,r,s){const n=this.config("level");i[n],i[t]}}const U=(t,e,...r)=>{const s=(t=>{if("string"==typeof t)return t;if(!t)return"unknown";if("function"==typeof t)return t.name||"unknown";if("object"==typeof t&&"constructor"in t){const e=t.constructor;if(e&&e.name)return e.name}return"unknown"})(t);return new L(s,e)},K=["\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 z,Y,G,Z,V;(t=>{t[t.NONE=0]="NONE",t[t.BASIC=1]="BASIC",t[t.ADVANCED=2]="ADVANCED",t[t.HIGH=3]="HIGH"})(z||(z={})),(t=>{t[t.NONE=0]="NONE",t[t.LOW=1]="LOW",t[t.MEDIUM=2]="MEDIUM",t[t.HIGH=3]="HIGH"})(Y||(Y={})),(t=>{t[t.FREE=0]="FREE",t[t.LOW=1]="LOW",t[t.MEDIUM=2]="MEDIUM",t[t.HIGH=3]="HIGH"})(G||(G={}));class Q extends v{get log(){return this._log||(this._log=o.for(this)),this._log}constructor(t){super(t)}logFor(t){const{sessionId:e,requestId:r,authInfo:s}=t||{};let n="string"==typeof e&&e.length>0?this.log.for(e):this.log;return s&&s.clientId&&(n=n.for(s.clientId)),r&&(n=n.for(r.toString())),n}setDescription(t){return this.description=t,this}getDescription(){return this.description}setName(t){return this.name=t,this}getName(){return this.name}setTitle(t){return this.title=t,this}}y([b(),g("design:type",String)],Q.prototype,"description",void 0),y([b(),g("design:type",String)],Q.prototype,"name",void 0),y([b(),g("design:type",String)],Q.prototype,"title",void 0);class X extends Q{constructor(t){super(t),this.reasoning=z.NONE,this.effort=Y.NONE,this.cost=G.FREE}setReasoning(t){return this.reasoning=t,this}setEffort(t){return this.effort=t,this}setCost(t){return this.cost=t,this}}function tt(t){if(!t)return;let e=t,r=e&&e._def;for(;r&&"ZodObject"!==r.typeName;){if("ZodEffects"===r.typeName&&r.schema)e=r.schema;else if("ZodOptional"===r.typeName&&r.innerType)e=r.innerType;else if("ZodDefault"===r.typeName&&r.innerType)e=r.innerType;else if("ZodNullable"===r.typeName&&r.innerType)e=r.innerType;else{if(!r.schema)return;e=r.schema}r=e&&e._def}return r&&"ZodObject"===r.typeName?r:void 0}function et(t,e="schema"){if(tt(t))return t;if(t&&"object"==typeof t){const e=t.def&&"object"==typeof t.def?t.def:void 0,r=e&&(e.shape||"object"===e.type)&&e.shape||("object"===t.type?t.shape:void 0)||(e&&"object"===e.type?{}:void 0);if(e||"object"===t.type||r){const t={};if(r&&"object"==typeof r)for(const[e,s]of Object.entries(r))t[e]=st(s)?s:j.any();return j.object(t)}}throw Error(`Registration error: provided a non-canonical ${e}. Export a ZodObject (z.object(...)).`)}function rt(t){if(!t)return;if(t&&"object"==typeof t&&!t._def)return t.def&&"object"==typeof t.def&&t.def.shape?t.def.shape:t;const e=tt(t);return e?"function"==typeof e.shape?e.shape():e.shape||void 0:void 0}function st(t){return!(!t||"object"!=typeof t||!t._def)}y([b(),g("design:type",Number)],X.prototype,"reasoning",void 0),y([b(),g("design:type",Number)],X.prototype,"effort",void 0),y([b(),g("design:type",Number)],X.prototype,"cost",void 0),(t=>{t.ASSETS="assets"})(Z||(Z={})),(t=>{t.PROMPT="prompts",t.DOCUMENTATION="documentation",t.CODE="code"})(V||(V={}));const nt=Buffer.from("DCAF1","ascii");function it(t){let e=f.resolve(t);for(;;){if(r.existsSync(f.join(e,"package.json")))return e;const t=f.dirname(e);if(t===e)break;e=t}}const ot=process.argv?.[1]?it(f.dirname(f.resolve(process.argv[1]))):void 0,at=(()=>{const t=Error().stack;if(!t)return;const e=t.split(/\r?\n/).slice(1);for(const t of e){const e=t.match(/\(?([^()]+?):\d+:\d+\)?/);if(!e)continue;let r=e[1];if(r.startsWith("file://"))try{r=J(r)}catch{continue}if(!r.includes("node:internal"))return f.dirname(r)}})(),ct=at?it(at):void 0,pt=ot??ct??process.cwd();function lt(...t){return f.join(pt,...t)}function ut(t){let r=t;for(;;){const t=h.join(r,"lib","assets");if(e.existsSync(t))return t;const s=h.join(r,"src","assets");if(e.existsSync(s))return s;const n=h.join(r,"assets");if(e.existsSync(n))return n;const i=h.dirname(r);if(i===r)break;r=i}}function dt(){const t=process.env.DECAF_ASSET_DIR||process.env.MCP_ASSET_DIR||process.env.ASSET_DIR||"";if(t&&e.existsSync(t))return t;const r=ut(__dirname);if(r)return r;const s=process.argv?.[1];if(s){const t=ut(h.dirname(s));if(t)return t}const n=[pt,process.env.INIT_CWD].filter(Boolean);for(const t of n){const e=ut(t);if(e)return e}return lt("assets")}let mt=class extends a{constructor(t){super(),this.basePath=t||dt()}listAssets(...t){const r=h.join(this.basePath,...t);return e.readdirSync(r)}listPrompts(){return this.listAssets(V.PROMPT)}getAsset(t,r="md",...s){const n=h.join(this.basePath,...s),i=(t,r=!1)=>{try{return r?(t=>{if(t.length<nt.length+16+12+16)throw Error("Invalid prompt payload (too short)");if(!t.subarray(0,nt.length).equals(nt))throw Error("Invalid prompt payload (bad magic)");const e=process.env.ENCRYPTION_KEY||"";if(!e)throw Error("Missing encryption key. Set ENCRYPTION_KEY to load obfuscated assets.");let r=nt.length;const s=t.subarray(r,r+16);r+=16;const n=t.subarray(r,r+12);r+=12;const i=t.subarray(r,r+16);r+=16;const o=t.subarray(r),a=((t,e)=>C.scryptSync(t,e,32))(e,s),c=C.createDecipheriv("aes-256-gcm",a,n);c.setAuthTag(i);const p=Buffer.concat([c.update(o),c.final()]);return H.gunzipSync(p)})(e.readFileSync(t)).toString("utf-8"):e.readFileSync(t,"utf-8")}catch(t){if("ENOENT"===t.code)return null;throw t}},o=i(h.join(n,`${t}.${r}`),"enc"===r);if(null!==o)return o;const a=i(h.join(n,t+".enc"),!0);if(null!==a)return a;throw Error("Asset not found: "+h.join(n,`${t}.${r}`))}getAllAssets(t,...e){return this.listAssets(t,...e).reduce((r,s)=>{const n=h.extname(s),i=h.basename(s,n),o=n.replace(/^\./,"")||void 0;return r[i]=this.getAsset(i,o??void 0,t,...e),r},{})}toPromptDef(t){const e=t=>"number"==typeof t?t:"string"==typeof t?(t=>{switch(t){case"none":return z.NONE;case"basic":return z.BASIC;case"advanced":return z.ADVANCED;case"high":return z.HIGH;case"medium":return Y.MEDIUM;case"low":return G.LOW;case"free":return G.FREE;default:throw new T("Cannon convert unknown level "+t)}})(t.toLowerCase()):z.NONE;return t.effort=e(t.effort),t.reasoning=e(t.reasoning),t.cost=e(t.cost),t}getPrompt(t,...e){const r=this.getAsset(c(t),"json",V.PROMPT,...e);let s;try{s=JSON.parse(r)}catch(r){throw new N(`Failed to parse prompt ${t} in categories ${e}: ${r}`)}return this.toPromptDef(s)}getAllPrompts(...t){const e=this.getAllAssets(V.PROMPT,...t);return Object.entries(e).reduce((e,[r,s])=>{try{e[r]=JSON.parse(s)}catch(e){throw new N(`Failed to parse prompt ${r} in categories ${t}: ${e}`)}return e},e)}};mt=y([I(),g("design:paramtypes",[String])],mt);class ht extends X{constructor(t){super(t)}setCb(t){return this.cb=t,this}setArgsSchema(t){return this.argsSchema=t,this}static get builder(){return new ht}static patchPrompt(t,e,r,s){const n=(e=Array.isArray(e)?e:Object.keys(e)).filter(t=>!Object.prototype.hasOwnProperty.call(r,t));if(n.length)throw new O("Missing replacements for placeholders: "+n.join(", "));s&&(s.verbose("Patching prompt with placeholders: "+JSON.stringify(e)),s.debug("Values: "+JSON.stringify(r)));const i=e.reduce((t,e)=>(t[e]=r[e],t),{});return p(t,i)}patchPrompt(t,e,r,s){return ht.patchPrompt(t,e,r,s||this.log.for(this.patchPrompt))}build(t,e){const r=this.log.for(this.build),s=this.hasErrors();if(s)throw new O(s.toString());try{this.argsSchema&&et(this.argsSchema,"argsSchema");const r=rt(this.argsSchema);return t.registerPrompt(this.name,{title:this.title,description:this.description,argsSchema:r},async(t,r)=>{const s=this.logFor(r);t=Object.assign({},e,t||{}),s.verbose(`Executing prompt ${this.name} with args: ${JSON.stringify(t)}`),t._meta=Object.assign(t._meta||{},{usage:{reasoning:this.reasoning,effort:this.effort,cost:this.cost}});const n=await Promise.resolve(this.cb(t,r));return s.verbose(`Prompt ${this.name} executed successfully.`),s.debug("Prompt execution meta: "+JSON.stringify(n._meta)),n})}catch(t){throw r.error("Failed to register prompt "+(this.name||this.constructor.name),t),t}}}y([k(mt),g("design:type",mt)],ht.prototype,"assets",void 0),y([b(),g("design:type",Object)],ht.prototype,"cb",void 0),y([b(),g("design:type",x)],ht.prototype,"argsSchema",void 0),y([A(),g("design:type",Object)],ht.prototype,"placeholders",void 0);class ft extends ht{setCategory(t){return this.promptCategory=t,this}addPrefix(t){return this.prefixes=this.prefixes||[],this.prefixes.push(t),this}addSuffix(t){return this.suffixes=this.suffixes||[],this.suffixes.push(t),this}constructor(t){super(t)}build(t){const e=this.assets.getPrompt(this.name,this.promptCategory);v.fromObject(this,e);const r=new Set((E.properties(ft)||[]).filter(t=>!["assets","promptCategory","prefixes","suffixes"].includes(t)));["cb","argsSchema"].forEach(t=>r.add(t));const s=this.hasErrors(...Array.from(r));if(s)throw new O(s.toString());const n=(this.prefixes||[]).map(t=>this.assets.getPrompt(t,this.promptCategory)),i=(this.suffixes||[]).map(t=>this.assets.getPrompt(t,this.promptCategory)),o=[...new Set([...e.placeholders,...n.map(t=>t.placeholders||[]),...i.map(t=>t.placeholders||[])].flat())].reduce((t,e)=>(t[e]=j.string().describe("The description for "+e),t),{});return this.setArgsSchema(j.object(o)),this.setCb((t,e)=>{const r=this.logFor(e).for(ft).for(this.promptCategory).for(this.name);function s(t=[]){return Array.isArray(t)?t:Object.keys(t)}const n=(this.prefixes||[]).map(t=>this.assets.getPrompt(t,this.promptCategory)),i=(this.suffixes||[]).map(t=>this.assets.getPrompt(t,this.promptCategory)),o=this.assets.getPrompt(this.name,this.promptCategory),a=[...new Set([...n.map(t=>s(t.placeholders)).flat(),...i.map(t=>s(t.placeholders)).flat(),...s(o.placeholders).flat()])];return{messages:[{role:"user",content:{type:"text",text:this.patchPrompt([...n.map(t=>t.prompt),o.prompt,...i.map(t=>t.prompt)].join("\n\n"),a,t,r)}}],_meta:{}}}),super.build(t)}setReasoning(t){throw new T("Named prompt builders don't require callback")}setEffort(t){throw new T("Named prompt builders don't require callback")}setCost(t){throw new T("Named prompt builders don't require callback")}setDescription(t){throw new T("Named prompt builders don't require callback")}setTitle(t){throw new T("Named prompt builders don't require callback")}static get builder(){return new ft}}y([b(),g("design:type",String)],ft.prototype,"promptCategory",void 0),y([w(String),S(1),g("design:type",Array)],ft.prototype,"prefixes",void 0),y([S(1),w(String),g("design:type",Array)],ft.prototype,"suffixes",void 0);const yt=ht.builder.setName("example.prompt").setTitle("Example prompt").setDescription("Example prompt for testing").setArgsSchema(j.object({message:j.string().optional()})).setCb(async t=>{const e=t.message??"default";return{messages:[{role:"assistant",content:{type:"text",text:e}}],content:[],structuredContent:{message:e},result:{message:e}}}),gt=ht.builder.setName("interactive.jsdoc").setTitle("Interactive JSDoc prompt").setDescription("Interactive prompt for jogging JSDoc helpers").setArgsSchema(j.object({gist:j.string().optional()})).setCb(async t=>{const e=t.gist??"interactive jsdoc response";return{messages:[{role:"assistant",content:{type:"text",text:e}}],content:[],structuredContent:{message:e},result:{message:e}}}),bt=Object.assign(gt,{name:gt.getName()});var vt;function wt(t,e=[],r=[]){const s=ft.builder.setCategory(vt.DOCS).setName(t);return["prefix",...e].forEach(t=>s.addPrefix(t)),["suffix",...r].forEach(t=>s.addSuffix(t)),s}(t=>{t.DOCS="documentation",t.CODE="code"})(vt||(vt={}));const St=[wt("class"),wt("constant"),wt("decorator"),wt("function"),wt("module"),wt("file"),wt("repo",[],["iterate"])],jt=j.object({className:j.string().describe("the class name to turn into a builder")}),xt=[yt,bt,...St,ht.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(jt).setReasoning(z.BASIC).setCb((t,e)=>(t.className=l(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 It extends X{setAnnotations(t){return this.annotations=Object.assign(this.annotations,t),this}setCb(t){return this.cb=t,this}setInputSchema(t){return this.inputSchema=t,this}setOutputSchema(t){return this.outputSchema=t,this}constructor(t){super(t),this.annotations={readOnlyHint:!0,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1}}static get builder(){return new It}build(t){const e=this.hasErrors();if(e)throw Error(e.toString());try{this.inputSchema&&et(this.inputSchema,"inputSchema"),this.outputSchema&&et(this.outputSchema,"outputSchema");const e=rt(this.inputSchema),r=rt(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(t,e)=>{const r=this.logFor(e);r.verbose(`Executing tool ${this.name} with args: ${JSON.stringify(t)}`),e._meta=Object.assign(e._meta||{},{usage:{reasoning:this.reasoning,effort:this.effort,cost:this.cost}});const s=await Promise.resolve(this.cb(t,e));return r.verbose(`Tool ${this.name} executed successfully.`),r.debug("Tool execution meta: "+JSON.stringify(s._meta)),s})}catch(t){const e=t?.message||t+"";if("string"==typeof e&&e.includes("already registered"))return o.for(this).warn(`Tool ${this.name} already registered - skipping duplicate registration`),{name:this.name};throw o.for(this).error("Error building tool",t),t}}}y([b(),g("design:type",Object)],It.prototype,"annotations",void 0),y([b(),g("design:type",Object)],It.prototype,"cb",void 0),y([b(),g("design:type",Function)],It.prototype,"inputSchema",void 0);const kt=It.builder.setName("example.tool").setTitle("Example tool").setDescription("A smoke tool used for quick testing").setInputSchema(j.object({})).setCb(async()=>({content:[{type:"text",text:"example tool ok"}],result:{status:"ok"}}));Object.assign(kt,{name:kt.getName()});const At=It.builder.setName("file.summarizer").setTitle("File summarizer").setDescription("Summaries files for quick previews").setInputSchema(j.object({filePath:j.string().optional()})).setCb(async()=>({content:[{type:"text",text:"file summary stub"}],result:{summary:"file summary stub"}}));Object.assign(At,{name:At.getName()});const Et="##VERSION##";E.registerLibrary("##PACKAGE##",Et);const Tt={mcpId:"decaf",name:"decaf-ts mcp server",title:"Decaf-TS MCP Server",description:"Provides precise coding assistance for the decaf-ts framework",version:Et,websiteUrl:"https://decaf-ts.github.io",repositoryUrl:"https://github.com/decaf-ts/mcp-server",license:"AGPL-3.0",workingDir:pt,assetDir:dt(),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:u.error},Nt=d.accumulate(Tt);function Ot(){const{host:t,email:e,apiKey:r,projectKey:s,issueType:n}=Nt.jira;return{host:t?.trim(),email:e?.trim(),apiKey:r?.trim(),projectKey:s?.trim(),issueType:n?.trim(),parentIssue:Nt.jira.parentIssue?.trim()}}function Ct(){const t=Ot();return[{name:"JIRA__HOST",required:!0,description:"Atlassian host (e.g. decaf-ts.atlassian.net) where your Jira instance is hosted.",value:t.host},{name:"JIRA__EMAIL",required:!0,description:"Email address of the Jira account that has API access.",value:t.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:t.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:t.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:t.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:t.parentIssue}]}function Ht(t){const e=t.value?((t,e)=>{if(t)return e?"<configured>":t})(t.value,t.sensitive):"not set",r=t.required?"(required)":"(optional)";return`\u2022 ${t.name} ${r}: ${t.description} Current state: ${e}.`}o.setConfig(Nt);class Jt extends Error{constructor(t){const e=Ct(),r=(t=>{const e=Ct();return`${t.length?`Missing Jira credentials: ${t.map(t=>t.name).join(", ")}.`:"Jira credentials are configured."}\n\nThis setup uses the following environment variables:\n${e.map(Ht).join("\n")}`})(t);super(r),this.name="MissingJiraEnvironmentError",this.descriptors=e,this.missing=t,"function"==typeof Error.captureStackTrace&&Error.captureStackTrace(this,Jt)}}function _t(t){if(!t)return{code:"jira_error",message:"Unknown Jira error",details:{raw:t}};const e=t?.status??t?.statusCode??t?.response?.status??t?.response?.statusCode,r="number"==typeof e?e:Number(e)||void 0,s=t?.response?.data??t?.data??t?.response?.body??t?.body,n=[];"string"==typeof t?.message&&n.push(t.message),((t,e)=>{t&&(Array.isArray(t.errorMessages)&&t.errorMessages.forEach(t=>"string"==typeof t&&e.push(t)),"string"==typeof t.errorMessage&&e.push(t.errorMessage),t.errorCollection&&Array.isArray(t.errorCollection.errors)&&t.errorCollection.errors.forEach(t=>{"string"==typeof t?e.push(t):t&&"string"==typeof t.message&&e.push(t.message)}),t?.errors&&"object"==typeof t.errors&&Object.values(t.errors).forEach(t=>{"string"==typeof t?e.push(t):"string"==typeof t?.message&&e.push(t.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:t?.code??"jira_error",message:o,details:{httpStatus:r,body:s,raw:t}}}const Dt=j.object({issueId:j.string().min(1),deleteSubtasks:j.boolean().optional().default(!0)}),Pt={name:"jira.issue-delete",inputSchema:Dt,runTool:async(t,e)=>{try{const r=Dt.parse(e),s=t.issues??t.issue??t,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 ${e.issueId} deleted successfully`}}catch(t){throw _t(t)}}},Rt=j.object({issueId:j.string().min(1),expand:j.string().optional(),fields:j.array(j.string()).optional(),properties:j.array(j.string()).optional()}),$t={name:"jira.issue-read",inputSchema:Rt,runTool:async(t,e)=>{try{const r=Rt.parse(e),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 t.issues.get(s);return n?.data??n}catch(t){throw _t(t)}}};function Mt(t,e,r){const s=((t.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 Ft(t,e){if(!t)return[];if(!e.enableAtMentions&&!e.enableEmojiShortcodes)return[{type:"text",text:t}];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<t.length;){const o=Bt(e.enableAtMentions?qt(n,t,r):null,e.enableEmojiShortcodes?qt(i,t,r):null);if(!o){s.push({type:"text",text:t.slice(r)});break}if(o.index>r&&s.push({type:"text",text:t.slice(r,o.index)}),"mention"===o.kind){const{full:t,groups:n}=o,i=n[0]??"",a=n[1]??"";i&&s.push({type:"text",text:i});const c=e.resolveMention?.(a);c?s.push({type:"mention",attrs:{id:c.id,text:c.text}}):s.push({type:"text",text:"@"+a}),r=o.index+t.length;continue}if("emoji"===o.kind){const{full:t,groups:n}=o,i=`:${n[0]}:`,a=e.resolveEmoji?.(i);s.push({type:"emoji",attrs:a?{shortName:a.shortName,text:a.text}:{shortName:i}}),r=o.index+t.length;continue}}return(t=>{const e=[];for(const r of t){const t=e[e.length-1];"text"!==r.type||"text"!==t?.type||t.marks||r.marks?e.push(r):t.text=(t.text??"")+(r.text??"")}return e})(s)}function qt(t,e,r){t.lastIndex=r;const s=t.exec(e);if(!s)return null;const n=t.source.includes("@")?"mention":"emoji";return{index:s.index,full:s[0],groups:s.slice(1),kind:n}}function Bt(t,e){return t?e&&t.index>e.index?e:t:e}function Wt(t){const e=(t.children??[])[0];return"text"===e?.type?(e.value??"")+"":"paragraph"===e?.type?((e.children??[]).map(t=>"text"===t.type?(t.value??"")+"":"").join("")||"")+"":""}function Lt(t){const e=((t??"")+"").toLowerCase().trim();return e?"info"===e||"note"===e||"success"===e||"warning"===e||"error"===e?e:"danger"===e?"error":null:null}function Ut(t){const e=((t??"")+"").toLowerCase().trim();return!e||"neutral"!==e&&"green"!==e&&"yellow"!==e&&"red"!==e&&"blue"!==e&&"purple"!==e?null:e}function Kt(t,e){const r=[];for(const s of t??[])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 t=(s.url??"")+"",n=Yt(s.children??[],t),i=Mt(s,0,e);if(i){"inline"===i.type?r.push(i.node):r.push({type:"text",text:n,marks:[{type:"link",attrs:{href:t}}]});continue}if(e.enableSmartCards&&Gt(n,t)){r.push({type:"inlineCard",attrs:{url:t}});continue}r.push({type:"text",text:n,marks:[{type:"link",attrs:{href:t}}]});continue}if("textDirective"===s.type&&"status"===s.name){const t=Wt(s)||"Status",e=Ut(s.attributes?.color)??"neutral";r.push({type:"status",attrs:{text:t,color:e}});continue}if("textDirective"===s.type&&"emoji"===s.name){const t=Zt(s);r.push(Vt(t,e));continue}}else r.push({type:"hardBreak"});else r.push({type:"text",text:(s.value??"")+"",marks:[{type:"code"}]});else r.push(...zt(Kt(s.children??[],e),{type:"strike"}));else r.push(...zt(Kt(s.children??[],e),{type:"em"}));else r.push(...zt(Kt(s.children??[],e),{type:"strong"}));else r.push(...Ft((s.value??"")+"",e));return r.filter(t=>!("text"===t.type&&""===(t.text??"")))}function zt(t,e){return t.map(t=>{if("text"!==t.type)return t;const r=t.marks?[...t.marks,e]:[e];return{...t,marks:r}})}function Yt(t,e){const r=[];for(const e of t??[])"text"===e.type||"inlineCode"===e.type?r.push((e.value??"")+""):"emphasis"!==e.type&&"strong"!==e.type&&"delete"!==e.type||r.push(Yt(e.children??[],""));return r.join("")||e}function Gt(t,e){const r=(t??"").trim(),s=(e??"").trim();return r===s&&/^https?:\/\//i.test(s)}function Zt(t){return(t.children??[]).map(t=>"text"===t.type?(t.value??"")+"":"").join("").trim()||""}function Vt(t,e){const r=t.startsWith(":")?t:`:${t}:`,s=e.resolveEmoji?.(r);return s?{type:"emoji",attrs:{shortName:s.shortName,text:s.text}}:{type:"emoji",attrs:{shortName:r}}}function Qt(t){return t?"string"==typeof t?t:"text"===t.type||"inlineCode"===t.type?(t.value??"")+"":Array.isArray(t.children)?t.children.map(Qt).join(""):"":""}function Xt(t,e){if(!t?.type)return null;if((t=>"containerDirective"===t?.type&&"panel"===t?.name)(t))return((t,e)=>{const r=t.attributes??{},s=Lt(r.type)??"info",n="string"==typeof r.title?r.title:void 0,i=(t.children??[]).map(t=>Xt(t,e)).flat().filter(Boolean);return{type:"panel",attrs:{panelType:s,...n?{panelType:s,title:n}:{panelType:s}},content:i.length?i:[{type:"paragraph",content:[]}]}})(t,e);switch(t.type){case"heading":return{type:"heading",attrs:{level:ee(t.depth??1,1,6)},content:Kt(t.children??[],e)};case"paragraph":return(t=>{const e=t.children??[];if(1!==e.length)return null;const r=e[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})(t)||{type:"paragraph",content:Kt(t.children??[],e)};case"blockquote":return{type:"blockquote",content:(t.children??[]).map(t=>Xt(t,e)).flat().filter(Boolean)};case"list":return((t,e)=>e.enableTaskLists&&(t.children??[]).some(t=>"boolean"==typeof t.checked)?((t,e)=>{const r=[];let s=0;for(const n of t.children??[]){if("boolean"!=typeof n.checked)continue;s+=1;const t=(n.children??[]).map(t=>Xt(t,e)).flat().filter(Boolean);r.push({type:"taskItem",attrs:{localId:"task-"+s,state:n.checked?"DONE":"TODO"},content:t.length?t:[{type:"paragraph",content:[]}]})}return{type:"taskList",content:r}})(t,e):{type:t.ordered?"orderedList":"bulletList",content:(t.children??[]).map(t=>((t,e)=>{const r=(t.children??[]).map(t=>Xt(t,e)).flat().filter(Boolean);return{type:"listItem",content:r.length?r:[{type:"paragraph",content:[]}]}})(t,e))})(t,e);case"code":{const r=((t,e)=>{const r=(t??"").toString().trim().toLowerCase();return r?e.enableMermaid&&"mermaid"===r?"mermaid":(t=>{const e=t.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"}[e]??e})(r):null})(t.lang,e);return{type:"codeBlock",attrs:{language:r},content:[{type:"text",text:(t.value??"")+""}]}}case"thematicBreak":return{type:"rule"};case"table":return((t,e)=>({type:"table",content:(t.children??[]).map((t,r)=>({type:"tableRow",content:(t.children??[]).map(t=>({type:0===r?"tableHeader":"tableCell",content:[{type:"paragraph",content:Kt(t.children??[],e)}]}))}))}))(t,e);case"leafDirective":return"status"===t.name?(t=>{const e=Ut((t.attributes??{}).color)??"neutral";return{type:"paragraph",content:[{type:"status",attrs:{text:Wt(t)||"Status",color:e}}]}})(t):"panel"===t.name?((t,e)=>{const r=t.attributes??{},s=Lt(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:Kt([{type:"text",value:Wt(t)}],e)}]}})(t,e):te(t,e);default:return te(t,e)}}function te(t,e){if("drop"===e.unknownNodeStrategy)return null;const r=Qt(t);return r?{type:"paragraph",content:[{type:"text",text:r}]}:null}function ee(t,e,r){const s=Number.isFinite(t)?Math.trunc(t):e;return Math.max(e,Math.min(r,s))}const re={resolveMention:void 0,resolveAttachment:void 0,resolveEmoji:void 0,enableSmartCards:!0,enableMermaid:!0,enableEmojiShortcodes:!0,enableAtMentions:!0,enableTaskLists:!0,unknownNodeStrategy:"text"};function se(t,e={}){const r={...re,...e},s=t??"",n=_().use(R).use(P).use(D),i=n.parse(s),o=n.runSync(i);return ne(o),((t,e)=>{const r=[];for(const s of t.children??[]){const t=Xt(s,e);t&&(Array.isArray(t)?r.push(...t):r.push(t))}return((t,e)=>{if(!e.enableSmartCards)return t;const r=t.content.map(t=>(t=>{if("paragraph"!==t.type)return t;const e=t.content??[];if(1!==e.length)return t;const r=e[0];if("inlineCard"!==r?.type)return t;const s=r.attrs?.url;return s?[{type:"blockCard",attrs:{url:s}}]:t})(t)).flat();return{...t,content:r}})({version:1,type:"doc",content:r},e)})(o,r)}function ne(t){if(!t||!Array.isArray(t.children))return;const e=[];for(const r of t.children)"definition"!==r?.type&&("html"!==r?.type?(ne(r),e.push(r)):e.push({type:"text",value:(r.value??"")+""}));t.children=e}const ie=j.object({issueId:j.string().min(1),transitionId:j.union([j.string(),j.number()]),fields:j.record(j.any()).optional(),update:j.record(j.array(j.object({set:j.any().optional(),add:j.any().optional(),remove:j.any().optional()}))).optional(),comment:j.string().optional()}),oe={name:"jira.issue-transition",inputSchema:ie,runTool:async(t,e)=>{try{const r=ie.parse(e),s={id:r.transitionId};r.fields&&(s.fields=r.fields),r.update&&(s.update=r.update),r.comment&&(s.comment={body:se(r.comment)});const n=await t.issues.transition({issueId:r.issueId,transition:s});return n?.data??n}catch(t){throw _t(t)}}},ae=j.object({issueId:j.string().min(1),fields:j.record(j.any()).optional(),update:j.record(j.array(j.object({set:j.any().optional(),add:j.any().optional(),remove:j.any().optional(),edit:j.any().optional()}))).optional(),properties:j.array(j.any()).optional(),notifyUsers:j.boolean().optional().default(!0),issueTemplateId:j.string().optional(),overrideScreenSecurity:j.boolean().optional().default(!1),overrideEditableFlag:j.boolean().optional().default(!1)}),ce={name:"jira.issue-update",inputSchema:ae,runTool:async(t,e)=>{try{const r=ae.parse(e),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 t.issues.update(s);return n?.data??n}catch(t){throw _t(t)}}},pe=j.object({issueId:j.string().min(1),assignee:j.union([j.string(),j.object({accountId:j.string().min(1)}),j.object({accountType:j.string().min(1)})])}),le={name:"jira.assign-issue",inputSchema:pe,runTool:async(t,e)=>{try{const r=pe.parse(e);let s;s="string"==typeof r.assignee?{accountId:r.assignee}:r.assignee;const n=await t.issues.assign({issueId:r.issueId,assignee:s});return n?.data??n}catch(t){throw _t(t)}}},ue=j.object({issueId:j.string().min(1)}),de={name:"jira.unassign-issue",inputSchema:ue,runTool:async(t,e)=>{try{const r=ue.parse(e),s=await t.issues.assign({issueId:r.issueId,assignee:{accountId:"-1"}});return s?.data??s}catch(t){throw _t(t)}}},me=j.object({issueId:j.string().min(1),body:j.string().min(1),visibility:j.object({type:j.enum(["role","group"]),value:j.string().min(1)}).optional()}),he={name:"jira.comment-add",inputSchema:me,runTool:async(t,e)=>{try{const r=me.parse(e),s={body:se(r.body)};r.visibility&&(s.visibility=r.visibility);const n=await t.issues.addComment({issueId:r.issueId,comment:s});return n?.data??n}catch(t){throw _t(t)}}},fe=j.object({issueId:j.string().min(1),start:j.number().optional().default(0),maxResults:j.number().optional().default(50),orderBy:j.string().optional(),expand:j.string().optional()}),ye={name:"jira.comment-list",inputSchema:fe,runTool:async(t,e)=>{try{const r=fe.parse(e),s=await t.issues.getComments({issueId:r.issueId,start:r.start,maxResults:r.maxResults,orderBy:r.orderBy,expand:r.expand});return s?.data??s}catch(t){throw _t(t)}}},ge=j.object({link:j.object({relationship:j.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:j.object({id:j.string().optional(),key:j.string().optional()}),outwardIssue:j.object({id:j.string().optional(),key:j.string().optional()}),comment:j.object({body:j.string().optional(),visibility:j.object({type:j.enum(["role","group"]),value:j.string().min(1)}).optional()}).optional()})}),be={name:"jira.link-create",inputSchema:ge,runTool:async(t,e)=>{try{const r=ge.parse(e).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=se(r.comment.body)),r.comment.visibility&&(s.visibility=r.comment.visibility));const n=await t.issues.link(s);return n?.data??n}catch(t){throw _t(t)}}},ve=j.object({issueId:j.string().min(1),file:j.string().min(1),mimeType:j.string().optional(),comment:j.string().optional()}),we={name:"jira.attach",inputSchema:ve,runTool:async(t,e)=>{try{const r=ve.parse(e),n=f.resolve(r.file),i=await s.readFile(n),o=f.basename(n),a=await t.issues.addAttachment({issueId:r.issueId,file:{name:o,content:i,mimeType:r.mimeType??"application/octet-stream"},comment:r.comment});return a?.data??a}catch(t){if(t&&t.code&&"string"==typeof t.code&&["ENOENT","EACCES"].includes(t.code))throw Error("Attachment file error: "+t.message);throw _t(t)}}},Se=j.object({issueId:j.string().min(1)}),je={name:"jira.attachment-list",inputSchema:Se,runTool:async(t,e)=>{try{const r=Se.parse(e),s=await t.issues.getAttachments({issueId:r.issueId});return s?.data??s}catch(t){throw _t(t)}}},xe=j.object({issueId:j.string().min(1),attachmentId:j.string().min(1)}),Ie={name:"jira.attachment-delete",inputSchema:xe,runTool:async(t,e)=>{try{const r=xe.parse(e);return await t.issues.deleteAttachment({issueId:r.issueId,attachmentId:r.attachmentId}),{success:!0,message:`Attachment ${e.attachmentId} deleted successfully`}}catch(t){throw _t(t)}}},ke=j.object({issueId:j.string().min(1),timeSpent:j.string().min(1),comment:j.string().optional(),author:j.object({accountId:j.string().min(1)}).optional(),startingOn:j.string().optional(),artifact:j.string().optional()}),Ae={name:"jira.worklog-add",inputSchema:ke,runTool:async(t,e)=>{try{const r=ke.parse(e),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 t.issues.addWorklog({issueId:r.issueId,...s});return n?.data??n}catch(t){throw _t(t)}}},Ee={[$t.name]:{title:"Jira Issue Read",description:"Read a Jira issue with expandable fields and properties",annotations:{readOnlyHint:!0,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1}},[ce.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}},[Pt.name]:{title:"Jira Issue Delete",description:"Delete a Jira issue and optionally remove its subtasks",annotations:{readOnlyHint:!1,destructiveHint:!0,idempotentHint:!1,openWorldHint:!0}},[oe.name]:{title:"Jira Issue Transition",description:"Transition a Jira issue while optionally adding a comment",annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!1,openWorldHint:!0}},[le.name]:{title:"Jira Issue Assign",description:"Assign a Jira issue to a user or account",annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!1,openWorldHint:!0}},[de.name]:{title:"Jira Issue Unassign",description:"Unassign the current owner from a Jira issue",annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!1,openWorldHint:!0}},[he.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}},[ye.name]:{title:"Jira Comment List",description:"List comments on a Jira issue with pagination support",annotations:{readOnlyHint:!0,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1}},[be.name]:{title:"Jira Link Create",description:"Create an issue link relationship with optional comment",annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!1,openWorldHint:!0}},[we.name]:{title:"Jira Attachment Add",description:"Attach a local file to a Jira issue",annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!1,openWorldHint:!0}},[je.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}},[Ae.name]:{title:"Jira Worklog Add",description:"Log time spent on a Jira issue",annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!1,openWorldHint:!0}}};async function Te(t){const e=o.for(Te);let r,s=null;try{r=(()=>{let t;try{const e=require("jira.js");t=e?.Version3Client||e.default?.Version3Client||e.default||e}catch(t){throw Error("Unable to require 'jira.js' \u2014 ensure it is installed as a dependency: "+t)}const{host:e,email:r,apiKey:s}=(()=>{const t=Ot(),e=Ct().filter(t=>t.required&&!t.value);if(e.length>0)throw new Jt(e);return{host:t.host,email:t.email,apiKey:t.apiKey}})();return new t({host:e,authentication:{basic:{email:r,apiToken:s}}})})()}catch(t){if(!(t instanceof Jt))return void e.warn("Skipping Jira tool registration; unable to create Jira client",{error:t});s=t,e.warn("Registering Jira tools without credentials; each tool will report configuration requirements.",{error:t})}const n=[$t,ce,Pt,oe,le,de,he,ye,be,we,je,Ie,Ae];for(const i of n){const n=Ee[i.name];if(n)try{await t.registerTool(i.name,{title:n.title,description:n.description,inputSchema:rt(i.inputSchema),annotations:n.annotations},async t=>{if(!r)throw s??Error("Jira client unavailable because credentials could not be loaded.");return i.runTool(r,t)}),e.info("Registered Jira tool "+i.name)}catch(t){e.error("Failed to register Jira tool "+i.name,{error:t})}}}async function Ne(t){await(async t=>{t.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 t=xt.map(t=>t.getName()).sort();return{content:[{type:"text",text:["Name: "+Nt.name,"Title: "+Nt.title,"Version: "+Nt.version,"Prompts: "+(t.join(", ")||"<none>")].join("\n")}]}})})(t);const e=o.for(Ne);try{await Te(t)}catch(t){e.error("Failed to register Jira tools",t)}}class Oe extends Q{setCb(t){return this.cb=t,this}setConfig(t){return this.config=t,this}setUriOtTemplate(t){return this.uriOrTemplate=t,this}constructor(t){super(t)}static get builder(){return new Oe}build(t){const e=this.hasErrors();if(e)throw Error(e.toString());try{const e="string"==typeof this.uriOrTemplate&&this.uriOrTemplate.includes("{")?new M(new $(this.uriOrTemplate),{list:void 0}):this.uriOrTemplate,r=Object.assign(this.config,{_meta:{}}),s=async(t,e)=>{const r=this.logFor(e);r.verbose(`Requesting resource ${this.name} from ${t.toString()}`);const s=await Promise.resolve(this.cb(t,e));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 o.for(this).error("Error registering resource "+this.name,t),t}}}y([b(),g("design:type",String)],Oe.prototype,"uriOrTemplate",void 0),y([b(),g("design:type",Function)],Oe.prototype,"cb",void 0),y([b(),g("design:type",Object)],Oe.prototype,"config",void 0);const Ce=dt()??h.join(__dirname,"..","assets"),He=h.join(Ce,"templates"),Je=h.join(Ce,"prompts"),_e=new WeakMap;class De extends a{get client(){const t=_e.get(this);if(!t)throw Error("Mcp server requires Mcp client");return t}constructor(){super()}async load(){const t=this.log.for(this.load);for(const e of xt)try{t.info("loading prompt "+e.getName());const r=e.build(this.client);t.verbose(`Loaded prompt ${r.title} from ${e.getName()} definition`)}catch(r){t.error("Failed to load prompt "+e.getName(),r)}try{await Ne(this.client),t.verbose("Registered built-in tools")}catch(e){t.error("Failed to register tools",e)}try{await(async(t,r)=>{r.info("Registering agent templates as resources...");const s=e.readdirSync(He).filter(t=>t.endsWith(".md"));for(const n of s){const s=h.basename(n,".md"),i=h.join(He,n),o=Oe.builder.setName(s).setTitle("Template: "+s).setDescription("Resource template for "+s).setUriOtTemplate("file:///"+i).setConfig({mimeType:"text/markdown",description:"Template for "+s}).setCb(async t=>{const r=e.readFileSync(t.pathname,"utf8");return{contents:[{uri:t.toString(),text:r,mimeType:"text/markdown"}],_meta:{}}});try{o.build(t),r.info("Registered template: "+s)}catch(t){r.error(`Failed to register template ${s}:`,t)}}r.info("Registering agent prompts...");const n=e.readdirSync(Je).filter(t=>t.endsWith(".md"));for(const s of n){const n=h.basename(s,".md"),i=h.join(Je,s),o=e.readFileSync(i,"utf8"),a=ht.builder.setName(n).setTitle("Prompt: "+n).setDescription("Dynamic prompt for "+n).setArgsSchema(j.object({})).setCb(async t=>({messages:[{role:"user",content:{type:"text",text:o}}],_meta:{}}));try{a.build(t),r.info("Registered prompt: "+n)}catch(t){r.error(`Failed to register prompt ${n}:`,t)}}})(this.client,t),t.verbose("Registered agent-specific assets")}catch(e){t.error("Failed to register agent assets",e)}}async boot(t="stdio"){let r=this.log;this.log.for(this.boot).info("McpServer booting..."),((t=o.get())=>{let r;try{r=(()=>{let t,r=__dirname;try{for(;r&&r!==h.parse(r).root;){const s=h.join(r,"node_modules");if(e.existsSync(s)&&e.statSync(s).isDirectory()){t=s;break}const n=h.dirname(r);if(n===r)break;r=n}}catch{}const s=[];if(t){const r=h.join(t,"@decaf-ts");try{if(e.existsSync(r)&&e.statSync(r).isDirectory()){const t=e.readdirSync(r);for(const n of t){const t=h.join(r,n);try{const r=h.join(t,"workdocs","assets","slogans.json");if(e.existsSync(r)&&e.statSync(r).isFile()){const t=e.readFileSync(r,"utf-8"),n=JSON.parse(t);if(Array.isArray(n))for(const t of n)"string"==typeof t&&t.trim().length>0&&s.push(t.trim())}}catch{}}}}catch{}}return 0===s.length?"Decaf: strongly brewed TypeScript.":s[Math.floor(Math.random()*s.length)]})()}catch{r="Decaf: strongly brewed TypeScript."}const s="# \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=s.reduce((t,e)=>Math.max(t,e.length),0);s.push("# "+r.padStart(n-3)),s.forEach((e,r)=>{const s=K[r%K.length]||"",n=t.info.bind(t);try{n(m(e||"").raw(s).text)}catch{n((e||"")+"")}})})(this.log),"stdio"===t&&(o.setFactory(U),r=o.for(this.constructor.name));const s=((Array.isArray(Nt.icons)?Nt.icons:[Nt.icons])||[]).map(t=>{const e="string"==typeof t?.src?t.src:(t?.src??"")+"",r="string"==typeof t?.mimeType?t.mimeType:(t?.mimeType??"")+"";let s=[];return Array.isArray(t?.sizes)?s=t.sizes.map(t=>t+""):"string"==typeof t?.sizes&&(s=(t.sizes+"").split(",").map(t=>t.trim())),{src:e,mimeType:r,sizes:s}}),n={name:Nt.name,title:Nt.title,websiteUrl:Nt.websiteUrl,version:Nt.version,icons:s},i=new F(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(((t,e)=>{_e.set(t,e)})(this,i),i.onerror=t=>{this.log.error("MCP instance onerror",t)},t){case"stdio":t=new B;break;case"http":t=new W({sessionIdGenerator:()=>q(),onsessioninitialized:t=>r.verbose("Session initialized: "+t),onsessionclosed:t=>r.verbose("Session closed: "+t),enableJsonResponse:!0,eventStore:void 0});break;default:if(!(a=t)||"object"!=typeof a||"function"!=typeof a.send&&"function"!=typeof a.close&&"function"!=typeof a.on)throw new T("Invalid transport type: "+t)}var a;try{this.log.info("Loading resources/prompts/tools..."),await this.load()}catch(t){throw this.log.error("Error loading resources/prompts/tools: "+t),t}await this.client.connect(t),r.info(`MCP Server connected via ${t.constructor.name} and running. Waiting for client connections...`)}}const Pe=(new t).command("start").option("--transport [String]","transport mode","stdio").description("starts decaf's mcp server").action(async t=>{const e=lt("package.json"),s=JSON.parse(r.readFileSync(e,"utf-8")),n=s.version,{transport:i}=t,o=(new L).for("mcp-server");if("stdio"!==i)throw Error("Unsupported transport mode: "+i);return o.info("Transport stdio"),o.debug(`running with options: ${JSON.stringify(t)} for ${s.name} version ${n}`),(new De).boot(i)});(new t).command("md-to-ast").description("pipes markdown to jira ast: `cat file.md` | npx decaf-mcp md-to-ast > ast.json").action(async t=>{const e=lt("package.json"),s=JSON.parse(r.readFileSync(e,"utf-8")),n=s.version;o.for("md-to-ast").debug(`running with options: ${JSON.stringify(t)} for ${s.name} version ${n}`);const i=se(await(async()=>{const t=[];for await(const e of process.stdin)t.push(Buffer.from(e));return Buffer.concat(t).toString("utf8")})(),{resolveMention:t=>({id:t,text:"@"+t}),resolveAttachment:t=>({id:t,collection:"attachments"})});process.stdout.write(JSON.stringify(i,null,2)+"\n")});const Re=(new t).name("mcp-server").command("mcp-server").description("decaf mcp server and agentic functionality");Re.addCommand(Pe),Re.parse(process.argv);
|
|
2
2
|
//# sourceMappingURL=mcp-server.js.map
|