msbuild-mcp-server 0.1.1__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.
@@ -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
- @mcp.tool()
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 = "Debug",
30
- platform: str = "x64",
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: 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.
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
- Use this tool to automate the build process for MSBuild projects, ensuring compatibility with various configurations and environments.
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, # Updated from sln_path to 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.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,6 +9,7 @@ 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: pydantic>=2.0.0
12
13
  Provides-Extra: dev
13
14
  Requires-Dist: pytest; extra == "dev"
14
15
  Dynamic: license-file
@@ -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,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (80.1.0)
2
+ Generator: setuptools (80.3.1)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,7 +0,0 @@
1
- msbuild_mcp_server/server.py,sha256=VwlfbLJ-AWjylxlI_fKvvvSPHP6xkmVOfZkJfBphcEo,3877
2
- msbuild_mcp_server-0.1.1.dist-info/licenses/LICENSE,sha256=zEukTMUBlTMWO2Xlr5s53ZzahKcZVcpRSegfwDKuLs0,1091
3
- msbuild_mcp_server-0.1.1.dist-info/METADATA,sha256=N0oG8WsfyLUkKOfkGaSimeJIoZQxDQqY7l38rqQqJwk,2588
4
- msbuild_mcp_server-0.1.1.dist-info/WHEEL,sha256=wXxTzcEDnjrTwFYjLPcsW_7_XihufBwmpiBeiXNBGEA,91
5
- msbuild_mcp_server-0.1.1.dist-info/entry_points.txt,sha256=OWN3dxqf2u2KixCBqT_3sj8hDwaElUa0-J9uaC6z-K8,70
6
- msbuild_mcp_server-0.1.1.dist-info/top_level.txt,sha256=6gy0MqZpIjrsVTU2b8izs-i6dJiC_FbjfL4JE0IvV2I,19
7
- msbuild_mcp_server-0.1.1.dist-info/RECORD,,