mirror of
https://github.com/pacnpal/Roo-Code.git
synced 2025-12-20 04:11:10 -05:00
Fixe resource template matching
This commit is contained in:
@@ -794,8 +794,6 @@ export const ChatRowContent = ({
|
||||
{useMcpServer.type === "access_mcp_resource" && (
|
||||
<McpResourceRow
|
||||
item={{
|
||||
// Always use the actual URI from the request
|
||||
uri: useMcpServer.uri || "",
|
||||
// Use the matched resource/template details, with fallbacks
|
||||
...(findMatchingResourceOrTemplate(
|
||||
useMcpServer.uri || "",
|
||||
@@ -806,6 +804,8 @@ export const ChatRowContent = ({
|
||||
mimeType: "",
|
||||
description: "",
|
||||
}),
|
||||
// Always use the actual URI from the request
|
||||
uri: useMcpServer.uri || "",
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
|
||||
@@ -5,8 +5,8 @@ type McpResourceRowProps = {
|
||||
}
|
||||
|
||||
const McpResourceRow = ({ item }: McpResourceRowProps) => {
|
||||
const isTemplate = "uriTemplate" in item
|
||||
const uri = isTemplate ? item.uriTemplate : item.uri
|
||||
const hasUri = "uri" in item
|
||||
const uri = hasUri ? item.uri : item.uriTemplate
|
||||
|
||||
return (
|
||||
<div
|
||||
|
||||
@@ -12,14 +12,12 @@ export function findMatchingTemplate(
|
||||
): McpResourceTemplate | undefined {
|
||||
return templates.find((template) => {
|
||||
// Convert template to regex pattern
|
||||
const pattern = template.uriTemplate
|
||||
// Replace {param} with ([^/]+) to match any non-slash characters
|
||||
.replace(/\{([^}]+)\}/g, "([^/]+)")
|
||||
// Escape special regex characters except the ones we just added
|
||||
const pattern = String(template.uriTemplate)
|
||||
// First escape special regex characters
|
||||
.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")
|
||||
// Un-escape the capturing groups we added
|
||||
.replace(/\\\(/g, "(")
|
||||
.replace(/\\\)/g, ")")
|
||||
// Then replace {param} with ([^/]+) to match any non-slash characters
|
||||
// We need to use \{ and \} because we just escaped them
|
||||
.replace(/\\\{([^}]+)\\\}/g, "([^/]+)")
|
||||
|
||||
const regex = new RegExp(`^${pattern}$`)
|
||||
return regex.test(uri)
|
||||
|
||||
Reference in New Issue
Block a user