msbuild-mcp-server 0.1.0__tar.gz → 0.1.2__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: msbuild-mcp-server
3
- Version: 0.1.0
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: pytest
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 using the `vswhere` Python package and provides customizable build configuration options.
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 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
+ - **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**: Integrates seamlessly with MCP clients, including VSCode, Cursor, Windsurf, and more.
25
- - **Cross-Language Support**: Works with MSBuild-compatible projects (.sln, .csproj, .vcxproj).
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 Client Setup
37
+ ## Registering the MCP Server
36
38
 
37
- Use the same configuration snippet for all MCP clients:
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
- "type": "stdio",
44
- "command": "uv",
47
+ "command": "uvx",
45
48
  "args": [
46
- "--directory",
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.
@@ -1,14 +1,14 @@
1
1
  # MSBuild MCP Server
2
2
 
3
- 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.
3
+ A lightweight MCP (Model Context Protocol) server for automating MSBuild projects and solutions builds. It dynamically locates MSBuild and provides customizable build configuration options.
4
4
 
5
5
  ## Features
6
6
 
7
- - **Dynamic MSBuild Discovery**: Automatically detects the MSBuild executable using `vswhere`, ensuring compatibility with various Visual Studio installations.
8
- - **Customizable Build Settings**: Easily configure build options such as configuration, platform, verbosity level, parallel build CPU count, NuGet restore, and additional command-line arguments.
7
+ - **Dynamic MSBuild Discovery**: Automatically detects the MSBuild executable, ensuring compatibility with various Visual Studio installations.
8
+ - **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.
9
9
  - **Clear Error Reporting**: Filters and presents concise, relevant error messages upon build failures.
10
- - **MCP Client Compatibility**: Integrates seamlessly with MCP clients, including VSCode, Cursor, Windsurf, and more.
11
- - **Cross-Language Support**: Works with MSBuild-compatible projects (.sln, .csproj, .vcxproj).
10
+ - **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.
11
+ - **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.
12
12
 
13
13
  ## Prerequisites
14
14
 
@@ -18,21 +18,19 @@ Ensure the following prerequisites are installed:
18
18
  - Visual Studio or Visual Studio Build Tools (for MSBuild)
19
19
  - [`uv`](https://docs.astral.sh/uv/getting-started/installation/) (recommended)
20
20
 
21
- ## MCP Client Setup
21
+ ## Registering the MCP Server
22
22
 
23
- Use the same configuration snippet for all MCP clients:
23
+ Ensure `uv` is installed.
24
+
25
+ In the MCP settings of your AI tools (e.g., Cursor, Windsurf, Claude Desktop, etc.), add the following configuration:
24
26
 
25
27
  ```json
26
28
  {
27
29
  "mcpServers": {
28
30
  "msbuild-mcp-server": {
29
- "type": "stdio",
30
- "command": "uv",
31
+ "command": "uvx",
31
32
  "args": [
32
- "--directory",
33
- "<path/to/cloned/msbuild-mcp-server>",
34
- "run",
35
- "src/msbuild_mcp_server/server.py"
33
+ "msbuild-mcp-server@latest"
36
34
  ]
37
35
  }
38
36
  }
@@ -44,6 +42,8 @@ Place this snippet in your client configuration file:
44
42
  - **Cursor**: `~/.cursor/mcp.json` or `<project-root>/.cursor/mcp.json`
45
43
  - **Windsurf**: `~/.codeium/windsurf/mcp_config.json`
46
44
 
45
+ Restart your tool to ensure that the `msbuild-mcp-server` and its provided tools are properly registered.
46
+
47
47
  ## License
48
48
 
49
49
  This project is licensed under the MIT License.
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "msbuild-mcp-server"
3
- version = "0.1.0"
3
+ version = "0.1.2"
4
4
  description = "A lightweight MCP server for automating MSBuild projects and solutions builds."
5
5
  license = { text = "MIT" }
6
6
  readme = "README.md"
@@ -10,7 +10,7 @@ dependencies = [
10
10
  "fastmcp>=2.0",
11
11
  "uv",
12
12
  "vswhere>=1.0.0",
13
- "pytest"
13
+ "pydantic>=2.0.0"
14
14
  ]
15
15
 
16
16
  [project.scripts]
@@ -20,4 +20,9 @@ msbuild-mcp-server = "msbuild_mcp_server.server:main"
20
20
  packages = ["msbuild_mcp_server"]
21
21
 
22
22
  [tool.setuptools.package-dir]
23
- "" = "src"
23
+ "" = "src"
24
+
25
+ [project.optional-dependencies]
26
+ dev = [
27
+ "pytest"
28
+ ]
@@ -0,0 +1,178 @@
1
+ import subprocess
2
+ import os
3
+ from fastmcp import FastMCP
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
9
+
10
+ # Create MCP server instance
11
+ mcp = FastMCP("MSBuild MCP Server")
12
+
13
+ # Replace the find_msbuild function to use the vswhere Python package
14
+ # and retrieve the latest MSBuild path dynamically.
15
+ def find_msbuild():
16
+ """
17
+ Use the vswhere Python package to locate the MSBuild executable.
18
+ Returns the path to MSBuild if found, otherwise raises an exception.
19
+ """
20
+ msbuild_installation_path = get_latest_path(products='*')
21
+ if not msbuild_installation_path:
22
+ raise FileNotFoundError("MSBuild executable not found. Ensure Visual Studio is installed.")
23
+
24
+ msbuild_path = os.path.join(msbuild_installation_path, "MSBuild", "Current", "Bin", "MSBuild.exe")
25
+ if not os.path.exists(msbuild_path):
26
+ raise FileNotFoundError(f"MSBuild executable not found at expected path: {msbuild_path}")
27
+
28
+ return msbuild_path
29
+
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
+ )
77
+ def build_msbuild_project(
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).")]=""
85
+ ) -> str:
86
+ """
87
+ Build an MSBuild project or solution (.sln, .csproj, .vcxproj) file using MSBuild
88
+
89
+ Parameters:
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 "".
97
+
98
+ Returns:
99
+ - A string indicating the build result, including success or filtered error messages.
100
+
101
+ This tool can be used to automate MSBuild project builds in various environments.
102
+ """
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
+
133
+ cmd = [
134
+ msbuild,
135
+ project_path,
136
+ f"/p:Configuration={configuration}",
137
+ f"/p:Platform={platform}",
138
+ f"/verbosity:{verbosity}"
139
+ ]
140
+
141
+ if max_cpu_count:
142
+ cmd.append(f"/maxcpucount:{max_cpu_count}")
143
+ else:
144
+ cmd.append("/m") # Default parallel build
145
+
146
+ if restore:
147
+ cmd.append("/restore")
148
+
149
+ if additional_args:
150
+ cmd.extend(additional_args.split())
151
+
152
+ try:
153
+ result = subprocess.run(
154
+ cmd,
155
+ stdout=subprocess.PIPE,
156
+ stderr=subprocess.PIPE, # Capture stderr separately
157
+ text=True,
158
+ encoding="utf-8"
159
+ )
160
+
161
+
162
+ if result.returncode == 0:
163
+ return f"Build succeeded."
164
+ else:
165
+ # Filter error messages from both stdout and stderr
166
+ error_lines_stdout = [line for line in result.stdout.splitlines() if "error" in line.lower()]
167
+ error_lines_stderr = [line for line in result.stderr.splitlines() if "error" in line.lower()]
168
+ filtered_errors = "\n".join(error_lines_stdout + error_lines_stderr)
169
+ return f"Build failed with errors.\nFiltered Errors:\n{filtered_errors}\nFull Output:\n{result.stdout}\nErrors:\n{result.stderr}"
170
+ except FileNotFoundError:
171
+ return "MSBuild executable not found. Ensure MSBuild is installed and added to the PATH."
172
+
173
+ def main():
174
+ """Entry point for the msbuild-mcp-server CLI."""
175
+ mcp.run()
176
+
177
+ if __name__ == "__main__":
178
+ main()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: msbuild-mcp-server
3
- Version: 0.1.0
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: pytest
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 using the `vswhere` Python package and provides customizable build configuration options.
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 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
+ - **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**: Integrates seamlessly with MCP clients, including VSCode, Cursor, Windsurf, and more.
25
- - **Cross-Language Support**: Works with MSBuild-compatible projects (.sln, .csproj, .vcxproj).
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 Client Setup
37
+ ## Registering the MCP Server
36
38
 
37
- Use the same configuration snippet for all MCP clients:
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
- "type": "stdio",
44
- "command": "uv",
47
+ "command": "uvx",
45
48
  "args": [
46
- "--directory",
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.
@@ -7,5 +7,4 @@ src/msbuild_mcp_server.egg-info/SOURCES.txt
7
7
  src/msbuild_mcp_server.egg-info/dependency_links.txt
8
8
  src/msbuild_mcp_server.egg-info/entry_points.txt
9
9
  src/msbuild_mcp_server.egg-info/requires.txt
10
- src/msbuild_mcp_server.egg-info/top_level.txt
11
- tests/test_server.py
10
+ src/msbuild_mcp_server.egg-info/top_level.txt
@@ -1,4 +1,7 @@
1
1
  fastmcp>=2.0
2
2
  uv
3
3
  vswhere>=1.0.0
4
+ pydantic>=2.0.0
5
+
6
+ [dev]
4
7
  pytest
@@ -1,102 +0,0 @@
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()
@@ -1,22 +0,0 @@
1
- import pytest
2
- from server import find_msbuild, build_msbuild_project
3
-
4
- def test_find_msbuild():
5
- """Test that find_msbuild returns a valid path."""
6
- try:
7
- msbuild_path = find_msbuild()
8
- assert msbuild_path.endswith("MSBuild.exe"), "MSBuild path does not end with MSBuild.exe"
9
- except FileNotFoundError:
10
- pytest.skip("MSBuild not found on this system.")
11
-
12
- def test_build_msbuild_project():
13
- """Test the build_msbuild_project function with a mock project."""
14
- # Mock project path (replace with an actual test project if available)
15
- project_path = "mock_project.sln"
16
- result = build_msbuild_project(
17
- project_path=project_path,
18
- configuration="Debug",
19
- platform="x64",
20
- verbosity="minimal"
21
- )
22
- assert "Build succeeded." in result or "Build failed" in result, "Unexpected build result."