Skip to content

feature - add session-scoped MCP tool selection to TUI#8

Draft
lgarceau768 wants to merge 2 commits intoflexfrom
feat/mcp-awareness
Draft

feature - add session-scoped MCP tool selection to TUI#8
lgarceau768 wants to merge 2 commits intoflexfrom
feat/mcp-awareness

Conversation

@lgarceau768
Copy link
Copy Markdown
Collaborator

Summary

  • Intercepts the first message submit on new sessions to show a searchable tool selection dialog when MCP servers are active, letting users choose which tools (and their token overhead) to include for the session
  • Tool selection is persisted as a `Permission.Ruleset` deny list on the session, filtering unselected tools from every LLM call for its lifetime
  • Adds a `session.tools` command palette entry for mid-session tool adjustment

Changes

  • `src/mcp/index.ts` — add `defs()` to `MCP.Interface`, exposing the in-memory `Record<string, MCPToolDef[]>` cache
  • `src/server/routes/instance/mcp.ts` — new `GET /mcp/tools` endpoint returning tools grouped by server with per-tool token estimates (`~chars/3.5`)
  • `packages/sdk/js` — SDK regenerated; `sdk.client.mcp.tools()` and `session.update({ permission })` now available in v2 client
  • `context/local.tsx` — `sessionTools` state: filter, pending prompt stash, resume callback, reset
  • `component/dialog-session-tools.tsx` — new searchable dialog: tools grouped by MCP server, checkbox toggle, `[space]` toggle / `[a]` all / `[n]` none / `[enter]` confirm, live token count in title
  • `component/prompt/index.tsx` — intercept first submit when MCP connected and pending is null; apply deny rules via `session.update` post-create; resume via stored callback after dialog closes
  • `app.tsx` — `session.tools` command in Agent palette; mid-session mode passes current `sessionID` and writes updated rules on confirm
  • `test/session/prompt-effect.test.ts`, `snapshot-tool-race.test.ts` — add `defs` to MCP mock objects

Test Plan

  • Start TUI with at least one MCP server connected
  • Type a message and press Enter — tool selection dialog should appear listing all tools grouped by server with token estimates
  • Toggle individual tools with Space, select all with `a`, none with `n`, confirm with Enter
  • Verify session is created and unselected tools are absent from subsequent LLM calls
  • Press Esc — session should start with all tools (no filter applied)
  • Open command palette mid-session and run `session.tools` — dialog pre-checks currently-enabled tools; confirm updates the session permission ruleset
  • `bun typecheck` passes with zero errors

- add GET /mcp/tools endpoint returning per-tool token estimates
- expose MCP.defs() on the service interface for tool listing
- intercept first-message submit to show tool selection dialog when MCP servers are active
- new DialogSessionTools component: searchable, grouped by server, checkbox toggle, live token count
- apply selected tools as session-level Permission.Ruleset deny rules after session creation
- register session.tools command in palette for mid-session tool adjustment
- regenerate v2 SDK to include mcp.tools() and session.update permission field
@github-actions
Copy link
Copy Markdown

Hey! Your PR title feature - add session-scoped MCP tool selection to TUI doesn't follow conventional commit format.

Please update it to start with one of:

  • feat: or feat(scope): new feature
  • fix: or fix(scope): bug fix
  • docs: or docs(scope): documentation changes
  • chore: or chore(scope): maintenance tasks
  • refactor: or refactor(scope): code refactoring
  • test: or test(scope): adding or updating tests

Where scope is the package name (e.g., app, desktop, opencode).

See CONTRIBUTING.md for details.

@github-actions
Copy link
Copy Markdown

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • PR description is missing required template sections. Please use the PR template.

Please edit this PR description to address the above within 2 hours, or it will be automatically closed.

If you believe this was flagged incorrectly, please let a maintainer know.

@lgarceau768
Copy link
Copy Markdown
Collaborator Author

Tested and did not work :(

  • needs more interation

@lgarceau768 lgarceau768 marked this pull request as draft April 21, 2026 01:20
@lgarceau768 lgarceau768 changed the base branch from dev to flex April 21, 2026 01:21
@lgarceau768
Copy link
Copy Markdown
Collaborator Author

after modifications, the model opens, a little buggy as return collapses and closes the dialog need to remove this.

@lgarceau768
Copy link
Copy Markdown
Collaborator Author

also blocks the session from beginning until all mcps has loaded - with a failing mcp this is a little annoying

@lgarceau768
Copy link
Copy Markdown
Collaborator Author

if the user escapes the dialog and presses enter we assume the default? May not be the best path

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant