Skip to content

Commit 9124357

Browse files
committed
feat: ensuring tool success
1 parent 14bae03 commit 9124357

46 files changed

Lines changed: 1730 additions & 995 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 57 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22

33
**Let AI assistants like Claude control Visual Studio through the Model Context Protocol!**
44

5-
[![License](https://img.shields.io/github/license/CodingWithCalvin/VS-VSMCP?style=for-the-badge)](https://github.com/CodingWithCalvin/VS-VSMCP/blob/main/LICENSE)
6-
[![Build Status](https://img.shields.io/github/actions/workflow/status/CodingWithCalvin/VS-VSMCP/build.yml?style=for-the-badge)](https://github.com/CodingWithCalvin/VS-VSMCP/actions/workflows/build.yml)
7-
[![Marketplace Version](https://img.shields.io/visual-studio-marketplace/v/CodingWithCalvin.VS-VSMCP?style=for-the-badge)](https://marketplace.visualstudio.com/items?itemName=CodingWithCalvin.VS-VSMCP)
8-
[![Marketplace Installs](https://img.shields.io/visual-studio-marketplace/i/CodingWithCalvin.VS-VSMCP?style=for-the-badge)](https://marketplace.visualstudio.com/items?itemName=CodingWithCalvin.VS-VSMCP)
5+
[![License](https://img.shields.io/github/license/CodingWithCalvin/VS-MCPServer?style=for-the-badge)](https://github.com/CodingWithCalvin/VS-MCPServer/blob/main/LICENSE)
6+
[![Build Status](https://img.shields.io/github/actions/workflow/status/CodingWithCalvin/VS-MCPServer/build.yml?style=for-the-badge)](https://github.com/CodingWithCalvin/VS-MCPServer/actions/workflows/build.yml)
7+
[![Marketplace Version](https://img.shields.io/visual-studio-marketplace/v/CodingWithCalvin.VS-MCPServer?style=for-the-badge)](https://marketplace.visualstudio.com/items?itemName=CodingWithCalvin.VS-MCPServer)
8+
[![Marketplace Installs](https://img.shields.io/visual-studio-marketplace/i/CodingWithCalvin.VS-MCPServer?style=for-the-badge)](https://marketplace.visualstudio.com/items?itemName=CodingWithCalvin.VS-MCPServer)
9+
[![Marketplace Rating](https://img.shields.io/visual-studio-marketplace/r/CodingWithCalvin.VS-MCPServer?style=for-the-badge)](https://marketplace.visualstudio.com/items?itemName=CodingWithCalvin.VS-MCPServer)
910

1011
---
1112

@@ -16,54 +17,66 @@
1617
## ✨ Features
1718

1819
### 📂 Solution Tools
19-
- **solution_info** - Get information about the current solution
20-
- **solution_open** - Open a solution file
21-
- **solution_close** - Close the current solution
22-
- **project_list** - List all projects in the solution
23-
- **project_info** - Get detailed project information
20+
21+
| Tool | Description |
22+
|------|-------------|
23+
| `solution_info` | Get information about the current solution |
24+
| `solution_open` | Open a solution file |
25+
| `solution_close` | Close the current solution |
26+
| `project_list` | List all projects in the solution |
27+
| `project_info` | Get detailed project information |
2428

2529
### 📝 Document Tools
26-
- **document_list** - List all open documents
27-
- **document_active** - Get the active document
28-
- **document_open** - Open a file in the editor
29-
- **document_close** - Close a document
30-
- **document_read** - Read document contents
31-
- **document_write** - Write to a document
30+
31+
| Tool | Description |
32+
|------|-------------|
33+
| `document_list` | List all open documents |
34+
| `document_active` | Get the active document |
35+
| `document_open` | Open a file in the editor |
36+
| `document_close` | Close a document |
37+
| `document_read` | Read document contents |
38+
| `document_write` | Write to a document |
3239

3340
### ✏️ Editor Tools
34-
- **selection_get** - Get the current text selection
35-
- **selection_set** - Set the selection range
36-
- **editor_insert** - Insert text at cursor position
37-
- **editor_replace** - Find and replace text
38-
- **editor_goto_line** - Navigate to a specific line
39-
- **editor_find** - Search within documents
41+
42+
| Tool | Description |
43+
|------|-------------|
44+
| `selection_get` | Get the current text selection |
45+
| `selection_set` | Set the selection range |
46+
| `editor_insert` | Insert text at cursor position |
47+
| `editor_replace` | Find and replace text |
48+
| `editor_goto_line` | Navigate to a specific line |
49+
| `editor_find` | Search within documents |
4050

4151
### 🔨 Build Tools
42-
- **build_solution** - Build the entire solution
43-
- **build_project** - Build a specific project
44-
- **clean_solution** - Clean the solution
45-
- **build_cancel** - Cancel a running build
46-
- **build_status** - Get current build status
52+
53+
| Tool | Description |
54+
|------|-------------|
55+
| `build_solution` | Build the entire solution |
56+
| `build_project` | Build a specific project |
57+
| `clean_solution` | Clean the solution |
58+
| `build_cancel` | Cancel a running build |
59+
| `build_status` | Get current build status |
4760

4861
## 🛠️ Installation
4962

5063
### Visual Studio Marketplace
5164

5265
1. Open Visual Studio 2022 or 2026
5366
2. Go to **Extensions > Manage Extensions**
54-
3. Search for "VS MCP Server"
67+
3. Search for "MCP Server"
5568
4. Click **Download** and restart Visual Studio
5669

5770
### Manual Installation
5871

59-
Download the latest `.vsix` from the [Releases](https://github.com/CodingWithCalvin/VS-VSMCP/releases) page and double-click to install.
72+
Download the latest `.vsix` from the [Releases](https://github.com/CodingWithCalvin/VS-MCPServer/releases) page and double-click to install.
6073

6174
## 🚀 Usage
6275

6376
### Starting the Server
6477

6578
1. Open Visual Studio
66-
2. Go to **Tools > VSMCP > Start Server** (or enable auto-start in settings)
79+
2. Go to **Tools > MCP Server > Start Server** (or enable auto-start in settings)
6780
3. The MCP server starts on `http://localhost:5050`
6881

6982
### Configuring Claude Desktop
@@ -74,26 +87,32 @@ Add this to your Claude Desktop MCP settings:
7487
{
7588
"mcpServers": {
7689
"visual-studio": {
77-
"url": "http://localhost:5050"
90+
"url": "http://localhost:5050/sse"
7891
}
7992
}
8093
}
8194
```
8295

8396
### Settings
8497

85-
Configure the extension at **Tools > Options > VSMCP**:
98+
Configure the extension at **Tools > Options > MCP Server**:
8699

87-
- **Auto-start server** - Start the MCP server when Visual Studio launches
88-
- **HTTP Port** - Port for the MCP server (default: 5050)
100+
| Setting | Description | Default |
101+
|---------|-------------|---------|
102+
| Auto-start server | Start the MCP server when Visual Studio launches | Off |
103+
| Binding Address | Address the server binds to | `localhost` |
104+
| HTTP Port | Port for the MCP server | `5050` |
105+
| Server Name | Name reported to MCP clients | `Visual Studio MCP` |
106+
| Log Level | Minimum log level for output | `Information` |
107+
| Log Retention | Days to keep log files | `7` |
89108

90109
## 🏗️ Architecture
91110

92111
```
93-
┌─────────────────┐ ┌─────────────────────┐ named pipes ┌─────────────────┐
94-
Claude Desktop HTTP/SSE │ VSMCP.Server.exe │ ◄────────────────► │ VS Extension
95-
(MCP Client) │ ◄────────────► │ (MCP Server) JSON-RPC (Tool Impl)
96-
└─────────────────┘ :5050 └─────────────────────┘ └─────────────────┘
112+
+------------------+ +----------------------+ named pipes +------------------+
113+
| Claude Desktop | HTTP/SSE | MCPServer.Server | <-------------> | VS Extension |
114+
| (MCP Client) | <---------> | (MCP Server) | JSON-RPC | (Tool Impl) |
115+
+------------------+ :5050 +----------------------+ +------------------+
97116
```
98117

99118
## 🤝 Contributing
@@ -103,7 +122,7 @@ Contributions are welcome! Whether it's bug reports, feature requests, or pull r
103122
### Development Setup
104123

105124
1. Clone the repository
106-
2. Open `src/CodingWithCalvin.VSMCP.slnx` in Visual Studio 2022
125+
2. Open `src/CodingWithCalvin.MCPServer.slnx` in Visual Studio 2022
107126
3. Ensure you have the "Visual Studio extension development" workload installed
108127
4. Ensure you have .NET 10.0 SDK installed
109128
5. Press F5 to launch the experimental instance

assets/logo.png

945 KB
Loading

resources/publish.manifest.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"$schema": "http://json.schemastore.org/vsix-publish",
3+
"categories": [
4+
"coding",
5+
"other"
6+
],
7+
"identity": {
8+
"internalName": "VS-VSMCP"
9+
},
10+
"overview": "../README.md",
11+
"publisher": "CodingWithCalvin",
12+
"qna": true,
13+
"repo": "https://www.github.com/CodingWithCalvin/VS-VSMCP"
14+
}

src/CodingWithCalvin.VSMCP.Server/CodingWithCalvin.VSMCP.Server.csproj renamed to src/CodingWithCalvin.MCPServer.Server/CodingWithCalvin.MCPServer.Server.csproj

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@
66
<LangVersion>latest</LangVersion>
77
<Nullable>enable</Nullable>
88
<ImplicitUsings>disable</ImplicitUsings>
9-
<RootNamespace>CodingWithCalvin.VSMCP.Server</RootNamespace>
10-
<AssemblyName>CodingWithCalvin.VSMCP.Server</AssemblyName>
9+
<RootNamespace>CodingWithCalvin.MCPServer.Server</RootNamespace>
10+
<AssemblyName>CodingWithCalvin.MCPServer.Server</AssemblyName>
11+
<PublishSingleFile>true</PublishSingleFile>
12+
<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
13+
<SatelliteResourceLanguages>en</SatelliteResourceLanguages>
1114
</PropertyGroup>
1215

1316
<ItemGroup>
@@ -18,7 +21,7 @@
1821
</ItemGroup>
1922

2023
<ItemGroup>
21-
<ProjectReference Include="..\CodingWithCalvin.VSMCP.Shared\CodingWithCalvin.VSMCP.Shared.csproj" />
24+
<ProjectReference Include="..\CodingWithCalvin.MCPServer.Shared\CodingWithCalvin.MCPServer.Shared.csproj" />
2225
</ItemGroup>
2326

2427
</Project>
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
using System;
2+
using System.CommandLine;
3+
using System.Threading;
4+
using System.Threading.Tasks;
5+
using CodingWithCalvin.MCPServer.Server;
6+
using CodingWithCalvin.MCPServer.Server.Tools;
7+
using Microsoft.AspNetCore.Builder;
8+
using Microsoft.Extensions.DependencyInjection;
9+
using Microsoft.Extensions.Hosting;
10+
using Microsoft.Extensions.Logging;
11+
using ModelContextProtocol.AspNetCore;
12+
using ModelContextProtocol.Protocol;
13+
using ModelContextProtocol.Server;
14+
15+
var pipeOption = new Option<string>(
16+
name: "--pipe",
17+
description: "Named pipe name for connecting to Visual Studio")
18+
{
19+
IsRequired = true
20+
};
21+
22+
var hostOption = new Option<string>(
23+
name: "--host",
24+
getDefaultValue: () => "localhost",
25+
description: "Host address to bind the HTTP server to (e.g., localhost, 0.0.0.0, *)");
26+
27+
var portOption = new Option<int>(
28+
name: "--port",
29+
getDefaultValue: () => 5050,
30+
description: "HTTP port for the MCP server");
31+
32+
var nameOption = new Option<string>(
33+
name: "--name",
34+
getDefaultValue: () => "Visual Studio MCP",
35+
description: "Server name displayed to MCP clients");
36+
37+
var logLevelOption = new Option<string>(
38+
name: "--log-level",
39+
getDefaultValue: () => "Information",
40+
description: "Minimum log level (Error, Warning, Information, Debug)");
41+
42+
var rootCommand = new RootCommand("Visual Studio MCP Server")
43+
{
44+
pipeOption,
45+
hostOption,
46+
portOption,
47+
nameOption,
48+
logLevelOption
49+
};
50+
51+
rootCommand.SetHandler(async (string pipeName, string host, int port, string serverName, string logLevel) =>
52+
{
53+
await RunServerAsync(pipeName, host, port, serverName, logLevel);
54+
}, pipeOption, hostOption, portOption, nameOption, logLevelOption);
55+
56+
return await rootCommand.InvokeAsync(args);
57+
58+
static async Task RunServerAsync(string pipeName, string host, int port, string serverName, string logLevel)
59+
{
60+
// Parse log level
61+
var msLogLevel = logLevel switch
62+
{
63+
"Error" => LogLevel.Error,
64+
"Warning" => LogLevel.Warning,
65+
"Debug" => LogLevel.Debug,
66+
_ => LogLevel.Information
67+
};
68+
69+
// Create shutdown token for graceful shutdown
70+
using var shutdownCts = new CancellationTokenSource();
71+
72+
// Connect to Visual Studio via named pipe
73+
var rpcClient = new RpcClient(shutdownCts);
74+
await rpcClient.ConnectAsync(pipeName);
75+
76+
Console.Error.WriteLine($"Connected to Visual Studio via pipe: {pipeName}");
77+
78+
// Build the web application
79+
var builder = WebApplication.CreateBuilder();
80+
81+
// Configure logging
82+
builder.Logging.SetMinimumLevel(msLogLevel);
83+
builder.Logging.AddFilter("Microsoft.AspNetCore", msLogLevel);
84+
builder.Logging.AddFilter("ModelContextProtocol", msLogLevel);
85+
86+
builder.Services.AddSingleton(rpcClient);
87+
88+
builder.Services.AddMcpServer(options =>
89+
{
90+
options.ServerInfo = new Implementation
91+
{
92+
Name = serverName,
93+
Version = "1.0.0"
94+
};
95+
})
96+
.WithHttpTransport()
97+
.WithTools<SolutionTools>()
98+
.WithTools<DocumentTools>()
99+
.WithTools<BuildTools>();
100+
101+
var app = builder.Build();
102+
103+
app.MapMcp();
104+
105+
var bindingUrl = $"http://{host}:{port}";
106+
app.Urls.Add(bindingUrl);
107+
108+
// Register shutdown token to stop the application
109+
var lifetime = app.Services.GetRequiredService<IHostApplicationLifetime>();
110+
shutdownCts.Token.Register(() => lifetime.StopApplication());
111+
112+
Console.Error.WriteLine($"MCP Server listening on {bindingUrl} (LogLevel: {logLevel})");
113+
114+
await app.RunAsync();
115+
116+
Console.Error.WriteLine("Server shutdown complete");
117+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"profiles": {
3+
"CodingWithCalvin.MCPServer.Server": {
4+
"commandName": "Project",
5+
"launchBrowser": true,
6+
"environmentVariables": {
7+
"ASPNETCORE_ENVIRONMENT": "Development"
8+
},
9+
"applicationUrl": "https://localhost:57573;http://localhost:57574"
10+
}
11+
}
12+
}

0 commit comments

Comments
 (0)