-
Notifications
You must be signed in to change notification settings - Fork 190
feat: add workspace selection flow for MCP and CLI #576
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ee33683
feat: add workspace selection and routing for MCP tools
phernandez 116bdda
tests: force local routing in project remove integration test
phernandez 9098bb2
tests: avoid substring false positives in project list assertions
phernandez d3bfbef
tests: avoid parsing project names from rich output
phernandez 3d9323c
fix review issues for workspace routing and tool contracts
phernandez 7107179
refactor async client token helpers
phernandez 2ba4f2b
refactor cloud client helper to async context manager
phernandez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| """Workspace commands for Basic Memory cloud workspaces.""" | ||
|
|
||
| import typer | ||
| from rich.console import Console | ||
| from rich.table import Table | ||
|
|
||
| from basic_memory.cli.app import app | ||
| from basic_memory.cli.commands.command_utils import run_with_cleanup | ||
| from basic_memory.mcp.project_context import get_available_workspaces | ||
|
|
||
| console = Console() | ||
|
|
||
| workspace_app = typer.Typer(help="Manage cloud workspaces") | ||
| app.add_typer(workspace_app, name="workspace") | ||
|
|
||
|
|
||
| @workspace_app.command("list") | ||
| def list_workspaces() -> None: | ||
| """List cloud workspaces available to the current OAuth session.""" | ||
|
|
||
| async def _list(): | ||
| return await get_available_workspaces() | ||
|
|
||
| try: | ||
| workspaces = run_with_cleanup(_list()) | ||
| except RuntimeError as exc: | ||
| console.print(f"[red]Error: {exc}[/red]") | ||
| raise typer.Exit(1) | ||
| except Exception as exc: # pragma: no cover | ||
| console.print(f"[red]Error listing workspaces: {exc}[/red]") | ||
| raise typer.Exit(1) | ||
|
|
||
| if not workspaces: | ||
| console.print("[yellow]No accessible workspaces found.[/yellow]") | ||
| return | ||
|
|
||
| table = Table(title="Available Workspaces") | ||
| table.add_column("Name", style="cyan") | ||
| table.add_column("Type", style="blue") | ||
| table.add_column("Role", style="green") | ||
| table.add_column("Tenant ID", style="yellow") | ||
|
|
||
| for workspace in workspaces: | ||
| table.add_row( | ||
| workspace.name, | ||
| workspace.workspace_type, | ||
| workspace.role, | ||
| workspace.tenant_id, | ||
| ) | ||
|
|
||
| console.print(table) | ||
|
|
||
|
|
||
| @app.command("workspaces") | ||
| def workspaces_alias() -> None: | ||
| """Alias for `bm workspace list`.""" | ||
| list_workspaces() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The JSON helper path opens a client with the raw
workspaceoption, which means a workspace name is sent directly asX-Workspace-IDinstead of being resolved totenant_idlike the MCP tool path does. With--workspace <name> --format json, text mode and JSON mode can diverge (or JSON fails after a successful write), because JSON bypassesget_project_client()'s workspace resolution logic. Resolve workspace first (or reuseget_project_client) so JSON and text flows route identically.Useful? React with 👍 / 👎.