{"record":{"id":"8a7d393a2d7be2c5","repo":"gitbutlerapp/gitbutler","slug":"mcp-root-is-not-a-file-uri","errorCode":null,"errorMessage":"MCP root is not a file URI: {}","messagePattern":"MCP root is not a file URI: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but/src/command/mcp/mod.rs","lineNumber":545,"sourceCode":"            }\n        };\n        match open_repository(&path) {\n            Ok(resolved) => return Ok(resolved),\n            Err(err) => failures.push(format!(\"{}: {err:#}\", path.display())),\n        }\n    }\n\n    bail!(\n        \"None of the MCP client's filesystem roots identify a Git repository. {}\",\n        failures.join(\"; \")\n    )\n}\n\nfn root_path(root: &Root) -> Result<PathBuf> {\n    let url = Url::parse(&root.uri)\n        .with_context(|| format!(\"MCP root is not a valid URI: {}\", root.uri))?;\n    url.to_file_path()\n        .map_err(|()| anyhow::anyhow!(\"MCP root is not a file URI: {}\", root.uri))\n}\n\nfn open_repository(repository: &Path) -> Result<ResolvedRepository> {\n    let repository = repository\n        .canonicalize()\n        .with_context(|| format!(\"Could not resolve repository at {}\", repository.display()))?;\n    let ctx = but_ctx::Context::discover(&repository)\n        .with_context(|| format!(\"Could not open repository at {}\", repository.display()))?;\n    let repository = ctx\n        .workdir_or_gitdir()\n        .context(\"Could not determine the repository root\")?\n        .canonicalize()\n        .context(\"Could not resolve the repository root\")?;\n    let name = repository\n        .file_name()\n        .and_then(|name| name.to_str())\n        .unwrap_or(\"repository\")\n        .to_owned();","sourceCodeStart":527,"sourceCodeEnd":563,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/but/src/command/mcp/mod.rs#L527-L563","documentation":"The MCP server converts each client-declared Root into a local filesystem path. After parsing the root's URI, `Url::to_file_path()` fails for any scheme other than `file://`, so the root cannot be mapped onto the local filesystem and this error is raised.","triggerScenarios":"An MCP client sends a `roots/list` entry whose `uri` uses a non-file scheme (e.g., `https://`, `ssh://`, or a custom scheme) or a malformed file URI (e.g., `file:relative/path` without a host/authority), making `to_file_path()` return `Err(())`.","commonSituations":"MCP client configured with remote or virtual roots; IDE clients exposing project roots via http URIs; hand-written MCP configs where the root URI lacks the required `file:///absolute/path` form.","solutions":["Configure the MCP client to declare roots as absolute `file://` URIs (e.g., `file:///home/user/project`).","Inspect the client's root configuration and replace any http/ssh/custom-scheme root with a local directory path.","If a remote root is intentional, mount or sync it locally first and point the root at the local copy."],"exampleFix":"// before (client root config)\n{ \"uri\": \"https://example.com/project\" }\n\n// after\n{ \"uri\": \"file:///home/user/project\" }","handlingStrategy":"type-guard","validationCode":"// client-side, before sending roots\nfor root of roots:\n  if !root.uri.startsWith(\"file:///\") throw new Error(`root must be a file:// URI: ${root.uri}`)","typeGuard":"fn is_file_root(root: &Root) -> bool {\n    Url::parse(&root.uri).map(|u| u.scheme() == \"file\").unwrap_or(false)\n}","tryCatchPattern":"match root_path(root) {\n    Err(e) if e.to_string().contains(\"not a file URI\") =>\n        eprintln!(\"Skipping unsupported root {}\", root.uri),\n    other => other,\n}","preventionTips":["Always declare MCP roots as absolute file:// URIs.","Validate root URIs in client config at startup.","Sync remote/virtual roots to a local path before exposing them."],"tags":["mcp","uri","filesystem"],"backgroundTag":"invalid-url-format","analyzedSha":"58e5313667b857ef39a730e380af31816a7b1768","analyzedAt":"2026-09-18T06:50:32.052Z","contentChangedAt":"2026-09-18T06:50:32.052Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}