Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/CodingWithCalvin.MCPServer.Server/RpcClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ public Task ShutdownAsync()
public Task<DocumentInfo?> GetActiveDocumentAsync() => Proxy.GetActiveDocumentAsync();
public Task<bool> OpenDocumentAsync(string path) => Proxy.OpenDocumentAsync(path);
public Task<bool> CloseDocumentAsync(string path, bool save) => Proxy.CloseDocumentAsync(path, save);
public Task<bool> SaveDocumentAsync(string path) => Proxy.SaveDocumentAsync(path);
public Task<string?> ReadDocumentAsync(string path) => Proxy.ReadDocumentAsync(path);
public Task<bool> WriteDocumentAsync(string path, string content) => Proxy.WriteDocumentAsync(path, content);
public Task<SelectionInfo?> GetSelectionAsync() => Proxy.GetSelectionAsync();
Expand Down
9 changes: 9 additions & 0 deletions src/CodingWithCalvin.MCPServer.Server/Tools/DocumentTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,15 @@ public async Task<string> CloseDocumentAsync(
return success ? $"Closed: {path}" : $"Document not found or failed to close: {path}";
}

[McpServerTool(Name = "document_save", Destructive = false, Idempotent = true)]
[Description("Save an open document in Visual Studio to disk.")]
public async Task<string> SaveDocumentAsync(
[Description("The full absolute path to the document. Must be open in VS. Get the path from document_list. Supports forward slashes (/) or backslashes (\\).")] string path)
{
var success = await _rpcClient.SaveDocumentAsync(path);
return success ? $"Saved: {path}" : $"Document not found or failed to save: {path}";
}

[McpServerTool(Name = "document_read", ReadOnly = true)]
[Description("Read the contents of a document. If the document is open in VS, reads the current editor buffer (including unsaved changes); otherwise reads from disk.")]
public async Task<string> ReadDocumentAsync(
Expand Down
1 change: 1 addition & 0 deletions src/CodingWithCalvin.MCPServer.Shared/RpcContracts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public interface IVisualStudioRpc
Task<DocumentInfo?> GetActiveDocumentAsync();
Task<bool> OpenDocumentAsync(string path);
Task<bool> CloseDocumentAsync(string path, bool save);
Task<bool> SaveDocumentAsync(string path);
Task<string?> ReadDocumentAsync(string path);
Task<bool> WriteDocumentAsync(string path, string content);
Task<SelectionInfo?> GetSelectionAsync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public interface IVisualStudioService
Task<DocumentInfo?> GetActiveDocumentAsync();
Task<bool> OpenDocumentAsync(string path);
Task<bool> CloseDocumentAsync(string path, bool save = true);
Task<bool> SaveDocumentAsync(string path);
Task<string?> ReadDocumentAsync(string path);
Task<bool> WriteDocumentAsync(string path, string content);
Task<SelectionInfo?> GetSelectionAsync();
Expand Down
1 change: 1 addition & 0 deletions src/CodingWithCalvin.MCPServer/Services/RpcServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ public async Task RequestShutdownAsync()
public Task<DocumentInfo?> GetActiveDocumentAsync() => _vsService.GetActiveDocumentAsync();
public Task<bool> OpenDocumentAsync(string path) => _vsService.OpenDocumentAsync(path);
public Task<bool> CloseDocumentAsync(string path, bool save) => _vsService.CloseDocumentAsync(path, save);
public Task<bool> SaveDocumentAsync(string path) => _vsService.SaveDocumentAsync(path);
public Task<string?> ReadDocumentAsync(string path) => _vsService.ReadDocumentAsync(path);
public Task<bool> WriteDocumentAsync(string path, string content) => _vsService.WriteDocumentAsync(path, content);
public Task<SelectionInfo?> GetSelectionAsync() => _vsService.GetSelectionAsync();
Expand Down
24 changes: 24 additions & 0 deletions src/CodingWithCalvin.MCPServer/Services/VisualStudioService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,30 @@ public async Task<bool> CloseDocumentAsync(string path, bool save = true)
return false;
}

public async Task<bool> SaveDocumentAsync(string path)
{
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
var dte = await GetDteAsync();

foreach (Document doc in dte.Documents)
{
try
{
if (PathsEqual(doc.FullName, path))
{
doc.Save();
return true;
}
}
catch (Exception ex)
{
VsixTelemetry.TrackException(ex);
}
}

return false;
}

public async Task<string?> ReadDocumentAsync(string path)
{
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
Expand Down
Loading