@@ -1413,27 +1413,44 @@ public class AzureOptions
14131413// ============================================================================
14141414
14151415/// <summary>
1416- /// Configuration for a local/stdio MCP server.
1416+ /// Abstract base class for MCP server configurations .
14171417/// </summary>
1418- public class McpLocalServerConfig
1418+ [ JsonPolymorphic (
1419+ TypeDiscriminatorPropertyName = "type" ,
1420+ IgnoreUnrecognizedTypeDiscriminators = true ) ]
1421+ [ JsonDerivedType ( typeof ( McpStdioServerConfig ) , "stdio" ) ]
1422+ [ JsonDerivedType ( typeof ( McpHttpServerConfig ) , "http" ) ]
1423+ public abstract class McpServerConfig
14191424{
1425+ private protected McpServerConfig ( ) { }
1426+
14201427 /// <summary>
14211428 /// List of tools to include from this server. Empty list means none. Use "*" for all.
14221429 /// </summary>
14231430 [ JsonPropertyName ( "tools" ) ]
14241431 public List < string > Tools { get ; set ; } = [ ] ;
14251432
14261433 /// <summary>
1427- /// Server type. Defaults to "local" .
1434+ /// The server type discriminator .
14281435 /// </summary>
1429- [ JsonPropertyName ( "type" ) ]
1430- public string ? Type { get ; set ; }
1436+ [ JsonIgnore ]
1437+ public virtual string Type => "unknown" ;
14311438
14321439 /// <summary>
14331440 /// Optional timeout in milliseconds for tool calls to this server.
14341441 /// </summary>
14351442 [ JsonPropertyName ( "timeout" ) ]
14361443 public int ? Timeout { get ; set ; }
1444+ }
1445+
1446+ /// <summary>
1447+ /// Configuration for a local/stdio MCP server.
1448+ /// </summary>
1449+ public sealed class McpStdioServerConfig : McpServerConfig
1450+ {
1451+ /// <inheritdoc />
1452+ [ JsonIgnore ]
1453+ public override string Type => "stdio" ;
14371454
14381455 /// <summary>
14391456 /// Command to run the MCP server.
@@ -1463,25 +1480,11 @@ public class McpLocalServerConfig
14631480/// <summary>
14641481/// Configuration for a remote MCP server (HTTP or SSE).
14651482/// </summary>
1466- public class McpRemoteServerConfig
1483+ public sealed class McpHttpServerConfig : McpServerConfig
14671484{
1468- /// <summary>
1469- /// List of tools to include from this server. Empty list means none. Use "*" for all.
1470- /// </summary>
1471- [ JsonPropertyName ( "tools" ) ]
1472- public List < string > Tools { get ; set ; } = [ ] ;
1473-
1474- /// <summary>
1475- /// Server type. Must be "http" or "sse".
1476- /// </summary>
1477- [ JsonPropertyName ( "type" ) ]
1478- public string Type { get ; set ; } = "http" ;
1479-
1480- /// <summary>
1481- /// Optional timeout in milliseconds for tool calls to this server.
1482- /// </summary>
1483- [ JsonPropertyName ( "timeout" ) ]
1484- public int ? Timeout { get ; set ; }
1485+ /// <inheritdoc />
1486+ [ JsonIgnore ]
1487+ public override string Type => "http" ;
14851488
14861489 /// <summary>
14871490 /// URL of the remote server.
@@ -1539,7 +1542,7 @@ public class CustomAgentConfig
15391542 /// MCP servers specific to this agent.
15401543 /// </summary>
15411544 [ JsonPropertyName ( "mcpServers" ) ]
1542- public Dictionary < string , object > ? McpServers { get ; set ; }
1545+ public Dictionary < string , McpServerConfig > ? McpServers { get ; set ; }
15431546
15441547 /// <summary>
15451548 /// Whether the agent should be available for model inference.
@@ -1608,7 +1611,7 @@ protected SessionConfig(SessionConfig? other)
16081611 Hooks = other . Hooks ;
16091612 InfiniteSessions = other . InfiniteSessions ;
16101613 McpServers = other . McpServers is not null
1611- ? new Dictionary < string , object > ( other . McpServers , other . McpServers . Comparer )
1614+ ? new Dictionary < string , McpServerConfig > ( other . McpServers , other . McpServers . Comparer )
16121615 : null ;
16131616 Model = other . Model ;
16141617 ModelCapabilities = other . ModelCapabilities ;
@@ -1740,9 +1743,9 @@ protected SessionConfig(SessionConfig? other)
17401743
17411744 /// <summary>
17421745 /// MCP server configurations for the session.
1743- /// Keys are server names, values are server configurations (McpLocalServerConfig or McpRemoteServerConfig ).
1746+ /// Keys are server names, values are server configurations (<see cref="McpStdioServerConfig"/> or <see cref="McpHttpServerConfig"/> ).
17441747 /// </summary>
1745- public Dictionary < string , object > ? McpServers { get ; set ; }
1748+ public Dictionary < string , McpServerConfig > ? McpServers { get ; set ; }
17461749
17471750 /// <summary>
17481751 /// Custom agent configurations for the session.
@@ -1836,7 +1839,7 @@ protected ResumeSessionConfig(ResumeSessionConfig? other)
18361839 Hooks = other . Hooks ;
18371840 InfiniteSessions = other . InfiniteSessions ;
18381841 McpServers = other . McpServers is not null
1839- ? new Dictionary < string , object > ( other . McpServers , other . McpServers . Comparer )
1842+ ? new Dictionary < string , McpServerConfig > ( other . McpServers , other . McpServers . Comparer )
18401843 : null ;
18411844 Model = other . Model ;
18421845 ModelCapabilities = other . ModelCapabilities ;
@@ -1972,9 +1975,9 @@ protected ResumeSessionConfig(ResumeSessionConfig? other)
19721975
19731976 /// <summary>
19741977 /// MCP server configurations for the session.
1975- /// Keys are server names, values are server configurations (McpLocalServerConfig or McpRemoteServerConfig ).
1978+ /// Keys are server names, values are server configurations (<see cref="McpStdioServerConfig"/> or <see cref="McpHttpServerConfig"/> ).
19761979 /// </summary>
1977- public Dictionary < string , object > ? McpServers { get ; set ; }
1980+ public Dictionary < string , McpServerConfig > ? McpServers { get ; set ; }
19781981
19791982 /// <summary>
19801983 /// Custom agent configurations for the session.
@@ -2519,8 +2522,7 @@ public class SystemMessageTransformRpcResponse
25192522[ JsonSerializable ( typeof ( GetForegroundSessionResponse ) ) ]
25202523[ JsonSerializable ( typeof ( GetModelsResponse ) ) ]
25212524[ JsonSerializable ( typeof ( GetStatusResponse ) ) ]
2522- [ JsonSerializable ( typeof ( McpLocalServerConfig ) ) ]
2523- [ JsonSerializable ( typeof ( McpRemoteServerConfig ) ) ]
2525+ [ JsonSerializable ( typeof ( McpServerConfig ) ) ]
25242526[ JsonSerializable ( typeof ( MessageOptions ) ) ]
25252527[ JsonSerializable ( typeof ( ModelBilling ) ) ]
25262528[ JsonSerializable ( typeof ( ModelCapabilities ) ) ]
0 commit comments