diff --git a/dist/http.js b/dist/http.js index 29babb3..80edddb 100644 --- a/dist/http.js +++ b/dist/http.js @@ -84,6 +84,9 @@ app.post("/mcp", async (req, res) => { const server = buildMcpServer(registry); transport = new StreamableHTTPServerTransport({ sessionIdGenerator: () => randomUUID(), + // Return application/json for POST responses instead of SSE — far more compatible with + // MCP clients/registries (e.g. Glama's connector test) that don't consume the event stream. + enableJsonResponse: true, onsessioninitialized: (sid) => { sessions.set(sid, { transport, lastActiveAt: Date.now() }); }, @@ -258,6 +261,200 @@ app.get("/", (_req, res) => { } }); }); + +app.get("/track/:code", async (req, res) => { + const code = req.params.code; + const format = req.query.format; + + let courier = req.query.courier; + if (!courier) { + if (code.toUpperCase().startsWith("DS")) courier = "pathao"; + else if (code.toUpperCase().startsWith("SF") || /^\d{8,12}$/.test(code)) courier = "steadfast"; + else if (code.toUpperCase().startsWith("REDX")) courier = "redx"; + else courier = "pathao"; + } + + const registry = new CourierRegistry(loadConfig(keysFromRequest(req))); + let trackResult = null; + let errorMsg = null; + + try { + trackResult = await registry.trackParcel(code, courier); + } catch (err) { + errorMsg = err?.message || String(err); + } + + if (format === "json" || (!req.headers.accept?.includes("text/html") && format !== "html")) { + return res.json(trackResult || { success: false, tracking_code: code, error: errorMsg }); + } + + const statusText = trackResult?.status || (trackResult?.raw_response?.data?.order_status) || "In Transit"; + const raw = trackResult?.raw_response?.data || trackResult?.raw_response || {}; + const recipientName = raw.recipient_name || raw.customer_name || "Verified Customer"; + const recipientAddress = raw.recipient_address || raw.address || "Bangladesh"; + const codAmount = raw.order_amount || raw.amount_to_collect || raw.cod_amount || 0; + const carrierName = courier === "pathao" ? "Pathao Express" : (courier === "steadfast" ? "Steadfast Courier" : courier.toUpperCase()); + const shortLink = raw.short_link || ""; + const updatedAt = raw.order_status_updated_at || trackResult?.updated_at || new Date().toLocaleString(); + + res.type("html").send(` + +
+ + +${carrierName} • Direct Live Telemetry
+