feat: Add SFTP file transfer tools (upload-file, download-file)#38
Open
mario-chamuty wants to merge 4 commits into
Open
feat: Add SFTP file transfer tools (upload-file, download-file)#38mario-chamuty wants to merge 4 commits into
mario-chamuty wants to merge 4 commits into
Conversation
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
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
upload-fileanddownload-fileMCP tools using the ssh2 SFTP subsystemgetSftp()method toSSHConnectionManagerfor creating SFTP sessionsensureConnectionManager()helper, deduplicating connection init logic fromexecandsudo-executf8(text) andbase64(binary) encoding for file contentDetails
Both tools reuse the existing persistent SSH connection and include timeout handling consistent with the
exectool.upload-fileacceptsremotePath,content, and optionalencoding(defaults toutf8). Writes file content via SFTPwriteFile.download-fileacceptsremotePathand optionalencoding. Reads file content via SFTPreadFileand returns it as text or base64.Test plan
test/sftp.test.tscovering:tsc --noEmit