msbuild-mcp-server 0.1.0__py3-none-any.whl → 0.1.2__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 +97 -21
- {msbuild_mcp_server-0.1.0.dist-info → msbuild_mcp_server-0.1.2.dist-info}/METADATA +17 -15
- msbuild_mcp_server-0.1.2.dist-info/RECORD +7 -0
- {msbuild_mcp_server-0.1.0.dist-info → msbuild_mcp_server-0.1.2.dist-info}/WHEEL +1 -1
- msbuild_mcp_server-0.1.0.dist-info/RECORD +0 -7
- {msbuild_mcp_server-0.1.0.dist-info → msbuild_mcp_server-0.1.2.dist-info}/entry_points.txt +0 -0
- {msbuild_mcp_server-0.1.0.dist-info → msbuild_mcp_server-0.1.2.dist-info}/licenses/LICENSE +0 -0
- {msbuild_mcp_server-0.1.0.dist-info → msbuild_mcp_server-0.1.2.dist-info}/top_level.txt +0 -0
msbuild_mcp_server/server.py
CHANGED
|
@@ -2,6 +2,10 @@ import subprocess
|
|
|
2
2
|
import os
|
|
3
3
|
from fastmcp import FastMCP
|
|
4
4
|
from vswhere import get_latest_path
|
|
5
|
+
import xml.etree.ElementTree as ET
|
|
6
|
+
import json
|
|
7
|
+
from typing import Annotated
|
|
8
|
+
from pydantic import Field
|
|
5
9
|
|
|
6
10
|
# Create MCP server instance
|
|
7
11
|
mcp = FastMCP("MSBuild MCP Server")
|
|
@@ -23,40 +27,112 @@ def find_msbuild():
|
|
|
23
27
|
|
|
24
28
|
return msbuild_path
|
|
25
29
|
|
|
26
|
-
|
|
30
|
+
|
|
31
|
+
def get_msbuild_configurations_and_platforms(project_path: str):
|
|
32
|
+
"""
|
|
33
|
+
Extract available configurations and platforms from a given MSBuild project or solution file.
|
|
34
|
+
Returns (configurations, platforms) as lists.
|
|
35
|
+
"""
|
|
36
|
+
configs = set()
|
|
37
|
+
plats = set()
|
|
38
|
+
if project_path.endswith('.sln'):
|
|
39
|
+
# Parse .sln file as text directly
|
|
40
|
+
with open(project_path, encoding='utf-8') as f:
|
|
41
|
+
for line in f:
|
|
42
|
+
if 'GlobalSection(SolutionConfigurationPlatforms)' in line:
|
|
43
|
+
for config_line in f:
|
|
44
|
+
if 'EndGlobalSection' in config_line:
|
|
45
|
+
break
|
|
46
|
+
if '=' in config_line:
|
|
47
|
+
configplat = config_line.split('=')[0].strip()
|
|
48
|
+
if '|' in configplat:
|
|
49
|
+
config, plat = configplat.split('|', 1)
|
|
50
|
+
configs.add(config)
|
|
51
|
+
plats.add(plat)
|
|
52
|
+
else:
|
|
53
|
+
# Parse .csproj/.vcxproj files as XML
|
|
54
|
+
try:
|
|
55
|
+
tree = ET.parse(project_path)
|
|
56
|
+
root = tree.getroot()
|
|
57
|
+
ns = {'msbuild': 'http://schemas.microsoft.com/developer/msbuild/2003'}
|
|
58
|
+
for pg in root.findall('.//msbuild:PropertyGroup', ns):
|
|
59
|
+
cond = pg.attrib.get('Condition', '')
|
|
60
|
+
if 'Configuration' in cond and 'Platform' in cond:
|
|
61
|
+
# Example: ' '$(Configuration)|$(Platform)' == 'Debug|x64' '
|
|
62
|
+
import re
|
|
63
|
+
m = re.search(r"'\$\(Configuration\)\|\$\(Platform\)'\s*==\s*'([^|]+)\|([^']+)'", cond)
|
|
64
|
+
if m:
|
|
65
|
+
configs.add(m.group(1))
|
|
66
|
+
plats.add(m.group(2))
|
|
67
|
+
except Exception:
|
|
68
|
+
pass
|
|
69
|
+
return list(configs), list(plats)
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
@mcp.tool(
|
|
73
|
+
name="build_msbuild_project",
|
|
74
|
+
description="Build an MSBuild project or solution (.sln, .csproj, .vcxproj) file using MSBuild.",
|
|
75
|
+
tags={"msbuild", "build", "visualstudio"}
|
|
76
|
+
)
|
|
27
77
|
def build_msbuild_project(
|
|
28
|
-
project_path: str,
|
|
29
|
-
configuration: str =
|
|
30
|
-
platform: str =
|
|
31
|
-
verbosity: str = "minimal",
|
|
32
|
-
max_cpu_count: int = None,
|
|
33
|
-
restore: bool = True,
|
|
34
|
-
additional_args: str = ""
|
|
78
|
+
project_path: Annotated[str, Field(description="Absolute path to the project or solution file to build.")],
|
|
79
|
+
configuration: Annotated[str, Field(description="Build configuration (e.g., Debug, Release).")],
|
|
80
|
+
platform: Annotated[str, Field(description="Target platform (e.g., x86, x64).")],
|
|
81
|
+
verbosity: Annotated[str, Field(description="MSBuild output verbosity (quiet, minimal, normal, detailed, diagnostic).")]="minimal",
|
|
82
|
+
max_cpu_count: Annotated[int, Field(description="Maximum number of CPUs for parallel build (default: None, uses automatic parallel build).")]=None,
|
|
83
|
+
restore: Annotated[bool, Field(description="Whether to perform NuGet restore before build. Default is True.")]=True,
|
|
84
|
+
additional_args: Annotated[str, Field(description="Additional MSBuild command-line arguments (as a string, separated by spaces).")]=""
|
|
35
85
|
) -> str:
|
|
36
86
|
"""
|
|
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.
|
|
87
|
+
Build an MSBuild project or solution (.sln, .csproj, .vcxproj) file using MSBuild
|
|
41
88
|
|
|
42
89
|
Parameters:
|
|
43
|
-
- project_path:
|
|
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
|
|
48
|
-
- restore: Whether to perform NuGet restore before build.
|
|
49
|
-
- additional_args: Additional MSBuild command-line arguments.
|
|
90
|
+
- project_path: Absolute path to the project or solution file to build.
|
|
91
|
+
- configuration: Build configuration (e.g., Debug, Release). Default is "Debug".
|
|
92
|
+
- platform: Target platform (e.g., x86, x64). Default is "x64".
|
|
93
|
+
- verbosity: MSBuild output verbosity (quiet, minimal, normal, detailed, diagnostic). Default is "minimal".
|
|
94
|
+
- max_cpu_count: Maximum number of CPUs for parallel build (default: None, if not specified, uses automatic parallel build).
|
|
95
|
+
- restore: Whether to perform NuGet restore before build. Default is True.
|
|
96
|
+
- additional_args: Additional MSBuild command-line arguments (as a string, separated by spaces). Default is "".
|
|
50
97
|
|
|
51
98
|
Returns:
|
|
52
99
|
- A string indicating the build result, including success or filtered error messages.
|
|
53
100
|
|
|
54
|
-
|
|
101
|
+
This tool can be used to automate MSBuild project builds in various environments.
|
|
55
102
|
"""
|
|
56
103
|
msbuild = find_msbuild()
|
|
104
|
+
|
|
105
|
+
if not os.path.isfile(project_path):
|
|
106
|
+
return (
|
|
107
|
+
f"The specified project_path does not exist or is not a file: {project_path}\n"
|
|
108
|
+
"Please provide the absolute path to the project or solution file to build."
|
|
109
|
+
)
|
|
110
|
+
|
|
111
|
+
# If configuration or platform is not specified, return the available options
|
|
112
|
+
configs, plats = get_msbuild_configurations_and_platforms(project_path)
|
|
113
|
+
if not configuration or not platform:
|
|
114
|
+
if not configs or not plats:
|
|
115
|
+
return "Could not extract available configurations or platforms from the project file. Please specify them manually."
|
|
116
|
+
return json.dumps({
|
|
117
|
+
"message": "Please select a configuration and platform from the available options.",
|
|
118
|
+
"available_configurations": configs,
|
|
119
|
+
"available_platforms": plats
|
|
120
|
+
}, ensure_ascii=False)
|
|
121
|
+
# If the provided configuration or platform is not in the supported list, return a message
|
|
122
|
+
if configs and configuration not in configs:
|
|
123
|
+
return json.dumps({
|
|
124
|
+
"message": f"The configuration '{configuration}' is not supported by this project. Please select from the available options.",
|
|
125
|
+
"available_configurations": configs
|
|
126
|
+
}, ensure_ascii=False)
|
|
127
|
+
if plats and platform not in plats:
|
|
128
|
+
return json.dumps({
|
|
129
|
+
"message": f"The platform '{platform}' is not supported by this project. Please select from the available options.",
|
|
130
|
+
"available_platforms": plats
|
|
131
|
+
}, ensure_ascii=False)
|
|
132
|
+
|
|
57
133
|
cmd = [
|
|
58
134
|
msbuild,
|
|
59
|
-
project_path,
|
|
135
|
+
project_path,
|
|
60
136
|
f"/p:Configuration={configuration}",
|
|
61
137
|
f"/p:Platform={platform}",
|
|
62
138
|
f"/verbosity:{verbosity}"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: msbuild-mcp-server
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.2
|
|
4
4
|
Summary: A lightweight MCP server for automating MSBuild projects and solutions builds.
|
|
5
5
|
License: MIT
|
|
6
6
|
Requires-Python: >=3.11
|
|
@@ -9,20 +9,22 @@ License-File: LICENSE
|
|
|
9
9
|
Requires-Dist: fastmcp>=2.0
|
|
10
10
|
Requires-Dist: uv
|
|
11
11
|
Requires-Dist: vswhere>=1.0.0
|
|
12
|
-
Requires-Dist:
|
|
12
|
+
Requires-Dist: pydantic>=2.0.0
|
|
13
|
+
Provides-Extra: dev
|
|
14
|
+
Requires-Dist: pytest; extra == "dev"
|
|
13
15
|
Dynamic: license-file
|
|
14
16
|
|
|
15
17
|
# MSBuild MCP Server
|
|
16
18
|
|
|
17
|
-
A lightweight MCP (Model Context Protocol) server for automating MSBuild projects and solutions builds. It dynamically locates MSBuild
|
|
19
|
+
A lightweight MCP (Model Context Protocol) server for automating MSBuild projects and solutions builds. It dynamically locates MSBuild and provides customizable build configuration options.
|
|
18
20
|
|
|
19
21
|
## Features
|
|
20
22
|
|
|
21
|
-
- **Dynamic MSBuild Discovery**: Automatically detects the MSBuild executable
|
|
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
|
+
- **Dynamic MSBuild Discovery**: Automatically detects the MSBuild executable, ensuring compatibility with various Visual Studio installations.
|
|
24
|
+
- **Customizable Build Settings**: Easily configure build options such as configuration, platform, verbosity level, parallel build CPU count, NuGet restore, and additional command-line arguments through LLM-driven tool invocation.
|
|
23
25
|
- **Clear Error Reporting**: Filters and presents concise, relevant error messages upon build failures.
|
|
24
|
-
- **MCP Client Compatibility**:
|
|
25
|
-
- **Cross-Language Support**:
|
|
26
|
+
- **MCP Client Compatibility**: Supports seamless integration with popular MCP clients such as VSCode, Cursor, Windsurf, and more. Configuration snippets for these clients are provided in the documentation.
|
|
27
|
+
- **Cross-Language Support**: Supports MSBuild-compatible projects, including .sln, .csproj, and .vcxproj files, enabling builds for languages like C#, C++, and more across Windows platforms.
|
|
26
28
|
|
|
27
29
|
## Prerequisites
|
|
28
30
|
|
|
@@ -32,21 +34,19 @@ Ensure the following prerequisites are installed:
|
|
|
32
34
|
- Visual Studio or Visual Studio Build Tools (for MSBuild)
|
|
33
35
|
- [`uv`](https://docs.astral.sh/uv/getting-started/installation/) (recommended)
|
|
34
36
|
|
|
35
|
-
## MCP
|
|
37
|
+
## Registering the MCP Server
|
|
36
38
|
|
|
37
|
-
|
|
39
|
+
Ensure `uv` is installed.
|
|
40
|
+
|
|
41
|
+
In the MCP settings of your AI tools (e.g., Cursor, Windsurf, Claude Desktop, etc.), add the following configuration:
|
|
38
42
|
|
|
39
43
|
```json
|
|
40
44
|
{
|
|
41
45
|
"mcpServers": {
|
|
42
46
|
"msbuild-mcp-server": {
|
|
43
|
-
"
|
|
44
|
-
"command": "uv",
|
|
47
|
+
"command": "uvx",
|
|
45
48
|
"args": [
|
|
46
|
-
"
|
|
47
|
-
"<path/to/cloned/msbuild-mcp-server>",
|
|
48
|
-
"run",
|
|
49
|
-
"src/msbuild_mcp_server/server.py"
|
|
49
|
+
"msbuild-mcp-server@latest"
|
|
50
50
|
]
|
|
51
51
|
}
|
|
52
52
|
}
|
|
@@ -58,6 +58,8 @@ Place this snippet in your client configuration file:
|
|
|
58
58
|
- **Cursor**: `~/.cursor/mcp.json` or `<project-root>/.cursor/mcp.json`
|
|
59
59
|
- **Windsurf**: `~/.codeium/windsurf/mcp_config.json`
|
|
60
60
|
|
|
61
|
+
Restart your tool to ensure that the `msbuild-mcp-server` and its provided tools are properly registered.
|
|
62
|
+
|
|
61
63
|
## License
|
|
62
64
|
|
|
63
65
|
This project is licensed under the MIT License.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
msbuild_mcp_server/server.py,sha256=MLu76aJOVHZNqk0NbCOVEcCyVroou4SIUlIxHbZ9dBY,8132
|
|
2
|
+
msbuild_mcp_server-0.1.2.dist-info/licenses/LICENSE,sha256=zEukTMUBlTMWO2Xlr5s53ZzahKcZVcpRSegfwDKuLs0,1091
|
|
3
|
+
msbuild_mcp_server-0.1.2.dist-info/METADATA,sha256=sKVOf6t8K_BgKG0qJoZVh0rnLLEGZdFhRQ3xgxCIU40,2620
|
|
4
|
+
msbuild_mcp_server-0.1.2.dist-info/WHEEL,sha256=0CuiUZ_p9E4cD6NyLD6UG80LBXYyiSYZOKDm5lp32xk,91
|
|
5
|
+
msbuild_mcp_server-0.1.2.dist-info/entry_points.txt,sha256=OWN3dxqf2u2KixCBqT_3sj8hDwaElUa0-J9uaC6z-K8,70
|
|
6
|
+
msbuild_mcp_server-0.1.2.dist-info/top_level.txt,sha256=6gy0MqZpIjrsVTU2b8izs-i6dJiC_FbjfL4JE0IvV2I,19
|
|
7
|
+
msbuild_mcp_server-0.1.2.dist-info/RECORD,,
|
|
@@ -1,7 +0,0 @@
|
|
|
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,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|