@@ -143,6 +143,7 @@ where t.GetCustomAttribute<McpServerToolTypeAttribute>() is not null
143143 /// <summary>Adds <see cref="McpServerPrompt"/> instances to the service collection backing <paramref name="builder"/>.</summary>
144144 /// <typeparam name="TPromptType">The prompt type.</typeparam>
145145 /// <param name="builder">The builder instance.</param>
146+ /// <param name="serializerOptions">The serializer options governing prompt parameter marshalling.</param>
146147 /// <returns>The builder provided in <paramref name="builder"/>.</returns>
147148 /// <exception cref="ArgumentNullException"><paramref name="builder"/> is <see langword="null"/>.</exception>
148149 /// <remarks>
@@ -154,7 +155,8 @@ where t.GetCustomAttribute<McpServerToolTypeAttribute>() is not null
154155 DynamicallyAccessedMemberTypes . PublicMethods |
155156 DynamicallyAccessedMemberTypes . NonPublicMethods |
156157 DynamicallyAccessedMemberTypes . PublicConstructors ) ] TPromptType > (
157- this IMcpServerBuilder builder )
158+ this IMcpServerBuilder builder ,
159+ JsonSerializerOptions ? serializerOptions = null )
158160 {
159161 Throw . IfNull ( builder ) ;
160162
@@ -163,8 +165,8 @@ where t.GetCustomAttribute<McpServerToolTypeAttribute>() is not null
163165 if ( promptMethod . GetCustomAttribute < McpServerPromptAttribute > ( ) is not null )
164166 {
165167 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 } ) ) ) ;
168170 }
169171 }
170172
@@ -174,6 +176,7 @@ where t.GetCustomAttribute<McpServerToolTypeAttribute>() is not null
174176 /// <summary>Adds <see cref="McpServerPrompt"/> instances to the service collection backing <paramref name="builder"/>.</summary>
175177 /// <param name="builder">The builder instance.</param>
176178 /// <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>
177180 /// <returns>The builder provided in <paramref name="builder"/>.</returns>
178181 /// <exception cref="ArgumentNullException"><paramref name="builder"/> is <see langword="null"/>.</exception>
179182 /// <exception cref="ArgumentNullException"><paramref name="promptTypes"/> is <see langword="null"/>.</exception>
@@ -183,7 +186,7 @@ where t.GetCustomAttribute<McpServerToolTypeAttribute>() is not null
183186 /// instance for each. For instance methods, an instance will be constructed for each invocation of the prompt.
184187 /// </remarks>
185188 [ 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 )
187190 {
188191 Throw . IfNull ( builder ) ;
189192 Throw . IfNull ( promptTypes ) ;
@@ -197,8 +200,8 @@ public static IMcpServerBuilder WithPrompts(this IMcpServerBuilder builder, para
197200 if ( promptMethod . GetCustomAttribute < McpServerPromptAttribute > ( ) is not null )
198201 {
199202 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 } ) ) ) ;
202205 }
203206 }
204207 }
@@ -211,6 +214,7 @@ public static IMcpServerBuilder WithPrompts(this IMcpServerBuilder builder, para
211214 /// Adds types marked with the <see cref="McpServerPromptTypeAttribute"/> attribute from the given assembly as prompts to the server.
212215 /// </summary>
213216 /// <param name="builder">The builder instance.</param>
217+ /// <param name="serializerOptions">The serializer options governing prompt parameter marshalling.</param>
214218 /// <param name="promptAssembly">The assembly to load the types from. If <see langword="null"/>, the calling assembly will be used.</param>
215219 /// <returns>The builder provided in <paramref name="builder"/>.</returns>
216220 /// <exception cref="ArgumentNullException"><paramref name="builder"/> is <see langword="null"/>.</exception>
@@ -235,7 +239,7 @@ public static IMcpServerBuilder WithPrompts(this IMcpServerBuilder builder, para
235239 /// </para>
236240 /// </remarks>
237241 [ 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 )
239243 {
240244 Throw . IfNull ( builder ) ;
241245
@@ -244,7 +248,8 @@ public static IMcpServerBuilder WithPromptsFromAssembly(this IMcpServerBuilder b
244248 return builder . WithPrompts (
245249 from t in promptAssembly . GetTypes ( )
246250 where t . GetCustomAttribute < McpServerPromptTypeAttribute > ( ) is not null
247- select t ) ;
251+ select t ,
252+ serializerOptions ) ;
248253 }
249254 #endregion
250255
0 commit comments