Skip to content

feat: improve Claude Desktop support and token refresh reliability#8

Open
rathga wants to merge 1 commit into
jhirono:mainfrom
rathga:feature/claude-desktop-support
Open

feat: improve Claude Desktop support and token refresh reliability#8
rathga wants to merge 1 commit into
jhirono:mainfrom
rathga:feature/claude-desktop-support

Conversation

@rathga

@rathga rathga commented Mar 4, 2026

Copy link
Copy Markdown

I tried using this in Claude Desktop, but had a few issues. I asked Claude code to fix them, which it did and it's all working smoothly now. Here's a PR with the changes that it came up with.

Summary

  • Fix dotenv path resolution: Resolve .env relative to script location instead of process.cwd(), which differs when launched by Claude Desktop (often C:\Windows\System32)
  • Improve token refresh: Add proactive refresh on token expiration, 401 retry logic, and use TENANT_ID from env for the refresh endpoint instead of hardcoding /consumers/
  • Fix token file resolution in CLI: Look for tokens.json next to the script before falling back to cwd, so it works when launched from any directory
  • Pass expiresAt through CLI: Forward token expiration time from tokens.json to the server so it can proactively refresh before API calls fail
  • Update README: Add Claude Desktop configuration instructions, token refresh documentation, and troubleshooting for common issues (server exit on Windows, 401 errors with personal accounts, tenant ID configuration)
  • Remove verbose logging: Clean up request/response debug logging that leaked into production

Test plan

  • Verify MCP server starts correctly from Claude Desktop on Windows using build/cli.js
  • Verify automatic token refresh works when access token expires (~1 hour)
  • Verify 401 retry logic recovers from expired tokens mid-session
  • Verify .env is loaded correctly regardless of working directory
  • Verify tokens.json is found when server is launched from a different directory
  • Run npm run build to confirm TypeScript compiles without errors

🤖 Generated with Claude Code

- Fix dotenv to resolve .env relative to script location instead of cwd,
  which may differ when launched by Claude Desktop
- Add automatic token refresh on expiration and 401 retry logic
- Use TENANT_ID from env for token refresh endpoint instead of hardcoding
- Resolve tokens.json relative to script location with cwd fallback
- Pass token expiration time through CLI to server for proactive refresh
- Add Claude Desktop configuration instructions and troubleshooting to README
- Remove verbose request/response logging

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@rathga
rathga marked this pull request as ready for review March 4, 2026 20:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant