derived-mcp-server 0.0.23 → 0.0.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/bundle.js +2 -2
  2. package/package.json +1 -1
package/dist/bundle.js CHANGED
@@ -7,9 +7,9 @@
7
7
  `:`[${n[l]}\r
8
8
  ]`;continue}s+=n[l],n[l]==="\\"?a=!0:i&&n[l]==="]"?i=!1:!i&&n[l]==="["&&(i=!0)}try{new RegExp(s)}catch{return console.warn(`Could not convert regex pattern at ${e.currentPath.join("/")} to a flag-independent form! Falling back to the flag-ignorant source`),r.source}return s}function pt(r,e){if(e.target==="openAi"&&console.warn("Warning: OpenAI may not support records in schemas! Try an array of key-value pairs instead."),e.target==="openApi3"&&r.keyType?._def.typeName===d.ZodEnum)return{type:"object",required:r.keyType._def.values,properties:r.keyType._def.values.reduce((n,s)=>({...n,[s]:y(r.valueType._def,{...e,currentPath:[...e.currentPath,"properties",s]})??{}}),{}),additionalProperties:e.rejectedAdditionalProperties};let t={type:"object",additionalProperties:y(r.valueType._def,{...e,currentPath:[...e.currentPath,"additionalProperties"]})??e.allowedAdditionalProperties};if(e.target==="openApi3")return t;if(r.keyType?._def.typeName===d.ZodString&&r.keyType._def.checks?.length){let{type:n,...s}=dt(r.keyType._def,e);return{...t,propertyNames:s}}else{if(r.keyType?._def.typeName===d.ZodEnum)return{...t,propertyNames:{enum:r.keyType._def.values}};if(r.keyType?._def.typeName===d.ZodBranded&&r.keyType._def.type._def.typeName===d.ZodString&&r.keyType._def.type._def.checks?.length){let{type:n,...s}=ut(r.keyType._def,e);return{...t,propertyNames:s}}}return t}function Zr(r,e){if(e.mapStrategy==="record")return pt(r,e);let t=y(r.keyType._def,{...e,currentPath:[...e.currentPath,"items","items","0"]})||{},n=y(r.valueType._def,{...e,currentPath:[...e.currentPath,"items","items","1"]})||{};return{type:"array",maxItems:125,items:{type:"array",items:[t,n],minItems:2,maxItems:2}}}function Lr(r){let e=r.values,n=Object.keys(r.values).filter(a=>typeof e[e[a]]!="number").map(a=>e[a]),s=Array.from(new Set(n.map(a=>typeof a)));return{type:s.length===1?s[0]==="string"?"string":"number":["string","number"],enum:n}}function qr(){return{not:{}}}function Vr(r){return r.target==="openApi3"?{enum:["null"],nullable:!0}:{type:"null"}}var De={ZodString:"string",ZodNumber:"number",ZodBigInt:"integer",ZodBoolean:"boolean",ZodNull:"null"};function zr(r,e){if(e.target==="openApi3")return Hr(r,e);let t=r.options instanceof Map?Array.from(r.options.values()):r.options;if(t.every(n=>n._def.typeName in De&&(!n._def.checks||!n._def.checks.length))){let n=t.reduce((s,a)=>{let i=De[a._def.typeName];return i&&!s.includes(i)?[...s,i]:s},[]);return{type:n.length>1?n:n[0]}}else if(t.every(n=>n._def.typeName==="ZodLiteral"&&!n.description)){let n=t.reduce((s,a)=>{let i=typeof a._def.value;switch(i){case"string":case"number":case"boolean":return[...s,i];case"bigint":return[...s,"integer"];case"object":if(a._def.value===null)return[...s,"null"];case"symbol":case"undefined":case"function":default:return s}},[]);if(n.length===t.length){let s=n.filter((a,i,c)=>c.indexOf(a)===i);return{type:s.length>1?s:s[0],enum:t.reduce((a,i)=>a.includes(i._def.value)?a:[...a,i._def.value],[])}}}else if(t.every(n=>n._def.typeName==="ZodEnum"))return{type:"string",enum:t.reduce((n,s)=>[...n,...s._def.values.filter(a=>!n.includes(a))],[])};return Hr(r,e)}var Hr=(r,e)=>{let t=(r.options instanceof Map?Array.from(r.options.values()):r.options).map((n,s)=>y(n._def,{...e,currentPath:[...e.currentPath,"anyOf",`${s}`]})).filter(n=>!!n&&(!e.strictUnions||typeof n=="object"&&Object.keys(n).length>0));return t.length?{anyOf:t}:void 0};function Ur(r,e){if(["ZodString","ZodNumber","ZodBigInt","ZodBoolean","ZodNull"].includes(r.innerType._def.typeName)&&(!r.innerType._def.checks||!r.innerType._def.checks.length))return e.target==="openApi3"?{type:De[r.innerType._def.typeName],nullable:!0}:{type:[De[r.innerType._def.typeName],"null"]};if(e.target==="openApi3"){let n=y(r.innerType._def,{...e,currentPath:[...e.currentPath]});return n&&"$ref"in n?{allOf:[n],nullable:!0}:n&&{...n,nullable:!0}}let t=y(r.innerType._def,{...e,currentPath:[...e.currentPath,"anyOf","0"]});return t&&{anyOf:[t,{type:"null"}]}}function Br(r,e){let t={type:"number"};if(!r.checks)return t;for(let n of r.checks)switch(n.kind){case"int":t.type="integer",Nt(t,"type",n.message,e);break;case"min":e.target==="jsonSchema7"?n.inclusive?x(t,"minimum",n.value,n.message,e):x(t,"exclusiveMinimum",n.value,n.message,e):(n.inclusive||(t.exclusiveMinimum=!0),x(t,"minimum",n.value,n.message,e));break;case"max":e.target==="jsonSchema7"?n.inclusive?x(t,"maximum",n.value,n.message,e):x(t,"exclusiveMaximum",n.value,n.message,e):(n.inclusive||(t.exclusiveMaximum=!0),x(t,"maximum",n.value,n.message,e));break;case"multipleOf":x(t,"multipleOf",n.value,n.message,e);break}return t}function Fr(r,e){let t=e.target==="openAi",n={type:"object",properties:{}},s=[],a=r.shape();for(let c in a){let l=a[c];if(l===void 0||l._def===void 0)continue;let u=ga(l);u&&t&&(l instanceof O&&(l=l._def.innerType),l.isNullable()||(l=l.nullable()),u=!1);let m=y(l._def,{...e,currentPath:[...e.currentPath,"properties",c],propertyPath:[...e.currentPath,"properties",c]});m!==void 0&&(n.properties[c]=m,u||s.push(c))}s.length&&(n.required=s);let i=ha(r,e);return i!==void 0&&(n.additionalProperties=i),n}function ha(r,e){if(r.catchall._def.typeName!=="ZodNever")return y(r.catchall._def,{...e,currentPath:[...e.currentPath,"additionalProperties"]});switch(r.unknownKeys){case"passthrough":return e.allowedAdditionalProperties;case"strict":return e.rejectedAdditionalProperties;case"strip":return e.removeAdditionalStrategy==="strict"?e.allowedAdditionalProperties:e.rejectedAdditionalProperties}}function ga(r){try{return r.isOptional()}catch{return!0}}var Jr=(r,e)=>{if(e.currentPath.toString()===e.propertyPath?.toString())return y(r.innerType._def,e);let t=y(r.innerType._def,{...e,currentPath:[...e.currentPath,"anyOf","1"]});return t?{anyOf:[{not:{}},t]}:{}};var Wr=(r,e)=>{if(e.pipeStrategy==="input")return y(r.in._def,e);if(e.pipeStrategy==="output")return y(r.out._def,e);let t=y(r.in._def,{...e,currentPath:[...e.currentPath,"allOf","0"]}),n=y(r.out._def,{...e,currentPath:[...e.currentPath,"allOf",t?"1":"0"]});return{allOf:[t,n].filter(s=>s!==void 0)}};function Yr(r,e){return y(r.type._def,e)}function Kr(r,e){let n={type:"array",uniqueItems:!0,items:y(r.valueType._def,{...e,currentPath:[...e.currentPath,"items"]})};return r.minSize&&x(n,"minItems",r.minSize.value,r.minSize.message,e),r.maxSize&&x(n,"maxItems",r.maxSize.value,r.maxSize.message,e),n}function Gr(r,e){return r.rest?{type:"array",minItems:r.items.length,items:r.items.map((t,n)=>y(t._def,{...e,currentPath:[...e.currentPath,"items",`${n}`]})).reduce((t,n)=>n===void 0?t:[...t,n],[]),additionalItems:y(r.rest._def,{...e,currentPath:[...e.currentPath,"additionalItems"]})}:{type:"array",minItems:r.items.length,maxItems:r.items.length,items:r.items.map((t,n)=>y(t._def,{...e,currentPath:[...e.currentPath,"items",`${n}`]})).reduce((t,n)=>n===void 0?t:[...t,n],[])}}function Xr(){return{not:{}}}function Qr(){return{}}var en=(r,e)=>y(r.innerType._def,e);var tn=(r,e,t)=>{switch(e){case d.ZodString:return dt(r,t);case d.ZodNumber:return Br(r,t);case d.ZodObject:return Fr(r,t);case d.ZodBigInt:return Cr(r,t);case d.ZodBoolean:return Or();case d.ZodDate:return jt(r,t);case d.ZodUndefined:return Xr();case d.ZodNull:return Vr(t);case d.ZodArray:return Pr(r,t);case d.ZodUnion:case d.ZodDiscriminatedUnion:return zr(r,t);case d.ZodIntersection:return Dr(r,t);case d.ZodTuple:return Gr(r,t);case d.ZodRecord:return pt(r,t);case d.ZodLiteral:return Mr(r,t);case d.ZodEnum:return Ar(r);case d.ZodNativeEnum:return Lr(r);case d.ZodNullable:return Ur(r,t);case d.ZodOptional:return Jr(r,t);case d.ZodMap:return Zr(r,t);case d.ZodSet:return Kr(r,t);case d.ZodLazy:return()=>r.getter()._def;case d.ZodPromise:return Yr(r,t);case d.ZodNaN:case d.ZodNever:return qr();case d.ZodEffects:return Ir(r,t);case d.ZodAny:return Er();case d.ZodUnknown:return Qr();case d.ZodDefault:return jr(r,t);case d.ZodBranded:return ut(r,t);case d.ZodReadonly:return en(r,t);case d.ZodCatch:return Nr(r,t);case d.ZodPipeline:return Wr(r,t);case d.ZodFunction:case d.ZodVoid:case d.ZodSymbol:return;default:return(n=>{})(e)}};function y(r,e,t=!1){let n=e.seen.get(r);if(e.override){let c=e.override?.(r,e,n,t);if(c!==Sr)return c}if(n&&!t){let c=ya(n,e);if(c!==void 0)return c}let s={def:r,path:e.currentPath,jsonSchema:void 0};e.seen.set(r,s);let a=tn(r,r.typeName,e),i=typeof a=="function"?y(a(),e):a;if(i&&_a(r,e,i),e.postProcess){let c=e.postProcess(i,r,e);return s.jsonSchema=i,c}return s.jsonSchema=i,i}var ya=(r,e)=>{switch(e.$refStrategy){case"root":return{$ref:r.path.join("/")};case"relative":return{$ref:va(e.currentPath,r.path)};case"none":case"seen":return r.path.length<e.currentPath.length&&r.path.every((t,n)=>e.currentPath[n]===t)?(console.warn(`Recursive reference detected at ${e.currentPath.join("/")}! Defaulting to any`),{}):e.$refStrategy==="seen"?{}:void 0}},va=(r,e)=>{let t=0;for(;t<r.length&&t<e.length&&r[t]===e[t];t++);return[(r.length-t).toString(),...e.slice(t)].join("/")},_a=(r,e,t)=>(r.description&&(t.description=r.description,e.markdownDescription&&(t.markdownDescription=r.description)),t);var Dt=(r,e)=>{let t=Rr(e),n=typeof e=="object"&&e.definitions?Object.entries(e.definitions).reduce((l,[u,m])=>({...l,[u]:y(m._def,{...t,currentPath:[...t.basePath,t.definitionPath,u]},!0)??{}}),{}):void 0,s=typeof e=="string"?e:e?.nameStrategy==="title"?void 0:e?.name,a=y(r._def,s===void 0?t:{...t,currentPath:[...t.basePath,t.definitionPath,s]},!1)??{},i=typeof e=="object"&&e.name!==void 0&&e.nameStrategy==="title"?e.name:void 0;i!==void 0&&(a.title=i);let c=s===void 0?n?{...a,[t.definitionPath]:n}:a:{$ref:[...t.$refStrategy==="relative"?[]:t.basePath,t.definitionPath,s].join("/"),[t.definitionPath]:{...n,[s]:a}};return t.target==="jsonSchema7"?c.$schema="http://json-schema.org/draft-07/schema#":(t.target==="jsonSchema2019-09"||t.target==="openAi")&&(c.$schema="https://json-schema.org/draft/2019-09/schema#"),t.target==="openAi"&&("anyOf"in c||"oneOf"in c||"allOf"in c||"type"in c&&Array.isArray(c.type))&&console.warn("Warning: OpenAI may not support schemas with unions as roots! Try wrapping it in an object property."),c};var Mt;(function(r){r.Completable="McpCompletable"})(Mt||(Mt={}));var Re=class extends _{_parse(e){let{ctx:t}=this._processInputParams(e),n=t.data;return this._def.type._parse({data:n,path:t.path,parent:t})}unwrap(){return this._def.type}};Re.create=(r,e)=>new Re({type:r,typeName:Mt.Completable,complete:e.complete,...ba(e)});function ba(r){if(!r)return{};let{errorMap:e,invalid_type_error:t,required_error:n,description:s}=r;if(e&&(t||n))throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);return e?{errorMap:e,description:s}:{errorMap:(i,c)=>{var l,u;let{message:m}=r;return i.code==="invalid_enum_value"?{message:m??c.defaultError}:typeof c.data>"u"?{message:(l=m??n)!==null&&l!==void 0?l:c.defaultError}:i.code!=="invalid_type"?{message:c.defaultError}:{message:(u=m??t)!==null&&u!==void 0?u:c.defaultError}},description:s}}var ft=class{constructor(e,t){this._registeredResources={},this._registeredResourceTemplates={},this._registeredTools={},this._registeredPrompts={},this._toolHandlersInitialized=!1,this._completionHandlerInitialized=!1,this._resourceHandlersInitialized=!1,this._promptHandlersInitialized=!1,this.server=new lt(e,t)}async connect(e){return await this.server.connect(e)}async close(){await this.server.close()}setToolRequestHandlers(){this._toolHandlersInitialized||(this.server.assertCanSetRequestHandler(at.shape.method.value),this.server.assertCanSetRequestHandler(it.shape.method.value),this.server.registerCapabilities({tools:{listChanged:!0}}),this.server.setRequestHandler(at,()=>({tools:Object.entries(this._registeredTools).filter(([,e])=>e.enabled).map(([e,t])=>({name:e,description:t.description,inputSchema:t.inputSchema?Dt(t.inputSchema,{strictUnions:!0}):xa,annotations:t.annotations}))})),this.server.setRequestHandler(it,async(e,t)=>{let n=this._registeredTools[e.params.name];if(!n)throw new T(S.InvalidParams,`Tool ${e.params.name} not found`);if(!n.enabled)throw new T(S.InvalidParams,`Tool ${e.params.name} disabled`);if(n.inputSchema){let s=await n.inputSchema.safeParseAsync(e.params.arguments);if(!s.success)throw new T(S.InvalidParams,`Invalid arguments for tool ${e.params.name}: ${s.error.message}`);let a=s.data,i=n.callback;try{return await Promise.resolve(i(a,t))}catch(c){return{content:[{type:"text",text:c instanceof Error?c.message:String(c)}],isError:!0}}}else{let s=n.callback;try{return await Promise.resolve(s(t))}catch(a){return{content:[{type:"text",text:a instanceof Error?a.message:String(a)}],isError:!0}}}}),this._toolHandlersInitialized=!0)}setCompletionRequestHandler(){this._completionHandlerInitialized||(this.server.assertCanSetRequestHandler(ot.shape.method.value),this.server.setRequestHandler(ot,async e=>{switch(e.params.ref.type){case"ref/prompt":return this.handlePromptCompletion(e,e.params.ref);case"ref/resource":return this.handleResourceCompletion(e,e.params.ref);default:throw new T(S.InvalidParams,`Invalid completion reference: ${e.params.ref}`)}}),this._completionHandlerInitialized=!0)}async handlePromptCompletion(e,t){let n=this._registeredPrompts[t.name];if(!n)throw new T(S.InvalidParams,`Prompt ${t.name} not found`);if(!n.enabled)throw new T(S.InvalidParams,`Prompt ${t.name} disabled`);if(!n.argsSchema)return mt;let s=n.argsSchema.shape[e.params.argument.name];if(!(s instanceof Re))return mt;let i=await s._def.complete(e.params.argument.value);return rn(i)}async handleResourceCompletion(e,t){let n=Object.values(this._registeredResourceTemplates).find(i=>i.resourceTemplate.uriTemplate.toString()===t.uri);if(!n){if(this._registeredResources[t.uri])return mt;throw new T(S.InvalidParams,`Resource template ${e.params.ref.uri} not found`)}let s=n.resourceTemplate.completeCallback(e.params.argument.name);if(!s)return mt;let a=await s(e.params.argument.value);return rn(a)}setResourceRequestHandlers(){this._resourceHandlersInitialized||(this.server.assertCanSetRequestHandler(Ge.shape.method.value),this.server.assertCanSetRequestHandler(Xe.shape.method.value),this.server.assertCanSetRequestHandler(Qe.shape.method.value),this.server.registerCapabilities({resources:{listChanged:!0}}),this.server.setRequestHandler(Ge,async(e,t)=>{let n=Object.entries(this._registeredResources).filter(([a,i])=>i.enabled).map(([a,i])=>({uri:a,name:i.name,...i.metadata})),s=[];for(let a of Object.values(this._registeredResourceTemplates)){if(!a.resourceTemplate.listCallback)continue;let i=await a.resourceTemplate.listCallback(t);for(let c of i.resources)s.push({...c,...a.metadata})}return{resources:[...n,...s]}}),this.server.setRequestHandler(Xe,async()=>({resourceTemplates:Object.entries(this._registeredResourceTemplates).map(([t,n])=>({name:t,uriTemplate:n.resourceTemplate.uriTemplate.toString(),...n.metadata}))})),this.server.setRequestHandler(Qe,async(e,t)=>{let n=new URL(e.params.uri),s=this._registeredResources[n.toString()];if(s){if(!s.enabled)throw new T(S.InvalidParams,`Resource ${n} disabled`);return s.readCallback(n,t)}for(let a of Object.values(this._registeredResourceTemplates)){let i=a.resourceTemplate.uriTemplate.match(n.toString());if(i)return a.readCallback(n,i,t)}throw new T(S.InvalidParams,`Resource ${n} not found`)}),this.setCompletionRequestHandler(),this._resourceHandlersInitialized=!0)}setPromptRequestHandlers(){this._promptHandlersInitialized||(this.server.assertCanSetRequestHandler(et.shape.method.value),this.server.assertCanSetRequestHandler(tt.shape.method.value),this.server.registerCapabilities({prompts:{listChanged:!0}}),this.server.setRequestHandler(et,()=>({prompts:Object.entries(this._registeredPrompts).filter(([,e])=>e.enabled).map(([e,t])=>({name:e,description:t.description,arguments:t.argsSchema?ka(t.argsSchema):void 0}))})),this.server.setRequestHandler(tt,async(e,t)=>{let n=this._registeredPrompts[e.params.name];if(!n)throw new T(S.InvalidParams,`Prompt ${e.params.name} not found`);if(!n.enabled)throw new T(S.InvalidParams,`Prompt ${e.params.name} disabled`);if(n.argsSchema){let s=await n.argsSchema.safeParseAsync(e.params.arguments);if(!s.success)throw new T(S.InvalidParams,`Invalid arguments for prompt ${e.params.name}: ${s.error.message}`);let a=s.data,i=n.callback;return await Promise.resolve(i(a,t))}else{let s=n.callback;return await Promise.resolve(s(t))}}),this.setCompletionRequestHandler(),this._promptHandlersInitialized=!0)}resource(e,t,...n){let s;typeof n[0]=="object"&&(s=n.shift());let a=n[0];if(typeof t=="string"){if(this._registeredResources[t])throw new Error(`Resource ${t} is already registered`);let i={name:e,metadata:s,readCallback:a,enabled:!0,disable:()=>i.update({enabled:!1}),enable:()=>i.update({enabled:!0}),remove:()=>i.update({uri:null}),update:c=>{typeof c.uri<"u"&&c.uri!==t&&(delete this._registeredResources[t],c.uri&&(this._registeredResources[c.uri]=i)),typeof c.name<"u"&&(i.name=c.name),typeof c.metadata<"u"&&(i.metadata=c.metadata),typeof c.callback<"u"&&(i.readCallback=c.callback),typeof c.enabled<"u"&&(i.enabled=c.enabled),this.sendResourceListChanged()}};return this._registeredResources[t]=i,this.setResourceRequestHandlers(),this.sendResourceListChanged(),i}else{if(this._registeredResourceTemplates[e])throw new Error(`Resource template ${e} is already registered`);let i={resourceTemplate:t,metadata:s,readCallback:a,enabled:!0,disable:()=>i.update({enabled:!1}),enable:()=>i.update({enabled:!0}),remove:()=>i.update({name:null}),update:c=>{typeof c.name<"u"&&c.name!==e&&(delete this._registeredResourceTemplates[e],c.name&&(this._registeredResourceTemplates[c.name]=i)),typeof c.template<"u"&&(i.resourceTemplate=c.template),typeof c.metadata<"u"&&(i.metadata=c.metadata),typeof c.callback<"u"&&(i.readCallback=c.callback),typeof c.enabled<"u"&&(i.enabled=c.enabled),this.sendResourceListChanged()}};return this._registeredResourceTemplates[e]=i,this.setResourceRequestHandlers(),this.sendResourceListChanged(),i}}tool(e,...t){if(this._registeredTools[e])throw new Error(`Tool ${e} is already registered`);let n=u=>typeof u!="object"||u===null?!1:Object.values(u).some(m=>m instanceof _),s;typeof t[0]=="string"&&(s=t.shift());let a,i;if(t.length>1){let u=t[0];n(u)?(a=t.shift(),t.length>1&&typeof t[0]=="object"&&t[0]!==null&&!n(t[0])&&(i=t.shift())):typeof u=="object"&&u!==null&&(i=t.shift())}let c=t[0],l={description:s,inputSchema:a===void 0?void 0:o.object(a),annotations:i,callback:c,enabled:!0,disable:()=>l.update({enabled:!1}),enable:()=>l.update({enabled:!0}),remove:()=>l.update({name:null}),update:u=>{typeof u.name<"u"&&u.name!==e&&(delete this._registeredTools[e],u.name&&(this._registeredTools[u.name]=l)),typeof u.description<"u"&&(l.description=u.description),typeof u.paramsSchema<"u"&&(l.inputSchema=o.object(u.paramsSchema)),typeof u.callback<"u"&&(l.callback=u.callback),typeof u.annotations<"u"&&(l.annotations=u.annotations),typeof u.enabled<"u"&&(l.enabled=u.enabled),this.sendToolListChanged()}};return this._registeredTools[e]=l,this.setToolRequestHandlers(),this.sendToolListChanged(),l}prompt(e,...t){if(this._registeredPrompts[e])throw new Error(`Prompt ${e} is already registered`);let n;typeof t[0]=="string"&&(n=t.shift());let s;t.length>1&&(s=t.shift());let a=t[0],i={description:n,argsSchema:s===void 0?void 0:o.object(s),callback:a,enabled:!0,disable:()=>i.update({enabled:!1}),enable:()=>i.update({enabled:!0}),remove:()=>i.update({name:null}),update:c=>{typeof c.name<"u"&&c.name!==e&&(delete this._registeredPrompts[e],c.name&&(this._registeredPrompts[c.name]=i)),typeof c.description<"u"&&(i.description=c.description),typeof c.argsSchema<"u"&&(i.argsSchema=o.object(c.argsSchema)),typeof c.callback<"u"&&(i.callback=c.callback),typeof c.enabled<"u"&&(i.enabled=c.enabled),this.sendPromptListChanged()}};return this._registeredPrompts[e]=i,this.setPromptRequestHandlers(),this.sendPromptListChanged(),i}isConnected(){return this.server.transport!==void 0}sendResourceListChanged(){this.isConnected()&&this.server.sendResourceListChanged()}sendToolListChanged(){this.isConnected()&&this.server.sendToolListChanged()}sendPromptListChanged(){this.isConnected()&&this.server.sendPromptListChanged()}};var xa={type:"object"};function ka(r){return Object.entries(r.shape).map(([e,t])=>({name:e,description:t.description,required:!t.isOptional()}))}function rn(r){return{completion:{values:r.slice(0,100),total:r.length,hasMore:r.length>100}}}var mt={completion:{values:[],hasMore:!1}};var $t=_t(require("node:process"),1);var ht=class{append(e){this._buffer=this._buffer?Buffer.concat([this._buffer,e]):e}readMessage(){if(!this._buffer)return null;let e=this._buffer.indexOf(`
