misumi-mcp 0.1.0__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.
Files changed (98) hide show
  1. misumi_mcp-0.1.0/LICENSE +21 -0
  2. misumi_mcp-0.1.0/PKG-INFO +167 -0
  3. misumi_mcp-0.1.0/README.md +118 -0
  4. misumi_mcp-0.1.0/pyproject.toml +66 -0
  5. misumi_mcp-0.1.0/setup.cfg +4 -0
  6. misumi_mcp-0.1.0/src/misumi_mcp/__init__.py +0 -0
  7. misumi_mcp-0.1.0/src/misumi_mcp/api/__init__.py +0 -0
  8. misumi_mcp-0.1.0/src/misumi_mcp/api/cadenas.py +151 -0
  9. misumi_mcp-0.1.0/src/misumi_mcp/api/client.py +475 -0
  10. misumi_mcp-0.1.0/src/misumi_mcp/api/download_xml.py +167 -0
  11. misumi_mcp-0.1.0/src/misumi_mcp/api/endpoints.py +416 -0
  12. misumi_mcp-0.1.0/src/misumi_mcp/api/errors.py +97 -0
  13. misumi_mcp-0.1.0/src/misumi_mcp/api/misumi.py +280 -0
  14. misumi_mcp-0.1.0/src/misumi_mcp/api/models.py +317 -0
  15. misumi_mcp-0.1.0/src/misumi_mcp/api/parsing.py +640 -0
  16. misumi_mcp-0.1.0/src/misumi_mcp/api/rapiddesign.py +112 -0
  17. misumi_mcp-0.1.0/src/misumi_mcp/api/spec_choices.py +656 -0
  18. misumi_mcp-0.1.0/src/misumi_mcp/api/throttle.py +63 -0
  19. misumi_mcp-0.1.0/src/misumi_mcp/api/webassistant.py +95 -0
  20. misumi_mcp-0.1.0/src/misumi_mcp/auth/__init__.py +38 -0
  21. misumi_mcp-0.1.0/src/misumi_mcp/auth/session.py +424 -0
  22. misumi_mcp-0.1.0/src/misumi_mcp/auth/terms.py +107 -0
  23. misumi_mcp-0.1.0/src/misumi_mcp/auth/token_store.py +108 -0
  24. misumi_mcp-0.1.0/src/misumi_mcp/cad/__init__.py +0 -0
  25. misumi_mcp-0.1.0/src/misumi_mcp/cad/archive.py +489 -0
  26. misumi_mcp-0.1.0/src/misumi_mcp/cad/models.py +355 -0
  27. misumi_mcp-0.1.0/src/misumi_mcp/cad/providers/__init__.py +0 -0
  28. misumi_mcp-0.1.0/src/misumi_mcp/cad/providers/cadenas.py +277 -0
  29. misumi_mcp-0.1.0/src/misumi_mcp/cad/providers/rapiddesign.py +113 -0
  30. misumi_mcp-0.1.0/src/misumi_mcp/cad/providers/web2cad.py +246 -0
  31. misumi_mcp-0.1.0/src/misumi_mcp/cad/registry.py +123 -0
  32. misumi_mcp-0.1.0/src/misumi_mcp/cad/rules.py +291 -0
  33. misumi_mcp-0.1.0/src/misumi_mcp/cad/rules_worker.py +235 -0
  34. misumi_mcp-0.1.0/src/misumi_mcp/cad/service.py +270 -0
  35. misumi_mcp-0.1.0/src/misumi_mcp/cad/steps.py +32 -0
  36. misumi_mcp-0.1.0/src/misumi_mcp/config/__init__.py +64 -0
  37. misumi_mcp-0.1.0/src/misumi_mcp/config/clock.py +33 -0
  38. misumi_mcp-0.1.0/src/misumi_mcp/config/locks.py +146 -0
  39. misumi_mcp-0.1.0/src/misumi_mcp/config/logging.py +88 -0
  40. misumi_mcp-0.1.0/src/misumi_mcp/config/settings.py +212 -0
  41. misumi_mcp-0.1.0/src/misumi_mcp/config/state.py +128 -0
  42. misumi_mcp-0.1.0/src/misumi_mcp/main.py +139 -0
  43. misumi_mcp-0.1.0/src/misumi_mcp/tools/__init__.py +0 -0
  44. misumi_mcp-0.1.0/src/misumi_mcp/tools/auth.py +107 -0
  45. misumi_mcp-0.1.0/src/misumi_mcp/tools/cad.py +86 -0
  46. misumi_mcp-0.1.0/src/misumi_mcp/tools/errors.py +226 -0
  47. misumi_mcp-0.1.0/src/misumi_mcp/tools/price.py +112 -0
  48. misumi_mcp-0.1.0/src/misumi_mcp/tools/search.py +186 -0
  49. misumi_mcp-0.1.0/src/misumi_mcp/tools/series.py +335 -0
  50. misumi_mcp-0.1.0/src/misumi_mcp/web/__init__.py +0 -0
  51. misumi_mcp-0.1.0/src/misumi_mcp/web/assets.py +161 -0
  52. misumi_mcp-0.1.0/src/misumi_mcp/web/auth_server.py +502 -0
  53. misumi_mcp-0.1.0/src/misumi_mcp.egg-info/PKG-INFO +167 -0
  54. misumi_mcp-0.1.0/src/misumi_mcp.egg-info/SOURCES.txt +96 -0
  55. misumi_mcp-0.1.0/src/misumi_mcp.egg-info/dependency_links.txt +1 -0
  56. misumi_mcp-0.1.0/src/misumi_mcp.egg-info/entry_points.txt +2 -0
  57. misumi_mcp-0.1.0/src/misumi_mcp.egg-info/requires.txt +4 -0
  58. misumi_mcp-0.1.0/src/misumi_mcp.egg-info/top_level.txt +1 -0
  59. misumi_mcp-0.1.0/tests/test_archive.py +557 -0
  60. misumi_mcp-0.1.0/tests/test_auth_server.py +601 -0
  61. misumi_mcp-0.1.0/tests/test_auth_session.py +574 -0
  62. misumi_mcp-0.1.0/tests/test_cad_models.py +195 -0
  63. misumi_mcp-0.1.0/tests/test_cad_service.py +560 -0
  64. misumi_mcp-0.1.0/tests/test_cad_shapes.py +285 -0
  65. misumi_mcp-0.1.0/tests/test_cadenas.py +819 -0
  66. misumi_mcp-0.1.0/tests/test_cadenas_codes_and_retry.py +407 -0
  67. misumi_mcp-0.1.0/tests/test_config.py +107 -0
  68. misumi_mcp-0.1.0/tests/test_download_providers.py +534 -0
  69. misumi_mcp-0.1.0/tests/test_download_rapiddesign.py +180 -0
  70. misumi_mcp-0.1.0/tests/test_endpoints.py +66 -0
  71. misumi_mcp-0.1.0/tests/test_error_response.py +289 -0
  72. misumi_mcp-0.1.0/tests/test_http_client.py +437 -0
  73. misumi_mcp-0.1.0/tests/test_logging.py +183 -0
  74. misumi_mcp-0.1.0/tests/test_login_page.py +1002 -0
  75. misumi_mcp-0.1.0/tests/test_login_status.py +1206 -0
  76. misumi_mcp-0.1.0/tests/test_main.py +37 -0
  77. misumi_mcp-0.1.0/tests/test_misumi_auth_api.py +247 -0
  78. misumi_mcp-0.1.0/tests/test_misumi_cad_api.py +208 -0
  79. misumi_mcp-0.1.0/tests/test_misumi_catalog_api.py +442 -0
  80. misumi_mcp-0.1.0/tests/test_misumi_price_api.py +420 -0
  81. misumi_mcp-0.1.0/tests/test_no_consent_tool.py +78 -0
  82. misumi_mcp-0.1.0/tests/test_not_found_retry.py +277 -0
  83. misumi_mcp-0.1.0/tests/test_rapiddesign.py +442 -0
  84. misumi_mcp-0.1.0/tests/test_redirect_target.py +81 -0
  85. misumi_mcp-0.1.0/tests/test_registry.py +171 -0
  86. misumi_mcp-0.1.0/tests/test_rules.py +297 -0
  87. misumi_mcp-0.1.0/tests/test_shared_state.py +230 -0
  88. misumi_mcp-0.1.0/tests/test_terms.py +114 -0
  89. misumi_mcp-0.1.0/tests/test_throttle.py +196 -0
  90. misumi_mcp-0.1.0/tests/test_token_store.py +100 -0
  91. misumi_mcp-0.1.0/tests/test_tools_auth.py +192 -0
  92. misumi_mcp-0.1.0/tests/test_tools_cad.py +580 -0
  93. misumi_mcp-0.1.0/tests/test_tools_price.py +315 -0
  94. misumi_mcp-0.1.0/tests/test_tools_search.py +594 -0
  95. misumi_mcp-0.1.0/tests/test_tools_series.py +1718 -0
  96. misumi_mcp-0.1.0/tests/test_web2cad.py +450 -0
  97. misumi_mcp-0.1.0/tests/test_web2cad_registry.py +107 -0
  98. misumi_mcp-0.1.0/tests/test_webassistant.py +298 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Jason Chueh
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,167 @@
1
+ Metadata-Version: 2.4
2
+ Name: misumi-mcp
3
+ Version: 0.1.0
4
+ Summary: 讓 AI agent 使用 MISUMI 台灣型錄的 MCP server:搜尋零件、查規格與價格、下載 CAD,密碼不經過 LLM
5
+ Author: Jason Chueh
6
+ License: MIT License
7
+
8
+ Copyright (c) 2026 Jason Chueh
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
27
+
28
+ Project-URL: Homepage, https://github.com/jasoncychueh/misumi-mcp
29
+ Project-URL: Repository, https://github.com/jasoncychueh/misumi-mcp.git
30
+ Project-URL: Issues, https://github.com/jasoncychueh/misumi-mcp/issues
31
+ Keywords: misumi,mcp,model-context-protocol,cad,claude
32
+ Classifier: Development Status :: 3 - Alpha
33
+ Classifier: Intended Audience :: Developers
34
+ Classifier: Intended Audience :: Manufacturing
35
+ Classifier: Programming Language :: Python :: 3
36
+ Classifier: Programming Language :: Python :: 3.10
37
+ Classifier: Programming Language :: Python :: 3.11
38
+ Classifier: Programming Language :: Python :: 3.12
39
+ Classifier: Programming Language :: Python :: 3.13
40
+ Classifier: Operating System :: OS Independent
41
+ Requires-Python: >=3.10
42
+ Description-Content-Type: text/markdown
43
+ License-File: LICENSE
44
+ Requires-Dist: mcp[cli]<2,>=1.12
45
+ Requires-Dist: aiohttp>=3.9
46
+ Requires-Dist: mini-racer<0.15,>=0.12.4
47
+ Requires-Dist: filelock
48
+ Dynamic: license-file
49
+
50
+ # misumi-mcp
51
+
52
+ [![PyPI](https://img.shields.io/pypi/v/misumi-mcp)](https://pypi.org/project/misumi-mcp/)
53
+ [![Python](https://img.shields.io/pypi/pyversions/misumi-mcp)](https://pypi.org/project/misumi-mcp/)
54
+ [![License: MIT](https://img.shields.io/github/license/jasoncychueh/misumi-mcp)](LICENSE)
55
+ [![GitHub](https://img.shields.io/github/stars/jasoncychueh/misumi-mcp?style=social)](https://github.com/jasoncychueh/misumi-mcp)
56
+
57
+ 讓 AI agent 使用 MISUMI 台灣型錄(tw.misumi-ec.com)的 MCP server。密碼只在本機登入頁由真人輸入,不經過 LLM。
58
+
59
+ 執行時只用一般 HTTP 呼叫 MISUMI 網站本來就在用的 JSON API,不使用瀏覽器自動化。內建用戶端節流,被網站的 bot 防護擋下時會停止並告訴 agent 暫停一段時間。
60
+
61
+ ## 安裝
62
+
63
+ 1. 安裝 [uv](https://docs.astral.sh/uv/)。
64
+
65
+ Windows(PowerShell):
66
+
67
+ ```powershell
68
+ powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
69
+ ```
70
+
71
+ macOS/Linux:
72
+
73
+ ```sh
74
+ curl -LsSf https://astral.sh/uv/install.sh | sh
75
+ ```
76
+
77
+ 2. 加到 MCP client。server 以 stdio 傳輸執行,`uvx` 會自動從 PyPI 下載並執行最新版,不需要另外 clone 或安裝。以 Claude Code 為例:
78
+
79
+ ```
80
+ claude mcp add misumi -- uvx misumi-mcp
81
+ ```
82
+
83
+ 其他 MCP client 的設定檔格式不同,但欄位相同:command 是 `uvx`,args 是 `["misumi-mcp"]`。要覆寫預設值時,用該 MCP client 設定環境變數的方式帶入下方的 `MISUMI_MCP_*` 變數。
84
+
85
+ 3. 重新啟動 MCP client,請 agent 呼叫 `login`,在它給的網址輸入 MISUMI 帳號密碼。
86
+
87
+ ### 從原始碼執行(開發用)
88
+
89
+ ```
90
+ claude mcp add misumi-dev -- uv run --project <本專案的路徑> misumi-mcp
91
+ ```
92
+
93
+ ## 登入
94
+
95
+ 登入分三步,真人只需要在第二步輸入一次帳密:
96
+
97
+ 1. agent 呼叫 `login`。工具不接受帳號或密碼,只回傳本機登入頁的網址。
98
+ 2. 請真人在瀏覽器開啟該網址,輸入 MISUMI 的帳號與密碼。頁面上同時列出三份 CAD 資料使用條款(MISUMI、CADENAS、SMC),每份附官方原文連結與各自的勾選框;下載 CAD 前需要勾選對應的條款,不勾選也可以登入。
99
+ 3. agent 呼叫 `get_login_status` 確認已登入,以及哪些條款已同意、哪些還缺。
100
+
101
+ 要點:
102
+
103
+ - 登入頁只綁定 `127.0.0.1`,網址含每次啟動隨機產生的識別,沒有識別的請求一律回 404。
104
+ - 帳密只會轉送給 MISUMI 一次,不存檔、不寫入 log、不出現在工具回應中。
105
+ - 條款同意只能在登入頁上、帳密被 MISUMI 接受的同一次送出時記錄。agent 沒有任何工具或參數可以代替真人同意。
106
+ - 同意記錄綁定帳號,登出後仍然保留;換另一個帳號登入時,該帳號需要自己同意。已登入時也可以再開登入頁,重新輸入帳密並勾選缺少的條款。
107
+ - 登入狀態保存在資料目錄,重新啟動 server 後不需要重新登入。access token 約一小時到期,到期前會自動續期;續期被 MISUMI 明確拒絕時才會清除登入,這時請重新呼叫 `login`。
108
+ - 多個 server 行程(例如同時開了兩個 Claude Code session)可以共用同一個資料目錄,登入與條款同意互相可見。
109
+ - 呼叫 `logout` 會通知 MISUMI 並刪除本機保存的登入,同意記錄保留。
110
+
111
+ ### 真人和 server 不在同一台機器
112
+
113
+ 遠端 harness 的情況下,同時設定 `MISUMI_MCP_AUTH_BIND_PORT` 與 `MISUMI_MCP_AUTH_BASE_URL`:server 綁定 `127.0.0.1:<port>`,`login` 回傳以 `MISUMI_MCP_AUTH_BASE_URL` 為基底的網址,由 harness 負責把這個對外網址接到該埠。兩個變數只設定一個時,server 會在啟動時失敗並說明原因。對外網址應該是 `https://`,否則帳密會以明文經過 harness 的轉接,啟動時會在 log 寫出警告。
114
+
115
+ ## 目前提供的工具
116
+
117
+ | 工具 | 說明 |
118
+ |---|---|
119
+ | `login` | 回傳本機登入頁網址,請真人開啟並登入 |
120
+ | `logout` | 登出 MISUMI 並刪除本機保存的登入 |
121
+ | `get_login_status` | 是否已登入、到期時間、已同意與尚未同意的條款 |
122
+
123
+ ## 環境變數
124
+
125
+ 所有變數都是選用的,未設定時使用預設值。
126
+
127
+ | 變數 | 預設值 | 說明 |
128
+ |---|---|---|
129
+ | `MISUMI_MCP_DATA_DIR` | Windows:`%LOCALAPPDATA%\misumi-mcp`;其他平台依該平台的使用者資料目錄慣例 | 資料目錄:登入狀態、條款同意記錄、節流狀態、下載的 CAD 檔 |
130
+ | `MISUMI_MCP_AUTH_BIND_PORT` | (未設定,使用臨時埠) | 登入頁綁定的埠;必須和 `MISUMI_MCP_AUTH_BASE_URL` 一起設定 |
131
+ | `MISUMI_MCP_AUTH_BASE_URL` | (未設定) | `login` 回傳的網址基底;必須和 `MISUMI_MCP_AUTH_BIND_PORT` 一起設定 |
132
+ | `MISUMI_MCP_MIN_REQUEST_INTERVAL_SECONDS` | `1.0` | 兩個對外請求之間的最小間隔(所有主機、所有行程合計) |
133
+ | `MISUMI_MCP_HOURLY_REQUEST_CAP` | `300` | 滾動一小時內的請求數上限 |
134
+ | `MISUMI_MCP_BLOCK_COOLDOWN_SECONDS` | `900` | 被 bot 防護擋下後,對該主機停止請求的秒數 |
135
+ | `MISUMI_MCP_CAD_TIMEOUT_SECONDS` | `60` | 整個 CAD 下載流程的期限 |
136
+ | `MISUMI_MCP_RULES_EVAL_TIMEOUT_SECONDS` | `10` | CADENAS 規則 JS 單次求值的時限 |
137
+ | `MISUMI_MCP_RULES_MEMORY_LIMIT_MB` | `256` | CADENAS 規則 JS 的記憶體上限 |
138
+ | `MISUMI_MCP_HTTP_CONNECT_TIMEOUT_SECONDS` | `10` | 單一請求的連線時間上限 |
139
+ | `MISUMI_MCP_HTTP_TOTAL_TIMEOUT_SECONDS` | `30` | 單一請求的總時間上限 |
140
+ | `MISUMI_MCP_RESTORE_TIMEOUT_SECONDS` | `15` | 啟動時確認保存的登入的時間上限(在背景進行,不阻塞啟動) |
141
+ | `MISUMI_MCP_STATE_LOCK_TIMEOUT_SECONDS` | `90` | 取得資料目錄中狀態檔的鎖的等待上限;必須大於 `2 × (HTTP_TOTAL_TIMEOUT_SECONDS + MIN_REQUEST_INTERVAL_SECONDS)` |
142
+ | `MISUMI_MCP_LOG_LEVEL` | `INFO` | log 等級(`DEBUG`、`INFO`、`WARNING`、`ERROR`、`CRITICAL`);log 只寫到 stderr |
143
+
144
+ ## Proxy
145
+
146
+ - 對外請求自動使用系統的 proxy 設定:`HTTP_PROXY`、`HTTPS_PROXY` 等環境變數;Windows 上沒有設定這些環境變數時,也會使用系統(Internet Settings)的 proxy。
147
+ - 符合 `NO_PROXY` 的主機不經過 proxy。
148
+ - 永遠不會讀取 `.netrc`,所以不會意外附加帳密。
149
+ - 只支援 HTTP proxy。選到 SOCKS proxy(`socks4`、`socks5` 等)時,請求不會送出,會立即回錯誤並寫明不支援的 scheme。
150
+ - 透過 proxy 的 HTTPS 以 CONNECT 轉送,proxy 看不到 token。TLS 攔截式的 proxy 會換掉伺服器憑證,需要系統信任該 proxy 的根憑證,否則連線會失敗。
151
+
152
+ ## 開發
153
+
154
+ ```
155
+ uv run pytest # 不連 MISUMI;live 測試需用 -m live 明確選取
156
+ uv run ruff check .
157
+ ```
158
+
159
+ CADENAS 的規則 JS 是第三方程式碼,不放在 repo 裡。第一次跑測試時會從 CADENAS 的公開路徑下載到 `tests/.cadenas-cache/`,之後重複使用;下載不到時,相關測試會略過。
160
+
161
+ ## 發布
162
+
163
+ 推送 `v*` tag(例如 `v0.1.0`)時,GitHub Actions 打包並以 PyPI Trusted Publishing 發布,不需要 token。打 tag 前先在本機跑完整測試,並把 `pyproject.toml` 的 `version` 改成同一個版本。
164
+
165
+ ## 授權
166
+
167
+ MIT,見 [LICENSE](LICENSE)。
@@ -0,0 +1,118 @@
1
+ # misumi-mcp
2
+
3
+ [![PyPI](https://img.shields.io/pypi/v/misumi-mcp)](https://pypi.org/project/misumi-mcp/)
4
+ [![Python](https://img.shields.io/pypi/pyversions/misumi-mcp)](https://pypi.org/project/misumi-mcp/)
5
+ [![License: MIT](https://img.shields.io/github/license/jasoncychueh/misumi-mcp)](LICENSE)
6
+ [![GitHub](https://img.shields.io/github/stars/jasoncychueh/misumi-mcp?style=social)](https://github.com/jasoncychueh/misumi-mcp)
7
+
8
+ 讓 AI agent 使用 MISUMI 台灣型錄(tw.misumi-ec.com)的 MCP server。密碼只在本機登入頁由真人輸入,不經過 LLM。
9
+
10
+ 執行時只用一般 HTTP 呼叫 MISUMI 網站本來就在用的 JSON API,不使用瀏覽器自動化。內建用戶端節流,被網站的 bot 防護擋下時會停止並告訴 agent 暫停一段時間。
11
+
12
+ ## 安裝
13
+
14
+ 1. 安裝 [uv](https://docs.astral.sh/uv/)。
15
+
16
+ Windows(PowerShell):
17
+
18
+ ```powershell
19
+ powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
20
+ ```
21
+
22
+ macOS/Linux:
23
+
24
+ ```sh
25
+ curl -LsSf https://astral.sh/uv/install.sh | sh
26
+ ```
27
+
28
+ 2. 加到 MCP client。server 以 stdio 傳輸執行,`uvx` 會自動從 PyPI 下載並執行最新版,不需要另外 clone 或安裝。以 Claude Code 為例:
29
+
30
+ ```
31
+ claude mcp add misumi -- uvx misumi-mcp
32
+ ```
33
+
34
+ 其他 MCP client 的設定檔格式不同,但欄位相同:command 是 `uvx`,args 是 `["misumi-mcp"]`。要覆寫預設值時,用該 MCP client 設定環境變數的方式帶入下方的 `MISUMI_MCP_*` 變數。
35
+
36
+ 3. 重新啟動 MCP client,請 agent 呼叫 `login`,在它給的網址輸入 MISUMI 帳號密碼。
37
+
38
+ ### 從原始碼執行(開發用)
39
+
40
+ ```
41
+ claude mcp add misumi-dev -- uv run --project <本專案的路徑> misumi-mcp
42
+ ```
43
+
44
+ ## 登入
45
+
46
+ 登入分三步,真人只需要在第二步輸入一次帳密:
47
+
48
+ 1. agent 呼叫 `login`。工具不接受帳號或密碼,只回傳本機登入頁的網址。
49
+ 2. 請真人在瀏覽器開啟該網址,輸入 MISUMI 的帳號與密碼。頁面上同時列出三份 CAD 資料使用條款(MISUMI、CADENAS、SMC),每份附官方原文連結與各自的勾選框;下載 CAD 前需要勾選對應的條款,不勾選也可以登入。
50
+ 3. agent 呼叫 `get_login_status` 確認已登入,以及哪些條款已同意、哪些還缺。
51
+
52
+ 要點:
53
+
54
+ - 登入頁只綁定 `127.0.0.1`,網址含每次啟動隨機產生的識別,沒有識別的請求一律回 404。
55
+ - 帳密只會轉送給 MISUMI 一次,不存檔、不寫入 log、不出現在工具回應中。
56
+ - 條款同意只能在登入頁上、帳密被 MISUMI 接受的同一次送出時記錄。agent 沒有任何工具或參數可以代替真人同意。
57
+ - 同意記錄綁定帳號,登出後仍然保留;換另一個帳號登入時,該帳號需要自己同意。已登入時也可以再開登入頁,重新輸入帳密並勾選缺少的條款。
58
+ - 登入狀態保存在資料目錄,重新啟動 server 後不需要重新登入。access token 約一小時到期,到期前會自動續期;續期被 MISUMI 明確拒絕時才會清除登入,這時請重新呼叫 `login`。
59
+ - 多個 server 行程(例如同時開了兩個 Claude Code session)可以共用同一個資料目錄,登入與條款同意互相可見。
60
+ - 呼叫 `logout` 會通知 MISUMI 並刪除本機保存的登入,同意記錄保留。
61
+
62
+ ### 真人和 server 不在同一台機器
63
+
64
+ 遠端 harness 的情況下,同時設定 `MISUMI_MCP_AUTH_BIND_PORT` 與 `MISUMI_MCP_AUTH_BASE_URL`:server 綁定 `127.0.0.1:<port>`,`login` 回傳以 `MISUMI_MCP_AUTH_BASE_URL` 為基底的網址,由 harness 負責把這個對外網址接到該埠。兩個變數只設定一個時,server 會在啟動時失敗並說明原因。對外網址應該是 `https://`,否則帳密會以明文經過 harness 的轉接,啟動時會在 log 寫出警告。
65
+
66
+ ## 目前提供的工具
67
+
68
+ | 工具 | 說明 |
69
+ |---|---|
70
+ | `login` | 回傳本機登入頁網址,請真人開啟並登入 |
71
+ | `logout` | 登出 MISUMI 並刪除本機保存的登入 |
72
+ | `get_login_status` | 是否已登入、到期時間、已同意與尚未同意的條款 |
73
+
74
+ ## 環境變數
75
+
76
+ 所有變數都是選用的,未設定時使用預設值。
77
+
78
+ | 變數 | 預設值 | 說明 |
79
+ |---|---|---|
80
+ | `MISUMI_MCP_DATA_DIR` | Windows:`%LOCALAPPDATA%\misumi-mcp`;其他平台依該平台的使用者資料目錄慣例 | 資料目錄:登入狀態、條款同意記錄、節流狀態、下載的 CAD 檔 |
81
+ | `MISUMI_MCP_AUTH_BIND_PORT` | (未設定,使用臨時埠) | 登入頁綁定的埠;必須和 `MISUMI_MCP_AUTH_BASE_URL` 一起設定 |
82
+ | `MISUMI_MCP_AUTH_BASE_URL` | (未設定) | `login` 回傳的網址基底;必須和 `MISUMI_MCP_AUTH_BIND_PORT` 一起設定 |
83
+ | `MISUMI_MCP_MIN_REQUEST_INTERVAL_SECONDS` | `1.0` | 兩個對外請求之間的最小間隔(所有主機、所有行程合計) |
84
+ | `MISUMI_MCP_HOURLY_REQUEST_CAP` | `300` | 滾動一小時內的請求數上限 |
85
+ | `MISUMI_MCP_BLOCK_COOLDOWN_SECONDS` | `900` | 被 bot 防護擋下後,對該主機停止請求的秒數 |
86
+ | `MISUMI_MCP_CAD_TIMEOUT_SECONDS` | `60` | 整個 CAD 下載流程的期限 |
87
+ | `MISUMI_MCP_RULES_EVAL_TIMEOUT_SECONDS` | `10` | CADENAS 規則 JS 單次求值的時限 |
88
+ | `MISUMI_MCP_RULES_MEMORY_LIMIT_MB` | `256` | CADENAS 規則 JS 的記憶體上限 |
89
+ | `MISUMI_MCP_HTTP_CONNECT_TIMEOUT_SECONDS` | `10` | 單一請求的連線時間上限 |
90
+ | `MISUMI_MCP_HTTP_TOTAL_TIMEOUT_SECONDS` | `30` | 單一請求的總時間上限 |
91
+ | `MISUMI_MCP_RESTORE_TIMEOUT_SECONDS` | `15` | 啟動時確認保存的登入的時間上限(在背景進行,不阻塞啟動) |
92
+ | `MISUMI_MCP_STATE_LOCK_TIMEOUT_SECONDS` | `90` | 取得資料目錄中狀態檔的鎖的等待上限;必須大於 `2 × (HTTP_TOTAL_TIMEOUT_SECONDS + MIN_REQUEST_INTERVAL_SECONDS)` |
93
+ | `MISUMI_MCP_LOG_LEVEL` | `INFO` | log 等級(`DEBUG`、`INFO`、`WARNING`、`ERROR`、`CRITICAL`);log 只寫到 stderr |
94
+
95
+ ## Proxy
96
+
97
+ - 對外請求自動使用系統的 proxy 設定:`HTTP_PROXY`、`HTTPS_PROXY` 等環境變數;Windows 上沒有設定這些環境變數時,也會使用系統(Internet Settings)的 proxy。
98
+ - 符合 `NO_PROXY` 的主機不經過 proxy。
99
+ - 永遠不會讀取 `.netrc`,所以不會意外附加帳密。
100
+ - 只支援 HTTP proxy。選到 SOCKS proxy(`socks4`、`socks5` 等)時,請求不會送出,會立即回錯誤並寫明不支援的 scheme。
101
+ - 透過 proxy 的 HTTPS 以 CONNECT 轉送,proxy 看不到 token。TLS 攔截式的 proxy 會換掉伺服器憑證,需要系統信任該 proxy 的根憑證,否則連線會失敗。
102
+
103
+ ## 開發
104
+
105
+ ```
106
+ uv run pytest # 不連 MISUMI;live 測試需用 -m live 明確選取
107
+ uv run ruff check .
108
+ ```
109
+
110
+ CADENAS 的規則 JS 是第三方程式碼,不放在 repo 裡。第一次跑測試時會從 CADENAS 的公開路徑下載到 `tests/.cadenas-cache/`,之後重複使用;下載不到時,相關測試會略過。
111
+
112
+ ## 發布
113
+
114
+ 推送 `v*` tag(例如 `v0.1.0`)時,GitHub Actions 打包並以 PyPI Trusted Publishing 發布,不需要 token。打 tag 前先在本機跑完整測試,並把 `pyproject.toml` 的 `version` 改成同一個版本。
115
+
116
+ ## 授權
117
+
118
+ MIT,見 [LICENSE](LICENSE)。
@@ -0,0 +1,66 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "misumi-mcp"
7
+ version = "0.1.0"
8
+ description = "讓 AI agent 使用 MISUMI 台灣型錄的 MCP server:搜尋零件、查規格與價格、下載 CAD,密碼不經過 LLM"
9
+ readme = "README.md"
10
+ license = {file = "LICENSE"}
11
+ authors = [{name = "Jason Chueh"}]
12
+ keywords = ["misumi", "mcp", "model-context-protocol", "cad", "claude"]
13
+ classifiers = [
14
+ "Development Status :: 3 - Alpha",
15
+ "Intended Audience :: Developers",
16
+ "Intended Audience :: Manufacturing",
17
+ "Programming Language :: Python :: 3",
18
+ "Programming Language :: Python :: 3.10",
19
+ "Programming Language :: Python :: 3.11",
20
+ "Programming Language :: Python :: 3.12",
21
+ "Programming Language :: Python :: 3.13",
22
+ "Operating System :: OS Independent",
23
+ ]
24
+ requires-python = ">=3.10"
25
+ dependencies = [
26
+ "mcp[cli]>=1.12,<2", # <2 必須保留:2.0 搬動了 mcp.server.fastmcp 並改名 FastMCP
27
+ "aiohttp>=3.9",
28
+ "mini-racer>=0.12.4,<0.15",
29
+ "filelock",
30
+ ]
31
+
32
+ [project.urls]
33
+ Homepage = "https://github.com/jasoncychueh/misumi-mcp"
34
+ Repository = "https://github.com/jasoncychueh/misumi-mcp.git"
35
+ Issues = "https://github.com/jasoncychueh/misumi-mcp/issues"
36
+
37
+ [project.scripts]
38
+ misumi-mcp = "misumi_mcp.main:run"
39
+
40
+ # uv 預設會安裝 dev 群組,所以 `uv run pytest` 不需要額外參數
41
+ [dependency-groups]
42
+ dev = ["pytest>=8.0", "pytest-asyncio>=0.24", "ruff>=0.14"]
43
+
44
+ [tool.setuptools.packages.find]
45
+ where = ["src"]
46
+
47
+ [tool.pytest.ini_options]
48
+ testpaths = ["tests"]
49
+ asyncio_mode = "auto"
50
+ asyncio_default_fixture_loop_scope = "function"
51
+ addopts = "-m 'not live'"
52
+ markers = [
53
+ "live: 真的連線到 MISUMI 的測試,預設不執行(以 -m live 選取)",
54
+ "case(id): 對應 spec 測試案例的編號,例如 T-12,可用 --case 選取",
55
+ ]
56
+
57
+ [tool.ruff]
58
+ target-version = "py310"
59
+ line-length = 100
60
+ src = ["src", "tests"]
61
+
62
+ [tool.ruff.lint]
63
+ select = ["E4", "E7", "E9", "F", "I"]
64
+
65
+ [tool.ruff.lint.isort]
66
+ known-first-party = ["misumi_mcp"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
File without changes
File without changes
@@ -0,0 +1,151 @@
1
+ """MISUMI 自家 CADENAS(`cadSiteType` 1)的 HTTP 端點。
2
+
3
+ 全部是匿名 GET:不送 Authorization、cookie、sessionId 或 userId。vars、`tblVars` 與零件字串
4
+ 只出現在 query 中,這裡不記錄它們。
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ import math
10
+ import re
11
+ from collections.abc import Mapping
12
+ from decimal import Decimal
13
+ from typing import Any
14
+ from urllib.parse import urlsplit
15
+
16
+ from misumi_mcp.api import endpoints as ep
17
+ from misumi_mcp.api.client import HttpClient, HttpRequest, HttpResponse
18
+ from misumi_mcp.api.download_xml import CadOrder, fetch_download_xml
19
+ from misumi_mcp.api.endpoints import Host, HostTable
20
+ from misumi_mcp.api.errors import UpstreamError
21
+ from misumi_mcp.api.models import CadenasValidation, StaticFile
22
+ from misumi_mcp.api.parsing import host_of, json_object, resolve_redirect_target
23
+
24
+ _MAX_AGE = re.compile(r"max-age\s*=\s*(\d+)", re.IGNORECASE)
25
+ _REDIRECT = 302
26
+
27
+
28
+ class CadenasClient:
29
+ """CADENAS 的規則靜態檔、`test.vbs`、`cgi2pview` 與 download.xml。不擁有 `http`。"""
30
+
31
+ def __init__(self, http: HttpClient, hosts: HostTable):
32
+ self._http = http
33
+ self._hosts = hosts
34
+
35
+ @property
36
+ def host(self) -> str:
37
+ """實際呼叫的主機(含埠),套用 `host_overrides` 之後。"""
38
+ return urlsplit(self._hosts.url(Host.CADENAS, "/")).netloc.lower()
39
+
40
+ async def fetch_static(self, path: str) -> StaticFile | None:
41
+ """取規則靜態檔;404 回 None。`path` 以 `/` 開頭,可以帶網站的版本參數。"""
42
+ resp = await self._http.request(HttpRequest("GET", self._hosts.url(Host.CADENAS, path)))
43
+ if resp.status == 404:
44
+ return None
45
+ if resp.status != 200:
46
+ raise UpstreamError(host_of(resp), resp.status, "unexpected status")
47
+ return StaticFile(resp.text(), _max_age_seconds(resp.headers))
48
+
49
+ async def validate_vars(self, prj: str, vars: Mapping[str, str]) -> CadenasValidation:
50
+ """`test.vbs`:vars 轉成正規化的 `tblVars` 與 `LINA`。`prj` 不含開頭的 `/`。
51
+
52
+ 這裡只解析,不判斷 `prjOK` 與 `LINA` 的意義。
53
+ """
54
+ resp = await self._http.request(
55
+ HttpRequest(
56
+ "GET",
57
+ self._hosts.url(Host.CADENAS, ep.CADENAS_VALIDATE_PATH),
58
+ query=ep.cadenas_validate_query(prj, vars),
59
+ )
60
+ )
61
+ if not 200 <= resp.status < 300:
62
+ raise UpstreamError(host_of(resp), resp.status, "unexpected status")
63
+ body = json_object(resp)
64
+ if body is None:
65
+ raise UpstreamError(host_of(resp), resp.status, "response is not a JSON object")
66
+ prj_ok = _is_one(body.get("prjOK"))
67
+ lina = body.get("LINA")
68
+ return CadenasValidation(
69
+ prj_ok=prj_ok,
70
+ lina=lina if isinstance(lina, str) and lina else None,
71
+ tbl_vars=_tbl_vars(resp, body) if prj_ok else {},
72
+ )
73
+
74
+ async def generate(self, part: str, format_code: str) -> str:
75
+ """`cgi2pview` 產生 CAD;回傳 download.xml 的絕對網址(取自 302 `Location` 的 `xmlfile`)。"""
76
+ resp = await self._http.request(
77
+ HttpRequest(
78
+ "GET",
79
+ self._hosts.url(Host.CADENAS, ep.CADENAS_GENERATE_PATH),
80
+ query=ep.cadenas_generate_query(part, format_code),
81
+ )
82
+ )
83
+ if resp.status != _REDIRECT:
84
+ raise UpstreamError(host_of(resp), resp.status, "generate did not redirect")
85
+ return resolve_redirect_target(resp.location, "xmlfile", self._hosts, Host.CADENAS)
86
+
87
+ async def download_xml(self, url: str) -> CadOrder:
88
+ """取得並解析 download.xml;HTTP 200 的內容也可能是服務的錯誤(`message`)。"""
89
+ return await fetch_download_xml(self._http, url)
90
+
91
+
92
+ def _max_age_seconds(headers: Mapping[str, str]) -> int | None:
93
+ """`Cache-Control` 的 `max-age`;沒有、不是正整數,或同時有 `no-store`/`no-cache` 時 None。"""
94
+ values = [value for name, value in headers.items() if name.lower() == "cache-control"]
95
+ directives = [part.strip() for value in values for part in value.split(",")]
96
+ if any(d.lower() in ("no-store", "no-cache") for d in directives):
97
+ return None
98
+ for directive in directives:
99
+ match = _MAX_AGE.fullmatch(directive)
100
+ if match and int(match.group(1)) > 0:
101
+ return int(match.group(1))
102
+ return None
103
+
104
+
105
+ def _is_one(value: object) -> bool:
106
+ if isinstance(value, bool):
107
+ return False
108
+ return value == 1 or value == "1"
109
+
110
+
111
+ def _tbl_vars(resp: HttpResponse, body: dict[str, Any]) -> dict[str, str]:
112
+ raw = body.get("tblVars")
113
+ if not isinstance(raw, dict):
114
+ raise UpstreamError(host_of(resp), resp.status, "tblVars is not an object")
115
+ out: dict[str, str] = {}
116
+ for key, value in raw.items():
117
+ if isinstance(value, (list, dict)):
118
+ raise UpstreamError(host_of(resp), resp.status, "tblVars holds a non-scalar value")
119
+ out[key] = _js_string(value)
120
+ return out
121
+
122
+
123
+ def _js_string(value: object) -> str:
124
+ """與 JS 的 `String()` 相同的字串化:整數值不帶小數點,`null` 是空字串。"""
125
+ if value is None:
126
+ return ""
127
+ if isinstance(value, bool):
128
+ return "true" if value else "false"
129
+ if isinstance(value, int):
130
+ return str(value)
131
+ if isinstance(value, float):
132
+ return _js_float(value)
133
+ return str(value)
134
+
135
+
136
+ def _js_float(value: float) -> str:
137
+ if math.isnan(value):
138
+ return "NaN"
139
+ if math.isinf(value):
140
+ return "Infinity" if value > 0 else "-Infinity"
141
+ if value.is_integer() and abs(value) < 1e21:
142
+ return str(int(value))
143
+ text = repr(value)
144
+ if "e" not in text:
145
+ return text
146
+ if 1e-6 <= abs(value) < 1e21:
147
+ # Python 的 repr 較早改用指數,JS 在這個範圍仍寫成一般小數。
148
+ return format(Decimal(text), "f")
149
+ mantissa, _, exponent = text.partition("e")
150
+ sign = "-" if int(exponent) < 0 else "+"
151
+ return f"{mantissa.removesuffix('.0')}e{sign}{abs(int(exponent))}"