File tree Expand file tree Collapse file tree 1 file changed +21
-1
lines changed Expand file tree Collapse file tree 1 file changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ import (
1111 "os/exec"
1212 "path/filepath"
1313 "slices"
14+ "strings"
1415
1516 "github.com/modelcontextprotocol/go-sdk/mcp"
1617 "github.com/pkg/sftp"
@@ -109,6 +110,25 @@ func (ts *ToolSet) TranslateHostPath(hostPath string) (string, error) {
109110 if ! filepath .IsAbs (hostPath ) {
110111 return "" , fmt .Errorf ("expected an absolute path, got a relative path: %q" , hostPath )
111112 }
112- // TODO: make sure that hostPath is mounted
113+ if ! ts .isMounted (hostPath ) {
114+ return "" , fmt .Errorf ("path %q is not mounted" , hostPath )
115+ }
113116 return hostPath , nil
114117}
118+
119+ func (ts * ToolSet ) isMounted (hostPath string ) bool {
120+ for _ , mount := range ts .inst .Config .Mounts {
121+ location := filepath .Clean (mount .Location )
122+ cleanPath := filepath .Clean (hostPath )
123+
124+ if cleanPath == location {
125+ return true
126+ }
127+
128+ rel , err := filepath .Rel (location , cleanPath )
129+ if err == nil && ! strings .HasPrefix (rel , ".." ) && rel != ".." {
130+ return true
131+ }
132+ }
133+ return false
134+ }
You can’t perform that action at this time.
0 commit comments