fixparser-plugin-mcp 9.1.7-ff35b2c1 → 9.1.7-ff7241ee
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 +1315 -840
- package/build/cjs/MCPLocal.js.map +4 -4
- package/build/esm/MCPLocal.mjs +1315 -830
- package/build/esm/MCPLocal.mjs.map +4 -4
- package/build-examples/cjs/example_mcp_local.js +60 -12
- package/build-examples/cjs/example_mcp_local.js.map +4 -4
- package/build-examples/esm/example_mcp_local.mjs +56 -8
- package/build-examples/esm/example_mcp_local.mjs.map +4 -4
- package/package.json +4 -5
- package/types/schemas/index.d.ts +0 -15
- package/types/schemas/schemas.d.ts +0 -168
- package/types/tools/index.d.ts +0 -17
- package/types/tools/marketData.d.ts +0 -40
- package/types/tools/order.d.ts +0 -12
- package/types/tools/parse.d.ts +0 -5
- package/types/tools/parseToJSON.d.ts +0 -5
|
@@ -1,16 +1,64 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
"use strict";var C=Object.create;var T=Object.defineProperty;var D=Object.getOwnPropertyDescriptor;var P=Object.getOwnPropertyNames;var M=Object.getPrototypeOf,R=Object.prototype.hasOwnProperty;var w=(t,i,e,r)=>{if(i&&typeof i=="object"||typeof i=="function")for(let o of P(i))!R.call(t,o)&&o!==e&&T(t,o,{get:()=>i[o],enumerable:!(r=D(i,o))||r.enumerable});return t};var N=(t,i,e)=>(e=t!=null?C(M(t)):{},w(i||!t||!t.__esModule?T(e,"default",{value:t,enumerable:!0}):e,t));var a=require("fixparser");var I=class{format;useStderr;constructor({format:t="json",useStderr:i=!1}){this.format=t,this.useStderr=i}configure(t){this.format=t.format||"json",t.useStderr!==void 0&&(this.useStderr=t.useStderr)}async send(t){let i=this.useStderr?console.error:console.log;if(this.format==="json")i(JSON.stringify(t));else if(this.format==="jsonrpc"){let{message:e,...r}=t,o={jsonrpc:"2.0",method:t.level,params:{message:e,...r},id:t.id||Date.now()};i(JSON.stringify(o))}else{let{name:e,id:r,message:o,level:c,...u}=t,m=Object.entries(u).map(([h,g])=>`${h}: ${g}`),p="";e&&(p+=`${e} `),p+=`${r}: ${o}`,i(p,m.join(", "))}}async flush(){}async close(){}status(){return"connected"}};var x=require("@modelcontextprotocol/sdk/server/index.js"),v=require("@modelcontextprotocol/sdk/server/stdio.js"),d=require("fixparser"),y=require("zod"),n=require("fixparser"),b=N(require("quickchart-js"),1),s=require("fixparser"),F={parse:{description:"Parses a FIX message and describes it in plain language",schema:{type:"object",properties:{fixString:{type:"string"}},required:["fixString"]}},parseToJSON:{description:"Parses a FIX message into JSON",schema:{type:"object",properties:{fixString:{type:"string"}},required:["fixString"]}},verifyOrder:{description:"Verifies order parameters before execution. verifyOrder must be called before executeOrder.",schema:{type:"object",properties:{clOrdID:{type:"string"},handlInst:{type:"string",enum:["1","2","3"],description:"Handling Instructions: 1=Automated Execution No Intervention, 2=Automated Execution Intervention OK, 3=Manual Order"},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"],description:"Order Type: 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"},side:{type:"string",enum:["1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H"],description:"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:{type:"string"},timeInForce:{type:"string",enum:["0","1","2","3","4","5","6","7","8","9","A","B","C"],description:"Time In Force: 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"}},required:["clOrdID","handlInst","quantity","price","ordType","side","symbol","timeInForce"]}},executeOrder:{description:"Executes a verified order. verifyOrder must be called before executeOrder. user has to explicitly allow executeOrder.",schema:{type:"object",properties:{clOrdID:{type:"string"},handlInst:{type:"string",enum:["1","2","3"],description:"Handling Instructions: 1=Automated Execution No Intervention, 2=Automated Execution Intervention OK, 3=Manual Order"},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"],description:"Order Type: 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"},side:{type:"string",enum:["1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H"],description:"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:{type:"string"},timeInForce:{type:"string",enum:["0","1","2","3","4","5","6","7","8","9","A","B","C"],description:"Time In Force: 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"}},required:["clOrdID","handlInst","quantity","price","ordType","side","symbol","timeInForce"]}},marketDataRequest:{description:"Requests market data for specified symbols",schema:{type:"object",properties:{mdUpdateType:{type:"string",enum:["0","1"],description:"Market Data Update Type: 0=Full Refresh, 1=Incremental Refresh"},symbols:{type:"array",items:{type:"string"}},mdReqID:{type:"string"},subscriptionRequestType:{type:"string",enum:["0","1","2"],description:"Subscription Request Type: 0=Snapshot, 1=Snapshot + Updates, 2=Disable Previous Snapshot + Update Request"},mdEntryTypes:{type:"array",items:{type:"string",enum:["0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]},description:"Market Data Entry Types: 0=Bid, 1=Offer, 2=Trade, 3=Index Value, 4=Opening Price, 5=Closing Price, 6=Settlement Price, 7=High Price, 8=Low Price, 9=Trade Volume, A=Open Interest, B=Simulated Sell Price, C=Simulated Buy Price, D=Empty Book, E=Session High Bid, F=Session Low Offer, G=Fixing Price, H=Electronic Volume, I=Threshold Limits and Price Band Variation, J=Clearing Price, K=Open Interest Change, L=Last Trade Price, M=Last Trade Volume, N=Last Trade Time, O=Last Trade Tick, P=Last Trade Exchange, Q=Last Trade ID, R=Last Trade Side, S=Last Trade Price Change, T=Last Trade Price Change Percent, U=Last Trade Price Change Basis Points, V=Last Trade Price Change Points, W=Last Trade Price Change Ticks, X=Last Trade Price Change Ticks Percent, Y=Last Trade Price Change Ticks Basis Points, Z=Last Trade Price Change Ticks Points"}},required:["mdUpdateType","symbols","mdReqID","subscriptionRequestType"]}},getStockGraph:{description:"Generates a price chart for a given symbol",schema:{type:"object",properties:{symbol:{type:"string"}},required:["symbol"]}},getStockPriceHistory:{description:"Returns price history for a given symbol",schema:{type:"object",properties:{symbol:{type:"string"}},required:["symbol"]}}},k=(t,i)=>async e=>{try{let r=new Promise(p=>{i.set(e.mdReqID,p)}),o=e.mdEntryTypes||[n.MDEntryType.Bid,n.MDEntryType.Offer,n.MDEntryType.TradeVolume],c=[new n.Field(n.Fields.MsgType,n.Messages.MarketDataRequest),new n.Field(n.Fields.SenderCompID,t.sender),new n.Field(n.Fields.MsgSeqNum,t.getNextTargetMsgSeqNum()),new n.Field(n.Fields.TargetCompID,t.target),new n.Field(n.Fields.SendingTime,t.getTimestamp()),new n.Field(n.Fields.MDReqID,e.mdReqID),new n.Field(n.Fields.SubscriptionRequestType,e.subscriptionRequestType),new n.Field(n.Fields.MarketDepth,0),new n.Field(n.Fields.MDUpdateType,e.mdUpdateType)];c.push(new n.Field(n.Fields.NoRelatedSym,e.symbols.length)),e.symbols.forEach(p=>{c.push(new n.Field(n.Fields.Symbol,p))}),c.push(new n.Field(n.Fields.NoMDEntryTypes,o.length)),o.forEach(p=>{c.push(new n.Field(n.Fields.MDEntryType,p))});let u=t.createMessage(...c);if(!t.connected)return{content:[{type:"text",text:"Error: Not connected. Ignoring message.",uri:"marketDataRequest"}],isError:!0};t.send(u);let m=await r;return{content:[{type:"text",text:`Market data for ${e.symbols.join(", ")}: ${JSON.stringify(m.toFIXJSON())}`,uri:"marketDataRequest"}]}}catch(r){return{content:[{type:"text",text:`Error: ${r instanceof Error?r.message:"Failed to request market data"}`,uri:"marketDataRequest"}],isError:!0}}},L=t=>async i=>{try{let e=i.symbol,r=t.get(e)||[];if(r.length===0)return{content:[{type:"text",text:`No price data available for ${e}`,uri:"getStockGraph"}]};let o=new b.default;o.setWidth(300),o.setHeight(150),o.setBackgroundColor("transparent");let c=r.map(l=>new Date(l.timestamp).toLocaleTimeString()),u=r.map(l=>l.bid),m=r.map(l=>l.offer),p=r.map(l=>l.spread),h=r.map(l=>l.volume),g={type:"line",data:{labels:c,datasets:[{label:"Bid",data:u,borderColor:"#28a745",backgroundColor:"rgba(40, 167, 69, 0.1)",fill:!1,tension:.4},{label:"Offer",data:m,borderColor:"#dc3545",backgroundColor:"rgba(220, 53, 69, 0.1)",fill:!1,tension:.4},{label:"Spread",data:p,borderColor:"#6c757d",backgroundColor:"rgba(108, 117, 125, 0.1)",fill:!1,tension:.4},{label:"Volume",data:h,borderColor:"#007bff",backgroundColor:"rgba(0, 123, 255, 0.1)",fill:!0,tension:.4}]},options:{responsive:!0,plugins:{title:{display:!0,text:`${e} Market Data`}},scales:{y:{beginAtZero:!1}}}};return o.setConfig(g),{content:[{type:"image",data:(await o.toBinary()).toString("base64"),mimeType:"image/png",metadata:{width:300,height:150}}]}}catch(e){return{content:[{type:"text",text:`Error: ${e instanceof Error?e.message:"Failed to generate chart"}`,uri:"getStockGraph"}],isError:!0}}},A=t=>async i=>{try{let e=i.symbol,r=t.get(e)||[];return r.length===0?{content:[{type:"text",text:`No price data available for ${e}`,uri:"getStockPriceHistory"}]}:{content:[{type:"text",text:JSON.stringify({symbol:e,count:r.length,data:r.map(o=>({timestamp:new Date(o.timestamp).toISOString(),bid:o.bid,offer:o.offer,spread:o.spread,volume:o.volume}))},null,2),uri:"getStockPriceHistory"}]}}catch(e){return{content:[{type:"text",text:`Error: ${e instanceof Error?e.message:"Failed to get stock price history"}`,uri:"getStockPriceHistory"}],isError:!0}}},q={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"},B={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"},G={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"},H={1:"AutomatedExecutionNoIntervention",2:"AutomatedExecutionInterventionOK",3:"ManualOrder"},$=(t,i)=>async e=>{try{return i.set(e.clOrdID,{clOrdID:e.clOrdID,handlInst:e.handlInst,quantity:Number.parseFloat(String(e.quantity)),price:Number.parseFloat(String(e.price)),ordType:e.ordType,side:e.side,symbol:e.symbol,timeInForce:e.timeInForce}),{content:[{type:"text",text:`VERIFICATION: All parameters valid. Ready to proceed with order execution.
|
|
3
|
-
|
|
2
|
+
"use strict";var p=require("fixparser");var I=class{format;constructor({format:o="json"}){this.format=o}configure(o){this.format=o.format||"json"}async send(o){if(this.format==="json")console.log(JSON.stringify(o));else if(this.format==="jsonrpc"){let{message:a,...t}=o,r={jsonrpc:"2.0",method:o.level,params:{message:a,...t},id:o.id||Date.now()};console.log(JSON.stringify(r))}else{let{name:a,id:t,message:r,level:s,...c}=o,d=Object.entries(c).map(([l,m])=>`${l}: ${m}`),i="";a&&(i+=`${a} `),i+=`${t}: ${r}`,console.log(i,d.join(", "))}}async flush(){}async close(){}status(){return"connected"}};var b=require("@modelcontextprotocol/sdk/server/index.js"),F=require("@modelcontextprotocol/sdk/server/stdio.js"),e=require("fixparser"),n=require("zod"),S=n.z.object({symbol:n.z.string()}),T=n.z.object({fixString:n.z.string()}),O=n.z.object({clOrdID:n.z.string(),handlInst:n.z.enum(["1","2","3"]),quantity:n.z.string(),price:n.z.string(),ordType:n.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"]),side:n.z.enum(["1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H"]),symbol:n.z.string(),timeInForce:n.z.enum(["0","1","2","3","4","5","6","7","8","9","A","B","C"])}),v=n.z.object({mdUpdateType:n.z.enum(["0","1"]),symbols:n.z.array(n.z.string()),mdReqID:n.z.string(),subscriptionRequestType:n.z.enum(["0","1","2"]),mdEntryTypes:n.z.array(n.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","R","S","T","U","V","W","X","Y","Z","a","b","c","d","e","g","h","i","t"]))}),E=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"]}}},resources:{greeting:{description:"A simple greeting resource",uri:"greeting-resource"},stockGraph:{description:"Generates a price chart for a given symbol",uri:"stockGraph",parameters:{type:"object",properties:{symbol:{type:"string"}},required:["symbol"]}},stockPriceHistory:{description:"Returns price history for a given symbol",uri:"stockPriceHistory",parameters:{type:"object",properties:{symbol:{type:"string"}},required:["symbol"]}}}}});transport=new F.StdioServerTransport;onReady=void 0;pendingRequests=new Map;verifiedOrders=new Map;marketDataPrices=new Map;MAX_PRICE_HISTORY=1e5;constructor({logger:o,onReady:a}){a&&(this.onReady=a)}async register(o){this.parser=o,this.parser.addOnMessageCallback(a=>{this.parser?.logger.log({level:"info",message:`MCP Server received message: ${a.messageType}: ${a.description}`});let t=a.messageType;if(t===e.Messages.MarketDataSnapshotFullRefresh||t===e.Messages.ExecutionReport||t===e.Messages.Reject||t===e.Messages.MarketDataIncrementalRefresh){this.parser?.logger.log({level:"info",message:`MCP Server handling message type: ${t}`});let r;if(t===e.Messages.MarketDataIncrementalRefresh||t===e.Messages.MarketDataSnapshotFullRefresh){let s=a.getField(e.Fields.Symbol),c=a.getField(e.Fields.MDEntryPx),d=a.getField(e.Fields.MDEntryTime)?.value||Date.now();if(s?.value&&c?.value){let i=String(s.value),l=Number(c.value),m=this.marketDataPrices.get(i)||[];m.push({timestamp:Number(d),price:l}),m.length>this.MAX_PRICE_HISTORY&&m.shift(),this.marketDataPrices.set(i,m),this.parser?.logger.log({level:"info",message:`MCP Server added ${s}: ${l}`})}}if(t===e.Messages.MarketDataSnapshotFullRefresh){let s=a.getField(e.Fields.MDReqID);s&&(r=String(s.value))}else if(t===e.Messages.ExecutionReport){let s=a.getField(e.Fields.ClOrdID);s&&(r=String(s.value))}else if(t===e.Messages.Reject){let s=a.getField(e.Fields.RefSeqNum);s&&(r=String(s.value))}if(r){let s=this.pendingRequests.get(r);s&&(s(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(n.z.object({method:n.z.literal("resources/list")}),async(o,a)=>({resources:[{name:"greeting",description:"A simple greeting resource",uri:"greeting-resource"},{name:"stockGraph",description:"Generates a price chart for a given symbol",uri:"stockGraph",parameters:{type:"object",properties:{symbol:{type:"string"}},required:["symbol"]}},{name:"stockPriceHistory",description:"Returns price history for a given symbol",uri:"stockPriceHistory",parameters:{type:"object",properties:{symbol:{type:"string"}},required:["symbol"]}}]})),this.server.setRequestHandler(n.z.object({method:n.z.literal("tools/list")}),async(o,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(n.z.object({method:n.z.literal("resources/read"),params:n.z.object({uri:n.z.string()})}),async(o,a)=>{let{uri:t}=o.params;switch(t){case"greeting-resource":return{contents:[{type:"text",text:"Hello, world!",uri:"greeting-resource"}]};case"stockGraph":return{contents:[{type:"text",text:"This resource requires a symbol parameter. Please use the stockGraph resource with a symbol parameter.",uri:"stockGraph"}]};case"stockPriceHistory":return{contents:[{type:"text",text:"This resource requires a symbol parameter. Please use the stockPriceHistory resource with a symbol parameter.",uri:"stockPriceHistory"}]};default:return{contents:[{type:"text",text:`Resource not found: ${t}`,uri:t}],isError:!0}}}),this.server.setRequestHandler(n.z.object({method:n.z.literal("parse"),params:T}),async(o,a)=>{try{let t=o.params,r=this.parser?.parse(t.fixString);return!r||r.length===0?{contents:[{type:"text",text:"Error: Failed to parse FIX string"}],isError:!0}:{contents:[{type:"text",text:`${r[0].description}
|
|
3
|
+
${r[0].messageTypeDescription}`}]}}catch(t){return{contents:[{type:"text",text:`Error: ${t instanceof Error?t.message:"Failed to parse FIX string"}`}],isError:!0}}}),this.server.setRequestHandler(n.z.object({method:n.z.literal("parseToJSON"),params:T}),async(o,a)=>{try{let t=o.params,r=this.parser?.parse(t.fixString);return!r||r.length===0?{contents:[{type:"text",text:"Error: Failed to parse FIX string"}],isError:!0}:{contents:[{type:"text",text:`${r[0].toFIXJSON()}`}]}}catch(t){return{contents:[{type:"text",text:`Error: ${t instanceof Error?t.message:"Failed to parse FIX string"}`}],isError:!0}}}),this.server.setRequestHandler(n.z.object({method:n.z.literal("verifyOrder"),params:O}),async(o,a)=>{try{let t=o.params;this.verifiedOrders.set(t.clOrdID,{clOrdID:t.clOrdID,handlInst:t.handlInst,quantity:Number.parseFloat(t.quantity),price:Number.parseFloat(t.price),ordType:t.ordType,side:t.side,symbol:t.symbol,timeInForce:t.timeInForce});let r={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"},s={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"},c={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"},d={1:"AutomatedExecutionNoIntervention",2:"AutomatedExecutionInterventionOK",3:"ManualOrder"};return{contents:[{type:"text",text:`VERIFICATION: All parameters valid. Ready to proceed with order execution.
|
|
4
|
+
|
|
4
5
|
Parameters verified:
|
|
5
|
-
- ClOrdID: ${
|
|
6
|
-
- HandlInst: ${
|
|
7
|
-
- Quantity: ${
|
|
8
|
-
- Price: ${
|
|
9
|
-
- OrdType: ${
|
|
10
|
-
- Side: ${
|
|
11
|
-
- Symbol: ${
|
|
12
|
-
- TimeInForce: ${
|
|
6
|
+
- ClOrdID: ${t.clOrdID}
|
|
7
|
+
- HandlInst: ${t.handlInst} (${d[t.handlInst]})
|
|
8
|
+
- Quantity: ${t.quantity}
|
|
9
|
+
- Price: ${t.price}
|
|
10
|
+
- OrdType: ${t.ordType} (${r[t.ordType]})
|
|
11
|
+
- Side: ${t.side} (${s[t.side]})
|
|
12
|
+
- Symbol: ${t.symbol}
|
|
13
|
+
- TimeInForce: ${t.timeInForce} (${c[t.timeInForce]})
|
|
13
14
|
|
|
14
|
-
To execute this order, call the executeOrder tool with these exact same parameters
|
|
15
|
-
|
|
15
|
+
To execute this order, call the executeOrder tool with these exact same parameters.`}]}}catch(t){return{contents:[{type:"text",text:`Error: ${t instanceof Error?t.message:"Failed to verify order parameters"}`}],isError:!0}}}),this.server.setRequestHandler(n.z.object({method:n.z.literal("executeOrder"),params:O}),async(o,a)=>{try{let t=o.params,r=this.verifiedOrders.get(t.clOrdID);if(!r)return{contents:[{type:"text",text:`Error: Order ${t.clOrdID} has not been verified. Please call verifyOrder first.`}],isError:!0};if(r.handlInst!==t.handlInst||r.quantity!==Number.parseFloat(t.quantity)||r.price!==Number.parseFloat(t.price)||r.ordType!==t.ordType||r.side!==t.side||r.symbol!==t.symbol||r.timeInForce!==t.timeInForce)return{contents:[{type:"text",text:"Error: Order parameters do not match the verified order. Please use the exact same parameters that were verified."}],isError:!0};let s=new Promise(i=>{this.pendingRequests.set(t.clOrdID,i)}),c=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,t.clOrdID),new e.Field(e.Fields.Side,t.side),new e.Field(e.Fields.Symbol,t.symbol),new e.Field(e.Fields.OrderQty,Number.parseFloat(t.quantity)),new e.Field(e.Fields.Price,Number.parseFloat(t.price)),new e.Field(e.Fields.OrdType,t.ordType),new e.Field(e.Fields.HandlInst,t.handlInst),new e.Field(e.Fields.TimeInForce,t.timeInForce),new e.Field(e.Fields.TransactTime,this.parser?.getTimestamp()));if(!this.parser?.connected)return{contents:[{type:"text",text:"Error: Not connected. Ignoring message."}],isError:!0};this.parser?.send(c);let d=await s;return this.verifiedOrders.delete(t.clOrdID),{contents:[{type:"text",text:d.messageType===e.Messages.Reject?`Reject message for order ${t.clOrdID}: ${JSON.stringify(d.toFIXJSON())}`:`Execution Report for order ${t.clOrdID}: ${JSON.stringify(d.toFIXJSON())}`}]}}catch(t){return{contents:[{type:"text",text:`Error: ${t instanceof Error?t.message:"Failed to execute order"}`}],isError:!0}}}),this.server.setRequestHandler(n.z.object({method:n.z.literal("marketDataRequest"),params:v}),async(o,a)=>{try{let t=o.params,r=new Promise(i=>{this.pendingRequests.set(t.mdReqID,i)}),s=[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,t.mdReqID),new e.Field(e.Fields.SubscriptionRequestType,t.subscriptionRequestType),new e.Field(e.Fields.MarketDepth,0),new e.Field(e.Fields.MDUpdateType,t.mdUpdateType)];s.push(new e.Field(e.Fields.NoRelatedSym,t.symbols.length)),t.symbols.forEach(i=>{s.push(new e.Field(e.Fields.Symbol,i))}),s.push(new e.Field(e.Fields.NoMDEntryTypes,t.mdEntryTypes.length)),t.mdEntryTypes.forEach(i=>{s.push(new e.Field(e.Fields.MDEntryType,i))});let c=this.parser?.createMessage(...s);if(!this.parser?.connected)return{contents:[{type:"text",text:"Error: Not connected. Ignoring message."}],isError:!0};this.parser?.send(c);let d=await r;return{contents:[{type:"text",text:`Market data for ${t.symbols.join(", ")}: ${JSON.stringify(d.toFIXJSON())}`}]}}catch(t){return{contents:[{type:"text",text:`Error: ${t instanceof Error?t.message:"Failed to request market data"}`}],isError:!0}}}),this.server.setRequestHandler(n.z.object({method:n.z.literal("stockGraph"),params:S}),async(o,a)=>{this.parser?.logger.log({level:"info",message:"MCP Server Resource called: stockGraph"});let r=o.params.symbol,s=this.marketDataPrices.get(r)||[];if(s.length===0)return{contents:[{type:"text",text:`No price data available for ${r}`}]};let c=600,d=300,i=40,l=(c-2*i)/(s.length-1),m=Math.min(...s.map(u=>u.price)),f=Math.max(...s.map(u=>u.price)),x=(d-2*i)/(f-m),D=s.map((u,y)=>{let g=i+y*l,h=d-i-(u.price-m)*x;return`${g},${h}`}).join(" L ");return{contents:[{type:"text",text:`<?xml version="1.0" encoding="UTF-8"?>
|
|
16
|
+
<svg width="${c}" height="${d}" 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},(u,y)=>{let g=i+(d-2*i)*y/4;return`<line x1="${i}" y1="${g}" x2="${c-i}" y2="${g}"/>`}).join(`
|
|
23
|
+
`)}
|
|
24
|
+
</g>
|
|
25
|
+
|
|
26
|
+
<!-- Price line -->
|
|
27
|
+
<path d="M ${D}"
|
|
28
|
+
fill="none"
|
|
29
|
+
stroke="#007bff"
|
|
30
|
+
stroke-width="2"/>
|
|
31
|
+
|
|
32
|
+
<!-- Data points -->
|
|
33
|
+
${s.map((u,y)=>{let g=i+y*l,h=d-i-(u.price-m)*x;return`<circle cx="${g}" 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},(u,y)=>{let g=i+(c-2*i)*y/4,h=Math.floor((s.length-1)*y/4),R=new Date(s[h].timestamp).toLocaleTimeString();return`<text x="${g+i}" y="${d-i+20}" text-anchor="middle">${R}</text>`}).join(`
|
|
39
|
+
`)}
|
|
40
|
+
${Array.from({length:5},(u,y)=>{let g=i+(d-2*i)*y/4,h=f-(f-m)*y/4;return`<text x="${i-5}" y="${g+4}" text-anchor="end">$${h.toFixed(2)}</text>`}).join(`
|
|
41
|
+
`)}
|
|
42
|
+
</g>
|
|
43
|
+
|
|
44
|
+
<!-- Title -->
|
|
45
|
+
<text x="${c/2}" y="${i/2}"
|
|
46
|
+
font-family="Arial" font-size="16" font-weight="bold"
|
|
47
|
+
text-anchor="middle" fill="#212529">
|
|
48
|
+
${r} - Price Chart (${s.length} points)
|
|
49
|
+
</text>
|
|
50
|
+
</svg>`}]}}),this.server.setRequestHandler(n.z.object({method:n.z.literal("stockPriceHistory"),params:S}),async(o,a)=>{this.parser?.logger.log({level:"info",message:"MCP Server Resource called: stockPriceHistory"});let r=o.params.symbol,s=this.marketDataPrices.get(r)||[];return s.length===0?{contents:[{type:"text",text:`No price data available for ${r}`}]}:{contents:[{type:"text",text:JSON.stringify({symbol:r,count:s.length,prices:s.map(c=>({timestamp:new Date(c.timestamp).toISOString(),price:c.price}))},null,2)}]}}),this.server.setRequestHandler(n.z.object({method:n.z.literal("tools/call"),params:n.z.object({name:n.z.string(),arguments:n.z.record(n.z.any()),_meta:n.z.object({progressToken:n.z.number()}).optional()})}),async(o,a)=>{let{name:t,arguments:r}=o.params;switch(t){case"parse":try{let s=this.parser?.parse(r.fixString);return!s||s.length===0?{contents:[{type:"text",text:"Error: Failed to parse FIX string"}],isError:!0}:{contents:[{type:"text",text:`${s[0].description}
|
|
51
|
+
${s[0].messageTypeDescription}`}]}}catch(s){return{contents:[{type:"text",text:`Error: ${s instanceof Error?s.message:"Failed to parse FIX string"}`}],isError:!0}}case"parseToJSON":try{let s=this.parser?.parse(r.fixString);return!s||s.length===0?{contents:[{type:"text",text:"Error: Failed to parse FIX string"}],isError:!0}:{contents:[{type:"text",text:`${s[0].toFIXJSON()}`}]}}catch(s){return{contents:[{type:"text",text:`Error: ${s instanceof Error?s.message:"Failed to parse FIX string"}`}],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 s={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"},c={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"},i={1:"AutomatedExecutionNoIntervention",2:"AutomatedExecutionInterventionOK",3:"ManualOrder"};return{contents:[{type:"text",text:`VERIFICATION: All parameters valid. Ready to proceed with order execution.
|
|
52
|
+
|
|
53
|
+
Parameters verified:
|
|
54
|
+
- ClOrdID: ${r.clOrdID}
|
|
55
|
+
- HandlInst: ${r.handlInst} (${i[r.handlInst]})
|
|
56
|
+
- Quantity: ${r.quantity}
|
|
57
|
+
- Price: ${r.price}
|
|
58
|
+
- OrdType: ${r.ordType} (${s[r.ordType]})
|
|
59
|
+
- Side: ${r.side} (${c[r.side]})
|
|
60
|
+
- Symbol: ${r.symbol}
|
|
61
|
+
- TimeInForce: ${r.timeInForce} (${d[r.timeInForce]})
|
|
62
|
+
|
|
63
|
+
To execute this order, call the executeOrder tool with these exact same parameters.`}]}}catch(s){return{contents:[{type:"text",text:`Error: ${s instanceof Error?s.message:"Failed to verify order parameters"}`}],isError:!0}}case"executeOrder":try{let s=this.verifiedOrders.get(r.clOrdID);if(!s)return{contents:[{type:"text",text:`Error: Order ${r.clOrdID} has not been verified. Please call verifyOrder first.`}],isError:!0};if(s.handlInst!==r.handlInst||s.quantity!==Number.parseFloat(r.quantity)||s.price!==Number.parseFloat(r.price)||s.ordType!==r.ordType||s.side!==r.side||s.symbol!==r.symbol||s.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."}],isError:!0};let c=new Promise(l=>{this.pendingRequests.set(r.clOrdID,l)}),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."}],isError:!0};this.parser?.send(d);let i=await c;return this.verifiedOrders.delete(r.clOrdID),{contents:[{type:"text",text:i.messageType===e.Messages.Reject?`Reject message for order ${r.clOrdID}: ${JSON.stringify(i.toFIXJSON())}`:`Execution Report for order ${r.clOrdID}: ${JSON.stringify(i.toFIXJSON())}`}]}}catch(s){return{contents:[{type:"text",text:`Error: ${s instanceof Error?s.message:"Failed to execute order"}`}],isError:!0}}case"marketDataRequest":try{let s=new Promise(l=>{this.pendingRequests.set(r.mdReqID,l)}),c=[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)];c.push(new e.Field(e.Fields.NoRelatedSym,r.symbols.length)),r.symbols.forEach(l=>{c.push(new e.Field(e.Fields.Symbol,l))}),c.push(new e.Field(e.Fields.NoMDEntryTypes,r.mdEntryTypes.length)),r.mdEntryTypes.forEach(l=>{c.push(new e.Field(e.Fields.MDEntryType,l))});let d=this.parser?.createMessage(...c);if(!this.parser?.connected)return{contents:[{type:"text",text:"Error: Not connected. Ignoring message."}],isError:!0};this.parser?.send(d);let i=await s;return{contents:[{type:"text",text:`Market data for ${r.symbols.join(", ")}: ${JSON.stringify(i.toFIXJSON())}`}]}}catch(s){return{contents:[{type:"text",text:`Error: ${s instanceof Error?s.message:"Failed to request market data"}`}],isError:!0}}default:return{contents:[{type:"text",text:`Tool not found: ${t}`}],isError:!0}}}),process.on("SIGINT",async()=>{await this.server.close(),process.exit(0)}))}};var w=async()=>{await p.LicenseManager.setLicenseKey(process.env.FIXPARSER_LICENSE_KEY);let o=process.env.FIXPARSER_SENDER||"SENDER",a=process.env.FIXPARSER_TARGET||"TARGET",t=new p.FIXParser({logging:!0,logOptions:{level:"info",format:"jsonrpc",transport:new I({format:"jsonrpc"})},plugins:[new E({port:3099,onReady:()=>{}})]}),r=()=>{let c=t.createMessage(new p.Field(p.Fields.MsgType,p.Messages.Logon),new p.Field(p.Fields.MsgSeqNum,t.getNextTargetMsgSeqNum()),new p.Field(p.Fields.SenderCompID,o),new p.Field(p.Fields.SendingTime,t.getTimestamp()),new p.Field(p.Fields.TargetCompID,a),new p.Field(p.Fields.ResetSeqNumFlag,p.ResetSeqNumFlag.Yes),new p.Field(p.Fields.EncryptMethod,p.EncryptMethod.None),new p.Field(p.Fields.HeartBtInt,10));t.send(c)},s={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:o,target:a,fixVersion:"FIX.4.4",onOpen:()=>{t.logger.log({level:"info",message:"FIXParser logging in..."}),r()},onClose:()=>{t.logger.log({level:"info",message:"FIXParser disconnected. Reconnecting in 1 second..."}),setTimeout(()=>{t.connect(s)},1e3)}};t.connect(s)};w().catch(o=>console.error("Error initializing server:",o));
|
|
16
64
|
//# sourceMappingURL=example_mcp_local.js.map
|