promptlike-mcp 0.4.2 → 0.4.3

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/CHANGELOG.md CHANGED
@@ -1,5 +1,29 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.4.3 — 2026-10-12
4
+
5
+ - **Fix:** a network problem while the session is being refreshed (no DNS,
6
+ connection refused, a dropped connection) no longer reports "Session expired.
7
+ Run `ple login`". The tool error now says the server could not be reached:
8
+ check the connection and try the tool again. The saved login is kept. A
9
+ temporary server problem during the refresh (busy, rate limited, 5xx) says to
10
+ try the tool again in a moment and keeps the login; only if it keeps
11
+ happening does it suggest `ple login` in a terminal. Only a definite rejection
12
+ from the server (the refresh token expired, was revoked or was already used)
13
+ still asks for `ple login` right away. Nothing is retried automatically.
14
+ - **Fix:** tool calls no longer sit on a stuck server for about five minutes
15
+ (Node's built-in limit, which ended in a bare "fetch failed"). Reads
16
+ (`list_prompts`, `search_prompts`, `get_prompt`, `suggest_prompts`, ...) give
17
+ up after 15 s, writes (`save_prompt`, `update_prompt`, tags) after 30 s, with
18
+ a plain "No response from <url>" message. After a write times out the message
19
+ says the server may still have finished, so the agent checks before retrying.
20
+ - **Fix:** when the session refresh itself gets no answer within 30 s, the
21
+ message no longer says "the server may still have completed the request;
22
+ check before retrying" (that warning is for the agent's own writes and was
23
+ misleading on read tools). It now says the refresh did not finish: try the
24
+ tool again, and if it then reports an expired session, run `ple login` in a
25
+ terminal.
26
+
3
27
  ## 0.4.2 — 2026-10-12
4
28
 
5
29
  - **Security:** `@modelcontextprotocol/sdk` is now `^1.31.0` (was `^1.30.1`).
@@ -9,10 +9,14 @@
9
9
  * - X-Client-Version header'ı `mcp/<sürüm>` gönderir.
10
10
  *
11
11
  * Sorumluluklar: bearer token ekleme, proaktif + reaktif (401→tek retry)
12
- * refresh, 429/hata gövdelerini temiz mesajlara map'leme.
12
+ * refresh, 429/hata gövdelerini temiz mesajlara map'leme, her isteği zaman
13
+ * aşımıyla sınırlama (O5 / PLE-03: asılı sunucu araç çağrısını sonsuza dek
14
+ * bekletmesin), yenilemede yalnız kesin reddi "oturum bitti" sayma (O11: ağ
15
+ * hatası ya da geçici sunucu hatası kayıtlı girişi korur).
13
16
  */
14
17
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.ApiError = exports.NOT_LOGGED_IN = void 0;
18
+ exports.ApiError = exports.NetworkError = exports.DEFINITIVE_REFRESH_CODES = exports.REFRESH_UNAVAILABLE_LAST_RESORT = exports.REFRESH_NETWORK_ADVICE = exports.REFRESH_TIMEOUT_ADVICE = exports.RequestTimeoutError = exports.USE_EVENT_TIMEOUT_MS = exports.WRITE_TIMEOUT_MS = exports.READ_TIMEOUT_MS = exports.NOT_LOGGED_IN = void 0;
19
+ exports.refreshUnavailableMessage = refreshUnavailableMessage;
16
20
  exports.ensureAuthed = ensureAuthed;
17
21
  exports.listPromptsPage = listPromptsPage;
18
22
  exports.listPrompts = listPrompts;
@@ -29,6 +33,94 @@ const constants_1 = require("./constants");
29
33
  const config_1 = require("./config");
30
34
  exports.NOT_LOGGED_IN = 'Not logged in. Run `ple login` in a terminal first (install: npm i -g promptlike).';
31
35
  const SESSION_EXPIRED = 'Session expired. Run `ple login` in a terminal to sign in again.';
