MCPcopy Create free account
hub / github.com/modelcontextprotocol/go-sdk / fileRoot

Function fileRoot

mcp/resource.go:150–172  ·  view source on GitHub ↗

fileRoot returns the absolute path for Root.

(root *Root)

Source from the content-addressed store, hash-verified

148
149// fileRoot returns the absolute path for Root.
150func fileRoot(root *Root) (_ string, err error) {
151 defer util.Wrapf(&err, "root %q", root.URI)
152
153 // Convert to absolute file path.
154 rurl, err := url.Parse(root.URI)
155 if err != nil {
156 return "", err
157 }
158 if rurl.Scheme != "file" {
159 return "", errors.New("not a file URI")
160 }
161 if rurl.Path == "" {
162 // A more specific error than the one below, to catch the
163 // common mistake "file://foo".
164 return "", errors.New("empty path")
165 }
166 // We don't want Localize here: we want an absolute path, which is not local.
167 fileRoot := filepath.Clean(filepath.FromSlash(rurl.Path))
168 if !filepath.IsAbs(fileRoot) {
169 return "", errors.New("not an absolute path")
170 }
171 return fileRoot, nil
172}
173
174// Matches reports whether the receiver's uri template matches the uri.
175func (sr *serverResourceTemplate) Matches(uri string) bool {

Callers 2

fileRootsFunction · 0.85
TestFileRootFunction · 0.85

Calls 1

WrapfFunction · 0.92

Tested by 1

TestFileRootFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…