Now I have all the information needed to provide a complete analysis. Here is my findings:
Root Cause Analysis: Why MCP-Tool Sessions Don't Appear in the VSCode Sidebar TreeView
1. How the TreeView Fetches Sessions (sessionTreeProvider.ts)
The SessionTreeProvider._fetchSessions() method (line 537) calls the backend via:
const result = await client.querySessions({
page: this._currentPage,
pageSize: PAGE_SIZE, // 50
workspacePath: this._workspacePath, // <-- KEY FILTER
keyword: this._filterKeyword,
onlyBoundToCommit: this._filterUnboundOnly ? false : undefined,
});
The critical field is this._workspacePath, which is initialized in the constructor (line 391):
this._workspacePath = resolveWorkspacePath();
And resolveWorkspacePath() (line 899) returns:
function resolveWorkspacePath(): string | undefined {
const folders = vscode.workspace.workspaceFolders;
return folders && folders.length > 0 ? folders[0].uri.fsPath : undefined;
}
This means _workspacePath is set to whatever folder is currently open in VS Code -- the first workspace folder's fsPath.
2. How the Extension Communicates with the Backend (backendClient.ts)
The querySessions() method (line 286) builds a query string from the filter object and calls GET /api/sessions:
async querySessions(filter: SessionQueryFilter = {}): Promise<PaginatedResponse<AgentSession>> {
const qs = buildQueryString(filter as Record<string, unknown>);
const resp = await this.request<...>("GET", `/api/sessions${qs}`);
...
}
The buildQueryString utility (line 696) serializes all non-null/non-undefined/non-empty values into URL query parameters. So if workspacePath is /Users/hobo/Projects/AgentLog, the request becomes:
GET /api/sessions?page=1&pageSize=50&workspacePath=/Users/hobo/Projects/AgentLog
3. Does the Backend Filter by workspace_path? (YES -- exact match)
In the GET /api/sessions route handler (sessions.ts, line 150):
const filter: SessionQueryFilter = {
workspacePath: q.workspacePath || undefined, // passed through from query string
provider: (q.provider as ModelProvider) || undefined,
source: (q.source as AgentSource) || undefined,
...
};
Then in logService.ts querySessions() (line 144):
if (workspacePath) {
conditions.push('workspace_path = @workspacePath'); // <-- EXACT MATCH
params.workspacePath = workspacePath;
}
This is an exact string equality check (=), not a prefix/LIKE match.
4. THE ROOT CAUSE: workspace_path Mismatch
Here is the full chain that causes the problem:
| Component | workspace_path value |
|---|
| MCP tool wrote | process.cwd() which was the directory the MCP tool process ran in. You mentioned the test was run from ~/Projects/AgentLogTest. So the session was stored with workspace_path = '/Users/hobo/Projects/AgentLogTest' (or possibly /Users/hobo/Projects/AgentLog if process.cwd() resolved there -- you mentioned both). |
| VS Code sidebar queries | vscode.workspace.workspaceFolders[0].uri.fsPath, which is the folder currently open in VS Code. If you had /Users/hobo/Projects/AgentLog open, it would query workspace_path = '/Users/hobo/Projects/AgentLog'. |
The SQL WHERE clause is an exact-match filter:
WHERE workspace_path = '/Users/hobo/Projects/AgentLog'
So if the MCP tool wrote the session with workspace_path = '/Users/hobo/Projects/AgentLogTest' (because process.cwd() was ~/Projects/AgentLogTest when the test ran), the session will never appear in the sidebar when VS Code has /Users/hobo/Projects/AgentLog open. They are different strings.
Even if the MCP tool used process.cwd() = /Users/hobo/Projects/AgentLog, there could still be subtle mismatches (trailing slash, symlink resolution, case differences on case-insensitive filesystems). But in your scenario, the paths are clearly different directories entirely.
Summary of All Filters
The TreeView does not filter by source or provider. It only passes these optional filters:
| Filter field | Used by TreeView? | Effect |
|---|
workspacePath | YES -- always sent if a workspace folder is open | Exact-match WHERE workspace_path = ? |
keyword | Only if user types a search | LIKE %keyword% on prompt/response/note |
onlyBoundToCommit | Only if user toggles the "unbound only" filter | WHERE commit_hash IS NOT NULL |
provider | No | Not sent by TreeView |
source | No | Not sent by TreeView |
What You Can Do
- Have the MCP tool accept an explicit
workspacePath parameter instead of relying on process.cwd(), so the caller can pass the correct workspace path.
- Make the backend use a prefix match or path normalization (e.g.,
LIKE @workspacePath || '%' or resolve symlinks/trailing slashes).
- When
workspacePath is not provided to the TreeView query, all sessions across all workspaces would be shown (the if (workspacePath) guard in logService.ts line 144 means the filter is simply omitted). So if resolveWorkspacePath() returned undefined, you'd see everything -- but that only happens when no folder is open in VS Code.