Skip to content

EHotwagner/FSharp.MCP.DevKit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

43 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

FSharp.MCP.DevKit ๐Ÿš€

.NET F# MCP License

An experimental prototype of an F# development toolkit delivered via the Model Context Protocol (MCP). It provides F# Interactive (FSI) capabilities, code documentation, safe code manipulation, and analysis tools with language server features. Integration with the FAKE build system is under development.

โš ๏ธ Disclaimer (by EHotwagner)

The project is on hold for the moment since everything is moving very fast and it makes sense to wait for things to settle down a bit and see what makes sense then. Just this july update https://code.visualstudio.com/updates/v1_103 brought tons of new features that might change the workflow considerably.

This project has been developed with significant reliance on AI-driven tools. While it has proven to be surprisingly effectiveโ€”largely by leveraging robust libraries like F# Compiler Services and Fantomasโ€”it will contain inaccuracies or incomplete features. Especially regarding Documentation, the agent tends to insert tons of industry buzzword BS whenever you look away for a second. This project has been developed with significant reliance on AI-driven tools. While it has proven to be surprisingly effectiveโ€”largely by leveraging robust libraries like F# Compiler Services and Fantomasโ€”it will contain inaccuracies or incomplete features. Especially regarding Documentation, the agent tends to insert tons of industry buzzword BS whenever you look away for a second.

Please Note

Please Note

  • Code Verification: The entire codebase and its documentation have not been manually verified for correctness or completeness. However, the core features described should be functional (as in I have seen them work at least once).

  • Agent Stability: The AI agent's instructions are generally initially effective, but after it deviates, restarting the agent to reset its context is recommended.

  • DevEnvironment: This project has been developed in VSCode with GH Copilot, mostly using Claude Sonnet 4 and a bit of Gemini 2.5 Pro for planning and design. https://austen.info/blog/github-copilot-agent-mcp/

  • DevEnvironment: This project has been developed in VSCode with GH Copilot, mostly using Claude Sonnet 4 and a bit of Gemini 2.5 Pro for planning and design. https://austen.info/blog/github-copilot-agent-mcp/

  • Design: Documentation is written somewhat with REPL-driven development in mind, allowing for interactive code generation and testing. I am currently tending towards a more script-driven development approach, which allows for structured experimentation and reproducible testing. A new, more rigorous approach, Signature-Driven Development, is also being considered.

  • REPL works with hosted FSI sessions, which in this context are not easy to configure, a bit fragile with some Input, have no nice output (only MCP-Tools output terminal and agent chat window). Letting the agent start a standard fsi process in an agent observed terminal is of course possible but cumbersome in VSCode since terminal actions need approval. This project should be neutral to the chosen approach in the future. VsCode Insiders has microsoft/vscode#253103 which changes the ergonomics a lot. Needs consideration.

  • Get Started: There are no releases yet. For VSCode use this https://devblogs.microsoft.com/dotnet/build-a-model-context-protocol-mcp-server-in-csharp/ approach. Add the project to the mcp.json file. Later a dotnet tool might be the best way to distribute this project.

โœจ Features

๐Ÿ”ง F# Interactive Integration

  • Persistent FSI Session: Stateful F# Interactive session management
  • Code Execution: Execute F# code with comprehensive error handling and validation
  • Script Loading: Load and manage F# script files with dependency tracking
  • Package Management: Reference .NET assemblies and NuGet packages seamlessly
  • Expression Evaluation: Evaluate F# expressions with full type information

๐Ÿ“š Documentation Generation & Search

  • ๐Ÿ“ฆ Package Documentation: Generate comprehensive API docs for NuGet packages
  • ๐Ÿ” Smart Search: Search through generated documentation with context-aware results
  • ๐Ÿ“– API Reference: Create structured markdown documentation for modules and types
  • ๐Ÿ—๏ธ Project Documentation: Bulk documentation generation for entire F# projects
  • ๐Ÿ’พ Package Discovery: Browse and explore available NuGet packages in local cache
  • โš™๏ธ Configuration Management: Runtime configuration of documentation settings

โœ๏ธ Safe Code Manipulation

  • ๐Ÿ›ก๏ธ Safe Code Insertion: Insert F# code with AST validation and type checking
  • ๐ŸŽจ Code Formatting: Deep integration with Fantomas for consistent code formatting
  • ๐Ÿ” Structure Analysis: Analyze F# code structure, dependencies, and syntax
  • ๐Ÿ‘€ Preview Capabilities: Preview code changes before applying them
  • โšก Atomic Operations: Atomic file operations with backup/rollback support

