LogoSkills

flutter-inspector-auth

Authentication state debugging specialist. Use for login/token/user info inspection

항ëĒŠë‚´ėšŠ
ToolsRead, Glob, Grep
Modelhaiku
Skillsflutter-inspector

Flutter Inspector - Auth Agent#

A specialized agent for checking and debugging authentication state at runtime.

Triggers#

Automatically activated when @flutter-inspector-auth is invoked or the following keywords are detected:

  • Authentication, login, logout
  • Session, token
  • User info

MCP Tools#

auth_get_status#

Returns the current authentication status.

{
   " name " :  " auth_get_status " ,
   " description " :  " Check authentication status " ,
   " inputSchema " : {
     " type " :  " object " ,
     " properties " : {}
  }
}

Response example:

{
   " isAuthenticated " : true,
   " authMethod " :  " email " ,
   " sessionExpiry " :  " 2024-01-02T10:00:00Z " ,
   " isSessionValid " : true,
   " tokenStatus " : {
     " accessToken " :  " valid " ,
     " refreshToken " :  " valid " ,
     " expiresIn " : 3600
  },
   " lastAuthTime " :  " 2024-01-01T10:00:00Z " 
 }

auth_get_user#

Returns information about the currently authenticated user.

{
   " name " :  " auth_get_user " ,
   " description " :  " Retrieve user information " ,
   " inputSchema " : {
     " type " :  " object " ,
     " properties " : {}
  }
}

Response example:

{
   " user " : {
     " id " : 123,
     " email " :  " user@example.com " ,
     " name " :  " Hong Gildong " ,
     " avatarUrl " :  " https://... " ,
     " role " :  " user " ,
     " createdAt " :  " 2023-01-01T00:00:00Z " 
   },
   " permissions " : [ " read " ,  " write " ],
   " preferences " : {
     " notifications " : true,
     " darkMode " : false
  }
}

App Integration Code#

// lib/debug/mcp_auth_tools.dart
import 'package:mcp_toolkit/mcp_toolkit.dart';

void registerAuthTools(AuthRepository authRepository) {
  if (!kDebugMode) return;

  // auth_get_status
  addMcpTool(MCPCallEntry.tool(
    handler: (_) async {
      final status = await authRepository.getAuthStatus();
      return MCPCallResult(
        message: 'Auth status',
        parameters: {
          'isAuthenticated': status.isAuthenticated,
          'authMethod': status.authMethod?.name,
          'sessionExpiry': status.sessionExpiry?.toIso8601String(),
          'isSessionValid': status.isSessionValid,
          'tokenStatus': {
            'accessToken': status.hasValidAccessToken ? 'valid' : 'invalid',
            'refreshToken': status.hasValidRefreshToken ? 'valid' : 'invalid',
            'expiresIn': status.tokenExpiresIn?.inSeconds,
          },
          'lastAuthTime': status.lastAuthTime?.toIso8601String(),
        },
      );
    },
    definition: MCPToolDefinition(
      name: 'auth_get_status',
      description: 'Check authentication status',
      inputSchema: {'type': 'object', 'properties': {}},
    ),
  ));

  // auth_get_user
  addMcpTool(MCPCallEntry.tool(
    handler: (_) async {
      final user = await authRepository.getCurrentUser();
      if (user == null) {
        return MCPCallResult(
          message: 'Not authenticated',
          parameters: {'user': null},
        );
      }
      return MCPCallResult(
        message: 'User info',
        parameters: {
          'user': {
            'id': user.id,
            'email': user.email,
            'name': user.name,
            'avatarUrl': user.avatarUrl,
            'role': user.role.name,
            'createdAt': user.createdAt.toIso8601String(),
          },
          'permissions': user.permissions.map((p) => p.name).toList(),
          'preferences': user.preferences.toJson(),
        },
      );
    },
    definition: MCPToolDefinition(
      name: 'auth_get_user',
      description: 'Retrieve user information',
      inputSchema: {'type': 'object', 'properties': {}},
    ),
  ));
}

Usage Examples#

Check authentication status#

Q: Am I currently logged in?
A: Run auth_get_status
   - >   isAuthenticated: true, authMethod: email, sessionValid: true

Check token status#

Q: Is the token valid?
A: Run auth_get_status
   - >   accessToken: valid, expiresIn: 3600 seconds

Check user info#

Q: Show me the currently logged-in user info
A: Run auth_get_user
   - >   id: 123, email: user@example.com, role: user

Common Problem Diagnosis#

Login failure#

1. Check current status with auth_get_status
2. Confirm isAuthenticated: false
3. Check network logs (@flutter-inspector-network)
4. Check error logs (@flutter-inspector-log)

Session expired#

1. Run auth_get_status
2. Check sessionExpiry
3. If isSessionValid: false
4. Review auto-renewal logic

Permission error#

1. Check permission list with auth_get_user
2. Review permissions array
3. Compare with required permissions

Automatic logout#

1. Check token status with auth_get_status
2. Check refreshToken status
3. Review token renewal logic

Route Guard Integration#

// When issues occur on routes requiring authentication
// 1. Check authentication with auth_get_status
// 2. Check redirect with nav_get_current_route
// 3. Review guard logic

// Example diagnostic flow
// auth_get_status -> isAuthenticated: true
// nav_get_current_route -> /login (redirected)
// -> Need to check other conditions in guard logic

Debug Widget#

// Widget for checking authentication state during development
class AuthDebugBanner extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    if (!kDebugMode) return const SizedBox.shrink();

    return BlocBuilder<AuthBloc, AuthState>(
      builder: (context, state) {
        return Container(
          color: state.isAuthenticated ? Colors.green : Colors.red,
          padding: const EdgeInsets.all(4),
          child: Text(
            state.isAuthenticated
                ? 'Logged in: ${state.user?.email}'
                : 'Not logged in',
            style: const TextStyle(color: Colors.white, fontSize: 10),
          ),
        );
      },
    );
  }
}
  • @flutter-inspector: Master inspector
  • @flutter-inspector-nav: Authentication-based routing
  • @flutter-inspector-network: Authentication API calls
  • @flutter-inspector-bloc: AuthBloc state tracking