refactor(dsl)!: Replace buildXxx functions with TypeName { } companion invoke pattern#534
Draft
refactor(dsl)!: Replace buildXxx functions with TypeName { } companion invoke pattern#534
Conversation
b5683cc to
62c8fc3
Compare
…dation - Introduced `ToolsResultDslTest` and `PromptsResultDslTest` to test result builders for tool and prompt operations. - Added `buildCompleteResult` and `buildInitializeResult` for server-side result creation. - Updated API surface to include result DSL functionality.
…SL across integration tests - Updated integration tests to use the `buildCallToolResult` DSL for constructing results, improving clarity and reducing boilerplate. - Added `@OptIn(ExperimentalMcpApi::class)` annotations to test files requiring experimental API. - Refactored delay handling in tests to streamline coroutine usage.
- Added new test cases for `CallToolResult`, `ListResourcesResult`, and `ReadResourceResult` to validate error handling, structured content, and metadata processing. - Improved coverage for resource and template handling with additional edge cases for mixed-field resources and pagination.
- Added `.toList()` defensive copying in `build()` methods to ensure immutability of returned collections. - Enhanced documentation for CallToolResult, metadata, and field nullability to align with MCP serialization conventions.
…ke` for cleaner DSL usage - Deprecated `build*Request` functions across DSLs in favor of the `Companion.invoke` operator. - Updated all documentation, examples, and tests to reflect the new syntax. - Improved clarity, reduced redundancy, and streamlined API usage.
62c8fc3 to
0f99c5a
Compare
…anion.invoke` and update tests - Added deprecation annotations to `build*Request` methods across all relevant DSLs with migration guidance. - Updated associated test cases and documentation to use the new `Companion.invoke` syntax. - Extract subscription DSLs from resources.dsl.kt into subscriptions.dsl.kt
devcrocod
requested changes
Feb 19, 2026
Contributor
devcrocod
left a comment
There was a problem hiding this comment.
Please avoid using invoke, especially on a companion object
it resolves very badly
Contributor
|
I think we should hold a design meeting on this |
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.
Replace buildXxx functions with TypeName { } companion invoke pattern
Replace top-level
buildXxx { }DSL entry-point functions withTypeName.Companion.invokeoperators across DSL filesCall sites now read
CallToolResult { ... }instead ofbuildCallToolResult { ... }, which reads more naturally and avoids top-level namespace pollution for library usersUpdate all test and integration files to use the new syntax. Kept old tests for deprecated methods.
Introduced ToolsResultDslTest and PromptsResultDslTest to test result builders for tool and prompt operations.
Added buildCompleteResult and buildInitializeResult for server-side result creation.
Updated API surface to include result DSL functionality.
Added new test cases for CallToolResult, ListResourcesResult, and ReadResourceResult to validate error handling, structured content, and metadata processing.
Improved coverage for resource and template handling with additional edge cases for mixed-field resources and pagination
Updated integration tests to use the buildCallToolResult DSL for constructing results, improving clarity and reducing boilerplate. Added @OptIn(ExperimentalMcpApi::class) annotations to test files requiring experimental API.
Refactored delay handling in tests to streamline coroutine usage.
Motivation and Context
Top-level
buildXxxfunctions bloat the global scope for every user of the library. Scoping DSL entry points to companion objects (TypeName { }) is idiomatic Kotlin — consistent with how buildList, buildMap etc. work in stdlib, but anchored to a type rather than a free function.Incorporates chandes from #530
How Has This Been Tested?
Unit/integration tests
Breaking Changes
Yes, DSL shape has changed
Types of changes
Checklist
Additional context
See discussion from #530