File tree Expand file tree Collapse file tree
kotlin-sdk-server/src/commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/server Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -79,17 +79,23 @@ public class UriTemplateFeatureKey(override val key: String) :
7979 // - Query parameters are ignored
8080 val uriWithoutQueryParameters = this .key.replace(Regex (" \\ {\\ ?[^}]+}" ), " " )
8181
82- val newRegex = Regex (" \\ {(<groupName>[^}*]*)(<wildcard>[*] ?)}" )
82+ var newRegex = Regex (" \\ {(? <groupName>[^}*]*)(? <wildcard>\\ * ?)}" )
8383 .replace(uriWithoutQueryParameters) { matchResult ->
8484 val groupName = matchResult.groups[" groupName" ]?.value
8585 checkNotNull(groupName) { " Invalid URI template: $this " }
8686 groups.add(groupName)
87- if (matchResult.groups[" wildcard" ]?.value != null ) {
87+ if (matchResult.groups[" wildcard" ]?.value?.isNotEmpty() == true ) {
8888 " (?<$groupName >.+)"
8989 } else {
90- " (?<$groupName >[^/]* )"
90+ " (?<$groupName >[^/]+ )"
9191 }
9292 }
93+ newRegex =
94+ if (newRegex.endsWith(' /' )) {
95+ " ^$newRegex ?$"
96+ } else {
97+ " ^$newRegex /?$"
98+ }
9399 this .value = Regex (newRegex)
94100 }
95101
@@ -99,7 +105,9 @@ public class UriTemplateFeatureKey(override val key: String) :
99105 val matchGroups = value.matchEntire(input)?.groups
100106 return groups.mapNotNull { groupName ->
101107 val groupValue = matchGroups?.get(groupName)?.value
102- if (groupValue != null ) {
108+ if (groupValue?.endsWith(' /' ) == true ) {
109+ groupName to groupValue.removeSuffix(" /" )
110+ } else if (groupValue != null ) {
103111 groupName to groupValue
104112 } else {
105113 null
You can’t perform that action at this time.
0 commit comments