cf-memory-mcp 3.25.0 → 3.26.0
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/bin/cf-memory-mcp.js +70 -2
- package/package.json +1 -1
package/bin/cf-memory-mcp.js
CHANGED
|
@@ -3548,7 +3548,31 @@ class CFMemoryMCP {
|
|
|
3548
3548
|
}
|
|
3549
3549
|
}
|
|
3550
3550
|
|
|
3551
|
+
/**
|
|
3552
|
+
* Retry-aware wrapper. Tries once, then once more after a short
|
|
3553
|
+
* backoff if the first attempt got a network error, 5xx, or timeout.
|
|
3554
|
+
* Opt out with CF_MEMORY_NO_RETRY=1.
|
|
3555
|
+
*/
|
|
3551
3556
|
async makeRequest(message, extraHeaders = null) {
|
|
3557
|
+
const noRetry = process.env.CF_MEMORY_NO_RETRY === '1' || process.env.CF_MEMORY_NO_RETRY === 'true';
|
|
3558
|
+
const first = await this.makeRequestOnce(message, extraHeaders);
|
|
3559
|
+
if (noRetry) return first;
|
|
3560
|
+
// Retry only on transient failures: connection error, timeout, or 5xx.
|
|
3561
|
+
// We never retry application-level errors (4xx / -32602 / -32603 from
|
|
3562
|
+
// server logic) since those are likely to repeat.
|
|
3563
|
+
const isTransient = first?.error && (
|
|
3564
|
+
/Network error|Request timeout/.test(first.error.message || '') ||
|
|
3565
|
+
/HTTP 5\d\d/.test(first.error.message || '')
|
|
3566
|
+
);
|
|
3567
|
+
if (!isTransient) return first;
|
|
3568
|
+
// Brief backoff to let an edge blip clear.
|
|
3569
|
+
await new Promise(r => setTimeout(r, 250));
|
|
3570
|
+
_mcpTrace('RETRY', `id=${message.id} after transient error: ${first.error.message}`);
|
|
3571
|
+
const second = await this.makeRequestOnce(message, extraHeaders);
|
|
3572
|
+
return second;
|
|
3573
|
+
}
|
|
3574
|
+
|
|
3575
|
+
async makeRequestOnce(message, extraHeaders = null) {
|
|
3552
3576
|
return new Promise((resolve) => {
|
|
3553
3577
|
const serverUrl = this.useStreamableHttp ? this.streamableHttpUrl : this.legacyServerUrl;
|
|
3554
3578
|
const url = new URL(serverUrl);
|
|
@@ -3588,6 +3612,18 @@ class CFMemoryMCP {
|
|
|
3588
3612
|
res.on('end', () => {
|
|
3589
3613
|
try {
|
|
3590
3614
|
const response = JSON.parse(body);
|
|
3615
|
+
// Promote 5xx HTTP status to a transient error
|
|
3616
|
+
// envelope so the retry path can catch it. The
|
|
3617
|
+
// server may have returned a valid JSON-RPC error
|
|
3618
|
+
// wrapped in 200, OR a body-less 5xx with no
|
|
3619
|
+
// error field — handle both.
|
|
3620
|
+
if (res.statusCode && res.statusCode >= 500 && !response.error) {
|
|
3621
|
+
response.error = {
|
|
3622
|
+
code: -32603,
|
|
3623
|
+
message: `HTTP ${res.statusCode}`,
|
|
3624
|
+
data: `Server returned ${res.statusCode}`,
|
|
3625
|
+
};
|
|
3626
|
+
}
|
|
3591
3627
|
resolve(response);
|
|
3592
3628
|
} catch (error) {
|
|
3593
3629
|
// Include HTTP status + body snippet so callers can
|
|
@@ -3596,12 +3632,16 @@ class CFMemoryMCP {
|
|
|
3596
3632
|
// "Invalid JSON" alone hides whether the worker is
|
|
3597
3633
|
// even reachable.
|
|
3598
3634
|
const bodyPreview = body.slice(0, 200).replace(/\s+/g, ' ');
|
|
3635
|
+
// 5xx with non-JSON body is transient too (Cloudflare
|
|
3636
|
+
// edge HTML pages). Tag the error message so retry catches it.
|
|
3637
|
+
const transientTag = (res.statusCode && res.statusCode >= 500)
|
|
3638
|
+
? `HTTP ${res.statusCode}` : `HTTP ${res.statusCode || '?'}`;
|
|
3599
3639
|
resolve({
|
|
3600
3640
|
jsonrpc: '2.0',
|
|
3601
3641
|
id: message.id || null,
|
|
3602
3642
|
error: {
|
|
3603
3643
|
code: -32603,
|
|
3604
|
-
message: `Invalid JSON response from server (
|
|
3644
|
+
message: `Invalid JSON response from server (${transientTag})`,
|
|
3605
3645
|
data: `${error.message}; body[0..200]=${bodyPreview}`
|
|
3606
3646
|
}
|
|
3607
3647
|
});
|
|
@@ -3773,7 +3813,7 @@ For more information, visit: https://github.com/johnlam90/cf-memory-mcp
|
|
|
3773
3813
|
}
|
|
3774
3814
|
|
|
3775
3815
|
// Parse positional + flag args for CLI subcommands. Returns
|
|
3776
|
-
// { positional: string[], flags: { json
|
|
3816
|
+
// { positional: string[], flags: { json, limit, md_path } }.
|
|
3777
3817
|
function parseCliArgs(rest) {
|
|
3778
3818
|
const positional = [];
|
|
3779
3819
|
const flags = { json: false };
|
|
@@ -3786,6 +3826,11 @@ function parseCliArgs(rest) {
|
|
|
3786
3826
|
} else if (a.startsWith('--limit=')) {
|
|
3787
3827
|
const n = parseInt(a.slice('--limit='.length), 10);
|
|
3788
3828
|
if (Number.isFinite(n) && n > 0) flags.limit = Math.min(n, 50);
|
|
3829
|
+
} else if (a === '--md') {
|
|
3830
|
+
// Next arg is path; supports `--md=path` too.
|
|
3831
|
+
flags.md_path = rest[++i];
|
|
3832
|
+
} else if (a.startsWith('--md=')) {
|
|
3833
|
+
flags.md_path = a.slice('--md='.length);
|
|
3789
3834
|
} else positional.push(a);
|
|
3790
3835
|
}
|
|
3791
3836
|
return { positional, flags };
|
|
@@ -3830,6 +3875,27 @@ async function runResumeCli() {
|
|
|
3830
3875
|
// 0 — handoff found and printed
|
|
3831
3876
|
// 3 — no handoff found (lets scripts branch: `if ! cf-memory-mcp resume; then ...`)
|
|
3832
3877
|
const found = !!payload.resume_handoff?.handoff;
|
|
3878
|
+
|
|
3879
|
+
// Warm the disk cache. The CLI bypasses the stdio dispatch hook
|
|
3880
|
+
// that normally writes the cache on a successful resume, so do
|
|
3881
|
+
// it here too. Means `cf-memory-mcp resume` ALSO populates the
|
|
3882
|
+
// offline-fallback cache, not just MCP-stdio usage.
|
|
3883
|
+
if (found) server.saveResumeToDisk(response);
|
|
3884
|
+
|
|
3885
|
+
// --md <path>: write the rendered markdown to a file instead of
|
|
3886
|
+
// (or in addition to) stdout. Useful for piping to a markdown
|
|
3887
|
+
// viewer or saving to the project.
|
|
3888
|
+
if (found && flags.md_path && payload.resume_prompt) {
|
|
3889
|
+
try {
|
|
3890
|
+
fs.writeFileSync(flags.md_path, payload.resume_prompt + '\n');
|
|
3891
|
+
process.stdout.write(`Wrote ${payload.resume_prompt.length} chars to ${flags.md_path}\n`);
|
|
3892
|
+
process.exit(0);
|
|
3893
|
+
} catch (err) {
|
|
3894
|
+
console.error(`Failed to write ${flags.md_path}: ${err.message}`);
|
|
3895
|
+
process.exit(1);
|
|
3896
|
+
}
|
|
3897
|
+
}
|
|
3898
|
+
|
|
3833
3899
|
if (flags.json) {
|
|
3834
3900
|
process.stdout.write(JSON.stringify(payload, null, 2) + '\n');
|
|
3835
3901
|
process.exit(found ? 0 : 3);
|
|
@@ -3889,6 +3955,8 @@ async function runListCli() {
|
|
|
3889
3955
|
const payload = JSON.parse(text || '{}');
|
|
3890
3956
|
const allList = Array.isArray(payload.recent_handoffs) ? payload.recent_handoffs : [];
|
|
3891
3957
|
const list = flags.limit ? allList.slice(0, flags.limit) : allList;
|
|
3958
|
+
// Warm the disk cache when there's a primary handoff in the payload.
|
|
3959
|
+
if (payload.resume_handoff) server.saveResumeToDisk(response);
|
|
3892
3960
|
|
|
3893
3961
|
if (flags.json) {
|
|
3894
3962
|
process.stdout.write(JSON.stringify({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cf-memory-mcp",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.26.0",
|
|
4
4
|
"description": "Cloudflare-hosted MCP server for code indexing, retrieval, and assistant memory with a direct remote MCP endpoint and local stdio bridge.",
|
|
5
5
|
"main": "bin/cf-memory-mcp.js",
|
|
6
6
|
"bin": {
|