workspace-mcp: strip /workspace prefix for API GW proxy route
This commit is contained in:
@@ -111,4 +111,23 @@ class _ActorCredentialsMiddleware:
|
|||||||
await self._app(scope, receive, send)
|
await self._app(scope, receive, send)
|
||||||
|
|
||||||
|
|
||||||
handler = Mangum(_ActorCredentialsMiddleware(_app), lifespan='auto')
|
class _PathPrefixStripMiddleware:
|
||||||
|
"""Strip /workspace prefix so API GW proxy route maps to FastMCP's /mcp path."""
|
||||||
|
_PREFIX = b'/workspace'
|
||||||
|
|
||||||
|
def __init__(self, app):
|
||||||
|
self._app = app
|
||||||
|
|
||||||
|
async def __call__(self, scope, receive, send):
|
||||||
|
if scope['type'] in ('http', 'websocket'):
|
||||||
|
path: str = scope.get('path', '')
|
||||||
|
if path.startswith('/workspace'):
|
||||||
|
scope = dict(scope)
|
||||||
|
scope['path'] = path[len('/workspace'):] or '/'
|
||||||
|
raw: bytes = scope.get('raw_path') or b''
|
||||||
|
if raw.startswith(self._PREFIX):
|
||||||
|
scope['raw_path'] = raw[len(self._PREFIX):] or b'/'
|
||||||
|
await self._app(scope, receive, send)
|
||||||
|
|
||||||
|
|
||||||
|
handler = Mangum(_PathPrefixStripMiddleware(_ActorCredentialsMiddleware(_app)), lifespan='auto')
|
||||||
|
|||||||
Reference in New Issue
Block a user