Skip to content

McpServerToolCreateOptions miss MarshalResult option. #1602

Open

Description

@truelife2

Is your feature request related to a problem? Please describe.
i need MarshalResult for AIFunctionFactoryOptions, but the CreateAIFunctionFactoryOptions assign the MarshalResult=new ValueTask(result).
i without any solution to reset it, i just can to create a AIFunction,then use the AIFunction to create McpServerTool.

but i will loss many settings from DeriveOptions and CreateAIFunctionFactoryOptions(private methods).

Describe the solution you'd like
please add a MarhsalResult option in McpServerToolCreateOptions, then i can initialize the AIFunctionFactoryOptions.MarshalResult.

or add a Action< AIFunctionFactoryOptions > initailizeAIFunctionOptions, then call after CreateAIFunctionFactoryOptions, give me a chance to update the aifunction options.

        public new static AIFunctionMcpServerResource Create(MethodInfo method, object? target, McpServerResourceCreateOptions? options
            , Action<AIFunctionFactoryOptions> initializeAIFunctionFactoryOptions = null)
        {
            Throw.IfNull(method, "method");
            options = DeriveOptions(method, options);

            var aioptions = CreateAIFunctionFactoryOptions(method, options);
            initializeAIFunctionFactoryOptions?.Invoke(aioptions);

            return Create(AIFunctionFactory.Create(method, target, aioptions), options);
        }
        public new static AIFunctionMcpServerTool Create(MethodInfo method, object? target, McpServerToolCreateOptions? options
            , Action<AIFunctionFactoryOptions> initializeAIFunctionFactoryOptions = null)
        {
            Throw.IfNull(method, "method");
            options = DeriveOptions(method, options);

            var aioptions = CreateAIFunctionFactoryOptions(method, options);
            initializeAIFunctionFactoryOptions?.Invoke(aioptions);

            return Create(AIFunctionFactory.Create(method, target, aioptions), options);
        }`
        public new static AIFunctionMcpServerPrompt Create(MethodInfo method, object? target, McpServerPromptCreateOptions? options
            , Action<AIFunctionFactoryOptions> initializeAIFunctionFactoryOptions = null)
        {
            Throw.IfNull(method, "method");
            options = DeriveOptions(method, options);

            var aioptions = CreateAIFunctionFactoryOptions(method, options);
            initializeAIFunctionFactoryOptions?.Invoke(aioptions);

            return Create(AIFunctionFactory.Create(method, target, aioptions), options);
        }

Describe alternatives you've considered
currently , i just can use reflection to invoke DeriveOptions and CreateAIFunctionFactoryOptions,
but this was not stable in the future version. please add a standard MarshalResult options for my feature.

                    var createoptions = new McpServerToolCreateOptions()
                    {
                        Name = mcpname,
                        SerializerOptions = serializeroptions,
                    };
                    createoptions = (McpServerToolCreateOptions)DummyInstance.Value.Tool_DeriveOptions.Invoke(null, [mcpmethod, createoptions]);

                    var aifuncoptions = (AIFunctionFactoryOptions)DummyInstance.Value.Tool_CreateAIFunctionFactoryOptions.Invoke(null, [mcpmethod, createoptions]);
                    aifuncoptions.MarshalResult = OnToolMarshalResult;

                    var aifunc = AIFunctionFactory.Create(mcpmethod, instance, aifuncoptions);
                    var tool = McpServerTool.Create(aifunc, createoptions);
                    log.Info($"McpTool 已建立 - tool:{tool}。\r\n{mcpmethod}");

                    tools.Add(tool);

Activity

  1. added
    ready for workHas enough information to start
    P2Moderate issues, valuable feature requests
    on Jul 27, 2026
  2. added this to the 2.x milestone on Jul 27, 2026
  3. andyst-dev commented on Jul 28, 2026

    @andyst-dev

    I would like to work on this. I plan to add a focused MarshalResult delegate to McpServerToolCreateOptions, thread it into AIFunctionFactoryOptions, preserve it when deriving options, and add a regression test covering custom result marshaling. I will keep the change limited to tools as requested.

  4. jstar0 commented on Sep 13, 2026

    @jstar0
    Contributor

    Picking this up — the previous attempt (#1761) was closed for lack of review rather than technical concerns, and its approach still looks right, so I plan to resubmit it with the narrow shape:

    • Add a MarshalResult delegate property (same shape as AIFunctionFactoryOptions.MarshalResult) to McpServerToolCreateOptions, nullable and defaulting to the current identity pass-through.
    • Thread it through DeriveOptions/Clone() and into CreateAIFunctionFactoryOptions, so tools created from MethodInfo can customize result marshaling without reimplementing private option-derivation logic.
    • Regression tests in McpServerToolTests covering a custom marshaller's transformed result and the unchanged default behavior.

    I'm deliberately not touching McpServerPromptCreateOptions/McpServerResourceCreateOptions since the request is tool-specific; happy to extend for symmetry later if maintainers want it. Will open a PR shortly.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Moderate issues, valuable feature requestsenhancementNew feature or requestready for workHas enough information to start

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions