-
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathSolutionTools.cs
More file actions
96 lines (82 loc) · 4.09 KB
/
SolutionTools.cs
File metadata and controls
96 lines (82 loc) · 4.09 KB
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
using System.ComponentModel;
using System.Text.Json;
using System.Threading.Tasks;
using ModelContextProtocol.Server;
namespace CodingWithCalvin.MCPServer.Server.Tools;
[McpServerToolType]
public class SolutionTools
{
private readonly RpcClient _rpcClient;
private readonly JsonSerializerOptions _jsonOptions;
public SolutionTools(RpcClient rpcClient)
{
_rpcClient = rpcClient;
_jsonOptions = new JsonSerializerOptions { WriteIndented = true };
}
[McpServerTool(Name = "solution_info", ReadOnly = true)]
[Description("Get information about the currently open solution in Visual Studio. Returns the solution name, full path, and whether it's open. Use this to verify a solution is loaded before performing other operations.")]
public async Task<string> GetSolutionInfoAsync()
{
var info = await _rpcClient.GetSolutionInfoAsync();
if (info == null)
{
return "No solution is currently open";
}
return JsonSerializer.Serialize(info, _jsonOptions);
}
[McpServerTool(Name = "solution_open", Destructive = true, Idempotent = true)]
[Description("Open a solution file in Visual Studio. This will close any currently open solution.")]
public async Task<string> OpenSolutionAsync(
[Description("The full absolute path to the solution file (.sln or .slnx). Supports forward slashes (/) or backslashes (\\).")] string path)
{
var success = await _rpcClient.OpenSolutionAsync(path);
return success ? $"Opened solution: {path}" : $"Failed to open solution: {path}";
}
[McpServerTool(Name = "solution_close", Destructive = true, Idempotent = true)]
[Description("Close the currently open solution in Visual Studio")]
public async Task<string> CloseSolutionAsync(
[Description("Whether to save changes before closing")] bool save = true)
{
await _rpcClient.CloseSolutionAsync(save);
return "Solution closed";
}
[McpServerTool(Name = "project_list", ReadOnly = true)]
[Description("Get a list of all projects in the current solution. Returns each project's Name, full Path (.csproj), and Kind (GUID). Use the Path value when calling build_project.")]
public async Task<string> GetProjectListAsync()
{
var projects = await _rpcClient.GetProjectsAsync();
if (projects.Count == 0)
{
return "No projects found (is a solution open?)";
}
return JsonSerializer.Serialize(projects, _jsonOptions);
}
[McpServerTool(Name = "startup_project_get", ReadOnly = true)]
[Description("Get the current startup project name. Returns the project that will be launched when debugging starts.")]
public async Task<string> GetStartupProjectAsync()
{
var startupProject = await _rpcClient.GetStartupProjectAsync();
return startupProject ?? "No startup project is set";
}
[McpServerTool(Name = "startup_project_set", Destructive = false)]
[Description("Set the startup project for debugging. Use project_list to get available project names.")]
public async Task<string> SetStartupProjectAsync(
[Description("The display name of the project to set as the startup project (e.g., 'MyProject'). Use project_list to see available project names.")] string name)
{
var success = await _rpcClient.SetStartupProjectAsync(name);
return success ? $"Startup project set to: {name}" : $"Failed to set startup project: {name}";
}
[McpServerTool(Name = "project_info", ReadOnly = true)]
[Description("Get detailed information about a specific project by its display name.")]
public async Task<string> GetProjectInfoAsync(
[Description("The display name of the project (e.g., 'MyProject'), not the full path. Use project_list to see available project names.")] string name)
{
var projects = await _rpcClient.GetProjectsAsync();
var project = projects.Find(p => p.Name == name);
if (project == null)
{
return $"Project not found: {name}";
}
return JsonSerializer.Serialize(project, _jsonOptions);
}
}