36
+ /**
37
+ * İstek zaman aşımları (O5 / PLE-03; CLI ile aynı değerler). Süre gövde
38
+ * okumasını da kapsar. Otomatik tekrar deneme YOK: zaman aşımına uğrayan bir
39
+ * yazma sunucuda tamamlanmış olabilir; ileti ajana "önce kontrol et" der.
40
+ */
41
+ /** GET istekleri (liste, detay, öneri): hafif okumalar. */
42
+ exports.READ_TIMEOUT_MS = 15000;
43
+ /** GET dışı istekler (save_prompt, update_prompt, etiket, yenileme). */
44
+ exports.WRITE_TIMEOUT_MS = 30000;
45
+ /** Kullanım kaydı (fire-and-forget). */
46
+ exports.USE_EVENT_TIMEOUT_MS = 5000;
47
+ /** Zaman aşımı hatası — `refreshSession` bunu "oturum bitti"ye çevirmesin diye ayrı sınıf. */
48
+ class RequestTimeoutError extends Error {
49
+ constructor(timeoutMs, method, advice) {
50
+ const defaultAdvice = method === 'GET'
51
+ ? 'Check the connection and try again.'
52
+ : 'The server may still have completed the request; check before retrying.';
53
+ super(`No response from ${constants_1.API_BASE_URL} within ${Math.round(timeoutMs / 1000)}s. ${advice ?? defaultAdvice}`);
54
+ this.timeoutMs = timeoutMs;
55
+ this.name = 'RequestTimeoutError';
56
+ }
57
+ }
58
+ exports.RequestTimeoutError = RequestTimeoutError;
59
+ /**
60
+ * Oturum yenileme zaman aşımına uğradığında ajana söylenecek şey. Yenileme
61
+ * araç çağrısının kendisi değil, arka plandaki bir POST'tur; "yazma sunucuda
62
+ * tamamlanmış olabilir, önce kontrol et" uyarısı okuma araçlarında bile çıkıp
63
+ * yanıltırdı. Sunucu yenilemeyi tamamlamış ama yeni token yerelde saklanmamış
64
+ * olabilir; bu durumda bir sonraki çağrı "Session expired" der.
65
+ */
66
+ exports.REFRESH_TIMEOUT_ADVICE = 'Session refresh did not finish. Try the tool again; if it then reports an expired session, run `ple login` in a terminal.';
67
+ /**
68
+ * Yenileme isteği sunucuya hiç ulaşamadığında (DNS, bağlantı reddi, kopma; O11).
69
+ * Ağ hatası oturumun bittiğini göstermez: paylaşılan yerel oturum silinmez,
70
+ * ajan kullanıcıyı gereksiz yere `ple login`'e yönlendirmez.
71
+ */
72
+ exports.REFRESH_NETWORK_ADVICE = 'Could not refresh the session: check the connection and try the tool again. The saved login is kept.';
73
+ /**
74
+ * Sunucu yenilemeyi kesin reddetmedi ama tamamlayamadı (503 + Retry-After, 429,
75
+ * 5xx, tanınmayan yanıt; O11). Web `/api/auth/cli/refresh` sözleşmesi: geçici,
76
+ * oturum korunur. Otomatik tekrar YOK.
77
+ * Son çare cümlesi: web tanınmayan üst servis hatasını (kodsuz 401/403, yeni bir
78
+ * GoTrue kodu) da 503 geçici sayar; refresh token gerçekten iptal edilmişse ajan
79
+ * kullanıcıyı sonsuz "tekrar dene"de bırakmasın.
80
+ */
81
+ exports.REFRESH_UNAVAILABLE_LAST_RESORT = 'If this keeps happening, run `ple login` in a terminal.';
82
+ function refreshUnavailableMessage(detail) {
83
+ return `Could not refresh the session right now (${detail}). Try the tool again in a moment; the saved login is kept. ${exports.REFRESH_UNAVAILABLE_LAST_RESORT}`;
84
+ }
85
+ /**
86
+ * Sunucunun yenilemeyi KESİN reddettiğini gösteren yanıt kodları (O11). Web
87
+ * `src/app/api/auth/cli/refresh/_handlers/classify.ts` DEFINITIVE_CODES (GoTrue
88
+ * `error_code`) ile aynı liste + rotanın kendi `SESSION_EXPIRED` kodu; tutarlılık
89
+ * `api-client.refresh.test.ts` ile kilitli (CLI kopyasıyla da aynı).
90
+ */
91
+ exports.DEFINITIVE_REFRESH_CODES = new Set([
92
+ 'SESSION_EXPIRED',
93
+ 'refresh_token_not_found',
94
+ 'refresh_token_already_used',
95
+ 'session_expired',
96
+ 'session_not_found',
97
+ 'invalid_grant',
98
+ 'user_not_found',
99
+ 'user_banned',
100
+ 'validation_failed',
101
+ ]);
102
+ /** İstek sunucuya ulaşamadı (DNS, bağlantı reddi, kopma). Varsayılan ileti eskisiyle aynı. */
103
+ class NetworkError extends Error {
104
+ constructor(detail, advice = 'Check your connection.') {
105
+ super(`Cannot reach ${constants_1.API_BASE_URL}. ${advice} (${detail})`);
106
+ this.detail = detail;
107
+ this.name = 'NetworkError';
108
+ }
109
+ }
110
+ exports.NetworkError = NetworkError;
111
+ /**
112
+ * Hata süre aşımından mı geldi? Önce sinyalin kendisine bakılır: eski Node /
113
+ * undici sürümlerinde gövde okuması yarıda kesilince hata `TimeoutError` yerine
114
+ * `TypeError: terminated` gibi başka biçimde gelebilir; sinyal `aborted` ise
115
+ * sebep süre dolmasıdır, hatanın biçimi önemsizdir. Ad kontrolü yedektir
116
+ * (AbortSignal.timeout → `TimeoutError`, iptal → `AbortError`).
117
+ */
118
+ function isTimeout(err, signal) {
119
+ if (signal.aborted)
120
+ return true;
121
+ const name = err?.name;
122
+ return name === 'TimeoutError' || name === 'AbortError';
123
+ }
32
124
  /**
33
125
  * HTTP error with the status kept, so write tools can tell a plan limit
34
126
  * (403 + upgradeUrl / 429 LIMIT_EXCEEDED) from a real failure.
@@ -47,6 +139,18 @@ class ApiError extends Error {
47
139
  }
48
140
  }
49
141
  exports.ApiError = ApiError;
142
+ /**
143
+ * Yenileme yanıtı oturumun gerçekten bittiğini mi söylüyor? Web sözleşmesi:
144
+ * 401 SESSION_EXPIRED (kesin ret) ve 400 (refresh_token eksik: yerel oturum
145
+ * kaydı bozuk) kesindir; 503 / 429 / 5xx / ağ / zaman aşımı geçicidir.
146
+ */
147
+ function isDefinitiveRefreshRejection(err) {
148
+ if (!(err instanceof ApiError))
149
+ return false;
150
+ if (err.status === 401 || err.status === 400)
151
+ return true;
152
+ return err.code !== undefined && exports.DEFINITIVE_REFRESH_CODES.has(err.code);
153
+ }
50
154
  function buildUrl(path, query) {
51
155
  const u = new URL(constants_1.API_BASE_URL + path);
52
156
  if (query) {
@@ -99,13 +203,26 @@ async function refreshSession() {
99
203
  auth: false,
100
204
  });
101
205
  }