๐Ÿง  Advanced Analysis Tools

  • ๐Ÿ” Symbol Detection: Advanced symbol detection and resolution

    • Powered by: SmartSymbolDetectionService - Uses F# Compiler Services to identify and resolve symbols, functions, types, and modules within F# code
    • How it works: Parses source code into AST, performs semantic analysis to resolve symbol bindings, their scope, and provides position-sensitive symbol lookup
    • MCP Tools: GetAllSymbols, GetSymbolAtPosition, WhatIsAtPosition, GetSymbolSignatureAtPosition
  • ๐Ÿ“Š Syntax Validation: Comprehensive F# syntax analysis and error reporting

    • Powered by: ParseAndCheckFSharpCode - Validates F# syntax and performs type checking with detailed diagnostics
    • How it works: Uses F# Compiler Services via IPC to parse source code, check for syntax errors, type mismatches, and compiler warnings with line-level error locations
  • ๐Ÿ—‚๏ธ Dependency Analysis: Track and analyze code dependencies and relationships

    • Powered by: AnalyzeCodeStructure - Provides basic file analysis including line count, character count, and diagnostic summaries
    • How it works: Performs F# Compiler Services parsing to identify errors, warnings, and structural issues in F# files
    • Current scope: File-level analysis rather than deep dependency graph analysis
  • ๐ŸŽฏ Position-Sensitive Analysis: Context-aware code analysis based on cursor position

๐Ÿ—๏ธ Architecture

The FSharp.MCP.DevKit follows a modular, layered architecture with clear separation of concerns:

โ”œโ”€โ”€ ๐Ÿ”ง FSharp.MCP.DevKit.Core/          # Foundation layer
โ”‚   โ”œโ”€โ”€ FSI session management & execution
โ”‚   โ”œโ”€โ”€ File system utilities & helpers  
โ”‚   โ””โ”€โ”€ Core types & configurations
โ”‚
โ”œโ”€โ”€ ๐Ÿ” FSharp.MCP.DevKit.Analysis/      # Code intelligence layer
โ”‚   โ”œโ”€โ”€ F# syntax validation & analysis
โ”‚   โ”œโ”€โ”€ Symbol detection & resolution
โ”‚   โ””โ”€โ”€ Code structure analysis
โ”‚
โ”œโ”€โ”€ ๐Ÿ“ก FSharp.MCP.DevKit.Communication/ # IPC infrastructure
โ”‚   โ”œโ”€โ”€ High-performance named pipes
โ”‚   โ””โ”€โ”€ Persistent REPL server
โ”‚
โ”œโ”€โ”€ โœ๏ธ FSharp.MCP.DevKit.CodeEditing/   # Code manipulation layer
โ”‚   โ”œโ”€โ”€ Safe code insertion & editing
โ”‚   โ”œโ”€โ”€ Fantomas formatting integration
โ”‚   โ””โ”€โ”€ Atomic file operations
โ”‚
โ”œโ”€โ”€ ๐Ÿ“š FSharp.MCP.DevKit.Documentation/ # Documentation generation
โ”‚   โ”œโ”€โ”€ .NET assembly analysis
โ”‚   โ”œโ”€โ”€ NuGet package documentation
โ”‚   โ””โ”€โ”€ Markdown API reference generation
โ”‚
โ””โ”€โ”€ ๐ŸŒ FSharp.MCP.DevKit.Server/        # MCP server & tools
    โ”œโ”€โ”€ MCP protocol implementation
    โ”œโ”€โ”€ 30+ specialized F# tools
    โ””โ”€โ”€ Server runtime & hosting

๐Ÿ”„ Data Flow Architecture

