@@ -1719,75 +1719,24 @@ partial class TestTools
17191719 AssertGeneratedSourceEquals ( expected , result . GeneratedSources [ 0 ] . SourceText . ToString ( ) ) ;
17201720 }
17211721
1722- [ Fact ]
1723- public void Generator_WithEnumFromDifferentNamespace_GeneratesFullyQualifiedTypeName ( )
1722+ [ Theory ]
1723+ [ InlineData ( true ) ]
1724+ [ InlineData ( false ) ]
1725+ public void Generator_WithTypeFromDifferentNamespace_GeneratesFullyQualifiedTypeName ( bool useFullyQualifiedTypesInSource )
17241726 {
1725- // This test validates the fix for the issue where parameter types from different namespaces
1726- // caused build failures because the generator was emitting unqualified type names.
1727- var result = RunGenerator ( """
1728- using ModelContextProtocol.Server;
1729- using System.ComponentModel;
1730- using System.Threading.Tasks;
1731-
1732- namespace MyApp.Actions
1733- {
1734- public enum MyAction
1735- {
1736- One,
1737- Two
1738- }
1739- }
1727+ // This test validates that regardless of whether the source code uses fully qualified
1728+ // or unqualified type names, the generator always emits fully qualified type names
1729+ // with global:: prefix. This fixes the issue where parameter types from different
1730+ // namespaces caused build failures.
1731+ string usingDirective = useFullyQualifiedTypesInSource ? "" : "using MyApp.Actions;" ;
1732+ string returnType = useFullyQualifiedTypesInSource ? "System.Threading.Tasks.Task<string>" : "Task<string>" ;
1733+ string parameterType = useFullyQualifiedTypesInSource ? "MyApp.Actions.MyAction" : "MyAction" ;
17401734
1741- namespace MyApp
1742- {
1743- [McpServerToolType]
1744- public sealed partial class Tools
1745- {
1746- /// <summary>Do a thing based on an action.</summary>
1747- /// <param name="action">The action to perform.</param>
1748- [McpServerTool]
1749- public async partial Task<string> DoThing(MyApp.Actions.MyAction action)
1750- => await Task.FromResult("ok");
1751- }
1752- }
1753- """ ) ;
1754-
1755- Assert . True ( result . Success ) ;
1756- Assert . Single ( result . GeneratedSources ) ;
1757-
1758- var expected = $$ """
1759- // <auto-generated/>
1760- // ModelContextProtocol.Analyzers {{ typeof ( XmlToDescriptionGenerator ) . Assembly . GetName ( ) . Version }}
1761-
1762- #pragma warning disable
1763-
1764- using System.ComponentModel;
1765- using ModelContextProtocol.Server;
1766-
1767- namespace MyApp
1768- {
1769- partial class Tools
1770- {
1771- [Description("Do a thing based on an action.")]
1772- public partial global::System.Threading.Tasks.Task<string> DoThing([Description("The action to perform.")] global::MyApp.Actions.MyAction action);
1773- }
1774- }
1775- """ ;
1776-
1777- AssertGeneratedSourceEquals ( expected , result . GeneratedSources [ 0 ] . SourceText . ToString ( ) ) ;
1778- }
1779-
1780- [ Fact ]
1781- public void Generator_WithUnqualifiedTypeInSource_GeneratesFullyQualifiedTypeName ( )
1782- {
1783- // This test validates that even when the source code uses an unqualified type name
1784- // (via a using directive), the generator still emits fully qualified type names.
1785- // This is the exact scenario from the original issue.
1786- var result = RunGenerator ( """
1735+ var result = RunGenerator ( $$ """
17871736 using ModelContextProtocol.Server;
17881737 using System.ComponentModel;
17891738 using System.Threading.Tasks;
1790- using MyApp.Actions;
1739+ {{ usingDirective }}
17911740
17921741 namespace MyApp.Actions
17931742 {
@@ -1806,7 +1755,7 @@ public sealed partial class Tools
18061755 /// <summary>Do a thing based on an action.</summary>
18071756 /// <param name="action">The action to perform.</param>
18081757 [McpServerTool]
1809- public async partial Task<string> DoThing(MyAction action)
1758+ public async partial {{ returnType }} DoThing({{ parameterType }} action)
18101759 => await Task.FromResult("ok");
18111760 }
18121761 }
@@ -1815,8 +1764,8 @@ public async partial Task<string> DoThing(MyAction action)
18151764 Assert . True ( result . Success ) ;
18161765 Assert . Single ( result . GeneratedSources ) ;
18171766
1818- // Even though the source uses unqualified "MyAction", the generated code should use
1819- // the fully qualified " global::MyApp.Actions.MyAction"
1767+ // Regardless of source qualification, generated code should always use
1768+ // fully qualified type names with global:: prefix
18201769 var expected = $$ """
18211770 // <auto-generated/>
18221771 // ModelContextProtocol.Analyzers {{ typeof ( XmlToDescriptionGenerator ) . Assembly . GetName ( ) . Version }}
0 commit comments