Skip to content

Fix Windows MCP spawn/DNS issues; add remote file rename support - #1

Open
15312618259 wants to merge 1 commit into
CodeSentryAI:mainfrom
15312618259:windows-compat-and-file-rename
Open

Fix Windows MCP spawn/DNS issues; add remote file rename support#1
15312618259 wants to merge 1 commit into
CodeSentryAI:mainfrom
15312618259:windows-compat-and-file-rename

Conversation

@15312618259

Copy link
Copy Markdown

-# PR: Windows compatibility fixes + remote file rename support

Summary

This PR fixes two Windows-specific breakages and adds remote file rename support
(the upstream SDK only wraps renameFolder). All changes are additive; no existing
behavior is altered except how the MCP server spawns the CLI child process.

1. Fix: MCP server fails with ENOENT on Windows

mcp-server.js spawns the CLI via execFileSync('cloud189', ...). On Windows, npm
installs cloud189 as a .cmd shim, which execFileSync cannot resolve — every MCP
tool call fails with ENOENT.

Fix (packages/mcp/src/mcp-server.js): resolve the CLI's real JS entry
via require.resolve('@codesentryai/cloud189/package.json') and run it with
execFileSync(process.execPath, [CLI_JS, ...]).

2. Fix: HTTP 400 InvalidSessionKey - check ip error on dual-stack networks

Tianyi Cloud (Cloud189) binds the sessionKey to the egress IP used at login. On
dual-stack (IPv4/IPv6) networks, Node may resolve the API host to an IPv6 address
while the login request went out over IPv4, so every subsequent API call returns
HTTP 400 InvalidSessionKey - check ip error.

Fix (packages/mcp/src/mcp-server.js): launch every CLI child process
with --dns-result-order=ipv4first, so API requests use the same address family as
login. This is enforced in the spawn args, not via env vars, so it cannot be lost.

3. Feature: rename remote files

The SDK only wraps folder rename. This PR adds file rename across all layers:

  • packages/cli/src/remote.js: new renameRemoteFile(client, fileId, fileName)
    calling the official open API endpoint POST {API_URL}/open/file/renameFile.action
    with form { destFileName, fileId } (API_URL from cloud189-sdk/dist/const).
  • packages/cli/src/cli.js: new CLI command rename-file <remoteFileId> <newName>
    with --json output support.
  • packages/cli/src/agent-safe.js: rename-file added to DANGEROUS_COMMANDS
    so the existing agent-mode confirmation flow covers it.

4. MCP: four new destructive/rename tools (guarded)

packages/mcp/src/mcp-server.js registers:
cloud189_rename_folder, cloud189_rename_file, cloud189_rm, cloud189_mv.

All four require an explicit confirm: true argument; the new assertConfirmed()
helper refuses execution otherwise and instructs the caller to preview with
cloud189_plan first.

Files changed

File Change
packages/cli/src/remote.js + renameRemoteFile(), + export
packages/cli/src/cli.js + rename-file command
packages/cli/src/agent-safe.js + rename-file in DANGEROUS_COMMANDS
packages/mcp/src/mcp-server.js Windows-safe CLI spawn (IPv4-first), + 4 guarded tools

Testing

Tested on Windows 11 (Git Bash + Node 22) against a real account:

  • login-qr → QR login OK; status --json reports session valid (previously
    HTTP 400 InvalidSessionKey on every call after login).
  • MCP tools: status, roots, quota, list, search all return JSON via the
    patched server (previously ENOENT).
  • rename-file <id> <newName> --json{ ok: true, fileId, newName }; rename
    verified in the web UI.
  • Destructive flow smoke test: mkdir-safeupload-saferename-file
    mvrename-folderrm (cleanup) — all return status 4 (task success);
    MCP rm/mv refuse without confirm: true.
  • Large export: tree -11 --json on a 4.29 TB / ~175k-entry account completed in
    ~32 minutes (no code change needed; noted for docs only).

Notes for reviewers

  • The renameFile.action endpoint is the official open API used by Tianyi Cloud's
    own web client; no reverse-engineered private endpoint is involved.
  • The IPv4-first flag matches the behavior of NODE_OPTIONS=--dns-result-order=ipv4first
    but is pinned in spawn args so the MCP server works regardless of the host env.

- mcp-server: resolve CLI JS entry via require.resolve instead of spawning
  the npm .cmd shim (fixes ENOENT on Windows)
- mcp-server: launch CLI child processes with --dns-result-order=ipv4first
  (fixes HTTP 400 InvalidSessionKey 'check ip error' on dual-stack networks)
- cli/remote: add renameRemoteFile via official open API renameFile.action
- cli: new 'rename-file <id> <newName>' command with --json output
- agent-safe: add 'rename-file' to DANGEROUS_COMMANDS
- mcp-server: add guarded cloud189_rename_folder/_file/rm/mv tools
  (require confirm: true, preview via cloud189_plan)
@15312618259

Copy link
Copy Markdown
Author

@CodeSentryAI Happy to adjust anything — all changes are tested on a real 4.29 TB account on Windows 10.

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