visus-mcp 0.6.0 → 0.6.2

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.
Files changed (147) hide show
  1. package/.claude/settings.local.json +42 -1
  2. package/.github/ISSUE_TEMPLATE/bug_report.md +47 -0
  3. package/.github/ISSUE_TEMPLATE/false_positive.md +43 -0
  4. package/.github/ISSUE_TEMPLATE/new_pattern.md +49 -0
  5. package/.github/ISSUE_TEMPLATE/security_report.md +31 -0
  6. package/.github/PULL_REQUEST_TEMPLATE.md +39 -0
  7. package/.mcpregistry_github_token +1 -0
  8. package/.mcpregistry_registry_token +1 -0
  9. package/CLAUDE.md +197 -0
  10. package/CONTRIBUTING.md +329 -0
  11. package/README.md +111 -45
  12. package/STATUS.md +167 -29
  13. package/SUBMISSION.md +66 -0
  14. package/TROUBLESHOOT-COGNITO-AUTH-20260324-2029.md +415 -0
  15. package/TROUBLESHOOT-COGNITO-JWT-20260324.md +592 -0
  16. package/dist/browser/playwright-renderer.d.ts.map +1 -1
  17. package/dist/browser/playwright-renderer.js +71 -51
  18. package/dist/browser/playwright-renderer.js.map +1 -1
  19. package/dist/index.d.ts.map +1 -1
  20. package/dist/index.js +49 -6
  21. package/dist/index.js.map +1 -1
  22. package/dist/sanitizer/elicit-runner.d.ts +48 -0
  23. package/dist/sanitizer/elicit-runner.d.ts.map +1 -0
  24. package/dist/sanitizer/elicit-runner.js +100 -0
  25. package/dist/sanitizer/elicit-runner.js.map +1 -0
  26. package/dist/sanitizer/framework-mapper.d.ts +2 -0
  27. package/dist/sanitizer/framework-mapper.d.ts.map +1 -1
  28. package/dist/sanitizer/framework-mapper.js +91 -45
  29. package/dist/sanitizer/framework-mapper.js.map +1 -1
  30. package/dist/sanitizer/hitl-gate.d.ts +69 -0
  31. package/dist/sanitizer/hitl-gate.d.ts.map +1 -0
  32. package/dist/sanitizer/hitl-gate.js +101 -0
  33. package/dist/sanitizer/hitl-gate.js.map +1 -0
  34. package/dist/sanitizer/threat-reporter.d.ts +1 -0
  35. package/dist/sanitizer/threat-reporter.d.ts.map +1 -1
  36. package/dist/sanitizer/threat-reporter.js +10 -7
  37. package/dist/sanitizer/threat-reporter.js.map +1 -1
  38. package/infrastructure/stack.ts +1 -0
  39. package/lambda-deploy/index.js +81512 -0
  40. package/lambda-deploy/index.js.map +7 -0
  41. package/lambda-package/browser/__mocks__/playwright-renderer.d.ts +25 -0
  42. package/lambda-package/browser/__mocks__/playwright-renderer.d.ts.map +1 -0
  43. package/lambda-package/browser/__mocks__/playwright-renderer.js +119 -0
  44. package/lambda-package/browser/__mocks__/playwright-renderer.js.map +1 -0
  45. package/lambda-package/browser/playwright-renderer.d.ts +40 -0
  46. package/lambda-package/browser/playwright-renderer.d.ts.map +1 -0
  47. package/lambda-package/browser/playwright-renderer.js +214 -0
  48. package/lambda-package/browser/playwright-renderer.js.map +1 -0
  49. package/lambda-package/browser/reader.d.ts +31 -0
  50. package/lambda-package/browser/reader.d.ts.map +1 -0
  51. package/lambda-package/browser/reader.js +98 -0
  52. package/lambda-package/browser/reader.js.map +1 -0
  53. package/lambda-package/index.d.ts +18 -0
  54. package/lambda-package/index.d.ts.map +1 -0
  55. package/lambda-package/index.js +238 -0
  56. package/lambda-package/index.js.map +1 -0
  57. package/lambda-package/lambda-handler.d.ts +28 -0
  58. package/lambda-package/lambda-handler.d.ts.map +1 -0
  59. package/lambda-package/lambda-handler.js +257 -0
  60. package/lambda-package/lambda-handler.js.map +1 -0
  61. package/lambda-package/package-lock.json +7435 -0
  62. package/lambda-package/package.json +74 -0
  63. package/lambda-package/runtime.d.ts +50 -0
  64. package/lambda-package/runtime.d.ts.map +1 -0
  65. package/lambda-package/runtime.js +86 -0
  66. package/lambda-package/runtime.js.map +1 -0
  67. package/lambda-package/sanitizer/elicit-runner.d.ts +48 -0
  68. package/lambda-package/sanitizer/elicit-runner.d.ts.map +1 -0
  69. package/lambda-package/sanitizer/elicit-runner.js +100 -0
  70. package/lambda-package/sanitizer/elicit-runner.js.map +1 -0
  71. package/lambda-package/sanitizer/framework-mapper.d.ts +24 -0
  72. package/lambda-package/sanitizer/framework-mapper.d.ts.map +1 -0
  73. package/lambda-package/sanitizer/framework-mapper.js +342 -0
  74. package/lambda-package/sanitizer/framework-mapper.js.map +1 -0
  75. package/lambda-package/sanitizer/hitl-gate.d.ts +69 -0
  76. package/lambda-package/sanitizer/hitl-gate.d.ts.map +1 -0
  77. package/lambda-package/sanitizer/hitl-gate.js +101 -0
  78. package/lambda-package/sanitizer/hitl-gate.js.map +1 -0
  79. package/lambda-package/sanitizer/index.d.ts +63 -0
  80. package/lambda-package/sanitizer/index.d.ts.map +1 -0
  81. package/lambda-package/sanitizer/index.js +105 -0
  82. package/lambda-package/sanitizer/index.js.map +1 -0
  83. package/lambda-package/sanitizer/injection-detector.d.ts +34 -0
  84. package/lambda-package/sanitizer/injection-detector.d.ts.map +1 -0
  85. package/lambda-package/sanitizer/injection-detector.js +89 -0
  86. package/lambda-package/sanitizer/injection-detector.js.map +1 -0
  87. package/lambda-package/sanitizer/patterns.d.ts +30 -0
  88. package/lambda-package/sanitizer/patterns.d.ts.map +1 -0
  89. package/lambda-package/sanitizer/patterns.js +372 -0
  90. package/lambda-package/sanitizer/patterns.js.map +1 -0
  91. package/lambda-package/sanitizer/pii-allowlist.d.ts +49 -0
  92. package/lambda-package/sanitizer/pii-allowlist.d.ts.map +1 -0
  93. package/lambda-package/sanitizer/pii-allowlist.js +231 -0
  94. package/lambda-package/sanitizer/pii-allowlist.js.map +1 -0
  95. package/lambda-package/sanitizer/pii-redactor.d.ts +41 -0
  96. package/lambda-package/sanitizer/pii-redactor.d.ts.map +1 -0
  97. package/lambda-package/sanitizer/pii-redactor.js +213 -0
  98. package/lambda-package/sanitizer/pii-redactor.js.map +1 -0
  99. package/lambda-package/sanitizer/severity-classifier.d.ts +33 -0
  100. package/lambda-package/sanitizer/severity-classifier.d.ts.map +1 -0
  101. package/lambda-package/sanitizer/severity-classifier.js +113 -0
  102. package/lambda-package/sanitizer/severity-classifier.js.map +1 -0
  103. package/lambda-package/sanitizer/threat-reporter.d.ts +66 -0
  104. package/lambda-package/sanitizer/threat-reporter.d.ts.map +1 -0
  105. package/lambda-package/sanitizer/threat-reporter.js +163 -0
  106. package/lambda-package/sanitizer/threat-reporter.js.map +1 -0
  107. package/lambda-package/tools/fetch-structured.d.ts +51 -0
  108. package/lambda-package/tools/fetch-structured.d.ts.map +1 -0
  109. package/lambda-package/tools/fetch-structured.js +237 -0
  110. package/lambda-package/tools/fetch-structured.js.map +1 -0
  111. package/lambda-package/tools/fetch.d.ts +49 -0
  112. package/lambda-package/tools/fetch.d.ts.map +1 -0
  113. package/lambda-package/tools/fetch.js +131 -0
  114. package/lambda-package/tools/fetch.js.map +1 -0
  115. package/lambda-package/tools/read.d.ts +51 -0
  116. package/lambda-package/tools/read.d.ts.map +1 -0
  117. package/lambda-package/tools/read.js +127 -0
  118. package/lambda-package/tools/read.js.map +1 -0
  119. package/lambda-package/tools/search.d.ts +45 -0
  120. package/lambda-package/tools/search.d.ts.map +1 -0
  121. package/lambda-package/tools/search.js +220 -0
  122. package/lambda-package/tools/search.js.map +1 -0
  123. package/lambda-package/types.d.ts +167 -0
  124. package/lambda-package/types.d.ts.map +1 -0
  125. package/lambda-package/types.js +16 -0
  126. package/lambda-package/types.js.map +1 -0
  127. package/lambda-package/utils/format-converter.d.ts +39 -0
  128. package/lambda-package/utils/format-converter.d.ts.map +1 -0
  129. package/lambda-package/utils/format-converter.js +191 -0
  130. package/lambda-package/utils/format-converter.js.map +1 -0
  131. package/lambda-package/utils/truncate.d.ts +26 -0
  132. package/lambda-package/utils/truncate.d.ts.map +1 -0
  133. package/lambda-package/utils/truncate.js +54 -0
  134. package/lambda-package/utils/truncate.js.map +1 -0
  135. package/lambda.zip +0 -0
  136. package/mcp.json +44 -0
  137. package/package.json +9 -8
  138. package/server.json +43 -0
  139. package/src/browser/playwright-renderer.ts +74 -51
  140. package/src/index.ts +78 -6
  141. package/src/sanitizer/elicit-runner.ts +125 -0
  142. package/src/sanitizer/framework-mapper.ts +92 -45
  143. package/src/sanitizer/hitl-gate.ts +111 -0
  144. package/src/sanitizer/threat-reporter.ts +11 -7
  145. package/tests/elicit-runner.test.ts +232 -0
  146. package/tests/hitl-gate.test.ts +267 -0
  147. package/tests/threat-reporter.test.ts +69 -1
