Skip to content

feat(dsl): add result DSL builders#530

Draft
kpavlov wants to merge 5 commits intomainfrom
kpavlov/extend-dsl
Draft

feat(dsl): add result DSL builders#530
kpavlov wants to merge 5 commits intomainfrom
kpavlov/extend-dsl

Conversation

@kpavlov
Copy link
Contributor

@kpavlov kpavlov commented Feb 17, 2026

Add result DSL builders and tests

  • 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

Build also results with DSL

How Has This Been Tested?

Unit test

Breaking Changes

No

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Tests update
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

@kpavlov kpavlov added the enhancement New feature or request label Feb 17, 2026
@kpavlov kpavlov requested a review from devcrocod February 17, 2026 12:39
@kpavlov kpavlov added the tests label Feb 17, 2026
@kpavlov kpavlov marked this pull request as ready for review February 17, 2026 12:39
@kpavlov kpavlov requested review from e5l February 17, 2026 13:23
@kpavlov kpavlov added this to the 0.9 milestone Feb 17, 2026
@kpavlov kpavlov changed the title feat(dsl): add result DSL builders for testing and serialization validation feat(dsl): add result DSL builders Feb 17, 2026
Copy link
Contributor

@e5l e5l left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only thing I'm not sure about is having DSL functions on the top level. Users will receive the top-level functions buildListResourcesResult for the whole application. While it is fine for stdlib, doing this in other library will bloat top-level scope.

Should we think about scoping the DSL to specific use-sites or anchor classes?

@devcrocod, what do you think?

@kpavlov
Copy link
Contributor Author

kpavlov commented Feb 18, 2026

Should we think about scoping the DSL to specific use-sites or anchor classes?

Agree
But it might require merging #515 first where we introduce handler context object as a receiver. It will be a perfect place, but I am not sure about the visibility yet, as server handler context lives in the server module.

What if we try addressing it in the follow up PR, after #515?

@kpavlov
Copy link
Contributor Author

kpavlov commented Feb 18, 2026

Actually, I'm not sure we should be very restrictive in letting users to build data classes

@devcrocod
Copy link
Contributor

The only thing I'm not sure about is having DSL functions on the top level. Users will receive the top-level functions buildListResourcesResult for the whole application. While it is fine for stdlib, doing this in other library will bloat top-level scope.

That’s true. Even in the stdlib this pattern is used rarely. Given that we already have quite a few objects, relying on a shared prefix would indeed make the api awkward to use

Should we think about scoping the DSL to specific use-sites or anchor classes?

I’ve thought about that as well, but introducing contextual scoping would require a more detailed design

…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.
@kpavlov kpavlov marked this pull request as draft February 19, 2026 12:12
@kpavlov kpavlov marked this pull request as draft February 19, 2026 12:12
@e5l e5l removed their request for review March 9, 2026 13:47
@kpavlov kpavlov modified the milestones: 0.9, 0.11 Mar 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants