@numeratica/mcp 0.1.0 → 0.1.1
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/package.json +1 -1
- package/src/bridge.js +17 -2
package/package.json
CHANGED
package/src/bridge.js
CHANGED
|
@@ -103,11 +103,26 @@ export async function forward(line, opts) {
|
|
|
103
103
|
|
|
104
104
|
if (!res.ok) {
|
|
105
105
|
if (isNotification) return null;
|
|
106
|
-
const detail = text ? `: ${text.slice(0, 500)}` : '';
|
|
106
|
+
const detail = text ? `: ${oneLine(text).slice(0, 500)}` : '';
|
|
107
107
|
return jsonRpcError(id, -32000, `Numeratica API error (HTTP ${res.status})${detail}`);
|
|
108
108
|
}
|
|
109
109
|
|
|
110
|
-
|
|
110
|
+
if (text === '') return null;
|
|
111
|
+
// MCP's stdio transport frames messages as single-line, newline-delimited JSON
|
|
112
|
+
// (a message MUST NOT contain embedded newlines). The hosted endpoint may
|
|
113
|
+
// pretty-print its JSON, so re-serialize compactly to guarantee one line.
|
|
114
|
+
try {
|
|
115
|
+
return JSON.stringify(JSON.parse(text));
|
|
116
|
+
} catch {
|
|
117
|
+
return oneLine(text);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// oneLine collapses any newlines/indentation into single spaces — a fallback for
|
|
122
|
+
// non-JSON or unparseable bodies so we never emit a multi-line stdout frame.
|
|
123
|
+
/** @param {string} s */
|
|
124
|
+
function oneLine(s) {
|
|
125
|
+
return s.replace(/\s*\r?\n\s*/g, ' ').trim();
|
|
111
126
|
}
|
|
112
127
|
|
|
113
128
|
/**
|