The FSharp.MCP.DevKit.CodeEditing module provides comprehensive F# Interactive (FSI) integration and code manipulation tools through the Model Context Protocol (MCP). This module serves as the bridge between AI assistants and F# development workflows.
This module consolidates all F# Interactive operations, code analysis, and system management tools into a unified MCP server implementation. It provides safe, validated, and efficient F# development capabilities through structured tool categories.
The module is organized into several key components:
FsiMcpService- Central service managing FSI pipe server and client connections- Helper Functions - Diagnostic formatting and file validation utilities
FSharpREPLTools- F# Interactive session management and code executionFSharpEnvironmentTools- Package and environment managementFSharpAnalysisTools- Code analysis and validationSystemManagementTools- Process and server management
- Persistent Sessions: Stateful F# Interactive session management
- Automatic Initialization: Common namespaces pre-loaded (
System,System.IO,System.Collections.Generic) - Pipe Communication: High-performance named pipe IPC
- Timeout Configuration: Configurable operation timeouts (default: 30 seconds)
- Resource Management: Proper disposal and cleanup of resources
- Code Execution: Execute arbitrary F# code with comprehensive error handling
- Expression Evaluation: Evaluate F# expressions with full type information
- Session State: Get current bindings and session state
- Session Reset: Clear all state while maintaining the session
- Server Status: Check FSI server availability and health
- Script Loading: Load F# script files with dependency tracking
- Assembly References: Add .NET assembly references dynamically
- NuGet Packages: Reference NuGet packages with version support
- Search Paths: Manage F# compiler search paths
- Syntax Validation: Parse and validate F# code for errors
- File Analysis: Comprehensive F# file structure analysis
- Diagnostic Reporting: Detailed error and warning information
- Performance Metrics: Line counts, character counts, and analysis summaries
- Process Management: Terminate MCP server processes
- Clean Shutdown: Graceful service termination
- Resource Cleanup: Automatic disposal of system resources
| Tool | Description | Parameters |
|---|---|---|
fsi-execute |
Execute F# code in FSI session | code: string, timeoutSeconds: int? |
fsi-evaluate |
Evaluate F# expression with type info | expression: string, timeoutSeconds: int? |
fsi-get-state |
Get current FSI session bindings | timeoutSeconds: int? |
fsi-reset |
Reset FSI session, clearing all state | timeoutSeconds: int? |
fsi-status |
Check FSI server availability | None |
| Tool | Description | Parameters |
|---|---|---|
fsi-load-script |
Load F# script into FSI session | filePath: string, timeoutSeconds: int? |
fsi-reference-assembly |
Add .NET assembly reference | assemblyPath: string, timeoutSeconds: int? |
fsi-reference-nuget |
Add NuGet package reference | packageName: string, timeoutSeconds: int? |
fsi-add-path |
Add directory to F# search path | path: string, timeoutSeconds: int? |
| Tool | Description | Parameters |
|---|---|---|
code-validate |
Parse and validate F# code | code: string, timeoutSeconds: int? |
file-analyze |
Analyze F# file structure | filePath: string |
| Tool | Description | Parameters |
|---|---|---|
server-kill-all |
Terminate all MCP server processes | None |
// Execute simple F# code
fsi-execute "let x = 1 + 2; printfn \"Result: %d\" x"
// Evaluate expressions
fsi-evaluate "List.map ((*) 2) [1..5]"// Reference a NuGet package
fsi-reference-nuget "FSharp.Data"
// Reference an assembly
fsi-reference-assembly "System.Data.dll"
// Load a script file
fsi-load-script "MyUtilities.fsx"// Validate F# code syntax
code-validate "let add x y = x + y"
// Analyze a complete file
file-analyze "MyModule.fs"The module provides comprehensive error handling with:
- Structured Diagnostics: Full compiler diagnostic information
- Error Categorization: Errors vs. warnings with line numbers
- Context Preservation: Original error messages with enhanced formatting
- Configurable Timeouts: Per-operation timeout configuration
- Default Values: Sensible 30-second default timeouts
- Graceful Degradation: Clean timeout handling without resource leaks
- Automatic Cleanup: Proper disposal of FSI services and pipe connections
- Exception Handling: Comprehensive try-catch with logging
- State Consistency: Consistent state management across operations
The module validates and supports the following F# file types:
.fsx- F# Script files.fs- F# Source files.fsi- F# Signature files
- Timeout: 30 seconds for all operations
- Pipe Name: Configured via
PipeConfig.defaultConfig - FSI Config: Uses
FsiConfig.defaultConfig
- Full Microsoft.Extensions.Logging integration
- Structured logging with context information
- Error tracking and performance monitoring
- FSharp.MCP.DevKit.Core - FSI services and configurations
- FSharp.MCP.DevKit.Communication.IPC - Named pipe communication
- FSharp.MCP.DevKit.Analysis - Code analysis capabilities
- ModelContextProtocol.Server - MCP server framework
- Fantomas.Core - Code formatting (imported but not actively used in current implementation)
- F# Compiler Services - Via core FSI service layer
- Named Pipes - High-performance IPC communication
- .NET Process Management - System process control
- Always check FSI status before executing complex operations
- Use timeouts appropriately for long-running operations
- Validate code syntax before execution when possible
- Monitor diagnostics for code quality feedback
- Clean up resources using the kill-all tool when needed
- Leverage the consolidated API instead of direct FSI access
- Use structured error handling with diagnostic information
- Configure appropriate timeouts for your use case
- Monitor logging output for performance and debugging
- Test with file validation before processing F# files
Potential areas for future development:
- Fantomas Integration: Active code formatting capabilities
- Advanced Diagnostics: Enhanced error reporting and suggestions
- Performance Monitoring: Built-in performance metrics and profiling
- Session Persistence: Save and restore FSI session state
- Multi-target Support: Support for different F# versions and frameworks