mcp-proxy-adapter 2.1.17__py3-none-any.whl → 3.0.0__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.
Files changed (84) hide show
  1. examples/__init__.py +19 -0
  2. examples/anti_patterns/README.md +51 -0
  3. examples/anti_patterns/__init__.py +9 -0
  4. examples/anti_patterns/bad_design/README.md +72 -0
  5. examples/anti_patterns/bad_design/global_state.py +170 -0
  6. examples/anti_patterns/bad_design/monolithic_command.py +272 -0
  7. examples/basic_example/README.md +131 -0
  8. examples/basic_example/__init__.py +8 -0
  9. examples/basic_example/commands/__init__.py +5 -0
  10. examples/basic_example/commands/echo_command.py +95 -0
  11. examples/basic_example/commands/math_command.py +151 -0
  12. examples/basic_example/commands/time_command.py +152 -0
  13. examples/basic_example/config.json +21 -0
  14. examples/basic_example/config.yaml +20 -0
  15. examples/basic_example/docs/EN/README.md +136 -0
  16. examples/basic_example/docs/RU/README.md +136 -0
  17. examples/basic_example/main.py +50 -0
  18. examples/basic_example/server.py +45 -0
  19. examples/basic_example/tests/conftest.py +243 -0
  20. examples/commands/echo_command.py +52 -0
  21. examples/commands/echo_result.py +65 -0
  22. examples/commands/get_date_command.py +98 -0
  23. examples/commands/new_uuid4_command.py +91 -0
  24. examples/complete_example/Dockerfile +24 -0
  25. examples/complete_example/README.md +92 -0
  26. examples/complete_example/__init__.py +8 -0
  27. examples/complete_example/commands/__init__.py +5 -0
  28. examples/complete_example/commands/system_command.py +327 -0
  29. examples/complete_example/config.json +41 -0
  30. examples/complete_example/configs/config.dev.yaml +40 -0
  31. examples/complete_example/configs/config.docker.yaml +40 -0
  32. examples/complete_example/docker-compose.yml +35 -0
  33. examples/complete_example/main.py +67 -0
  34. examples/complete_example/requirements.txt +20 -0
  35. examples/complete_example/server.py +85 -0
  36. examples/minimal_example/README.md +51 -0
  37. examples/minimal_example/__init__.py +8 -0
  38. examples/minimal_example/config.json +21 -0
  39. examples/minimal_example/config.yaml +26 -0
  40. examples/minimal_example/main.py +67 -0
  41. examples/minimal_example/simple_server.py +124 -0
  42. examples/minimal_example/tests/conftest.py +171 -0
  43. examples/minimal_example/tests/test_hello_command.py +111 -0
  44. examples/minimal_example/tests/test_integration.py +183 -0
  45. examples/server.py +69 -0
  46. examples/simple_server.py +137 -0
  47. examples/test_server.py +126 -0
  48. mcp_proxy_adapter/__init__.py +33 -1
  49. mcp_proxy_adapter/config.py +186 -0
  50. mcp_proxy_adapter/custom_openapi.py +125 -0
  51. mcp_proxy_adapter/framework.py +109 -0
  52. mcp_proxy_adapter/openapi.py +403 -0
  53. mcp_proxy_adapter/version.py +3 -0
  54. mcp_proxy_adapter-3.0.0.dist-info/METADATA +200 -0
  55. mcp_proxy_adapter-3.0.0.dist-info/RECORD +58 -0
  56. {mcp_proxy_adapter-2.1.17.dist-info → mcp_proxy_adapter-3.0.0.dist-info}/top_level.txt +1 -0
  57. mcp_proxy_adapter/adapter.py +0 -697
  58. mcp_proxy_adapter/analyzers/__init__.py +0 -1
  59. mcp_proxy_adapter/analyzers/docstring_analyzer.py +0 -199
  60. mcp_proxy_adapter/analyzers/type_analyzer.py +0 -151
  61. mcp_proxy_adapter/dispatchers/__init__.py +0 -1
  62. mcp_proxy_adapter/dispatchers/base_dispatcher.py +0 -85
  63. mcp_proxy_adapter/dispatchers/json_rpc_dispatcher.py +0 -262
  64. mcp_proxy_adapter/examples/analyze_config.py +0 -141
  65. mcp_proxy_adapter/examples/basic_integration.py +0 -155
  66. mcp_proxy_adapter/examples/docstring_and_schema_example.py +0 -69
  67. mcp_proxy_adapter/examples/extension_example.py +0 -72
  68. mcp_proxy_adapter/examples/help_best_practices.py +0 -67
  69. mcp_proxy_adapter/examples/help_usage.py +0 -64
  70. mcp_proxy_adapter/examples/mcp_proxy_client.py +0 -131
  71. mcp_proxy_adapter/examples/openapi_server.py +0 -383
  72. mcp_proxy_adapter/examples/project_structure_example.py +0 -47
  73. mcp_proxy_adapter/examples/testing_example.py +0 -64
  74. mcp_proxy_adapter/models.py +0 -47
  75. mcp_proxy_adapter/registry.py +0 -439
  76. mcp_proxy_adapter/schema.py +0 -257
  77. mcp_proxy_adapter/testing_utils.py +0 -112
  78. mcp_proxy_adapter/validators/__init__.py +0 -1
  79. mcp_proxy_adapter/validators/docstring_validator.py +0 -75
  80. mcp_proxy_adapter/validators/metadata_validator.py +0 -76
  81. mcp_proxy_adapter-2.1.17.dist-info/METADATA +0 -376
  82. mcp_proxy_adapter-2.1.17.dist-info/RECORD +0 -30
  83. {mcp_proxy_adapter-2.1.17.dist-info → mcp_proxy_adapter-3.0.0.dist-info}/WHEEL +0 -0
  84. {mcp_proxy_adapter-2.1.17.dist-info → mcp_proxy_adapter-3.0.0.dist-info}/licenses/LICENSE +0 -0
