Repository navigation
fix(core): check resource URI depth before splitting - #1175
Open
Christiansada wants to merge 1 commit into
Open
Christiansada wants to merge 1 commit into
Christiansada wants to merge 1 commit into
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Updates #1084.
PathSegmentTemplateMatcher.match()splits an incoming URI into a list before rejecting it for exceedingmaxDepth. Count separators after the existing normalization and trimming steps, then reject over-depth paths before allocating the segment list. Matching results and public APIs remain unchanged.The server tie-breaker should stay:
test://items/{id}/{id}andtest://items/{first}/{second}matchtest://items/42/42with equal scores but one versus two distinct captured keys. The new in-memory client/server test demonstrates this counterexample to the issue's second premise. Temporarily deleting the tie-breaker made it fail withexpected:<repeated> but was:<distinct>; it was restored before final validation.Validation
macOS 26.6.2 arm64, Temurin 21.0.13+9, Gradle 9.8.2; base
61500503990410e1015e35a602c3d2aefe1bdcaf:--rerun-tasks.ktlintCheck, corecheckKotlinAbi(including multiplatform comparison), andgit diff --checkpass.detektMainJvmexits successfully but reports 110 compiler-analysis errors on both unchanged base and fixed source, limiting its analysis accuracy../gradlew :kotlin-sdk-core:jvmTest :integration-test:jvmTest --tests '*ServerResourceTemplateTest' --rerun-tasks ./gradlew :kotlin-sdk-core:ktlintCheck :integration-test:ktlintCheck :kotlin-sdk-core:checkKotlinAbiLocal allocation evidence
A separate JVM probe measured mean current-thread allocated bytes over 20 calls after 30 warmups:
These are measurements in the instrumented test environment, not throughput, peak-heap, or end-to-end results. The probe uses
maxDepth=2; both inputs fit the normal 2,048-character length limit. Behavioral tests pass before and after, as expected for an allocation improvement.Accepted paths gain a separator-counting pass. Normalization/trimming can still allocate, and the default URI length limit already bounds inputs. Full multiplatform runtime tests, the whole-repository JVM suite and external conformance were not run.
Manual allocation probe and reproduction
Temporarily save the following as
kotlin-sdk-core/src/jvmTest/kotlin/io/modelcontextprotocol/kotlin/sdk/utils/PathAllocationProbeTest.ktin isolated base and PR checkouts, using JDK 21. Run each with a separate output filename:MCP_ALLOCATION_PROBE_OUTPUT=/tmp/mcp-1084-allocation.txt ./gradlew :kotlin-sdk-core:jvmTest --tests '*PathAllocationProbeTest' --rerun-tasks cat /tmp/mcp-1084-allocation.txtRemove the temporary file afterward. It is a diagnostic probe, not a CI allocation threshold.