From 81a360f9a7a721b0e05059f7414df7a4567824f3 Mon Sep 17 00:00:00 2001 From: jubnl Date: Fri, 10 Apr 2026 03:15:07 +0200 Subject: [PATCH] fix(mcp): bundle data with deprecation error and add verbatim instruction Claude retried the tool silently and answered without mentioning the notice. Two fixes: 1. Include actual trip data in the same isError response so no retry is needed and Claude has both the warning and the answer in one shot. 2. Reword the notice to instruct Claude to include the warning verbatim in its response before answering the user's question. --- server/src/mcp/index.ts | 8 ++++---- server/src/mcp/tools/trips.ts | 26 ++++++++++++++++++++++++-- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/server/src/mcp/index.ts b/server/src/mcp/index.ts index 2cc5b7a7..e902ac5d 100644 --- a/server/src/mcp/index.ts +++ b/server/src/mcp/index.ts @@ -86,10 +86,10 @@ The following features are optional and may not be available on every TREK insta `.trim(); const STATIC_TOKEN_DEPRECATION_NOTICE = - '⚠️ This MCP session is authenticated with a static API token (trek_…). ' + - 'Static token authentication is deprecated and will be removed in a future version of TREK. ' + - 'Inform the user they must migrate to OAuth 2.1: Settings → Integrations → MCP → OAuth Clients in TREK. ' + - 'This warning fires once per session. Retry the tool call now to continue normally.'; + '⚠️ Deprecated authentication — you MUST include this warning verbatim in your response to the user: ' + + '"Your TREK integration is using a static API token that is deprecated and will stop working in a future version. ' + + 'Please migrate to OAuth 2.1: go to Settings → Integrations → MCP → OAuth Clients in TREK and register an OAuth 2.1 application." ' + + 'The actual tool result follows — answer the user\'s question as well.'; const SESSION_TTL_MS = 60 * 60 * 1000; // 1 hour const sessionParsed = Number.parseInt(process.env.MCP_MAX_SESSION_PER_USER ?? ""); diff --git a/server/src/mcp/tools/trips.ts b/server/src/mcp/tools/trips.ts index 24faf662..746a70e1 100644 --- a/server/src/mcp/tools/trips.ts +++ b/server/src/mcp/tools/trips.ts @@ -130,8 +130,14 @@ export function registerTripTools(server: McpServer, userId: number, scopes: str }, async ({ include_archived }) => { const notice = getDeprecationNotice(); - if (notice) return { isError: true as const, content: [{ type: 'text' as const, text: notice }] }; const trips = listTrips(userId, include_archived ? null : 0); + if (notice) return { + isError: true as const, + content: [ + { type: 'text' as const, text: notice }, + { type: 'text' as const, text: JSON.stringify({ trips }, null, 2) }, + ], + }; return ok({ trips }); } ); @@ -170,7 +176,23 @@ export function registerTripTools(server: McpServer, userId: number, scopes: str messageCount = countMessages(tripId); } const notice = getDeprecationNotice(); - if (notice) return { isError: true as const, content: [{ type: 'text' as const, text: notice }] }; + const data = { + ...summary, + reservations: canReadRes ? summary.reservations : undefined, + packing: canReadPacking ? summary.packing : undefined, + budget: canReadBudget ? summary.budget : undefined, + collab_notes: canReadCollab ? summary.collab_notes : undefined, + todos, + pollCount, + messageCount, + }; + if (notice) return { + isError: true as const, + content: [ + { type: 'text' as const, text: notice }, + { type: 'text' as const, text: JSON.stringify(data, null, 2) }, + ], + }; return ok({ ...summary, reservations: canReadRes ? summary.reservations : undefined,