JWT_TOKEN_ENCODING_ISSUE.mdโข5.4 kB
# JWT Token Encoding Issue - Troubleshooting Guide
**Issue ID**: JWT-ENCODING-001
**Date Identified**: June 10, 2025
**Severity**: High (Blocks Browser Automation)
**Status**: Resolved
## ๐ Problem Description
### Symptoms
- Browser automation fails with authentication errors
- MCP server generates URLs that don't work with Composer
- JWT token authentication rejected by EuConquisto Composer
### Root Cause
Character encoding corruption in JWT token at position 660:
- **Incorrect**: `_8xsw2oLD`
- **Correct**: `_xsw2oLD`
The extra "8" character in the JWT token breaks authentication with the EuConquisto Composer API.
## ๐ Technical Analysis
### Affected Files
1. `src/index.ts` - Line ~93 (get-composer-url tool)
2. `src/lib/composition-lifecycle.ts` - Line ~26 (ComposerClient class)
### Impact
- โ Browser automation fails to authenticate
- โ `complete-composition-workflow` tool non-functional
- โ All composition lifecycle tools blocked
- โ
Basic MCP tools (test-connection, get-widget-info) still work
### Detection Method
Compare working URL with MCP-generated URL:
```
Working URL: .../_xsw2oLD/...
MCP URL: .../_8xsw2oLD/...
^
Extra "8" character
```
## ๐ Applied Fix
### Step 1: Identify Source vs Compiled Issue
**Critical Discovery**: Previous fixes were applied to source files but compilation wasn't rebuilding properly.
**Verification Commands**:
```bash
# Check source file (should have correct token)
grep "_xsw2oLD" src/index.ts
grep "_xsw2oLD" src/lib/composition-lifecycle.ts
# Check compiled file (may have old incorrect token)
grep "_8xsw2oLD" dist/index.js
grep "_8xsw2oLD" dist/lib/composition-lifecycle.js
```
### Step 2: Root Cause Analysis
1. โ
Source files contained correct fix
2. โ Compiled `dist/` files still had incorrect token
3. โ Build process wasn't picking up source changes
4. โ Claude Desktop was running old compiled code
### Step 3: Complete Fix Process
```bash
# 1. Verify source files have correct token
cd /Users/ricardokawasaki/Desktop/euconquisto-composer-mcp-poc
# 2. Rebuild project to update dist/ files
npm run build
# 3. Verify compiled files now have correct token
grep "_xsw2oLD" dist/index.js
grep "_xsw2oLD" dist/lib/composition-lifecycle.js
# 4. Restart Claude Desktop to reload MCP server
# (Manual step via GUI)
```
## ๐ Why Previous Fix Failed
### Failed Approach 1: Source-Only Fix
- โ
Applied correct token to `src/index.ts` and `src/lib/composition-lifecycle.ts`
- โ Forgot to rebuild project (`npm run build`)
- โ Claude Desktop continued using old `dist/index.js` with incorrect token
### Failed Approach 2: Assumed Build Was Current
- โ Assumed TypeScript compilation was automatic
- โ Didn't verify `dist/` files were updated
- โ Didn't check file modification timestamps
### Successful Approach 3: Complete Workflow
- โ
Verified source files have correct token
- โ
Forced rebuild with `npm run build`
- โ
Verified compiled files now have correct token
- โ
Documented requirement for Claude Desktop restart
## ๐ Prevention Checklist
### For JWT Token Updates
- [ ] Update source files (`src/index.ts` and `src/lib/composition-lifecycle.ts`)
- [ ] Rebuild project (`npm run build`)
- [ ] Verify compiled files in `dist/` directory
- [ ] Check file modification timestamps
- [ ] Restart Claude Desktop to reload MCP server
- [ ] Test authentication with actual Composer URL
### For All MCP Server Changes
```bash
# Development workflow
npm run build # Compile TypeScript
npm run mcp:validate # Test MCP functionality
# Restart Claude Desktop # Reload server
# Test via Claude chat # Verify integration
```
## ๐งช Verification Tests
### Test 1: URL Generation
```javascript
// Call get-composer-url tool
// Verify response contains "_xsw2oLD" not "_8xsw2oLD"
```
### Test 2: Browser Authentication
```javascript
// Call complete-composition-workflow tool
// Should authenticate successfully, not fail with auth error
```
### Test 3: Token Consistency
```bash
# Verify both source and compiled files have same token
diff <(grep "jwtToken" src/index.ts) <(grep "jwtToken" dist/index.js)
diff <(grep "jwtToken" src/lib/composition-lifecycle.ts) <(grep "jwtToken" dist/lib/composition-lifecycle.js)
```
## ๐ Lessons Learned
1. **Always rebuild after source changes**: TypeScript compilation is not automatic
2. **Verify compiled output**: Source fixes don't matter if `dist/` files aren't updated
3. **Check file timestamps**: Confirm build actually regenerated files
4. **Test end-to-end**: Source code correctness โ runtime functionality
5. **Document build dependencies**: MCP server changes require full rebuild + restart cycle
## ๐ Related Documentation
- [Build Process](../development/BUILD_PROCESS.md)
- [Claude Desktop Integration](../integration/claude-desktop-setup.md)
- [MCP Server Development](../development/MCP_SERVER_DEVELOPMENT.md)
- [Browser Automation Troubleshooting](./BROWSER_AUTOMATION_TROUBLESHOOTING.md)
## ๐ Contact
For questions about this issue or similar JWT authentication problems:
- **Project**: EuConquisto Composer MCP Server
- **Version**: 0.1.6
- **Team**: EuConquisto Development Team
---
**Issue Resolution**: โ
RESOLVED
**Last Updated**: June 10, 2025
**Verified By**: MCP Testing Session
**Status**: Production Ready