msbuild-mcp-server 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- msbuild_mcp_server/server.py +102 -0
- msbuild_mcp_server-0.1.0.dist-info/METADATA +64 -0
- msbuild_mcp_server-0.1.0.dist-info/RECORD +7 -0
- msbuild_mcp_server-0.1.0.dist-info/WHEEL +5 -0
- msbuild_mcp_server-0.1.0.dist-info/entry_points.txt +2 -0
- msbuild_mcp_server-0.1.0.dist-info/licenses/LICENSE +21 -0
- msbuild_mcp_server-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import subprocess
|
|
2
|
+
import os
|
|
3
|
+
from fastmcp import FastMCP
|
|
4
|
+
from vswhere import get_latest_path
|
|
5
|
+
|
|
6
|
+
# Create MCP server instance
|
|
7
|
+
mcp = FastMCP("MSBuild MCP Server")
|
|
8
|
+
|
|
9
|
+
# Replace the find_msbuild function to use the vswhere Python package
|
|
10
|
+
# and retrieve the latest MSBuild path dynamically.
|
|
11
|
+
def find_msbuild():
|
|
12
|
+
"""
|
|
13
|
+
Use the vswhere Python package to locate the MSBuild executable.
|
|
14
|
+
Returns the path to MSBuild if found, otherwise raises an exception.
|
|
15
|
+
"""
|
|
16
|
+
msbuild_installation_path = get_latest_path(products='*')
|
|
17
|
+
if not msbuild_installation_path:
|
|
18
|
+
raise FileNotFoundError("MSBuild executable not found. Ensure Visual Studio is installed.")
|
|
19
|
+
|
|
20
|
+
msbuild_path = os.path.join(msbuild_installation_path, "MSBuild", "Current", "Bin", "MSBuild.exe")
|
|
21
|
+
if not os.path.exists(msbuild_path):
|
|
22
|
+
raise FileNotFoundError(f"MSBuild executable not found at expected path: {msbuild_path}")
|
|
23
|
+
|
|
24
|
+
return msbuild_path
|
|
25
|
+
|
|
26
|
+
@mcp.tool()
|
|
27
|
+
def build_msbuild_project(
|
|
28
|
+
project_path: str,
|
|
29
|
+
configuration: str = "Debug",
|
|
30
|
+
platform: str = "x64",
|
|
31
|
+
verbosity: str = "minimal",
|
|
32
|
+
max_cpu_count: int = None,
|
|
33
|
+
restore: bool = True,
|
|
34
|
+
additional_args: str = ""
|
|
35
|
+
) -> str:
|
|
36
|
+
"""
|
|
37
|
+
Build an MSBuild project or solution (.sln, .csproj, .vcxproj) file using MSBuild.
|
|
38
|
+
|
|
39
|
+
This tool dynamically locates the MSBuild executable using the vswhere Python package.
|
|
40
|
+
It supports flexible build configurations, including verbosity, platform, and additional arguments.
|
|
41
|
+
|
|
42
|
+
Parameters:
|
|
43
|
+
- project_path: Path to the project or solution file to build.
|
|
44
|
+
- configuration: Build configuration (e.g., Debug, Release).
|
|
45
|
+
- platform: Target platform (e.g., x86, x64).
|
|
46
|
+
- verbosity: MSBuild output verbosity (quiet, minimal, normal, detailed, diagnostic).
|
|
47
|
+
- max_cpu_count: Maximum number of CPUs for parallel build (None for default).
|
|
48
|
+
- restore: Whether to perform NuGet restore before build.
|
|
49
|
+
- additional_args: Additional MSBuild command-line arguments.
|
|
50
|
+
|
|
51
|
+
Returns:
|
|
52
|
+
- A string indicating the build result, including success or filtered error messages.
|
|
53
|
+
|
|
54
|
+
Use this tool to automate the build process for MSBuild projects, ensuring compatibility with various configurations and environments.
|
|
55
|
+
"""
|
|
56
|
+
msbuild = find_msbuild()
|
|
57
|
+
cmd = [
|
|
58
|
+
msbuild,
|
|
59
|
+
project_path, # Updated from sln_path to project_path
|
|
60
|
+
f"/p:Configuration={configuration}",
|
|
61
|
+
f"/p:Platform={platform}",
|
|
62
|
+
f"/verbosity:{verbosity}"
|
|
63
|
+
]
|
|
64
|
+
|
|
65
|
+
if max_cpu_count:
|
|
66
|
+
cmd.append(f"/maxcpucount:{max_cpu_count}")
|
|
67
|
+
else:
|
|
68
|
+
cmd.append("/m") # Default parallel build
|
|
69
|
+
|
|
70
|
+
if restore:
|
|
71
|
+
cmd.append("/restore")
|
|
72
|
+
|
|
73
|
+
if additional_args:
|
|
74
|
+
cmd.extend(additional_args.split())
|
|
75
|
+
|
|
76
|
+
try:
|
|
77
|
+
result = subprocess.run(
|
|
78
|
+
cmd,
|
|
79
|
+
stdout=subprocess.PIPE,
|
|
80
|
+
stderr=subprocess.PIPE, # Capture stderr separately
|
|
81
|
+
text=True,
|
|
82
|
+
encoding="utf-8"
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
if result.returncode == 0:
|
|
87
|
+
return f"Build succeeded."
|
|
88
|
+
else:
|
|
89
|
+
# Filter error messages from both stdout and stderr
|
|
90
|
+
error_lines_stdout = [line for line in result.stdout.splitlines() if "error" in line.lower()]
|
|
91
|
+
error_lines_stderr = [line for line in result.stderr.splitlines() if "error" in line.lower()]
|
|
92
|
+
filtered_errors = "\n".join(error_lines_stdout + error_lines_stderr)
|
|
93
|
+
return f"Build failed with errors.\nFiltered Errors:\n{filtered_errors}\nFull Output:\n{result.stdout}\nErrors:\n{result.stderr}"
|
|
94
|
+
except FileNotFoundError:
|
|
95
|
+
return "MSBuild executable not found. Ensure MSBuild is installed and added to the PATH."
|
|
96
|
+
|
|
97
|
+
def main():
|
|
98
|
+
"""Entry point for the msbuild-mcp-server CLI."""
|
|
99
|
+
mcp.run()
|
|
100
|
+
|
|
101
|
+
if __name__ == "__main__":
|
|
102
|
+
main()
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: msbuild-mcp-server
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A lightweight MCP server for automating MSBuild projects and solutions builds.
|
|
5
|
+
License: MIT
|
|
6
|
+
Requires-Python: >=3.11
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Requires-Dist: fastmcp>=2.0
|
|
10
|
+
Requires-Dist: uv
|
|
11
|
+
Requires-Dist: vswhere>=1.0.0
|
|
12
|
+
Requires-Dist: pytest
|
|
13
|
+
Dynamic: license-file
|
|
14
|
+
|
|
15
|
+
# MSBuild MCP Server
|
|
16
|
+
|
|
17
|
+
A lightweight MCP (Model Context Protocol) server for automating MSBuild projects and solutions builds. It dynamically locates MSBuild using the `vswhere` Python package and provides customizable build configuration options.
|
|
18
|
+
|
|
19
|
+
## Features
|
|
20
|
+
|
|
21
|
+
- **Dynamic MSBuild Discovery**: Automatically detects the MSBuild executable using `vswhere`, ensuring compatibility with various Visual Studio installations.
|
|
22
|
+
- **Customizable Build Settings**: Easily configure build options such as configuration, platform, verbosity level, parallel build CPU count, NuGet restore, and additional command-line arguments.
|
|
23
|
+
- **Clear Error Reporting**: Filters and presents concise, relevant error messages upon build failures.
|
|
24
|
+
- **MCP Client Compatibility**: Integrates seamlessly with MCP clients, including VSCode, Cursor, Windsurf, and more.
|
|
25
|
+
- **Cross-Language Support**: Works with MSBuild-compatible projects (.sln, .csproj, .vcxproj).
|
|
26
|
+
|
|
27
|
+
## Prerequisites
|
|
28
|
+
|
|
29
|
+
Ensure the following prerequisites are installed:
|
|
30
|
+
|
|
31
|
+
- Python 3.11 or higher
|
|
32
|
+
- Visual Studio or Visual Studio Build Tools (for MSBuild)
|
|
33
|
+
- [`uv`](https://docs.astral.sh/uv/getting-started/installation/) (recommended)
|
|
34
|
+
|
|
35
|
+
## MCP Client Setup
|
|
36
|
+
|
|
37
|
+
Use the same configuration snippet for all MCP clients:
|
|
38
|
+
|
|
39
|
+
```json
|
|
40
|
+
{
|
|
41
|
+
"mcpServers": {
|
|
42
|
+
"msbuild-mcp-server": {
|
|
43
|
+
"type": "stdio",
|
|
44
|
+
"command": "uv",
|
|
45
|
+
"args": [
|
|
46
|
+
"--directory",
|
|
47
|
+
"<path/to/cloned/msbuild-mcp-server>",
|
|
48
|
+
"run",
|
|
49
|
+
"src/msbuild_mcp_server/server.py"
|
|
50
|
+
]
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Place this snippet in your client configuration file:
|
|
57
|
+
- [**VSCode**](https://code.visualstudio.com/docs/copilot/chat/mcp-servers): `.vscode/mcp.json`
|
|
58
|
+
- **Cursor**: `~/.cursor/mcp.json` or `<project-root>/.cursor/mcp.json`
|
|
59
|
+
- **Windsurf**: `~/.codeium/windsurf/mcp_config.json`
|
|
60
|
+
|
|
61
|
+
## License
|
|
62
|
+
|
|
63
|
+
This project is licensed under the MIT License.
|
|
64
|
+
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
msbuild_mcp_server/server.py,sha256=VwlfbLJ-AWjylxlI_fKvvvSPHP6xkmVOfZkJfBphcEo,3877
|
|
2
|
+
msbuild_mcp_server-0.1.0.dist-info/licenses/LICENSE,sha256=zEukTMUBlTMWO2Xlr5s53ZzahKcZVcpRSegfwDKuLs0,1091
|
|
3
|
+
msbuild_mcp_server-0.1.0.dist-info/METADATA,sha256=aG7SyB29Ofr7n58usmYohyuwFMZXt9GSIAyfDf1Dhq4,2290
|
|
4
|
+
msbuild_mcp_server-0.1.0.dist-info/WHEEL,sha256=wXxTzcEDnjrTwFYjLPcsW_7_XihufBwmpiBeiXNBGEA,91
|
|
5
|
+
msbuild_mcp_server-0.1.0.dist-info/entry_points.txt,sha256=OWN3dxqf2u2KixCBqT_3sj8hDwaElUa0-J9uaC6z-K8,70
|
|
6
|
+
msbuild_mcp_server-0.1.0.dist-info/top_level.txt,sha256=6gy0MqZpIjrsVTU2b8izs-i6dJiC_FbjfL4JE0IvV2I,19
|
|
7
|
+
msbuild_mcp_server-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Jin Hyung Ahn
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
msbuild_mcp_server
|