mirror of
https://github.com/pacnpal/Roo-Code.git
synced 2025-12-21 04:41:16 -05:00
Incorporate MCP changes (#93)
Co-authored-by: Saoud Rizwan <7799382+saoudrizwan@users.noreply.github.com>
This commit is contained in:
45
webview-ui/src/utils/mcp.ts
Normal file
45
webview-ui/src/utils/mcp.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
import { McpResource, McpResourceTemplate } from "../../../src/shared/mcp"
|
||||
|
||||
/**
|
||||
* Matches a URI against an array of URI templates and returns the matching template
|
||||
* @param uri The URI to match
|
||||
* @param templates Array of URI templates to match against
|
||||
* @returns The matching template or undefined if no match is found
|
||||
*/
|
||||
export function findMatchingTemplate(
|
||||
uri: string,
|
||||
templates: McpResourceTemplate[] = [],
|
||||
): McpResourceTemplate | undefined {
|
||||
return templates.find((template) => {
|
||||
// Convert template to regex pattern
|
||||
const pattern = String(template.uriTemplate)
|
||||
// First escape special regex characters
|
||||
.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)
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds either an exact resource match or a matching template for a given URI
|
||||
* @param uri The URI to find a match for
|
||||
* @param resources Array of concrete resources
|
||||
* @param templates Array of resource templates
|
||||
* @returns The matching resource, template, or undefined
|
||||
*/
|
||||
export function findMatchingResourceOrTemplate(
|
||||
uri: string,
|
||||
resources: McpResource[] = [],
|
||||
templates: McpResourceTemplate[] = [],
|
||||
): McpResource | McpResourceTemplate | undefined {
|
||||
// First try to find an exact resource match
|
||||
const exactMatch = resources.find((resource) => resource.uri === uri)
|
||||
if (exactMatch) return exactMatch
|
||||
|
||||
// If no exact match, try to find a matching template
|
||||
return findMatchingTemplate(uri, templates)
|
||||
}
|
||||
Reference in New Issue
Block a user