Skip to content

Add custom tool result marshaling - #1761

Open
andyst-dev wants to merge 1 commit into
modelcontextprotocol:mainfrom
andyst-dev:feat/tool-marshal-result
Open

Add custom tool result marshaling#1761
andyst-dev wants to merge 1 commit into
modelcontextprotocol:mainfrom
andyst-dev:feat/tool-marshal-result

Conversation

@andyst-dev

Copy link
Copy Markdown

Summary

  • add a MarshalResult delegate to McpServerToolCreateOptions
  • pass the custom delegate to AIFunctionFactoryOptions while preserving the existing pass-through default
  • preserve the delegate when deriving tool options
  • add a regression test covering the result value, declared return type, cancellation token, and transformed tool response

Motivation and context

This lets reflection-created MCP tools customize AIFunction result marshaling without recreating the SDK's private option-derivation logic.

Closes #1602.

Validation

  • dotnet test tests/ModelContextProtocol.Tests/ModelContextProtocol.Tests.csproj --framework net10.0 --filter FullyQualifiedName~SupportsCustomResultMarshaling — 1 passed
  • dotnet test tests/ModelContextProtocol.Tests/ModelContextProtocol.Tests.csproj --framework net10.0 --filter "Execution!=Manual" — 2,335 passed, 3 skipped
  • make generate-docs — Release build and DocFX succeeded with 0 warnings and 0 errors
  • git diff --check

Breaking changes

None. The new option is nullable and the existing pass-through behavior remains the default.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

McpServerToolCreateOptions miss MarshalResult option.

1 participant