Skip to content

feat: Add SFTP file transfer tools (upload-file, download-file)#38

Open
mario-chamuty wants to merge 4 commits into
tufantunc:mainfrom
mario-chamuty:feature/sftp-file-transfer
Open

feat: Add SFTP file transfer tools (upload-file, download-file)#38
mario-chamuty wants to merge 4 commits into
tufantunc:mainfrom
mario-chamuty:feature/sftp-file-transfer

Conversation

@mario-chamuty

@mario-chamuty mario-chamuty commented Mar 10, 2026

Copy link
Copy Markdown

Summary

  • Add upload-file and download-file MCP tools using the ssh2 SFTP subsystem
  • Add getSftp() method to SSHConnectionManager for creating SFTP sessions
  • Extract shared ensureConnectionManager() helper, deduplicating connection init logic from exec and sudo-exec
  • Support both utf8 (text) and base64 (binary) encoding for file content

Details

Both tools reuse the existing persistent SSH connection and include timeout handling consistent with the exec tool.

upload-file accepts remotePath, content, and optional encoding (defaults to utf8). Writes file content via SFTP writeFile.

download-file accepts remotePath and optional encoding. Reads file content via SFTP readFile and returns it as text or base64.

Test plan

  • 13 new integration tests in test/sftp.test.ts covering:
    • SFTP session creation and error handling
    • Text and binary file upload
    • File overwrite, empty file, non-existent directory error
    • File download, non-existent file error, UTF-8 special characters
    • Upload/download round-trip with fresh sessions
    • Large file transfer (100KB)
  • All 63 tests pass (13 new + 50 existing)
  • TypeScript compiles cleanly with tsc --noEmit

Add upload-file and download-file MCP tools using the ssh2 SFTP subsystem.
Supports utf8 text and base64-encoded binary content. Includes getSftp()
method on SSHConnectionManager and ensureConnectionManager() helper.
Deduplicate connection initialization logic from exec and sudo-exec into
a shared ensureConnectionManager() helper. Remove redundant .optional()
from encoding schema defaults. Use returned manager instead of global.
- Add --maxFileSize flag (default 10MB, "none" to disable) to prevent
  OOM from downloading huge files via download-file
- Validate remotePath is non-empty and absolute (starts with /) in both
  upload-file and download-file tools
- Check file size via sftp.stat() before calling readFile
@mario-chamuty mario-chamuty marked this pull request as ready for review March 10, 2026 16:25
…TP tools

Enrich upload-file and download-file tool descriptions with usage
guidance for AI agents (encoding choices, parent dir requirements,
file size limits). Document new tools and --maxFileSize parameter
in README.
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