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, functioning essentially as a simple IDE made for AI users.
To build the SharpTools solution:
dotnet build SharpTools.sln
You can run SharpTools in two different server modes:
The SSE server hosts the tools on an HTTP endpoint.
# Navigate to the SseServer project directory
cd SharpTools.SseServer
# Run with default options (port 3001)
dotnet run
# Run with specific options
dotnet run -- --port 3005 --log-file ./logs/mcp-sse-server.log --log-level Debug
Key options:
--port <number>
: Port to listen on (default: 3001)--log-file <path>
: Path to a log file--log-level <level>
: Minimum log level (Verbose, Debug, Information, Warning, Error, Fatal)--load-solution <path>
: Path to a .sln file to load on startupThe Stdio server communicates over standard input/output. Configure it in your MCP client of choice.
VSCode Copilot example configuration:
"mcp": {
"servers": {
"SharpTools": {
"type": "stdio",
"command": "/path/to/repo/SharpToolsMCP/SharpTools.StdioServer/bin/Debug/net8.0/SharpTools.StdioServer",
"args": [
"--log-directory",
"/var/log/sharptools/",
"--log-level",
"Debug",
]
}
}
},
Key options:
--log-directory <path>
: Directory to store log files--log-level <level>
: Minimum log level--load-solution <path>
: Path to a .sln file to load on startupSharpTools exposes various functions via MCP that can be used by AI agents to analyze and modify C# code. Here are the key functions organized by category:
Begin by loading your solution:
SharpTool_LoadSolution
This initializes the workspace with a given .sln file and is the primary entry point for all operations.
After loading your solution, you can explore its structure:
SharpTool_LoadProject
This provides a detailed structural overview of a specific project within the loaded solution, including namespaces and types.
Explore code with these tools:
SharpTool_GetMembers
: Lists members of a type, including signatures and documentationSharpTool_ViewDefinition
: Displays the source code of a symbol with contextual informationSharpTool_ListImplementations
: Finds all implementations of an interface/abstract methodSharpTool_FindReferences
: Locates all usages of a symbol across the solutionSharpTool_SearchDefinitions
: Performs regex-based search across symbol declarationsSharpTool_AnalyzeComplexity
: Analyzes code complexity metricsModify code precisely with these tools:
SharpTool_AddMember
: Adds a new member to a specified typeSharpTool_OverwriteMember
: Replaces or deletes an existing memberSharpTool_RenameSymbol
: Renames a symbol and updates all referencesSharpTool_FindAndReplace
: Performs regex-based find and replace operationsSharpTool_MoveMember
: Moves a member from one type/namespace to anotherSharpTool_Undo
: Reverts the last applied change using Git integrationManage entire files with:
SharpTool_ReadRawFromRoslynDocument
: Reads the raw content of a fileSharpTool_CreateRoslynDocument
: Creates a new file with specified contentSharpTool_OverwriteRoslynDocument
: Overwrites an existing fileSharpTool_ReadTypesFromRoslynDocument
: Lists all types in a specific fileSharpTool_ManageUsings
: Reads or overwrites using directivesSharpTool_ManageAttributes
: Reads or overwrites attributesSharpTool_RequestNewTool
: Allows requesting new tools or featuresSharpTools provides several advantages over plain text code manipulation:
There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json
file so that it is available in all of your projects.
If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json
file.
To add a global MCP server go to Cursor Settings > MCP and click "Add new global MCP server".
When you click that button the ~/.cursor/mcp.json
file will be opened and you can add your server like this:
{
"mcpServers": {
"cursor-rules-mcp": {
"command": "npx",
"args": [
"-y",
"cursor-rules-mcp"
]
}
}
}
To add an MCP server to a project you can create a new .cursor/mcp.json
file or add it to the existing one. This will look exactly the same as the global MCP server example above.
Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.
The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.
You can also explictly ask the agent to use the tool by mentioning the tool name and describing what the function does.