Skip to content
Back to search

SharpToolsMCP

A suite of MCP tools for AIs to analyze and modify C# solutions with high signal, Roslyn powered context.

Safety scan

A static text scan, not a guarantee. Select the badge to see what was scanned and every finding.

Checked today
Badge for your README
findsafeskills safety rating

Markdown

[![findsafeskills safety rating](/api/listings/kooshi--sharptoolsmcp/badge.svg)](/listings/kooshi--sharptoolsmcp)

HTML

<a href="/listings/kooshi--sharptoolsmcp"><img src="/api/listings/kooshi--sharptoolsmcp/badge.svg" alt="findsafeskills safety rating" /></a>

Install

i

What was scanned

The files the safety scan read, as written by the repository's author and shown as plain text. Lines with a finding are marked.

README.md · README · 184 lines

View this file on GitHub (read at the repository's current version: the scan did not record which commit it read)

  1. # SharpTools: Roslyn Powered C# Analysis & Modification MCP Server
  2. SharpTools is a robust service designed to empower AI agents with advanced capabilities for understanding, analyzing, and modifying C# codebases. It leverages the .NET Compiler Platform (Roslyn) to provide deep static analysis and precise code manipulation, going far beyond simple text-based operations.
  3. SharpTools is designed to give AI the same insights and tools a human developer relies on, leading to more intelligent and reliable code assistance. It is effectively a simple IDE, made for an AI user.
  4. Due to the comprehensive nature of the suite, it can almost be used completely standalone for editing existing C# solutions. If you use the SSE server and port forward your router, I think it's even possible to have Claude's web chat ui connect to this and have it act as a full coding assistant.
  5. ## Prompts
  6. The included [Identity Prompt](Prompts/identity.prompt) is my personal C# coding assistant prompt, and it works well in combination with this suite. You're welcome to use it as is, modify it to match your preferences, or omit it entirely.
  7. In VS Code, set it as your `copilot-instructions.md` to have it included in every interaction.
  8. The [Tool Use Prompt](Prompts/github-copilot-sharptools.prompt) is fomulated specifically for Github Copilot's Agent mode. It overrides specific sections within the Copilot Agent System Prompt so that it avoids the built in tools.
  9. It is available as an MCP prompt as well, so within Copilot, you just need to type `/mcp`, and it should show up as an option.
  10. Something similar will be necessary for other coding assistants to prevent them from using their own default editing tools.
  11. I recommend crafting custom tool use prompts for each agent you use this with, based on their [individual system prompts](https://github.com/x1xhlol/system-prompts-and-models-of-ai-tools).
  12. ## Note
  13. This is a personal project, slapped together over a few weeks, and built in no small part by its own tools. It generally works well as it is, but the code is still fairly ugly, and some of the features are still quirky (like removing newlines before and after overwritten members).
  14. I intend to maintain and improve it for as long as I am using it, and I welcome feedback and contributions as a part of that.
  15. ## Features
  16. * **Dynamic Project Structure Mapping:** Generates a "map" of the solution, detailing namespaces and types, with complexity-adjusted resolution.
  17. * **Contextual Navigation Aids:** Provides simplified call graphs and dependency trees for local code understanding.
  18. * **Token Efficient Operation** Designed to provide only the highest signal context at every step to keep your agent on track longer without being overwhelmed or requiring summarization.
  19. * All indentation is omitted in returned code, saving roughly 10% of tokens without affecting performance on the smartest models.
  20. * FQN based navigation means the agent rarely needs to read unrelated code.
  21. * **FQN Fuzzy Matching:** Intelligently resolves potentially imprecise or incomplete Fully Qualified Names (FQNs) to exact Roslyn symbols.
  22. * **Comprehensive Source Resolution:** Retrieves source code for symbols from:
  23. * Local solution files.
  24. * External libraries via SourceLink.
  25. * Embedded PDBs.
  26. * Decompilation (ILSpy-based) as a fallback.
  27. * **Precise, Roslyn-Based Modifications:** Enables surgical code changes (add/overwrite/rename/move members, find/replace) rather than simple text manipulation.
  28. * **Automated Git Integration:**
  29. * Creates dedicated, timestamped `sharptools/` branches for all modifications.
  30. * Automatically commits every code change with a descriptive message.
  31. * Offers a Git-powered `Undo` for the last modification.
  32. * **Concise AI Feedback Loop:**
  33. * Confirms changes with precise diffs instead of full code blocks.
  34. * Provides immediate, in-tool compilation error reports after modifications.
  35. * **Proactive Code Quality Analysis:**
  36. * Detects and warns about high code complexity (cyclomatic, cognitive).
  37. * Identifies semantically similar code to flag potential duplicates upon member addition.
  38. * **Broad Project Support:**
  39. * Runs on Windows and Linux (and probably Mac)
  40. * Can analyze projects targeting any .NET version, from Framework to Core to 5+
  41. * Compatible with both modern SDK-style and legacy C# project formats.
  42. * Respects `.editorconfig` settings for consistent code formatting.
  43. * **MCP Server Interface:** Exposes tools via Model Context Protocol (MCP) through:
  44. * Server-Sent Events (SSE) for remote clients.
  45. * Standard I/O (Stdio) for local process communication.
  46. ## Exposed Tools
  47. SharpTools exposes a variety of "SharpTool_*" functions via MCP. Here's a brief overview categorized by their respective service files:
  48. ### Solution Tools
  49. * `SharpTool_LoadSolution`: Initializes the workspace with a given `.sln` file. This is the primary entry point.
  50. * `SharpTool_LoadProject`: Provides a detailed structural overview of a specific project within the loaded solution, including namespaces and types, to aid AI understanding of the project's layout.
  51. ### Analysis Tools
  52. * `SharpTool_GetMembers`: Lists members (methods, properties, etc.) of a type, including signatures and XML documentation.
  53. * `SharpTool_ViewDefinition`: Displays the source code of a symbol (class, method, etc.), including contextual information like call graphs or type references.
  54. * `SharpTool_ListImplementations`: Finds all implementations of an interface/abstract method or derived classes of a base class.
  55. * `SharpTool_FindReferences`: Locates all usages of a symbol across the solution, providing contextual code snippets.
  56. * `SharpTool_SearchDefinitions`: Performs a regex-based search across symbol declarations and signatures in both source code and compiled assemblies.
  57. * `SharpTool_ManageUsings`: Reads or overwrites using directives in a document.
  58. * `SharpTool_ManageAttributes`: Reads or overwrites attributes on a specific declaration.
  59. * `SharpTool_AnalyzeComplexity`: Performs complexity analysis (cyclomatic, cognitive, coupling, etc.) on methods, classes, or projects.
  60. * ~(Disabled) `SharpTool_GetAllSubtypes`: Recursively lists all nested members of a type.~
  61. * ~(Disabled) `SharpTool_ViewInheritanceChain`: Shows the inheritance hierarchy for a type.~
  62. * ~(Disabled) `SharpTool_ViewCallGraph`: Displays incoming and outgoing calls for a method.~
  63. * ~(Disabled) `SharpTool_FindPotentialDuplicates`: Finds semantically similar methods or classes.~
  64. ### Document Tools
  65. * `SharpTool_ReadRawFromRoslynDocument`: Reads the raw content of a file (indentation omitted).
  66. * `SharpTool_CreateRoslynDocument`: Creates a new file with specified content.
  67. * `SharpTool_OverwriteRoslynDocument`: Overwrites an existing file with new content.
  68. * `SharpTool_ReadTypesFromRoslynDocument`: Lists all types and their members defined within a specific source file.
  69. ### Modification Tools
  70. * `SharpTool_AddMember`: Adds a new member (method, property, field, nested type, etc.) to a specified type.
  71. * `SharpTool_OverwriteMember`: Replaces the definition of an existing member or type with new code, or deletes it.
  72. * `SharpTool_RenameSymbol`: Renames a symbol and updates all its references throughout the solution.
  73. * `SharpTool_FindAndReplace`: Performs regex-based find and replace operations within a specified symbol's declaration or across files matching a glob pattern.
  74. * `SharpTool_MoveMember`: Moves a member from one type/namespace to another.
  75. * `SharpTool_Undo`: Reverts the last applied change using Git integration.
  76. * ~(Disabled) `SharpTool_ReplaceAllReferences`: Replaces all references to a symbol with specified C# code.~
  77. ### Package Tools
  78. * ~(Disabled) `SharpTool_AddOrModifyNugetPackage`: Adds or updates a NuGet package reference in a project file.~
  79. ### Misc Tools
  80. * `SharpTool_RequestNewTool`: Allows the AI to request new tools or features, logging the request for human review.
  81. ## Prerequisites
  82. * .NET 8+ SDK for running the server
  83. * The .NET SDK of your target solution
  84. ## Building
  85. To build the entire solution:
  86. ```bash
  87. dotnet build SharpTools.sln
  88. ```
  89. This will build all services and server applications.
  90. ## Running the Servers
  91. ### SSE Server (HTTP)
  92. The SSE server hosts the tools on an HTTP endpoint.
  93. ```bash
  94. # Navigate to the SseServer project directory
  95. cd SharpTools.SseServer
  96. # Run with default options (port 3001)
  97. dotnet run
  98. # Run with specific options
  99. dotnet run -- --port 3005 --log-file ./logs/mcp-sse-server.log --log-level Debug
  100. ```
  101. Key Options:
  102. * `--port <number>`: Port to listen on (default: 3001).
  103. * `--log-file <path>`: Path to a log file.
  104. * `--log-level <level>`: Minimum log level (Verbose, Debug, Information, Warning, Error, Fatal).
  105. * `--load-solution <path>`: Path to a `.sln` file to load on startup. Useful for manual testing. It is recommended to let the AI run the LoadSolution tool instead, as it returns some useful information.
  106. * `--build-configuration <config>`: Build configuration to use when loading the solution (e.g., `Debug`, `Release`).
  107. * `--disable-git`: Disables all Git integration features.
  108. ### Stdio Server
  109. The Stdio server communicates over standard input/output.
  110. Configure it in your MCP client of choice.
  111. VSCode Copilot example:
  112. ```json
  113. "mcp": {
  114. "servers": {
  115. "SharpTools": {
  116. "type": "stdio",
  117. "command": "/path/to/repo/SharpToolsMCP/SharpTools.StdioServer/bin/Debug/net8.0/SharpTools.StdioServer",
  118. "args": [
  119. "--log-directory",
  120. "/var/log/sharptools/",
  121. "--log-level",
  122. "Debug",
  123. ]
  124. }
  125. }
  126. },
  127. ```
  128. Key Options:
  129. * `--log-directory <path>`: Directory to store log files.
  130. * `--log-level <level>`: Minimum log level.
  131. * `--load-solution <path>`: Path to a `.sln` file to load on startup. Useful for manual testing. It is recommended to let the AI run the LoadSolution tool instead, as it returns some useful information.
  132. * `--build-configuration <config>`: Build configuration to use when loading the solution (e.g., `Debug`, `Release`).
  133. * `--disable-git`: Disables all Git integration features.
  134. ## Contributing
  135. Contributions are welcome! Please feel free to submit pull requests or open issues.
  136. ## License
  137. This project is licensed under the MIT License - see the LICENSE file for details.

Ratings and comments

Sign in to rate this skill.

Sign in

Free to use. If it’s helped, pass it on.