mcp-proxy-adapter 1.0.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 (70) hide show
  1. mcp_proxy_adapter-1.0.0/LICENSE +21 -0
  2. mcp_proxy_adapter-1.0.0/MANIFEST.in +12 -0
  3. mcp_proxy_adapter-1.0.0/PKG-INFO +262 -0
  4. mcp_proxy_adapter-1.0.0/README.md +230 -0
  5. mcp_proxy_adapter-1.0.0/code_index.yaml +263 -0
  6. mcp_proxy_adapter-1.0.0/docs/README.md +172 -0
  7. mcp_proxy_adapter-1.0.0/docs/README_ru.md +172 -0
  8. mcp_proxy_adapter-1.0.0/docs/architecture.md +251 -0
  9. mcp_proxy_adapter-1.0.0/docs/architecture_ru.md +343 -0
  10. mcp_proxy_adapter-1.0.0/docs/command_development.md +250 -0
  11. mcp_proxy_adapter-1.0.0/docs/command_development_ru.md +593 -0
  12. mcp_proxy_adapter-1.0.0/docs/deployment.md +251 -0
  13. mcp_proxy_adapter-1.0.0/docs/deployment_ru.md +1298 -0
  14. mcp_proxy_adapter-1.0.0/docs/examples.md +254 -0
  15. mcp_proxy_adapter-1.0.0/docs/examples_ru.md +401 -0
  16. mcp_proxy_adapter-1.0.0/docs/mcp_proxy_adapter.md +251 -0
  17. mcp_proxy_adapter-1.0.0/docs/mcp_proxy_adapter_ru.md +405 -0
  18. mcp_proxy_adapter-1.0.0/docs/quickstart.md +251 -0
  19. mcp_proxy_adapter-1.0.0/docs/quickstart_ru.md +397 -0
  20. mcp_proxy_adapter-1.0.0/docs/testing.md +255 -0
  21. mcp_proxy_adapter-1.0.0/docs/testing_ru.md +469 -0
  22. mcp_proxy_adapter-1.0.0/docs/validation_ru.md +287 -0
  23. mcp_proxy_adapter-1.0.0/examples/analyze_config.py +141 -0
  24. mcp_proxy_adapter-1.0.0/examples/basic_integration.py +161 -0
  25. mcp_proxy_adapter-1.0.0/examples/mcp_proxy_client.py +131 -0
  26. mcp_proxy_adapter-1.0.0/examples/mcp_proxy_config.json +175 -0
  27. mcp_proxy_adapter-1.0.0/examples/openapi_server.py +369 -0
  28. mcp_proxy_adapter-1.0.0/pyproject.toml +42 -0
  29. mcp_proxy_adapter-1.0.0/requirements.txt +5 -0
  30. mcp_proxy_adapter-1.0.0/setup.cfg +4 -0
  31. mcp_proxy_adapter-1.0.0/setup.py +43 -0
  32. mcp_proxy_adapter-1.0.0/src/adapters/__init__.py +16 -0
  33. mcp_proxy_adapter-1.0.0/src/analyzers/__init__.py +14 -0
  34. mcp_proxy_adapter-1.0.0/src/analyzers/docstring_analyzer.py +199 -0
  35. mcp_proxy_adapter-1.0.0/src/analyzers/type_analyzer.py +151 -0
  36. mcp_proxy_adapter-1.0.0/src/cli/__init__.py +12 -0
  37. mcp_proxy_adapter-1.0.0/src/cli/__main__.py +79 -0
  38. mcp_proxy_adapter-1.0.0/src/cli/command_runner.py +233 -0
  39. mcp_proxy_adapter-1.0.0/src/dispatchers/__init__.py +14 -0
  40. mcp_proxy_adapter-1.0.0/src/dispatchers/base_dispatcher.py +85 -0
  41. mcp_proxy_adapter-1.0.0/src/dispatchers/json_rpc_dispatcher.py +198 -0
  42. mcp_proxy_adapter-1.0.0/src/generators/__init__.py +14 -0
  43. mcp_proxy_adapter-1.0.0/src/generators/endpoint_generator.py +172 -0
  44. mcp_proxy_adapter-1.0.0/src/generators/openapi_generator.py +254 -0
  45. mcp_proxy_adapter-1.0.0/src/generators/rest_api_generator.py +207 -0
  46. mcp_proxy_adapter-1.0.0/src/mcp_proxy_adapter.egg-info/PKG-INFO +262 -0
  47. mcp_proxy_adapter-1.0.0/src/mcp_proxy_adapter.egg-info/SOURCES.txt +68 -0
  48. mcp_proxy_adapter-1.0.0/src/mcp_proxy_adapter.egg-info/dependency_links.txt +1 -0
  49. mcp_proxy_adapter-1.0.0/src/mcp_proxy_adapter.egg-info/requires.txt +5 -0
  50. mcp_proxy_adapter-1.0.0/src/mcp_proxy_adapter.egg-info/top_level.txt +9 -0
  51. mcp_proxy_adapter-1.0.0/src/openapi_schema/__init__.py +38 -0
  52. mcp_proxy_adapter-1.0.0/src/openapi_schema/command_registry.py +312 -0
  53. mcp_proxy_adapter-1.0.0/src/openapi_schema/rest_schema.py +510 -0
  54. mcp_proxy_adapter-1.0.0/src/openapi_schema/rpc_generator.py +307 -0
  55. mcp_proxy_adapter-1.0.0/src/openapi_schema/rpc_schema.py +416 -0
  56. mcp_proxy_adapter-1.0.0/src/validators/__init__.py +14 -0
  57. mcp_proxy_adapter-1.0.0/src/validators/base_validator.py +23 -0
  58. mcp_proxy_adapter-1.0.0/src/validators/docstring_validator.py +75 -0
  59. mcp_proxy_adapter-1.0.0/src/validators/metadata_validator.py +76 -0
  60. mcp_proxy_adapter-1.0.0/tests/conftest.py +12 -0
  61. mcp_proxy_adapter-1.0.0/tests/test_adapter.py +531 -0
  62. mcp_proxy_adapter-1.0.0/tests/test_adapter_coverage.py +274 -0
  63. mcp_proxy_adapter-1.0.0/tests/test_basic_dispatcher.py +172 -0
  64. mcp_proxy_adapter-1.0.0/tests/test_command_registry.py +328 -0
  65. mcp_proxy_adapter-1.0.0/tests/test_mcp_proxy_adapter.py +320 -0
  66. mcp_proxy_adapter-1.0.0/tests/test_mcp_proxy_adapter_basic.py +252 -0
  67. mcp_proxy_adapter-1.0.0/tests/test_part1.py +348 -0
  68. mcp_proxy_adapter-1.0.0/tests/test_part2.py +514 -0
  69. mcp_proxy_adapter-1.0.0/tests/test_schema.py +358 -0
  70. mcp_proxy_adapter-1.0.0/tests/test_simple_adapter.py +251 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023-2024 Vasiliy VZ
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,12 @@
1
+ include README.md
2
+ include LICENSE
3
+ include requirements.txt
4
+ include pyproject.toml
5
+ include code_index.yaml
6
+ recursive-include docs *.md
7
+ recursive-include examples *.py *.json
8
+ recursive-include tests *.py
9
+ global-exclude __pycache__
10
+ global-exclude *.py[cod]
11
+ global-exclude *.so
12
+ global-exclude .DS_Store
@@ -0,0 +1,262 @@
1
+ Metadata-Version: 2.4
2
+ Name: mcp-proxy-adapter
3
+ Version: 1.0.0
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,>=1.10.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
+ @registry.command
63
+ def calculate_total(prices: list[float], discount: float = 0.0) -> float:
64
+ """
65
+ Calculates the total price with discount.
66
+ Args:
67
+ prices: List of item prices
68
+ discount: Discount percentage (0-100)
69
+ Returns:
70
+ Total price with discount
71
+ """
72
+ subtotal = sum(prices)
73
+ return subtotal * (1 - discount / 100)
74
+
75
+ # Create FastAPI app
76
+ app = FastAPI()
77
+
78
+ # Create and configure MCP Proxy adapter
79
+ adapter = MCPProxyAdapter(registry)
80
+
81
+ # Register endpoints in FastAPI app
82
+ adapter.register_endpoints(app)
83
+
84
+ # Generate and save MCP Proxy config
85
+ adapter.save_config_to_file("mcp_proxy_config.json")
86
+ ```
87
+
88
+ ## Supported Request Formats
89
+
90
+ The adapter supports three request formats for command execution:
91
+
92
+ ### 1. JSON-RPC format
93
+
94
+ ```json
95
+ {
96
+ "jsonrpc": "2.0",
97
+ "method": "command_name",
98
+ "params": {
99
+ "param1": "value1",
100
+ "param2": "value2"
101
+ },
102
+ "id": 1
103
+ }
104
+ ```
105
+
106
+ Example request to `/cmd` endpoint:
107
+
108
+ ```bash
109
+ curl -X POST -H "Content-Type: application/json" -d '{
110
+ "jsonrpc": "2.0",
111
+ "method": "calculate_total",
112
+ "params": {
113
+ "prices": [100, 200, 300],
114
+ "discount": 10
115
+ },
116
+ "id": 1
117
+ }' http://localhost:8000/cmd
118
+ ```
119
+
120
+ Response:
121
+
122
+ ```json
123
+ {
124
+ "jsonrpc": "2.0",
125
+ "result": 540.0,
126
+ "id": 1
127
+ }
128
+ ```
129
+
130
+ ### 2. MCP Proxy format
131
+
132
+ ```json
133
+ {
134
+ "command": "command_name",
135
+ "params": {
136
+ "param1": "value1",
137
+ "param2": "value2"
138
+ }
139
+ }
140
+ ```
141
+
142
+ Example request:
143
+
144
+ ```bash
145
+ curl -X POST -H "Content-Type: application/json" -d '{
146
+ "command": "calculate_total",
147
+ "params": {
148
+ "prices": [100, 200, 300],
149
+ "discount": 10
150
+ }
151
+ }' http://localhost:8000/cmd
152
+ ```
153
+
154
+ Response:
155
+
156
+ ```json
157
+ {
158
+ "result": 540.0
159
+ }
160
+ ```
161
+
162
+ ### 3. Params-only format
163
+
164
+ ```json
165
+ {
166
+ "params": {
167
+ "command": "command_name",
168
+ "param1": "value1",
169
+ "param2": "value2"
170
+ }
171
+ }
172
+ ```
173
+
174
+ or
175
+
176
+ ```json
177
+ {
178
+ "params": {
179
+ "query": "command_name",
180
+ "param1": "value1",
181
+ "param2": "value2"
182
+ }
183
+ }
184
+ ```
185
+
186
+ Example request:
187
+
188
+ ```bash
189
+ curl -X POST -H "Content-Type: application/json" -d '{
190
+ "params": {
191
+ "command": "calculate_total",
192
+ "prices": [100, 200, 300],
193
+ "discount": 10
194
+ }
195
+ }' http://localhost:8000/cmd
196
+ ```
197
+
198
+ Response:
199
+
200
+ ```json
201
+ {
202
+ "result": 540.0
203
+ }
204
+ ```
205
+
206
+ ## Full Example: Integration with FastAPI
207
+
208
+ ```python
209
+ import logging
210
+ from fastapi import FastAPI, APIRouter
211
+ from mcp_proxy_adapter import CommandRegistry, MCPProxyAdapter, configure_logger
212
+
213
+ # Configure logging
214
+ logging.basicConfig(level=logging.INFO)
215
+ project_logger = logging.getLogger("my_project")
216
+
217
+ # Create FastAPI app
218
+ app = FastAPI(title="My API with MCP Proxy Integration")
219
+
220
+ # Create existing API router
221
+ router = APIRouter()
222
+
223
+ @router.get("/items")
224
+ async def get_items():
225
+ """Returns a list of items."""
226
+ return [
227
+ {"id": 1, "name": "Smartphone X", "price": 999.99},
228
+ {"id": 2, "name": "Laptop Y", "price": 1499.99},
229
+ ]
230
+
231
+ app.include_router(router)
232
+
233
+ # Register commands
234
+ registry = CommandRegistry()
235
+
236
+ @registry.command
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
+ # Create and register MCP Proxy adapter
244
+ adapter = MCPProxyAdapter(registry)
245
+ adapter.register_endpoints(app)
246
+
247
+ # Save MCP Proxy config
248
+ adapter.save_config_to_file("mcp_proxy_config.json")
249
+ ```
250
+
251
+ ## Features
252
+ - Universal JSON-RPC endpoint for command execution
253
+ - Automatic OpenAPI schema generation and optimization for MCP Proxy
254
+ - Tool metadata for AI models
255
+ - Customizable endpoints and logging
256
+ - Full test coverage and examples
257
+
258
+ ## License
259
+ MIT
260
+
261
+ ## Documentation
262
+ See [docs/](docs/) for detailed guides, architecture, and examples.
@@ -0,0 +1,230 @@
1
+ # MCP Proxy Adapter
2
+
3
+ Adapter for integrating [Command Registry](docs/README.md) with MCP Proxy, allowing you to use commands as tools for AI models.
4
+
5
+ ## Overview
6
+
7
+ MCP Proxy Adapter transforms commands registered in the Command Registry into a format compatible with MCP Proxy. This enables:
8
+
9
+ 1. Using existing commands as tools for AI models
10
+ 2. Creating a hybrid REST/JSON-RPC API for command execution
11
+ 3. Automatic generation of OpenAPI schemas optimized for MCP Proxy
12
+ 4. Managing tool metadata for better AI system integration
13
+
14
+ ## Installation
15
+
16
+ ```bash
17
+ pip install mcp-proxy-adapter
18
+ ```
19
+
20
+ ## Quick Start
21
+
22
+ ```python
23
+ from mcp_proxy_adapter import MCPProxyAdapter, CommandRegistry
24
+ from fastapi import FastAPI
25
+
26
+ # Create a command registry instance
27
+ registry = CommandRegistry()
28
+
29
+ # Register commands
30
+ @registry.command
31
+ def calculate_total(prices: list[float], discount: float = 0.0) -> float:
32
+ """
33
+ Calculates the total price with discount.
34
+ Args:
35
+ prices: List of item prices
36
+ discount: Discount percentage (0-100)
37
+ Returns:
38
+ Total price with discount
39
+ """
40
+ subtotal = sum(prices)
41
+ return subtotal * (1 - discount / 100)
42
+
43
+ # Create FastAPI app
44
+ app = FastAPI()
45
+
46
+ # Create and configure MCP Proxy adapter
47
+ adapter = MCPProxyAdapter(registry)
48
+
49
+ # Register endpoints in FastAPI app
50
+ adapter.register_endpoints(app)
51
+
52
+ # Generate and save MCP Proxy config
53
+ adapter.save_config_to_file("mcp_proxy_config.json")
54
+ ```
55
+
56
+ ## Supported Request Formats
57
+
58
+ The adapter supports three request formats for command execution:
59
+
60
+ ### 1. JSON-RPC format
61
+
62
+ ```json
63
+ {
64
+ "jsonrpc": "2.0",
65
+ "method": "command_name",
66
+ "params": {
67
+ "param1": "value1",
68
+ "param2": "value2"
69
+ },
70
+ "id": 1
71
+ }
72
+ ```
73
+
74
+ Example request to `/cmd` endpoint:
75
+
76
+ ```bash
77
+ curl -X POST -H "Content-Type: application/json" -d '{
78
+ "jsonrpc": "2.0",
79
+ "method": "calculate_total",
80
+ "params": {
81
+ "prices": [100, 200, 300],
82
+ "discount": 10
83
+ },
84
+ "id": 1
85
+ }' http://localhost:8000/cmd
86
+ ```
87
+
88
+ Response:
89
+
90
+ ```json
91
+ {
92
+ "jsonrpc": "2.0",
93
+ "result": 540.0,
94
+ "id": 1
95
+ }
96
+ ```
97
+
98
+ ### 2. MCP Proxy format
99
+
100
+ ```json
101
+ {
102
+ "command": "command_name",
103
+ "params": {
104
+ "param1": "value1",
105
+ "param2": "value2"
106
+ }
107
+ }
108
+ ```
109
+
110
+ Example request:
111
+
112
+ ```bash
113
+ curl -X POST -H "Content-Type: application/json" -d '{
114
+ "command": "calculate_total",
115
+ "params": {
116
+ "prices": [100, 200, 300],
117
+ "discount": 10
118
+ }
119
+ }' http://localhost:8000/cmd
120
+ ```
121
+
122
+ Response:
123
+
124
+ ```json
125
+ {
126
+ "result": 540.0
127
+ }
128
+ ```
129
+
130
+ ### 3. Params-only format
131
+
132
+ ```json
133
+ {
134
+ "params": {
135
+ "command": "command_name",
136
+ "param1": "value1",
137
+ "param2": "value2"
138
+ }
139
+ }
140
+ ```
141
+
142
+ or
143
+
144
+ ```json
145
+ {
146
+ "params": {
147
+ "query": "command_name",
148
+ "param1": "value1",
149
+ "param2": "value2"
150
+ }
151
+ }
152
+ ```
153
+
154
+ Example request:
155
+
156
+ ```bash
157
+ curl -X POST -H "Content-Type: application/json" -d '{
158
+ "params": {
159
+ "command": "calculate_total",
160
+ "prices": [100, 200, 300],
161
+ "discount": 10
162
+ }
163
+ }' http://localhost:8000/cmd
164
+ ```
165
+
166
+ Response:
167
+
168
+ ```json
169
+ {
170
+ "result": 540.0
171
+ }
172
+ ```
173
+
174
+ ## Full Example: Integration with FastAPI
175
+
176
+ ```python
177
+ import logging
178
+ from fastapi import FastAPI, APIRouter
179
+ from mcp_proxy_adapter import CommandRegistry, MCPProxyAdapter, configure_logger
180
+
181
+ # Configure logging
182
+ logging.basicConfig(level=logging.INFO)
183
+ project_logger = logging.getLogger("my_project")
184
+
185
+ # Create FastAPI app
186
+ app = FastAPI(title="My API with MCP Proxy Integration")
187
+
188
+ # Create existing API router
189
+ router = APIRouter()
190
+
191
+ @router.get("/items")
192
+ async def get_items():
193
+ """Returns a list of items."""
194
+ return [
195
+ {"id": 1, "name": "Smartphone X", "price": 999.99},
196
+ {"id": 2, "name": "Laptop Y", "price": 1499.99},
197
+ ]
198
+
199
+ app.include_router(router)
200
+
201
+ # Register commands
202
+ registry = CommandRegistry()
203
+
204
+ @registry.command
205
+ def get_discounted_price(price: float, discount: float = 0.0) -> float:
206
+ """
207
+ Returns the price after applying a discount.
208
+ """
209
+ return price * (1 - discount / 100)
210
+
211
+ # Create and register MCP Proxy adapter
212
+ adapter = MCPProxyAdapter(registry)
213
+ adapter.register_endpoints(app)
214
+
215
+ # Save MCP Proxy config
216
+ adapter.save_config_to_file("mcp_proxy_config.json")
217
+ ```
218
+
219
+ ## Features
220
+ - Universal JSON-RPC endpoint for command execution
221
+ - Automatic OpenAPI schema generation and optimization for MCP Proxy
222
+ - Tool metadata for AI models
223
+ - Customizable endpoints and logging
224
+ - Full test coverage and examples
225
+
226
+ ## License
227
+ MIT
228
+
229
+ ## Documentation
230
+ See [docs/](docs/) for detailed guides, architecture, and examples.