diff --git a/internal/ghmcp/server.go b/internal/ghmcp/server.go index 7fe526869..612e0d1f7 100644 --- a/internal/ghmcp/server.go +++ b/internal/ghmcp/server.go @@ -416,6 +416,79 @@ func NewUnauthenticatedMCPServer(cfg MCPServerConfig) (*UnauthenticatedServerRes cfg.Logger.Info("auth tools removed after successful authentication") } }, + GetSessionInfo: func(ctx context.Context, token string) string { + // Create a temporary client to fetch user info + apiHost, err := parseAPIHost(cfg.Host) + if err != nil { + return "" + } + + tempClient := gogithub.NewClient(nil).WithAuthToken(token) + tempClient.BaseURL = apiHost.baseRESTURL + + // Build session information text + var sessionInfo strings.Builder + + // Fetch and include user information + if user, _, err := tempClient.Users.Get(ctx, ""); err == nil && user != nil { + sessionInfo.WriteString("## Your GitHub Account\n\n") + sessionInfo.WriteString(fmt.Sprintf("**Username:** @%s\n", user.GetLogin())) + if name := user.GetName(); name != "" { + sessionInfo.WriteString(fmt.Sprintf("**Name:** %s\n", name)) + } + if email := user.GetEmail(); email != "" { + sessionInfo.WriteString(fmt.Sprintf("**Email:** %s\n", email)) + } + if company := user.GetCompany(); company != "" { + sessionInfo.WriteString(fmt.Sprintf("**Company:** %s\n", company)) + } + if location := user.GetLocation(); location != "" { + sessionInfo.WriteString(fmt.Sprintf("**Location:** %s\n", location)) + } + sessionInfo.WriteString(fmt.Sprintf("**Profile:** %s\n", user.GetHTMLURL())) + } + + // Add server configuration + sessionInfo.WriteString("\n## Server Configuration\n\n") + + // Determine effective toolsets + var effectiveToolsets []string + if enabledToolsets == nil { + // nil means defaults - expand them here + effectiveToolsets = github.GetDefaultToolsetIDs() + } else { + effectiveToolsets = enabledToolsets + } + + if len(effectiveToolsets) > 0 { + sessionInfo.WriteString(fmt.Sprintf("**Enabled Toolsets:** %s\n", strings.Join(effectiveToolsets, ", "))) + } + + if len(cfg.EnabledTools) > 0 { + sessionInfo.WriteString(fmt.Sprintf("**Enabled Tools:** %s\n", strings.Join(cfg.EnabledTools, ", "))) + } + + // Configuration flags + var configFlags []string + if cfg.ReadOnly { + configFlags = append(configFlags, "Read-only mode (write operations disabled)") + } + if cfg.LockdownMode { + configFlags = append(configFlags, "Lockdown mode (repository access restricted)") + } + if cfg.DynamicToolsets { + configFlags = append(configFlags, "Dynamic toolsets (can be enabled at runtime)") + } + + if len(configFlags) > 0 { + sessionInfo.WriteString("\n**Configuration:**\n") + for _, flag := range configFlags { + sessionInfo.WriteString(fmt.Sprintf("- %s\n", flag)) + } + } + + return sessionInfo.String() + }, } // Register only auth tools diff --git a/pkg/github/auth_tools.go b/pkg/github/auth_tools.go index 841ef4bc5..24e9ed94b 100644 --- a/pkg/github/auth_tools.go +++ b/pkg/github/auth_tools.go @@ -34,6 +34,9 @@ type AuthToolDependencies struct { // OnAuthComplete is called after authentication flow completes (success or failure). // It can be used to clean up auth tools after they're no longer needed. OnAuthComplete func() + // GetSessionInfo is called after authentication to get session context information + // to include in the auth_login success response. + GetSessionInfo func(ctx context.Context, token string) string } // AuthTools returns the authentication tools. @@ -164,13 +167,16 @@ func pollAndComplete(ctx context.Context, session *mcp.ServerSession, authDeps A authDeps.OnAuthComplete() } - return utils.NewToolResultText(`✅ Successfully authenticated with GitHub! + // Build the success response with session information + successMessage := "✅ Successfully authenticated with GitHub!\n\nAll GitHub tools are now available." -All GitHub tools are now available. You can now: -- Create and manage repositories -- Work with issues and pull requests -- Access your organizations and teams -- And much more, depending on your GitHub configuration + // Get session info if the callback is provided + if authDeps.GetSessionInfo != nil { + sessionInfo := authDeps.GetSessionInfo(ctx, authMgr.Token()) + if sessionInfo != "" { + successMessage += "\n\n" + sessionInfo + } + } -Call get_me to see who you're logged in as.`), nil + return utils.NewToolResultText(successMessage), nil }