@@ -16,6 +16,7 @@ import ListPane from "./ListPane";
16
16
import { useEffect , useState } from "react" ;
17
17
import { useCompletionState } from "@/lib/hooks/useCompletionState" ;
18
18
import JsonView from "./JsonView" ;
19
+ import { UriTemplate } from "@modelcontextprotocol/sdk/shared/uriTemplate.js" ;
19
20
20
21
const ResourcesTab = ( {
21
22
resources,
@@ -79,10 +80,10 @@ const ResourcesTab = ({
79
80
template : string ,
80
81
values : Record < string , string > ,
81
82
) : string => {
82
- return template . replace (
83
- / { ( [ ^ } ] + ) } / g ,
84
- ( _ , key ) => values [ key ] || `{ ${ key } }` ,
85
- ) ;
83
+ console . log ( "Expanding template:" , template , "with values:" , values ) ;
84
+ const result = new UriTemplate ( template ) . expand ( values ) ;
85
+ console . log ( "Filled template:" , result ) ;
86
+ return result ;
86
87
} ;
87
88
88
89
const handleTemplateValueChange = async ( key : string , value : string ) => {
@@ -240,7 +241,8 @@ const ResourcesTab = ({
240
241
{ selectedTemplate . uriTemplate
241
242
. match ( / { ( [ ^ } ] + ) } / g)
242
243
?. map ( ( param ) => {
243
- const key = param . slice ( 1 , - 1 ) ;
244
+ // Remove leading operator characters (?, &, /, #, ;, +, .) from variable name
245
+ const key = param . slice ( 1 , - 1 ) . replace ( / ^ [ ? & / # ; + . ] / , "" ) ;
244
246
return (
245
247
< div key = { key } >
246
248
< Label htmlFor = { key } > { key } </ Label >
0 commit comments