mirror of
https://github.com/open-webui/mcpo
synced 2025-06-26 18:26:58 +00:00
As discussed (discussions/24), this new parameter 'prefix' adds an optional prefix to the routes of the services
This commit is contained in:
@@ -47,6 +47,9 @@ def main(
|
||||
ssl_keyfile: Annotated[
|
||||
Optional[str], typer.Option("--ssl-keyfile", "-k", help="SSL keyfile")
|
||||
] = None,
|
||||
prefix: Annotated[
|
||||
Optional[str], typer.Option("--prefix", "-x", help="URL prefix")
|
||||
] = None,
|
||||
):
|
||||
server_command = None
|
||||
if not config:
|
||||
@@ -81,6 +84,17 @@ def main(
|
||||
for key, value in env_dict.items():
|
||||
os.environ[key] = value
|
||||
|
||||
# Whatever the prefix is, make sure it starts and ends with a /
|
||||
if prefix is None:
|
||||
# Set default value
|
||||
prefix = "/"
|
||||
# if prefix doesn't end with a /, add it
|
||||
if not prefix.endswith("/"):
|
||||
prefix = f"{prefix}/"
|
||||
# if prefix doesn't start with a /, add it
|
||||
if not prefix.startswith("/"):
|
||||
prefix = f"/{prefix}"
|
||||
|
||||
# Run your async run function from mcpo.main
|
||||
asyncio.run(
|
||||
run(
|
||||
@@ -95,6 +109,7 @@ def main(
|
||||
server_command=server_command,
|
||||
ssl_certfile=ssl_certfile,
|
||||
ssl_keyfile=ssl_keyfile,
|
||||
prefix=prefix,
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
@@ -159,6 +159,7 @@ async def run(
|
||||
version = kwargs.get("version") or "1.0"
|
||||
ssl_certfile = kwargs.get("ssl_certfile")
|
||||
ssl_keyfile= kwargs.get("ssl_keyfile")
|
||||
prefix = kwargs.get("prefix") or "/"
|
||||
|
||||
main_app = FastAPI(
|
||||
title=name, description=description, version=version, ssl_certfile=ssl_certfile, ssl_keyfile=ssl_keyfile, lifespan=lifespan
|
||||
@@ -209,7 +210,7 @@ async def run(
|
||||
|
||||
sub_app.state.api_dependency = api_dependency
|
||||
|
||||
main_app.mount(f"/{server_name}", sub_app)
|
||||
main_app.mount(f"/mcpo/{server_name}", sub_app)
|
||||
|
||||
else:
|
||||
raise ValueError("You must provide either server_command or config.")
|
||||
|
||||
Reference in New Issue
Block a user