fixparser-plugin-mcp 9.1.7-71fc8a2b → 9.1.7-8db521e7
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/cjs/MCPLocal.js +346 -1614
- package/build/cjs/MCPLocal.js.map +4 -4
- package/build/esm/MCPLocal.mjs +346 -1623
- package/build/esm/MCPLocal.mjs.map +4 -4
- package/build-examples/cjs/example_mcp_local.js +4 -7
- package/build-examples/cjs/example_mcp_local.js.map +4 -4
- package/build-examples/esm/example_mcp_local.mjs +4 -7
- package/build-examples/esm/example_mcp_local.mjs.map +4 -4
- package/package.json +9 -8
- package/types/MCPLocal.d.ts +0 -1
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{EncryptMethod as je,FIXParser as Le,Field as S,Fields as P,LicenseManager as Xe,Messages as ze,ResetSeqNumFlag as Ue}from"fixparser";import{Server as B}from"@modelcontextprotocol/sdk/server/index.js";import{StdioServerTransport as J}from"@modelcontextprotocol/sdk/server/stdio.js";import{CallToolRequestSchema as H,GetPromptRequestSchema as K,ListPromptsRequestSchema as G,ListResourcesRequestSchema as V,ListToolsRequestSchema as W}from"@modelcontextprotocol/sdk/types.js";import{z as u}from"zod";import{ZodFirstPartyTypeKind as p}from"zod";import{ZodFirstPartyTypeKind as re}from"zod";import{ZodFirstPartyTypeKind as T}from"zod";import{ZodOptional as Ie}from"zod";import{Field as g,Fields as d,HandlInst as _,MDEntryType as q,Messages as I,OrdType as Ce,SubscriptionRequestType as R,TimeInForce as Z}from"fixparser";var Q=Symbol("Let zodToJsonSchema decide on which parser to use"),A={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"},Y=t=>typeof t=="string"?{...A,name:t}:{...A,...t},ee=t=>{let e=Y(t),n=e.name!==void 0?[...e.basePath,e.definitionPath,e.name]:e.basePath;return{...e,currentPath:n,propertyPath:void 0,seen:new Map(Object.entries(e.definitions).map(([r,a])=>[a._def,{def:a._def,path:[...e.basePath,e.definitionPath,r],jsonSchema:void 0}]))}};function E(t,e,n,r){r?.errorMessages&&n&&(t.errorMessage={...t.errorMessage,[e]:n})}function m(t,e,n,r,a){t[e]=n,E(t,e,r,a)}function te(){return{}}function ne(t,e){let n={type:"array"};return t.type?._def&&t.type?._def?.typeName!==re.ZodAny&&(n.items=l(t.type._def,{...e,currentPath:[...e.currentPath,"items"]})),t.minLength&&m(n,"minItems",t.minLength.value,t.minLength.message,e),t.maxLength&&m(n,"maxItems",t.maxLength.value,t.maxLength.message,e),t.exactLength&&(m(n,"minItems",t.exactLength.value,t.exactLength.message,e),m(n,"maxItems",t.exactLength.value,t.exactLength.message,e)),n}function ae(t,e){let n={type:"integer",format:"int64"};if(!t.checks)return n;for(let r of t.checks)switch(r.kind){case"min":e.target==="jsonSchema7"?r.inclusive?m(n,"minimum",r.value,r.message,e):m(n,"exclusiveMinimum",r.value,r.message,e):(r.inclusive||(n.exclusiveMinimum=!0),m(n,"minimum",r.value,r.message,e));break;case"max":e.target==="jsonSchema7"?r.inclusive?m(n,"maximum",r.value,r.message,e):m(n,"exclusiveMaximum",r.value,r.message,e):(r.inclusive||(n.exclusiveMaximum=!0),m(n,"maximum",r.value,r.message,e));break;case"multipleOf":m(n,"multipleOf",r.value,r.message,e);break}return n}function ie(){return{type:"boolean"}}function $(t,e){return l(t.type._def,e)}var se=(t,e)=>l(t.innerType._def,e);function C(t,e,n){let r=n??e.dateStrategy;if(Array.isArray(r))return{anyOf:r.map((a,i)=>C(t,e,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 oe(t,e)}}var oe=(t,e)=>{let n={type:"integer",format:"unix-time"};if(e.target==="openApi3")return n;for(let r of t.checks)switch(r.kind){case"min":m(n,"minimum",r.value,r.message,e);break;case"max":m(n,"maximum",r.value,r.message,e);break}return n};function ue(t,e){return{...l(t.innerType._def,e),default:t.defaultValue()}}function ce(t,e){return e.effectStrategy==="input"?l(t.schema._def,e):{}}function pe(t){return{type:"string",enum:Array.from(t.values)}}var le=t=>"type"in t&&t.type==="string"?!1:"allOf"in t;function de(t,e){let n=[l(t.left._def,{...e,currentPath:[...e.currentPath,"allOf","0"]}),l(t.right._def,{...e,currentPath:[...e.currentPath,"allOf","1"]})].filter(i=>!!i),r=e.target==="jsonSchema2019-09"?{unevaluatedProperties:!1}:void 0,a=[];return n.forEach(i=>{if(le(i))a.push(...i.allOf),i.unevaluatedProperties===void 0&&(r=void 0);else{let o=i;if("additionalProperties"in i&&i.additionalProperties===!1){let{additionalProperties:c,...s}=i;o=s}else r=void 0;a.push(o)}}),a.length?{allOf:a,...r}:void 0}function me(t,e){let n=typeof t.value;return n!=="bigint"&&n!=="number"&&n!=="boolean"&&n!=="string"?{type:Array.isArray(t.value)?"array":"object"}:e.target==="openApi3"?{type:n==="bigint"?"integer":n,enum:[t.value]}:{type:n==="bigint"?"integer":n,const:t.value}}var M=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:()=>(M===void 0&&(M=RegExp("^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$","u")),M),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 j(t,e){let n={type:"string"};if(t.checks)for(let r of t.checks)switch(r.kind){case"min":m(n,"minLength",typeof n.minLength=="number"?Math.max(n.minLength,r.value):r.value,r.message,e);break;case"max":m(n,"maxLength",typeof n.maxLength=="number"?Math.min(n.maxLength,r.value):r.value,r.message,e);break;case"email":switch(e.emailStrategy){case"format:email":b(n,"email",r.message,e);break;case"format:idn-email":b(n,"idn-email",r.message,e);break;case"pattern:zod":y(n,h.email,r.message,e);break}break;case"url":b(n,"uri",r.message,e);break;case"uuid":b(n,"uuid",r.message,e);break;case"regex":y(n,r.regex,r.message,e);break;case"cuid":y(n,h.cuid,r.message,e);break;case"cuid2":y(n,h.cuid2,r.message,e);break;case"startsWith":y(n,RegExp(`^${D(r.value,e)}`),r.message,e);break;case"endsWith":y(n,RegExp(`${D(r.value,e)}$`),r.message,e);break;case"datetime":b(n,"date-time",r.message,e);break;case"date":b(n,"date",r.message,e);break;case"time":b(n,"time",r.message,e);break;case"duration":b(n,"duration",r.message,e);break;case"length":m(n,"minLength",typeof n.minLength=="number"?Math.max(n.minLength,r.value):r.value,r.message,e),m(n,"maxLength",typeof n.maxLength=="number"?Math.min(n.maxLength,r.value):r.value,r.message,e);break;case"includes":{y(n,RegExp(D(r.value,e)),r.message,e);break}case"ip":{r.version!=="v6"&&b(n,"ipv4",r.message,e),r.version!=="v4"&&b(n,"ipv6",r.message,e);break}case"base64url":y(n,h.base64url,r.message,e);break;case"jwt":y(n,h.jwt,r.message,e);break;case"cidr":{r.version!=="v6"&&y(n,h.ipv4Cidr,r.message,e),r.version!=="v4"&&y(n,h.ipv6Cidr,r.message,e);break}case"emoji":y(n,h.emoji(),r.message,e);break;case"ulid":{y(n,h.ulid,r.message,e);break}case"base64":{switch(e.base64Strategy){case"format:binary":{b(n,"binary",r.message,e);break}case"contentEncoding:base64":{m(n,"contentEncoding","base64",r.message,e);break}case"pattern:zod":{y(n,h.base64,r.message,e);break}}break}case"nanoid":y(n,h.nanoid,r.message,e);case"toLowerCase":case"toUpperCase":case"trim":break;default:}return n}function D(t,e){return e.patternStrategy==="escape"?ye(t):t}var ge=new Set("ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789");function ye(t){let e="";for(let n=0;n<t.length;n++)ge.has(t[n])||(e+="\\"),e+=t[n];return e}function b(t,e,n,r){t.format||t.anyOf?.some(a=>a.format)?(t.anyOf||(t.anyOf=[]),t.format&&(t.anyOf.push({format:t.format,...t.errorMessage&&r.errorMessages&&{errorMessage:{format:t.errorMessage.format}}}),delete t.format,t.errorMessage&&(delete t.errorMessage.format,Object.keys(t.errorMessage).length===0&&delete t.errorMessage)),t.anyOf.push({format:e,...n&&r.errorMessages&&{errorMessage:{format:n}}})):m(t,"format",e,n,r)}function y(t,e,n,r){t.pattern||t.allOf?.some(a=>a.pattern)?(t.allOf||(t.allOf=[]),t.pattern&&(t.allOf.push({pattern:t.pattern,...t.errorMessage&&r.errorMessages&&{errorMessage:{pattern:t.errorMessage.pattern}}}),delete t.pattern,t.errorMessage&&(delete t.errorMessage.pattern,Object.keys(t.errorMessage).length===0&&delete t.errorMessage)),t.allOf.push({pattern:F(e,r),...n&&r.errorMessages&&{errorMessage:{pattern:n}}})):m(t,"pattern",F(e,r),n,r)}function F(t,e){if(!e.applyRegexFlags||!t.flags)return t.source;let n={i:t.flags.includes("i"),m:t.flags.includes("m"),s:t.flags.includes("s")},r=n.i?t.source.toLowerCase():t.source,a="",i=!1,o=!1,c=!1;for(let s=0;s<r.length;s++){if(i){a+=r[s],i=!1;continue}if(n.i){if(o){if(r[s].match(/[a-z]/)){c?(a+=r[s],a+=`${r[s-2]}-${r[s]}`.toUpperCase(),c=!1):r[s+1]==="-"&&r[s+2]?.match(/[a-z]/)?(a+=r[s],c=!0):a+=`${r[s]}${r[s].toUpperCase()}`;continue}}else if(r[s].match(/[a-z]/)){a+=`[${r[s]}${r[s].toUpperCase()}]`;continue}}if(n.m){if(r[s]==="^"){a+=`(^|(?<=[\r
|
|
3
|
-
]))
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
]`;continue}a+=r[s],r[s]==="\\"?i=!0:o&&r[s]==="]"?o=!1:!o&&r[s]==="["&&(o=!0)}try{new RegExp(a)}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`),t.source}return a}function L(t,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"&&t.keyType?._def.typeName===T.ZodEnum)return{type:"object",required:t.keyType._def.values,properties:t.keyType._def.values.reduce((r,a)=>({...r,[a]:l(t.valueType._def,{...e,currentPath:[...e.currentPath,"properties",a]})??{}}),{}),additionalProperties:e.rejectedAdditionalProperties};let n={type:"object",additionalProperties:l(t.valueType._def,{...e,currentPath:[...e.currentPath,"additionalProperties"]})??e.allowedAdditionalProperties};if(e.target==="openApi3")return n;if(t.keyType?._def.typeName===T.ZodString&&t.keyType._def.checks?.length){let{type:r,...a}=j(t.keyType._def,e);return{...n,propertyNames:a}}else{if(t.keyType?._def.typeName===T.ZodEnum)return{...n,propertyNames:{enum:t.keyType._def.values}};if(t.keyType?._def.typeName===T.ZodBranded&&t.keyType._def.type._def.typeName===T.ZodString&&t.keyType._def.type._def.checks?.length){let{type:r,...a}=$(t.keyType._def,e);return{...n,propertyNames:a}}}return n}function fe(t,e){if(e.mapStrategy==="record")return L(t,e);let n=l(t.keyType._def,{...e,currentPath:[...e.currentPath,"items","items","0"]})||{},r=l(t.valueType._def,{...e,currentPath:[...e.currentPath,"items","items","1"]})||{};return{type:"array",maxItems:125,items:{type:"array",items:[n,r],minItems:2,maxItems:2}}}function he(t){let e=t.values,r=Object.keys(t.values).filter(i=>typeof e[e[i]]!="number").map(i=>e[i]),a=Array.from(new Set(r.map(i=>typeof i)));return{type:a.length===1?a[0]==="string"?"string":"number":["string","number"],enum:r}}function be(){return{not:{}}}function ve(t){return t.target==="openApi3"?{enum:["null"],nullable:!0}:{type:"null"}}var O={ZodString:"string",ZodNumber:"number",ZodBigInt:"integer",ZodBoolean:"boolean",ZodNull:"null"};function Se(t,e){if(e.target==="openApi3")return N(t,e);let n=t.options instanceof Map?Array.from(t.options.values()):t.options;if(n.every(r=>r._def.typeName in O&&(!r._def.checks||!r._def.checks.length))){let r=n.reduce((a,i)=>{let o=O[i._def.typeName];return o&&!a.includes(o)?[...a,o]: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,i)=>{let o=typeof i._def.value;switch(o){case"string":case"number":case"boolean":return[...a,o];case"bigint":return[...a,"integer"];case"object":if(i._def.value===null)return[...a,"null"];case"symbol":case"undefined":case"function":default:return a}},[]);if(r.length===n.length){let a=r.filter((i,o,c)=>c.indexOf(i)===o);return{type:a.length>1?a:a[0],enum:n.reduce((i,o)=>i.includes(o._def.value)?i:[...i,o._def.value],[])}}}else if(n.every(r=>r._def.typeName==="ZodEnum"))return{type:"string",enum:n.reduce((r,a)=>[...r,...a._def.values.filter(i=>!r.includes(i))],[])};return N(t,e)}var N=(t,e)=>{let n=(t.options instanceof Map?Array.from(t.options.values()):t.options).map((r,a)=>l(r._def,{...e,currentPath:[...e.currentPath,"anyOf",`${a}`]})).filter(r=>!!r&&(!e.strictUnions||typeof r=="object"&&Object.keys(r).length>0));return n.length?{anyOf:n}:void 0};function Pe(t,e){if(["ZodString","ZodNumber","ZodBigInt","ZodBoolean","ZodNull"].includes(t.innerType._def.typeName)&&(!t.innerType._def.checks||!t.innerType._def.checks.length))return e.target==="openApi3"?{type:O[t.innerType._def.typeName],nullable:!0}:{type:[O[t.innerType._def.typeName],"null"]};if(e.target==="openApi3"){let r=l(t.innerType._def,{...e,currentPath:[...e.currentPath]});return r&&"$ref"in r?{allOf:[r],nullable:!0}:r&&{...r,nullable:!0}}let n=l(t.innerType._def,{...e,currentPath:[...e.currentPath,"anyOf","0"]});return n&&{anyOf:[n,{type:"null"}]}}function Te(t,e){let n={type:"number"};if(!t.checks)return n;for(let r of t.checks)switch(r.kind){case"int":n.type="integer",E(n,"type",r.message,e);break;case"min":e.target==="jsonSchema7"?r.inclusive?m(n,"minimum",r.value,r.message,e):m(n,"exclusiveMinimum",r.value,r.message,e):(r.inclusive||(n.exclusiveMinimum=!0),m(n,"minimum",r.value,r.message,e));break;case"max":e.target==="jsonSchema7"?r.inclusive?m(n,"maximum",r.value,r.message,e):m(n,"exclusiveMaximum",r.value,r.message,e):(r.inclusive||(n.exclusiveMaximum=!0),m(n,"maximum",r.value,r.message,e));break;case"multipleOf":m(n,"multipleOf",r.value,r.message,e);break}return n}function ke(t,e){let n=e.target==="openAi",r={type:"object",properties:{}},a=[],i=t.shape();for(let c in i){let s=i[c];if(s===void 0||s._def===void 0)continue;let f=we(s);f&&n&&(s instanceof Ie&&(s=s._def.innerType),s.isNullable()||(s=s.nullable()),f=!1);let v=l(s._def,{...e,currentPath:[...e.currentPath,"properties",c],propertyPath:[...e.currentPath,"properties",c]});v!==void 0&&(r.properties[c]=v,f||a.push(c))}a.length&&(r.required=a);let o=Oe(t,e);return o!==void 0&&(r.additionalProperties=o),r}function Oe(t,e){if(t.catchall._def.typeName!=="ZodNever")return l(t.catchall._def,{...e,currentPath:[...e.currentPath,"additionalProperties"]});switch(t.unknownKeys){case"passthrough":return e.allowedAdditionalProperties;case"strict":return e.rejectedAdditionalProperties;case"strip":return e.removeAdditionalStrategy==="strict"?e.allowedAdditionalProperties:e.rejectedAdditionalProperties}}function we(t){try{return t.isOptional()}catch{return!0}}var Me=(t,e)=>{if(e.currentPath.toString()===e.propertyPath?.toString())return l(t.innerType._def,e);let n=l(t.innerType._def,{...e,currentPath:[...e.currentPath,"anyOf","1"]});return n?{anyOf:[{not:{}},n]}:{}},De=(t,e)=>{if(e.pipeStrategy==="input")return l(t.in._def,e);if(e.pipeStrategy==="output")return l(t.out._def,e);let n=l(t.in._def,{...e,currentPath:[...e.currentPath,"allOf","0"]}),r=l(t.out._def,{...e,currentPath:[...e.currentPath,"allOf",n?"1":"0"]});return{allOf:[n,r].filter(a=>a!==void 0)}};function xe(t,e){return l(t.type._def,e)}function Ae(t,e){let r={type:"array",uniqueItems:!0,items:l(t.valueType._def,{...e,currentPath:[...e.currentPath,"items"]})};return t.minSize&&m(r,"minItems",t.minSize.value,t.minSize.message,e),t.maxSize&&m(r,"maxItems",t.maxSize.value,t.maxSize.message,e),r}function Fe(t,e){return t.rest?{type:"array",minItems:t.items.length,items:t.items.map((n,r)=>l(n._def,{...e,currentPath:[...e.currentPath,"items",`${r}`]})).reduce((n,r)=>r===void 0?n:[...n,r],[]),additionalItems:l(t.rest._def,{...e,currentPath:[...e.currentPath,"additionalItems"]})}:{type:"array",minItems:t.items.length,maxItems:t.items.length,items:t.items.map((n,r)=>l(n._def,{...e,currentPath:[...e.currentPath,"items",`${r}`]})).reduce((n,r)=>r===void 0?n:[...n,r],[])}}function Ne(){return{not:{}}}function _e(){return{}}var qe=(t,e)=>l(t.innerType._def,e),Re=(t,e,n)=>{switch(e){case p.ZodString:return j(t,n);case p.ZodNumber:return Te(t,n);case p.ZodObject:return ke(t,n);case p.ZodBigInt:return ae(t,n);case p.ZodBoolean:return ie();case p.ZodDate:return C(t,n);case p.ZodUndefined:return Ne();case p.ZodNull:return ve(n);case p.ZodArray:return ne(t,n);case p.ZodUnion:case p.ZodDiscriminatedUnion:return Se(t,n);case p.ZodIntersection:return de(t,n);case p.ZodTuple:return Fe(t,n);case p.ZodRecord:return L(t,n);case p.ZodLiteral:return me(t,n);case p.ZodEnum:return pe(t);case p.ZodNativeEnum:return he(t);case p.ZodNullable:return Pe(t,n);case p.ZodOptional:return Me(t,n);case p.ZodMap:return fe(t,n);case p.ZodSet:return Ae(t,n);case p.ZodLazy:return()=>t.getter()._def;case p.ZodPromise:return xe(t,n);case p.ZodNaN:case p.ZodNever:return be();case p.ZodEffects:return ce(t,n);case p.ZodAny:return te();case p.ZodUnknown:return _e();case p.ZodDefault:return ue(t,n);case p.ZodBranded:return $(t,n);case p.ZodReadonly:return qe(t,n);case p.ZodCatch:return se(t,n);case p.ZodPipeline:return De(t,n);case p.ZodFunction:case p.ZodVoid:case p.ZodSymbol:return;default:return(r=>{})(e)}};function l(t,e,n=!1){let r=e.seen.get(t);if(e.override){let c=e.override?.(t,e,r,n);if(c!==Q)return c}if(r&&!n){let c=Ze(r,e);if(c!==void 0)return c}let a={def:t,path:e.currentPath,jsonSchema:void 0};e.seen.set(t,a);let i=Re(t,t.typeName,e),o=typeof i=="function"?l(i(),e):i;if(o&&$e(t,e,o),e.postProcess){let c=e.postProcess(o,t,e);return a.jsonSchema=o,c}return a.jsonSchema=o,o}var Ze=(t,e)=>{switch(e.$refStrategy){case"root":return{$ref:t.path.join("/")};case"relative":return{$ref:Ee(e.currentPath,t.path)};case"none":case"seen":return t.path.length<e.currentPath.length&&t.path.every((n,r)=>e.currentPath[r]===n)?(console.warn(`Recursive reference detected at ${e.currentPath.join("/")}! Defaulting to any`),{}):e.$refStrategy==="seen"?{}:void 0}},Ee=(t,e)=>{let n=0;for(;n<t.length&&n<e.length&&t[n]===e[n];n++);return[(t.length-n).toString(),...e.slice(n)].join("/")},$e=(t,e,n)=>(t.description&&(n.description=t.description,e.markdownDescription&&(n.markdownDescription=t.description)),n),k=(t,e)=>{let n=ee(e),r=typeof e=="object"&&e.definitions?Object.entries(e.definitions).reduce((s,[f,v])=>({...s,[f]:l(v._def,{...n,currentPath:[...n.basePath,n.definitionPath,f]},!0)??{}}),{}):void 0,a=typeof e=="string"?e:e?.nameStrategy==="title"?void 0:e?.name,i=l(t._def,a===void 0?n:{...n,currentPath:[...n.basePath,n.definitionPath,a]},!1)??{},o=typeof e=="object"&&e.name!==void 0&&e.nameStrategy==="title"?e.name:void 0;o!==void 0&&(i.title=o);let c=a===void 0?r?{...i,[n.definitionPath]:r}:i:{$ref:[...n.$refStrategy==="relative"?[]:n.basePath,n.definitionPath,a].join("/"),[n.definitionPath]:{...r,[a]:i}};return n.target==="jsonSchema7"?c.$schema="http://json-schema.org/draft-07/schema#":(n.target==="jsonSchema2019-09"||n.target==="openAi")&&(c.$schema="https://json-schema.org/draft/2019-09/schema#"),n.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},X=class{logger;parser;server=new B({name:"fixparser",version:"1.0.0"},{capabilities:{tools:{},prompts:{},resources:{}}});transport=new J;onReady=void 0;pendingRequests=new Map;constructor({logger:t,onReady:e}){t&&(this.logger=t),e&&(this.onReady=e)}async register(t){this.parser=t,this.parser.addOnMessageCallback(e=>{this.logger?.log({level:"info",message:`FIXParser (MCP): (${t.protocol?.toUpperCase()}): << received ${e.description}`});let n=e.messageType;if(n===I.MarketDataSnapshotFullRefresh||n===I.ExecutionReport){let r=n===I.MarketDataSnapshotFullRefresh?e.getField(d.MDReqID):e.getField(d.ClOrdID);if(r){let a=r.value;if(typeof a=="string"||typeof a=="number"){let i=this.pendingRequests.get(String(a));i&&(i(e),this.pendingRequests.delete(String(a)))}}}}),this.logger=t.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(V,async()=>({resources:[]})),this.server.setRequestHandler(W,async()=>({tools:[{name:"parse",description:"Parses a FIX message and describes it in plain language",inputSchema:k(u.object({fixString:u.string().describe("FIX message string to parse")}),{name:"ParseInput"})},{name:"parseToJSON",description:"Parses a FIX message into JSON",inputSchema:k(u.object({fixString:u.string().describe("FIX message string to parse")}),{name:"ParseToJSONInput"})},{name:"newOrderSingle",description:"Creates and sends a New Order Single",inputSchema:k(u.object({clOrdID:u.string().describe("Client Order ID"),handlInst:u.enum(["1","2","3"]).default(_.AutomatedExecutionNoIntervention).optional().describe("Handling instruction"),quantity:u.number().describe("Order quantity"),price:u.number().describe("Order price"),ordType:u.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.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.string().describe("Trading symbol"),timeInForce:u.enum(["0","1","2","3","4","5","6","7","8","9","A","B","C"]).default(Z.Day).optional().describe("Time in force")}),{name:"NewOrderSingleInput"})},{name:"marketDataRequest",description:"Sends a request for Market Data with the given symbol",inputSchema:k(u.object({mdUpdateType:u.enum(["0","1"]).default("0").optional().describe("Market data update type"),symbol:u.string().describe("Trading symbol"),mdReqID:u.string().describe("Market data request ID"),subscriptionRequestType:u.enum(["0","1","2"]).default(R.SnapshotAndUpdates).optional().describe("Subscription request type"),mdEntryType:u.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(q.Bid).optional().describe("Market data entry type")}),{name:"MarketDataRequestInput"})}]})),this.server.setRequestHandler(H,async t=>{let{name:e,arguments:n}=t.params;switch(e){case"parse":{let{fixString:r}=u.object({fixString:u.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.object({fixString:u.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:i,price:o,ordType:c,side:s,symbol:f,timeInForce:v}=u.object({clOrdID:u.string().describe("Client Order ID"),handlInst:u.enum(["1","2","3"]).default(_.AutomatedExecutionNoIntervention).optional().describe("Handling instruction"),quantity:u.number().describe("Order quantity"),price:u.number().describe("Order price"),ordType:u.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(Ce.Market).optional().describe("Order type"),side:u.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.string().describe("Trading symbol"),timeInForce:u.enum(["0","1","2","3","4","5","6","7","8","9","A","B","C"]).default(Z.Day).optional().describe("Time in force")}).parse(n||{}),w=new Promise(U=>{this.pendingRequests.set(r,U)}),x=this.parser?.createMessage(new g(d.MsgType,I.NewOrderSingle),new g(d.MsgSeqNum,this.parser?.getNextTargetMsgSeqNum()),new g(d.SenderCompID,this.parser?.sender),new g(d.TargetCompID,this.parser?.target),new g(d.SendingTime,this.parser?.getTimestamp()),new g(d.ClOrdID,r),new g(d.Side,s),new g(d.Symbol,f),new g(d.OrderQty,i),new g(d.Price,o),new g(d.OrdType,c),new g(d.HandlInst,a),new g(d.TimeInForce,v),new g(d.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(x),this.logger?.log({level:"info",message:`FIXParser (MCP): (${this.parser?.protocol?.toUpperCase()}): >> sent ${x?.description}`});let z=await w;return{content:[{type:"text",text:`Execution Report for order ${r}: ${JSON.stringify(z.toFIXJSON())}`}]}}case"marketDataRequest":{let{mdUpdateType:r,symbol:a,mdReqID:i,subscriptionRequestType:o,mdEntryType:c}=u.object({mdUpdateType:u.enum(["0","1"]).default("0").optional().describe("Market data update type"),symbol:u.string().describe("Trading symbol"),mdReqID:u.string().describe("Market data request ID"),subscriptionRequestType:u.enum(["0","1","2"]).default(R.SnapshotAndUpdates).optional().describe("Subscription request type"),mdEntryType:u.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(q.Bid).optional().describe("Market data entry type")}).parse(n||{}),s=new Promise(w=>{this.pendingRequests.set(i,w)}),f=this.parser?.createMessage(new g(d.MsgType,I.MarketDataRequest),new g(d.SenderCompID,this.parser?.sender),new g(d.MsgSeqNum,this.parser?.getNextTargetMsgSeqNum()),new g(d.TargetCompID,this.parser?.target),new g(d.SendingTime,this.parser?.getTimestamp()),new g(d.MarketDepth,0),new g(d.MDUpdateType,r),new g(d.NoRelatedSym,1),new g(d.Symbol,a),new g(d.MDReqID,i),new g(d.SubscriptionRequestType,o),new g(d.NoMDEntryTypes,1),new g(d.MDEntryType,c));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 s;return{content:[{type:"text",text:`Market data for ${a}: ${JSON.stringify(v.toFIXJSON())}`}]}}default:throw new Error(`Unknown tool: ${e}`)}}),this.server.setRequestHandler(G,async()=>({prompts:[{name:"parse",description:"Parses a FIX message and describes it in plain language",arguments:[{name:"fixString",description:"FIX message string to parse",required:!0}]},{name:"parseToJSON",description:"Parses a FIX message into JSON",arguments:[{name:"fixString",description:"FIX message string to parse",required:!0}]},{name:"newOrderSingle",description:"Creates and sends a New Order Single",arguments:[{name:"clOrdID",description:"Client Order ID",required:!0},{name:"handlInst",description:"Handling instruction",required:!1},{name:"quantity",description:"Order quantity",required:!0},{name:"price",description:"Order price",required:!0},{name:"ordType",description:"Order type",required:!1},{name:"side",description:"Order side (1=Buy, 2=Sell)",required:!0},{name:"symbol",description:"Trading symbol",required:!0},{name:"timeInForce",description:"Time in force",required:!1}]},{name:"marketDataRequest",description:"Sends a request for Market Data with the given symbol",arguments:[{name:"mdUpdateType",description:"Market data update type",required:!1},{name:"symbol",description:"Trading symbol",required:!0},{name:"mdReqID",description:"Market data request ID",required:!0},{name:"subscriptionRequestType",description:"Subscription request type",required:!1},{name:"mdEntryType",description:"Market data entry type",required:!1}]}]})),this.server.setRequestHandler(K,async t=>{let{name:e,arguments:n}=t.params;switch(e){case"parse":return{messages:[{role:"user",content:{type:"text",text:`Please parse and explain this FIX message: ${n?.fixString||""}`}}]};case"parseToJSON":return{messages:[{role:"user",content:{type:"text",text:`Please parse the FIX message to JSON: ${n?.fixString||""}`}}]};case"newOrderSingle":{let{clOrdID:r,handlInst:a,quantity:i,price:o,ordType:c,side:s,symbol:f,timeInForce:v}=n||{};return{messages:[{role:"user",content:{type:"text",text:["Create a New Order Single FIX message with the following parameters:",`- ClOrdID: ${r}`,`- HandlInst: ${a??"default"}`,`- Quantity: ${i}`,`- Price: ${o}`,`- OrdType: ${c??"default (Market)"}`,`- Side: ${s}`,`- Symbol: ${f}`,`- TimeInForce: ${v??"default (Day)"}`,"","Format the response as a JSON object with FIX tag numbers as keys and their corresponding values."].join(`
|
|
7
|
-
`)}}]}}case"marketDataRequest":{let{mdUpdateType:r,symbol:a,mdReqID:i,subscriptionRequestType:o,mdEntryType:c}=n||{};return{messages:[{role:"user",content:{type:"text",text:["Create a Market Data Request FIX message with the following parameters:",`- MDUpdateType: ${r??"default (0 = FullRefresh)"}`,`- Symbol: ${a}`,`- MDReqID: ${i}`,`- SubscriptionRequestType: ${o??"default (0 = Snapshot + Updates)"}`,`- MDEntryType: ${c??"default (0 = Bid)"}`,"","Format the response as a JSON object with FIX tag numbers as keys and their corresponding values."].join(`
|
|
8
|
-
`)}}]}}default:throw new Error(`Unknown prompt: ${e}`)}}),process.on("SIGINT",async()=>{await this.server.close(),process.exit(0)})}};var Be=async()=>{await Xe.setLicenseKey(process.env.FIXPARSER_LICENSE_KEY);let t=new Le({plugins:[new X({port:3099,onReady:()=>{}})]}),e=()=>{let i=t.createMessage(new S(P.MsgType,ze.Logon),new S(P.MsgSeqNum,t.getNextTargetMsgSeqNum()),new S(P.SenderCompID,n),new S(P.SendingTime,t.getTimestamp()),new S(P.TargetCompID,r),new S(P.ResetSeqNumFlag,Ue.Yes),new S(P.EncryptMethod,je.None),new S(P.HeartBtInt,10));t.send(i)},n="CLIENT2",r="EXECUTOR",a={host:"localhost",port:5001,protocol:"tcp",sender:n,target:r,fixVersion:"FIX.4.4",logging:!1,onOpen:()=>{e()},onMessage:i=>{},onClose:()=>{}};t.connect(a)};Be().catch(t=>console.error("Error initializing server:",t));
|
|
2
|
+
import{EncryptMethod as P,FIXParser as X,Field as l,Fields as u,LicenseManager as k,Messages as $,ResetSeqNumFlag as U}from"fixparser";import{Server as D}from"@modelcontextprotocol/sdk/server/index.js";import{StdioServerTransport as b}from"@modelcontextprotocol/sdk/server/stdio.js";import{CallToolRequestSchema as E,GetPromptRequestSchema as v,ListPromptsRequestSchema as N,ListResourcesRequestSchema as C,ListToolsRequestSchema as A}from"@modelcontextprotocol/sdk/types.js";import{Field as r,Fields as t,Messages as c}from"fixparser";var T={type:"object",properties:{fixString:{type:"string",description:"FIX message string to parse"}},required:["fixString"]},I={type:"object",properties:{fixString:{type:"string",description:"FIX message string to parse"}},required:["fixString"]},R={type:"object",properties:{clOrdID:{type:"string",description:"Client Order ID"},handlInst:{type:"string",enum:["1","2","3"],description:'Handling instruction (IMPORTANT: Use the numeric/alphabetic value, not the descriptive name. For example, use "1" for Manual, "2" for Automated, "3" for AutomatedNoIntervention)'},quantity:{type:"number",description:"Order quantity"},price:{type:"number",description:"Order price"},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"],description:'Order type (IMPORTANT: Use the numeric/alphabetic value, not the descriptive name. For example, use "1" for Market, "2" for Limit, "3" for Stop)'},side:{type:"string",enum:["1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H"],description:'Order side (IMPORTANT: Use the numeric/alphabetic value, not the descriptive name. For example, use "1" for Buy, "2" for Sell, "3" for BuyMinus, "4" for SellPlus, "5" for SellShort, "6" for SellShortExempt, "7" for Undisclosed, "8" for Cross, "9" for CrossShort, "A" for CrossShortExempt, "B" for AsDefined, "C" for Opposite, "D" for Subscribe, "E" for Redeem, "F" for Lend, "G" for Borrow, "H" for SellUndisclosed)'},symbol:{type:"string",description:"Trading symbol"},timeInForce:{type:"string",enum:["0","1","2","3","4","5","6","7","8","9","A","B","C"],description:'Time in force (IMPORTANT: Use the numeric/alphabetic value, not the descriptive name. For example, use "0" for Day, "1" for Good Till Cancel, "2" for At Opening, "3" for Immediate or Cancel, "4" for Fill or Kill, "5" for Good Till Crossing, "6" for Good Till Date)'}},required:["clOrdID","quantity","price","side","symbol","handlInst","ordType","timeInForce"]},O={type:"object",properties:{mdUpdateType:{type:"string",enum:["0","1"],description:'Market data update type (IMPORTANT: Use the numeric/alphabetic value, not the descriptive name. For example, use "0" for FullRefresh, "1" for IncrementalRefresh)'},symbol:{type:"string",description:"Trading symbol"},mdReqID:{type:"string",description:"Market data request ID"},subscriptionRequestType:{type:"string",enum:["0","1","2"],description:'Subscription request type (IMPORTANT: Use the numeric/alphabetic value, not the descriptive name. For example, use "0" for Snapshot + Updates, "1" for Snapshot, "2" for Unsubscribe)'},mdEntryType:{type:"string",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"],description:'Market data entry type (IMPORTANT: Use the numeric/alphabetic value, not the descriptive name. For example, use "0" for Bid, "1" for Offer, "2" for Trade, "3" for Index Value, "4" for Opening Price)'}},required:["symbol","mdReqID"]},q=class{parser;server=new D({name:"fixparser",version:"1.0.0"},{capabilities:{tools:{},prompts:{},resources:{}}});transport=new b;onReady=void 0;pendingRequests=new Map;constructor({logger:a,onReady:i}){i&&(this.onReady=i)}async register(a){this.parser=a,this.parser.addOnMessageCallback(i=>{let o=i.messageType;if(o===c.MarketDataSnapshotFullRefresh||o===c.ExecutionReport||o===c.Reject){let n=o===c.MarketDataSnapshotFullRefresh?i.getField(t.MDReqID):o===c.Reject?i.getField(t.RefSeqNum):i.getField(t.ClOrdID);if(n){let e=n.value;if(typeof e=="string"||typeof e=="number")if(o===c.Reject){let s=i.getField(t.RefMsgType);if(s&&s.value===c.NewOrderSingle){let p=this.pendingRequests.get(String(e));p&&(p(i),this.pendingRequests.delete(String(e)))}}else{let s=this.pendingRequests.get(String(e));s&&(s(i),this.pendingRequests.delete(String(e)))}}}}),this.addWorkflows(),await this.server.connect(this.transport),this.onReady&&this.onReady()}addWorkflows(){if(!this.parser||!this.server)return;let a=(i,o)=>{let n={};for(let[e,s]of Object.entries(o.properties||{})){let p=s,d=i?.[e];if(p.required&&d==null)throw new Error(`Required property '${e}' is missing`);d!==void 0?n[e]=d:p.default!==void 0&&(n[e]=p.default)}return n};this.server.setRequestHandler(C,async()=>({resources:[]})),this.server.setRequestHandler(A,async()=>({tools:[{name:"parse",description:"Parses a FIX message and describes it in plain language",inputSchema:T},{name:"parseToJSON",description:"Parses a FIX message into JSON",inputSchema:I},{name:"newOrderSingle",description:"Creates and sends a New Order Single",inputSchema:R},{name:"marketDataRequest",description:"Sends a request for Market Data with the given symbol",inputSchema:O}]})),this.server.setRequestHandler(E,async i=>{let{name:o,arguments:n}=i.params;switch(o){case"parse":try{let{fixString:e}=a(n,T),s=this.parser?.parse(e);return!s||s.length===0?{isError:!0,content:[{type:"text",text:"Error: Failed to parse FIX string"}]}:{content:[{type:"text",text:`${s[0].description}
|
|
3
|
+
${s[0].messageTypeDescription}`}]}}catch(e){return{isError:!0,content:[{type:"text",text:`Error: ${e instanceof Error?e.message:"Failed to parse FIX string"}`}]}}case"parseToJSON":try{let{fixString:e}=a(n,I),s=this.parser?.parse(e);return!s||s.length===0?{isError:!0,content:[{type:"text",text:"Error: Failed to parse FIX string"}]}:{content:[{type:"text",text:`${s[0].toFIXJSON()}`}]}}catch(e){return{isError:!0,content:[{type:"text",text:`Error: ${e instanceof Error?e.message:"Failed to parse FIX string"}`}]}}case"newOrderSingle":try{let{clOrdID:e,handlInst:s,quantity:p,price:d,ordType:m,side:g,symbol:y,timeInForce:h}=a(n,R),S=new Promise(M=>{this.pendingRequests.set(e,M)}),x=this.parser?.createMessage(new r(t.MsgType,c.NewOrderSingle),new r(t.MsgSeqNum,this.parser?.getNextTargetMsgSeqNum()),new r(t.SenderCompID,this.parser?.sender),new r(t.TargetCompID,this.parser?.target),new r(t.SendingTime,this.parser?.getTimestamp()),new r(t.ClOrdID,e),new r(t.Side,g),new r(t.Symbol,y),new r(t.OrderQty,p),new r(t.Price,d),new r(t.OrdType,m),new r(t.HandlInst,s),new r(t.TimeInForce,h),new r(t.TransactTime,this.parser?.getTimestamp()));if(!this.parser?.connected)return{isError:!0,content:[{type:"text",text:"Error: Not connected. Ignoring message."}]};this.parser?.send(x);let f=await S;return{content:[{type:"text",text:f.messageType===c.Reject?`Reject message for order ${e}: ${JSON.stringify(f.toFIXJSON())}`:`Execution Report for order ${e}: ${JSON.stringify(f.toFIXJSON())}`}]}}catch(e){return{isError:!0,content:[{type:"text",text:`Error: ${e instanceof Error?e.message:"Failed to create order"}`}]}}case"marketDataRequest":try{let{mdUpdateType:e,symbol:s,mdReqID:p,subscriptionRequestType:d,mdEntryType:m}=a(n,O),g=new Promise(S=>{this.pendingRequests.set(p,S)}),y=this.parser?.createMessage(new r(t.MsgType,c.MarketDataRequest),new r(t.SenderCompID,this.parser?.sender),new r(t.MsgSeqNum,this.parser?.getNextTargetMsgSeqNum()),new r(t.TargetCompID,this.parser?.target),new r(t.SendingTime,this.parser?.getTimestamp()),new r(t.MarketDepth,0),new r(t.MDUpdateType,e),new r(t.NoRelatedSym,1),new r(t.Symbol,s),new r(t.MDReqID,p),new r(t.SubscriptionRequestType,d),new r(t.NoMDEntryTypes,1),new r(t.MDEntryType,m));if(!this.parser?.connected)return{isError:!0,content:[{type:"text",text:"Error: Not connected. Ignoring message."}]};this.parser?.send(y);let h=await g;return{content:[{type:"text",text:`Market data for ${s}: ${JSON.stringify(h.toFIXJSON())}`}]}}catch(e){return{isError:!0,content:[{type:"text",text:`Error: ${e instanceof Error?e.message:"Failed to request market data"}`}]}}default:throw new Error(`Unknown tool: ${o}`)}}),this.server.setRequestHandler(N,async()=>({prompts:[{name:"parse",description:"Parses a FIX message and describes it in plain language",arguments:[{name:"fixString",description:"FIX message string to parse",required:!0}]},{name:"parseToJSON",description:"Parses a FIX message into JSON",arguments:[{name:"fixString",description:"FIX message string to parse",required:!0}]},{name:"newOrderSingle",description:"Creates and sends a New Order Single. IMPORTANT: All parameters must be explicitly provided by the user - no assumptions will be made.",arguments:[{name:"clOrdID",description:"Client Order ID",required:!0},{name:"handlInst",description:"Handling instruction (1=Manual, 2=Automated, 3=AutomatedNoIntervention)",required:!0},{name:"quantity",description:"Order quantity",required:!0},{name:"price",description:"Order price",required:!0},{name:"ordType",description:"Order type (1=Market, 2=Limit, 3=Stop)",required:!0},{name:"side",description:"Order side (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)",required:!0},{name:"symbol",description:"Trading symbol",required:!0},{name:"timeInForce",description:"Time in force (0=Day, 1=Good Till Cancel, 2=At Opening, 3=Immediate or Cancel, 4=Fill or Kill, 5=Good Till Crossing, 6=Good Till Date)",required:!0}]},{name:"marketDataRequest",description:"Sends a request for Market Data with the given symbol. IMPORTANT: All parameters must be explicitly provided by the user - no assumptions will be made.",arguments:[{name:"mdUpdateType",description:"Market data update type (0=FullRefresh, 1=IncrementalRefresh)",required:!0},{name:"symbol",description:"Trading symbol",required:!0},{name:"mdReqID",description:"Market data request ID",required:!0},{name:"subscriptionRequestType",description:"Subscription request type (0=Snapshot + Updates, 1=Snapshot, 2=Unsubscribe)",required:!0},{name:"mdEntryType",description:"Market data entry type (0=Bid, 1=Offer, 2=Trade, 3=Index Value, 4=Opening Price)",required:!0}]}]})),this.server.setRequestHandler(v,async i=>{let{name:o,arguments:n}=i.params;switch(o){case"parse":return{messages:[{role:"user",content:{type:"text",text:`Please parse and explain this FIX message: ${n?.fixString||""}`}}]};case"parseToJSON":return{messages:[{role:"user",content:{type:"text",text:`Please parse the FIX message to JSON: ${n?.fixString||""}`}}]};case"newOrderSingle":{let{clOrdID:e,handlInst:s,quantity:p,price:d,ordType:m,side:g,symbol:y,timeInForce:h}=n||{};return{messages:[{role:"user",content:{type:"text",text:["You are an AI assistant that helps users create FIX New Order Single messages.","You must **first verify** that all required fields are provided:","- ClOrdID (Client Order ID)","- HandlInst (1=Manual, 2=Automated, 3=AutomatedNoIntervention)","- Quantity (Order quantity)","- Price (Order price)","- OrdType (1=Market, 2=Limit, 3=Stop)","- Side (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)","- Symbol (Trading symbol)","- TimeInForce (0=Day, 1=Good Till Cancel, 2=At Opening, 3=Immediate or Cancel, 4=Fill or Kill, 5=Good Till Crossing, 6=Good Till Date)","","Only when all fields are present and valid, respond with:","`VERIFICATION: All parameters valid. Ready to proceed.`","","Otherwise, list the missing or invalid ones.","","Do not create the FIX message until verification is complete.","","Current parameters:",`- ClOrdID: ${e}`,`- HandlInst: ${s}`,`- Quantity: ${p}`,`- Price: ${d}`,`- OrdType: ${m}`,`- Side: ${g}`,`- Symbol: ${y}`,`- TimeInForce: ${h}`,"","IMPORTANT: The response will be either:","1. An Execution Report (MsgType=8) if the order was successfully placed","2. A Reject message (MsgType=3) if the order failed to execute (e.g., due to missing or invalid parameters)"].join(`
|
|
4
|
+
`)}}]}}case"marketDataRequest":{let{mdUpdateType:e,symbol:s,mdReqID:p,subscriptionRequestType:d,mdEntryType:m}=n||{};return{messages:[{role:"user",content:{type:"text",text:["You are an AI assistant that helps users create FIX Market Data Request messages.","You must **first verify** that all required fields are provided:","- MDUpdateType (0=FullRefresh, 1=IncrementalRefresh)","- Symbol (Trading symbol)","- MDReqID (Market data request ID)","- SubscriptionRequestType (0=Snapshot + Updates, 1=Snapshot, 2=Unsubscribe)","- MDEntryType (0=Bid, 1=Offer, 2=Trade, 3=Index Value, 4=Opening Price)","","Only when all fields are present and valid, respond with:","`VERIFICATION: All parameters valid. Ready to proceed.`","","Otherwise, list the missing or invalid ones.","","Do not create the FIX message until verification is complete.","","Current parameters:",`- MDUpdateType: ${e}`,`- Symbol: ${s}`,`- MDReqID: ${p}`,`- SubscriptionRequestType: ${d}`,`- MDEntryType: ${m}`].join(`
|
|
5
|
+
`)}}]}}default:throw new Error(`Unknown prompt: ${o}`)}}),process.on("SIGINT",async()=>{await this.server.close(),process.exit(0)})}};var w="CLIENT2",F="EXECUTOR",B=async()=>{await k.setLicenseKey(process.env.FIXPARSER_LICENSE_KEY);let a=new X({logging:!1,plugins:[new q({port:3099,onReady:()=>{}})]}),i=()=>{let n=a.createMessage(new l(u.MsgType,$.Logon),new l(u.MsgSeqNum,a.getNextTargetMsgSeqNum()),new l(u.SenderCompID,w),new l(u.SendingTime,a.getTimestamp()),new l(u.TargetCompID,F),new l(u.ResetSeqNumFlag,U.Yes),new l(u.EncryptMethod,P.None),new l(u.HeartBtInt,10));a.send(n)},o={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:process.env.FIXPARSER_SENDER||w,target:process.env.FIXPARSER_TARGET||F,fixVersion:process.env.FIXPARSER_TARGET||"FIX.4.4",onOpen:()=>{i()},onMessage:n=>{},onClose:()=>{setTimeout(()=>{a.connect(o)},1e3)}};a.connect(o)};B().catch(a=>console.error("Error initializing server:",a));
|
|
9
6
|
//# sourceMappingURL=example_mcp_local.mjs.map
|