Allow local llama UI to access MCP proxy
This commit is contained in:
+7
-2
@@ -12,6 +12,7 @@ from mcp.server.lowlevel import Server
|
|||||||
from mcp.server.streamable_http_manager import StreamableHTTPSessionManager
|
from mcp.server.streamable_http_manager import StreamableHTTPSessionManager
|
||||||
from mcp.server.transport_security import TransportSecuritySettings
|
from mcp.server.transport_security import TransportSecuritySettings
|
||||||
from starlette.applications import Starlette
|
from starlette.applications import Starlette
|
||||||
|
from starlette.middleware.cors import CORSMiddleware
|
||||||
from starlette.routing import Mount
|
from starlette.routing import Mount
|
||||||
|
|
||||||
from story_client import EXPECTED, MCP_URL, OAuth
|
from story_client import EXPECTED, MCP_URL, OAuth
|
||||||
@@ -58,7 +59,8 @@ def make_app(port):
|
|||||||
app=server, json_response=True, stateless=True,
|
app=server, json_response=True, stateless=True,
|
||||||
security_settings=TransportSecuritySettings(enable_dns_rebinding_protection=True,
|
security_settings=TransportSecuritySettings(enable_dns_rebinding_protection=True,
|
||||||
allowed_hosts=[f'127.0.0.1:{port}', f'localhost:{port}'],
|
allowed_hosts=[f'127.0.0.1:{port}', f'localhost:{port}'],
|
||||||
allowed_origins=[f'http://127.0.0.1:{port}', f'http://localhost:{port}']))
|
allowed_origins=[f'http://127.0.0.1:{port}', f'http://localhost:{port}',
|
||||||
|
'http://127.0.0.1:8080']))
|
||||||
@contextlib.asynccontextmanager
|
@contextlib.asynccontextmanager
|
||||||
async def lifespan(app):
|
async def lifespan(app):
|
||||||
try:
|
try:
|
||||||
@@ -68,7 +70,10 @@ def make_app(port):
|
|||||||
async def handle(scope, receive, send):
|
async def handle(scope, receive, send):
|
||||||
# A fixed local route; mounted ASGI app receives /mcp in the original path.
|
# A fixed local route; mounted ASGI app receives /mcp in the original path.
|
||||||
await manager.handle_request(scope, receive, send)
|
await manager.handle_request(scope, receive, send)
|
||||||
return Starlette(routes=[Mount('/mcp', app=handle)], lifespan=lifespan)
|
app = Starlette(routes=[Mount('/mcp', app=handle)], lifespan=lifespan)
|
||||||
|
return CORSMiddleware(app, allow_origins=['http://127.0.0.1:8080'],
|
||||||
|
allow_methods=['GET', 'POST', 'DELETE', 'OPTIONS'],
|
||||||
|
allow_headers=['*'], expose_headers=['Mcp-Session-Id', 'Mcp-Protocol-Version'])
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|||||||
Reference in New Issue
Block a user