fixparser-plugin-mcp 9.1.7-3e178996 → 9.1.7-3f807208

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,51 @@
1
1
  #!/usr/bin/env node
2
- "use strict";var g=require("fixparser");var x=require("@modelcontextprotocol/sdk/server/index.js"),_=require("@modelcontextprotocol/sdk/server/stdio.js"),T=require("@modelcontextprotocol/sdk/types.js"),u=require("zod"),p=require("zod"),Z=require("zod"),P=require("zod"),$=require("zod"),i=require("fixparser"),X=Symbol("Let zodToJsonSchema decide on which parser to use"),O={name:void 0,$refStrategy:"root",basePath:["#"],effectStrategy:"input",pipeStrategy:"all",dateStrategy:"format:date-time",mapStrategy:"entries",removeAdditionalStrategy:"passthrough",allowedAdditionalProperties:!0,rejectedAdditionalProperties:!1,definitionPath:"definitions",target:"jsonSchema7",strictUnions:!1,definitions:{},errorMessages:!1,markdownDescription:!1,patternStrategy:"escape",applyRegexFlags:!1,emailStrategy:"format:email",base64Strategy:"contentEncoding:base64",nameStrategy:"ref"},U=e=>typeof e=="string"?{...O,name:e}:{...O,...e},B=e=>{let t=U(e),n=t.name!==void 0?[...t.basePath,t.definitionPath,t.name]:t.basePath;return{...t,currentPath:n,propertyPath:void 0,seen:new Map(Object.entries(t.definitions).map(([r,a])=>[a._def,{def:a._def,path:[...t.basePath,t.definitionPath,r],jsonSchema:void 0}]))}};function N(e,t,n,r){r?.errorMessages&&n&&(e.errorMessage={...e.errorMessage,[t]:n})}function m(e,t,n,r,a){e[t]=n,N(e,t,r,a)}function J(){return{}}function H(e,t){let n={type:"array"};return e.type?._def&&e.type?._def?.typeName!==Z.ZodFirstPartyTypeKind.ZodAny&&(n.items=d(e.type._def,{...t,currentPath:[...t.currentPath,"items"]})),e.minLength&&m(n,"minItems",e.minLength.value,e.minLength.message,t),e.maxLength&&m(n,"maxItems",e.maxLength.value,e.maxLength.message,t),e.exactLength&&(m(n,"minItems",e.exactLength.value,e.exactLength.message,t),m(n,"maxItems",e.exactLength.value,e.exactLength.message,t)),n}function K(e,t){let n={type:"integer",format:"int64"};if(!e.checks)return n;for(let r of e.checks)switch(r.kind){case"min":t.target==="jsonSchema7"?r.inclusive?m(n,"minimum",r.value,r.message,t):m(n,"exclusiveMinimum",r.value,r.message,t):(r.inclusive||(n.exclusiveMinimum=!0),m(n,"minimum",r.value,r.message,t));break;case"max":t.target==="jsonSchema7"?r.inclusive?m(n,"maximum",r.value,r.message,t):m(n,"exclusiveMaximum",r.value,r.message,t):(r.inclusive||(n.exclusiveMaximum=!0),m(n,"maximum",r.value,r.message,t));break;case"multipleOf":m(n,"multipleOf",r.value,r.message,t);break}return n}function G(){return{type:"boolean"}}function E(e,t){return d(e.type._def,t)}var V=(e,t)=>d(e.innerType._def,t);function R(e,t,n){let r=n??t.dateStrategy;if(Array.isArray(r))return{anyOf:r.map((a,s)=>R(e,t,a))};switch(r){case"string":case"format:date-time":return{type:"string",format:"date-time"};case"format:date":return{type:"string",format:"date"};case"integer":return W(e,t)}}var W=(e,t)=>{let n={type:"integer",format:"unix-time"};if(t.target==="openApi3")return n;for(let r of e.checks)switch(r.kind){case"min":m(n,"minimum",r.value,r.message,t);break;case"max":m(n,"maximum",r.value,r.message,t);break}return n};function Q(e,t){return{...d(e.innerType._def,t),default:e.defaultValue()}}function Y(e,t){return t.effectStrategy==="input"?d(e.schema._def,t):{}}function ee(e){return{type:"string",enum:Array.from(e.values)}}var te=e=>"type"in e&&e.type==="string"?!1:"allOf"in e;function re(e,t){let n=[d(e.left._def,{...t,currentPath:[...t.currentPath,"allOf","0"]}),d(e.right._def,{...t,currentPath:[...t.currentPath,"allOf","1"]})].filter(s=>!!s),r=t.target==="jsonSchema2019-09"?{unevaluatedProperties:!1}:void 0,a=[];return n.forEach(s=>{if(te(s))a.push(...s.allOf),s.unevaluatedProperties===void 0&&(r=void 0);else{let c=s;if("additionalProperties"in s&&s.additionalProperties===!1){let{additionalProperties:l,...o}=s;c=o}else r=void 0;a.push(c)}}),a.length?{allOf:a,...r}:void 0}function ne(e,t){let n=typeof e.value;return n!=="bigint"&&n!=="number"&&n!=="boolean"&&n!=="string"?{type:Array.isArray(e.value)?"array":"object"}:t.target==="openApi3"?{type:n==="bigint"?"integer":n,enum:[e.value]}:{type:n==="bigint"?"integer":n,const:e.value}}var A=void 0,h={cuid:/^[cC][^\s-]{8,}$/,cuid2:/^[0-9a-z]+$/,ulid:/^[0-9A-HJKMNP-TV-Z]{26}$/,email:/^(?!\.)(?!.*\.\.)([a-zA-Z0-9_'+\-\.]*)[a-zA-Z0-9_+-]@([a-zA-Z0-9][a-zA-Z0-9\-]*\.)+[a-zA-Z]{2,}$/,emoji:()=>(A===void 0&&(A=RegExp("^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$","u")),A),uuid:/^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/,ipv4:/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,ipv4Cidr:/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/(3[0-2]|[12]?[0-9])$/,ipv6:/^(([a-f0-9]{1,4}:){7}|::([a-f0-9]{1,4}:){0,6}|([a-f0-9]{1,4}:){1}:([a-f0-9]{1,4}:){0,5}|([a-f0-9]{1,4}:){2}:([a-f0-9]{1,4}:){0,4}|([a-f0-9]{1,4}:){3}:([a-f0-9]{1,4}:){0,3}|([a-f0-9]{1,4}:){4}:([a-f0-9]{1,4}:){0,2}|([a-f0-9]{1,4}:){5}:([a-f0-9]{1,4}:){0,1})([a-f0-9]{1,4}|(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2})))$/,ipv6Cidr:/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,base64:/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,base64url:/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,nanoid:/^[a-zA-Z0-9_-]{21}$/,jwt:/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/};function C(e,t){let n={type:"string"};if(e.checks)for(let r of e.checks)switch(r.kind){case"min":m(n,"minLength",typeof n.minLength=="number"?Math.max(n.minLength,r.value):r.value,r.message,t);break;case"max":m(n,"maxLength",typeof n.maxLength=="number"?Math.min(n.maxLength,r.value):r.value,r.message,t);break;case"email":switch(t.emailStrategy){case"format:email":b(n,"email",r.message,t);break;case"format:idn-email":b(n,"idn-email",r.message,t);break;case"pattern:zod":y(n,h.email,r.message,t);break}break;case"url":b(n,"uri",r.message,t);break;case"uuid":b(n,"uuid",r.message,t);break;case"regex":y(n,r.regex,r.message,t);break;case"cuid":y(n,h.cuid,r.message,t);break;case"cuid2":y(n,h.cuid2,r.message,t);break;case"startsWith":y(n,RegExp(`^${I(r.value,t)}`),r.message,t);break;case"endsWith":y(n,RegExp(`${I(r.value,t)}$`),r.message,t);break;case"datetime":b(n,"date-time",r.message,t);break;case"date":b(n,"date",r.message,t);break;case"time":b(n,"time",r.message,t);break;case"duration":b(n,"duration",r.message,t);break;case"length":m(n,"minLength",typeof n.minLength=="number"?Math.max(n.minLength,r.value):r.value,r.message,t),m(n,"maxLength",typeof n.maxLength=="number"?Math.min(n.maxLength,r.value):r.value,r.message,t);break;case"includes":{y(n,RegExp(I(r.value,t)),r.message,t);break}case"ip":{r.version!=="v6"&&b(n,"ipv4",r.message,t),r.version!=="v4"&&b(n,"ipv6",r.message,t);break}case"base64url":y(n,h.base64url,r.message,t);break;case"jwt":y(n,h.jwt,r.message,t);break;case"cidr":{r.version!=="v6"&&y(n,h.ipv4Cidr,r.message,t),r.version!=="v4"&&y(n,h.ipv6Cidr,r.message,t);break}case"emoji":y(n,h.emoji(),r.message,t);break;case"ulid":{y(n,h.ulid,r.message,t);break}case"base64":{switch(t.base64Strategy){case"format:binary":{b(n,"binary",r.message,t);break}case"contentEncoding:base64":{m(n,"contentEncoding","base64",r.message,t);break}case"pattern:zod":{y(n,h.base64,r.message,t);break}}break}case"nanoid":y(n,h.nanoid,r.message,t);case"toLowerCase":case"toUpperCase":case"trim":break;default:}return n}function I(e,t){return t.patternStrategy==="escape"?ie(e):e}var ae=new Set("ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789");function ie(e){let t="";for(let n=0;n<e.length;n++)ae.has(e[n])||(t+="\\"),t+=e[n];return t}function b(e,t,n,r){e.format||e.anyOf?.some(a=>a.format)?(e.anyOf||(e.anyOf=[]),e.format&&(e.anyOf.push({format:e.format,...e.errorMessage&&r.errorMessages&&{errorMessage:{format:e.errorMessage.format}}}),delete e.format,e.errorMessage&&(delete e.errorMessage.format,Object.keys(e.errorMessage).length===0&&delete e.errorMessage)),e.anyOf.push({format:t,...n&&r.errorMessages&&{errorMessage:{format:n}}})):m(e,"format",t,n,r)}function y(e,t,n,r){e.pattern||e.allOf?.some(a=>a.pattern)?(e.allOf||(e.allOf=[]),e.pattern&&(e.allOf.push({pattern:e.pattern,...e.errorMessage&&r.errorMessages&&{errorMessage:{pattern:e.errorMessage.pattern}}}),delete e.pattern,e.errorMessage&&(delete e.errorMessage.pattern,Object.keys(e.errorMessage).length===0&&delete e.errorMessage)),e.allOf.push({pattern:D(t,r),...n&&r.errorMessages&&{errorMessage:{pattern:n}}})):m(e,"pattern",D(t,r),n,r)}function D(e,t){if(!t.applyRegexFlags||!e.flags)return e.source;let n={i:e.flags.includes("i"),m:e.flags.includes("m"),s:e.flags.includes("s")},r=n.i?e.source.toLowerCase():e.source,a="",s=!1,c=!1,l=!1;for(let o=0;o<r.length;o++){if(s){a+=r[o],s=!1;continue}if(n.i){if(c){if(r[o].match(/[a-z]/)){l?(a+=r[o],a+=`${r[o-2]}-${r[o]}`.toUpperCase(),l=!1):r[o+1]==="-"&&r[o+2]?.match(/[a-z]/)?(a+=r[o],l=!0):a+=`${r[o]}${r[o].toUpperCase()}`;continue}}else if(r[o].match(/[a-z]/)){a+=`[${r[o]}${r[o].toUpperCase()}]`;continue}}if(n.m){if(r[o]==="^"){a+=`(^|(?<=[\r
3
- ]))`;continue}else if(r[o]==="$"){a+=`($|(?=[\r
4
- ]))`;continue}}if(n.s&&r[o]==="."){a+=c?`${r[o]}\r
5
- `:`[${r[o]}\r
6
- ]`;continue}a+=r[o],r[o]==="\\"?s=!0:c&&r[o]==="]"?c=!1:!c&&r[o]==="["&&(c=!0)}try{new RegExp(a)}catch{return console.warn(`Could not convert regex pattern at ${t.currentPath.join("/")} to a flag-independent form! Falling back to the flag-ignorant source`),e.source}return a}function j(e,t){if(t.target==="openAi"&&console.warn("Warning: OpenAI may not support records in schemas! Try an array of key-value pairs instead."),t.target==="openApi3"&&e.keyType?._def.typeName===P.ZodFirstPartyTypeKind.ZodEnum)return{type:"object",required:e.keyType._def.values,properties:e.keyType._def.values.reduce((r,a)=>({...r,[a]:d(e.valueType._def,{...t,currentPath:[...t.currentPath,"properties",a]})??{}}),{}),additionalProperties:t.rejectedAdditionalProperties};let n={type:"object",additionalProperties:d(e.valueType._def,{...t,currentPath:[...t.currentPath,"additionalProperties"]})??t.allowedAdditionalProperties};if(t.target==="openApi3")return n;if(e.keyType?._def.typeName===P.ZodFirstPartyTypeKind.ZodString&&e.keyType._def.checks?.length){let{type:r,...a}=C(e.keyType._def,t);return{...n,propertyNames:a}}else{if(e.keyType?._def.typeName===P.ZodFirstPartyTypeKind.ZodEnum)return{...n,propertyNames:{enum:e.keyType._def.values}};if(e.keyType?._def.typeName===P.ZodFirstPartyTypeKind.ZodBranded&&e.keyType._def.type._def.typeName===P.ZodFirstPartyTypeKind.ZodString&&e.keyType._def.type._def.checks?.length){let{type:r,...a}=E(e.keyType._def,t);return{...n,propertyNames:a}}}return n}function se(e,t){if(t.mapStrategy==="record")return j(e,t);let n=d(e.keyType._def,{...t,currentPath:[...t.currentPath,"items","items","0"]})||{},r=d(e.valueType._def,{...t,currentPath:[...t.currentPath,"items","items","1"]})||{};return{type:"array",maxItems:125,items:{type:"array",items:[n,r],minItems:2,maxItems:2}}}function oe(e){let t=e.values,r=Object.keys(e.values).filter(s=>typeof t[t[s]]!="number").map(s=>t[s]),a=Array.from(new Set(r.map(s=>typeof s)));return{type:a.length===1?a[0]==="string"?"string":"number":["string","number"],enum:r}}function ue(){return{not:{}}}function ce(e){return e.target==="openApi3"?{enum:["null"],nullable:!0}:{type:"null"}}var k={ZodString:"string",ZodNumber:"number",ZodBigInt:"integer",ZodBoolean:"boolean",ZodNull:"null"};function pe(e,t){if(t.target==="openApi3")return F(e,t);let n=e.options instanceof Map?Array.from(e.options.values()):e.options;if(n.every(r=>r._def.typeName in k&&(!r._def.checks||!r._def.checks.length))){let r=n.reduce((a,s)=>{let c=k[s._def.typeName];return c&&!a.includes(c)?[...a,c]:a},[]);return{type:r.length>1?r:r[0]}}else if(n.every(r=>r._def.typeName==="ZodLiteral"&&!r.description)){let r=n.reduce((a,s)=>{let c=typeof s._def.value;switch(c){case"string":case"number":case"boolean":return[...a,c];case"bigint":return[...a,"integer"];case"object":if(s._def.value===null)return[...a,"null"];case"symbol":case"undefined":case"function":default:return a}},[]);if(r.length===n.length){let a=r.filter((s,c,l)=>l.indexOf(s)===c);return{type:a.length>1?a:a[0],enum:n.reduce((s,c)=>s.includes(c._def.value)?s:[...s,c._def.value],[])}}}else if(n.every(r=>r._def.typeName==="ZodEnum"))return{type:"string",enum:n.reduce((r,a)=>[...r,...a._def.values.filter(s=>!r.includes(s))],[])};return F(e,t)}var F=(e,t)=>{let n=(e.options instanceof Map?Array.from(e.options.values()):e.options).map((r,a)=>d(r._def,{...t,currentPath:[...t.currentPath,"anyOf",`${a}`]})).filter(r=>!!r&&(!t.strictUnions||typeof r=="object"&&Object.keys(r).length>0));return n.length?{anyOf:n}:void 0};function le(e,t){if(["ZodString","ZodNumber","ZodBigInt","ZodBoolean","ZodNull"].includes(e.innerType._def.typeName)&&(!e.innerType._def.checks||!e.innerType._def.checks.length))return t.target==="openApi3"?{type:k[e.innerType._def.typeName],nullable:!0}:{type:[k[e.innerType._def.typeName],"null"]};if(t.target==="openApi3"){let r=d(e.innerType._def,{...t,currentPath:[...t.currentPath]});return r&&"$ref"in r?{allOf:[r],nullable:!0}:r&&{...r,nullable:!0}}let n=d(e.innerType._def,{...t,currentPath:[...t.currentPath,"anyOf","0"]});return n&&{anyOf:[n,{type:"null"}]}}function de(e,t){let n={type:"number"};if(!e.checks)return n;for(let r of e.checks)switch(r.kind){case"int":n.type="integer",N(n,"type",r.message,t);break;case"min":t.target==="jsonSchema7"?r.inclusive?m(n,"minimum",r.value,r.message,t):m(n,"exclusiveMinimum",r.value,r.message,t):(r.inclusive||(n.exclusiveMinimum=!0),m(n,"minimum",r.value,r.message,t));break;case"max":t.target==="jsonSchema7"?r.inclusive?m(n,"maximum",r.value,r.message,t):m(n,"exclusiveMaximum",r.value,r.message,t):(r.inclusive||(n.exclusiveMaximum=!0),m(n,"maximum",r.value,r.message,t));break;case"multipleOf":m(n,"multipleOf",r.value,r.message,t);break}return n}function me(e,t){let n=t.target==="openAi",r={type:"object",properties:{}},a=[],s=e.shape();for(let l in s){let o=s[l];if(o===void 0||o._def===void 0)continue;let f=ye(o);f&&n&&(o instanceof $.ZodOptional&&(o=o._def.innerType),o.isNullable()||(o=o.nullable()),f=!1);let v=d(o._def,{...t,currentPath:[...t.currentPath,"properties",l],propertyPath:[...t.currentPath,"properties",l]});v!==void 0&&(r.properties[l]=v,f||a.push(l))}a.length&&(r.required=a);let c=ge(e,t);return c!==void 0&&(r.additionalProperties=c),r}function ge(e,t){if(e.catchall._def.typeName!=="ZodNever")return d(e.catchall._def,{...t,currentPath:[...t.currentPath,"additionalProperties"]});switch(e.unknownKeys){case"passthrough":return t.allowedAdditionalProperties;case"strict":return t.rejectedAdditionalProperties;case"strip":return t.removeAdditionalStrategy==="strict"?t.allowedAdditionalProperties:t.rejectedAdditionalProperties}}function ye(e){try{return e.isOptional()}catch{return!0}}var fe=(e,t)=>{if(t.currentPath.toString()===t.propertyPath?.toString())return d(e.innerType._def,t);let n=d(e.innerType._def,{...t,currentPath:[...t.currentPath,"anyOf","1"]});return n?{anyOf:[{not:{}},n]}:{}},he=(e,t)=>{if(t.pipeStrategy==="input")return d(e.in._def,t);if(t.pipeStrategy==="output")return d(e.out._def,t);let n=d(e.in._def,{...t,currentPath:[...t.currentPath,"allOf","0"]}),r=d(e.out._def,{...t,currentPath:[...t.currentPath,"allOf",n?"1":"0"]});return{allOf:[n,r].filter(a=>a!==void 0)}};function be(e,t){return d(e.type._def,t)}function ve(e,t){let r={type:"array",uniqueItems:!0,items:d(e.valueType._def,{...t,currentPath:[...t.currentPath,"items"]})};return e.minSize&&m(r,"minItems",e.minSize.value,e.minSize.message,t),e.maxSize&&m(r,"maxItems",e.maxSize.value,e.maxSize.message,t),r}function Pe(e,t){return e.rest?{type:"array",minItems:e.items.length,items:e.items.map((n,r)=>d(n._def,{...t,currentPath:[...t.currentPath,"items",`${r}`]})).reduce((n,r)=>r===void 0?n:[...n,r],[]),additionalItems:d(e.rest._def,{...t,currentPath:[...t.currentPath,"additionalItems"]})}:{type:"array",minItems:e.items.length,maxItems:e.items.length,items:e.items.map((n,r)=>d(n._def,{...t,currentPath:[...t.currentPath,"items",`${r}`]})).reduce((n,r)=>r===void 0?n:[...n,r],[])}}function Se(){return{not:{}}}function ke(){return{}}var Te=(e,t)=>d(e.innerType._def,t),Me=(e,t,n)=>{switch(t){case p.ZodFirstPartyTypeKind.ZodString:return C(e,n);case p.ZodFirstPartyTypeKind.ZodNumber:return de(e,n);case p.ZodFirstPartyTypeKind.ZodObject:return me(e,n);case p.ZodFirstPartyTypeKind.ZodBigInt:return K(e,n);case p.ZodFirstPartyTypeKind.ZodBoolean:return G();case p.ZodFirstPartyTypeKind.ZodDate:return R(e,n);case p.ZodFirstPartyTypeKind.ZodUndefined:return Se();case p.ZodFirstPartyTypeKind.ZodNull:return ce(n);case p.ZodFirstPartyTypeKind.ZodArray:return H(e,n);case p.ZodFirstPartyTypeKind.ZodUnion:case p.ZodFirstPartyTypeKind.ZodDiscriminatedUnion:return pe(e,n);case p.ZodFirstPartyTypeKind.ZodIntersection:return re(e,n);case p.ZodFirstPartyTypeKind.ZodTuple:return Pe(e,n);case p.ZodFirstPartyTypeKind.ZodRecord:return j(e,n);case p.ZodFirstPartyTypeKind.ZodLiteral:return ne(e,n);case p.ZodFirstPartyTypeKind.ZodEnum:return ee(e);case p.ZodFirstPartyTypeKind.ZodNativeEnum:return oe(e);case p.ZodFirstPartyTypeKind.ZodNullable:return le(e,n);case p.ZodFirstPartyTypeKind.ZodOptional:return fe(e,n);case p.ZodFirstPartyTypeKind.ZodMap:return se(e,n);case p.ZodFirstPartyTypeKind.ZodSet:return ve(e,n);case p.ZodFirstPartyTypeKind.ZodLazy:return()=>e.getter()._def;case p.ZodFirstPartyTypeKind.ZodPromise:return be(e,n);case p.ZodFirstPartyTypeKind.ZodNaN:case p.ZodFirstPartyTypeKind.ZodNever:return ue();case p.ZodFirstPartyTypeKind.ZodEffects:return Y(e,n);case p.ZodFirstPartyTypeKind.ZodAny:return J();case p.ZodFirstPartyTypeKind.ZodUnknown:return ke();case p.ZodFirstPartyTypeKind.ZodDefault:return Q(e,n);case p.ZodFirstPartyTypeKind.ZodBranded:return E(e,n);case p.ZodFirstPartyTypeKind.ZodReadonly:return Te(e,n);case p.ZodFirstPartyTypeKind.ZodCatch:return V(e,n);case p.ZodFirstPartyTypeKind.ZodPipeline:return he(e,n);case p.ZodFirstPartyTypeKind.ZodFunction:case p.ZodFirstPartyTypeKind.ZodVoid:case p.ZodFirstPartyTypeKind.ZodSymbol:return;default:return(r=>{})(t)}};function d(e,t,n=!1){let r=t.seen.get(e);if(t.override){let l=t.override?.(e,t,r,n);if(l!==X)return l}if(r&&!n){let l=Ae(r,t);if(l!==void 0)return l}let a={def:e,path:t.currentPath,jsonSchema:void 0};t.seen.set(e,a);let s=Me(e,e.typeName,t),c=typeof s=="function"?d(s(),t):s;if(c&&we(e,t,c),t.postProcess){let l=t.postProcess(c,e,t);return a.jsonSchema=c,l}return a.jsonSchema=c,c}var Ae=(e,t)=>{switch(t.$refStrategy){case"root":return{$ref:e.path.join("/")};case"relative":return{$ref:Ie(t.currentPath,e.path)};case"none":case"seen":return e.path.length<t.currentPath.length&&e.path.every((n,r)=>t.currentPath[r]===n)?(console.warn(`Recursive reference detected at ${t.currentPath.join("/")}! Defaulting to any`),{}):t.$refStrategy==="seen"?{}:void 0}},Ie=(e,t)=>{let n=0;for(;n<e.length&&n<t.length&&e[n]===t[n];n++);return[(e.length-n).toString(),...t.slice(n)].join("/")},we=(e,t,n)=>(e.description&&(n.description=e.description,t.markdownDescription&&(n.markdownDescription=e.description)),n),S=(e,t)=>{let n=B(t),r=typeof t=="object"&&t.definitions?Object.entries(t.definitions).reduce((o,[f,v])=>({...o,[f]:d(v._def,{...n,currentPath:[...n.basePath,n.definitionPath,f]},!0)??{}}),{}):void 0,a=typeof t=="string"?t:t?.nameStrategy==="title"?void 0:t?.name,s=d(e._def,a===void 0?n:{...n,currentPath:[...n.basePath,n.definitionPath,a]},!1)??{},c=typeof t=="object"&&t.name!==void 0&&t.nameStrategy==="title"?t.name:void 0;c!==void 0&&(s.title=c);let l=a===void 0?r?{...s,[n.definitionPath]:r}:s:{$ref:[...n.$refStrategy==="relative"?[]:n.basePath,n.definitionPath,a].join("/"),[n.definitionPath]:{...r,[a]:s}};return n.target==="jsonSchema7"?l.$schema="http://json-schema.org/draft-07/schema#":(n.target==="jsonSchema2019-09"||n.target==="openAi")&&(l.$schema="https://json-schema.org/draft/2019-09/schema#"),n.target==="openAi"&&("anyOf"in l||"oneOf"in l||"allOf"in l||"type"in l&&Array.isArray(l.type))&&console.warn("Warning: OpenAI may not support schemas with unions as roots! Try wrapping it in an object property."),l},q=class{logger;parser;server=new x.Server({name:"fixparser",version:"1.0.0"},{capabilities:{tools:{}}});transport=new _.StdioServerTransport;onReady=void 0;pendingRequests=new Map;constructor({logger:e,onReady:t}){e&&(this.logger=e),t&&(this.onReady=t)}async register(e){this.parser=e,this.parser.addOnMessageCallback(t=>{this.logger?.log({level:"info",message:`FIXParser (MCP): (${e.protocol?.toUpperCase()}): << received ${t.description}`});let n=t.messageType;if(n===i.Messages.MarketDataSnapshotFullRefresh||n===i.Messages.ExecutionReport){let r=n===i.Messages.MarketDataSnapshotFullRefresh?t.getField(i.Fields.MDReqID):t.getField(i.Fields.ClOrdID);if(r){let a=r.value;if(typeof a=="string"||typeof a=="number"){let s=this.pendingRequests.get(String(a));s&&(s(t),this.pendingRequests.delete(String(a)))}}}}),this.logger=e.logger,this.addWorkflows(),await this.server.connect(this.transport),this.onReady&&this.onReady()}addWorkflows(){if(!this.parser){this.logger?.log({level:"error",message:"FIXParser (MCP): -- FIXParser instance not initialized. Ignoring setup of workflows..."});return}if(!this.server){this.logger?.log({level:"error",message:"FIXParser (MCP): -- MCP Server not initialized. Ignoring setup of workflows..."});return}this.server.setRequestHandler(T.ListToolsRequestSchema,async()=>({tools:[{name:"parse",description:"Parses a FIX message and describes it in plain language",inputSchema:S(u.z.object({fixString:u.z.string().describe("FIX message string to parse")}),{name:"ParseInput"})},{name:"parseToJSON",description:"Parses a FIX message into JSON",inputSchema:S(u.z.object({fixString:u.z.string().describe("FIX message string to parse")}),{name:"ParseToJSONInput"})},{name:"newOrderSingle",description:"Creates and sends a New Order Single",inputSchema:S(u.z.object({clOrdID:u.z.string().describe("Client Order ID"),handlInst:u.z.enum(["1","2","3"]).default(i.HandlInst.AutomatedExecutionNoIntervention).optional().describe("Handling instruction"),quantity:u.z.number().describe("Order quantity"),price:u.z.number().describe("Order price"),ordType:u.z.enum(["1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H","I","J","K","L","M","P","Q","R","S"]).default("1").optional().describe("Order type"),side:u.z.enum(["1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H"]).describe("Order side (1=Buy, 2=Sell)"),symbol:u.z.string().describe("Trading symbol"),timeInForce:u.z.enum(["0","1","2","3","4","5","6","7","8","9","A","B","C"]).default(i.TimeInForce.Day).optional().describe("Time in force")}),{name:"NewOrderSingleInput"})},{name:"marketDataRequest",description:"Sends a request for Market Data with the given symbol",inputSchema:S(u.z.object({mdUpdateType:u.z.enum(["0","1"]).default("0").optional().describe("Market data update type"),symbol:u.z.string().describe("Trading symbol"),mdReqID:u.z.string().describe("Market data request ID"),subscriptionRequestType:u.z.enum(["0","1","2"]).default(i.SubscriptionRequestType.SnapshotAndUpdates).optional().describe("Subscription request type"),mdEntryType:u.z.enum(["0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H","J","K","L","M","N","O","P","Q","S","R","T","U","V","W","X","Y","Z","a","b","c","d","e","g","h","i","t"]).default(i.MDEntryType.Bid).optional().describe("Market data entry type")}),{name:"MarketDataRequestInput"})}]})),this.server.setRequestHandler(T.CallToolRequestSchema,async e=>{let{name:t,arguments:n}=e.params;switch(t){case"parse":{let{fixString:r}=u.z.object({fixString:u.z.string().describe("FIX message string to parse")}).parse(n||{});try{let a=this.parser?.parse(r);return!a||a.length===0?{isError:!0,content:[{type:"text",text:"Error: Failed to parse FIX string"}]}:{content:[{type:"text",text:`Parsed FIX message: ${r} (placeholder implementation)`}]}}catch{return{isError:!0,content:[{type:"text",text:"Error: Failed to parse FIX string"}]}}}case"parseToJSON":{let{fixString:r}=u.z.object({fixString:u.z.string().describe("FIX message string to parse")}).parse(n||{});try{let a=this.parser?.parse(r);return!a||a.length===0?{isError:!0,content:[{type:"text",text:"Error: Failed to parse FIX string"}]}:{content:[{type:"text",text:JSON.stringify({fixString:r,parsed:"placeholder"})}]}}catch{return{isError:!0,content:[{type:"text",text:"Error: Failed to parse FIX string"}]}}}case"newOrderSingle":{let{clOrdID:r,handlInst:a,quantity:s,price:c,ordType:l,side:o,symbol:f,timeInForce:v}=u.z.object({clOrdID:u.z.string().describe("Client Order ID"),handlInst:u.z.enum(["1","2","3"]).default(i.HandlInst.AutomatedExecutionNoIntervention).optional().describe("Handling instruction"),quantity:u.z.number().describe("Order quantity"),price:u.z.number().describe("Order price"),ordType:u.z.enum(["1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H","I","J","K","L","M","P","Q","R","S"]).default(i.OrdType.Market).optional().describe("Order type"),side:u.z.enum(["1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H"]).describe("Order side (1=Buy, 2=Sell)"),symbol:u.z.string().describe("Trading symbol"),timeInForce:u.z.enum(["0","1","2","3","4","5","6","7","8","9","A","B","C"]).default(i.TimeInForce.Day).optional().describe("Time in force")}).parse(n||{}),M=new Promise(z=>{this.pendingRequests.set(r,z)}),w=this.parser?.createMessage(new i.Field(i.Fields.MsgType,i.Messages.NewOrderSingle),new i.Field(i.Fields.MsgSeqNum,this.parser?.getNextTargetMsgSeqNum()),new i.Field(i.Fields.SenderCompID,this.parser?.sender),new i.Field(i.Fields.TargetCompID,this.parser?.target),new i.Field(i.Fields.SendingTime,this.parser?.getTimestamp()),new i.Field(i.Fields.ClOrdID,r),new i.Field(i.Fields.Side,o),new i.Field(i.Fields.Symbol,f),new i.Field(i.Fields.OrderQty,s),new i.Field(i.Fields.Price,c),new i.Field(i.Fields.OrdType,l),new i.Field(i.Fields.HandlInst,a),new i.Field(i.Fields.TimeInForce,v),new i.Field(i.Fields.TransactTime,this.parser?.getTimestamp()));if(!this.parser?.connected)return this.logger?.log({level:"error",message:"FIXParser (MCP): -- Not connected. Ignoring message."}),{isError:!0,content:[{type:"text",text:"Error: Not connected. Ignoring message."}]};this.parser?.send(w),this.logger?.log({level:"info",message:`FIXParser (MCP): (${this.parser?.protocol?.toUpperCase()}): >> sent ${w?.description}`});let L=await M;return{content:[{type:"text",text:`Execution Report for order ${r}: ${JSON.stringify(L.toFIXJSON())}`}]}}case"marketDataRequest":{let{mdUpdateType:r,symbol:a,mdReqID:s,subscriptionRequestType:c,mdEntryType:l}=u.z.object({mdUpdateType:u.z.enum(["0","1"]).default("0").optional().describe("Market data update type"),symbol:u.z.string().describe("Trading symbol"),mdReqID:u.z.string().describe("Market data request ID"),subscriptionRequestType:u.z.enum(["0","1","2"]).default(i.SubscriptionRequestType.SnapshotAndUpdates).optional().describe("Subscription request type"),mdEntryType:u.z.enum(["0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H","J","K","L","M","N","O","P","Q","S","R","T","U","V","W","X","Y","Z","a","b","c","d","e","g","h","i","t"]).default(i.MDEntryType.Bid).optional().describe("Market data entry type")}).parse(n||{}),o=new Promise(M=>{this.pendingRequests.set(s,M)}),f=this.parser?.createMessage(new i.Field(i.Fields.MsgType,i.Messages.MarketDataRequest),new i.Field(i.Fields.SenderCompID,this.parser?.sender),new i.Field(i.Fields.MsgSeqNum,this.parser?.getNextTargetMsgSeqNum()),new i.Field(i.Fields.TargetCompID,this.parser?.target),new i.Field(i.Fields.SendingTime,this.parser?.getTimestamp()),new i.Field(i.Fields.MarketDepth,0),new i.Field(i.Fields.MDUpdateType,r),new i.Field(i.Fields.NoRelatedSym,1),new i.Field(i.Fields.Symbol,a),new i.Field(i.Fields.MDReqID,s),new i.Field(i.Fields.SubscriptionRequestType,c),new i.Field(i.Fields.NoMDEntryTypes,1),new i.Field(i.Fields.MDEntryType,l));if(!this.parser?.connected)return this.logger?.log({level:"error",message:"FIXParser (MCP): -- Not connected. Ignoring message."}),{isError:!0,content:[{type:"text",text:"Error: Not connected. Ignoring message."}]};this.parser?.send(f),this.logger?.log({level:"info",message:`FIXParser (MCP): (${this.parser?.protocol?.toUpperCase()}): >> sent ${f?.description}`});let v=await o;return{content:[{type:"text",text:`Market data for ${a}: ${JSON.stringify(v.toFIXJSON())}`}]}}default:throw new Error(`Unknown tool: ${t}`)}}),process.on("SIGINT",async()=>{await this.server.close(),process.exit(0)})}};var Oe=async()=>{await g.LicenseManager.setLicenseKey(process.env.FIXPARSER_LICENSE_KEY);let e=new g.FIXParser({plugins:[new q({port:3099,onReady:()=>{}})]}),t=()=>{let s=e.createMessage(new g.Field(g.Fields.MsgType,g.Messages.Logon),new g.Field(g.Fields.MsgSeqNum,e.getNextTargetMsgSeqNum()),new g.Field(g.Fields.SenderCompID,n),new g.Field(g.Fields.SendingTime,e.getTimestamp()),new g.Field(g.Fields.TargetCompID,r),new g.Field(g.Fields.ResetSeqNumFlag,g.ResetSeqNumFlag.Yes),new g.Field(g.Fields.EncryptMethod,g.EncryptMethod.None),new g.Field(g.Fields.HeartBtInt,10));e.send(s)},n="CLIENT2",r="EXECUTOR",a={host:"localhost",port:5001,protocol:"tcp",sender:n,target:r,fixVersion:"FIX.4.4",logging:!1,onOpen:()=>{t()},onMessage:s=>{},onClose:()=>{}};e.connect(a)};Oe().catch(e=>console.error("Error initializing server:",e));
2
+ "use strict";var n=require("fixparser");var S=class{format;constructor({format:c="json"}){this.format=c}configure(c){this.format=c.format||"json"}async send(c){if(this.format==="json")console.log(JSON.stringify(c));else if(this.format==="jsonrpc"){let{message:a,...o}=c,r={jsonrpc:"2.0",method:c.level,params:{message:a,...o},id:c.id||Date.now()};console.log(JSON.stringify(r))}else{let{name:a,id:o,message:r,level:t,...i}=c,d=Object.entries(i).map(([s,g])=>`${s}: ${g}`),p="";a&&(p+=`${a} `),p+=`${o}: ${r}`,console.log(p,d.join(", "))}}async flush(){}async close(){}status(){return"connected"}};var b=require("@modelcontextprotocol/sdk/server/index.js"),T=require("@modelcontextprotocol/sdk/server/stdio.js"),e=require("fixparser"),l=require("zod"),O=class{parser;server=new b.Server({name:"fixparser",version:"1.0.0"},{capabilities:{tools:{parse:{description:"Parses a FIX message and describes it in plain language",parameters:{type:"object",properties:{fixString:{type:"string"}},required:["fixString"]}},parseToJSON:{description:"Parses a FIX message into JSON",parameters:{type:"object",properties:{fixString:{type:"string"}},required:["fixString"]}},verifyOrder:{description:"Verifies order parameters before execution",parameters:{type:"object",properties:{clOrdID:{type:"string"},handlInst:{type:"string",enum:["1","2","3"]},quantity:{type:"string"},price:{type:"string"},ordType:{type:"string",enum:["1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H","I","J","K","L","M","P","Q","R","S"]},side:{type:"string",enum:["1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H"]},symbol:{type:"string"},timeInForce:{type:"string",enum:["0","1","2","3","4","5","6","7","8","9","A","B","C"]}},required:["clOrdID","handlInst","quantity","price","ordType","side","symbol","timeInForce"]}},executeOrder:{description:"Executes a verified order",parameters:{type:"object",properties:{clOrdID:{type:"string"},handlInst:{type:"string",enum:["1","2","3"]},quantity:{type:"string"},price:{type:"string"},ordType:{type:"string"},side:{type:"string"},symbol:{type:"string"},timeInForce:{type:"string"}},required:["clOrdID","handlInst","quantity","price","ordType","side","symbol","timeInForce"]}},marketDataRequest:{description:"Requests market data for specified symbols",parameters:{type:"object",properties:{mdUpdateType:{type:"string",enum:["0","1"]},symbols:{type:"array",items:{type:"string"}},mdReqID:{type:"string"},subscriptionRequestType:{type:"string",enum:["0","1","2"]},mdEntryTypes:{type:"array",items:{type:"string"}}},required:["mdUpdateType","symbols","mdReqID","subscriptionRequestType","mdEntryTypes"]}},getStockGraph:{description:"Generates a price chart for a given symbol",parameters:{type:"object",properties:{symbol:{type:"string"}},required:["symbol"]}},getStockPriceHistory:{description:"Returns price history for a given symbol",parameters:{type:"object",properties:{symbol:{type:"string"}},required:["symbol"]}}},resources:{greeting:{description:"A simple greeting resource",uri:"greeting-resource"},stockGraph:{description:"Generates a price chart for a given symbol",uri:"stockGraph/{symbol}"},stockPriceHistory:{description:"Returns price history for a given symbol",uri:"stockPriceHistory/{symbol}"}}}});transport=new T.StdioServerTransport;onReady=void 0;pendingRequests=new Map;verifiedOrders=new Map;marketDataPrices=new Map;MAX_PRICE_HISTORY=1e5;constructor({logger:c,onReady:a}){a&&(this.onReady=a)}async register(c){this.parser=c,this.parser.addOnMessageCallback(a=>{this.parser?.logger.log({level:"info",message:`MCP Server received message: ${a.messageType}: ${a.description}`});let o=a.messageType;if(o===e.Messages.MarketDataSnapshotFullRefresh||o===e.Messages.ExecutionReport||o===e.Messages.Reject||o===e.Messages.MarketDataIncrementalRefresh){this.parser?.logger.log({level:"info",message:`MCP Server handling message type: ${o}`});let r;if(o===e.Messages.MarketDataIncrementalRefresh||o===e.Messages.MarketDataSnapshotFullRefresh){let t=a.getField(e.Fields.Symbol),i=a.getField(e.Fields.MDEntryPx),d=a.getField(e.Fields.MDEntryTime)?.value||Date.now();if(t?.value&&i?.value){let p=String(t.value),s=Number(i.value),g=this.marketDataPrices.get(p)||[];g.push({timestamp:Number(d),price:s}),g.length>this.MAX_PRICE_HISTORY&&g.shift(),this.marketDataPrices.set(p,g),this.parser?.logger.log({level:"info",message:`MCP Server added ${t}: ${s}`}),this.server.notification({method:"priceUpdate",params:{symbol:p,price:s,timestamp:Number(d)}})}}if(o===e.Messages.MarketDataSnapshotFullRefresh){let t=a.getField(e.Fields.MDReqID);t&&(r=String(t.value))}else if(o===e.Messages.ExecutionReport){let t=a.getField(e.Fields.ClOrdID);t&&(r=String(t.value))}else if(o===e.Messages.Reject){let t=a.getField(e.Fields.RefSeqNum);t&&(r=String(t.value))}if(r){let t=this.pendingRequests.get(r);t&&(t(a),this.pendingRequests.delete(r))}}}),this.addWorkflows(),await this.server.connect(this.transport),this.onReady&&this.onReady()}addWorkflows(){this.parser&&this.server&&(this.server.setRequestHandler(l.z.object({method:l.z.literal("resources/list")}),async(c,a)=>({resources:[{name:"greeting",description:"A simple greeting resource",uri:"greeting-resource"}]})),this.server.setRequestHandler(l.z.object({method:l.z.literal("resources/templates/list")}),async(c,a)=>({resourceTemplates:[{name:"stockGraph",description:"Generates a price chart for a given symbol",uriTemplate:"stockGraph/{symbol}",parameters:{type:"object",properties:{symbol:{type:"string"}},required:["symbol"]}},{name:"stockPriceHistory",description:"Returns price history for a given symbol",uriTemplate:"stockPriceHistory/{symbol}",parameters:{type:"object",properties:{symbol:{type:"string"}},required:["symbol"]}}]})),this.server.setRequestHandler(l.z.object({method:l.z.literal("tools/list")}),async(c,a)=>({tools:[{name:"parse",description:"Parses a FIX message and describes it in plain language",inputSchema:{type:"object",properties:{fixString:{type:"string"}},required:["fixString"]}},{name:"parseToJSON",description:"Parses a FIX message into JSON",inputSchema:{type:"object",properties:{fixString:{type:"string"}},required:["fixString"]}},{name:"verifyOrder",description:"Verifies order parameters before execution",inputSchema:{type:"object",properties:{clOrdID:{type:"string"},handlInst:{type:"string",enum:["1","2","3"]},quantity:{type:"string"},price:{type:"string"},ordType:{type:"string",enum:["1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H","I","J","K","L","M","P","Q","R","S"]},side:{type:"string",enum:["1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H"]},symbol:{type:"string"},timeInForce:{type:"string",enum:["0","1","2","3","4","5","6","7","8","9","A","B","C"]}},required:["clOrdID","handlInst","quantity","price","ordType","side","symbol","timeInForce"]}},{name:"executeOrder",description:"Executes a verified order",inputSchema:{type:"object",properties:{clOrdID:{type:"string"},handlInst:{type:"string",enum:["1","2","3"]},quantity:{type:"string"},price:{type:"string"},ordType:{type:"string"},side:{type:"string"},symbol:{type:"string"},timeInForce:{type:"string"}},required:["clOrdID","handlInst","quantity","price","ordType","side","symbol","timeInForce"]}},{name:"marketDataRequest",description:"Requests market data for specified symbols",inputSchema:{type:"object",properties:{mdUpdateType:{type:"string",enum:["0","1"]},symbols:{type:"array",items:{type:"string"}},mdReqID:{type:"string"},subscriptionRequestType:{type:"string",enum:["0","1","2"]},mdEntryTypes:{type:"array",items:{type:"string"}}},required:["mdUpdateType","symbols","mdReqID","subscriptionRequestType","mdEntryTypes"]}}]})),this.server.setRequestHandler(l.z.object({method:l.z.literal("tools/call"),params:l.z.object({name:l.z.string(),arguments:l.z.any(),_meta:l.z.object({progressToken:l.z.number()}).optional()})}),async(c,a)=>{let{name:o,arguments:r}=c.params;switch(o){case"parse":try{let t=this.parser?.parse(r.fixString);return!t||t.length===0?{contents:[{type:"text",text:"Error: Failed to parse FIX string",uri:"parse"}],isError:!0}:{contents:[{type:"text",text:`${t[0].description}
3
+ ${t[0].messageTypeDescription}`,uri:"parse"}]}}catch(t){return{contents:[{type:"text",text:`Error: ${t instanceof Error?t.message:"Failed to parse FIX string"}`,uri:"parse"}],isError:!0}}case"parseToJSON":try{let t=this.parser?.parse(r.fixString);return!t||t.length===0?{contents:[{type:"text",text:"Error: Failed to parse FIX string",uri:"parseToJSON"}],isError:!0}:{contents:[{type:"text",text:`${t[0].toFIXJSON()}`,uri:"parseToJSON"}]}}catch(t){return{contents:[{type:"text",text:`Error: ${t instanceof Error?t.message:"Failed to parse FIX string"}`,uri:"parseToJSON"}],isError:!0}}case"verifyOrder":try{this.verifiedOrders.set(r.clOrdID,{clOrdID:r.clOrdID,handlInst:r.handlInst,quantity:Number.parseFloat(r.quantity),price:Number.parseFloat(r.price),ordType:r.ordType,side:r.side,symbol:r.symbol,timeInForce:r.timeInForce});let t={1:"Market",2:"Limit",3:"Stop",4:"StopLimit",5:"MarketOnClose",6:"WithOrWithout",7:"LimitOrBetter",8:"LimitWithOrWithout",9:"OnBasis",A:"OnClose",B:"LimitOnClose",C:"ForexMarket",D:"PreviouslyQuoted",E:"PreviouslyIndicated",F:"ForexLimit",G:"ForexSwap",H:"ForexPreviouslyQuoted",I:"Funari",J:"MarketIfTouched",K:"MarketWithLeftOverAsLimit",L:"PreviousFundValuationPoint",M:"NextFundValuationPoint",P:"Pegged",Q:"CounterOrderSelection",R:"StopOnBidOrOffer",S:"StopLimitOnBidOrOffer"},i={1:"Buy",2:"Sell",3:"BuyMinus",4:"SellPlus",5:"SellShort",6:"SellShortExempt",7:"Undisclosed",8:"Cross",9:"CrossShort",A:"CrossShortExempt",B:"AsDefined",C:"Opposite",D:"Subscribe",E:"Redeem",F:"Lend",G:"Borrow",H:"SellUndisclosed"},d={0:"Day",1:"GoodTillCancel",2:"AtTheOpening",3:"ImmediateOrCancel",4:"FillOrKill",5:"GoodTillCrossing",6:"GoodTillDate",7:"AtTheClose",8:"GoodThroughCrossing",9:"AtCrossing",A:"GoodForTime",B:"GoodForAuction",C:"GoodForMonth"},p={1:"AutomatedExecutionNoIntervention",2:"AutomatedExecutionInterventionOK",3:"ManualOrder"};return{contents:[{type:"text",text:`VERIFICATION: All parameters valid. Ready to proceed with order execution.
4
+
5
+ Parameters verified:
6
+ - ClOrdID: ${r.clOrdID}
7
+ - HandlInst: ${r.handlInst} (${p[r.handlInst]})
8
+ - Quantity: ${r.quantity}
9
+ - Price: ${r.price}
10
+ - OrdType: ${r.ordType} (${t[r.ordType]})
11
+ - Side: ${r.side} (${i[r.side]})
12
+ - Symbol: ${r.symbol}
13
+ - TimeInForce: ${r.timeInForce} (${d[r.timeInForce]})
14
+
15
+ To execute this order, call the executeOrder tool with these exact same parameters.`,uri:"verifyOrder"}]}}catch(t){return{contents:[{type:"text",text:`Error: ${t instanceof Error?t.message:"Failed to verify order parameters"}`,uri:"verifyOrder"}],isError:!0}}case"executeOrder":try{let t=this.verifiedOrders.get(r.clOrdID);if(!t)return{contents:[{type:"text",text:`Error: Order ${r.clOrdID} has not been verified. Please call verifyOrder first.`,uri:"executeOrder"}],isError:!0};if(t.handlInst!==r.handlInst||t.quantity!==Number.parseFloat(r.quantity)||t.price!==Number.parseFloat(r.price)||t.ordType!==r.ordType||t.side!==r.side||t.symbol!==r.symbol||t.timeInForce!==r.timeInForce)return{contents:[{type:"text",text:"Error: Order parameters do not match the verified order. Please use the exact same parameters that were verified.",uri:"executeOrder"}],isError:!0};let i=new Promise(s=>{this.pendingRequests.set(r.clOrdID,s)}),d=this.parser?.createMessage(new e.Field(e.Fields.MsgType,e.Messages.NewOrderSingle),new e.Field(e.Fields.MsgSeqNum,this.parser?.getNextTargetMsgSeqNum()),new e.Field(e.Fields.SenderCompID,this.parser?.sender),new e.Field(e.Fields.TargetCompID,this.parser?.target),new e.Field(e.Fields.SendingTime,this.parser?.getTimestamp()),new e.Field(e.Fields.ClOrdID,r.clOrdID),new e.Field(e.Fields.Side,r.side),new e.Field(e.Fields.Symbol,r.symbol),new e.Field(e.Fields.OrderQty,Number.parseFloat(r.quantity)),new e.Field(e.Fields.Price,Number.parseFloat(r.price)),new e.Field(e.Fields.OrdType,r.ordType),new e.Field(e.Fields.HandlInst,r.handlInst),new e.Field(e.Fields.TimeInForce,r.timeInForce),new e.Field(e.Fields.TransactTime,this.parser?.getTimestamp()));if(!this.parser?.connected)return{contents:[{type:"text",text:"Error: Not connected. Ignoring message.",uri:"executeOrder"}],isError:!0};this.parser?.send(d);let p=await i;return this.verifiedOrders.delete(r.clOrdID),{contents:[{type:"text",text:p.messageType===e.Messages.Reject?`Reject message for order ${r.clOrdID}: ${JSON.stringify(p.toFIXJSON())}`:`Execution Report for order ${r.clOrdID}: ${JSON.stringify(p.toFIXJSON())}`,uri:"executeOrder"}]}}catch(t){return{contents:[{type:"text",text:`Error: ${t instanceof Error?t.message:"Failed to execute order"}`,uri:"executeOrder"}],isError:!0}}case"marketDataRequest":try{let t=new Promise(s=>{this.pendingRequests.set(r.mdReqID,s)}),i=[new e.Field(e.Fields.MsgType,e.Messages.MarketDataRequest),new e.Field(e.Fields.SenderCompID,this.parser?.sender),new e.Field(e.Fields.MsgSeqNum,this.parser?.getNextTargetMsgSeqNum()),new e.Field(e.Fields.TargetCompID,this.parser?.target),new e.Field(e.Fields.SendingTime,this.parser?.getTimestamp()),new e.Field(e.Fields.MDReqID,r.mdReqID),new e.Field(e.Fields.SubscriptionRequestType,r.subscriptionRequestType),new e.Field(e.Fields.MarketDepth,0),new e.Field(e.Fields.MDUpdateType,r.mdUpdateType)];i.push(new e.Field(e.Fields.NoRelatedSym,r.symbols.length)),r.symbols.forEach(s=>{i.push(new e.Field(e.Fields.Symbol,s))}),i.push(new e.Field(e.Fields.NoMDEntryTypes,r.mdEntryTypes.length)),r.mdEntryTypes.forEach(s=>{i.push(new e.Field(e.Fields.MDEntryType,s))});let d=this.parser?.createMessage(...i);if(!this.parser?.connected)return{contents:[{type:"text",text:"Error: Not connected. Ignoring message.",uri:"marketDataRequest"}],isError:!0};this.parser?.send(d);let p=await t;return{contents:[{type:"text",text:`Market data for ${r.symbols.join(", ")}: ${JSON.stringify(p.toFIXJSON())}`,uri:"marketDataRequest"}]}}catch(t){return{contents:[{type:"text",text:`Error: ${t instanceof Error?t.message:"Failed to request market data"}`,uri:"marketDataRequest"}],isError:!0}}case"getStockGraph":try{let t=r.symbol,i=this.marketDataPrices.get(t)||[];if(i.length===0)return{contents:[{type:"text",text:`No price data available for ${t}`,uri:"getStockGraph"}]};let d=600,p=300,s=40,g=(d-2*s)/(i.length-1),f=Math.min(...i.map(y=>y.price)),x=Math.max(...i.map(y=>y.price)),I=(p-2*s)/(x-f),F=i.map((y,m)=>{let u=s+m*g,h=p-s-(y.price-f)*I;return`${u},${h}`}).join(" L ");return{contents:[{type:"text",text:`<?xml version="1.0" encoding="UTF-8"?>
16
+ <svg width="${d}" height="${p}" xmlns="http://www.w3.org/2000/svg">
17
+ <!-- Background -->
18
+ <rect width="100%" height="100%" fill="#f8f9fa"/>
19
+
20
+ <!-- Grid lines -->
21
+ <g stroke="#e9ecef" stroke-width="1">
22
+ ${Array.from({length:5},(y,m)=>{let u=s+(p-2*s)*m/4;return`<line x1="${s}" y1="${u}" x2="${d-s}" y2="${u}"/>`}).join(`
23
+ `)}
24
+ </g>
25
+
26
+ <!-- Price line -->
27
+ <path d="M ${F}"
28
+ fill="none"
29
+ stroke="#007bff"
30
+ stroke-width="2"/>
31
+
32
+ <!-- Data points -->
33
+ ${i.map((y,m)=>{let u=s+m*g,h=p-s-(y.price-f)*I;return`<circle cx="${u}" cy="${h}" r="3" fill="#007bff"/>`}).join(`
34
+ `)}
35
+
36
+ <!-- Labels -->
37
+ <g font-family="Arial" font-size="12" fill="#495057">
38
+ ${Array.from({length:5},(y,m)=>{let u=s+(d-2*s)*m/4,h=Math.floor((i.length-1)*m/4),R=new Date(i[h].timestamp).toLocaleTimeString();return`<text x="${u+s}" y="${p-s+20}" text-anchor="middle">${R}</text>`}).join(`
39
+ `)}
40
+ ${Array.from({length:5},(y,m)=>{let u=s+(p-2*s)*m/4,h=x-(x-f)*m/4;return`<text x="${s-5}" y="${u+4}" text-anchor="end">$${h.toFixed(2)}</text>`}).join(`
41
+ `)}
42
+ </g>
43
+
44
+ <!-- Title -->
45
+ <text x="${d/2}" y="${s/2}"
46
+ font-family="Arial" font-size="16" font-weight="bold"
47
+ text-anchor="middle" fill="#212529">
48
+ ${t} - Price Chart (${i.length} points)
49
+ </text>
50
+ </svg>`,uri:"getStockGraph"}]}}catch(t){return{contents:[{type:"text",text:`Error: ${t instanceof Error?t.message:"Failed to generate stock graph"}`,uri:"getStockGraph"}],isError:!0}}case"getStockPriceHistory":try{let t=r.symbol,i=this.marketDataPrices.get(t)||[];return i.length===0?{contents:[{type:"text",text:`No price data available for ${t}`,uri:"getStockPriceHistory"}]}:{contents:[{type:"text",text:JSON.stringify({symbol:t,count:i.length,prices:i.map(d=>({timestamp:new Date(d.timestamp).toISOString(),price:d.price}))},null,2),uri:"getStockPriceHistory"}]}}catch(t){return{contents:[{type:"text",text:`Error: ${t instanceof Error?t.message:"Failed to get stock price history"}`,uri:"getStockPriceHistory"}],isError:!0}}default:return{contents:[{type:"text",text:`Tool not found: ${o}`,uri:o}],isError:!0}}}),process.on("SIGINT",async()=>{await this.server.close(),process.exit(0)}))}};var E=async()=>{await n.LicenseManager.setLicenseKey(process.env.FIXPARSER_LICENSE_KEY);let c=process.env.FIXPARSER_SENDER||"SENDER",a=process.env.FIXPARSER_TARGET||"TARGET",o=new n.FIXParser({logging:!0,logOptions:{level:"info",format:"jsonrpc",transport:new S({format:"jsonrpc"})},plugins:[new O({port:3099,onReady:()=>{}})]}),r=()=>{let i=o.createMessage(new n.Field(n.Fields.MsgType,n.Messages.Logon),new n.Field(n.Fields.MsgSeqNum,o.getNextTargetMsgSeqNum()),new n.Field(n.Fields.SenderCompID,c),new n.Field(n.Fields.SendingTime,o.getTimestamp()),new n.Field(n.Fields.TargetCompID,a),new n.Field(n.Fields.ResetSeqNumFlag,n.ResetSeqNumFlag.Yes),new n.Field(n.Fields.EncryptMethod,n.EncryptMethod.None),new n.Field(n.Fields.HeartBtInt,10));o.send(i)},t={host:process.env.FIXPARSER_HOST||"10.0.1.42",port:process.env.FIXPARSER_PORT?Number.parseInt(process.env.FIXPARSER_PORT,10):5001,protocol:"tcp",sender:c,target:a,fixVersion:"FIX.4.4",onOpen:()=>{o.logger.log({level:"info",message:"FIXParser logging in..."}),r()},onClose:()=>{o.logger.log({level:"info",message:"FIXParser disconnected. Reconnecting in 1 second..."}),setTimeout(()=>{o.connect(t)},1e3)}};o.connect(t)};E().catch(c=>console.error("Error initializing server:",c));
7
51
  //# sourceMappingURL=example_mcp_local.js.map