@@ -143,6 +143,7 @@ where t.GetCustomAttribute<McpServerToolTypeAttribute>() is not null
143
143
/// <summary>Adds <see cref="McpServerPrompt"/> instances to the service collection backing <paramref name="builder"/>.</summary>
144
144
/// <typeparam name="TPromptType">The prompt type.</typeparam>
145
145
/// <param name="builder">The builder instance.</param>
146
+ /// <param name="serializerOptions">The serializer options governing prompt parameter marshalling.</param>
146
147
/// <returns>The builder provided in <paramref name="builder"/>.</returns>
147
148
/// <exception cref="ArgumentNullException"><paramref name="builder"/> is <see langword="null"/>.</exception>
148
149
/// <remarks>
@@ -154,7 +155,8 @@ where t.GetCustomAttribute<McpServerToolTypeAttribute>() is not null
154
155
DynamicallyAccessedMemberTypes . PublicMethods |
155
156
DynamicallyAccessedMemberTypes . NonPublicMethods |
156
157
DynamicallyAccessedMemberTypes . PublicConstructors ) ] TPromptType > (
157
- this IMcpServerBuilder builder )
158
+ this IMcpServerBuilder builder ,
159
+ JsonSerializerOptions ? serializerOptions = null )
158
160
{
159
161
Throw . IfNull ( builder ) ;
160
162
@@ -163,8 +165,8 @@ where t.GetCustomAttribute<McpServerToolTypeAttribute>() is not null
163
165
if ( promptMethod . GetCustomAttribute < McpServerPromptAttribute > ( ) is not null )
164
166
{
165
167
builder . Services . AddSingleton ( ( Func < IServiceProvider , McpServerPrompt > ) ( promptMethod . IsStatic ?
166
- services => McpServerPrompt . Create ( promptMethod , options : new ( ) { Services = services } ) :
167
- services => McpServerPrompt . Create ( promptMethod , typeof ( TPromptType ) , new ( ) { Services = services } ) ) ) ;
168
+ services => McpServerPrompt . Create ( promptMethod , options : new ( ) { Services = services , SerializerOptions = serializerOptions } ) :
169
+ services => McpServerPrompt . Create ( promptMethod , typeof ( TPromptType ) , new ( ) { Services = services , SerializerOptions = serializerOptions } ) ) ) ;
168
170
}
169
171
}
170
172
@@ -174,6 +176,7 @@ where t.GetCustomAttribute<McpServerToolTypeAttribute>() is not null
174
176
/// <summary>Adds <see cref="McpServerPrompt"/> instances to the service collection backing <paramref name="builder"/>.</summary>
175
177
/// <param name="builder">The builder instance.</param>
176
178
/// <param name="promptTypes">Types with marked methods to add as prompts to the server.</param>
179
+ /// <param name="serializerOptions">The serializer options governing prompt parameter marshalling.</param>
177
180
/// <returns>The builder provided in <paramref name="builder"/>.</returns>
178
181
/// <exception cref="ArgumentNullException"><paramref name="builder"/> is <see langword="null"/>.</exception>
179
182
/// <exception cref="ArgumentNullException"><paramref name="promptTypes"/> is <see langword="null"/>.</exception>
@@ -183,7 +186,7 @@ where t.GetCustomAttribute<McpServerToolTypeAttribute>() is not null
183
186
/// instance for each. For instance methods, an instance will be constructed for each invocation of the prompt.
184
187
/// </remarks>
185
188
[ RequiresUnreferencedCode ( WithPromptsRequiresUnreferencedCodeMessage ) ]
186
- public static IMcpServerBuilder WithPrompts ( this IMcpServerBuilder builder , params IEnumerable < Type > promptTypes )
189
+ public static IMcpServerBuilder WithPrompts ( this IMcpServerBuilder builder , IEnumerable < Type > promptTypes , JsonSerializerOptions ? serializerOptions = null )
187
190
{
188
191
Throw . IfNull ( builder ) ;
189
192
Throw . IfNull ( promptTypes ) ;
@@ -197,8 +200,8 @@ public static IMcpServerBuilder WithPrompts(this IMcpServerBuilder builder, para
197
200
if ( promptMethod . GetCustomAttribute < McpServerPromptAttribute > ( ) is not null )
198
201
{
199
202
builder . Services . AddSingleton ( ( Func < IServiceProvider , McpServerPrompt > ) ( promptMethod . IsStatic ?
200
- services => McpServerPrompt . Create ( promptMethod , options : new ( ) { Services = services } ) :
201
- services => McpServerPrompt . Create ( promptMethod , promptType , new ( ) { Services = services } ) ) ) ;
203
+ services => McpServerPrompt . Create ( promptMethod , options : new ( ) { Services = services , SerializerOptions = serializerOptions } ) :
204
+ services => McpServerPrompt . Create ( promptMethod , promptType , new ( ) { Services = services , SerializerOptions = serializerOptions } ) ) ) ;
202
205
}
203
206
}
204
207
}
@@ -211,6 +214,7 @@ public static IMcpServerBuilder WithPrompts(this IMcpServerBuilder builder, para
211
214
/// Adds types marked with the <see cref="McpServerPromptTypeAttribute"/> attribute from the given assembly as prompts to the server.
212
215
/// </summary>
213
216
/// <param name="builder">The builder instance.</param>
217
+ /// <param name="serializerOptions">The serializer options governing prompt parameter marshalling.</param>
214
218
/// <param name="promptAssembly">The assembly to load the types from. If <see langword="null"/>, the calling assembly will be used.</param>
215
219
/// <returns>The builder provided in <paramref name="builder"/>.</returns>
216
220
/// <exception cref="ArgumentNullException"><paramref name="builder"/> is <see langword="null"/>.</exception>
@@ -235,7 +239,7 @@ public static IMcpServerBuilder WithPrompts(this IMcpServerBuilder builder, para
235
239
/// </para>
236
240
/// </remarks>
237
241
[ RequiresUnreferencedCode ( WithPromptsRequiresUnreferencedCodeMessage ) ]
238
- public static IMcpServerBuilder WithPromptsFromAssembly ( this IMcpServerBuilder builder , Assembly ? promptAssembly = null )
242
+ public static IMcpServerBuilder WithPromptsFromAssembly ( this IMcpServerBuilder builder , Assembly ? promptAssembly = null , JsonSerializerOptions ? serializerOptions = null )
239
243
{
240
244
Throw . IfNull ( builder ) ;
241
245
@@ -244,7 +248,8 @@ public static IMcpServerBuilder WithPromptsFromAssembly(this IMcpServerBuilder b
244
248
return builder . WithPrompts (
245
249
from t in promptAssembly . GetTypes ( )
246
250
where t . GetCustomAttribute < McpServerPromptTypeAttribute > ( ) is not null
247
- select t ) ;
251
+ select t ,
252
+ serializerOptions ) ;
248
253
}
249
254
#endregion
250
255
0 commit comments