An MCP (Model Context Protocol) server that evaluates and executes C# scripts using Roslyn. This tool allows AI assistants to run C# code dynamically, either from direct input or from .csx script files.
- 🚀 Execute C# scripts directly or from files
- 📦 Full Roslyn scripting support with common namespaces pre-imported
- 🔒 Console output capture (safe for MCP stdio protocol)
- ⚡ Comprehensive error handling for compilation and runtime errors
- 🐳 Available as both Docker container and dotnet tool
- ✅ Full test coverage with NUnit and FluentAssertions
# Install globally
dotnet tool install -g InfinityFlow.CSharp.Eval
# Run the tool
infinityflow-csharp-eval# Pull from GitHub Container Registry
docker pull ghcr.io/infinityflowapp/csharp-mcp:latest
# Run interactively
docker run -it ghcr.io/infinityflowapp/csharp-mcp:latest
# Or use docker-compose
docker-compose run csharp-eval-mcp# Clone the repository
git clone https://github.com/InfinityFlowApp/csharp-mcp.git
cd csharp-mcp
# Build and run
dotnet build
dotnet run --project src/InfinityFlow.CSharp.EvalThe MCP server exposes a single tool: EvalCSharp
csxFile(optional): Full path to a .csx file to executecsx(optional): C# script code to execute directly
Either csxFile or csx must be provided, but not both.
{
"tool": "EvalCSharp",
"parameters": {
"csx": "Console.WriteLine(\"Hello World!\"); 2 + 2"
}
}Output:
Hello World!
Result: 4
{
"tool": "EvalCSharp",
"parameters": {
"csxFile": "/scripts/example.csx"
}
}var numbers = Enumerable.Range(1, 10);
var evenSum = numbers.Where(n => n % 2 == 0).Sum();
Console.WriteLine($"Sum of even numbers: {evenSum}");
evenSum * 2Output:
Sum of even numbers: 30
Result: 60
The following namespaces are automatically available:
SystemSystem.IOSystem.LinqSystem.TextSystem.Collections.GenericSystem.Threading.Tasks
Add to your Cursor settings (.cursor/mcp_settings.json or via Settings UI):
{
"mcpServers": {
"csharp-eval": {
"command": "docker",
"args": ["run", "-i", "--rm", "ghcr.io/infinityflowapp/csharp-mcp:latest"],
"env": {
"CSX_ALLOWED_PATH": "/scripts"
}
}
}
}Or if installed as a dotnet tool:
{
"mcpServers": {
"csharp-eval": {
"command": "infinityflow-csharp-eval",
"env": {
"CSX_ALLOWED_PATH": "${workspaceFolder}/scripts"
}
}
}
}Add to your Claude Code configuration (claude_desktop_config.json):
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - Windows:
%APPDATA%\Claude\claude_desktop_config.json - Linux:
~/.config/claude/claude_desktop_config.json
{
"mcpServers": {
"csharp-eval": {
"command": "docker",
"args": ["run", "-i", "--rm", "ghcr.io/infinityflowapp/csharp-mcp:latest"],
"env": {
"CSX_ALLOWED_PATH": "/scripts"
}
}
}
}Or if installed as a dotnet tool:
{
"mcpServers": {
"csharp-eval": {
"command": "infinityflow-csharp-eval",
"env": {
"CSX_ALLOWED_PATH": "/Users/your-username/scripts"
}
}
}
}Create .vscode/mcp.json:
{
"servers": {
"csharp-eval": {
"type": "stdio",
"command": "infinityflow-csharp-eval"
}
}
}Create .mcp.json in solution directory:
{
"servers": {
"csharp-eval": {
"type": "stdio",
"command": "dnx",
"args": [
"InfinityFlow.CSharp.Eval",
"--version",
"1.0.0",
"--yes"
]
}
}
}- .NET 9.0 SDK or later
- Docker (optional, for containerization)
# Restore dependencies
dotnet restore
# Build the project
dotnet build
# Run tests
dotnet test
# Pack as dotnet tool
dotnet pack -c ReleaseThe project includes comprehensive unit tests using NUnit and FluentAssertions:
dotnet test# Build the Docker image
docker build -t infinityflow/csharp-eval-mcp .
# Run the container
docker run -it infinityflow/csharp-eval-mcpcsharp-mcp/
├── src/
│ └── InfinityFlow.CSharp.Eval/ # Main MCP server implementation
│ ├── Tools/
│ │ └── CSharpEvalTools.cs # Roslyn script evaluation tool
│ ├── Program.cs # MCP server entry point
│ └── .mcp/
│ └── server.json # MCP server configuration
├── tests/
│ └── InfinityFlow.CSharp.Eval.Tests/ # Unit tests
│ └── CSharpEvalToolsTests.cs # Comprehensive test suite
├── Directory.Packages.props # Central package management
├── Dockerfile # Docker containerization
├── docker-compose.yml # Docker compose configuration
└── .github/
└── workflows/ # GitHub Actions CI/CD
├── ci-cd.yml # Main CI/CD pipeline
├── validate-pr.yml # PR validation
└── release-drafter.yml # Automated release notes
The project uses GitHub Actions for continuous integration and deployment:
- CI/CD Pipeline: Automated testing, Docker builds, and NuGet publishing
- PR Validation: Build and test validation for all pull requests
- Release Drafter: Automated release notes generation
- Dependabot: Automated dependency updates
Releases are automatically published when a version tag is pushed:
git tag v1.0.0
git push origin v1.0.0This will:
- Build and test the project
- Publish Docker image to GitHub Container Registry
- Publish NuGet package to NuGet.org
- Create a GitHub release with auto-generated notes
⚠️ Scripts run in the same process context as the MCP server- 🔐 Console output is captured to prevent interference with MCP stdio protocol
- 🐳 Docker container runs as non-root user for additional security
- 🛡️ Use appropriate sandboxing when running untrusted scripts
- 📁 File access can be restricted via
CSX_ALLOWED_PATHenvironment variable - 🔒 Only .csx files are allowed for execution
- ⏱️ Scripts have a configurable timeout (default 30 seconds)
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
MIT