Skip to content

Update Microsoft.Extensions.AI version & expose JSON configuration on McpServerResourceCreateOptions #511

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 13, 2025

Conversation

sbomer
Copy link
Contributor

@sbomer sbomer commented Jun 12, 2025

Per #357 (comment), this should fix #357.

@eiriktsarpalis
Copy link
Member

Is there any chance you could add a test validating that this is indeed fixed?

@stephentoub
Copy link
Contributor

Updating the version is fine and good (we need to anyway for other reasons), but...

Are you sure this impacts the cited issue? Wasn't that fix in the 9.5 version already?

@sbomer
Copy link
Contributor Author

sbomer commented Jun 12, 2025

Hmm, actually it looks like the mentioned fix was already in 9.5.0: dotnet/extensions@v9.4.0...v9.5.0.

Confirmed that updating to the latest version of ModelContextProtocol fixed the issue for me, so I think #357 is fixed already.

@stephentoub
Copy link
Contributor

stephentoub commented Jun 12, 2025

@eiriktsarpalis, this is failing with errors like:

Message: 
System.NotSupportedException : JsonTypeInfo metadata for type 'ModelContextProtocol.Protocol.PromptMessage[]' was not provided by TypeInfoResolver of type '[ModelContextProtocol.McpJsonUtilities+JsonContext, Microsoft.Extensions.AI.AIJsonUtilities+JsonContext]'. If using source generation, ensure that all root types passed to the serializer have been annotated with 'JsonSerializableAttribute', along with any types that might be serialized polymorphically.

  Stack Trace: 
ThrowHelper.ThrowNotSupportedException_NoMetadataForType(Type type, IJsonTypeInfoResolver resolver)
JsonSerializerOptions.GetTypeInfoInternal(Type type, Boolean ensureConfigured, Nullable`1 ensureNotNull, Boolean resolveIfMutable, Boolean fallBackToNearestAncestorType)
JsonSchemaExporter.GetJsonSchemaAsNode(JsonSerializerOptions options, Type type, JsonSchemaExporterOptions exporterOptions)
AIJsonUtilities.CreateJsonSchemaCore(Type type, String parameterName, String description, Boolean hasDefaultValue, Object defaultValue, JsonSerializerOptions serializerOptions, AIJsonSchemaCreateOptions inferenceOptions)
AIJsonUtilities.CreateJsonSchema(Type type, String description, Boolean hasDefaultValue, Object defaultValue, JsonSerializerOptions serializerOptions, AIJsonSchemaCreateOptions inferenceOptions)
ReflectionAIFunctionDescriptor.ctor(DescriptorKey key, JsonSerializerOptions serializerOptions)
ReflectionAIFunctionDescriptor.GetOrCreate(MethodInfo method, AIFunctionFactoryOptions options)
ReflectionAIFunction.Build(MethodInfo method, Object target, AIFunctionFactoryOptions options)
AIFunctionFactory.Create(MethodInfo method, Object target, AIFunctionFactoryOptions options)
AIFunctionMcpServerPrompt.Create(MethodInfo method, Object target, McpServerPromptCreateOptions options) line 39
AIFunctionMcpServerPrompt.Create(Delegate method, McpServerPromptCreateOptions options) line 24
McpServerPrompt.Create(Delegate method, McpServerPromptCreateOptions options) line 161
McpServerPromptTests.CanReturnPromptMessages() line 212
--- End of stack trace from previous location ---

Any idea what changed in Microsoft.Extensions.AI.Abstractions that would have affected this? I'm concerned we had an unexpected fallout from something.

@stephentoub
Copy link
Contributor

This is also failing:

  Message: 
System.InvalidOperationException : The node must be of type 'JsonObject'.

  Stack Trace: 
ThrowHelper.ThrowInvalidOperationException_NodeWrongType(ReadOnlySpan`1 supportedTypeNames)
JsonNode.AsObject()
JsonNode.set_Item(String propertyName, JsonNode value)
<>c.<SupportsSchemaCreateOptions>b__15_2(AIJsonSchemaCreateContext context, JsonNode node) line 327
<>c__DisplayClass32_0.<CreateJsonSchemaCore>g__TransformSchemaNode|0(JsonSchemaExporterContext schemaExporterContext, JsonNode schema)
JsonSchema.<ToJsonNode>g__CompleteSchema|100_0(JsonNode schema, <>c__DisplayClass100_0&)
JsonSchema.ToJsonNode(JsonSchemaExporterOptions options)
JsonSchema.ToJsonNode(JsonSchemaExporterOptions options)
JsonSchemaExporter.GetJsonSchemaAsNode(JsonTypeInfo typeInfo, JsonSchemaExporterOptions exporterOptions)
JsonSchemaExporter.GetJsonSchemaAsNode(JsonSerializerOptions options, Type type, JsonSchemaExporterOptions exporterOptions)
AIJsonUtilities.CreateJsonSchemaCore(Type type, String parameterName, String description, Boolean hasDefaultValue, Object defaultValue, JsonSerializerOptions serializerOptions, AIJsonSchemaCreateOptions inferenceOptions)
AIJsonUtilities.CreateJsonSchema(Type type, String description, Boolean hasDefaultValue, Object defaultValue, JsonSerializerOptions serializerOptions, AIJsonSchemaCreateOptions inferenceOptions)
ReflectionAIFunctionDescriptor.ctor(DescriptorKey key, JsonSerializerOptions serializerOptions)
ReflectionAIFunctionDescriptor.GetOrCreate(MethodInfo method, AIFunctionFactoryOptions options)
ReflectionAIFunction.Build(MethodInfo method, Object target, AIFunctionFactoryOptions options)
AIFunctionFactory.Create(MethodInfo method, Object target, AIFunctionFactoryOptions options)
AIFunctionMcpServerPrompt.Create(MethodInfo method, Object target, McpServerPromptCreateOptions options) line 39
AIFunctionMcpServerPrompt.Create(Delegate method, McpServerPromptCreateOptions options) line 24
McpServerPrompt.Create(Delegate method, McpServerPromptCreateOptions options) line 161
McpServerPromptTests.SupportsSchemaCreateOptions() line 332
--- End of stack trace from previous location ---

@eiriktsarpalis
Copy link
Member

I speculate that it's related to the output schema now being generated for every AI function. If our server infrastructure was hardcoding detection of return types PromptMessage[], then STJ was not being exercised for that particular type until today. I'll investigate further.

@eiriktsarpalis eiriktsarpalis changed the title Update Microsoft.Extensions.AI version Update Microsoft.Extensions.AI version & expose JSON configuration on McpServerResourceCreateOptions Jun 13, 2025
@eiriktsarpalis eiriktsarpalis merged commit 28d6547 into modelcontextprotocol:main Jun 13, 2025
6 of 7 checks passed
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.

Optional parameters not working
3 participants