fix(mcp): preserved native resource URIs and opaque scheme routing

- Native (non-mcp://) resource URIs now pass through byte-for-byte via
  rawHref; slash elision applies only to the legacy mcp:// wrapper, so
  catalog://root/ style URIs match exact-equality server lookups.
- resources/templates/list failure no longer discards a successful
  resources/list (Promise.allSettled; templates retried later).
- Opaque RFC 3986 URIs (urn:doc, custom:item) are recognized by both
  the router and read-cli discovery gates, with drive-path and
  read-selector false positives guarded.
- Review follow-up for PR #6790.
This commit is contained in:
can1357
2026-07-27 16:15:02 +02:00
parent 8c5dc16344
commit 41ce810cff
11 changed files with 175 additions and 17 deletions
+6 -3
View File
@@ -8,6 +8,7 @@
import { getProjectDir } from "@oh-my-pi/pi-utils";
import chalk from "chalk";
import { Settings } from "../config/settings";
import { extractUriScheme } from "../internal-urls/parse";
import { InternalUrlRouter } from "../internal-urls/router";
import { discoverAndLoadMCPTools } from "../mcp/loader";
import { MCPManager } from "../mcp/manager";
@@ -23,9 +24,11 @@ export interface ReadCommandArgs {
}
function shouldDiscoverMcp(path: string): boolean {
const match = path.match(/^([a-z][a-z0-9+.-]*):\/\//i);
if (!match) return false;
const scheme = match[1].toLowerCase();
// MCP resource URIs may be hierarchical (`test://notes`) or opaque
// (`urn:example:document`); `extractUriScheme` recognizes both while
// rejecting Windows drive paths and selector-shaped filesystem inputs.
const scheme = extractUriScheme(path);
if (!scheme) return false;
if (scheme === "mcp") return true;
if (["conflict", "file", "http", "https"].includes(scheme)) return false;
return InternalUrlRouter.instance().getHandler(scheme) === undefined;