102
- catch {
103
- throw new Error(SESSION_EXPIRED);
206
+ catch (err) {
207
+ // Asılı sunucu "oturumun bitti, yeniden giriş yap" demek değildir.
208
+ if (err instanceof RequestTimeoutError) {
209
+ throw new RequestTimeoutError(err.timeoutMs, 'POST', exports.REFRESH_TIMEOUT_ADVICE);
210
+ }
211
+ // Yalnız sunucunun kesin reddi oturumu bitirir (O11).
212
+ if (isDefinitiveRefreshRejection(err))
213
+ throw new Error(SESSION_EXPIRED);
214
+ // Ağ hatası (DNS, bağlantı reddi): sunucuya ulaşılamadı, oturum hakkında bilgi yok.
215
+ if (err instanceof NetworkError)
216
+ throw new NetworkError(err.detail, exports.REFRESH_NETWORK_ADVICE);
217
+ // 503 / 429 / 5xx / tanınmayan yanıt: geçici; yerel oturum korunur.
218
+ throw new Error(refreshUnavailableMessage(err instanceof Error ? err.message : String(err)));
104
219
  }
105
220
  persist(data);
106
221
  }
107
222
  async function apiFetch(path, opts = {}) {
108
223
  const { method = 'GET', body, query, auth = true } = opts;
224
+ const timeoutMs = opts.timeoutMs ?? (method === 'GET' ? exports.READ_TIMEOUT_MS : exports.WRITE_TIMEOUT_MS);
225
+ const signal = AbortSignal.timeout(timeoutMs);
109
226
  const headers = {
110
227
  'Content-Type': 'application/json',
111
228
  'X-Client-Version': `mcp/${constants_1.MCP_VERSION}`,
@@ -119,10 +236,14 @@ async function apiFetch(path, opts = {}) {
119
236
  method,
120
237
  headers,
121
238
  body: body === undefined ? undefined : JSON.stringify(body),
239
+ // Süre başlıkla sınırlı değil: gövde okuması da aynı sinyalle kesilir.
240
+ signal,
122
241
  });
123
242
  }