9
9
  `);if(e===-1)return null;let t=this._buffer.toString("utf8",0,e).replace(/\r$/,"");return this._buffer=this._buffer.subarray(e+1),wa(t)}clear(){this._buffer=void 0}};function wa(r){return fr.parse(JSON.parse(r))}function nn(r){return JSON.stringify(r)+`
10
- `}var gt=class{constructor(e=$t.default.stdin,t=$t.default.stdout){this._stdin=e,this._stdout=t,this._readBuffer=new ht,this._started=!1,this._ondata=n=>{this._readBuffer.append(n),this.processReadBuffer()},this._onerror=n=>{var s;(s=this.onerror)===null||s===void 0||s.call(this,n)}}async start(){if(this._started)throw new Error("StdioServerTransport already started! If using Server class, note that connect() calls start() automatically.");this._started=!0,this._stdin.on("data",this._ondata),this._stdin.on("error",this._onerror)}processReadBuffer(){for(var e,t;;)try{let n=this._readBuffer.readMessage();if(n===null)break;(e=this.onmessage)===null||e===void 0||e.call(this,n)}catch(n){(t=this.onerror)===null||t===void 0||t.call(this,n)}}async close(){var e;this._stdin.off("data",this._ondata),this._stdin.off("error",this._onerror),this._stdin.listenerCount("data")===0&&this._stdin.pause(),this._readBuffer.clear(),(e=this.onclose)===null||e===void 0||e.call(this)}send(e){return new Promise(t=>{let n=nn(e);this._stdout.write(n)?t():this._stdout.once("drain",t)})}};var yn=_t(ln());var fn=_t(pn());var mn=r=>r==null?!1:typeof r=="string"?r.trim().length>0:Array.isArray(r)?r.length>0:typeof r=="object"?Object.keys(r).length>0:!0;var Wa=new fn.default,Ya=o.object({query:o.string().describe("User request to add, create, build, generate, implement, or develop new features, components, pages, modules, dashboards, or functionality. Trigger words include: 'add', 'create', 'build', 'generate', 'implement', 'develop', 'make', 'setup'. Examples: 'add login page', 'create auth flow', 'build sales dashboard', 'implement user CRUD', 'generate reports module', 'setup payment system'. Use this for new development requests, not for questions or modifications to existing code."),selectedBlockCode:o.string().describe("The Code of the selected block.").optional(),blockInput:o.string().describe("JSON string containing the input data for the block when required by the block's schema.").optional()}),hn=r=>{r.tool("add_block","REQUIRED: Use this tool when users request to add, create, build, or implement new features, components, pages, modules, or functionality in their project. This searches Derived's template library for matching blocks based on semantic similarity to the user's request. Trigger for requests like: 'add login page', 'create auth flow', 'build dashboard', 'implement user CRUD', 'generate reports module'. The tool finds matching blocks, handles user selection for multiple options, and collects required input data.",Ya.shape,async({query:e,selectedBlockCode:t,blockInput:n})=>{console.error("add_block",e,t,n);try{if(t){let i=`npx derived-cli add ${t}`;if(mn(n)){let c=Buffer.from(JSON.stringify(n)).toString("base64");i+=` -i ${c}`}return{content:[{type:"text",text:`Run cli command ${i},
10
+ `}var gt=class{constructor(e=$t.default.stdin,t=$t.default.stdout){this._stdin=e,this._stdout=t,this._readBuffer=new ht,this._started=!1,this._ondata=n=>{this._readBuffer.append(n),this.processReadBuffer()},this._onerror=n=>{var s;(s=this.onerror)===null||s===void 0||s.call(this,n)}}async start(){if(this._started)throw new Error("StdioServerTransport already started! If using Server class, note that connect() calls start() automatically.");this._started=!0,this._stdin.on("data",this._ondata),this._stdin.on("error",this._onerror)}processReadBuffer(){for(var e,t;;)try{let n=this._readBuffer.readMessage();if(n===null)break;(e=this.onmessage)===null||e===void 0||e.call(this,n)}catch(n){(t=this.onerror)===null||t===void 0||t.call(this,n)}}async close(){var e;this._stdin.off("data",this._ondata),this._stdin.off("error",this._onerror),this._stdin.listenerCount("data")===0&&this._stdin.pause(),this._readBuffer.clear(),(e=this.onclose)===null||e===void 0||e.call(this)}send(e){return new Promise(t=>{let n=nn(e);this._stdout.write(n)?t():this._stdout.once("drain",t)})}};var yn=_t(ln());var fn=_t(pn());var mn=r=>r==null?!1:typeof r=="string"?r.trim().length>0:Array.isArray(r)?r.length>0:typeof r=="object"?Object.keys(r).length>0:!0;var Wa=new fn.default,Ya=o.object({query:o.string().describe("User request to add, create, build, generate, implement, or develop new features, components, pages, modules, dashboards, or functionality. Trigger words include: 'add', 'create', 'build', 'generate', 'implement', 'develop', 'make', 'setup'. Examples: 'add login page', 'create auth flow', 'build sales dashboard', 'implement user CRUD', 'generate reports module', 'setup payment system'. Use this for new development requests, not for questions or modifications to existing code."),selectedBlockCode:o.string().describe("The Code of the selected block.").optional(),blockInput:o.string().describe("JSON string containing the input data for the block when required by the block's schema.").optional()}),hn=r=>{r.tool("add_block","REQUIRED: Use this tool when users request to add, create, build, or implement new features, components, pages, modules, or functionality in their project. This searches Derived's template library for matching blocks based on semantic similarity to the user's request. Trigger for requests like: 'add login page', 'create auth flow', 'build dashboard', 'implement user CRUD', 'generate reports module'. The tool finds matching blocks, handles user selection for multiple options, and collects required input data. Do not read existing files and use extra tokens if you use this tool directly use the add tool and follow instructions",Ya.shape,async({query:e,selectedBlockCode:t,blockInput:n})=>{console.error("add_block",e,t,n);try{if(t){let i=`npx derived-cli add ${t}`;if(mn(n)){let c=Buffer.from(JSON.stringify(n)).toString("base64");i+=` -i ${c}`}return{content:[{type:"text",text:`Run cli command ${i},
11
11
  cli options
12
- "-o, --overwrite", "Automatically overwrite existing files"
12
+ "-o, --overwrite", "Automatically overwrite existing files, recommended for most cases"
13
13
  "-i, --block-input <value>", "Optional block input json schema in base 64 encoded"
14
14
  `}]}}let a=(await Wa.searchBlocksByName(e)).result;return!a||a.length===0?{content:[{type:"text",text:"No blocks found matching."}]}:a.length?{content:[{type:"text",text:`Found ${a.length} blocks:
15
15
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "derived-mcp-server",
3
- "version": "0.0.23",
3
+ "version": "0.0.24",
4
4
  "description": "MCP server for Derived",
5
5
  "author": "Derived",
6
6
  "license": "MIT",