@requestly/mcp 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/build/index.js CHANGED
@@ -5,7 +5,7 @@ var Ml=Object.create;var za=Object.defineProperty;var zl=Object.getOwnPropertyDe
5
5
  `:`[${s[c]}\r
6
6
  ]`;continue}r+=s[c],s[c]==="\\"?n=!0:o&&s[c]==="]"?o=!1:!o&&s[c]==="["&&(o=!0)}try{new RegExp(r)}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`),a.source}return r}function xa(a,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"&&a.keyType?._def.typeName===T.ZodEnum)return{type:"object",required:a.keyType._def.values,properties:a.keyType._def.values.reduce((s,r)=>({...s,[r]:Q(a.valueType._def,{...e,currentPath:[...e.currentPath,"properties",r]})??me(e)}),{}),additionalProperties:e.rejectedAdditionalProperties};let t={type:"object",additionalProperties:Q(a.valueType._def,{...e,currentPath:[...e.currentPath,"additionalProperties"]})??e.allowedAdditionalProperties};if(e.target==="openApi3")return t;if(a.keyType?._def.typeName===T.ZodString&&a.keyType._def.checks?.length){let{type:s,...r}=Pa(a.keyType._def,e);return{...t,propertyNames:r}}else{if(a.keyType?._def.typeName===T.ZodEnum)return{...t,propertyNames:{enum:a.keyType._def.values}};if(a.keyType?._def.typeName===T.ZodBranded&&a.keyType._def.type._def.typeName===T.ZodString&&a.keyType._def.type._def.checks?.length){let{type:s,...r}=ba(a.keyType._def,e);return{...t,propertyNames:r}}}return t}function Fo(a,e){if(e.mapStrategy==="record")return xa(a,e);let t=Q(a.keyType._def,{...e,currentPath:[...e.currentPath,"items","items","0"]})||me(e),s=Q(a.valueType._def,{...e,currentPath:[...e.currentPath,"items","items","1"]})||me(e);return{type:"array",maxItems:125,items:{type:"array",items:[t,s],minItems:2,maxItems:2}}}function qo(a){let e=a.values,s=Object.keys(a.values).filter(n=>typeof e[e[n]]!="number").map(n=>e[n]),r=Array.from(new Set(s.map(n=>typeof n)));return{type:r.length===1?r[0]==="string"?"string":"number":["string","number"],enum:s}}function Mo(a){return a.target==="openAi"?void 0:{not:me({...a,currentPath:[...a.currentPath,"not"]})}}function zo(a){return a.target==="openApi3"?{enum:["null"],nullable:!0}:{type:"null"}}var Tt={ZodString:"string",ZodNumber:"number",ZodBigInt:"integer",ZodBoolean:"boolean",ZodNull:"null"};function Ho(a,e){if(e.target==="openApi3")return Uo(a,e);let t=a.options instanceof Map?Array.from(a.options.values()):a.options;if(t.every(s=>s._def.typeName in Tt&&(!s._def.checks||!s._def.checks.length))){let s=t.reduce((r,n)=>{let o=Tt[n._def.typeName];return o&&!r.includes(o)?[...r,o]:r},[]);return{type:s.length>1?s:s[0]}}else if(t.every(s=>s._def.typeName==="ZodLiteral"&&!s.description)){let s=t.reduce((r,n)=>{let o=typeof n._def.value;switch(o){case"string":case"number":case"boolean":return[...r,o];case"bigint":return[...r,"integer"];case"object":if(n._def.value===null)return[...r,"null"];case"symbol":case"undefined":case"function":default:return r}},[]);if(s.length===t.length){let r=s.filter((n,o,i)=>i.indexOf(n)===o);return{type:r.length>1?r:r[0],enum:t.reduce((n,o)=>n.includes(o._def.value)?n:[...n,o._def.value],[])}}}else if(t.every(s=>s._def.typeName==="ZodEnum"))return{type:"string",enum:t.reduce((s,r)=>[...s,...r._def.values.filter(n=>!s.includes(n))],[])};return Uo(a,e)}var Uo=(a,e)=>{let t=(a.options instanceof Map?Array.from(a.options.values()):a.options).map((s,r)=>Q(s._def,{...e,currentPath:[...e.currentPath,"anyOf",`${r}`]})).filter(s=>!!s&&(!e.strictUnions||typeof s=="object"&&Object.keys(s).length>0));return t.length?{anyOf:t}:void 0};function Vo(a,e){if(["ZodString","ZodNumber","ZodBigInt","ZodBoolean","ZodNull"].includes(a.innerType._def.typeName)&&(!a.innerType._def.checks||!a.innerType._def.checks.length))return e.target==="openApi3"?{type:Tt[a.innerType._def.typeName],nullable:!0}:{type:[Tt[a.innerType._def.typeName],"null"]};if(e.target==="openApi3"){let s=Q(a.innerType._def,{...e,currentPath:[...e.currentPath]});return s&&"$ref"in s?{allOf:[s],nullable:!0}:s&&{...s,nullable:!0}}let t=Q(a.innerType._def,{...e,currentPath:[...e.currentPath,"anyOf","0"]});return t&&{anyOf:[t,{type:"null"}]}}function Zo(a,e){let t={type:"number"};if(!a.checks)return t;for(let s of a.checks)switch(s.kind){case"int":t.type="integer",ws(t,"type",s.message,e);break;case"min":e.target==="jsonSchema7"?s.inclusive?ee(t,"minimum",s.value,s.message,e):ee(t,"exclusiveMinimum",s.value,s.message,e):(s.inclusive||(t.exclusiveMinimum=!0),ee(t,"minimum",s.value,s.message,e));break;case"max":e.target==="jsonSchema7"?s.inclusive?ee(t,"maximum",s.value,s.message,e):ee(t,"exclusiveMaximum",s.value,s.message,e):(s.inclusive||(t.exclusiveMaximum=!0),ee(t,"maximum",s.value,s.message,e));break;case"multipleOf":ee(t,"multipleOf",s.value,s.message,e);break}return t}function Qo(a,e){let t=e.target==="openAi",s={type:"object",properties:{}},r=[],n=a.shape();for(let i in n){let c=n[i];if(c===void 0||c._def===void 0)continue;let f=kf(c);f&&t&&(c._def.typeName==="ZodOptional"&&(c=c._def.innerType),c.isNullable()||(c=c.nullable()),f=!1);let p=Q(c._def,{...e,currentPath:[...e.currentPath,"properties",i],propertyPath:[...e.currentPath,"properties",i]});p!==void 0&&(s.properties[i]=p,f||r.push(i))}r.length&&(s.required=r);let o=If(a,e);return o!==void 0&&(s.additionalProperties=o),s}function If(a,e){if(a.catchall._def.typeName!=="ZodNever")return Q(a.catchall._def,{...e,currentPath:[...e.currentPath,"additionalProperties"]});switch(a.unknownKeys){case"passthrough":return e.allowedAdditionalProperties;case"strict":return e.rejectedAdditionalProperties;case"strip":return e.removeAdditionalStrategy==="strict"?e.allowedAdditionalProperties:e.rejectedAdditionalProperties}}function kf(a){try{return a.isOptional()}catch{return!0}}var Bo=(a,e)=>{if(e.currentPath.toString()===e.propertyPath?.toString())return Q(a.innerType._def,e);let t=Q(a.innerType._def,{...e,currentPath:[...e.currentPath,"anyOf","1"]});return t?{anyOf:[{not:me(e)},t]}:me(e)};var Ko=(a,e)=>{if(e.pipeStrategy==="input")return Q(a.in._def,e);if(e.pipeStrategy==="output")return Q(a.out._def,e);let t=Q(a.in._def,{...e,currentPath:[...e.currentPath,"allOf","0"]}),s=Q(a.out._def,{...e,currentPath:[...e.currentPath,"allOf",t?"1":"0"]});return{allOf:[t,s].filter(r=>r!==void 0)}};function Jo(a,e){return Q(a.type._def,e)}function Go(a,e){let s={type:"array",uniqueItems:!0,items:Q(a.valueType._def,{...e,currentPath:[...e.currentPath,"items"]})};return a.minSize&&ee(s,"minItems",a.minSize.value,a.minSize.message,e),a.maxSize&&ee(s,"maxItems",a.maxSize.value,a.maxSize.message,e),s}function Yo(a,e){return a.rest?{type:"array",minItems:a.items.length,items:a.items.map((t,s)=>Q(t._def,{...e,currentPath:[...e.currentPath,"items",`${s}`]})).reduce((t,s)=>s===void 0?t:[...t,s],[]),additionalItems:Q(a.rest._def,{...e,currentPath:[...e.currentPath,"additionalItems"]})}:{type:"array",minItems:a.items.length,maxItems:a.items.length,items:a.items.map((t,s)=>Q(t._def,{...e,currentPath:[...e.currentPath,"items",`${s}`]})).reduce((t,s)=>s===void 0?t:[...t,s],[])}}function Wo(a){return{not:me(a)}}function Xo(a){return me(a)}var el=(a,e)=>Q(a.innerType._def,e);var rl=(a,e,t)=>{switch(e){case T.ZodString:return Pa(a,t);case T.ZodNumber:return Zo(a,t);case T.ZodObject:return Qo(a,t);case T.ZodBigInt:return $o(a,t);case T.ZodBoolean:return Oo();case T.ZodDate:return Ts(a,t);case T.ZodUndefined:return Wo(t);case T.ZodNull:return zo(t);case T.ZodArray:return Ao(a,t);case T.ZodUnion:case T.ZodDiscriminatedUnion:return Ho(a,t);case T.ZodIntersection:return jo(a,t);case T.ZodTuple:return Yo(a,t);case T.ZodRecord:return xa(a,t);case T.ZodLiteral:return No(a,t);case T.ZodEnum:return Co(a);case T.ZodNativeEnum:return qo(a);case T.ZodNullable:return Vo(a,t);case T.ZodOptional:return Bo(a,t);case T.ZodMap:return Fo(a,t);case T.ZodSet:return Go(a,t);case T.ZodLazy:return()=>a.getter()._def;case T.ZodPromise:return Jo(a,t);case T.ZodNaN:case T.ZodNever:return Mo(t);case T.ZodEffects:return Do(a,t);case T.ZodAny:return me(t);case T.ZodUnknown:return Xo(t);case T.ZodDefault:return ko(a,t);case T.ZodBranded:return ba(a,t);case T.ZodReadonly:return el(a,t);case T.ZodCatch:return Io(a,t);case T.ZodPipeline:return Ko(a,t);case T.ZodFunction:case T.ZodVoid:case T.ZodSymbol:return;default:return(s=>{})(e)}};function Q(a,e,t=!1){let s=e.seen.get(a);if(e.override){let i=e.override?.(a,e,s,t);if(i!==Ro)return i}if(s&&!t){let i=Df(s,e);if(i!==void 0)return i}let r={def:a,path:e.currentPath,jsonSchema:void 0};e.seen.set(a,r);let n=rl(a,a.typeName,e),o=typeof n=="function"?Q(n(),e):n;if(o&&Cf(a,e,o),e.postProcess){let i=e.postProcess(o,a,e);return r.jsonSchema=o,i}return r.jsonSchema=o,o}var Df=(a,e)=>{switch(e.$refStrategy){case"root":return{$ref:a.path.join("/")};case"relative":return{$ref:_a(e.currentPath,a.path)};case"none":case"seen":return a.path.length<e.currentPath.length&&a.path.every((t,s)=>e.currentPath[s]===t)?(console.warn(`Recursive reference detected at ${e.currentPath.join("/")}! Defaulting to any`),me(e)):e.$refStrategy==="seen"?me(e):void 0}},Cf=(a,e,t)=>(a.description&&(t.description=a.description,e.markdownDescription&&(t.markdownDescription=a.description)),t);var Ea=(a,e)=>{let t=To(e),s=typeof e=="object"&&e.definitions?Object.entries(e.definitions).reduce((c,[f,p])=>({...c,[f]:Q(p._def,{...t,currentPath:[...t.basePath,t.definitionPath,f]},!0)??me(t)}),{}):void 0,r=typeof e=="string"?e:e?.nameStrategy==="title"?void 0:e?.name,n=Q(a._def,r===void 0?t:{...t,currentPath:[...t.basePath,t.definitionPath,r]},!1)??me(t),o=typeof e=="object"&&e.name!==void 0&&e.nameStrategy==="title"?e.name:void 0;o!==void 0&&(n.title=o),t.flags.hasReferencedOpenAiAnyType&&(s||(s={}),s[t.openAiAnyTypeName]||(s[t.openAiAnyTypeName]={type:["string","number","integer","boolean","array","null"],items:{$ref:t.$refStrategy==="relative"?"1":[...t.basePath,t.definitionPath,t.openAiAnyTypeName].join("/")}}));let i=r===void 0?s?{...n,[t.definitionPath]:s}:n:{$ref:[...t.$refStrategy==="relative"?[]:t.basePath,t.definitionPath,r].join("/"),[t.definitionPath]:{...s,[r]:n}};return t.target==="jsonSchema7"?i.$schema="http://json-schema.org/draft-07/schema#":(t.target==="jsonSchema2019-09"||t.target==="openAi")&&(i.$schema="https://json-schema.org/draft/2019-09/schema#"),t.target==="openAi"&&("anyOf"in i||"oneOf"in i||"allOf"in i||"type"in i&&Array.isArray(i.type))&&console.warn("Warning: OpenAI may not support schemas with unions as roots! Try wrapping it in an object property."),i};var Os;(function(a){a.Completable="McpCompletable"})(Os||(Os={}));var pt=class extends J{_parse(e){let{ctx:t}=this._processInputParams(e),s=t.data;return this._def.type._parse({data:s,path:t.path,parent:t})}unwrap(){return this._def.type}};pt.create=(a,e)=>new pt({type:a,typeName:Os.Completable,complete:e.complete,...jf(e)});function jf(a){if(!a)return{};let{errorMap:e,invalid_type_error:t,required_error:s,description:r}=a;if(e&&(t||s))throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);return e?{errorMap:e,description:r}:{errorMap:(o,i)=>{var c,f;let{message:p}=a;return o.code==="invalid_enum_value"?{message:p??i.defaultError}:typeof i.data>"u"?{message:(c=p??s)!==null&&c!==void 0?c:i.defaultError}:o.code!=="invalid_type"?{message:i.defaultError}:{message:(f=p??t)!==null&&f!==void 0?f:i.defaultError}},description:r}}var Ra=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 ya(e,t)}async connect(e){return await this.server.connect(e)}async close(){await this.server.close()}setToolRequestHandlers(){this._toolHandlersInitialized||(this.server.assertCanSetRequestHandler(Gt.shape.method.value),this.server.assertCanSetRequestHandler(Yt.shape.method.value),this.server.registerCapabilities({tools:{listChanged:!0}}),this.server.setRequestHandler(Gt,()=>({tools:Object.entries(this._registeredTools).filter(([,e])=>e.enabled).map(([e,t])=>{let s={name:e,title:t.title,description:t.description,inputSchema:t.inputSchema?Ea(t.inputSchema,{strictUnions:!0}):Nf,annotations:t.annotations};return t.outputSchema&&(s.outputSchema=Ea(t.outputSchema,{strictUnions:!0})),s})})),this.server.setRequestHandler(Yt,async(e,t)=>{let s=this._registeredTools[e.params.name];if(!s)throw new pe(fe.InvalidParams,`Tool ${e.params.name} not found`);if(!s.enabled)throw new pe(fe.InvalidParams,`Tool ${e.params.name} disabled`);let r;if(s.inputSchema){let n=await s.inputSchema.safeParseAsync(e.params.arguments);if(!n.success)throw new pe(fe.InvalidParams,`Invalid arguments for tool ${e.params.name}: ${n.error.message}`);let o=n.data,i=s.callback;try{r=await Promise.resolve(i(o,t))}catch(c){r={content:[{type:"text",text:c instanceof Error?c.message:String(c)}],isError:!0}}}else{let n=s.callback;try{r=await Promise.resolve(n(t))}catch(o){r={content:[{type:"text",text:o instanceof Error?o.message:String(o)}],isError:!0}}}if(s.outputSchema&&!r.isError){if(!r.structuredContent)throw new pe(fe.InvalidParams,`Tool ${e.params.name} has an output schema but no structured content was provided`);let n=await s.outputSchema.safeParseAsync(r.structuredContent);if(!n.success)throw new pe(fe.InvalidParams,`Invalid structured content for tool ${e.params.name}: ${n.error.message}`)}return r}),this._toolHandlersInitialized=!0)}setCompletionRequestHandler(){this._completionHandlerInitialized||(this.server.assertCanSetRequestHandler(Wt.shape.method.value),this.server.registerCapabilities({completions:{}}),this.server.setRequestHandler(Wt,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 pe(fe.InvalidParams,`Invalid completion reference: ${e.params.ref}`)}}),this._completionHandlerInitialized=!0)}async handlePromptCompletion(e,t){let s=this._registeredPrompts[t.name];if(!s)throw new pe(fe.InvalidParams,`Prompt ${t.name} not found`);if(!s.enabled)throw new pe(fe.InvalidParams,`Prompt ${t.name} disabled`);if(!s.argsSchema)return Sa;let r=s.argsSchema.shape[e.params.argument.name];if(!(r instanceof pt))return Sa;let o=await r._def.complete(e.params.argument.value,e.params.context);return al(o)}async handleResourceCompletion(e,t){let s=Object.values(this._registeredResourceTemplates).find(o=>o.resourceTemplate.uriTemplate.toString()===t.uri);if(!s){if(this._registeredResources[t.uri])return Sa;throw new pe(fe.InvalidParams,`Resource template ${e.params.ref.uri} not found`)}let r=s.resourceTemplate.completeCallback(e.params.argument.name);if(!r)return Sa;let n=await r(e.params.argument.value,e.params.context);return al(n)}setResourceRequestHandlers(){this._resourceHandlersInitialized||(this.server.assertCanSetRequestHandler(Zt.shape.method.value),this.server.assertCanSetRequestHandler(Qt.shape.method.value),this.server.assertCanSetRequestHandler(Bt.shape.method.value),this.server.registerCapabilities({resources:{listChanged:!0}}),this.server.setRequestHandler(Zt,async(e,t)=>{let s=Object.entries(this._registeredResources).filter(([n,o])=>o.enabled).map(([n,o])=>({uri:n,name:o.name,...o.metadata})),r=[];for(let n of Object.values(this._registeredResourceTemplates)){if(!n.resourceTemplate.listCallback)continue;let o=await n.resourceTemplate.listCallback(t);for(let i of o.resources)r.push({...n.metadata,...i})}return{resources:[...s,...r]}}),this.server.setRequestHandler(Qt,async()=>({resourceTemplates:Object.entries(this._registeredResourceTemplates).map(([t,s])=>({name:t,uriTemplate:s.resourceTemplate.uriTemplate.toString(),...s.metadata}))})),this.server.setRequestHandler(Bt,async(e,t)=>{let s=new URL(e.params.uri),r=this._registeredResources[s.toString()];if(r){if(!r.enabled)throw new pe(fe.InvalidParams,`Resource ${s} disabled`);return r.readCallback(s,t)}for(let n of Object.values(this._registeredResourceTemplates)){let o=n.resourceTemplate.uriTemplate.match(s.toString());if(o)return n.readCallback(s,o,t)}throw new pe(fe.InvalidParams,`Resource ${s} not found`)}),this.setCompletionRequestHandler(),this._resourceHandlersInitialized=!0)}setPromptRequestHandlers(){this._promptHandlersInitialized||(this.server.assertCanSetRequestHandler(Kt.shape.method.value),this.server.assertCanSetRequestHandler(Jt.shape.method.value),this.server.registerCapabilities({prompts:{listChanged:!0}}),this.server.setRequestHandler(Kt,()=>({prompts:Object.entries(this._registeredPrompts).filter(([,e])=>e.enabled).map(([e,t])=>({name:e,title:t.title,description:t.description,arguments:t.argsSchema?Ff(t.argsSchema):void 0}))})),this.server.setRequestHandler(Jt,async(e,t)=>{let s=this._registeredPrompts[e.params.name];if(!s)throw new pe(fe.InvalidParams,`Prompt ${e.params.name} not found`);if(!s.enabled)throw new pe(fe.InvalidParams,`Prompt ${e.params.name} disabled`);if(s.argsSchema){let r=await s.argsSchema.safeParseAsync(e.params.arguments);if(!r.success)throw new pe(fe.InvalidParams,`Invalid arguments for prompt ${e.params.name}: ${r.error.message}`);let n=r.data,o=s.callback;return await Promise.resolve(o(n,t))}else{let r=s.callback;return await Promise.resolve(r(t))}}),this.setCompletionRequestHandler(),this._promptHandlersInitialized=!0)}resource(e,t,...s){let r;typeof s[0]=="object"&&(r=s.shift());let n=s[0];if(typeof t=="string"){if(this._registeredResources[t])throw new Error(`Resource ${t} is already registered`);let o=this._createRegisteredResource(e,void 0,t,r,n);return this.setResourceRequestHandlers(),this.sendResourceListChanged(),o}else{if(this._registeredResourceTemplates[e])throw new Error(`Resource template ${e} is already registered`);let o=this._createRegisteredResourceTemplate(e,void 0,t,r,n);return this.setResourceRequestHandlers(),this.sendResourceListChanged(),o}}registerResource(e,t,s,r){if(typeof t=="string"){if(this._registeredResources[t])throw new Error(`Resource ${t} is already registered`);let n=this._createRegisteredResource(e,s.title,t,s,r);return this.setResourceRequestHandlers(),this.sendResourceListChanged(),n}else{if(this._registeredResourceTemplates[e])throw new Error(`Resource template ${e} is already registered`);let n=this._createRegisteredResourceTemplate(e,s.title,t,s,r);return this.setResourceRequestHandlers(),this.sendResourceListChanged(),n}}_createRegisteredResource(e,t,s,r,n){let o={name:e,title:t,metadata:r,readCallback:n,enabled:!0,disable:()=>o.update({enabled:!1}),enable:()=>o.update({enabled:!0}),remove:()=>o.update({uri:null}),update:i=>{typeof i.uri<"u"&&i.uri!==s&&(delete this._registeredResources[s],i.uri&&(this._registeredResources[i.uri]=o)),typeof i.name<"u"&&(o.name=i.name),typeof i.title<"u"&&(o.title=i.title),typeof i.metadata<"u"&&(o.metadata=i.metadata),typeof i.callback<"u"&&(o.readCallback=i.callback),typeof i.enabled<"u"&&(o.enabled=i.enabled),this.sendResourceListChanged()}};return this._registeredResources[s]=o,o}_createRegisteredResourceTemplate(e,t,s,r,n){let o={resourceTemplate:s,title:t,metadata:r,readCallback:n,enabled:!0,disable:()=>o.update({enabled:!1}),enable:()=>o.update({enabled:!0}),remove:()=>o.update({name:null}),update:i=>{typeof i.name<"u"&&i.name!==e&&(delete this._registeredResourceTemplates[e],i.name&&(this._registeredResourceTemplates[i.name]=o)),typeof i.title<"u"&&(o.title=i.title),typeof i.template<"u"&&(o.resourceTemplate=i.template),typeof i.metadata<"u"&&(o.metadata=i.metadata),typeof i.callback<"u"&&(o.readCallback=i.callback),typeof i.enabled<"u"&&(o.enabled=i.enabled),this.sendResourceListChanged()}};return this._registeredResourceTemplates[e]=o,o}_createRegisteredPrompt(e,t,s,r,n){let o={title:t,description:s,argsSchema:r===void 0?void 0:l.object(r),callback:n,enabled:!0,disable:()=>o.update({enabled:!1}),enable:()=>o.update({enabled:!0}),remove:()=>o.update({name:null}),update:i=>{typeof i.name<"u"&&i.name!==e&&(delete this._registeredPrompts[e],i.name&&(this._registeredPrompts[i.name]=o)),typeof i.title<"u"&&(o.title=i.title),typeof i.description<"u"&&(o.description=i.description),typeof i.argsSchema<"u"&&(o.argsSchema=l.object(i.argsSchema)),typeof i.callback<"u"&&(o.callback=i.callback),typeof i.enabled<"u"&&(o.enabled=i.enabled),this.sendPromptListChanged()}};return this._registeredPrompts[e]=o,o}_createRegisteredTool(e,t,s,r,n,o,i){let c={title:t,description:s,inputSchema:r===void 0?void 0:l.object(r),outputSchema:n===void 0?void 0:l.object(n),annotations:o,callback:i,enabled:!0,disable:()=>c.update({enabled:!1}),enable:()=>c.update({enabled:!0}),remove:()=>c.update({name:null}),update:f=>{typeof f.name<"u"&&f.name!==e&&(delete this._registeredTools[e],f.name&&(this._registeredTools[f.name]=c)),typeof f.title<"u"&&(c.title=f.title),typeof f.description<"u"&&(c.description=f.description),typeof f.paramsSchema<"u"&&(c.inputSchema=l.object(f.paramsSchema)),typeof f.callback<"u"&&(c.callback=f.callback),typeof f.annotations<"u"&&(c.annotations=f.annotations),typeof f.enabled<"u"&&(c.enabled=f.enabled),this.sendToolListChanged()}};return this._registeredTools[e]=c,this.setToolRequestHandlers(),this.sendToolListChanged(),c}tool(e,...t){if(this._registeredTools[e])throw new Error(`Tool ${e} is already registered`);let s,r,n,o;if(typeof t[0]=="string"&&(s=t.shift()),t.length>1){let c=t[0];tl(c)?(r=t.shift(),t.length>1&&typeof t[0]=="object"&&t[0]!==null&&!tl(t[0])&&(o=t.shift())):typeof c=="object"&&c!==null&&(o=t.shift())}let i=t[0];return this._createRegisteredTool(e,void 0,s,r,n,o,i)}registerTool(e,t,s){if(this._registeredTools[e])throw new Error(`Tool ${e} is already registered`);let{title:r,description:n,inputSchema:o,outputSchema:i,annotations:c}=t;return this._createRegisteredTool(e,r,n,o,i,c,s)}prompt(e,...t){if(this._registeredPrompts[e])throw new Error(`Prompt ${e} is already registered`);let s;typeof t[0]=="string"&&(s=t.shift());let r;t.length>1&&(r=t.shift());let n=t[0],o=this._createRegisteredPrompt(e,void 0,s,r,n);return this.setPromptRequestHandlers(),this.sendPromptListChanged(),o}registerPrompt(e,t,s){if(this._registeredPrompts[e])throw new Error(`Prompt ${e} is already registered`);let{title:r,description:n,argsSchema:o}=t,i=this._createRegisteredPrompt(e,r,n,o,s);return 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 Nf={type:"object",properties:{}};function tl(a){return typeof a!="object"||a===null?!1:Object.keys(a).length===0||Object.values(a).some(Lf)}function Lf(a){return a!==null&&typeof a=="object"&&"parse"in a&&typeof a.parse=="function"&&"safeParse"in a&&typeof a.safeParse=="function"}function Ff(a){return Object.entries(a.shape).map(([e,t])=>({name:e,description:t.description,required:!t.isOptional()}))}function al(a){return{completion:{values:a.slice(0,100),total:a.length,hasMore:a.length>100}}}var Sa={completion:{values:[],hasMore:!1}};import nl from"node:process";var wa=class{append(e){this._buffer=this._buffer?Buffer.concat([this._buffer,e]):e}readMessage(){if(!this._buffer)return null;let e=this._buffer.indexOf(`
7
7
  `);if(e===-1)return null;let t=this._buffer.toString("utf8",0,e).replace(/\r$/,"");return this._buffer=this._buffer.subarray(e+1),qf(t)}clear(){this._buffer=void 0}};function qf(a){return dn.parse(JSON.parse(a))}function sl(a){return JSON.stringify(a)+`
8
- `}var Ta=class{constructor(e=nl.stdin,t=nl.stdout){this._stdin=e,this._stdout=t,this._readBuffer=new wa,this._started=!1,this._ondata=s=>{this._readBuffer.append(s),this.processReadBuffer()},this._onerror=s=>{var r;(r=this.onerror)===null||r===void 0||r.call(this,s)}}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 s=this._readBuffer.readMessage();if(s===null)break;(e=this.onmessage)===null||e===void 0||e.call(this,s)}catch(s){(t=this.onerror)===null||t===void 0||t.call(this,s)}}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 s=sl(e);this._stdout.write(s)?t():this._stdout.once("drain",t)})}};var vr=l.object({key:l.enum(["Url","Host","Path"]).describe("Source key for matching: Url, Host, or Path."),operator:l.enum(["Equals","Contains","Matches","Wildcard_Matches"]).describe("Operator for matching: Equals, Contains, Matches, or Wildcard_Matches."),value:l.string().describe("Value to match against."),filters:l.object({requestMethod:l.array(l.string()).optional().describe("Array of allowed HTTP methods for matching."),requestPayload:l.object({key:l.string().describe("Key in the request payload."),value:l.string().describe("Value for the request payload key.")}).optional().describe("Request payload filter.")}).optional().describe("Optional filters for advanced matching.")}).describe("Source matching criteria for a rule."),Aa=l.object({source:vr,destinationType:l.string().describe("Type of destination for redirect."),destination:l.string().describe("Target URL for redirect.")}).describe("Redirect rule pair: source and destination info."),$a=l.object({source:vr}).describe("Cancel rule pair: source info only."),Oa=l.object({source:vr,from:l.string().describe("String to replace."),to:l.string().describe("Replacement string.")}).describe("Replace rule pair: source, from, and to info."),il=l.object({header:l.string().describe("Header name to modify."),type:l.enum(["Add","Remove","Modify"]).describe("Modification type: Add, Remove, or Modify."),value:l.string().optional().describe("Optional value for header modification.")}).describe("Header modification details."),Ia=l.object({source:vr,modifications:l.object({Request:l.array(il).optional().describe("Request header modifications."),Response:l.array(il).optional().describe("Response header modifications.")}).describe("Header modifications for request/response.")}).describe("Headers rule pair: source and modifications."),ka=l.object({source:vr,userAgent:l.string().describe("Custom user agent string.")}).describe("User agent rule pair: source and user agent."),Mf=l.object({param:l.string().describe("Query parameter name."),type:l.enum(["Add","Remove","Remove All"]).describe("Modification type for query param."),value:l.string().optional().describe("Optional value for query param modification.")}).describe("Query parameter modification details."),Da=l.object({source:vr,modifications:l.array(Mf).describe("Array of query parameter modifications.")}).describe("Query parameter rule pair: source and modifications."),Ca=l.object({source:vr,request:l.object({type:l.enum(["code","static"]).describe("Request type: code or static."),value:l.string().describe("Request content.")}).describe("Request details.")}).describe("Request rule pair: source and request."),ja=l.object({source:vr,response:l.object({type:l.enum(["code","static"]).describe("Response type: code or static."),value:l.string().describe("Response content."),resourceType:l.string().optional().describe("Optional resource type for response."),statusCode:l.union([l.string(),l.number()]).optional().describe("Optional status code for response."),statusText:l.string().optional().describe("Optional status text for response."),serveWithoutRequest:l.boolean().optional().describe("Whether to serve response without request.")}).describe("Response details.")}).describe("Response rule pair: source and response."),Na=l.object({source:vr,delay:l.string().refine(a=>/^\d+$/.test(a),{message:"Delay must be a string containing a number"}).describe("Delay value in milliseconds (stringified number).")}).describe("Delay rule pair: source and delay."),zg=l.enum(["Redirect","Cancel","Replace","Headers","UserAgent","QueryParam","Request","Response","Delay"]).describe("Enumeration of all supported rule types.");function gr(a,e){return ae.object({name:ae.string().describe("Name of the rule."),description:ae.string().optional().describe("Description of the rule."),ruleType:ae.literal(a).describe("Type of the rule."),status:ae.enum(["Active","Inactive"]).optional().default("Active").describe("Status of the rule."),pairs:ae.array(e).describe("List of rule pair objects for the rule type."),groupId:ae.string().optional().describe("ID of the group the rule belongs to.")})}var zf=()=>{let a={name:ae.string().describe("Name of the rule."),description:ae.string().optional().describe("Description of the rule."),ruleType:ae.enum(["Redirect","Cancel","Replace","Headers","UserAgent","QueryParam","Request","Response","Delay"]).describe("Type of the rule. This determines the structure of the pairs array."),status:ae.enum(["Active","Inactive"]).optional().default("Active").describe("Status of the rule."),groupId:ae.string().optional().describe("ID of the group the rule belongs to.")},e={Redirect:"Array of redirect pairs. Each pair must have: source (matching criteria), destinationType (string), destination (target URL)",Cancel:"Array of cancel pairs. Each pair must have: source (matching criteria to cancel requests)",Replace:"Array of replace pairs. Each pair must have: source (matching criteria), from (string to replace), to (replacement string)",Headers:"Array of header pairs. Each pair must have: source (matching criteria), modifications (array of header modifications with header, type, and optional value)",UserAgent:"Array of user agent pairs. Each pair must have: source (matching criteria), userAgent (custom user agent string)",QueryParam:"Array of query param pairs. Each pair must have: source (matching criteria), modifications (array of param modifications)",Request:'Array of request pairs. Each pair must have: type ("code" or "static"), value (request content)',Response:"Array of response pairs. Each pair must have: source (matching criteria), response (object with type, value, and optional serveWithoutRequest)",Delay:"Array of delay pairs. Each pair must have: source (matching criteria), delay (number in milliseconds)"};return{...a,pairs:ae.array(ae.unknown()).describe(`List of rule pair objects. Structure depends on ruleType:
8
+ `}var Ta=class{constructor(e=nl.stdin,t=nl.stdout){this._stdin=e,this._stdout=t,this._readBuffer=new wa,this._started=!1,this._ondata=s=>{this._readBuffer.append(s),this.processReadBuffer()},this._onerror=s=>{var r;(r=this.onerror)===null||r===void 0||r.call(this,s)}}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 s=this._readBuffer.readMessage();if(s===null)break;(e=this.onmessage)===null||e===void 0||e.call(this,s)}catch(s){(t=this.onerror)===null||t===void 0||t.call(this,s)}}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 s=sl(e);this._stdout.write(s)?t():this._stdout.once("drain",t)})}};var vr=l.object({key:l.enum(["Url","Host","Path"]).describe("Source key for matching: Url, Host, or Path."),operator:l.enum(["Equals","Contains","Matches","Wildcard_Matches"]).describe("Operator for matching: Equals, Contains, Matches, or Wildcard_Matches."),value:l.string().describe("Value to match against."),filters:l.array(l.object({requestMethod:l.array(l.string()).optional().describe("Array of allowed HTTP methods for matching."),requestPayload:l.object({key:l.string().describe("Key in the request payload."),value:l.string().describe("Value for the request payload key.")}).optional().describe("Request payload filter.")})).optional().describe("Array of filter objects for advanced matching.")}).describe("Source matching criteria for a rule."),Aa=l.object({source:vr,destinationType:l.string().describe("Type of destination for redirect."),destination:l.string().describe("Target URL for redirect.")}).describe("Redirect rule pair: source and destination info."),$a=l.object({source:vr}).describe("Cancel rule pair: source info only."),Oa=l.object({source:vr,from:l.string().describe("String to replace."),to:l.string().describe("Replacement string.")}).describe("Replace rule pair: source, from, and to info."),il=l.object({header:l.string().describe("Header name to modify."),type:l.enum(["Add","Remove","Modify"]).describe("Modification type: Add, Remove, or Modify."),value:l.string().optional().describe("Optional value for header modification.")}).describe("Header modification details."),Ia=l.object({source:vr,modifications:l.object({Request:l.array(il).optional().describe("Request header modifications."),Response:l.array(il).optional().describe("Response header modifications.")}).describe("Header modifications for request/response.")}).describe("Headers rule pair: source and modifications."),ka=l.object({source:vr,userAgent:l.string().describe("Custom user agent string.")}).describe("User agent rule pair: source and user agent."),Mf=l.object({param:l.string().describe("Query parameter name."),type:l.enum(["Add","Remove","Remove All"]).describe("Modification type for query param."),value:l.string().optional().describe("Optional value for query param modification.")}).describe("Query parameter modification details."),Da=l.object({source:vr,modifications:l.array(Mf).describe("Array of query parameter modifications.")}).describe("Query parameter rule pair: source and modifications."),Ca=l.object({source:vr,request:l.object({type:l.enum(["code","static"]).describe("Request type: code or static."),value:l.string().describe("Request content.")}).describe("Request details.")}).describe("Request rule pair: source and request."),ja=l.object({source:vr,response:l.object({type:l.enum(["code","static"]).describe("Response type: code or static."),value:l.string().describe("Response content."),resourceType:l.string().optional().describe("Optional resource type for response."),statusCode:l.union([l.string(),l.number()]).optional().describe("Optional status code for response."),statusText:l.string().optional().describe("Optional status text for response."),serveWithoutRequest:l.boolean().optional().describe("Whether to serve response without request.")}).describe("Response details.")}).describe("Response rule pair: source and response."),Na=l.object({source:vr,delay:l.string().refine(a=>/^\d+$/.test(a),{message:"Delay must be a string containing a number"}).describe("Delay value in milliseconds (stringified number).")}).describe("Delay rule pair: source and delay."),zg=l.enum(["Redirect","Cancel","Replace","Headers","UserAgent","QueryParam","Request","Response","Delay"]).describe("Enumeration of all supported rule types.");function gr(a,e){return ae.object({name:ae.string().describe("Name of the rule."),description:ae.string().optional().describe("Description of the rule."),ruleType:ae.literal(a).describe("Type of the rule."),status:ae.enum(["Active","Inactive"]).optional().default("Active").describe("Status of the rule."),pairs:ae.array(e).describe("List of rule pair objects for the rule type."),groupId:ae.string().optional().describe("ID of the group the rule belongs to.")})}var zf=()=>{let a={name:ae.string().describe("Name of the rule."),description:ae.string().optional().describe("Description of the rule."),ruleType:ae.enum(["Redirect","Cancel","Replace","Headers","UserAgent","QueryParam","Request","Response","Delay"]).describe("Type of the rule. This determines the structure of the pairs array."),status:ae.enum(["Active","Inactive"]).optional().default("Active").describe("Status of the rule."),groupId:ae.string().optional().describe("ID of the group the rule belongs to.")},e={Redirect:"Array of redirect pairs. Each pair must have: source (matching criteria), destinationType (string), destination (target URL)",Cancel:"Array of cancel pairs. Each pair must have: source (matching criteria to cancel requests)",Replace:"Array of replace pairs. Each pair must have: source (matching criteria), from (string to replace), to (replacement string)",Headers:"Array of header pairs. Each pair must have: source (matching criteria), modifications (array of header modifications with header, type, and optional value)",UserAgent:"Array of user agent pairs. Each pair must have: source (matching criteria), userAgent (custom user agent string)",QueryParam:"Array of query param pairs. Each pair must have: source (matching criteria), modifications (array of param modifications)",Request:'Array of request pairs. Each pair must have: type ("code" or "static"), value (request content)',Response:"Array of response pairs. Each pair must have: source (matching criteria), response (object with type, value, and optional serveWithoutRequest)",Delay:"Array of delay pairs. Each pair must have: source (matching criteria), delay (number in milliseconds)"};return{...a,pairs:ae.array(ae.unknown()).describe(`List of rule pair objects. Structure depends on ruleType:
9
9
 
10
10
  - Redirect: ${e.Redirect}
11
11
  - Cancel: ${e.Cancel}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@requestly/mcp",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "main": "build/index.js",
5
5
  "type": "module",
6
6
  "bin": {
@@ -4,13 +4,15 @@ export const SourceSchema = z.object({
4
4
  key: z.enum(['Url', 'Host', 'Path']).describe('Source key for matching: Url, Host, or Path.'),
5
5
  operator: z.enum(['Equals', 'Contains', 'Matches', 'Wildcard_Matches']).describe('Operator for matching: Equals, Contains, Matches, or Wildcard_Matches.'),
6
6
  value: z.string().describe('Value to match against.'),
7
- filters: z.object({
8
- requestMethod: z.array(z.string()).optional().describe('Array of allowed HTTP methods for matching.'),
9
- requestPayload: z.object({
10
- key: z.string().describe('Key in the request payload.'),
11
- value: z.string().describe('Value for the request payload key.'),
12
- }).optional().describe('Request payload filter.'),
13
- }).optional().describe('Optional filters for advanced matching.'),
7
+ filters: z.array(
8
+ z.object({
9
+ requestMethod: z.array(z.string()).optional().describe('Array of allowed HTTP methods for matching.'),
10
+ requestPayload: z.object({
11
+ key: z.string().describe('Key in the request payload.'),
12
+ value: z.string().describe('Value for the request payload key.'),
13
+ }).optional().describe('Request payload filter.'),
14
+ })
15
+ ).optional().describe('Array of filter objects for advanced matching.'),
14
16
  }).describe('Source matching criteria for a rule.');
15
17
 
16
18
  // All pair schemas...