Repository navigation
McpServerToolCreateOptions miss MarshalResult option. #1602
Description
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
andyst-dev commentedon Jul 28, 2026
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.
jstar0 commentedon Sep 13, 2026
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:
MarshalResultdelegate property (same shape asAIFunctionFactoryOptions.MarshalResult) toMcpServerToolCreateOptions, nullable and defaulting to the current identity pass-through.DeriveOptions/Clone()and intoCreateAIFunctionFactoryOptions, so tools created fromMethodInfocan customize result marshaling without reimplementing private option-derivation logic.McpServerToolTestscovering a custom marshaller's transformed result and the unchanged default behavior.I'm deliberately not touching
McpServerPromptCreateOptions/McpServerResourceCreateOptionssince the request is tool-specific; happy to extend for symmetry later if maintainers want it. Will open a PR shortly.