File size: 15,565 Bytes
e462aae | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 | ---
title: Roslyn Stone
emoji: πͺ¨
colorFrom: gray
colorTo: blue
sdk: docker
app_port: 7860
pinned: true
tags:
- mcp
- csharp
- roslyn
- repl
- building-mcp-track-enterprise
short_description: LLM-friendly C# sandbox for creating single-file programs
space_sdk: docker
---
# Roslyn-Stone
> **Note**: This project was collaboratively built with GitHub Copilot, embracing the future of AI-assisted development.
A developer- and LLM-friendly C# sandbox for creating single-file utility programs through the Model Context Protocol (MCP). Named as a playful nod to the Rosetta Stoneβthe ancient artifact that helped decode languagesβRoslyn-Stone helps AI systems create runnable C# programs using file-based apps (top-level statements).
Build complete, runnable .cs files using the power of the Roslyn compiler. Execute C# code, validate syntax, load NuGet packages, and lookup documentation through MCP for seamless integration with Claude Code, VS Code, and other AI-powered development tools.
Perfect for creating command-line utilities, data processing scripts, automation tools, and quick C# programs without project scaffolding.
## Quick Start with Docker
The fastest way to get started is using the pre-built Docker container with your favorite MCP-enabled editor:
### Claude Code / VS Code / Cursor
Add this to your MCP configuration file:
**Linux/macOS**: `~/.config/Code/User/globalStorage/saoudrizwan.claude-dev/settings/cline_mcp_settings.json`
**Windows**: `%APPDATA%\Code\User\globalStorage\saoudrizwan.claude-dev\settings\cline_mcp_settings.json`
```json
{
"mcpServers": {
"roslyn-stone": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"-e", "DOTNET_USE_POLLING_FILE_WATCHER=1",
"ghcr.io/dylanlangston/roslyn-stone:latest"
]
}
}
}
```
**Using Podman?** Just replace `"docker"` with `"podman"` in the command field.
### Claude Desktop
Add to `~/Library/Application Support/Claude/claude_desktop_config.json` (macOS) or equivalent:
```json
{
"mcpServers": {
"roslyn-stone": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"-e", "DOTNET_USE_POLLING_FILE_WATCHER=1",
"ghcr.io/dylanlangston/roslyn-stone:latest"
]
}
}
}
```
That's it! The container provides isolated execution of C# code with minimal setup and enhanced security.
## Features
**File-Based C# Apps** - Create single-file utilities using top-level statements aligned with .NET 10's `dotnet run app.cs` feature
**Inline Package Loading** - Use `nugetPackages` parameter to load packages during testing, finalize with `#:package` directive for self-contained apps
**C# Execution via Roslyn** - Execute and test C# code with full .NET 10 support and recursive NuGet dependency resolution
**Iterative Development** - Build programs incrementally with optional stateful sessions and context management
**Real-time Error Feedback** - Get detailed compilation errors and warnings with actionable messages
**Resources & Tools** - Proper MCP separation: Resources (data) vs Tools (operations)
**Documentation Access** - Query .NET type/method docs via `doc://` resource URIs (includes core SDK types like System.String)
**NuGet Integration** - Search packages via `nuget://` resources, load with tools, full dependency tree resolution
**MCP Protocol** - Official ModelContextProtocol SDK with stdio and HTTP transports
**Dual Transport** - Support for both stdio (local) and HTTP (remote) MCP connections
**AI-Friendly** - Designed for LLM interactions via Model Context Protocol
**Token-Optimized Prompts** - Efficient guidance for creating utility programs with .NET 10 directive examples
**Containerized** - Docker support with .NET Aspire orchestration
**OpenTelemetry** - Built-in observability with logs, metrics, and traces
## Architecture
Roslyn-Stone implements the Model Context Protocol (MCP) to help LLMs create single-file C# utility programs. It follows best practices by properly distinguishing between:
- **Resources** (passive data sources): URI-based read-only access to documentation (`doc://`), NuGet packages (`nuget://`), and execution state (`repl://`)
- **Tools** (active operations): Code execution, validation, and package loading for building utility programs
- **Prompts** (optimized templates): Token-efficient guidance for creating file-based C# apps
The solution follows clean architecture principles with functional programming patterns. It implements best practices for dynamic code compilation and execution, including proper AssemblyLoadContext usage for memory management.
### Key Components
- **Context Management**: Thread-safe session lifecycle with automatic cleanup (30min timeout)
- **Stateful Execution**: Variables and types persist within sessions for iterative development
- **Resource Discovery**: Query docs, packages, and state before execution for efficient workflows
- **Token Optimization**: Prompts guide LLMs to create complete, runnable .cs files
See `MCP_ARCHITECTURE.md` for detailed design documentation and `DYNAMIC_COMPILATION_BEST_PRACTICES.md` for compilation details.
```
RoslynStone/
βββ src/
β βββ RoslynStone.Api/ # Console Host with MCP Server
β βββ RoslynStone.Core/ # Domain models (ExecutionResult, PackageMetadata, etc.)
β βββ RoslynStone.Infrastructure/ # MCP Tools, Roslyn services, functional helpers
β βββ RoslynStone.ServiceDefaults/# OpenTelemetry and Aspire defaults
β βββ RoslynStone.AppHost/ # Aspire orchestration
βββ tests/
βββ RoslynStone.Tests/ # xUnit unit and integration tests
βββ RoslynStone.Benchmarks/ # BenchmarkDotNet performance tests
βββ RoslynStone.LoadTests/ # HTTP load and concurrency tests
```
### Architecture Principles
- **Functional Programming**: Leverages LINQ, pure functions, and functional composition
- **Direct Service Calls**: MCP Tools call services directly without abstraction layers
- **Thread Safety**: Static and instance-level synchronization for reliable parallel execution
- **Immutable Models**: Uses records and readonly properties where appropriate
### MCP Resources (Read-Only Data Access)
Resources provide URI-based access to passive data sources:
- **`doc://{symbolName}`** - .NET XML documentation lookup
- Example: `doc://System.String`, `doc://System.Linq.Enumerable.Select`
- **New:** Supports NuGet packages: `doc://{packageId}@{symbolName}`
- Example: `doc://Newtonsoft.Json@Newtonsoft.Json.JsonConvert`
- **`nuget://search?q={query}`** - Search NuGet packages
- Example: `nuget://search?q=json&take=10`
- **`nuget://packages/{id}/versions`** - Get package version list
- Example: `nuget://packages/Newtonsoft.Json/versions`
- **`nuget://packages/{id}/readme`** - Get package README
- Example: `nuget://packages/Newtonsoft.Json/readme?version=13.0.3`
- **`repl://state`** - General REPL information and capabilities
- **`repl://sessions`** - List active REPL sessions
- **`repl://sessions/{contextId}/state`** - Session-specific metadata
### MCP Tools (Active Operations)
Tools perform operations and can modify state. All tools support optional context management:
**Execution Tools:**
- **EvaluateCsharp** - Execute C# code to create and test single-file utility programs
- Optional `contextId` parameter for iterative development
- Returns `contextId` for session continuity
- **ValidateCsharp** - Validate C# syntax and semantics before execution
- Optional `contextId` for context-aware validation
- **ResetRepl** - Reset execution sessions
- Optional `contextId` to reset specific session or all sessions
- **GetReplInfo** - Get execution environment information and capabilities
- Optional `contextId` for session-specific state
- Returns framework version, capabilities, tips, and examples
**NuGet Tools:**
- **LoadNuGetPackage** - Load NuGet packages into REPL environment
- Packages persist in session until reset
- **SearchNuGetPackages** - Search for NuGet packages
- Parameters: `query`, `skip`, `take` for pagination
- Alternative to `nuget://search` resource for clients without resource support
- **GetNuGetPackageVersions** - Get all versions of a package
- Parameter: `packageId`
- Alternative to `nuget://packages/{id}/versions` resource
- **GetNuGetPackageReadme** - Get package README content
- Parameters: `packageId`, optional `version`
- Alternative to `nuget://packages/{id}/readme` resource
**Documentation Tools:**
- **GetDocumentation** - Get XML documentation for .NET types/methods
- Parameters: `symbolName`, optional `packageId`
- Alternative to `doc://` resource for clients without resource support
- Example: GetDocumentation("System.String") or GetDocumentation("JsonConvert", "Newtonsoft.Json")
> **Note:** Both Resources and Tools are provided for maximum client compatibility. Resources are preferred for passive data access, while Tools work in all MCP clients.
### MCP Prompts
Roslyn-Stone includes built-in prompts to help LLMs create single-file C# utility programs:
- **GetStartedWithCsharpRepl** - Comprehensive introduction to file-based C# apps, development workflow, and best practices
- **ReplBestPractices** - Patterns for creating single-file utilities with complete examples
- **WorkingWithPackages** - How to discover, evaluate, and use NuGet packages in utility programs
- **PackageIntegrationGuide** - Deep dive into package integration with detailed utility examples
These prompts provide detailed guidance on creating runnable .cs files, including examples, common patterns, and tips for success.
## What Can It Do?
Once configured, your AI assistant can help you create single-file C# utility programs aligned with .NET 10's file-based app feature:
**Build a simple utility:**
```
User: "Create a utility that lists files in the current directory"
Assistant: [Calls EvaluateCsharp with complete file-based app code]
β Returns complete .cs file using top-level statements
β Can be run directly with: dotnet run utility.cs
```
**Create self-contained apps with packages:**
```
User: "Create a JSON formatter utility"
Assistant:
1. [Searches packages: nuget://search?q=json]
2. [Tests with nugetPackages parameter: EvaluateCsharp(..., nugetPackages: [{packageName: "Newtonsoft.Json", version: "13.0.3"}])]
3. [Returns complete json-formatter.cs with #:package directive]
β Complete self-contained app:
#:package Newtonsoft.Json@13.0.3
using Newtonsoft.Json;
// ... utility code ...
β Run with: dotnet run json-formatter.cs (no .csproj needed!)
```
**Query documentation for .NET types:**
```
User: "Show me how to use System.String.Split"
Assistant: [Option 1: Reads doc://System.String.Split resource]
[Option 2: Calls GetDocumentation("System.String.Split")]
β Returns XML documentation with summary, parameters, examples
```
**Validate before execution:**
```
User: "Check if this C# code is valid: <code>"
Assistant: [Calls ValidateCsharp with code]
β Returns syntax validation results with detailed diagnostics
```
**Iterative development with context:**
```
User: "Start a CSV processor utility"
Assistant: [EvaluateCsharp with createContext=true, nugetPackages: CsvHelper]
β Returns contextId for session
User: "Add filtering by date"
Assistant: [EvaluateCsharp with contextId, adds filtering logic]
β Builds incrementally on previous code
```
The AI assistant creates complete, runnable single-file C# programs using .NET 10's modern syntaxβno class, Main method, or project file boilerplate needed.
## For Developers
Want to contribute, run from source, or learn more about the internals? Check out our comprehensive [Getting Started Guide](GETTING_STARTED.md) for:
- Building from source
- Development environment setup
- Running tests and benchmarks
- Adding new MCP tools
- Debugging with MCP Inspector
- Architecture details
## Security Considerations
β οΈ **Important**: This is a code execution service. Deploy with appropriate security measures:
- Run in isolated containers/sandboxes
- Implement rate limiting
- Add authentication/authorization
- Restrict network access
- Monitor resource usage
- Use read-only file systems where possible
## Future Enhancements
- [x] Full NuGet package resolution and loading
- [x] Docker container support
- [x] OpenTelemetry integration
- [ ] Persistent REPL sessions with user isolation
- [ ] Code snippet history and caching
- [ ] Syntax highlighting and IntelliSense data
- [ ] WebSocket support for interactive sessions
- [ ] Multi-architecture container images (amd64, arm64)
## Contributing
Contributions are welcome! Please see our [Getting Started Guide](GETTING_STARTED.md) for development setup instructions. Feel free to submit issues and pull requests.
## License
See [LICENSE](LICENSE) file for details.
## Recommended Pairing: Microsoft Learn MCP
For the best experience creating C# utility programs, **we recommend using Roslyn-Stone alongside the Microsoft Learn MCP server** ([github.com/microsoftdocs/mcp](https://github.com/microsoftdocs/mcp)).
**Why pair these tools?**
- **Roslyn-Stone**: Provides C# code execution, validation, and package loading for building utilities
- **Microsoft Learn MCP**: Provides comprehensive .NET documentation, API references, and code samples from official Microsoft Learn
**Together they enable:**
1. **Search official docs** (Microsoft Learn MCP) β **Find APIs** β **Test with C# code** (Roslyn-Stone)
2. **Get code samples** (Microsoft Learn) β **Execute and validate** (Roslyn-Stone) β **Build utility**
3. **Look up .NET types** (both) β **Understand usage** (Learn docs) β **Test implementation** (Roslyn-Stone)
**Example workflow:**
```
User: "Create a utility to parse JSON files"
Assistant:
1. [microsoft-learn MCP: Searches for JSON documentation]
2. [microsoft-learn MCP: Gets System.Text.Json code samples]
3. [roslyn-stone: Tests code with EvaluateCsharp]
4. [roslyn-stone: Returns complete json-parser.cs]
β Best of both worlds: Official docs + live execution
```
**Setup both servers:**
```json
{
"mcpServers": {
"roslyn-stone": {
"command": "docker",
"args": ["run", "-i", "--rm", "ghcr.io/dylanlangston/roslyn-stone:latest"]
},
"microsoft-learn": {
"command": "npx",
"args": ["-y", "@microsoft/docs-mcp-server"]
}
}
}
```
This combination provides comprehensive .NET documentation alongside live C# execution for the ultimate utility program development experience.
## Learn More
- [Getting Started Guide](GETTING_STARTED.md) - Development and contribution guide
- [MCP Architecture](MCP_ARCHITECTURE.md) - Detailed design documentation for file-based C# apps
- [Model Context Protocol (MCP)](https://github.com/modelcontextprotocol/specification)
- [Microsoft Learn MCP](https://github.com/microsoftdocs/mcp) - Official .NET documentation MCP server (recommended pairing)
- [Roslyn Scripting APIs](https://learn.microsoft.com/en-us/archive/msdn-magazine/2016/january/essential-net-csharp-scripting)
- [Dynamic Compilation Best Practices](DYNAMIC_COMPILATION_BEST_PRACTICES.md)
- [.NET 10 File-Based Apps](https://devblogs.microsoft.com/dotnet/announcing-dotnet-run-app/) - Official blog post about `dotnet run app.cs`
|