mcp-proxy-adapter 6.3.14__py3-none-any.whl → 6.3.16__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.
@@ -103,6 +103,9 @@ class ProtocolMiddleware(BaseHTTPMiddleware):
103
103
  try:
104
104
  # Get protocol from request
105
105
  protocol = self._get_request_protocol(request)
106
+ logger.debug(f"Detected protocol: {protocol} for {request.method} {request.url.path}")
107
+ logger.debug(f"Request scheme: {request.url.scheme}")
108
+ logger.debug(f"Request headers: {dict(request.headers)}")
106
109
 
107
110
  # Check if protocol is allowed
108
111
  if not self.protocol_manager.is_protocol_allowed(protocol):
@@ -119,11 +122,13 @@ class ProtocolMiddleware(BaseHTTPMiddleware):
119
122
  )
120
123
 
121
124
  # Continue processing
125
+ logger.debug(f"Protocol '{protocol}' allowed, continuing to next middleware/handler")
122
126
  response = await call_next(request)
127
+ logger.debug(f"Protocol middleware completed successfully for {request.method} {request.url.path}")
123
128
  return response
124
129
 
125
130
  except Exception as e:
126
- logger.error(f"Protocol middleware error: {e}")
131
+ logger.error(f"Protocol middleware error: {e}", exc_info=True)
127
132
  return JSONResponse(
128
133
  status_code=500,
129
134
  content={"error": "Protocol validation error", "message": str(e)},
@@ -139,39 +144,71 @@ class ProtocolMiddleware(BaseHTTPMiddleware):
139
144
  Returns:
140
145
  Protocol name (http, https, mtls)
141
146
  """
142
- # Check if request is secure (HTTPS)
143
- if request.url.scheme:
144
- scheme = request.url.scheme.lower()
145
-
146
- # If HTTPS, check if client certificate is provided (MTLS)
147
- if scheme == "https":
148
- # Check for client certificate in headers or SSL context
149
- if hasattr(request, "scope") and "ssl" in request.scope:
150
- ssl_context = request.scope.get("ssl")
151
- if ssl_context and hasattr(ssl_context, "getpeercert"):
152
- try:
153
- cert = ssl_context.getpeercert()
154
- if cert:
155
- return "mtls"
156
- except:
157
- pass
158
-
159
- # Check for client certificate in headers
160
- if request.headers.get("ssl-client-cert") or request.headers.get(
161
- "x-client-cert"
162
- ):
163
- return "mtls"
164
-
165
- return "https"
166
-
167
- return scheme
168
-
169
- # Fallback to checking headers
170
- if request.headers.get("x-forwarded-proto"):
171
- return request.headers.get("x-forwarded-proto").lower()
172
-
173
- # Default to HTTP
174
- return "http"
147
+ try:
148
+ # Check if request is secure (HTTPS)
149
+ if request.url.scheme:
150
+ scheme = request.url.scheme.lower()
151
+
152
+ # If HTTPS, check if client certificate is provided (MTLS)
153
+ if scheme == "https":
154
+ # Check for client certificate in ASGI scope
155
+ try:
156
+ # Method 1: Check transport info in ASGI scope
157
+ if hasattr(request, "scope") and request.scope:
158
+ # Check for client certificate in transport layer
159
+ transport = request.scope.get("transport")
160
+ if transport and hasattr(transport, "get_extra_info"):
161
+ try:
162
+ ssl_object = transport.get_extra_info("ssl_object")
163
+ if ssl_object:
164
+ try:
165
+ cert = ssl_object.getpeercert()
166
+ if cert:
167
+ logger.debug(f"mTLS client certificate detected: {cert.get('subject', 'unknown')}")
168
+ return "mtls"
169
+ except Exception as e:
170
+ logger.debug(f"Error checking client certificate: {e}")
171
+ except Exception as e:
172
+ logger.debug(f"Error getting SSL object from transport: {e}")
173
+
174
+ # Method 2: Check client info in ASGI scope
175
+ try:
176
+ client_info = request.scope.get("client")
177
+ if client_info and len(client_info) > 2:
178
+ # client_info format: (host, port, additional_info...)
179
+ # Additional info might contain certificate information
180
+ logger.debug(f"Client info detected, might be mTLS: {client_info}")
181
+ except Exception as e:
182
+ logger.debug(f"Error checking client info: {e}")
183
+ except Exception as e:
184
+ logger.debug(f"Error checking ASGI scope for mTLS: {e}")
185
+
186
+ # Check for client certificate in headers (proxy forwarded)
187
+ try:
188
+ if (request.headers.get("ssl-client-cert") or
189
+ request.headers.get("x-client-cert") or
190
+ request.headers.get("x-ssl-cert") or
191
+ request.headers.get("x-forwarded-client-cert")):
192
+ logger.debug("mTLS client certificate detected in headers")
193
+ return "mtls"
194
+ except Exception as e:
195
+ logger.debug(f"Error checking headers for mTLS: {e}")
196
+
197
+ return "https"
198
+
199
+ return scheme
200
+
201
+ # Fallback to checking headers
202
+ if request.headers.get("x-forwarded-proto"):
203
+ return request.headers.get("x-forwarded-proto").lower()
204
+
205
+ # Default to HTTP
206
+ return "http"
207
+
208
+ except Exception as e:
209
+ logger.error(f"Error in _get_request_protocol: {e}", exc_info=True)
210
+ # Fallback to HTTP if there's any error
211
+ return "http"
175
212
 
176
213
 
177
214
  def setup_protocol_middleware(app, app_config: Optional[Dict[str, Any]] = None):
@@ -2,4 +2,4 @@
2
2
  Version information for MCP Proxy Adapter.
3
3
  """
4
4
 
5
- __version__ = "6.3.14"
5
+ __version__ = "6.3.16"
@@ -1,11 +1,12 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mcp-proxy-adapter
3
- Version: 6.3.14
3
+ Version: 6.3.16
4
4
  Summary: Powerful JSON-RPC microservices framework with built-in security, authentication, and proxy registration
5
5
  Home-page: https://github.com/maverikod/mcp-proxy-adapter
6
6
  Author: Vasiliy Zdanovskiy
7
7
  Author-email: Vasiliy Zdanovskiy <vasilyvz@gmail.com>
8
8
  Maintainer-email: Vasiliy Zdanovskiy <vasilyvz@gmail.com>
9
+ License: MIT
9
10
  Project-URL: Homepage, https://github.com/maverikod/mcp-proxy-adapter
10
11
  Project-URL: Documentation, https://github.com/maverikod/mcp-proxy-adapter#readme
11
12
  Project-URL: Source, https://github.com/maverikod/mcp-proxy-adapter
@@ -14,7 +15,6 @@ Project-URL: PyPI, https://pypi.org/project/mcp-proxy-adapter/
14
15
  Keywords: json-rpc,microservices,fastapi,security,authentication,authorization,proxy,mcp,mtls,ssl,rest,api
15
16
  Classifier: Development Status :: 4 - Beta
16
17
  Classifier: Intended Audience :: Developers
17
- Classifier: License :: OSI Approved :: MIT License
18
18
  Classifier: Operating System :: OS Independent
19
19
  Classifier: Programming Language :: Python :: 3
20
20
  Classifier: Programming Language :: Python :: 3.9
@@ -27,7 +27,6 @@ Classifier: Topic :: Security
27
27
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
28
28
  Requires-Python: >=3.9
29
29
  Description-Content-Type: text/markdown
30
- License-File: LICENSE
31
30
  Requires-Dist: fastapi<1.0.0,>=0.95.0
32
31
  Requires-Dist: pydantic>=2.0.0
33
32
  Requires-Dist: hypercorn<1.0.0,>=0.15.0
@@ -53,7 +52,6 @@ Requires-Dist: httpx>=0.24.0; extra == "test"
53
52
  Requires-Dist: pytest-mock>=3.10.0; extra == "test"
54
53
  Dynamic: author
55
54
  Dynamic: home-page
56
- Dynamic: license-file
57
55
  Dynamic: requires-python
58
56
 
59
57
  # MCP Proxy Adapter
@@ -4,7 +4,7 @@ mcp_proxy_adapter/config.py,sha256=-7iVS0mUWWKNeao7nqTAFlUD6FcMwRlDkchN7OwYsr0,2
4
4
  mcp_proxy_adapter/custom_openapi.py,sha256=yLle4CntYK9wpivgn9NflZyJhy-YNrmWjJzt0ai5nP0,14672
5
5
  mcp_proxy_adapter/main.py,sha256=qDkQTXnCvf8u0I3b8PRrguOoVdjd8YRr90ZooOqeOto,3401
6
6
  mcp_proxy_adapter/openapi.py,sha256=2UZOI09ZDRJuBYBjKbMyb2U4uASszoCMD5o_4ktRpvg,13480
7
- mcp_proxy_adapter/version.py,sha256=MVfIeHEccRPPVwIvZE06OOoj8ARRyWOlAwfPcn9D8gY,75
7
+ mcp_proxy_adapter/version.py,sha256=pf4_y_pbHzVAUiMXhbiLW3FJHLCg0pslVHNa-MDrJkE,75
8
8
  mcp_proxy_adapter/api/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
9
  mcp_proxy_adapter/api/app.py,sha256=22NIDGo6pGkOZnvBWeKv_-RIRye4YaYkIskVGIsCCMs,28600
10
10
  mcp_proxy_adapter/api/handlers.py,sha256=iyFGoEuUS1wxbV1ELA0zmaxIyQR7j4zw-4MrD-uIO6E,8294
@@ -18,7 +18,7 @@ mcp_proxy_adapter/api/middleware/error_handling.py,sha256=i3oghY1VdjHppFa7bTIx87
18
18
  mcp_proxy_adapter/api/middleware/factory.py,sha256=r0BXntUOxF6DiCVqqmAUb3JjargdR28aj2d9X5z-zX4,7987
19
19
  mcp_proxy_adapter/api/middleware/logging.py,sha256=AGv9lqfkTOCVJxYKflLghe1cd4kVPMLO1ni5E2FQBlk,4840
20
20
  mcp_proxy_adapter/api/middleware/performance.py,sha256=-EvA7YIcTlxn8RuxlWlScJvX2EIoeEp3P5dKVWZHYRY,2357
21
- mcp_proxy_adapter/api/middleware/protocol_middleware.py,sha256=dPNYdJ77qD7C7HyjHtH9cknJejrdeyTtvFRtlqlS9C8,8333
21
+ mcp_proxy_adapter/api/middleware/protocol_middleware.py,sha256=zm-Q0KnCzbAB3ue8dwnEkb-OyCuIbqu01s2_GE2rtH0,11094
22
22
  mcp_proxy_adapter/api/middleware/transport_middleware.py,sha256=VG1rWyuh-O2pdc0kQ3SADFvyh286o5Wrnkt8OFQ0WQw,4274
23
23
  mcp_proxy_adapter/api/middleware/unified_security.py,sha256=PMbJxVzGNlb-IPAqvIeEo1st-jykYX9Mns6lXIfdtAE,7764
24
24
  mcp_proxy_adapter/api/middleware/user_info_middleware.py,sha256=A3liNzkZWDDlkDSBBoz8lH9fTLKlOQc_oI_M_dIGHx4,9330
@@ -136,10 +136,9 @@ mcp_proxy_adapter/examples/scripts/generate_certificates_and_tokens.py,sha256=hU
136
136
  mcp_proxy_adapter/schemas/base_schema.json,sha256=v9G9cGMd4dRhCZsOQ_FMqOi5VFyVbI6Cf3fyIvOT9dc,2881
137
137
  mcp_proxy_adapter/schemas/openapi_schema.json,sha256=C3yLkwmDsvnLW9B5gnKKdBGl4zxkeU-rEmjTrNVsQU0,8405
138
138
  mcp_proxy_adapter/utils/config_generator.py,sha256=UXxuxxAyKTesAS3DOofQ26e20v771inA7EfBV8PZD1c,47543
139
- mcp_proxy_adapter-6.3.14.dist-info/licenses/LICENSE,sha256=6KdtUcTwmTRbJrAmYjVn7e6S-V42ubeDJ-AiVEzZ510,1075
140
139
  mcp_proxy_adapter_issue_package/demonstrate_issue.py,sha256=O54fwWQvUAjEGiHhQGm1JLnARkhVCwAqjBk_89HyRbY,7894
141
- mcp_proxy_adapter-6.3.14.dist-info/METADATA,sha256=rLsXqMhDpbDRKpHcUitRcvI0bZTeD9MaBFdZJap0vQs,22348
142
- mcp_proxy_adapter-6.3.14.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
143
- mcp_proxy_adapter-6.3.14.dist-info/entry_points.txt,sha256=J3eV6ID0lt_VSp4lIdIgBFTqLCThgObNNxRCbyfiMHw,70
144
- mcp_proxy_adapter-6.3.14.dist-info/top_level.txt,sha256=CHk-Mc-AxjO-tRheegA2qLiQnU4vZRnxuTF81So6SAc,50
145
- mcp_proxy_adapter-6.3.14.dist-info/RECORD,,
140
+ mcp_proxy_adapter-6.3.16.dist-info/METADATA,sha256=MbTaIC1gffjPJw8WnlLRi2EbvWVGCZy_2xQOCsgyw9E,22266
141
+ mcp_proxy_adapter-6.3.16.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
142
+ mcp_proxy_adapter-6.3.16.dist-info/entry_points.txt,sha256=J3eV6ID0lt_VSp4lIdIgBFTqLCThgObNNxRCbyfiMHw,70
143
+ mcp_proxy_adapter-6.3.16.dist-info/top_level.txt,sha256=CHk-Mc-AxjO-tRheegA2qLiQnU4vZRnxuTF81So6SAc,50
144
+ mcp_proxy_adapter-6.3.16.dist-info/RECORD,,
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2024 Vasiliy Zdanovskiy
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.