Skip to content

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

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

feature - add session-scoped MCP tool selection to TUI#8
lgarceau768 wants to merge 12 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

lgarceau768 and others added 11 commits April 15, 2026 12:09
Mark the skill template TextPart as synthetic so the full prompt is
sent to the model but hidden from the user. Add a short ignored
summary part ('Running skill: <command>') so the user still sees
confirmation that the skill was loaded.

Rebased from flexion/hide-skill-prompt-in-chat onto v1.4.0.
Gate tool resolution, LiteLLM noop injection, activeTools, tools, and
toolChoice behind input.model.capabilities.toolcall. Without this fix,
tool_call: false in opencode.json is parsed and stored but never checked,
causing Bedrock models that don't support streaming + tool use to fail.

Adds regression test verifying body.tools is not sent when toolcall: false.

Cherry-picked from lgarceau768#1 and rebased onto v1.4.0.
Covers cloning, building with bun, AWS SSO profile config,
opencode.json Bedrock provider setup, and the opencode-work
shell alias. Notes the tool_call fix included in this branch.
Bun's embedded code signature is rejected by Darwin 25+ at runtime,
killing the binary with SIGKILL (exit 137) before it starts. Strip the
signature and apply a fresh ad-hoc one via codesign after each darwin
build. Also documents the fix in LOCAL_AWS_SETUP.md.
fix: re-sign macOS binaries after Bun compile to fix Darwin 25+ SIGKILL
…ditional models

- Add palmyra and pixtral to US cross-region inference profile prefix list
- Strip reasoning content from message history for non-reasoning models
- Exclude palmyra from reasoning variant generation to prevent unsupported params
chore - merge dev into flex, resolve conflicts in session/llm.ts and session/prompt.ts
…o flex

# Conflicts:
#	packages/opencode/src/provider/provider.ts
#	packages/opencode/src/provider/transform.ts
- 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.

3 participants