尝试将Claude桌面版MCP连接到Home Assistant - 错误:pywin32-311.data已被锁定
正在寻求帮助,将在我的Windows 10机器上运行的Claude Desktop与在树莓派上通过Docker运行的HA连接起来,因为我遇到了一个错误,问题一直绕来绕去。我原本在 /homeassistant发帖,但觉得问题比HA更偏向Claude,因此在这里发帖。
错误:
无法连接到MCP服务器。你可以检查服务器URL并验证服务器是否在运行。如果问题仍然存在,请将此引用提供给技术支持:“ofid_ee1d834ad4adee4c”
MCP home-assistant:服务器已断开连接。有关故障排除的指南,请访问我们的调试文档。
原因:无法删除目录 C:\Users\USERNAME\AppData\Local\uv\cache\builds-v0\.tmpE7rqrS\Lib\site-packages\pywin32-311.data:该进程无法访问该文件,因为它正被另一个进程使用。(操作系统错误32)
我的过程:
我在HA和 Claude > 设置 > 开发者 > 编辑配置中都创建了一个令牌,并将mcPServers的 JSON粘贴到偏好设置部分下面的配置文件中,这样文件就像下面这样。
我的claude_desktop_config.json文件位于:
{
"mcpServers": {
"home-assistant": {
"command": "uvx",
"args": [
"ha-mcp"
],
"env": {
"HA_URL": "https://192.168.xx.XXX:8123",
"HA_TOKEN": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
}
}
},
"preferences": {
"coworkScheduledTasksEnabled": true,
"ccdScheduledTasksEnabled": true,
"sidebarMode": "task",
"coworkWebSearchEnabled": true
}
}
其中HA_URL是我的HA内部IP
而HA_TOKEN是令牌。
我保存此文件,然后通过File > Exit重启Claude。
然后进入Customise > Connectors > Home Assistant > Connect,点击Connect。
它会打开一个浏览器,询问是否要打开Claude。我点击 打开,结果出现以下错误:
无法连接到MCP服务器。你可以检查服务器URL并验证服务器是否在运行。如果问题仍然存在,请将此引用提供给技术支持:“ofid_ee1d834ad4adee4c”
MCP home-assistant:服务器已断开连接。有关故障排除的指南,请访问我们的调试文档。
检查开发者设置 > 查看日志:
我的日志中出现以下错误:
2026-04-06T21:10:20.038Z [home-assistant] [info] Server started and connected successfully { metadata: undefined }
2026-04-06T21:10:21.341Z [home-assistant] [info] Message from client: {"method":"initialize","params":{"protocolVersion":"2025-11-25","capabilities":{"extensions":{"io.modelcontextprotocol/ui":{"mimeTypes":["text/html;profile=mcp-app"]}}},"clientInfo":{"name":"claude-ai","version":"0.1.0"}},"jsonrpc":"2.0","id":0} { metadata: undefined }
2026-04-06T21:10:21.991Z [home-assistant] [info] Server transport closed { metadata: undefined }
2026-04-06T21:10:21.992Z [home-assistant] [info] Client transport closed { metadata: undefined }
error: Failed to install: pywin32-311-cp313-cp313-win_amd64.whl (pywin32==311)
Caused by: failed to remove directory `C:\Users\<USERNAME>\AppData\Local\uv\cache\builds-v0\.tmphGl9ly\Lib\site-packages\pywin32-311.data`: The process cannot access the file because it is being used by another process. (os error 32)
2026-04-06T21:10:25.653Z [home-assistant] [info] Server transport closed { metadata: undefined }
2026-04-06T21:10:25.653Z [home-assistant] [info] Server transport closed unexpectedly, this is likely due to the process exiting early. If you are developing this MCP server you can add output to stderr (i.e. `console.error('...')` in JavaScript, `print('...', file=sys.stderr)` in python) and it will appear in this log. { metadata: undefined }
2026-04-06T21:10:25.653Z [home-assistant] [error] Server disconnected. For troubleshooting guidance, please visit our [debugging documentation](https://modelcontextprotocol.io/docs/tools/debugging) { metadata: { context: 'connection', stack: undefined } }
2026-04-06T21:10:25.653Z [home-assistant] [info] Client transport closed { metadata: undefined }
2026-04-06T21:10:25.653Z [home-assistant] [info] Client transport closed { metadata: undefined }
2026-04-07T13:38:30.652Z [home-assistant] [info] Initializing server... { metadata: undefined }
2026-04-07T13:38:30.696Z [home-assistant] [info] Using MCP server command: C:\Users\<USERNAME>\AppData\Local\Microsoft\WinGet\Links\uvx.exe with args and path: {
metadata: {
args: [ 'ha-mcp', [length]: 1 ],
paths: [
'C:\\Users\\<USERNAME>\\AppData\\Local\\Programs\\Python\\Python310',
'C:\\Perl\\site\\bin',
'C:\\Perl\\bin',
'C:\\Program Files\\Oculus\\Support\\oculus-runtime',
'C:\\Program Files (x86)\\Common Files\\Intel\\Shared Libraries\\redist\\intel64\\compiler',
'C:\\Windows\\system32',
'C:\\Windows',
'C:\\Windows\\System32\\Wbem',
'C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\',
'C:\\Windows\\System32\\OpenSSH\\',
'C:\\Program Files\\IDM Computer Solutions\\UltraEdit',
'C:\\Program Files\\PuTTY\\',
'C:\\Program Files\\NVIDIA Corporation\\NVIDIA NvDLISR',
'C:\\Program Files (x86)\\NVIDIA Corporation\\PhysX\\Common',
'C:\\Program Files (x86)\\ZeroTier\\One\\',
'C:\\Program Files\\IDM Computer Solutions\\UltraCompare',
'C:\\Users\\<USERNAME>\\AppData\\Local\\Programs\\Python\\Python310\\Scripts\\',
'C:\\Users\\<USERNAME>\\AppData\\Local\\Programs\\Python\\Python310\\',
'C:\\Users\\<USERNAME>\\AppData\\Local\\Microsoft\\WindowsApps',
'C:\\Program Files\\JetBrains\\PyCharm Community Edition 2021.2.3\\bin',
'C:\\Users\\<USERNAME>\\AppData\\Local\\Programs\\Microsoft VS Code\\bin',
'E:\\Astro Photography\\GraXpert\\',
'C:\\Users\\<USERNAME>\\AppData\\Local\\Microsoft\\WinGet\\Links',
[length]: 23
]
}
} %o
2026-04-07T13:38:30.899Z [home-assistant] [info] Server started and connected successfully { metadata: undefined }
2026-04-07T13:38:31.736Z [home-assistant] [info] Message from client: {"method":"initialize","params":{"protocolVersion":"2025-11-25","capabilities":{"extensions":{"io.modelcontextprotocol/ui":{"mimeTypes":["text/html;profile=mcp-app"]}}},"clientInfo":{"name":"claude-ai","version":"0.1.0"}},"jsonrpc":"2.0","id":0} { metadata: undefined }
error: Failed to install: pywin32-311-cp313-cp313-win_amd64.whl (pywin32==311)
Caused by: failed to remove directory `C:\Users\<USERNAME>\AppData\Local\uv\cache\builds-v0\.tmp3Oc5HQ\Lib\site-packages\pywin32-311.data`: The process cannot access the file because it is being used by another process. (os error 32)
2026-04-07T13:38:36.363Z [home-assistant] [info] Server transport closed { metadata: undefined }
2026-04-07T13:38:36.363Z [home-assistant] [info] Server transport closed unexpectedly, this is likely due to the process exiting early. If you are developing this MCP server you can add output to stderr (i.e. `console.error('...')` in JavaScript, `print('...', file=sys.stderr)` in python) and it will appear in this log. { metadata: undefined }
2026-04-07T13:38:36.363Z [home-assistant] [error] Server disconnected. For troubleshooting guidance, please visit our [debugging documentation](https://modelcontextprotocol.io/docs/tools/debugging) { metadata: { context: 'connection', stack: undefined } }
2026-04-07T13:38:36.363Z [home-assistant] [info] Client transport closed { metadata: undefined }
2026-04-07T13:38:36.363Z [home-assistant] [info] Client transport closed { metadata: undefined }
2026-04-07T13:39:24.822Z [home-assistant] [info] Client transport closed { metadata: undefined }
2026-04-07T13:39:24.822Z [home-assistant] [info] Shutting down server... { metadata: undefined }
2026-04-07T13:39:24.823Z [home-assistant] [info] Initializing server... { metadata: undefined }
2026-04-07T13:39:24.831Z [home-assistant] [info] Using MCP server command: C:\Users\<USERNAME>\AppData\Local\Microsoft\WinGet\Links\uvx.exe with args and path: {
metadata: {
args: [ 'ha-mcp', [length]: 1 ],
paths: [
'C:\\Users\\<USERNAME>\\AppData\\Local\\Programs\\Python\\Python310',
'C:\\Perl\\site\\bin',
'C:\\Perl\\bin',
'C:\\Program Files\\Oculus\\Support\\oculus-runtime',
'C:\\Program Files (x86)\\Common Files\\Intel\\Shared Libraries\\redist\\intel64\\compiler',
'C:\\Windows\\system32',
'C:\\Windows',
'C:\\Windows\\System32\\Wbem',
'C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\',
'C:\\Windows\\System32\\OpenSSH\\',
'C:\\Program Files\\IDM Computer Solutions\\UltraEdit',
'C:\\Program Files\\PuTTY\\',
'C:\\Program Files\\NVIDIA Corporation\\NVIDIA NvDLISR',
'C:\\Program Files (x86)\\NVIDIA Corporation\\PhysX\\Common',
'C:\\Program Files (x86)\\ZeroTier\\One\\',
'C:\\Program Files\\IDM Computer Solutions\\UltraCompare',
'C:\\Users\\<USERNAME>\\AppData\\Local\\Programs\\Python\\Python310\\Scripts\\',
'C:\\Users\\<USERNAME>\\AppData\\Local\\Programs\\Python\\Python310\\',
'C:\\Users\\<USERNAME>\\AppData\\Local\\Microsoft\\WindowsApps',
'C:\\Program Files\\JetBrains\\PyCharm Community Edition 2021.2.3\\bin',
'C:\\Users\\<USERNAME>\\AppData\\Local\\Programs\\Microsoft VS Code\\bin',
'E:\\Astro Photography\\GraXpert\\',
'C:\\Users\\<USERNAME>\\AppData\\Local\\Microsoft\\WinGet\\Links',
[length]: 23
]
}
} %o
2026-04-07T13:39:24.837Z [home-assistant] [info] Server started and connected successfully { metadata: undefined }
2026-04-07T13:39:25.297Z [home-assistant] [info] Message from client: {"method":"initialize","params":{"protocolVersion":"2025-11-25","capabilities":{"extensions":{"io.modelcontextprotocol/ui":{"mimeTypes":["text/html;profile=mcp-app"]}}},"clientInfo":{"name":"claude-ai","version":"0.1.0"}},"jsonrpc":"2.0","id":0} { metadata: undefined }
error: Failed to install: pywin32-311-cp313-cp313-win_amd64.whl (pywin32==311)
Caused by: failed to remove directory `C:\Users\<USERNAME>\AppData\Local\uv\cache\builds-v0\.tmpsNO8KN\Lib\site-packages\pywin32-311.data`: The process cannot access the file because it is being used by another process. (os error 32)
2026-04-07T13:39:28.305Z [home-assistant] [info] Server transport closed { metadata: undefined }
2026-04-07T13:39:28.305Z [home-assistant] [info] Server transport closed unexpectedly, this is likely due to the process exiting early. If you are developing this MCP server you can add output to stderr (i.e. `console.error('...')` in JavaScript, `print('...', file=sys.stderr)` in python) and it will appear in this log. { metadata: undefined }
2026-04-07T13:39:28.305Z [home-assistant] [error] Server disconnected. For troubleshooting guidance, please visit our [debugging documentation](https://modelcontextprotocol.io/docs/tools/debugging) { metadata: { context: 'connection', stack: undefined } }
2026-04-07T13:39:28.305Z [home-assistant] [info] Client transport closed { metadata: undefined }
2026-04-07T13:39:28.305Z [home-assistant] [info] Client transport closed { metadata: undefined }
I've closed Claude & deleted the cache directory:
C:\\Users\\USERNAME\\AppData\\Local\\uv\\cache\\builds-v0
Checked Task Manger & Sys Internals both show no Python process running (In Process Manager I searched for the pywin32 handle. Nothing.
Rebooted
Disabled my Window AV
Ran uv cache clean
Ran Claude as admin
Posted here on Reddit 😊
What are my next steps?
I've got pyCharm installed but not running so it shouldn't be locking. Kinda run out of ideas.
Thanks for your help.
解决方案
这对我有用:
修复:在Windows上安装ha-mcp时出现的pywin32-311错误
如果官方安装程序在遇到pywin32文件锁定错误时失败,请跳过它,改为执行以下步骤:
1.打开PowerShell,手动安装ha-mcp:
powershell
uv cache clean
uv tool install ha-mcp --from git+https://github.com/homeassistant-ai/ha-mcp.git
2.将 uv工具添加到PATH:
powershell
uv tool update-shell
关闭并重新打开PowerShell。
3.更新你的 claude_desktop_config.json(在 C:\Users\<USERNAME>\AppData\Roaming\Claude\claude_desktop_config.json 找到):
json
{
"mcpServers": {
"Home Assistant": {
"command": "ha-mcp",
"args": [],
"env": {
"HOMEASSISTANT_URL": "http://homeassistant.local:8123",
"HOMEASSISTANT_TOKEN": "YOUR_TOKEN_HERE"
}
}
}
}
4.彻底重启Claude Desktop(File → Exit,然后重新打开)。
关键修复是直接将 ha-mcp 作为命令使用,而不是 uvx,并避免 --python 3.13,因为它会在Windows上触发pywin32问题。