MCPcopy Create free account
hub / github.com/53AI/53AIHub / CurrentMCPAuthInfo

Function CurrentMCPAuthInfo

api/controller/mcp_server.go:107–145  ·  view source on GitHub ↗

CurrentMCPAuthInfo extracts the current authenticated user, enterprise and role.

(ctx context.Context)

Source from the content-addressed store, hash-verified

105
106// CurrentMCPAuthInfo extracts the current authenticated user, enterprise and role.
107func CurrentMCPAuthInfo(ctx context.Context) (userID int64, eid int64, role int64, err error) {
108 tokenInfo := auth.TokenInfoFromContext(ctx)
109 if tokenInfo == nil {
110 return 0, 0, 0, errors.New("missing MCP authentication context")
111 }
112
113 userID, err = CurrentMCPUserID(ctx)
114 if err != nil {
115 return 0, 0, 0, err
116 }
117
118 if tokenInfo.Extra != nil {
119 if v, ok := tokenInfo.Extra["user_eid"]; ok {
120 switch value := v.(type) {
121 case int64:
122 eid = value
123 case int:
124 eid = int64(value)
125 case float64:
126 eid = int64(value)
127 case string:
128 eid, _ = strconv.ParseInt(value, 10, 64)
129 }
130 }
131 if v, ok := tokenInfo.Extra["user_role"]; ok {
132 switch value := v.(type) {
133 case int64:
134 role = value
135 case int:
136 role = int64(value)
137 case float64:
138 role = int64(value)
139 case string:
140 role, _ = strconv.ParseInt(value, 10, 64)
141 }
142 }
143 }
144 return userID, eid, role, nil
145}
146
147// CurrentMCPAPIKeyID extracts the current MCP API key ID from the request context.
148func CurrentMCPAPIKeyID(ctx context.Context) (int64, error) {

Callers 5

registerMCPKeyToolsFunction · 0.85
registerMCPSpaceToolsFunction · 0.85
registerMCPLibraryToolsFunction · 0.85
registerMCPFileToolsFunction · 0.85

Calls 2

CurrentMCPUserIDFunction · 0.85
NewMethod · 0.45

Tested by

no test coverage detected