mcp-proxy-adapter 2.0.2__py3-none-any.whl → 2.1.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 (35) hide show
  1. {mcp_proxy_adapter-2.0.2.dist-info → mcp_proxy_adapter-2.1.0.dist-info}/METADATA +47 -13
  2. mcp_proxy_adapter-2.1.0.dist-info/RECORD +28 -0
  3. {mcp_proxy_adapter-2.0.2.dist-info → mcp_proxy_adapter-2.1.0.dist-info}/WHEEL +1 -1
  4. mcp_proxy_adapter-2.1.0.dist-info/top_level.txt +7 -0
  5. mcp_proxy_adapter/__init__.py +0 -17
  6. mcp_proxy_adapter/adapter.py +0 -697
  7. mcp_proxy_adapter/models.py +0 -47
  8. mcp_proxy_adapter/registry.py +0 -439
  9. mcp_proxy_adapter/schema.py +0 -257
  10. mcp_proxy_adapter-2.0.2.dist-info/RECORD +0 -33
  11. mcp_proxy_adapter-2.0.2.dist-info/top_level.txt +0 -1
  12. {mcp_proxy_adapter/adapters → adapters}/__init__.py +0 -0
  13. {mcp_proxy_adapter/analyzers → analyzers}/__init__.py +0 -0
  14. {mcp_proxy_adapter/analyzers → analyzers}/docstring_analyzer.py +0 -0
  15. {mcp_proxy_adapter/analyzers → analyzers}/type_analyzer.py +0 -0
  16. {mcp_proxy_adapter/cli → cli}/__init__.py +0 -0
  17. {mcp_proxy_adapter/cli → cli}/__main__.py +0 -0
  18. {mcp_proxy_adapter/cli → cli}/command_runner.py +0 -0
  19. {mcp_proxy_adapter/dispatchers → dispatchers}/__init__.py +0 -0
  20. {mcp_proxy_adapter/dispatchers → dispatchers}/base_dispatcher.py +0 -0
  21. {mcp_proxy_adapter/dispatchers → dispatchers}/json_rpc_dispatcher.py +0 -0
  22. {mcp_proxy_adapter/generators → generators}/__init__.py +0 -0
  23. {mcp_proxy_adapter/generators → generators}/endpoint_generator.py +0 -0
  24. {mcp_proxy_adapter/generators → generators}/openapi_generator.py +0 -0
  25. {mcp_proxy_adapter/generators → generators}/rest_api_generator.py +0 -0
  26. {mcp_proxy_adapter-2.0.2.dist-info → mcp_proxy_adapter-2.1.0.dist-info}/licenses/LICENSE +0 -0
  27. {mcp_proxy_adapter/openapi_schema → openapi_schema}/__init__.py +0 -0
  28. {mcp_proxy_adapter/openapi_schema → openapi_schema}/command_registry.py +0 -0
  29. {mcp_proxy_adapter/openapi_schema → openapi_schema}/rest_schema.py +0 -0
  30. {mcp_proxy_adapter/openapi_schema → openapi_schema}/rpc_generator.py +0 -0
  31. {mcp_proxy_adapter/openapi_schema → openapi_schema}/rpc_schema.py +0 -0
  32. {mcp_proxy_adapter/validators → validators}/__init__.py +0 -0
  33. {mcp_proxy_adapter/validators → validators}/base_validator.py +0 -0
  34. {mcp_proxy_adapter/validators → validators}/docstring_validator.py +0 -0
  35. {mcp_proxy_adapter/validators → validators}/metadata_validator.py +0 -0