graph TB
    subgraph "๐Ÿค– AI Assistant Layer"
        Assistant["`**AI Assistant**
        (Claude, GPT, etc.)
        โ€ข F# Development Support
        โ€ข Code Generation
        โ€ข Interactive Analysis`"]
    end
    
    subgraph "๐Ÿ“ก MCP Protocol Layer"
        MCPServer["`**MCP Server**
        โ€ข 30+ F# Tools
        โ€ข Stdio Transport
        โ€ข JSON-RPC Protocol`"]
    end
    
    subgraph "๐ŸŒ Application Layer"
        Server["`**FSharp.MCP.DevKit.Server**
        โ€ข Tool Implementation
        โ€ข Request Routing
        โ€ข Error Handling`"]
    end
    
    subgraph "๐Ÿ› ๏ธ Service Layers"
        Documentation["`**๐Ÿ“š Documentation**
        โ€ข Package Documentation
        โ€ข API Reference Generation
        โ€ข Smart Search & Discovery`"]
        
        DocumentationTool["`**๐Ÿ”ง Documentation Tool**
        โ€ข CLI for Doc Generation`"]

        CodeEditing["`**โœ๏ธ Code Editing**
        โ€ข Safe Code Insertion
        โ€ข Fantomas Integration
        โ€ข Atomic Operations`"]
        
        Communication["`**๐Ÿ“ก Communication**
        โ€ข Named Pipes IPC
        โ€ข Concurrent Processing
        โ€ข REPL Server`"]
        
        Analysis["`**๐Ÿ” Analysis**
        โ€ข Symbol Detection
        โ€ข Syntax Validation
        โ€ข Structure Analysis`"]
    end
    
    subgraph "๐Ÿ”ง Foundation Layer"
        Core["`**FSharp.MCP.DevKit.Core**
        โ€ข FSI Session Management
        โ€ข File Operations
        โ€ข Configuration`"]
    end
    
    subgraph "๐Ÿ”— External Dependencies"
        FCS["`**F# Compiler Services**
        โ€ข Code Compilation
        โ€ข Type Checking
        โ€ข AST Analysis`"]
        
        Fantomas["`**Fantomas**
        โ€ข Code Formatting
        โ€ข Style Enforcement`"]
        
        FSI["`**F# Interactive**
        โ€ข Code Execution
        โ€ข REPL Environment`"]
    end
    
    %% Connections
    Assistant <--> MCPServer
    MCPServer <--> Server
    Server --> Documentation
    Server --> CodeEditing
    Server --> Communication
    Server --> Analysis
    Documentation --> Core
    DocumentationTool --> Documentation
    CodeEditing --> Core
    Communication --> Core
    Analysis --> Core
    
    %% External integrations
    Core --> FCS
    Core --> FSI
    CodeEditing --> Fantomas
    Analysis --> FCS
    Documentation --> FCS
    
    %% Styling
    classDef aiLayer fill:#4B0082,stroke:#ffffff,stroke-width:3px,color:#ffffff
    classDef mcpLayer fill:#8B0000,stroke:#ffffff,stroke-width:2px,color:#ffffff
    classDef appLayer fill:#000080,stroke:#ffffff,stroke-width:2px,color:#ffffff
    classDef serviceLayer fill:#006400,stroke:#ffffff,stroke-width:2px,color:#ffffff
    classDef foundationLayer fill:#2F4F4F,stroke:#ffffff,stroke-width:2px,color:#ffffff
    classDef externalDep fill:#FF8C00,stroke:#000000,stroke-width:2px,color:#000000
    
    class Assistant aiLayer
    class MCPServer mcpLayer
    class Server appLayer
    class Documentation,CodeEditing,Communication,Analysis,DocumentationTool serviceLayer
    class Core foundationLayer
    class FCS,Fantomas,FSI externalDep
Loading

๐Ÿ› ๏ธ MCP Tools Overview

The server provides 30+ specialized MCP tools organized into categories:

๐Ÿ“š Documentation Tools (New!)

  • GeneratePackageDocumentation - Generate comprehensive API docs for NuGet packages
  • GenerateProjectDocumentation - Bulk documentation for entire F# projects
  • SearchDocumentation - Search through generated documentation with context
  • ListCachedPackages - Browse available NuGet packages in local cache
  • ShowPackageInfo - Get detailed information about specific packages
  • SetDocumentationOutputDirectory - Configure documentation output settings
  • ShowDocumentationConfig - Display current documentation configuration

๐Ÿ”ง FSI Management

  • CheckFSIServerStatus - Check FSI server status and availability
  • ResetFSISession - Reset the FSI session clearing all state
  • RestartFSISession - Restart FSI session (stop and start fresh)
  • GetFSIState - Get current FSI state and bindings

โšก Code Execution

  • ExecuteFSharpCode - Execute F# code with comprehensive error handling
  • ExecuteFSharpCodeDetailed - Execute with detailed error information
  • EvaluateFSharpExpression - Evaluate expressions with type information
  • LoadFSharpScript - Load F# script files with dependency tracking
  • ReferenceAssembly - Reference .NET assemblies
  • ReferenceNuGetPackage - Reference NuGet packages dynamically
  • AddSearchPath - Add directories to F# search path

โœ๏ธ Code Manipulation & File Operations

  • InsertCode - Unified code insertion with validation and formatting
  • PreviewCodeInjection - Preview code changes before applying
  • FormatFile - Format entire F# files using Fantomas
  • DeleteLines - Delete specific lines from files
  • ReplaceTextRange - Replace text in specific line ranges
  • SearchAndReplace - Search and replace with pattern matching
  • MoveCodeBlock - Move code blocks between locations
  • GetLines - Extract specific lines for inspection
  • CountLines - Count lines and characters in files
  • SearchInFile - Search for patterns with line numbers

๐Ÿ” Analysis & Structure

  • AnalyzeCodeStructure - Analyze F# code structure and dependencies
  • ParseAndCheckFSharpCode - Parse and validate F# syntax and types
  • ParseSourceToAST - Parse code to Abstract Syntax Tree

๐Ÿ› ๏ธ Utility & Management

  • KillAll - Kill all MCP server processes for clean restarts (temporary till FAKE integration)

๐Ÿš€ Usage Examples

Documentation Generation

# Generate documentation for a NuGet package
GeneratePackageDocumentation "System.Text.Json" "./docs" true

# Search through generated documentation  
SearchDocumentation "./docs" "JsonSerializer"

# List available packages
ListCachedPackages "System"

Code Execution

// Execute F# code
ExecuteFSharpCode "let x = 1 + 2; printfn \"Result: %d\" x"

// Evaluate expressions with type info
EvaluateFSharpExpression "List.map ((*) 2) [1..5]"

// Reference packages
ReferenceNuGetPackage "FSharp.Data"

Safe Code Insertion

// Insert code with formatting, validation disabled by default for performance
InsertCode "let newFunction x = x * 2" "MyScript.fsx" 10 1 true false

// Enable validation for small, critical code pieces  
InsertCode "let helper = x + 1" "MyScript.fsx" 5 1 true true

// Preview changes first
PreviewCodeInjection "let helper = ..." "MyScript.fsx" 15

๐Ÿค– Agent Development Strategies

This project provides comprehensive strategies for AI agents to work effectively with F# development through different methodologies:

๐Ÿ“‹ Available Development Approaches

The toolkit supports multiple development philosophies, each optimized for different scenarios and agent capabilities:

Recommended for: Production workflows, complex validation, agent-driven development

Recommended for: Exploration, prototyping, interactive development

Recommended for: Contract-first development, rigorous validation, clear interfaces

Recommended for: Contract-first development, rigorous validation, clear interfaces

๐Ÿ“– Documentation

๐Ÿ“‚ Project Documentation

Comprehensive documentation organized by project:

๐Ÿ“‹ General Documentation

๏ฟฝ๏ธ Development Roadmap

๐ŸŽฏ Near-term Enhancements

๐Ÿ”„ Currently In Progress:

  • ๐Ÿ“š Cross-reference linking - Automatic linking between types in documentation (maybe https://marketplace.visualstudio.com/items?itemName=foam.foam-vscode )
  • Fake Integration
  • Planning Tools - Adding some deterministic planning tools and Knowledge bases to help the AI agent generate more structured code.
  • Increase performance and robustness of text, file handling and code insertion.

๏ฟฝ๐Ÿ”— Key Technologies

  • F# Compiler Services - F# language analysis and compilation
  • Fantomas - F# code formatting
  • Model Context Protocol - AI assistant integration protocol
  • Named Pipes - High-performance inter-process communication
  • .NET 9.0 - Modern .NET runtime and libraries

For current development status and known issues, see:

๏ฟฝ Communication & Contact

We welcome your feedback, questions, and contributions! Here's how to get in touch:

๐ŸŽฎ Discord Community

Join the F# community discussions:

๐Ÿ› Issues & Bug Reports

Found a bug or have a feature request?

  • GitHub Issues - Report bugs, request features, or ask questions

๏ฟฝ๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ”— Resources


๐Ÿ“š Documentation โ€ข ๐Ÿ› ๏ธ Tools โ€ข ๐Ÿ—๏ธ Architecture

Built with โค๏ธ using F# and the Model Context Protocol

About

Experimental prototype of an F# development toolkit delivered via the Model Context Protocol (MCP).

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors