Skip to content

feat: add MCP token management UI to My Tokens page#617

Open
sap-yuan wants to merge 6 commits into
masterfrom
feat/mcp-token-ui
Open

feat: add MCP token management UI to My Tokens page#617
sap-yuan wants to merge 6 commits into
masterfrom
feat/mcp-token-ui

Conversation

@sap-yuan

Copy link
Copy Markdown
Collaborator

Summary

  • Add MCP token CRUD to UserTokenService.js — 4 new methods wiring up the /api/v1/mcp/tokens/* endpoints added in DIARCHERS-1396: MCP-dedicated API layer with rate limiting, auth, and audit #610
  • Append a MCP Tokens card to the existing /user/tokens page (UserGlobalTokens.vue) — no new route needed
  • Post-create dialog shows the ib_mcp_* token value (shown once) with a INFRABOX_MCP_TOKEN=... usage hint for the MCP client

What users can do after this PR

  1. Open My Tokens in the sidebar
  2. Scroll down to the MCP Tokens section
  3. Create a token with a name and validity period
  4. Copy the ib_mcp_* value and set INFRABOX_MCP_TOKEN in their MCP client config
  5. Toggle trigger permission per-token via a switch
  6. Revoke tokens when no longer needed

Related

Completes the frontend half of DIARCHERS-1396 / #610 (backend MCP API layer).

@sap-yuan sap-yuan self-assigned this Jun 25, 2026

@liuwei08 liuwei08 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two bugs that must be fixed before merge — see inline comments.

},

toggleMcpTrigger (token) {
const newVal = !token.allow_trigger

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: switch visual state and data state can diverge on API failure.

vue-material's md-switch fires its @change handler and flips its visual state before the API call resolves. If setMcpTrigger rejects, token.allow_trigger is never mutated in the .then, but the switch already looks toggled to the user.

Fix — revert the visual state on failure:

toggleMcpTrigger (token) {
    const newVal = !token.allow_trigger
    UserTokenService.setMcpTrigger(token.token_id, newVal)
        .then(() => { token.allow_trigger = newVal })
        .catch(() => {
            // Revert: force Vue to re-render the switch at the original value
            token.allow_trigger = !newVal
        })
}

<pre>$ export INFRABOX_MCP_TOKEN=&lt;TOKEN_VALUE&gt;</pre>
</md-dialog-content>
<md-dialog-actions>
<md-button class="md-primary" @click="$refs['mcpTokenDialog'].close()">OK</md-button>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: previous token value leaks if dialog is reopened.

newMcpToken is never cleared after the dialog closes. If the user creates a second token but this dialog re-renders before fully reinitializing, the previous ib_mcp_* value will briefly be visible.

Fix — clear newMcpToken in the click handler:

<md-button class="md-primary" @click="$refs['mcpTokenDialog'].close(); newMcpToken = ''">OK</md-button>

Or better, wire a dedicated close method so cleanup is explicit and testable:

closeMcpTokenDialog () {
    this.$refs['mcpTokenDialog'].close()
    this.newMcpToken = ''
}

@sap-yuan

Copy link
Copy Markdown
Collaborator Author

Fixed in 902bf9b:

  1. Trigger switch revert on failure — added .catch(() => { token.allow_trigger = !newVal }) to revert visual state if the API call fails
  2. Token value leak on dialog reopen — extracted closeMcpTokenDialog() method that calls .close() and clears newMcpToken = ''; wired the OK button to this method

Yuan Huang added 4 commits June 26, 2026 16:32
- UserTokenService: add loadMcpTokens, createMcpToken, revokeMcpToken,
  setMcpTrigger methods calling /api/v1/mcp/tokens/* endpoints
- UserGlobalTokens.vue: append MCP Tokens card to /user/tokens page
  with create form, token list (name, project scope, expiry, last used,
  trigger toggle), revoke action, and post-create dialog showing the
  ib_mcp_* token value with INFRABOX_MCP_TOKEN usage hint
- createMcpToken form: native checkbox list for project selection
- token list: edit button expands inline scope editor per token
- PATCH /api/v1/mcp/tokens/<id> via new updateMcpToken service method
- NewAPIService: add patch() method
- validation: show error messages on invalid name/days input
@sap-yuan sap-yuan force-pushed the feat/mcp-token-ui branch from 680ae35 to 94d4e0f Compare June 26, 2026 08:33
Yuan Huang added 2 commits June 26, 2026 16:59
- projects.py: empty dict falls through to full collaborator query
- auth.py: check_project_access_mcp treats empty dict as allow-all
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants