Skip to content

feat(server): add MarshalResult to McpServerToolCreateOptions - #1874

Open
jstar0 wants to merge 1 commit into
modelcontextprotocol:mainfrom
jstar0:feat/1602-tool-marshal-result-option
Open

feat(server): add MarshalResult to McpServerToolCreateOptions#1874
jstar0 wants to merge 1 commit into
modelcontextprotocol:mainfrom
jstar0:feat/1602-tool-marshal-result-option

Conversation

@jstar0

@jstar0 jstar0 commented Sep 13, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Adds a MarshalResult delegate property to McpServerToolCreateOptions, matching the shape of AIFunctionFactoryOptions.MarshalResult.
  • Threads the delegate through option cloning and into CreateAIFunctionFactoryOptions, so tools created from MethodInfo/Delegate can customize result marshaling without reflecting into the private DeriveOptions/CreateAIFunctionFactoryOptions methods.
  • The default remains the existing identity pass-through when the option is unset, so behavior is unchanged unless configured.
  • Regression tests cover a custom marshaller (including the declared result type it receives) and the unchanged default path.

Motivation and context

Closes #1602. Tools created from a method previously had no supported way to set AIFunctionFactoryOptions.MarshalResult; the options class is built internally with a hard-coded pass-through, and the only workaround was invoking private methods via reflection, which is not stable across versions. The previous attempt (#1761) was closed by its author for lack of review rather than technical objections; this PR resubmits the same narrow shape on the current main.

Validation

  • dotnet test tests/ModelContextProtocol.Tests/ModelContextProtocol.Tests.csproj --filter "Execution!=Manual" — 2,361 passed, 3 skipped, 0 failed.
  • dotnet build — 0 warnings, 0 errors.

Breaking changes

None. The new option is nullable and unset by default.

Tools created via McpServerTool.Create from MethodInfo/Delegate could not
customize AIFunctionFactoryOptions.MarshalResult because the factory options
were built internally with an identity pass-through; the only workaround was
reflecting into private DeriveOptions/CreateAIFunctionFactoryOptions methods.

Add a MarshalResult delegate property that is threaded through option cloning
and CreateAIFunctionFactoryOptions, defaulting to the existing identity
pass-through when unset.

Closes modelcontextprotocol#1602
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