Files
mcpctl/.taskmaster/tasks/task_047.md

62 lines
1.9 KiB
Markdown
Raw Normal View History

# Task ID: 47
**Title:** Implement session state management for gating
**Status:** done
**Dependencies:** 39 ✓
**Priority:** high
**Description:** Extend the McpRouter to track per-session gating state including gated status, accumulated tags, and retrieved prompts set.
**Details:**
1. Update `/src/mcplocal/src/router.ts` to add session state:
```typescript
interface SessionState {
gated: boolean; // starts true if project is gated
tags: string[]; // accumulated from begin_session + read_prompts
retrievedPrompts: Set<string>; // prompts already sent (avoid duplicates)
}
export class McpRouter {
private sessionStates: Map<string, SessionState> = new Map();
getSessionState(sessionId: string): SessionState {
if (!this.sessionStates.has(sessionId)) {
this.sessionStates.set(sessionId, {
gated: this.projectConfig?.gated ?? true,
tags: [],
retrievedPrompts: new Set(),
});
}
return this.sessionStates.get(sessionId)!;
}
ungateSession(sessionId: string): void {
const state = this.getSessionState(sessionId);
state.gated = false;
}
addRetrievedPrompts(sessionId: string, names: string[]): void {
const state = this.getSessionState(sessionId);
names.forEach(n => state.retrievedPrompts.add(n));
}
}
```
2. Clean up session state when session closes
3. Handle session state for non-gated projects (gated=false from start)
**Test Strategy:**
- Unit test: New session starts with gated=true for gated project
- Unit test: New session starts with gated=false for non-gated project
- Unit test: ungateSession changes gated to false
- Unit test: addRetrievedPrompts adds to set
- Unit test: retrievedPrompts prevents duplicates
- Unit test: Session state isolated per sessionId
- Unit test: Session cleanup removes state