mcp-proxy-adapter 2.1.2__py3-none-any.whl → 2.1.4__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.
- {examples → mcp_proxy_adapter/examples}/openapi_server.py +35 -7
- {mcp_proxy_adapter-2.1.2.dist-info → mcp_proxy_adapter-2.1.4.dist-info}/METADATA +98 -2
- mcp_proxy_adapter-2.1.4.dist-info/RECORD +28 -0
- mcp_proxy_adapter-2.1.4.dist-info/top_level.txt +1 -0
- docs/README.md +0 -172
- docs/README_ru.md +0 -172
- docs/architecture.md +0 -251
- docs/architecture_ru.md +0 -343
- docs/command_development.md +0 -250
- docs/command_development_ru.md +0 -593
- docs/deployment.md +0 -251
- docs/deployment_ru.md +0 -1298
- docs/examples.md +0 -254
- docs/examples_ru.md +0 -401
- docs/mcp_proxy_adapter.md +0 -251
- docs/mcp_proxy_adapter_ru.md +0 -405
- docs/quickstart.md +0 -251
- docs/quickstart_ru.md +0 -397
- docs/testing.md +0 -255
- docs/testing_ru.md +0 -469
- docs/validation_ru.md +0 -287
- examples/mcp_proxy_config.json +0 -175
- mcp_proxy_adapter-2.1.2.dist-info/RECORD +0 -61
- mcp_proxy_adapter-2.1.2.dist-info/top_level.txt +0 -5
- scripts/code_analyzer/code_analyzer.py +0 -328
- scripts/code_analyzer/register_commands.py +0 -446
- scripts/publish.py +0 -85
- tests/conftest.py +0 -12
- tests/test_adapter.py +0 -529
- tests/test_adapter_coverage.py +0 -274
- tests/test_basic_dispatcher.py +0 -169
- tests/test_command_registry.py +0 -328
- tests/test_examples.py +0 -32
- tests/test_mcp_proxy_adapter.py +0 -568
- tests/test_mcp_proxy_adapter_basic.py +0 -262
- tests/test_part1.py +0 -348
- tests/test_part2.py +0 -524
- tests/test_schema.py +0 -358
- tests/test_simple_adapter.py +0 -251
- {examples → mcp_proxy_adapter/examples}/analyze_config.py +0 -0
- {examples → mcp_proxy_adapter/examples}/basic_integration.py +0 -0
- {examples → mcp_proxy_adapter/examples}/docstring_and_schema_example.py +0 -0
- {examples → mcp_proxy_adapter/examples}/extension_example.py +0 -0
- {examples → mcp_proxy_adapter/examples}/help_best_practices.py +0 -0
- {examples → mcp_proxy_adapter/examples}/help_usage.py +0 -0
- {examples → mcp_proxy_adapter/examples}/mcp_proxy_client.py +0 -0
- {examples → mcp_proxy_adapter/examples}/project_structure_example.py +0 -0
- {examples → mcp_proxy_adapter/examples}/testing_example.py +0 -0
- {mcp_proxy_adapter-2.1.2.dist-info → mcp_proxy_adapter-2.1.4.dist-info}/WHEEL +0 -0
- {mcp_proxy_adapter-2.1.2.dist-info → mcp_proxy_adapter-2.1.4.dist-info}/licenses/LICENSE +0 -0
@@ -90,7 +90,8 @@ class MockDispatcher:
|
|
90
90
|
"update_item": self.update_item,
|
91
91
|
"delete_item": self.delete_item,
|
92
92
|
"search_items": self.search_items,
|
93
|
-
"execute": self.execute_command
|
93
|
+
"execute": self.execute_command,
|
94
|
+
"help": self.help_command
|
94
95
|
}
|
95
96
|
self.commands_info = {
|
96
97
|
"get_items": {
|
@@ -166,14 +167,24 @@ class MockDispatcher:
|
|
166
167
|
"required": False
|
167
168
|
}
|
168
169
|
}
|
170
|
+
},
|
171
|
+
"help": {
|
172
|
+
"description": "Show information about available commands or a specific command.",
|
173
|
+
"params": {
|
174
|
+
"command": {
|
175
|
+
"type": "string",
|
176
|
+
"description": "Command name for detailed info",
|
177
|
+
"required": False
|
178
|
+
}
|
179
|
+
}
|
169
180
|
}
|
170
181
|
}
|
171
182
|
|
172
|
-
def execute(self,
|
183
|
+
def execute(self, command_name, **params):
|
173
184
|
"""Executes command with specified parameters."""
|
174
|
-
if
|
175
|
-
raise KeyError(f"Unknown command: {
|
176
|
-
return self.commands[
|
185
|
+
if command_name not in self.commands:
|
186
|
+
raise KeyError(f"Unknown command: {command_name}")
|
187
|
+
return self.commands[command_name](**params)
|
177
188
|
|
178
189
|
def execute_command(self, **params):
|
179
190
|
"""Universal method for executing commands."""
|
@@ -209,9 +220,9 @@ class MockDispatcher:
|
|
209
220
|
"""Returns list of available commands."""
|
210
221
|
return list(self.commands.keys())
|
211
222
|
|
212
|
-
def get_command_info(self,
|
223
|
+
def get_command_info(self, command_name):
|
213
224
|
"""Returns information about command."""
|
214
|
-
return self.commands_info.get(
|
225
|
+
return self.commands_info.get(command_name)
|
215
226
|
|
216
227
|
def get_commands_info(self):
|
217
228
|
"""Returns information about all commands."""
|
@@ -265,6 +276,23 @@ class MockDispatcher:
|
|
265
276
|
(item["description"] and keyword in item["description"].lower())
|
266
277
|
]
|
267
278
|
|
279
|
+
def help_command(self, **params):
|
280
|
+
"""Return info about all commands or a specific command."""
|
281
|
+
# Если в будущем появится пользовательская команда help, можно реализовать её здесь
|
282
|
+
command = params.get("command")
|
283
|
+
if command:
|
284
|
+
info = self.commands_info.get(command)
|
285
|
+
if info:
|
286
|
+
return {"command": command, "info": info}
|
287
|
+
else:
|
288
|
+
return {"error": f"Command '{command}' not found", "available_commands": list(self.commands_info.keys())}
|
289
|
+
# Если параметр command не указан, возвращаем краткую информацию обо всех
|
290
|
+
return {
|
291
|
+
"commands": {cmd: {"description": info["description"], "params": info["params"]} for cmd, info in self.commands_info.items()},
|
292
|
+
"total": len(self.commands_info),
|
293
|
+
"note": "Use the 'command' parameter to get detailed information about a specific command"
|
294
|
+
}
|
295
|
+
|
268
296
|
class CustomMockRegistry(MockRegistry):
|
269
297
|
"""Custom command registry for example."""
|
270
298
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: mcp-proxy-adapter
|
3
|
-
Version: 2.1.
|
3
|
+
Version: 2.1.4
|
4
4
|
Summary: Adapter for exposing Command Registry commands as tools for AI models via MCP Proxy.
|
5
5
|
Home-page: https://github.com/vasilyvz/mcp-proxy-adapter
|
6
6
|
Author: Vasiliy VZ
|
@@ -303,4 +303,100 @@ See [docs/](docs/) for detailed guides, architecture, and examples.
|
|
303
303
|
7. **Add usage example** to examples/
|
304
304
|
8. **Check help integration** (with/without param)
|
305
305
|
9. **Check schema/OpenAPI generation**
|
306
|
-
10. **Document in README.md** (EN/RU)
|
306
|
+
10. **Document in README.md** (EN/RU)
|
307
|
+
|
308
|
+
## ❓ FAQ
|
309
|
+
|
310
|
+
### Ошибка: got multiple values for argument 'command' при вызове команды help
|
311
|
+
|
312
|
+
**Проблема:**
|
313
|
+
|
314
|
+
Если в JSON-RPC запросе к endpoint `/cmd` используется команда `help` с параметром `command`, может возникнуть ошибка:
|
315
|
+
|
316
|
+
```
|
317
|
+
TypeError: help_command() got multiple values for argument 'command'
|
318
|
+
```
|
319
|
+
|
320
|
+
**Причина:**
|
321
|
+
|
322
|
+
В Python, если метод `execute(self, command, **params)` получает параметр `command` и в `params` также есть ключ `command`, возникает конфликт имён.
|
323
|
+
|
324
|
+
**Решение:**
|
325
|
+
|
326
|
+
Переименуйте первый аргумент метода `execute` в классе `MockDispatcher` (и аналогичных) с `command` на `command_name`:
|
327
|
+
|
328
|
+
```python
|
329
|
+
def execute(self, command_name, **params):
|
330
|
+
if command_name not in self.commands:
|
331
|
+
raise KeyError(f"Unknown command: {command_name}")
|
332
|
+
return self.commands[command_name](**params)
|
333
|
+
```
|
334
|
+
|
335
|
+
Это устранит конфликт и позволит корректно вызывать команду help с параметром `command` через JSON-RPC.
|
336
|
+
|
337
|
+
## 🚀 Deployment & Packaging FAQ
|
338
|
+
|
339
|
+
### Как собрать, проверить и опубликовать пакет (wheel/sdist) с примерами и документацией
|
340
|
+
|
341
|
+
1. **Перенесите каталоги `examples` и `docs` внутрь основного пакета** (например, `mcp_proxy_adapter/examples`, `mcp_proxy_adapter/docs`).
|
342
|
+
2. **Обновите `setup.py`:**
|
343
|
+
- Укажите `include_package_data=True`.
|
344
|
+
- В `package_data` добавьте:
|
345
|
+
```python
|
346
|
+
package_data={
|
347
|
+
'mcp_proxy_adapter': ['examples/*.py', 'examples/*.json', 'docs/*.md', '../README.md'],
|
348
|
+
},
|
349
|
+
```
|
350
|
+
3. **Обновите `MANIFEST.in`:**
|
351
|
+
- Убедитесь, что включены нужные файлы:
|
352
|
+
```
|
353
|
+
include README.md
|
354
|
+
include LICENSE
|
355
|
+
include requirements.txt
|
356
|
+
include pyproject.toml
|
357
|
+
include code_index.yaml
|
358
|
+
recursive-include mcp_proxy_adapter/examples *.py *.json
|
359
|
+
recursive-include mcp_proxy_adapter/docs *.md
|
360
|
+
```
|
361
|
+
4. **Соберите пакет:**
|
362
|
+
```bash
|
363
|
+
rm -rf dist build mcp_proxy_adapter.egg-info
|
364
|
+
python3 -m build
|
365
|
+
```
|
366
|
+
5. **Создайте новое виртуальное окружение и установите пакет:**
|
367
|
+
```bash
|
368
|
+
python3 -m venv ../mcp_proxy_adapter_test_env
|
369
|
+
source ../mcp_proxy_adapter_test_env/bin/activate
|
370
|
+
pip install --upgrade pip
|
371
|
+
pip install dist/mcp_proxy_adapter-*.whl
|
372
|
+
```
|
373
|
+
6. **Проверьте, что примеры и документация попали в пакет:**
|
374
|
+
```bash
|
375
|
+
ls -l ../mcp_proxy_adapter_test_env/lib/python*/site-packages/mcp_proxy_adapter/examples
|
376
|
+
ls -l ../mcp_proxy_adapter_test_env/lib/python*/site-packages/mcp_proxy_adapter/docs
|
377
|
+
```
|
378
|
+
7. **Запустите пример сервера:**
|
379
|
+
```bash
|
380
|
+
python ../mcp_proxy_adapter_test_env/lib/python*/site-packages/mcp_proxy_adapter/examples/openapi_server.py
|
381
|
+
```
|
382
|
+
8. **Проверьте работоспособность через curl:**
|
383
|
+
```bash
|
384
|
+
curl http://localhost:8000/openapi.json | jq .
|
385
|
+
```
|
386
|
+
9. **Публикация на PyPI:**
|
387
|
+
- Проверьте, что у вас настроен `~/.pypirc` и установлен twine:
|
388
|
+
```bash
|
389
|
+
pip install twine
|
390
|
+
twine upload dist/*
|
391
|
+
```
|
392
|
+
|
393
|
+
### Типовые проблемы и решения
|
394
|
+
- **Примеры или документация не попадают в пакет:**
|
395
|
+
- Убедитесь, что они находятся внутри основного пакета и правильно указаны в `package_data` и `MANIFEST.in`.
|
396
|
+
- **Каталог docs не виден в wheel:**
|
397
|
+
- Проверьте расширения файлов и шаблоны в `package_data`/`MANIFEST.in`.
|
398
|
+
- **Проверяйте установку только через wheel, а не через sdist!**
|
399
|
+
|
400
|
+
**Best practice:**
|
401
|
+
- Для публикации документации используйте GitHub и PyPI project page (README.md).
|
402
|
+
- Для примеров — всегда размещайте их внутри пакета, если хотите распространять с wheel.
|
@@ -0,0 +1,28 @@
|
|
1
|
+
mcp_proxy_adapter/__init__.py,sha256=_6D-TfANWp9zc550M5LUeGPvioFqG1bAl3tZj-gNmJU,463
|
2
|
+
mcp_proxy_adapter/adapter.py,sha256=76dkVeDuqLsJ5AhuftzLlwy2M6yr_PfNbmNfo9dXVhc,28844
|
3
|
+
mcp_proxy_adapter/models.py,sha256=acqVQBYAojHXeJ1MJyvpMyT6-J6aMxWuZMszn_-RsOU,2338
|
4
|
+
mcp_proxy_adapter/registry.py,sha256=jgC4TKaPbMbAsoxvGp2ToaOE4drD-VfZug7WJbm4IW4,15853
|
5
|
+
mcp_proxy_adapter/schema.py,sha256=HZM0TTQTSi8ha1TEeVevdCyGZOUPoT1soB7Nex0hV50,10947
|
6
|
+
mcp_proxy_adapter/analyzers/__init__.py,sha256=2rcYZDP-bXq078MQpxP32lAwYYyRhOwAQGBcefBfBzY,368
|
7
|
+
mcp_proxy_adapter/analyzers/docstring_analyzer.py,sha256=T3FLJEo_uChShfiEKRl8GpVoHvh5HiudZkxnj4KixfA,7541
|
8
|
+
mcp_proxy_adapter/analyzers/type_analyzer.py,sha256=6Wac7osKwF03waFSwQ8ZM0Wqn_zAP2D-I4WMEpR0hQM,5230
|
9
|
+
mcp_proxy_adapter/dispatchers/__init__.py,sha256=FWgimgInGphIjCEnvA3-ZExiapUzYAVis2H9C5IWivU,365
|
10
|
+
mcp_proxy_adapter/dispatchers/base_dispatcher.py,sha256=S5_Xri058jAmOWeit1tedB_GMZQ9RLcNcYabA83ZF6k,2288
|
11
|
+
mcp_proxy_adapter/dispatchers/json_rpc_dispatcher.py,sha256=ffu1M32E1AdC7IB44mlbV2L56eJQMsp-7fYi_r4rmHc,6331
|
12
|
+
mcp_proxy_adapter/examples/analyze_config.py,sha256=vog7TNHDw5ZoYhQLbAvZvEoufmQwH54KJzQBJrSq5w4,4283
|
13
|
+
mcp_proxy_adapter/examples/basic_integration.py,sha256=w_oA777YiQt36gzI113KPQ6k45caXbMCqW9hD8sy8zo,4657
|
14
|
+
mcp_proxy_adapter/examples/docstring_and_schema_example.py,sha256=c96L4KF_7yWzffmvd4hyeQuXSdYyYkv7Uvuy0QxgMcQ,1929
|
15
|
+
mcp_proxy_adapter/examples/extension_example.py,sha256=vnatnFdNTapMpPcQ79Ugitk92ZiUfpLTs7Dvsodf1og,2277
|
16
|
+
mcp_proxy_adapter/examples/help_best_practices.py,sha256=wUtZRnAktnpfAc9vAvqSxUquHEr5ewaPDPyc6BoCqdQ,2637
|
17
|
+
mcp_proxy_adapter/examples/help_usage.py,sha256=UOd3HJeYlQpQkAyceGNm66jXX_h-T05pjIGD-b7-Pfg,2568
|
18
|
+
mcp_proxy_adapter/examples/mcp_proxy_client.py,sha256=z4IzFlGigVTQSb8TpcrQ_a0migsmC58LnNwc8wZmTfw,3811
|
19
|
+
mcp_proxy_adapter/examples/openapi_server.py,sha256=xAt-aUEz5vusvz7fd1vFIybi4EpwlnGPXLsce3j3YZw,14024
|
20
|
+
mcp_proxy_adapter/examples/project_structure_example.py,sha256=sswTo6FZb1F5juHa0FYG3cgvrh3wfgGfJu2bBy5tCm4,1460
|
21
|
+
mcp_proxy_adapter/examples/testing_example.py,sha256=AB13c4C1bjs1145O-yriwyreeVXtMOlQLzs2BCGmprk,1719
|
22
|
+
mcp_proxy_adapter/validators/docstring_validator.py,sha256=Onpq2iNJ1qF4ejkJJIlBkLROuSNIVALHVmXIgkCpaFI,2934
|
23
|
+
mcp_proxy_adapter/validators/metadata_validator.py,sha256=uCrn38-VYYn89l6f5CC_GoTAHAweaOW2Z6Esro1rtGw,3155
|
24
|
+
mcp_proxy_adapter-2.1.4.dist-info/licenses/LICENSE,sha256=OkApFEwdgMCt_mbvUI-eIwKMSTe38K3XnU2DT5ub-wI,1072
|
25
|
+
mcp_proxy_adapter-2.1.4.dist-info/METADATA,sha256=u8AFozMDHraUrudOrA6D62VLkHL3s9LC36O2U29yR9g,12578
|
26
|
+
mcp_proxy_adapter-2.1.4.dist-info/WHEEL,sha256=wXxTzcEDnjrTwFYjLPcsW_7_XihufBwmpiBeiXNBGEA,91
|
27
|
+
mcp_proxy_adapter-2.1.4.dist-info/top_level.txt,sha256=JZT7vPLBYrtroX-ij68JBhJYbjDdghcV-DFySRy-Nnw,18
|
28
|
+
mcp_proxy_adapter-2.1.4.dist-info/RECORD,,
|
@@ -0,0 +1 @@
|
|
1
|
+
mcp_proxy_adapter
|
docs/README.md
DELETED
@@ -1,172 +0,0 @@
|
|
1
|
-
# Command Registry
|
2
|
-
|
3
|
-
## Overview
|
4
|
-
|
5
|
-
Command Registry is a high-level system for centralized command management in applications. It provides a unified mechanism for defining, registering, executing, and documenting commands through various interfaces.
|
6
|
-
|
7
|
-
## Key Features
|
8
|
-
|
9
|
-
- **Single access point** for application commands
|
10
|
-
- **Automatic metadata extraction** from Python docstrings and type hints
|
11
|
-
- **Integration with various protocols** (REST, JSON-RPC, WebSockets)
|
12
|
-
- **API documentation generation** based on command metadata
|
13
|
-
- **Input parameters and output values validation**
|
14
|
-
- **Metadata compliance verification** with actual function signatures
|
15
|
-
- **Extensibility** through interfaces for dispatchers, adapters, and schema generators
|
16
|
-
- **AI model integration** via MCP Proxy Adapter
|
17
|
-
|
18
|
-
## Getting Started
|
19
|
-
|
20
|
-
### Installation
|
21
|
-
|
22
|
-
```bash
|
23
|
-
pip install command-registry
|
24
|
-
```
|
25
|
-
|
26
|
-
For MCP Proxy integration, also install:
|
27
|
-
|
28
|
-
```bash
|
29
|
-
pip install mcp-proxy-adapter
|
30
|
-
```
|
31
|
-
|
32
|
-
### Simple Example
|
33
|
-
|
34
|
-
```python
|
35
|
-
from command_registry import CommandRegistry
|
36
|
-
|
37
|
-
# Create a command registry instance
|
38
|
-
registry = CommandRegistry()
|
39
|
-
|
40
|
-
# Define a command
|
41
|
-
def add_numbers(a: int, b: int) -> int:
|
42
|
-
"""Adds two numbers.
|
43
|
-
|
44
|
-
Args:
|
45
|
-
a: First number
|
46
|
-
b: Second number
|
47
|
-
|
48
|
-
Returns:
|
49
|
-
Sum of numbers a and b
|
50
|
-
"""
|
51
|
-
return a + b
|
52
|
-
|
53
|
-
# Register the command
|
54
|
-
registry.register_command("add", add_numbers)
|
55
|
-
|
56
|
-
# Execute the command
|
57
|
-
result = registry.execute("add", {"a": 5, "b": 3}) # Returns 8
|
58
|
-
```
|
59
|
-
|
60
|
-
### FastAPI Export
|
61
|
-
|
62
|
-
```python
|
63
|
-
from fastapi import FastAPI
|
64
|
-
from command_registry.adapters import RESTAdapter
|
65
|
-
|
66
|
-
app = FastAPI()
|
67
|
-
adapter = RESTAdapter(registry)
|
68
|
-
adapter.register_endpoints(app)
|
69
|
-
```
|
70
|
-
|
71
|
-
### MCP Proxy Integration for AI Models
|
72
|
-
|
73
|
-
```python
|
74
|
-
from fastapi import FastAPI
|
75
|
-
from mcp_proxy_adapter.adapter import MCPProxyAdapter
|
76
|
-
|
77
|
-
app = FastAPI()
|
78
|
-
adapter = MCPProxyAdapter(registry)
|
79
|
-
adapter.register_endpoints(app)
|
80
|
-
|
81
|
-
# Create configuration for MCP Proxy
|
82
|
-
adapter.save_config_to_file("mcp_proxy_config.json")
|
83
|
-
```
|
84
|
-
|
85
|
-
### Automatic Command Registration from Module
|
86
|
-
|
87
|
-
```python
|
88
|
-
# Scan module and register all found commands
|
89
|
-
registry.scan_module("myapp.commands")
|
90
|
-
```
|
91
|
-
|
92
|
-
## Documentation
|
93
|
-
|
94
|
-
- [Architecture](architecture.md) - detailed component description
|
95
|
-
- [Command Development Guide](command_development.md) - best practices
|
96
|
-
- [Examples](examples.md) - usage examples for various scenarios
|
97
|
-
- [Validation](validation.md) - command validation mechanisms
|
98
|
-
- [MCP Proxy Adapter](mcp_proxy_adapter.md) - AI model integration via MCP Proxy
|
99
|
-
|
100
|
-
## Project Structure
|
101
|
-
|
102
|
-
```
|
103
|
-
command_registry/
|
104
|
-
├── __init__.py # Main public API
|
105
|
-
├── core.py # Core CommandRegistry logic
|
106
|
-
├── dispatchers/ # Command dispatchers
|
107
|
-
│ ├── __init__.py
|
108
|
-
│ ├── base_dispatcher.py # Abstract base class
|
109
|
-
│ └── command_dispatcher.py # Main implementation
|
110
|
-
├── metadata/ # Metadata extraction
|
111
|
-
│ ├── __init__.py
|
112
|
-
│ ├── docstring_parser.py # Docstring parser
|
113
|
-
│ └── type_analyzer.py # Type analyzer
|
114
|
-
├── validators/ # Validators
|
115
|
-
│ ├── __init__.py
|
116
|
-
│ └── parameter_validator.py # Parameter validation
|
117
|
-
├── adapters/ # Protocol adapters
|
118
|
-
│ ├── __init__.py
|
119
|
-
│ ├── rest_adapter.py # REST API
|
120
|
-
│ └── json_rpc_adapter.py # JSON-RPC
|
121
|
-
└── schema/ # Schema generators
|
122
|
-
├── __init__.py
|
123
|
-
├── openapi_generator.py # OpenAPI
|
124
|
-
└── json_schema_generator.py # JSON Schema
|
125
|
-
```
|
126
|
-
|
127
|
-
## Integration with Existing Systems
|
128
|
-
|
129
|
-
Command Registry is designed for easy integration with existing systems and frameworks:
|
130
|
-
|
131
|
-
- **FastAPI** - via RESTAdapter
|
132
|
-
- **Flask** - via RESTAdapter with modifications
|
133
|
-
- **aiohttp** - via WebSockets adapter
|
134
|
-
- **Click** - via CLI adapter
|
135
|
-
- **GraphQL** - via GraphQL adapter
|
136
|
-
- **MCP Proxy** - via MCPProxyAdapter for AI model integration
|
137
|
-
|
138
|
-
## Usage Examples
|
139
|
-
|
140
|
-
### REST API
|
141
|
-
|
142
|
-
```python
|
143
|
-
from fastapi import FastAPI
|
144
|
-
from command_registry import CommandRegistry
|
145
|
-
from command_registry.adapters import RESTAdapter
|
146
|
-
|
147
|
-
app = FastAPI()
|
148
|
-
registry = CommandRegistry()
|
149
|
-
registry.scan_module("myapp.commands")
|
150
|
-
|
151
|
-
adapter = RESTAdapter(registry)
|
152
|
-
adapter.register_endpoints(app)
|
153
|
-
```
|
154
|
-
|
155
|
-
### JSON-RPC via MCP Proxy Adapter
|
156
|
-
|
157
|
-
```python
|
158
|
-
from fastapi import FastAPI
|
159
|
-
from command_registry import CommandRegistry
|
160
|
-
from mcp_proxy_adapter.adapter import MCPProxyAdapter
|
161
|
-
|
162
|
-
app = FastAPI()
|
163
|
-
registry = CommandRegistry()
|
164
|
-
registry.scan_module("myapp.commands")
|
165
|
-
|
166
|
-
adapter = MCPProxyAdapter(registry)
|
167
|
-
adapter.register_endpoints(app)
|
168
|
-
```
|
169
|
-
|
170
|
-
## License
|
171
|
-
|
172
|
-
MIT
|
docs/README_ru.md
DELETED
@@ -1,172 +0,0 @@
|
|
1
|
-
# Command Registry
|
2
|
-
|
3
|
-
## Обзор
|
4
|
-
|
5
|
-
Command Registry - это высокоуровневая система для централизованного управления командами в приложении. Она предоставляет унифицированный механизм определения, регистрации, выполнения и документирования команд через различные интерфейсы.
|
6
|
-
|
7
|
-
## Основные возможности
|
8
|
-
|
9
|
-
- **Единая точка доступа** к командам приложения
|
10
|
-
- **Автоматическое извлечение метаданных** из докстрингов и типизации Python
|
11
|
-
- **Интеграция с различными протоколами** (REST, JSON-RPC, WebSockets)
|
12
|
-
- **Генерация документации API** на основе метаданных команд
|
13
|
-
- **Валидация входных параметров** и выходных значений
|
14
|
-
- **Проверка соответствия метаданных** фактической сигнатуре функций
|
15
|
-
- **Расширяемость** через интерфейсы для диспетчеров, адаптеров и генераторов схем
|
16
|
-
- **Интеграция с моделями ИИ** через MCP Proxy Adapter
|
17
|
-
|
18
|
-
## Начало работы
|
19
|
-
|
20
|
-
### Установка
|
21
|
-
|
22
|
-
```bash
|
23
|
-
pip install command-registry
|
24
|
-
```
|
25
|
-
|
26
|
-
Для работы с MCP Proxy также установите:
|
27
|
-
|
28
|
-
```bash
|
29
|
-
pip install mcp-proxy-adapter
|
30
|
-
```
|
31
|
-
|
32
|
-
### Простой пример
|
33
|
-
|
34
|
-
```python
|
35
|
-
from command_registry import CommandRegistry
|
36
|
-
|
37
|
-
# Создание экземпляра реестра команд
|
38
|
-
registry = CommandRegistry()
|
39
|
-
|
40
|
-
# Определение команды
|
41
|
-
def add_numbers(a: int, b: int) -> int:
|
42
|
-
"""Складывает два числа.
|
43
|
-
|
44
|
-
Args:
|
45
|
-
a: Первое число
|
46
|
-
b: Второе число
|
47
|
-
|
48
|
-
Returns:
|
49
|
-
Сумма чисел a и b
|
50
|
-
"""
|
51
|
-
return a + b
|
52
|
-
|
53
|
-
# Регистрация команды
|
54
|
-
registry.register_command("add", add_numbers)
|
55
|
-
|
56
|
-
# Выполнение команды
|
57
|
-
result = registry.execute("add", {"a": 5, "b": 3}) # Вернёт 8
|
58
|
-
```
|
59
|
-
|
60
|
-
### Экспорт через FastAPI
|
61
|
-
|
62
|
-
```python
|
63
|
-
from fastapi import FastAPI
|
64
|
-
from command_registry.adapters import RESTAdapter
|
65
|
-
|
66
|
-
app = FastAPI()
|
67
|
-
adapter = RESTAdapter(registry)
|
68
|
-
adapter.register_endpoints(app)
|
69
|
-
```
|
70
|
-
|
71
|
-
### Интеграция с MCP Proxy для моделей ИИ
|
72
|
-
|
73
|
-
```python
|
74
|
-
from fastapi import FastAPI
|
75
|
-
from mcp_proxy_adapter.adapter import MCPProxyAdapter
|
76
|
-
|
77
|
-
app = FastAPI()
|
78
|
-
adapter = MCPProxyAdapter(registry)
|
79
|
-
adapter.register_endpoints(app)
|
80
|
-
|
81
|
-
# Создание конфигурации для MCP Proxy
|
82
|
-
adapter.save_config_to_file("mcp_proxy_config.json")
|
83
|
-
```
|
84
|
-
|
85
|
-
### Автоматическая регистрация команд из модуля
|
86
|
-
|
87
|
-
```python
|
88
|
-
# Сканирование модуля и регистрация всех найденных команд
|
89
|
-
registry.scan_module("myapp.commands")
|
90
|
-
```
|
91
|
-
|
92
|
-
## Документация
|
93
|
-
|
94
|
-
- [Архитектура](architecture.md) - подробное описание компонентов
|
95
|
-
- [Руководство по разработке команд](command_development.md) - лучшие практики
|
96
|
-
- [Примеры](examples.md) - примеры использования для различных сценариев
|
97
|
-
- [Валидация](validation.md) - механизмы проверки команд
|
98
|
-
- [MCP Proxy Adapter](mcp_proxy_adapter.md) - интеграция с моделями ИИ через MCP Proxy
|
99
|
-
|
100
|
-
## Структура проекта
|
101
|
-
|
102
|
-
```
|
103
|
-
command_registry/
|
104
|
-
├── __init__.py # Основные публичные API
|
105
|
-
├── core.py # Основная логика CommandRegistry
|
106
|
-
├── dispatchers/ # Диспетчеры команд
|
107
|
-
│ ├── __init__.py
|
108
|
-
│ ├── base_dispatcher.py # Абстрактный базовый класс
|
109
|
-
│ └── command_dispatcher.py # Основная реализация
|
110
|
-
├── metadata/ # Извлечение метаданных
|
111
|
-
│ ├── __init__.py
|
112
|
-
│ ├── docstring_parser.py # Парсер докстрингов
|
113
|
-
│ └── type_analyzer.py # Анализатор типов
|
114
|
-
├── validators/ # Валидаторы
|
115
|
-
│ ├── __init__.py
|
116
|
-
│ └── parameter_validator.py # Валидация параметров
|
117
|
-
├── adapters/ # Адаптеры протоколов
|
118
|
-
│ ├── __init__.py
|
119
|
-
│ ├── rest_adapter.py # REST API
|
120
|
-
│ └── json_rpc_adapter.py # JSON-RPC
|
121
|
-
└── schema/ # Генераторы схем
|
122
|
-
├── __init__.py
|
123
|
-
├── openapi_generator.py # OpenAPI
|
124
|
-
└── json_schema_generator.py # JSON Schema
|
125
|
-
```
|
126
|
-
|
127
|
-
## Интеграция с существующими системами
|
128
|
-
|
129
|
-
Command Registry спроектирован для легкой интеграции с существующими системами и фреймворками:
|
130
|
-
|
131
|
-
- **FastAPI** - через RESTAdapter
|
132
|
-
- **Flask** - через RESTAdapter с модификациями
|
133
|
-
- **aiohttp** - через адаптер для WebSockets
|
134
|
-
- **Click** - через CLI адаптер
|
135
|
-
- **GraphQL** - через GraphQL адаптер
|
136
|
-
- **MCP Proxy** - через MCPProxyAdapter для интеграции с моделями ИИ
|
137
|
-
|
138
|
-
## Примеры использования
|
139
|
-
|
140
|
-
### REST API
|
141
|
-
|
142
|
-
```python
|
143
|
-
from fastapi import FastAPI
|
144
|
-
from command_registry import CommandRegistry
|
145
|
-
from command_registry.adapters import RESTAdapter
|
146
|
-
|
147
|
-
app = FastAPI()
|
148
|
-
registry = CommandRegistry()
|
149
|
-
registry.scan_module("myapp.commands")
|
150
|
-
|
151
|
-
adapter = RESTAdapter(registry)
|
152
|
-
adapter.register_endpoints(app)
|
153
|
-
```
|
154
|
-
|
155
|
-
### JSON-RPC через MCP Proxy Adapter
|
156
|
-
|
157
|
-
```python
|
158
|
-
from fastapi import FastAPI
|
159
|
-
from command_registry import CommandRegistry
|
160
|
-
from mcp_proxy_adapter.adapter import MCPProxyAdapter
|
161
|
-
|
162
|
-
app = FastAPI()
|
163
|
-
registry = CommandRegistry()
|
164
|
-
registry.scan_module("myapp.commands")
|
165
|
-
|
166
|
-
adapter = MCPProxyAdapter(registry)
|
167
|
-
adapter.register_endpoints(app)
|
168
|
-
```
|
169
|
-
|
170
|
-
## Лицензия
|
171
|
-
|
172
|
-
MIT
|