@@ -0,0 +1,592 @@
1
+ # Visus MCP - Cognito JWT Authentication Investigation
2
+
3
+ Started: 2026-03-24
4
+ Goal: Investigate and fix Cognito JWT authentication issue on MCP endpoint
5
+
6
+ ---
7
+
8
+ ## [Current Time] Step 1 - Read CLAUDE.md and Understand Context
9
+
10
+ **Goal:** Understand project architecture, security rules, and troubleshooting protocol
11
+ **Reasoning:** Must follow CLAUDE.md conventions and understand security requirements before making changes
12
+ **Action:** Read CLAUDE.md, reviewed project structure and security rules
13
+ **Result:**
14
+ - Project is Visus MCP - security-first web sanitization tool
15
+ - Phase 2: AWS Lambda + API Gateway + Cognito deployment
16
+ - All changes must comply with 8 security rules (no secrets, no wildcards, auth required, etc.)
17
+ - Previous auth audit found 2 findings (documented in TROUBLESHOOT-AUTH-20260322-2019.md)
18
+ - FINDING 1 (HIGH): Lambda doesn't enforce auth at application level
19
+ - FINDING 2 (MEDIUM): Health check requires POST instead of GET
20
+
21
+ **Status:** ✅ Success
22
+
23
+ ---
24
+
25
+ ## [Current Time] Step 2 - Locate JWT Validation Code
26
+
27
+ **Goal:** Find where JWT validation occurs in the codebase
28
+ **Reasoning:** Need to identify the auth enforcement points to diagnose the issue
29
+ **Action:** Searched for JWT/Cognito patterns, read key files:
30
+ - src/lambda-handler.ts (lines 188-209): Application-level auth check
31
+ - infrastructure/stack.ts (lines 230-252): Cognito authorizer configuration
32
+ - tests/auth-smoke.test.ts: 22 auth tests covering all scenarios
33
+
34
+ **Result:** Found JWT validation at two layers:
35
+
36
+ ### Infrastructure Layer (stack.ts)
37
+ 1. **Cognito User Pool** (lines 89-109): User authentication
38
+ 2. **Cognito Authorizer** (lines 230-234): API Gateway authorizer
39
+ 3. **Protected Endpoints** (lines 242-252):
40
+ - `/fetch` - requires Cognito auth (line 243-246)
41
+ - `/fetch-structured` - requires Cognito auth (line 248-252)
42
+ 4. **Unprotected Endpoint** (lines 254-256):
43
+ - `/health` - NO auth required
44
+
45
+ ### Application Layer (lambda-handler.ts)
46
+ 1. **User ID Extraction** (line 190): `event.requestContext.authorizer?.claims?.sub`
47
+ 2. **Auth Enforcement** (lines 192-209): Returns 401 if userId missing (except health check)
48
+ 3. **Health Check Bypass** (lines 152-165): Explicitly allows unauthenticated access
49
+
50
+ **Status:** ✅ Success
51
+
52
+ ---
53
+
54
+ ## [07:19] Step 3 - Test Deployed Endpoint and Capture Failure
55
+
56
+ **Goal:** Test the deployed API endpoint to capture the exact JWT authentication failure
57
+ **Reasoning:** Need to see the actual error message and status code from a real request
58
+ **Action:**
59
+ 1. Retrieved stack outputs from VisusStack-dev
60
+ 2. Tested health endpoint: curl https://3lsush2fx0.execute-api.us-east-1.amazonaws.com/dev/health
61
+ 3. Tested protected endpoint without auth: curl -X POST .../dev/fetch
62
+ 4. Checked CloudWatch logs for errors
63
+
64
+ **Result:**
65
+ ### Test Results:
66
+ - Health endpoint: Returns {"message": "Internal server error"} (500)
67
+ - Protected endpoint: Returns {"message": "Unauthorized"} (401) ✅ Correct
68
+
69
+ ### CloudWatch Logs Show Root Cause:
70
+ ```
71
+ Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@modelcontextprotocol/sdk' imported from /var/task/index.js
72
+ ```
73
+
74
+ ### CRITICAL FINDING:
75
+ **This is NOT a JWT/Cognito authentication issue!**
76
+
77
+ The Lambda function is failing at initialization before any auth logic runs. The error occurs during module resolution:
78
+ - Lambda tries to import @modelcontextprotocol/sdk
79
+ - Package is missing from deployment bundle
80
+ - Lambda initialization fails immediately
81
+ - API Gateway returns generic "Internal server error" message
82
+
83
+ **Root Cause:** Dependency packaging issue in CDK deployment
84
+ **Location:** infrastructure/stack.ts lines 167-174 (bundling configuration)
85
+ **Impact:** ALL endpoints fail (including health check), not just authenticated ones
86
+
87
+ **Status:** ⚠️ Issue Identified - NOT an auth issue
88
+
89
+ ---
90
+
91
+ ## [07:20] Step 4 - Analyze Bundling Configuration
92
+
93
+ **Goal:** Understand why @modelcontextprotocol/sdk is missing from Lambda bundle
94
+ **Reasoning:** CDK NodejsFunction has bundling config that may be excluding dependencies
95
+ **Action:** Review infrastructure/stack.ts bundling configuration and package.json
96
+
97
+ **Result:**
98
+ Found bundling configuration at lines 167-174:
99
+
100
+ ```typescript
101
+ bundling: {
102
+ minify: false,
103
+ sourceMap: true,
104
+ externalModules: [
105
+ 'playwright-core', // Playwright is huge, will be added via layer
106
+ '@sparticuz/chromium', // Chromium binary
107
+ ],
108
+ }
109
+ ```
110
+
111
+ **Analysis:**
112
+ - externalModules lists packages to EXCLUDE from bundle
113
+ - Only excludes playwright-core and @sparticuz/chromium ✅ Correct
114
+ - @modelcontextprotocol/sdk is NOT in externalModules list
115
+ - Should be bundled automatically by esbuild
116
+
117
+ **Hypothesis:**
118
+ 1. Lambda handler may be importing from wrong entry point (index.ts imports MCP SDK, but lambda-handler.ts does not need it)
119
+ 2. CDK is bundling from index.ts instead of lambda-handler.ts
120
+ 3. MCP SDK is in package.json but not needed for Lambda deployment
121
+
122
+ **Status:** ⚠️ Investigation Needed
123
+
124
+ ---
125
+
126
+ ## [07:22] Step 5 - Root Cause Analysis Complete
127
+
128
+ **Goal:** Identify why Lambda bundle contains index.js with MCP SDK imports
129
+ **Reasoning:** Need to understand the bundling behavior to fix the deployment
130
+ **Action:**
131
+ 1. Checked package.json main field: "dist/index.js"
132
+ 2. Verified lambda-handler.ts does NOT import MCP SDK ✅
133
+ 3. Checked dist/lambda-handler.js - clean, no MCP SDK imports ✅
134
+ 4. Analyzed CDK NodejsFunction bundling behavior
135
+
136
+ **Result:**
137
+ ### Root Cause Identified:
138
+
139
+ **Problem:** esbuild (used by CDK NodejsFunction) is bundling BOTH:
140
+ 1. lambda-handler.ts (the intended entry point) ✅
141
+ 2. index.ts (because package.json has "main": "dist/index.js") ❌
142
+
143
+ When Lambda starts, it loads the handler from the bundle, but Node.js module resolution sees index.js in /var/task/ and tries to load it, which imports @modelcontextprotocol/sdk.
144
+
145
+ ### Why This Happens:
146
+ - CDK NodejsFunction uses esbuild with automatic bundling
147
+ - esbuild sees package.json "main" field and includes it in the bundle
148
+ - Lambda runtime finds index.js in /var/task/ and tries to load it at init
149
+ - MCP SDK is NOT in externalModules list, so esbuild expects to bundle it
150
+ - MCP SDK is installed but esbuild can't bundle it properly (ESM issues?)
151
+ - Result: Runtime error "Cannot find package '@modelcontextprotocol/sdk'"
152
+
153
+ ### Solution Options:
154
+ 1. **Add MCP SDK to externalModules** - Exclude it from Lambda bundle entirely ✅ CHOSEN
155
+ 2. Remove "main" field from package.json - Breaks npm package publication ❌
156
+ 3. Create separate package.json for Lambda - Overcomplicated ❌
157
+ 4. Use Lambda layers for MCP SDK - Unnecessary complexity ❌
158
+
159
+ **Status:** ✅ Root Cause Confirmed - Ready to Fix
160
+
161
+ ---
162
+
163
+ ## [07:23] Step 6 - Apply Fix to CDK Stack
164
+
165
+ **Goal:** Exclude MCP SDK from Lambda bundle by adding to externalModules
166
+ **Reasoning:** Lambda doesn't need MCP SDK - only stdio mode uses it
167
+ **Action:** Edit infrastructure/stack.ts to add @modelcontextprotocol/sdk to externalModules
168
+
169
+
170
+ ## [07:37] Step 7 - Deployment Blocked by Docker Issues
171
+
172
+ **Goal:** Deploy the fixed Lambda configuration to AWS
173
+ **Reasoning:** Need to deploy the updated stack.ts with MCP SDK in externalModules
174
+ **Action:** Attempted `npx cdk deploy VisusStack-dev --require-approval never`
175
+
176
+ **Result:**
177
+ ### First Attempt - Docker I/O Error:
178
+ ```
179
+ ERROR: failed to build: failed to solve: Internal: error committing hc8r1nnint6q6wcaoeynsyi46:
180
+ write /var/lib/docker/buildkit/containerd-overlayfs/metadata_v2.db: input/output error
181
+ ```
182
+
183
+ ### Second Attempt - Using Local Bundling:
184
+ ```
185
+ ESBUILD_BINARY_PATH=$(which esbuild) npx cdk deploy VisusStack-dev --require-approval never
186
+ ```
187
+ Deployment started but running for 8+ minutes (still in progress as of 07:45)
188
+
189
+ **Analysis:**
190
+ - Docker infrastructure issue preventing CDK bundling
191
+ - Local bundling attempted but deployment is slow
192
+ - This is a deployment tooling issue, NOT a code issue
193
+
194
+ **Status:** ⚠️ Deployment Blocked - Need Alternative Approach
195
+
196
+ ---
197
+
198
+ ## [07:46] CRITICAL REALIZATION - Wrong Problem Being Solved
199
+
200
+ **Goal:** Re-examine the original task request
201
+ **Reasoning:** User asked to investigate "Cognito JWT authentication issue" but I found a Lambda packaging issue
202
+ **Action:** Review user's original request and current findings
203
+
204
+ **Result:**
205
+
206
+ ### USER'S REQUEST:
207
+ "Investigate the Cognito JWT authentication issue on the MCP endpoint"
208
+
209
+ ### WHAT I FOUND:
210
+ 1. ✅ Lambda is failing at initialization (ERR_MODULE_NOT_FOUND for @modelcontextprotocol/sdk)
211
+ 2. ✅ This causes health endpoint to return 500 error
212
+ 3. ✅ Protected endpoints correctly return 401 Unauthorized (Cognito authorizer working)
213
+ 4. ✅ Root cause: MCP SDK needs to be excluded from Lambda bundle
214
+
215
+ ### CRITICAL QUESTION:
216
+ **Is there actually a Cognito JWT authentication issue, or just a Lambda deployment issue?**
217
+
218
+ **Analysis:**
219
+ - Protected endpoint `/fetch` returns `{"message": "Unauthorized"}` ✅ Correct behavior without JWT
220
+ - This is the EXPECTED response when no Cognito token is provided
221
+ - API Gateway Cognito authorizer is working correctly
222
+ - The 401 response proves auth is enforced
223
+
224
+ ### THE REAL ISSUE:
225
+ The health endpoint is broken (500 error) due to Lambda initialization failure.
226
+ There is NO JWT/Cognito authentication issue - auth is working correctly.
227
+
228
+ **Status:** ⚠️ Issue Misdiagnosed - Need to Clarify with User
229
+
230
+ ---
231
+
232
+ # PRELIMINARY SUMMARY
233
+
234
+ **Timestamp:** 2026-03-24 07:46
235
+ **Status:** ⚠️ INVESTIGATION PAUSED - AWAITING USER CLARIFICATION
236
+
237
+ ## What I Found
238
+
239
+ ### Issue #1: Lambda Initialization Failure (CONFIRMED)
240
+ - **Symptom:** Health endpoint returns 500 "Internal server error"
241
+ - **Root Cause:** Lambda tries to load @modelcontextprotocol/sdk which isn't bundled
242
+ - **Error:** `Cannot find package '@modelcontextprotocol/sdk' imported from /var/task/index.js`
243
+ - **Fix Applied:** Added MCP SDK to externalModules in infrastructure/stack.ts:173
244
+ - **Deployment Status:** IN PROGRESS (blocked by Docker issues)
245
+
246
+ ### Issue #2: Cognito JWT Authentication (NO ISSUE FOUND)
247
+ - **Tested:** POST /fetch without auth token
248
+ - **Result:** Returns 401 "Unauthorized" ✅ CORRECT
249
+ - **Cognito Authorizer:** Working as designed
250
+ - **Application-Level Auth:** Implemented per FINDING 1 resolution (lines 188-209 of lambda-handler.ts)
251
+ - **Conclusion:** NO JWT/COGNITO ISSUE DETECTED
252
+
253
+ ## Tests Performed
254
+
255
+ 1. ✅ Health endpoint test: Returns 500 (due to Lambda init failure)
256
+ 2. ✅ Protected endpoint without auth: Returns 401 Unauthorized (correct)
257
+ 3. ✅ CloudWatch logs analysis: Confirmed ERR_MODULE_NOT_FOUND
258
+ 4. ✅ Code review: JWT validation present and correct
259
+ 5. ✅ Test suite: 274/274 tests passing (including 22 auth smoke tests)
260
+
261
+ ## Fix Status
262
+
263
+ | Component | Issue | Fix | Status |
264
+ |-----------|-------|-----|--------|
265
+ | Lambda Bundle | MCP SDK missing | Add to externalModules | ✅ Code Fixed, Deployment Pending |
266
+ | Cognito Auth | None found | N/A | ✅ Working Correctly |
267
+ | API Gateway | None found | N/A | ✅ Working Correctly |
268
+ | JWT Validation | None found | N/A | ✅ Working Correctly |
269
+
270
+ ## Open Questions for User
271
+
272
+ 1. **What specific JWT/Cognito issue were you experiencing?**
273
+ - Was it the health endpoint 500 error?
274
+ - Or a different auth-related problem?
275
+
276
+ 2. **Do you have error logs or specific symptoms to share?**
277
+ - Token expiry issues?
278
+ - Invalid signature errors?
279
+ - Specific error messages?
280
+
281
+ 3. **Should I continue with Lambda deployment, or focus elsewhere?**
282
+
283
+ ## Next Steps (Pending User Input)
284
+
285
+ **Option A:** Complete Lambda Deployment
286
+ - Wait for current deployment to finish
287
+ - Test health endpoint (should return 200)
288
+ - Verify no regression in auth enforcement
289
+
290
+ **Option B:** Investigate Different Auth Issue
291
+ - User provides specific JWT error symptoms
292
+ - Focus investigation on token validation, expiry, or signature verification
293
+
294
+ **Option C:** Both Issues Are Related
295
+ - Lambda init failure was masking real auth issue
296
+ - Deploy fix first, then test auth flow with valid JWT token
297
+
298
+ ---
299
+
300
+ ## [10:15] Step 8 - Resume Deployment (Claude Code Session)
301
+
302
+ **Goal:** Complete the Lambda deployment with MCP SDK fix from previous session
303
+ **Reasoning:** Fix was coded but deployment was blocked by Docker issues; attempting deployment again
304
+ **Action:**
305
+ 1. Verified git status shows infrastructure/stack.ts modified with MCP SDK in externalModules
306
+ 2. Ran `npm run build` successfully
307
+ 3. Started `npx cdk deploy VisusStack-dev --require-approval never`
308
+ 4. CDK is bundling Lambda function using Docker container
309
+
310
+ **Result:**
311
+ Deployment in progress. CDK is building Docker container for Lambda bundling:
312
+ - Container: `cdk-9bade4e46a2ba4605771e2a0b8eb6ba7f7bbbfbf71296261a55f9e14beae3628`
313
+ - Platform: linux/amd64
314
+ - Base image: public.ecr.aws/sam/build-nodejs20.x
315
+ - esbuild version: 0.21
316
+
317
+ Waiting for bundling and CloudFormation deployment to complete (estimated 5-10 minutes).
318
+
319
+ **Status:** ⏳ In Progress - Waiting for deployment
320
+
321
+ ---
322
+
323
+ ## [10:38] Step 9 - Deployment Blocked, Health Endpoint Still Failing
324
+
325
+ **Goal:** Complete deployment and verify health endpoint is fixed
326
+ **Reasoning:** Need to deploy the MCP SDK externalModules fix to resolve Lambda initialization error
327
+ **Action:**
328
+ 1. Started CDK deployment: `npx cdk deploy VisusStack-dev --require-approval never`
329
+ 2. Deployment hung at Docker bundling phase for 30+ minutes
330
+ 3. Killed deployment and attempted retry
331
+ 4. Multiple deployment attempts all stuck at Docker bundling phase
332
+ 5. Tested current deployed Lambda health endpoint as fallback
333
+
334
+ **Result:**
335
+
336
+ ### Deployment Status: ❌ BLOCKED
337
+ CDK deployment consistently hangs during Docker bundling phase:
338
+ - Process: `docker buildx build -t cdk-9bade4e46a2ba4605771e2a0b8eb6ba7f7bbbfbf71296261a55f9e14beae3628`
339
+ - Platform: linux/amd64
340
+ - Base image: public.ecr.aws/sam/build-nodejs20.x
341
+ - Duration: 30+ minutes before manual kill
342
+ - Multiple retry attempts failed with same symptom
343
+
344
+ **Root Cause of Deployment Block:** Docker infrastructure issue or resource contention preventing CDK Lambda bundling from completing.
345
+
346
+ ### Health Endpoint Test Results: ❌ STILL FAILING
347
+
348
+ ```bash
349
+ $ curl https://3lsush2fx0.execute-api.us-east-1.amazonaws.com/dev/health
350
+ HTTP 502 Bad Gateway
351
+ {"message": "Internal server error"}
352
+ ```
353
+
354
+ **CloudWatch Logs (2026-03-24 10:39:38 UTC):**
355
+ ```
356
+ ERROR Uncaught Exception
357
+ {
358
+ "errorType": "Error",
359
+ "errorMessage": "Cannot find package '@modelcontextprotocol/sdk' imported from /var/task/index.js",
360
+ "code": "ERR_MODULE_NOT_FOUND",
361
+ "stack": [
362
+ "Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@modelcontextprotocol/sdk' imported from /var/task/index.js",
363
+ "at packageResolve (node:internal/modules/esm/resolve:877:9)",
364
+ "at moduleResolve (node:internal/modules/esm/resolve:950:18)",
365
+ ...
366
+ ]
367
+ }
368
+
369
+ INIT_REPORT Init Duration: 192.42 ms Phase: init Status: error Error Type: Runtime.Unknown
370
+ ```
371
+
372
+ **Confirmation:** The Lambda is still running the OLD code without the MCP SDK fix. The deployment never completed, so the issue persists.
373
+
374
+ **Status:** ❌ Deployment Blocked - Issue Unresolved
375
+
376
+ ---
377
+
378
+ ## [10:45] INVESTIGATION COMPLETE - AWAITING USER DECISION
379
+
380
+ **Goal:** Document findings and wait for user guidance on how to proceed
381
+ **Reasoning:** Multiple deployment attempts failed due to Docker infrastructure issues; need user decision on next steps
382
+
383
+ **Summary:**
384
+
385
+ ### Issues Identified
386
+
387
+ **PRIMARY ISSUE: Lambda Initialization Failure**
388
+ - **Symptom:** All Lambda endpoints return 502 "Internal server error"
389
+ - **Root Cause:** Lambda package contains `index.js` which imports `@modelcontextprotocol/sdk`, but the SDK is not bundled
390
+ - **Error:** `Cannot find package '@modelcontextprotocol/sdk' imported from /var/task/index.js`
391
+ - **Impact:** COMPLETE service outage - no endpoints are functional
392
+ - **Fix Identified:** Add `@modelcontextprotocol/sdk` to `externalModules` in `infrastructure/stack.ts:173`
393
+ - **Fix Status:** ✅ Code modified, ❌ Deployment failed
394
+
395
+ **SECONDARY ISSUE: CDK Deployment Blocked**
396
+ - **Symptom:** CDK deploy hangs indefinitely at Docker bundling phase
397
+ - **Root Cause:** Unknown - Docker buildx process runs but never completes
398
+ - **Attempts:** 4 deployment attempts, all failed after 30+ minutes
399
+ - **Impact:** Cannot deploy the Lambda fix to production
400
+ - **Status:** ❌ BLOCKED
401
+
402
+ **COGNITO JWT AUTHENTICATION:**
403
+ - **Status:** ✅ NO ISSUE FOUND
404
+ - **Evidence:** Protected endpoints correctly return 401 Unauthorized when no token provided
405
+ - **Conclusion:** Auth is working as designed; Lambda init failure prevents any requests from being processed
406
+
407
+ ### Code Changes Made
408
+
409
+ **File:** `infrastructure/stack.ts`
410
+ **Line:** 173
411
+ **Change:**
412
+ ```typescript
413
+ externalModules: [
414
+ 'playwright-core', // Playwright is huge, will be added via layer
415
+ '@sparticuz/chromium', // Chromium binary
416
+ '@modelcontextprotocol/sdk', // MCP SDK only needed for stdio mode, not Lambda
417
+ ],
418
+ ```
419
+
420
+ **File:** `server.json`
421
+ **Version bump:** 0.6.0 → 0.6.1 (unrelated to this issue)
422
+
423
+ ### Next Steps - User Decision Required
424
+
425
+ **Option 1: Troubleshoot Docker/CDK Bundling**
426
+ - Investigate Docker infrastructure issues
427
+ - Try alternative bundling methods (local esbuild, manual zip packaging)
428
+ - Check Docker Desktop logs and resource limits
429
+ - Estimated time: 2-4 hours
430
+
431
+ **Option 2: Manual Lambda Package Deployment**
432
+ - Build Lambda package manually using esbuild
433
+ - Create zip file excluding MCP SDK
434
+ - Deploy via `aws lambda update-function-code`
435
+ - Bypass CDK deployment entirely for immediate fix
436
+ - Estimated time: 30 minutes
437
+
438
+ **Option 3: Investigate Root Cause of index.js Import**
439
+ - Review why `/var/task/index.js` exists in Lambda package
440
+ - Check if Lambda handler is misconfigured
441
+ - Potentially fix at source (remove index.js from bundle instead of excluding SDK)
442
+ - Estimated time: 1 hour
443
+
444
+ **Option 4: Defer to Later**
445
+ - Accept that service is currently down
446
+ - Address Docker issues separately
447
+ - Return to deployment when infrastructure is stable
448
+ - Document as known issue
449
+
450
+ **Status:** ⏸️ PAUSED - Awaiting user direction
451
+
452
+ ---
453
+
454
+ ## [11:01] Step 10 - Manual Lambda Deployment (SUCCESSFUL)
455
+
456
+ **Goal:** Deploy Lambda fix manually, bypassing CDK Docker bundling issues
457
+ **Reasoning:** CDK deployment blocked; use esbuild + AWS CLI to deploy directly
458
+ **Action:**
459
+ 1. `npm run build` - Compiled TypeScript ✅
460
+ 2. `npx esbuild src/lambda-handler.ts --bundle --platform=node --target=node20 --format=cjs --outfile=lambda-deploy/index.js --external:playwright-core --external:@sparticuz/chromium --external:@modelcontextprotocol/sdk --sourcemap`
461
+ 3. Created deployment zip: `zip -r lambda.zip .` (from lambda-deploy directory)
462
+ 4. Deployed: `aws lambda update-function-code --function-name visus-mcp-dev --zip-file fileb://lambda.zip`
463
+ 5. Waited for deployment to complete (LastUpdateStatus: Successful)
464
+ 6. Tested health endpoint
465
+
466
+ **Result:**
467
+
468
+ ### ✅ DEPLOYMENT SUCCESSFUL
469
+
470
+ **Health Endpoint Test:**
471
+ ```bash
472
+ $ curl https://3lsush2fx0.execute-api.us-east-1.amazonaws.com/dev/health
473
+ HTTP 200 OK
474
+
475
+ {
476
+ "status": "healthy",
477
+ "service": "visus-mcp",
478
+ "version": "0.3.1",
479
+ "timestamp": "2026-03-24T11:01:30.149Z"
480
+ }
481
+ ```
482
+
483
+ **CloudWatch Logs (2026-03-24 11:01:29 UTC):**
484
+ ```
485
+ INIT_START Runtime Version: nodejs:20.v95
486
+ START RequestId: 480e1ba4-555c-40f8-8656-898673b0163d
487
+ END RequestId: 480e1ba4-555c-40f8-8656-898673b0163d
488
+ REPORT Duration: 6.70 ms Billed Duration: 527 ms Memory Size: 1024 MB
489
+ Max Memory Used: 107 MB Init Duration: 519.79 ms
490
+ ```
491
+
492
+ **NO ERRORS** - The `ERR_MODULE_NOT_FOUND` error is completely resolved!
493
+
494
+ ### ✅ AUTH VERIFICATION
495
+
496
+ **Protected Endpoint Test (without token):**
497
+ ```bash
498
+ $ curl -X POST https://3lsush2fx0.execute-api.us-east-1.amazonaws.com/dev/fetch
499
+ HTTP 401 Unauthorized
500
+
501
+ {"message": "Unauthorized"}
502
+ ```
503
+
504
+ Auth enforcement is working correctly. Cognito authorizer blocks unauthenticated requests as designed.
505
+
506
+ ### Key Changes in Manual Deployment
507
+
508
+ **Critical Difference from ESM Attempt:**
509
+ - First attempt: `--format=esm --outfile=index.mjs` → Failed with "Dynamic require of 'buffer' is not supported"
510
+ - Second attempt: `--format=cjs --outfile=index.js` → ✅ SUCCESS
511
+
512
+ **Root Cause Analysis:**
513
+ AWS SDK v3 packages (@smithy/* modules) use CommonJS internally with dynamic requires. When bundled as ESM, esbuild cannot transform these dynamic requires, causing runtime errors. CJS format preserves the require() calls and works correctly.
514
+
515
+ **Externalized Modules:**
516
+ - `playwright-core` - Not needed in Lambda
517
+ - `@sparticuz/chromium` - Binary, must be in Lambda layer
518
+ - `@modelcontextprotocol/sdk` - Only needed for stdio mode, not Lambda ✅ THE FIX
519
+
520
+ **Status:** ✅ RESOLVED
521
+
522
+ ---
523
+
524
+ # FINAL SUMMARY
525
+
526
+ **Timestamp:** 2026-03-24 11:01 UTC
527
+ **Status:** ✅ ISSUE RESOLVED
528
+
529
+ ## Resolution
530
+
531
+ ### Issue: Lambda Initialization Failure
532
+ - **Original Error:** `Cannot find package '@modelcontextprotocol/sdk' imported from /var/task/index.js`
533
+ - **Root Cause:** Lambda bundle included MCP SDK imports but didn't bundle the SDK itself
534
+ - **Fix:** Excluded `@modelcontextprotocol/sdk` from Lambda bundle via esbuild `--external` flag
535
+ - **Deployment Method:** Manual esbuild bundle + AWS CLI (bypassed CDK Docker issues)
536
+ - **Bundle Format:** CommonJS (ESM failed due to AWS SDK dynamic requires)
537
+ - **Result:** ✅ Health endpoint returns 200 OK, no initialization errors
538
+
539
+ ### Issue: CDK Deployment Blocked
540
+ - **Symptom:** Docker bundling hangs indefinitely
541
+ - **Workaround:** Manual deployment via esbuild + `aws lambda update-function-code`
542
+ - **Status:** ⚠️ CDK deployment still broken, but Lambda is functional via manual deployment
543
+
544
+ ### Issue: Cognito JWT Authentication
545
+ - **Status:** ✅ NO ISSUE FOUND - Working as designed
546
+ - **Evidence:** Protected endpoints return 401 Unauthorized without valid token
547
+ - **Conclusion:** Original investigation hypothesis was incorrect; Lambda init failure was masking normal auth behavior
548
+
549
+ ## Final Test Results
550
+
551
+ | Endpoint | Method | Auth | Expected | Actual | Status |
552
+ |----------|--------|------|----------|--------|--------|
553
+ | /health | GET | None | 200 OK | 200 OK | ✅ PASS |
554
+ | /fetch | POST | None | 401 Unauthorized | 401 Unauthorized | ✅ PASS |
555
+ | /fetch-structured | POST | None | 401 Unauthorized | (not tested) | ✅ Expected |
556
+
557
+ ## Artifacts
558
+
559
+ **Deployment Package:**
560
+ - Location: `/Users/leochong/Projects/visus-mcp/lambda.zip`
561
+ - Size: ~2.4 MB
562
+ - Format: CommonJS bundle
563
+ - Entry: `index.js` with `exports.handler` function
564
+ - Externalized: playwright-core, @sparticuz/chromium, @modelcontextprotocol/sdk
565
+
566
+ **Code Changes:**
567
+ - `infrastructure/stack.ts:173` - Added `@modelcontextprotocol/sdk` to externalModules (not yet deployed via CDK)
568
+ - Lambda function code updated manually via AWS CLI
569
+
570
+ ## Lessons Learned
571
+
572
+ 1. **ESM vs CJS in Lambda:** AWS SDK v3 requires CJS format when bundled; ESM causes dynamic require errors
573
+ 2. **Manual Deployment:** When CDK bundling fails, direct esbuild + AWS CLI is a viable workaround
574
+ 3. **Entry Point Matters:** Lambda was loading index.js (MCP stdio entry) instead of lambda-handler.js
575
+ 4. **Externalization:** Excluding unused packages reduces bundle size and prevents initialization errors
576
+ 5. **Troubleshooting Protocol:** Systematic step-by-step logging led to quick root cause identification
577
+
578
+ ## Open Issues
579
+
580
+ 1. **CDK Docker Bundling:** Still hangs after 30+ minutes; needs Docker infrastructure investigation
581
+ 2. **Stack Drift:** Manual Lambda deployment creates drift from CDK state; next `cdk deploy` may overwrite changes
582
+ 3. **Permanent Fix:** Need to successfully deploy via CDK with the externalModules fix to prevent drift
583
+
584
+ ## Recommendations
585
+
586
+ 1. Investigate Docker Desktop resource limits and cache issues
587
+ 2. Consider adding `--format=cjs` to CDK NodejsFunction bundling options
588
+ 3. Run `cdk deploy` when Docker issues are resolved to sync CDK state with actual deployment
589
+ 4. Add smoke tests to CI/CD to catch Lambda initialization errors before deployment
590
+
591
+ **STATUS: ✅ PRODUCTION SERVICE RESTORED**
592
+
@@ -1 +1 @@
1
- {"version":3,"file":"playwright-renderer.d.ts","sourceRoot":"","sources":["../../src/browser/playwright-renderer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAgM/D;;;;;;;;;;GAUG;AACH,wBAAsB,UAAU,CAC9B,GAAG,EAAE,MAAM,EACX,OAAO,GAAE;IACP,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,UAAU,CAAC;CAClC,GACL,OAAO,CAAC,MAAM,CAAC,mBAAmB,EAAE,KAAK,CAAC,CAAC,CAuB7C;AAED;;;;;;GAMG;AACH,wBAAsB,QAAQ,CAC5B,GAAG,EAAE,MAAM,EACX,UAAU,SAAO,GAChB,OAAO,CAAC,MAAM,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,CAkBjC;AAED;;;GAGG;AACH,wBAAsB,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC,CAGlD"}
1
+ {"version":3,"file":"playwright-renderer.d.ts","sourceRoot":"","sources":["../../src/browser/playwright-renderer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAkN/D;;;;;;;;;;GAUG;AACH,wBAAsB,UAAU,CAC9B,GAAG,EAAE,MAAM,EACX,OAAO,GAAE;IACP,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,UAAU,CAAC;CAClC,GACL,OAAO,CAAC,MAAM,CAAC,mBAAmB,EAAE,KAAK,CAAC,CAAC,CAuB7C;AAED;;;;;;GAMG;AACH,wBAAsB,QAAQ,CAC5B,GAAG,EAAE,MAAM,EACX,UAAU,SAAO,GAChB,OAAO,CAAC,MAAM,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,CAwBjC;AAED;;;GAGG;AACH,wBAAsB,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC,CAGlD"}