RSCG_MCP2File by Ignat Andrei
NuGet / site data
Details
Info
info
Name: RSCG_MCP2File
Generating MCP tool function that exports to file the result of another MCP tool.
Author: Ignat Andrei
NuGet: https://www.nuget.org/packages/RSCG_MCP2File/
You can find more details at https://github.com/ignatandrei/RSCG_OpenApi2MCP
Author
note
Ignat Andrei

Original Readme
note
This is a place holder
About
note
Generating code for saving MCP result to file.
How to use
Example (source csproj, source files)
- CSharp Project
- Program.cs
- MyTools.cs
This is the CSharp Project that references RSCG_MCP2File
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="10.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="10.0.0" />
<PackageReference Include="ModelContextProtocol" Version="0.5.0-preview.1" />
<PackageReference Include="ModelContextProtocol.AspNetCore" Version="0.5.0-preview.1" />
<PackageReference Include="RSCG_MCP2File" Version="9.2025.1202.1952" />
<PackageReference Include="OpenAPISwaggerUI" Version="9.2024.1215.2209" />
<PackageReference Include="Serilog.AspNetCore" Version="10.0.0" />
</ItemGroup>
<PropertyGroup>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GX</CompilerGeneratedFilesOutputPath>
</PropertyGroup>
</Project>
This is the use of RSCG_MCP2File in Program.cs
// See https://aka.ms/new-console-template for more information
using MCPDemo;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using OpenAPISwaggerUI;
using Serilog;
using Serilog.Events;
Console.WriteLine("Hello, World!");
var builderApp = Host.CreateApplicationBuilder(args);
var builderWeb = WebApplication.CreateBuilder();
// Configure all logs to go to stderr (stdout is used for the MCP protocol messages).
//builder.Logging.AddConsole(o => o.LogToStandardErrorThreshold = LogLevel.Trace);
var serverApp = builderApp.Services
.AddMcpServer();
serverApp = serverApp.WithStdioServerTransport();
serverApp.WithTools<MyTools>();
var serverWeb = builderWeb.Services.AddMcpServer();
serverWeb = serverWeb.WithHttpTransport();
serverWeb.WithTools<MyTools>();
builderWeb.Services.AddOpenApi();
builderWeb.Services.AddTransient<MyTools>();
var app = builderApp.Build();
var web = builderWeb.Build();
web.MapOpenApi();
web.MapOpenApi("/openapi/{documentName}.yaml");
web.MapMcp();
web.UseOpenAPISwaggerUI();
var t1 = web.RunAsync();
var t2 = app.RunAsync();
await Task.WhenAll(t1, t2);
This is the use of RSCG_MCP2File in MyTools.cs
using ModelContextProtocol.Server;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
namespace MCPDemo;
[MCP2File.AddMCPExportToFile()]
partial class MyTools
{
[McpServerTool]
[Description("Echo demo")]
public async Task<string> SendEcho([Description("echo")] string echoData)
{
await Task.Delay(10);
return echoData;
}
}
Generated Files
Those are taken from $(BaseIntermediateOutputPath)\GX
- MCPExportToFile.g.cs
- Microsoft.CodeAnalysis.EmbeddedAttribute.cs
- MyTools_ExportToFile.g.cs
namespace MCP2File
{
[global::Microsoft.CodeAnalysis.EmbeddedAttribute]
[global::System.AttributeUsage(global::System.AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
internal class AddMCPExportToFile: global::System.Attribute {}
}
// <auto-generated/>
namespace Microsoft.CodeAnalysis
{
internal sealed partial class EmbeddedAttribute : global::System.Attribute
{
}
}
// Auto-generated by MCP2File
namespace MCPDemo
{
public partial class MyTools
{
[global::ModelContextProtocol.Server.McpServerTool]
[global::System.ComponentModel.Description("calls the SendEcho and saves the result to a file ")]
public async Task SendEchoExportToFile(string echoData, string exportToFile)
{
dynamic result = await SendEcho(echoData);
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);
}
}
}
}
Useful
Download Example (.NET C#)
Share RSCG_MCP2File
https://ignatandrei.github.io/RSCG_Examples/v2/docs/RSCG_MCP2File
Category "MCP" has the following generators:
1 RSCG_MCP2File
2025-11-15
2 RSCG_MCP2OpenAPI
2025-11-11