@@ -1,257 +0,0 @@
1
- """
2
- Module for optimizing OpenAPI schema for MCP Proxy.
3
- """
4
- from typing import Dict, Any, List, Optional
5
-
6
- class SchemaOptimizer:
7
- """
8
- OpenAPI schema optimizer for use with MCP Proxy.
9
-
10
- This class transforms a standard OpenAPI schema into a format
11
- more suitable for use with MCP Proxy and AI models.
12
- """
13
-
14
- def optimize(
15
- self,
16
- schema: Dict[str, Any],
17
- cmd_endpoint: str,
18
- commands_info: Dict[str, Dict[str, Any]]
19
- ) -> Dict[str, Any]:
20
- """
21
- Optimizes OpenAPI schema for MCP Proxy.
22
-
23
- Args:
24
- schema: Original OpenAPI schema
25
- cmd_endpoint: Path for universal JSON-RPC endpoint
26
- commands_info: Information about registered commands
27
-
28
- Returns:
29
- Dict[str, Any]: Optimized schema
30
- """
31
- # Create a new schema in a format compatible with the proxy
32
- optimized = {
33
- "openapi": "3.0.2",
34
- "info": {
35
- "title": "Command Registry API",
36
- "description": "API for executing commands through MCPProxy",
37
- "version": "1.0.0"
38
- },
39
- "paths": {
40
- cmd_endpoint: {
41
- "post": {
42
- "summary": "Execute command",
43
- "description": "Universal endpoint for executing various commands",
44
- "operationId": "execute_command",
45
- "requestBody": {
46
- "content": {
47
- "application/json": {
48
- "schema": {
49
- "$ref": "#/components/schemas/CommandRequest"
50
- },
51
- "examples": {}
52
- }
53
- },
54
- "required": True
55
- },
56
- "responses": {
57
- "200": {
58
- "description": "Command executed successfully",
59
- "content": {
60
- "application/json": {
61
- "schema": {
62
- "$ref": "#/components/schemas/CommandResponse"
63
- }
64
- }
65
- }
66
- },
67
- "400": {
68
- "description": "Error in request or during command execution",
69
- "content": {
70
- "application/json": {
71
- "schema": {
72
- "type": "object",
73
- "properties": {
74
- "detail": {
75
- "type": "string",
76
- "description": "Error description"
77
- }
78
- }
79
- }
80
- }
81
- }
82
- }
83
- }
84
- }
85
- }
86
- },
87
- "components": {
88
- "schemas": {
89
- "CommandRequest": {
90
- "title": "CommandRequest",
91
- "description": "Command execution request",
92
- "type": "object",
93
- "required": ["command"],
94
- "properties": {
95
- "command": {
96
- "title": "Command",
97
- "description": "Command to execute",
98
- "type": "string",
99
- "enum": list(commands_info.keys())
100
- },
101
- "params": {
102
- "title": "Parameters",
103
- "description": "Command parameters, depend on command type",
104
- "oneOf": []
105
- }
106
- }
107
- },
108
- "CommandResponse": {
109
- "title": "CommandResponse",
110
- "description": "Command execution response",
111
- "type": "object",
112
- "required": ["result"],
113
- "properties": {
114
- "result": {
115
- "title": "Result",
116
- "description": "Command execution result"
117
- }
118
- }
119
- }
120
- },
121
- "examples": {}
122
- }
123
- }
124
-
125
- # Add parameter schemas and examples for each command
126
- for cmd_name, cmd_info in commands_info.items():
127
- param_schema_name = f"{cmd_name.capitalize()}Params"
128
- params = cmd_info.get("params", {})
129
- has_params = bool(params)
130
-
131
- # Define parameter schema (даже если params пустой, схема будет пустым объектом)
132
- param_schema = {
133
- "title": param_schema_name,
134
- "description": f"Parameters for command {cmd_name}",
135
- "type": "object",
136
- "properties": {},
137
- }
138
- required_params = []
139
- example_params = {}
140
-
141
- for param_name, param_info in params.items():
142
- param_property = {
143
- "title": param_name.capitalize(),
144
- "type": param_info.get("type", "string"),
145
- "description": param_info.get("description", "")
146
- }
147
- if "default" in param_info:
148
- param_property["default"] = param_info["default"]
149
- if "enum" in param_info:
150
- param_property["enum"] = param_info["enum"]
151
- param_schema["properties"][param_name] = param_property
152
- if param_info.get("required", False):
153
- required_params.append(param_name)
154
- if "example" in param_info:
155
- example_params[param_name] = param_info["example"]
156
- elif "default" in param_info:
157
- example_params[param_name] = param_info["default"]
158
- elif param_info.get("type") == "string":
159
- example_params[param_name] = "example_value"
160
- elif param_info.get("type") == "integer":
161
- example_params[param_name] = 1
162
- elif param_info.get("type") == "boolean":
163
- example_params[param_name] = False
164
-
165
- if required_params:
166
- param_schema["required"] = required_params
167
-
168
- # Добавляем схему параметров всегда, даже если она пустая
169
- optimized["components"]["schemas"][param_schema_name] = param_schema
170
-
171
- # Добавляем $ref на схему параметров в oneOf всегда
172
- optimized["components"]["schemas"]["CommandRequest"]["properties"]["params"]["oneOf"].append({
173
- "$ref": f"#/components/schemas/{param_schema_name}"
174
- })
175
-
176
- # Пример использования команды
177
- example_id = f"{cmd_name}_example"
178
- example = {
179
- "summary": f"Example of using command {cmd_name}",
180
- "value": {
181
- "command": cmd_name
182
- }
183
- }
184
- if has_params:
185
- example["value"]["params"] = example_params
186
- optimized["components"]["examples"][example_id] = example
187
- optimized["paths"][cmd_endpoint]["post"]["requestBody"]["content"]["application/json"]["examples"][example_id] = {
188
- "$ref": f"#/components/examples/{example_id}"
189
- }
190
-
191
- # Для команд без параметров добавляем type: null в oneOf
192
- optimized_oneof = optimized["components"]["schemas"]["CommandRequest"]["properties"]["params"]["oneOf"]
193
- optimized_oneof.append({"type": "null"})
194
-
195
- # Add tool descriptions to schema for AI models
196
- self._add_tool_descriptions(optimized, commands_info)
197
- return optimized
198
-
199
- def _add_tool_descriptions(
200
- self,
201
- schema: Dict[str, Any],
202
- commands_info: Dict[str, Dict[str, Any]]
203
- ) -> None:
204
- """
205
- Adds AI tool descriptions to the schema.
206
-
207
- This method enhances the OpenAPI schema with special descriptions
208
- for better integration with AI models and MCPProxy.
209
-
210
- Args:
211
- schema: OpenAPI schema to enhance
212
- commands_info: Information about registered commands
213
- """
214
- # Add AI tool descriptions to x-mcp-tools
215
- schema["x-mcp-tools"] = []
216
-
217
- for cmd_name, cmd_info in commands_info.items():
218
- # Create tool description
219
- tool = {
220
- "name": f"mcp_{cmd_name}", # Add mcp_ prefix to command name
221
- "description": cmd_info.get("description", "") or cmd_info.get("summary", ""),
222
- "parameters": {
223
- "type": "object",
224
- "properties": {},
225
- "required": []
226
- }
227
- }
228
-
229
- # Add parameters
230
- for param_name, param_info in cmd_info.get("params", {}).items():
231
- # Convert parameter to JSON Schema format
232
- param_schema = {}
233
-
234
- # Parameter type
235
- param_schema["type"] = param_info.get("type", "string")
236
-
237
- # Description
238
- if "description" in param_info:
239
- param_schema["description"] = param_info["description"]
240
-
241
- # Default value
242
- if "default" in param_info:
243
- param_schema["default"] = param_info["default"]
244
-
245
- # Possible values
246
- if "enum" in param_info:
247
- param_schema["enum"] = param_info["enum"]
248
-
249
- # Add parameter to schema
250
- tool["parameters"]["properties"][param_name] = param_schema
251
-
252
- # If parameter is required, add to required list
253
- if param_info.get("required", False):
254
- tool["parameters"]["required"].append(param_name)
255
-
256
- # Add tool to list
257
- schema["x-mcp-tools"].append(tool)
@@ -1,33 +0,0 @@
1
- mcp_proxy_adapter/__init__.py,sha256=9qzzMqbq2lbVI4wGAsFSLqTKMGDfnfaCXb5YPKqFt3s,463
2
- mcp_proxy_adapter/adapter.py,sha256=76dkVeDuqLsJ5AhuftzLlwy2M6yr_PfNbmNfo9dXVhc,28844
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/adapters/__init__.py,sha256=7QraK1j5y29KFSRF4mVxTiWC2Y3IYZLd6GhxUCtjyhg,790
7
- mcp_proxy_adapter/analyzers/__init__.py,sha256=2rcYZDP-bXq078MQpxP32lAwYYyRhOwAQGBcefBfBzY,368
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/cli/__init__.py,sha256=vJ0VTT7D4KRIOi9nQSgBLub7xywq68i2R1zYQkdA0Uk,416
11
- mcp_proxy_adapter/cli/__main__.py,sha256=qtjEOB4vkeMASjTppyRFok4IFihRrVOqjk6vLx8OW1g,2400
12
- mcp_proxy_adapter/cli/command_runner.py,sha256=4d0BZKRG9k4CLk3ZE26jfSxwwrls2e-KsflRoVimfyE,8328
13
- mcp_proxy_adapter/dispatchers/__init__.py,sha256=FWgimgInGphIjCEnvA3-ZExiapUzYAVis2H9C5IWivU,365
14
- mcp_proxy_adapter/dispatchers/base_dispatcher.py,sha256=S5_Xri058jAmOWeit1tedB_GMZQ9RLcNcYabA83ZF6k,2288
15
- mcp_proxy_adapter/dispatchers/json_rpc_dispatcher.py,sha256=ffu1M32E1AdC7IB44mlbV2L56eJQMsp-7fYi_r4rmHc,6331
16
- mcp_proxy_adapter/generators/__init__.py,sha256=KC8p2HcIBqdyCY1wHnN_c1EfbnPM39YhZLNBDcuv3vA,538
17
- mcp_proxy_adapter/generators/endpoint_generator.py,sha256=fhEInY3JPwdc5EENesN9VrrONwVZMpsledVpubouJLA,6513
18
- mcp_proxy_adapter/generators/openapi_generator.py,sha256=0Iqsn0fRr10sTWUK9-MU5MXOXKDHccxKYnmaiQPkKFw,9773
19
- mcp_proxy_adapter/generators/rest_api_generator.py,sha256=Zg9HVeIuspowXd6aBlyho4UXz-te_Hd4egGzjjIVF48,9159
20
- mcp_proxy_adapter/openapi_schema/__init__.py,sha256=S_lEg-VtlgDdhFxB_u9ZUM1dWKbzW_L_FM-6OCT4EXM,1334
21
- mcp_proxy_adapter/openapi_schema/command_registry.py,sha256=VqqdsVCcd5neqZ-bsfeKTHeLBeputwUZHxvNxVuvqZs,12075
22
- mcp_proxy_adapter/openapi_schema/rest_schema.py,sha256=nfF9axtmEA-B-Rw8TCnpmRf6Br3MfQ3TJVx-QHUHoy8,24103
23
- mcp_proxy_adapter/openapi_schema/rpc_generator.py,sha256=5FGMqjMXcaW0Ej6oey5mgiIxtEKTtA87dc-_kWLWqb0,13640
24
- mcp_proxy_adapter/openapi_schema/rpc_schema.py,sha256=pebSNt9rKyP2dyHpbjSllak6pQe5AnllReKHhR3UIaI,20162
25
- mcp_proxy_adapter/validators/__init__.py,sha256=s6zd5oZ3V2pXtzONoH3CiZYLzSVtCoLXpETMFUQfwWY,403
26
- mcp_proxy_adapter/validators/base_validator.py,sha256=qTEcXnfGqsgKKtc-lnttLiPTuq6vOHfDpZrQ5oP5Fi0,602
27
- mcp_proxy_adapter/validators/docstring_validator.py,sha256=Onpq2iNJ1qF4ejkJJIlBkLROuSNIVALHVmXIgkCpaFI,2934
28
- mcp_proxy_adapter/validators/metadata_validator.py,sha256=uCrn38-VYYn89l6f5CC_GoTAHAweaOW2Z6Esro1rtGw,3155
29
- mcp_proxy_adapter-2.0.2.dist-info/licenses/LICENSE,sha256=OkApFEwdgMCt_mbvUI-eIwKMSTe38K3XnU2DT5ub-wI,1072
30
- mcp_proxy_adapter-2.0.2.dist-info/METADATA,sha256=3-LXLlAgg1swHpgFqA015-zEi_kQ9jAfNoe6e-ExKPk,6076
31
- mcp_proxy_adapter-2.0.2.dist-info/WHEEL,sha256=ooBFpIzZCPdw3uqIQsOo4qqbA4ZRPxHnOH7peeONza0,91
32
- mcp_proxy_adapter-2.0.2.dist-info/top_level.txt,sha256=JZT7vPLBYrtroX-ij68JBhJYbjDdghcV-DFySRy-Nnw,18
33
- mcp_proxy_adapter-2.0.2.dist-info/RECORD,,
@@ -1 +0,0 @@
1
- mcp_proxy_adapter
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes