fixparser-plugin-mcp 9.1.7-c6228661 → 9.1.7-d47799ff
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 +596 -1543
- package/build/cjs/MCPLocal.js.map +4 -4
- package/build/cjs/MCPRemote.js +435 -1618
- package/build/cjs/MCPRemote.js.map +4 -4
- package/build/esm/MCPLocal.mjs +596 -1533
- package/build/esm/MCPLocal.mjs.map +4 -4
- package/build/esm/MCPRemote.mjs +444 -1608
- package/build/esm/MCPRemote.mjs.map +4 -4
- package/build-examples/cjs/example_mcp_local.js +46 -10
- package/build-examples/cjs/example_mcp_local.js.map +4 -4
- package/build-examples/esm/example_mcp_local.mjs +46 -10
- package/build-examples/esm/example_mcp_local.mjs.map +4 -4
- package/package.json +8 -9
- package/types/MCPLocal.d.ts +14 -0
- package/types/MCPRemote.d.ts +60 -0
- package/types/PluginOptions.d.ts +6 -0
- package/types/index.d.ts +3 -0
- package/build/cjs/index.js +0 -1917
- package/build/cjs/index.js.map +0 -7
- package/build/esm/index.mjs +0 -1879
- package/build/esm/index.mjs.map +0 -7
- package/build-examples/cjs/example_mcp_remote.js +0 -18
- package/build-examples/cjs/example_mcp_remote.js.map +0 -7
- package/build-examples/esm/example_mcp_remote.mjs +0 -18
- package/build-examples/esm/example_mcp_remote.mjs.map +0 -7
|
@@ -1,18 +1,54 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
"use strict";var E=Object.create;var T=Object.defineProperty;var L=Object.getOwnPropertyDescriptor;var D=Object.getOwnPropertyNames;var B=Object.getPrototypeOf,V=Object.prototype.hasOwnProperty;var H=(t,r,e,s)=>{if(r&&typeof r=="object"||typeof r=="function")for(let i of D(r))!V.call(t,i)&&i!==e&&T(t,i,{get:()=>r[i],enumerable:!(s=L(r,i))||s.enumerable});return t};var N=(t,r,e)=>(e=t!=null?E(B(t)):{},H(r||!t||!t.__esModule?T(e,"default",{value:t,enumerable:!0}):e,t));var g=require("fixparser");var w=class{format;useStderr;constructor({format:t="json",useStderr:r=!1}){this.format=t,this.useStderr=r}configure(t){this.format=t.format||"json",t.useStderr!==void 0&&(this.useStderr=t.useStderr)}async send(t){let r=this.useStderr?console.error:console.log;if(this.format==="json")r(JSON.stringify(t));else if(this.format==="jsonrpc"){let{message:e,...s}=t,i={jsonrpc:"2.0",method:t.level,params:{message:e,...s},id:t.id||Date.now()};r(JSON.stringify(i))}else{let{name:e,id:s,message:i,level:u,...p}=t,m=Object.entries(p).map(([h,n])=>`${h}: ${n}`),l="";e&&(l+=`${e} `),l+=`${s}: ${i}`,r(l,m.join(", "))}}async flush(){}async close(){}status(){return"connected"}};var x=require("@modelcontextprotocol/sdk/server/index.js"),M=require("@modelcontextprotocol/sdk/server/stdio.js"),f=require("zod"),o=require("fixparser"),C=N(require("quickchart-js"),1),d=require("fixparser"),a=require("fixparser");var se=require("@modelcontextprotocol/sdk/server/mcp.js"),oe=require("@modelcontextprotocol/sdk/server/streamableHttp.js"),ne=require("@modelcontextprotocol/sdk/types.js"),ae=require("zod"),q=class{logger;parser;onReady=void 0;verifiedOrders=new Map;pendingRequests=new Map;marketDataPrices=new Map;MAX_PRICE_HISTORY=1e5;constructor({logger:t,onReady:r}){this.logger=t,this.onReady=r}},R={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.",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"]}},technicalAnalysis:{description:"Performs comprehensive technical analysis on market data for a given symbol, including indicators like SMA, EMA, RSI, Bollinger Bands, and trading signals",schema:{type:"object",properties:{symbol:{type:"string",description:"The trading symbol to analyze (e.g., AAPL, MSFT, EURUSD)"}},required:["symbol"]}}};function j(t){return t.reduce((r,e)=>r+e,0)}var $=class{prices;volumes;highs;lows;constructor(t){this.prices=t.map(r=>r.trade>0?r.trade:r.midPrice),this.volumes=t.map(r=>r.volume),this.highs=t.map(r=>r.tradingSessionHighPrice>0?r.tradingSessionHighPrice:r.trade),this.lows=t.map(r=>r.tradingSessionLowPrice>0?r.tradingSessionLowPrice:r.trade)}calculateSMA(t,r){let e=[];for(let s=r-1;s<t.length;s++){let i=t.slice(s-r+1,s+1).reduce((u,p)=>u+p,0);e.push(i/r)}return e}calculateEMA(t,r){let e=2/(r+1),s=[t[0]];for(let i=1;i<t.length;i++)s.push(t[i]*e+s[i-1]*(1-e));return s}calculateRSI(t,r=14){if(t.length<r+1)return[];let e=[];for(let l=1;l<t.length;l++)e.push(t[l]-t[l-1]);let s=e.map(l=>l>0?l:0),i=e.map(l=>l<0?Math.abs(l):0),u=s.slice(0,r).reduce((l,h)=>l+h,0)/r,p=i.slice(0,r).reduce((l,h)=>l+h,0)/r,m=[];for(let l=r;l<e.length;l++){let h=u/p;m.push(100-100/(1+h)),u=(u*(r-1)+s[l])/r,p=(p*(r-1)+i[l])/r}return m}calculateBollingerBands(t,r=20,e=2){if(t.length<r)return[];let s=this.calculateSMA(t,r),i=[];for(let u=0;u<s.length;u++){let p=t.slice(u,u+r),m=s[u],l=p.reduce((n,P)=>n+(P-m)**2,0)/r,h=Math.sqrt(l);i.push({upper:m+h*e,middle:m,lower:m-h*e})}return i}calculateMaxDrawdown(t){let r=t[0],e=0;for(let s=1;s<t.length;s++){t[s]>r&&(r=t[s]);let i=(r-t[s])/r;i>e&&(e=i)}return e}calculatePriceChanges(){let t=[];for(let r=1;r<this.prices.length;r++)t.push((this.prices[r]-this.prices[r-1])/this.prices[r-1]);return t}analyze(){let t=this.prices[this.prices.length-1],r=this.prices[0],e=Math.max(...this.highs),s=Math.min(...this.lows),i=j(this.volumes),u=i/this.volumes.length,p=this.calculatePriceChanges(),m=p.length>0?Math.sqrt(p.reduce((b,c)=>b+c**2,0)/p.length)*Math.sqrt(252)*100:0,l=(t-r)/r*100,h=(t-s)/(e-s)*100,n=this.prices.reduce((b,c,y)=>b+c*this.volumes[y],0)/i,P=this.prices.length>5?(t-this.prices[Math.max(0,this.prices.length-6)])/this.prices[Math.max(0,this.prices.length-6)]*100:0,v=this.prices.length>10?(t-this.prices[Math.max(0,this.prices.length-11)])/this.prices[Math.max(0,this.prices.length-11)]*100:0,S=this.calculateMaxDrawdown(this.prices);return{currentPrice:t,startPrice:r,sessionHigh:e,sessionLow:s,totalVolume:i,avgVolume:u,volatility:m,sessionReturn:l,pricePosition:h,trueVWAP:n,momentum5:P,momentum10:v,maxDrawdown:S}}getTechnicalIndicators(){return{sma5:this.calculateSMA(this.prices,5),sma10:this.calculateSMA(this.prices,10),ema8:this.calculateEMA(this.prices,8),ema21:this.calculateEMA(this.prices,21),rsi:this.calculateRSI(this.prices,14),bollinger:this.calculateBollingerBands(this.prices,20,2)}}generateSignals(){let t=this.analyze(),r=0,e=0,s=[];t.currentPrice>t.trueVWAP?(s.push(`\u2713 BULLISH: Price above VWAP (+${((t.currentPrice-t.trueVWAP)/t.trueVWAP*100).toFixed(2)}%)`),r++):(s.push(`\u2717 BEARISH: Price below VWAP (${((t.currentPrice-t.trueVWAP)/t.trueVWAP*100).toFixed(2)}%)`),e++),t.momentum5>0&&t.momentum10>0?(s.push("\u2713 BULLISH: Positive momentum on both timeframes"),r++):t.momentum5<0&&t.momentum10<0?(s.push("\u2717 BEARISH: Negative momentum on both timeframes"),e++):s.push("\u25D0 MIXED: Conflicting momentum signals");let u=this.volumes[this.volumes.length-1]/t.avgVolume;return u>1.2&&t.sessionReturn>0?(s.push("\u2713 BULLISH: Above-average volume supporting upward move"),r++):u>1.2&&t.sessionReturn<0?(s.push("\u2717 BEARISH: Above-average volume supporting downward move"),e++):s.push("\u25D0 NEUTRAL: Volume not providing clear direction"),t.pricePosition>65&&t.volatility>30?(s.push("\u2717 BEARISH: High in range with elevated volatility - reversal risk"),e++):t.pricePosition<35&&t.volatility>30?(s.push("\u2713 BULLISH: Low in range with volatility - potential bounce"),r++):s.push("\u25D0 NEUTRAL: Price position and volatility not extreme"),{bullishSignals:r,bearishSignals:e,signals:s}}generateJSONAnalysis(t){let r=this.analyze(),e=this.getTechnicalIndicators(),s=this.generateSignals(),i=e.sma5.length>0?e.sma5[e.sma5.length-1]:null,u=e.sma10.length>0?e.sma10[e.sma10.length-1]:null,p=e.ema8[e.ema8.length-1],m=e.ema21[e.ema21.length-1],l=e.rsi.length>0?e.rsi[e.rsi.length-1]:null,h=e.bollinger.length>0?e.bollinger[e.bollinger.length-1]:null,n=this.volumes[this.volumes.length-1],P=n/r.avgVolume,v=(r.sessionHigh-r.currentPrice)/r.sessionHigh*100,S=(r.sessionHigh-r.sessionLow)/r.sessionLow*100,b=(r.currentPrice-r.trueVWAP)/r.trueVWAP*100,c=s.bullishSignals-s.bearishSignals,y=c>0?"BULLISH_BIAS":c<0?"BEARISH_BIAS":"NEUTRAL",O=Math.max(r.sessionLow*1.005,r.trueVWAP*.998),I=r.sessionLow*.995,F=r.sessionHigh*.995,k=(F-r.currentPrice)/(r.currentPrice-I);return{symbol:t,timestamp:new Date().toISOString(),marketStructure:{currentPrice:r.currentPrice,startPrice:r.startPrice,sessionHigh:r.sessionHigh,sessionLow:r.sessionLow,rangeWidth:S,totalVolume:r.totalVolume,sessionPerformance:r.sessionReturn,positionInRange:r.pricePosition},volatility:{impliedVolatility:r.volatility,maxDrawdown:r.maxDrawdown*100,currentDrawdown:v},technicalIndicators:{sma5:i,sma10:u,ema8:p,ema21:m,rsi:l,bollingerBands:h?{upper:h.upper,middle:h.middle,lower:h.lower,position:(r.currentPrice-h.lower)/(h.upper-h.lower)*100}:null},volumeAnalysis:{currentVolume:n,averageVolume:Math.round(r.avgVolume),volumeRatio:P,trueVWAP:r.trueVWAP,priceVsVWAP:b},momentum:{momentum5:r.momentum5,momentum10:r.momentum10,sessionROC:r.sessionReturn},tradingSignals:{...s,overallSignal:y,signalScore:c},riskManagement:{targetEntry:O,stopLoss:I,profitTarget:F,riskRewardRatio:k}}}},G=t=>async r=>{try{let e=r.symbol,s=t.get(e)||[];if(s.length===0)return{content:[{type:"text",text:`No price data available for ${e}. Please request market data first.`,uri:"technicalAnalysis"}]};let u=new $(s).generateJSONAnalysis(e);return{content:[{type:"text",text:`Technical Analysis for ${e}:
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
"use strict";var i=require("fixparser");var u=require("@modelcontextprotocol/sdk/server/mcp.js"),T=require("@modelcontextprotocol/sdk/server/stdio.js"),t=require("fixparser"),s=require("zod"),b=class{parser;server=new u.McpServer({name:"fixparser",version:"1.0.0"},{capabilities:{tools:{},prompts:{},resources:{}}});transport=new T.StdioServerTransport;onReady=void 0;pendingRequests=new Map;verifiedOrders=new Map;constructor({logger:e,onReady:r}){r&&(this.onReady=r)}async register(e){this.parser=e,this.parser.addOnMessageCallback(r=>{let o=r.messageType;if(o===t.Messages.MarketDataSnapshotFullRefresh||o===t.Messages.ExecutionReport||o===t.Messages.Reject){let a;if(o===t.Messages.MarketDataSnapshotFullRefresh){let n=r.getField(t.Fields.MDReqID);n&&(a=String(n.value))}else if(o===t.Messages.ExecutionReport){let n=r.getField(t.Fields.ClOrdID);n&&(a=String(n.value))}else if(o===t.Messages.Reject){let n=r.getField(t.Fields.RefSeqNum);n&&(a=String(n.value))}if(a){let n=this.pendingRequests.get(a);n&&(n(r),this.pendingRequests.delete(a))}}}),this.addWorkflows(),await this.server.connect(this.transport),this.onReady&&this.onReady()}addWorkflows(){this.parser&&this.server&&(this.server.tool("parse","Parses a FIX message and describes it in plain language",{fixString:s.z.string().describe("FIX message string to parse")},async e=>{try{let r=this.parser?.parse(e.fixString);return!r||r.length===0?{content:[{type:"text",text:"Error: Failed to parse FIX string"}],isError:!0}:{content:[{type:"text",text:`${r[0].description}
|
|
3
|
+
${r[0].messageTypeDescription}`}]}}catch(r){return{content:[{type:"text",text:`Error: ${r instanceof Error?r.message:"Failed to parse FIX string"}`}],isError:!0}}}),this.server.tool("parseToJSON","Parses a FIX message into JSON",{fixString:s.z.string().describe("FIX message string to parse")},async e=>{try{let r=this.parser?.parse(e.fixString);return!r||r.length===0?{content:[{type:"text",text:"Error: Failed to parse FIX string"}],isError:!0}:{content:[{type:"text",text:`${r[0].toFIXJSON()}`}]}}catch(r){return{content:[{type:"text",text:`Error: ${r instanceof Error?r.message:"Failed to parse FIX string"}`}],isError:!0}}}),this.server.tool("verifyOrder","Verifies all parameters for a New Order Single. This is the first step - verification only, no order is sent.",{clOrdID:s.z.string().describe("Client Order ID"),handlInst:s.z.enum(["1","2","3"]).describe("Handling instruction (1=Manual, 2=Automated, 3=AutomatedNoIntervention)"),quantity:s.z.string().describe("Order quantity"),price:s.z.string().describe("Order price"),ordType:s.z.string().describe("Order type (1=Market, 2=Limit, 3=Stop)"),side:s.z.string().describe("Order side (1=Buy, 2=Sell, etc.)"),symbol:s.z.string().describe("Trading symbol"),timeInForce:s.z.string().describe("Time in force (0=Day, 1=Good Till Cancel, etc.)")},async e=>{try{return this.verifiedOrders.set(e.clOrdID,{clOrdID:e.clOrdID,handlInst:e.handlInst,quantity:Number.parseFloat(e.quantity),price:Number.parseFloat(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.
|
|
4
|
+
|
|
6
5
|
Parameters verified:
|
|
7
6
|
- ClOrdID: ${e.clOrdID}
|
|
8
|
-
- HandlInst: ${e.handlInst}
|
|
7
|
+
- HandlInst: ${e.handlInst}
|
|
9
8
|
- Quantity: ${e.quantity}
|
|
10
9
|
- Price: ${e.price}
|
|
11
|
-
- OrdType: ${e.ordType}
|
|
12
|
-
- Side: ${e.side}
|
|
10
|
+
- OrdType: ${e.ordType}
|
|
11
|
+
- Side: ${e.side}
|
|
13
12
|
- Symbol: ${e.symbol}
|
|
14
|
-
- TimeInForce: ${e.timeInForce}
|
|
13
|
+
- TimeInForce: ${e.timeInForce}
|
|
15
14
|
|
|
16
|
-
To execute this order, call the executeOrder tool with these exact same parameters
|
|
17
|
-
|
|
15
|
+
To execute this order, call the executeOrder tool with these exact same parameters.`}]}}catch(r){return{content:[{type:"text",text:`Error: ${r instanceof Error?r.message:"Failed to verify order parameters"}`}],isError:!0}}}),this.server.tool("executeOrder","Executes a New Order Single after verification. This is the second step - only call after successful verification.",{clOrdID:s.z.string().describe("Client Order ID"),handlInst:s.z.enum(["1","2","3"]).describe("Handling instruction (1=Manual, 2=Automated, 3=AutomatedNoIntervention)"),quantity:s.z.string().describe("Order quantity"),price:s.z.string().describe("Order price"),ordType:s.z.string().describe("Order type (1=Market, 2=Limit, 3=Stop)"),side:s.z.string().describe("Order side (1=Buy, 2=Sell, etc.)"),symbol:s.z.string().describe("Trading symbol"),timeInForce:s.z.string().describe("Time in force (0=Day, 1=Good Till Cancel, etc.)")},async e=>{try{let r=this.verifiedOrders.get(e.clOrdID);if(!r)return{content:[{type:"text",text:`Error: Order ${e.clOrdID} has not been verified. Please call verifyOrder first.`}],isError:!0};if(r.handlInst!==e.handlInst||r.quantity!==Number.parseFloat(e.quantity)||r.price!==Number.parseFloat(e.price)||r.ordType!==e.ordType||r.side!==e.side||r.symbol!==e.symbol||r.timeInForce!==e.timeInForce)return{content:[{type:"text",text:"Error: Order parameters do not match the verified order. Please use the exact same parameters that were verified."}],isError:!0};let o=new Promise(c=>{this.pendingRequests.set(e.clOrdID,c)}),a=this.parser?.createMessage(new t.Field(t.Fields.MsgType,t.Messages.NewOrderSingle),new t.Field(t.Fields.MsgSeqNum,this.parser?.getNextTargetMsgSeqNum()),new t.Field(t.Fields.SenderCompID,this.parser?.sender),new t.Field(t.Fields.TargetCompID,this.parser?.target),new t.Field(t.Fields.SendingTime,this.parser?.getTimestamp()),new t.Field(t.Fields.ClOrdID,e.clOrdID),new t.Field(t.Fields.Side,e.side),new t.Field(t.Fields.Symbol,e.symbol),new t.Field(t.Fields.OrderQty,Number.parseFloat(e.quantity)),new t.Field(t.Fields.Price,Number.parseFloat(e.price)),new t.Field(t.Fields.OrdType,e.ordType),new t.Field(t.Fields.HandlInst,e.handlInst),new t.Field(t.Fields.TimeInForce,e.timeInForce),new t.Field(t.Fields.TransactTime,this.parser?.getTimestamp()));if(!this.parser?.connected)return{content:[{type:"text",text:"Error: Not connected. Ignoring message."}],isError:!0};this.parser?.send(a);let n=await o;return this.verifiedOrders.delete(e.clOrdID),{content:[{type:"text",text:n.messageType===t.Messages.Reject?`Reject message for order ${e.clOrdID}: ${JSON.stringify(n.toFIXJSON())}`:`Execution Report for order ${e.clOrdID}: ${JSON.stringify(n.toFIXJSON())}`}]}}catch(r){return{content:[{type:"text",text:`Error: ${r instanceof Error?r.message:"Failed to execute order"}`}],isError:!0}}}),this.server.tool("marketDataRequest","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.",{mdUpdateType:s.z.enum(["0","1"]).describe("Market data update type (0=FullRefresh, 1=IncrementalRefresh)"),symbol:s.z.string().describe("Trading symbol"),mdReqID:s.z.string().describe("Market data request ID"),subscriptionRequestType:s.z.enum(["0","1","2"]).describe("Subscription request type (0=Snapshot + Updates, 1=Snapshot, 2=Unsubscribe)"),mdEntryType:s.z.string().describe("Market data entry type (0=Bid, 1=Offer, 2=Trade, etc.)")},async e=>{try{let r=new Promise(n=>{this.pendingRequests.set(e.mdReqID,n)}),o=this.parser?.createMessage(new t.Field(t.Fields.MsgType,t.Messages.MarketDataRequest),new t.Field(t.Fields.SenderCompID,this.parser?.sender),new t.Field(t.Fields.MsgSeqNum,this.parser?.getNextTargetMsgSeqNum()),new t.Field(t.Fields.TargetCompID,this.parser?.target),new t.Field(t.Fields.SendingTime,this.parser?.getTimestamp()),new t.Field(t.Fields.MarketDepth,0),new t.Field(t.Fields.MDUpdateType,e.mdUpdateType),new t.Field(t.Fields.NoRelatedSym,1),new t.Field(t.Fields.Symbol,e.symbol),new t.Field(t.Fields.MDReqID,e.mdReqID),new t.Field(t.Fields.SubscriptionRequestType,e.subscriptionRequestType),new t.Field(t.Fields.NoMDEntryTypes,1),new t.Field(t.Fields.MDEntryType,e.mdEntryType));if(!this.parser?.connected)return{content:[{type:"text",text:"Error: Not connected. Ignoring message."}],isError:!0};this.parser?.send(o);let a=await r;return{content:[{type:"text",text:`Market data for ${e.symbol}: ${JSON.stringify(a.toFIXJSON())}`}]}}catch(r){return{content:[{type:"text",text:`Error: ${r instanceof Error?r.message:"Failed to request market data"}`}],isError:!0}}}),this.server.prompt("parse","Parses a FIX message and describes it in plain language",{fixString:s.z.string().describe("FIX message string to parse")},async e=>({messages:[{role:"user",content:{type:"text",text:`Please parse and explain this FIX message: ${e.fixString}`}}]})),this.server.prompt("parseToJSON","Parses a FIX message into JSON",{fixString:s.z.string().describe("FIX message string to parse")},async e=>({messages:[{role:"user",content:{type:"text",text:`Please parse the FIX message to JSON: ${e.fixString}`}}]})),this.server.prompt("verifyOrder","Verifies all parameters for a New Order Single. This is the first step - verification only, no order is sent.",{clOrdID:s.z.string().describe("Client Order ID"),handlInst:s.z.enum(["1","2","3"]).describe("Handling instruction (1=Manual, 2=Automated, 3=AutomatedNoIntervention)"),quantity:s.z.string().describe("Order quantity"),price:s.z.string().describe("Order price"),ordType:s.z.string().describe("Order type (1=Market, 2=Limit, 3=Stop)"),side:s.z.string().describe("Order side (1=Buy, 2=Sell, etc.)"),symbol:s.z.string().describe("Trading symbol"),timeInForce:s.z.string().describe("Time in force (0=Day, 1=Good Till Cancel, etc.)")},async e=>({messages:[{role:"user",content:{type:"text",text:["You are an AI assistant that helps users verify FIX New Order Single parameters.","This is STEP 1 of 2 - VERIFICATION ONLY. No order will be sent at this stage.","","You must verify that all required fields are provided and valid:","- 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)","","Current parameters to verify:",`- ClOrdID: ${e.clOrdID}`,`- HandlInst: ${e.handlInst}`,`- Quantity: ${e.quantity}`,`- Price: ${e.price}`,`- OrdType: ${e.ordType}`,`- Side: ${e.side}`,`- Symbol: ${e.symbol}`,`- TimeInForce: ${e.timeInForce}`,"","If all parameters are valid, respond with:","`VERIFICATION: All parameters valid. Ready to proceed.`","","Otherwise, list the missing or invalid ones.","","IMPORTANT: This is only verification. To actually send the order, the user must call the executeOrder tool with the same parameters."].join(`
|
|
16
|
+
`)}}]})),this.server.prompt("executeOrder","Executes a New Order Single after verification. This is the second step - only call after successful verification.",{clOrdID:s.z.string().describe("Client Order ID"),handlInst:s.z.enum(["1","2","3"]).describe("Handling instruction (1=Manual, 2=Automated, 3=AutomatedNoIntervention)"),quantity:s.z.string().describe("Order quantity"),price:s.z.string().describe("Order price"),ordType:s.z.string().describe("Order type (1=Market, 2=Limit, 3=Stop)"),side:s.z.string().describe("Order side (1=Buy, 2=Sell, etc.)"),symbol:s.z.string().describe("Trading symbol"),timeInForce:s.z.string().describe("Time in force (0=Day, 1=Good Till Cancel, etc.)")},async e=>({messages:[{role:"user",content:{type:"text",text:["You are an AI assistant that helps users execute FIX New Order Single messages.","This is STEP 2 of 2 - EXECUTION. This will send the order to the market.","","IMPORTANT: This tool should only be called after successful verification of all parameters.","","Parameters to execute:",`- ClOrdID: ${e.clOrdID}`,`- HandlInst: ${e.handlInst}`,`- Quantity: ${e.quantity}`,`- Price: ${e.price}`,`- OrdType: ${e.ordType}`,`- Side: ${e.side}`,`- Symbol: ${e.symbol}`,`- TimeInForce: ${e.timeInForce}`,"","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(`
|
|
17
|
+
`)}}]})),this.server.prompt("marketDataRequest","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.",{mdUpdateType:s.z.enum(["0","1"]).describe("Market data update type (0=FullRefresh, 1=IncrementalRefresh)"),symbol:s.z.string().describe("Trading symbol"),mdReqID:s.z.string().describe("Market data request ID"),subscriptionRequestType:s.z.enum(["0","1","2"]).describe("Subscription request type (0=Snapshot + Updates, 1=Snapshot, 2=Unsubscribe)"),mdEntryType:s.z.string().describe("Market data entry type (0=Bid, 1=Offer, 2=Trade, etc.)")},async e=>({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.mdUpdateType}`,`- Symbol: ${e.symbol}`,`- MDReqID: ${e.mdReqID}`,`- SubscriptionRequestType: ${e.subscriptionRequestType}`,`- MDEntryType: ${e.mdEntryType}`].join(`
|
|
18
|
+
`)}}]})),this.server.resource("greeting-resource","https://example.com/greetings/default",{mimeType:"text/plain"},async()=>({contents:[{uri:"https://example.com/greetings/default",text:"Hello, world!"}]})),this.server.resource("greeting",new u.ResourceTemplate("greeting://{name}",{list:void 0}),async(e,{name:r})=>({contents:[{uri:e.href,text:`Hello, ${r}!`}]})),this.server.resource("echo",new u.ResourceTemplate("echo://{message}",{list:void 0}),async(e,{message:r})=>({contents:[{uri:e.href,text:`Resource echo: ${r}`}]})),this.server.resource("stockGraph",new u.ResourceTemplate("stock://{symbol}",{list:void 0}),async(e,r)=>{let o=r.symbol,a=[{time:"09:30",price:150},{time:"10:30",price:152.5},{time:"11:30",price:151.75},{time:"12:30",price:153.25},{time:"13:30",price:154},{time:"14:30",price:153.5},{time:"15:30",price:155},{time:"16:00",price:154.75}],n=600,c=300,d=40,g=(n-2*d)/(a.length-1),h=Math.min(...a.map(l=>l.price)),f=Math.max(...a.map(l=>l.price)),I=(c-2*d)/(f-h),x=a.map((l,p)=>{let m=d+p*g,y=c-d-(l.price-h)*I;return`${m},${y}`}).join(" L "),S=`<?xml version="1.0" encoding="UTF-8"?>
|
|
19
|
+
<svg width="${n}" height="${c}" xmlns="http://www.w3.org/2000/svg">
|
|
20
|
+
<!-- Background -->
|
|
21
|
+
<rect width="100%" height="100%" fill="#f8f9fa"/>
|
|
22
|
+
|
|
23
|
+
<!-- Grid lines -->
|
|
24
|
+
<g stroke="#e9ecef" stroke-width="1">
|
|
25
|
+
${Array.from({length:5},(l,p)=>{let m=d+(c-2*d)*p/4;return`<line x1="${d}" y1="${m}" x2="${n-d}" y2="${m}"/>`}).join(`
|
|
26
|
+
`)}
|
|
27
|
+
</g>
|
|
28
|
+
|
|
29
|
+
<!-- Price line -->
|
|
30
|
+
<path d="M ${x}"
|
|
31
|
+
fill="none"
|
|
32
|
+
stroke="#007bff"
|
|
33
|
+
stroke-width="2"/>
|
|
34
|
+
|
|
35
|
+
<!-- Data points -->
|
|
36
|
+
${a.map((l,p)=>{let m=d+p*g,y=c-d-(l.price-h)*I;return`<circle cx="${m}" cy="${y}" r="3" fill="#007bff"/>`}).join(`
|
|
37
|
+
`)}
|
|
38
|
+
|
|
39
|
+
<!-- Labels -->
|
|
40
|
+
<g font-family="Arial" font-size="12" fill="#495057">
|
|
41
|
+
${a.map((l,p)=>`<text x="${d+p*g}" y="${c-d+20}" text-anchor="middle">${l.time}</text>`).join(`
|
|
42
|
+
`)}
|
|
43
|
+
${Array.from({length:5},(l,p)=>{let m=d+(c-2*d)*p/4,y=f-(f-h)*p/4;return`<text x="${d-5}" y="${m+4}" text-anchor="end">$${y.toFixed(2)}</text>`}).join(`
|
|
44
|
+
`)}
|
|
45
|
+
</g>
|
|
46
|
+
|
|
47
|
+
<!-- Title -->
|
|
48
|
+
<text x="${n/2}" y="${d/2}"
|
|
49
|
+
font-family="Arial" font-size="16" font-weight="bold"
|
|
50
|
+
text-anchor="middle" fill="#212529">
|
|
51
|
+
${o} - 1 Day Price Chart
|
|
52
|
+
</text>
|
|
53
|
+
</svg>`;return{contents:[{uri:e.href,text:S}]}}),process.on("SIGINT",async()=>{await this.server.close(),process.exit(0)}))}};var O=async()=>{await i.LicenseManager.setLicenseKey(process.env.FIXPARSER_LICENSE_KEY);let e=process.env.FIXPARSER_SENDER||"SENDER",r=process.env.FIXPARSER_TARGET||"TARGET",o=new i.FIXParser({logging:!1,plugins:[new b({port:3099,onReady:()=>{}})]}),a=()=>{let c=o.createMessage(new i.Field(i.Fields.MsgType,i.Messages.Logon),new i.Field(i.Fields.MsgSeqNum,o.getNextTargetMsgSeqNum()),new i.Field(i.Fields.SenderCompID,e),new i.Field(i.Fields.SendingTime,o.getTimestamp()),new i.Field(i.Fields.TargetCompID,r),new i.Field(i.Fields.ResetSeqNumFlag,i.ResetSeqNumFlag.Yes),new i.Field(i.Fields.EncryptMethod,i.EncryptMethod.None),new i.Field(i.Fields.HeartBtInt,10));o.send(c)},n={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:e,target:r,fixVersion:process.env.FIXPARSER_TARGET||"FIX.4.4",onOpen:()=>{a()},onMessage:c=>{},onClose:()=>{setTimeout(()=>{o.connect(n)},1e3)}};o.connect(n)};O().catch(e=>console.error("Error initializing server:",e));
|
|
18
54
|
//# sourceMappingURL=example_mcp_local.js.map
|