@@ -8,23 +8,33 @@ namespace WinGetMCPServer.Response
88{
99 using Microsoft . Management . Deployment ;
1010 using ModelContextProtocol . Protocol ;
11- using System . Text . Json ;
11+ using WinGetMCPServer . Extensions ;
1212
1313 /// <summary>
1414 /// Contains reusable responses for package tools.
1515 /// </summary>
1616 internal static class PackageResponse
1717 {
18- public static CallToolResponse ResponseForConnectError ( ConnectResult connectResult )
18+ /// <summary>
19+ /// Creates a response for a ConnectResult error.
20+ /// </summary>
21+ /// <param name="connectResult">The connect result.</param>
22+ /// <returns>The response.</returns>
23+ public static CallToolResponse ForConnectError ( ConnectResult connectResult )
1924 {
2025 return new CallToolResponse ( )
2126 {
2227 IsError = true ,
23- Content = [ new Content ( ) { Text = $ "Failed when connecting to the WinGet package catalog with error: { connectResult . ExtendedErrorCode . Message } [0x{ connectResult . ExtendedErrorCode . HResult : X8} ]" } ] ,
28+ Content = [ new Content ( ) { Text = $ "Failed when connecting to the package catalog with error: { connectResult . ExtendedErrorCode . Message } [0x{ connectResult . ExtendedErrorCode . HResult : X8} ]" } ] ,
2429 } ;
2530 }
2631
27- public static CallToolResponse ResponseForFindError ( FindPackagesResult findResult )
32+ /// <summary>
33+ /// Creates a response for a FindPackagesResult error.
34+ /// </summary>
35+ /// <param name="findResult">The find packages result.</param>
36+ /// <returns>The response.</returns>
37+ public static CallToolResponse ForFindError ( FindPackagesResult findResult )
2838 {
2939 return new CallToolResponse ( )
3040 {
@@ -33,7 +43,11 @@ public static CallToolResponse ResponseForFindError(FindPackagesResult findResul
3343 } ;
3444 }
3545
36- public static CallToolResponse ResponseForCancelBeforeSystemChange ( )
46+ /// <summary>
47+ /// Creates a response that indicates the operation was cancelled before any changes were made.
48+ /// </summary>
49+ /// <returns>The response.</returns>
50+ public static CallToolResponse ForCancelBeforeSystemChange ( )
3751 {
3852 return new CallToolResponse ( )
3953 {
@@ -42,7 +56,13 @@ public static CallToolResponse ResponseForCancelBeforeSystemChange()
4256 } ;
4357 }
4458
45- public static CallToolResponse ResponseForEmptyFind ( string identifer , string ? catalog )
59+ /// <summary>
60+ /// Creates a response for not finding any packages.
61+ /// </summary>
62+ /// <param name="identifer">The identifier used when searching.</param>
63+ /// <param name="catalog">The catalog that was searched.</param>
64+ /// <returns>The response.</returns>
65+ public static CallToolResponse ForEmptyFind ( string identifer , string ? catalog )
4666 {
4767 PackageIdentityErrorResult result = new ( )
4868 {
@@ -51,10 +71,10 @@ public static CallToolResponse ResponseForEmptyFind(string identifer, string? ca
5171 Catalog = catalog ,
5272 } ;
5373
54- return ResponseFromObject ( result ) ;
74+ return ToolResponse . FromObject ( result ) ;
5575 }
5676
57- public static CallToolResponse ResponseForMultiFind ( string identifer , string ? catalog , FindPackagesResult findResult )
77+ public static CallToolResponse ForMultiFind ( string identifer , string ? catalog , FindPackagesResult findResult )
5878 {
5979 PackageIdentityErrorResult result = new ( )
6080 {
@@ -63,12 +83,12 @@ public static CallToolResponse ResponseForMultiFind(string identifer, string? ca
6383 Catalog = catalog ,
6484 } ;
6585
66- AddFoundPackagesToList ( result . Packages , findResult ) ;
86+ result . Packages . AddPackages ( findResult ) ;
6787
68- return ResponseFromObject ( result ) ;
88+ return ToolResponse . FromObject ( result ) ;
6989 }
7090
71- public static CallToolResponse ResponseForInstallOperation ( InstallResult installResult , FindPackagesResult ? findResult )
91+ public static CallToolResponse ForInstallOperation ( InstallResult installResult , FindPackagesResult ? findResult )
7292 {
7393 InstallOperationResult result = new InstallOperationResult ( ) ;
7494
@@ -126,10 +146,10 @@ public static CallToolResponse ResponseForInstallOperation(InstallResult install
126146
127147 if ( findResult != null && findResult . Status == FindPackagesResultStatus . Ok && findResult . Matches ? . Count == 1 )
128148 {
129- result . InstalledPackageInformation = FindPackageResultFromCatalogPackage ( findResult . Matches [ 0 ] . CatalogPackage ) ;
149+ result . InstalledPackageInformation = PackageListExtensions . FindPackageResultFromCatalogPackage ( findResult . Matches [ 0 ] . CatalogPackage ) ;
130150 }
131151
132- return ResponseFromObject ( result , installResult . Status != InstallResultStatus . Ok ) ;
152+ return ToolResponse . FromObject ( result , installResult . Status != InstallResultStatus . Ok ) ;
133153 }
134154 }
135155}
0 commit comments