@@ -1,376 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: mcp-proxy-adapter
3
- Version: 2.1.17
4
- Summary: Adapter for exposing Command Registry commands as tools for AI models via MCP Proxy.
5
- Home-page: https://github.com/vasilyvz/mcp-proxy-adapter
6
- Author: Vasiliy VZ
7
- Author-email: Vasiliy VZ <vasilyvz@example.com>
8
- License: MIT
9
- Project-URL: Homepage, https://github.com/vasilyvz/mcp-proxy-adapter
10
- Project-URL: Bug Tracker, https://github.com/vasilyvz/mcp-proxy-adapter/issues
11
- Project-URL: Documentation, https://github.com/vasilyvz/mcp-proxy-adapter/tree/main/docs
12
- Classifier: Development Status :: 4 - Beta
13
- Classifier: Intended Audience :: Developers
14
- Classifier: License :: OSI Approved :: MIT License
15
- Classifier: Programming Language :: Python :: 3
16
- Classifier: Programming Language :: Python :: 3.9
17
- Classifier: Programming Language :: Python :: 3.10
18
- Classifier: Programming Language :: Python :: 3.11
19
- Classifier: Programming Language :: Python :: 3.12
20
- Requires-Python: >=3.9, <4
21
- Description-Content-Type: text/markdown
22
- License-File: LICENSE
23
- Requires-Dist: fastapi<1.0.0,>=0.95.0
24
- Requires-Dist: pydantic>=2.0.0
25
- Requires-Dist: uvicorn<1.0.0,>=0.22.0
26
- Requires-Dist: docstring-parser<1.0.0,>=0.15
27
- Requires-Dist: typing-extensions<5.0.0,>=4.5.0
28
- Dynamic: author
29
- Dynamic: home-page
30
- Dynamic: license-file
31
- Dynamic: requires-python
32
-
33
- # MCP Proxy Adapter
34
-
35
- Adapter for integrating [Command Registry](docs/README.md) with MCP Proxy, allowing you to use commands as tools for AI models.
36
-
37
- ## Overview
38
-
39
- MCP Proxy Adapter transforms commands registered in the Command Registry into a format compatible with MCP Proxy. This enables:
40
-
41
- 1. Using existing commands as tools for AI models
42
- 2. Creating a hybrid REST/JSON-RPC API for command execution
43
- 3. Automatic generation of OpenAPI schemas optimized for MCP Proxy
44
- 4. Managing tool metadata for better AI system integration
45
-
46
- ## Installation
47
-
48
- ```bash
49
- pip install mcp-proxy-adapter
50
- ```
51
-
52
- ## Quick Start
53
-
54
- ```python
55
- from mcp_proxy_adapter import MCPProxyAdapter, CommandRegistry
56
- from fastapi import FastAPI
57
-
58
- # Create a command registry instance
59
- registry = CommandRegistry()
60
-
61
- # Register commands
62
- def calculate_total(prices: list[float], discount: float = 0.0) -> float:
63
- """
64
- Calculates the total price with discount.
65
- Args:
66
- prices: List of item prices
67
- discount: Discount percentage (0-100)
68
- Returns:
69
- Total price with discount
70
- """
71
- subtotal = sum(prices)
72
- return subtotal * (1 - discount / 100)
73
-
74
- registry.register_command("calculate_total", calculate_total)
75
-
76
- # Create FastAPI app
77
- app = FastAPI()
78
-
79
- # Create and configure MCP Proxy adapter
80
- adapter = MCPProxyAdapter(registry)
81
-
82
- # Register endpoints in FastAPI app
83
- adapter.register_endpoints(app)
84
-
85
- # Generate and save MCP Proxy config
86
- adapter.save_config_to_file("mcp_proxy_config.json")
87
- ```
88
-
89
- ## Supported Request Formats
90
-
91
- The adapter supports three request formats for command execution:
92
-
93
- ### 1. JSON-RPC format
94
-
95
- ```json
96
- {
97
- "jsonrpc": "2.0",
98
- "method": "command_name",
99
- "params": {
100
- "param1": "value1",
101
- "param2": "value2"
102
- },
103
- "id": 1
104
- }
105
- ```
106
-
107
- Example request to `/cmd` endpoint:
108
-
109
- ```bash
110
- curl -X POST -H "Content-Type: application/json" -d '{
111
- "jsonrpc": "2.0",
112
- "method": "calculate_total",
113
- "params": {
114
- "prices": [100, 200, 300],
115
- "discount": 10
116
- },
117
- "id": 1
118
- }' http://localhost:8000/cmd
119
- ```
120
-
121
- Response:
122
-
123
- ```json
124
- {
125
- "jsonrpc": "2.0",
126
- "result": 540.0,
127
- "id": 1
128
- }
129
- ```
130
-
131
- ### 2. MCP Proxy format
132
-
133
- ```json
134
- {
135
- "command": "command_name",
136
- "params": {
137
- "param1": "value1",
138
- "param2": "value2"
139
- }
140
- }
141
- ```
142
-
143
- Example request:
144
-
145
- ```bash
146
- curl -X POST -H "Content-Type: application/json" -d '{
147
- "command": "calculate_total",
148
- "params": {
149
- "prices": [100, 200, 300],
150
- "discount": 10
151
- }
152
- }' http://localhost:8000/cmd
153
- ```
154
-
155
- Response:
156
-
157
- ```json
158
- {
159
- "result": 540.0
160
- }
161
- ```
162
-
163
- ### 3. Params-only format
164
-
165
- ```json
166
- {
167
- "params": {
168
- "command": "command_name",
169
- "param1": "value1",
170
- "param2": "value2"
171
- }
172
- }
173
- ```
174
-
175
- or
176
-
177
- ```json
178
- {
179
- "params": {
180
- "query": "command_name",
181
- "param1": "value1",
182
- "param2": "value2"
183
- }
184
- }
185
- ```
186
-
187
- Example request:
188
-
189
- ```bash
190
- curl -X POST -H "Content-Type: application/json" -d '{
191
- "params": {
192
- "command": "calculate_total",
193
- "prices": [100, 200, 300],
194
- "discount": 10
195
- }
196
- }' http://localhost:8000/cmd
197
- ```
198
-
199
- Response:
200
-
201
- ```json
202
- {
203
- "result": 540.0
204
- }
205
- ```
206
-
207
- ## Full Example: Integration with FastAPI
208
-
209
- ```python
210
- import logging
211
- from fastapi import FastAPI, APIRouter
212
- from mcp_proxy_adapter import CommandRegistry, MCPProxyAdapter, configure_logger
213
-
214
- # Configure logging
215
- logging.basicConfig(level=logging.INFO)
216
- project_logger = logging.getLogger("my_project")
217
-
218
- # Create FastAPI app
219
- app = FastAPI(title="My API with MCP Proxy Integration")
220
-
221
- # Create existing API router
222
- router = APIRouter()
223
-
224
- @router.get("/items")
225
- async def get_items():
226
- """Returns a list of items."""
227
- return [
228
- {"id": 1, "name": "Smartphone X", "price": 999.99},
229
- {"id": 2, "name": "Laptop Y", "price": 1499.99},
230
- ]
231
-
232
- app.include_router(router)
233
-
234
- # Register commands
235
- registry = CommandRegistry()
236
-
237
- def get_discounted_price(price: float, discount: float = 0.0) -> float:
238
- """
239
- Returns the price after applying a discount.
240
- """
241
- return price * (1 - discount / 100)
242
-
243
- registry.register_command("get_discounted_price", get_discounted_price)
244
-
245
- # Create and register MCP Proxy adapter
246
- adapter = MCPProxyAdapter(registry)
247
- adapter.register_endpoints(app)
248
-
249
- # Save MCP Proxy config
250
- adapter.save_config_to_file("mcp_proxy_config.json")
251
- ```
252
-
253
- ## Features
254
- - Universal JSON-RPC endpoint for command execution
255
- - Automatic OpenAPI schema generation and optimization for MCP Proxy
256
- - Tool metadata for AI models
257
- - Customizable endpoints and logging
258
- - Full test coverage and examples
259
-
260
- ## FAQ
261
-
262
- **Q: Почему не удаётся использовать декоратор @registry.command для регистрации команд?**
263
- A: В последних версиях пакета декоратор @registry.command больше не поддерживается. Теперь команды регистрируются только явно, через вызов метода:
264
-
265
- ```python
266
- registry.register_command("имя_команды", функция)
267
- ```
268
-
269
- **Q: Почему не удаётся импортировать CommandRegistry напрямую из mcp_proxy_adapter?**
270
- A: Класс CommandRegistry находится в подмодуле registry. Используйте:
271
-
272
- ```python
273
- from mcp_proxy_adapter.registry import CommandRegistry
274
- ```
275
-
276
- **Q: Какой способ импорта MCPProxyAdapter и configure_logger?**
277
- A: Импортируйте их из подмодуля adapter:
278
-
279
- ```python
280
- from mcp_proxy_adapter.adapter import MCPProxyAdapter, configure_logger
281
- ```
282
-
283
- **Q: Как добавить свою команду?**
284
- A: Зарегистрируйте функцию через registry.register_command или декоратор (см. примеры выше).
285
-
286
- **Q: Как получить OpenAPI-схему?**
287
- A: После регистрации адаптера вызовите /openapi.json в вашем FastAPI-приложении.
288
-
289
- **Q: Какой формат запроса поддерживается?**
290
- A: JSON-RPC, MCP Proxy и params-only (см. раздел Supported Request Formats).
291
-
292
- ## HOWTO
293
-
294
- **Как интегрировать MCP Proxy Adapter с FastAPI:**
295
- 1. Установите пакет:
296
- ```bash
297
- pip install mcp-proxy-adapter
298
- ```
299
- 2. Импортируйте нужные классы:
300
- ```python
301
- from mcp_proxy_adapter.registry import CommandRegistry
302
- from mcp_proxy_adapter.adapter import MCPProxyAdapter
303
- ```
304
- 3. Зарегистрируйте команды и настройте FastAPI:
305
- ```python
306
- registry = CommandRegistry()
307
- registry.register_command("my_command", my_function)
308
- app = FastAPI()
309
- adapter = MCPProxyAdapter(registry)
310
- adapter.register_endpoints(app)
311
- ```
312
- 4. (Опционально) Сохраните конфиг для MCP Proxy:
313
- ```python
314
- adapter.save_config_to_file("mcp_proxy_config.json")
315
- ```
316
-
317
- **Как добавить поддержку кастомного логгера:**
318
- ```python
319
- import logging
320
- from mcp_proxy_adapter.adapter import configure_logger
321
- logger = logging.getLogger("my_project")
322
- adapter_logger = configure_logger(logger)
323
- ```
324
-
325
- **Как получить список всех команд через API:**
326
- Вызовите GET `/api/commands` на вашем сервере FastAPI.
327
-
328
- ## License
329
- MIT
330
-
331
- ## Documentation
332
- See [docs/](docs/) for detailed guides, architecture, and examples.
333
-
334
- ## CI/CD & PyPI automation
335
-
336
- This project uses GitHub Actions for continuous integration and automated publishing to PyPI.
337
-
338
- - All tests are run on every push and pull request.
339
- - On push of a new tag (vX.Y.Z), the package is built and published to PyPI automatically.
340
-
341
- See `.github/workflows/publish.yml` for details.
342
-
343
- ## Встроенная команда help: правила и типовые ошибки
344
-
345
- ### Как работает
346
- - Команда `help` всегда встроена в MCPProxyAdapter и не требует реализации или регистрации со стороны пользователя.
347
- - Для получения справки по конкретной команде используйте параметр `cmdname`:
348
- ```json
349
- {"jsonrpc": "2.0", "method": "help", "params": {"cmdname": "имя_команды"}, "id": 1}
350
- ```
351
- - Для получения списка всех команд:
352
- ```json
353
- {"jsonrpc": "2.0", "method": "help", "id": 1}
354
- ```
355
-
356
- ### Типовые ошибки и их решения
357
- - **Ошибка: передан параметр `command` вместо `cmdname`**
358
- - Ответ:
359
- ```json
360
- {"error": "Parameter 'command' is not supported. Use 'cmdname' instead.", "hint": "Send params: {\"cmdname\": \"your_command\"}", ...}
361
- ```
362
- - **Решение:** всегда используйте `cmdname`.
363
- - **Ошибка сериализации coroutine**
364
- - Причина: handler вызывается без await, либо возвращает coroutine.
365
- - Ответ:
366
- ```json
367
- {"error": "Help handler must be awaited. Call as await dispatcher.execute('help', ...) in async context.", ...}
368
- ```
369
- - **Решение:** всегда await-ить dispatcher.execute в async endpoint.
370
-
371
- ### Важно для интеграторов и пользователей
372
- - Не реализуйте свой обработчик help — используйте встроенный.
373
- - Не используйте параметр `command` — только `cmdname`.
374
- - Все ошибки help-команды теперь сопровождаются понятной подсказкой и примером корректного запроса.
375
-
376
- ---
@@ -1,30 +0,0 @@
1
- mcp_proxy_adapter/__init__.py,sha256=Nqnn8clbgv-5l0PgxcTOldg8mkMKrFn4TvPL-rYUUGg,1
2
- mcp_proxy_adapter/adapter.py,sha256=x5pT-t4uT12O3GzLurrKBSQ_hwVpjhCRx5oZ5AdZnpY,28856
3
- mcp_proxy_adapter/models.py,sha256=8zVWU6ly18pWozOnKQ2gsGpmTgL37-fFE_Fr1SDW-Nk,2530
4
- mcp_proxy_adapter/registry.py,sha256=jgC4TKaPbMbAsoxvGp2ToaOE4drD-VfZug7WJbm4IW4,15853
5
- mcp_proxy_adapter/schema.py,sha256=HZM0TTQTSi8ha1TEeVevdCyGZOUPoT1soB7Nex0hV50,10947
6
- mcp_proxy_adapter/testing_utils.py,sha256=RWjQFNSUtVkeP0qNzp6_jrT6_tub3w_052DrRmvxVk0,4243
7
- mcp_proxy_adapter/analyzers/__init__.py,sha256=Nqnn8clbgv-5l0PgxcTOldg8mkMKrFn4TvPL-rYUUGg,1
8
- mcp_proxy_adapter/analyzers/docstring_analyzer.py,sha256=T3FLJEo_uChShfiEKRl8GpVoHvh5HiudZkxnj4KixfA,7541
9
- mcp_proxy_adapter/analyzers/type_analyzer.py,sha256=6Wac7osKwF03waFSwQ8ZM0Wqn_zAP2D-I4WMEpR0hQM,5230
10
- mcp_proxy_adapter/dispatchers/__init__.py,sha256=Nqnn8clbgv-5l0PgxcTOldg8mkMKrFn4TvPL-rYUUGg,1
11
- mcp_proxy_adapter/dispatchers/base_dispatcher.py,sha256=S5_Xri058jAmOWeit1tedB_GMZQ9RLcNcYabA83ZF6k,2288
12
- mcp_proxy_adapter/dispatchers/json_rpc_dispatcher.py,sha256=DBhO8DKPBKKBsARlq6IesnOFvl4GU6XVDP8gB6hZMpk,9885
13
- mcp_proxy_adapter/examples/analyze_config.py,sha256=vog7TNHDw5ZoYhQLbAvZvEoufmQwH54KJzQBJrSq5w4,4283
14
- mcp_proxy_adapter/examples/basic_integration.py,sha256=mtRval4VSUgTb_C2p8U_DPPSEKA08dZYKZk-bOrE4H4,4470
15
- mcp_proxy_adapter/examples/docstring_and_schema_example.py,sha256=wFg3Cf2Jgve0J5kFzApvFSII8JOsOGaych64hIC7FqQ,2183
16
- mcp_proxy_adapter/examples/extension_example.py,sha256=W5fcvPHjpDSPQnmhAWDJqZtLoUfY7h58ZzFoFXDF3Fc,2525
17
- mcp_proxy_adapter/examples/help_best_practices.py,sha256=ByHMDiBT9V-cHoSMr2q0PmbteKELY8mTGeJrvAxOWpY,2646
18
- mcp_proxy_adapter/examples/help_usage.py,sha256=pEwb8-QhiWuBPCK9cbHW-oMKxk4WMo345SHIAl-dosg,2577
19
- mcp_proxy_adapter/examples/mcp_proxy_client.py,sha256=z4IzFlGigVTQSb8TpcrQ_a0migsmC58LnNwc8wZmTfw,3811
20
- mcp_proxy_adapter/examples/openapi_server.py,sha256=HUcnv_XEEur1kLuAotHuwwAhykApVXgVj4miOgk8DYA,13229
21
- mcp_proxy_adapter/examples/project_structure_example.py,sha256=sswTo6FZb1F5juHa0FYG3cgvrh3wfgGfJu2bBy5tCm4,1460
22
- mcp_proxy_adapter/examples/testing_example.py,sha256=OxFUhGP9OXiu9eWjSpytpQ5MzoR9uww3M4jYb0_v7dc,2004
23
- mcp_proxy_adapter/validators/__init__.py,sha256=Nqnn8clbgv-5l0PgxcTOldg8mkMKrFn4TvPL-rYUUGg,1
24
- mcp_proxy_adapter/validators/docstring_validator.py,sha256=Onpq2iNJ1qF4ejkJJIlBkLROuSNIVALHVmXIgkCpaFI,2934
25
- mcp_proxy_adapter/validators/metadata_validator.py,sha256=uCrn38-VYYn89l6f5CC_GoTAHAweaOW2Z6Esro1rtGw,3155
26
- mcp_proxy_adapter-2.1.17.dist-info/licenses/LICENSE,sha256=OkApFEwdgMCt_mbvUI-eIwKMSTe38K3XnU2DT5ub-wI,1072
27
- mcp_proxy_adapter-2.1.17.dist-info/METADATA,sha256=Ru_MBUNRwbAxzhofC-0M8JD-NmnzmI2-h9wbgned1Z4,10822
28
- mcp_proxy_adapter-2.1.17.dist-info/WHEEL,sha256=0CuiUZ_p9E4cD6NyLD6UG80LBXYyiSYZOKDm5lp32xk,91
29
- mcp_proxy_adapter-2.1.17.dist-info/top_level.txt,sha256=JZT7vPLBYrtroX-ij68JBhJYbjDdghcV-DFySRy-Nnw,18
30
- mcp_proxy_adapter-2.1.17.dist-info/RECORD,,