RSCG_MCP2File 10.2025.1212.1953
dotnet add package RSCG_MCP2File --version 10.2025.1212.1953
NuGet\Install-Package RSCG_MCP2File -Version 10.2025.1212.1953
<PackageReference Include="RSCG_MCP2File" Version="10.2025.1212.1953" />
<PackageVersion Include="RSCG_MCP2File" Version="10.2025.1212.1953" />
<PackageReference Include="RSCG_MCP2File" />
paket add RSCG_MCP2File --version 10.2025.1212.1953
#r "nuget: RSCG_MCP2File, 10.2025.1212.1953"
#:package RSCG_MCP2File@10.2025.1212.1953
#addin nuget:?package=RSCG_MCP2File&version=10.2025.1212.1953
#tool nuget:?package=RSCG_MCP2File&version=10.2025.1212.1953
RSCG_MCP2File
RSCG_MCP2File is a .NET Standard 2.0 source generator that generates MCP (Microsoft Code Platform) tools that generates exports to file from each MCP function defined
Features
- Generates an MCP tool that writes the result of another tool to file
Usage
Add RSCG_MCP2File as a NuGet package to your project.
Add the following attribute to your MCP function to generate a file export tool:
[MCP2File.AddMCPExportToFile]
[McpServerToolType]
public partial class WeatherTool
{
In the program.cs file, register the generated tool:
builder.Services.AddMcpServer()
.WithToolsFromAssembly()
How it works
For each function that returns a value, a corresponding tool will be generated that exports the result to a file. It assumes that the result is either a byte array, a string, or an object that can be converted to a string.
For example
[McpServerToolType]
[MCP2File.AddMCPExportToFile]
public partial class WeatherTool
{
[McpServerTool, Description("Returns the current weather for a specific city")]
public string MyGetWeatherForCity(string cityName)
{
it generates
[global::ModelContextProtocol.Server.McpServerTool]
[global::System.ComponentModel.Description("calls the MyGetWeatherForCity and saves the result to a file . Investigate Success parameter from result and, if false, see the ErrorMessage ")]
public async Task<MCP2File.ResultWriteToFile> MyGetWeatherForCityExportToFile(string cityName, [global::System.ComponentModel.Description("please use full file path. Do NOT use relative path ")]string exportToFile)
{
try{
dynamic result = MyGetWeatherForCity(cityName);
if (result is byte[] bytes)
{
await File.WriteAllBytesAsync(exportToFile, bytes);
}
else if (result is string str)
{
await File.WriteAllTextAsync(exportToFile, str);
}
else
{
await File.WriteAllTextAsync(exportToFile, result?.ToString() ?? string.Empty);
}
return MCP2File.ResultWriteToFile.FromSuccess();
}
catch (Exception ex)
{
return MCP2File.ResultWriteToFile.FromError(ex.Message);
}
}
The ResultWriteToFile class is defined as:
public class ResultWriteToFile
{
public bool Success { get; set; }
public string? ErrorMessage { get; set; }
public static ResultWriteToFile FromSuccess() => new ResultWriteToFile { Success = true};
public static ResultWriteToFile FromError(string errorMessage) => new ResultWriteToFile { Success = false, ErrorMessage = errorMessage };
}
The AI should investigate the Success parameter from the result and, if false, see the ErrorMessage.
License
This project is licensed under the MIT License.
Repository
For more information, visit the GitHub repository.
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.0
- Microsoft.CodeAnalysis.CSharp (>= 5.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 10.2025.1212.1953 | 138 | 12/12/2025 |
| 9.2025.1208.1952 | 413 | 12/8/2025 |
| 9.2025.1202.1952 | 687 | 12/2/2025 |
| 9.2025.1202.817 | 669 | 12/2/2025 |
| 9.2025.1202.800 | 724 | 12/2/2025 |
| 9.2025.1201.1800 | 579 | 12/1/2025 |
| 9.2025.1201.1726 | 578 | 12/1/2025 |