浏览代码

fix(mcp): prevent resource key collisions (#33596)

Aiden Cline 4 月之前
父节点
当前提交
6c12c32fb1
共有 1 个文件被更改,包括 3 次插入 和 1 次删除
  1. 3 1
      packages/opencode/src/mcp/catalog.ts

+ 3 - 1
packages/opencode/src/mcp/catalog.ts

@@ -100,9 +100,11 @@ export function fetch<T extends { name: string }>(
     ),
     Effect.map((items) => {
       const sanitizedClient = sanitize(clientName)
+      // Escape both the separator and escape marker so `server:uri` keys remain unambiguous.
+      const resourceClient = clientName.replaceAll("%", "%25").replaceAll(":", "%3A")
       return Object.fromEntries(
         items.map((item) => [
-          key ? clientName + ":" + key(item) : sanitizedClient + ":" + sanitize(item.name),
+          key ? resourceClient + ":" + key(item) : sanitizedClient + ":" + sanitize(item.name),
           { ...item, client: clientName },
         ]),
       )