Skip to content

Fix MCP token file save on Windows - #1229

Open
Yeagerist0 wants to merge 1 commit into
OWASP:mainfrom
Yeagerist0:fix/mcp-windows-token-file
Open

Yeagerist0 wants to merge 1 commit into
OWASP:mainfrom
Yeagerist0:fix/mcp-windows-token-file

Conversation

@Yeagerist0

@Yeagerist0 Yeagerist0 commented Nov 15, 2026 •

Copy link
Copy Markdown

Summary

Fixes #1224. The file-backed MCP refresh-token store now skips fchmod on Windows, where the supported Python version does not provide it. POSIX still requires fchmod(0600) and fails closed if that step fails. The login CLI reports token-store OSError as a clean failure instead of a traceback.

Verification

  • Added regression tests for Windows file save/load, POSIX chmod failure, and the CLI error message.
  • Ran isolated checks against the actual token-store and CLI modules: Windows save/load and POSIX fail-closed behavior passed; CLI emitted Login failed: cannot store token and returned 1.
  • python -m compileall -q on changed files and git diff --check passed.
  • PYTHONPATH=/tmp/opencre-app-deps:$PWD python -m unittest application.tests.mcp_auth_test -v passed: 16 tests (small missing dependencies installed only in a temporary path). The full suite and a native Windows run remain untested.

LLM Usage Considerations

Codex helped investigate the bug, write the fix and tests, and prepare this PR description. The behavior was checked with the stated tests. Independent review by the human contributor is pending; no claim of human validation is made.

@coderabbitai

coderabbitai Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Summary by CodeRabbit

  • Bug Fixes
    • Login now reports token-storage errors as login failures and returns a failure status.
    • Token saving now handles file permissions appropriately across Windows and other platforms. On non-Windows systems, permission-setting failures are reported rather than silently ignored.

Walkthrough

Token saving now skips os.fchmod on Windows and retains mode-setting error handling on other platforms. The login command reports OSError as a login failure.

Changes

MCP token login

Layer / File(s) Summary
Platform-specific token storage
application/mcp/token_store.py, application/tests/mcp_auth_test.py
Windows token saves skip os.fchmod. Other platforms retain the 0600 mode check and raise an error if it fails. Tests cover both platform paths.
Login storage error reporting
application/mcp/cli.py, application/tests/mcp_auth_test.py
_login handles OSError by reporting the error and returning 1. A test verifies the reported failure and return status.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: Minimal · up to fb0fe

This change lets MCP login save and refresh tokens on Windows by skipping the POSIX-only permission call. POSIX behavior is unchanged and still fails closed, and the login command now reports storage errors cleanly. No concrete merge-blocking defect was found. A native Windows run would be a useful follow-up check.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "Fix MCP token file save on Windows" matches the main change: the file-backed MCP token store now skips fchmod on Windows so saves succeed there. It is specific and concise, and it names the…
Linked Issues check Passed Issue #1224 requires that MCP login store the refresh token with the file backend on Windows, that POSIX keep fail-closed mode-setting, and that the login CLI report token-store OSError cleanly. The r…
Out of Scope Changes check Passed The whole-PR diff against the merge base changes three files: application/mcp/token_store.py, application/mcp/cli.py, and application/tests/mcp_auth_test.py. The token_store.py and cli.py hunks implem…
Description check Passed The description states the PR purpose: skipping fchmod on Windows in the file-backed MCP refresh-token store, keeping fchmod(0600) with fail-closed behavior on POSIX, and making the login CLI report t…
Full details: Title check

Explanation

The title "Fix MCP token file save on Windows" matches the main change: the file-backed MCP token store now skips fchmod on Windows so saves succeed there. It is specific and concise, and it names the platform and component.

Full details: Linked Issues check

Explanation

Issue #1224 requires that MCP login store the refresh token with the file backend on Windows, that POSIX keep fail-closed mode-setting, and that the login CLI report token-store OSError cleanly. The reviewed diff addresses each point. In application/mcp/token_store.py, save() calls os.fchmod(fd, 0o600) only when sys.platform != 'win32'. On POSIX, an AttributeError or OSError from fchmod still closes the descriptor and raises OSError, so fail-closed behavior is kept. In application/mcp/cli.py, _login() catches (auth.AuthError, OSError), prints 'Login failed: ...', and returns 1. Refresh uses the same save path, so the Windows fix applies there too. The author reports regression tests for these cases in application/tests/mcp_auth_test.py. I did not run those tests. The repository test module could not start in the author's checkout, so the test results are reported but not independently confirmed.

Full details: Out of Scope Changes check

Explanation

The whole-PR diff against the merge base changes three files: application/mcp/token_store.py, application/mcp/cli.py, and application/tests/mcp_auth_test.py. The token_store.py and cli.py hunks implement #1224 directly. The token_store.py hunk also updates the related comment to describe the Windows ACL behavior. The test changes cover the Windows save path, POSIX chmod failure, and the CLI error message, which supports the issue requirements. No unrelated functional change was found in the inspected hunks.

Full details: Description check

Explanation

The description states the PR purpose: skipping fchmod on Windows in the file-backed MCP refresh-token store, keeping fchmod(0600) with fail-closed behavior on POSIX, and making the login CLI report token-store OSError cleanly. It also lists the tests added and the verification run. This matches the changeset (token_store.py, cli.py, mcp_auth_test.py), so the description is related and specific.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: OWASP/OpenCRE
  • Branch: main
  • File: .coderabbit.yml
  • Commit: 6bc7a30
  • Layers: Repository YAML
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 319449ff-6e45-4028-8760-152b49d270db
Commits

Reviewing files that changed from the base of the PR and between 6bc7a30 and fb0fe71.

Files selected for processing: 3

  • application/mcp/cli.py
  • application/mcp/token_store.py
  • application/tests/mcp_auth_test.py

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.

This branch has not been deployed

No deployments
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.

MCP login can't store the token on Windows with the file backend (os.fchmod missing)

1 participant