Conversation
Test Coverage ReportOverall Coverage: 93.6%
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Pull request overview
This PR adds a new whoami action to the manage_context tool, enabling AI agents to introspect authentication status, token capabilities, and tool availability. This solves a critical UX problem where agents couldn't understand or communicate why operations fail due to limited token scopes.
Changes:
- Adds comprehensive token introspection with user identity, token info, server config, capabilities breakdown, and actionable recommendations
- Implements
getFilterStats()method in RegistryManager to provide detailed tool filtering statistics - Includes 23 unit tests covering various token scenarios (full access, limited scopes, expired tokens, OAuth mode, read-only mode, tier restrictions)
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/entities/context/schema.ts | Adds WhoamiSchema to discriminated union, updates action count to 8 |
| src/entities/context/types.ts | Defines comprehensive type interfaces for whoami response (WhoamiResult, WhoamiUserInfo, WhoamiTokenInfo, etc.) |
| src/entities/context/whoami.ts | Core implementation with user fetching, token/server info building, capability analysis, and recommendation generation |
| src/entities/context/handlers.ts | Adds handleWhoami dispatcher and updates return type union |
| src/entities/context/registry.ts | Updates tool description to include whoami action |
| src/registry-manager.ts | Adds getFilterStats() method with FilterStats interface to expose tool filtering statistics |
| tests/unit/entities/context/whoami.test.ts | Comprehensive test suite with 23 tests covering multiple scenarios |
…ty discovery Add new `whoami` action to manage_context tool that provides comprehensive information about current authentication status, token capabilities, and available tools. This enables AI agents to understand access limitations and provide actionable guidance to users. Key features: - User identity info (fetched via REST API) - Token info (name, scopes, expiry, validity) - Server config (host, version, tier) - Capabilities summary (available/filtered tools breakdown) - Current context (preset, profile, scope) - Warnings (expiring token, limited scopes, read-only mode) - Recommendations (create token, renew, upgrade tier) Dynamic Token Refresh: - Re-introspects token on each whoami call - Detects permission changes without server restart - Automatically refreshes tool registry when scopes change - Sends tools/list_changed notification to MCP clients - Returns scopesRefreshed=true when tools were updated Implementation: - Add WhoamiSchema to discriminated union schema - Add comprehensive types (WhoamiResult, WhoamiUserInfo, etc.) - New whoami.ts with main logic and token refresh flow - Add refreshTokenScopes() to ConnectionManager - Add getFilterStats() to RegistryManager with FilterStats interface - Integrate sendToolsListChangedNotification for hot-reload - 34 unit tests covering various scenarios Author: Pavel Oliynyk <[email protected]> Closes #203
bc2b08a to
86a307e
Compare
- Replace local isOAuthMode() with shared isOAuthEnabled() - Add tests for ConnectionManager.refreshTokenScopes method - Add isOAuthEnabled mock to whoami tests
- Remove @author tag to follow codebase conventions - Simplify scope assignment using nullish coalescing - Remove unused RuntimeScope import
Set filteredByScopes to 35 to reflect that write_repository scope without api filters most tools requiring GraphQL access.
|
🎉 This PR is included in version 6.46.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add new
whoamiaction tomanage_contexttool that provides comprehensive information about current authentication status, token capabilities, and available tools. This enables AI agents to understand access limitations and provide actionable guidance to users.Key Feature: Dynamic Token Refresh - When called,
whoamire-introspects the token to detect permission changes. If scopes have changed since startup, the tool registry is automatically refreshed and clients receive atools/list_changednotification. No server restart required.Problem
When a user connects with a limited-scope token, the MCP server silently filters tools and the agent has no way to understand why operations fail or how to help the user fix access issues. Additionally, if the user updates their token permissions, they previously had to restart the server.
Solution
The
whoamiaction returns detailed introspection data:Dynamic Token Refresh Flow
Changes
WhoamiSchemato discriminated union inschema.tstypes.ts(WhoamiResult,WhoamiUserInfo,WhoamiTokenInfo, etc.)src/entities/context/whoami.tswith main implementationrefreshTokenScopes()toConnectionManagerfor hot-reloadgetFilterStats()toRegistryManagerfor tool filtering statisticshandlers.tswithhandleWhoami()dispatchersendToolsListChangedNotification()for client updatesExample Response
{ "user": { "id": 123, "username": "developer", "name": "John Developer", "state": "active" }, "token": { "type": "personal_access_token", "name": "gitlab-mcp", "scopes": ["api", "read_user"], "expiresAt": "2025-12-31", "daysUntilExpiry": 340, "isValid": true, "hasGraphQLAccess": true, "hasWriteAccess": true }, "server": { "host": "gitlab.example.com", "version": "17.5.2", "tier": "ultimate", "readOnlyMode": false }, "capabilities": { "canBrowse": true, "canManage": true, "canAccessGraphQL": true, "availableToolCount": 45, "totalToolCount": 45, "filteredByScopes": 0 }, "warnings": [], "recommendations": [], "scopesRefreshed": false }Test plan
yarn lintpasses (0 errors)yarn testpasses (4005 tests)yarn buildsucceedsCloses #203