124
243
  catch (err) {
125
- throw new Error(`Cannot reach ${constants_1.API_BASE_URL}. Check your connection. (${err instanceof Error ? err.message : String(err)})`);
244
+ if (isTimeout(err, signal))
245
+ throw new RequestTimeoutError(timeoutMs, method);
246
+ throw new NetworkError(err instanceof Error ? err.message : String(err));
126
247
  }
127
248
  if (res.status === 401 && auth) {
128
249
  if (opts._retried)
@@ -146,7 +267,15 @@ async function apiFetch(path, opts = {}) {
146
267
  if (!res.ok) {
147
268
  throw await toError(res);
148
269
  }
149
- return (await res.json());
270
+ try {
271
+ return (await res.json());
272
+ }
273
+ catch (err) {
274
+ // Başlıklar geldi, gövde yarıda kaldı ve süre doldu.
275
+ if (isTimeout(err, signal))
276
+ throw new RequestTimeoutError(timeoutMs, method);
277
+ throw err;
278
+ }
150
279
  }
151
280
  // ---------------------------------------------------------------------------
152
281
  // Public surface used by the tools / resolver
@@ -224,7 +353,11 @@ function sanitizeClientName(v) {
224
353
  * istemciyi ve `via`yı taşır (W1-1 olay defteri). Hata YUTULUR.
225
354
  */
226
355
  function recordPromptUse(promptId, opts = { surface: 'mcp_tool' }) {
227
- apiFetch(`/api/prompts/${promptId}/use`, { method: 'POST', body: buildUseEventBody(opts) }).catch(() => {
356
+ apiFetch(`/api/prompts/${promptId}/use`, {
357
+ method: 'POST',
358
+ body: buildUseEventBody(opts),
359
+ timeoutMs: exports.USE_EVENT_TIMEOUT_MS,
360
+ }).catch(() => {
228
361
  /* sessiz — telemetri */
229
362
  });
230
363
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "promptlike-mcp",
3
- "version": "0.4.2",
3
+ "version": "0.4.3",
4
4
  "mcpName": "io.github.zeynepaslierhan/promptlike-mcp",
5
5
  "description": "MCP server for PromptLikeEngineer - your prompt library as MCP tools, slash-command prompts and @-resources: list, search, get, fill {{variables}}, suggest, and save new prompts/versions (add-only).",
6
6
  "bin": {