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

Function CurrentMCPAPIKeyID

api/controller/mcp_server.go:148–172  ·  view source on GitHub ↗

CurrentMCPAPIKeyID extracts the current MCP API key ID from the request context.

(ctx context.Context)

Source from the content-addressed store, hash-verified

146
147// CurrentMCPAPIKeyID extracts the current MCP API key ID from the request context.
148func CurrentMCPAPIKeyID(ctx context.Context) (int64, error) {
149 tokenInfo := auth.TokenInfoFromContext(ctx)
150 if tokenInfo == nil {
151 return 0, errors.New("missing MCP authentication context")
152 }
153 if tokenInfo.Extra == nil {
154 return 0, errors.New("missing MCP authentication context")
155 }
156 v, ok := tokenInfo.Extra["api_key_id"]
157 if !ok {
158 return 0, errors.New("missing MCP api key context")
159 }
160 switch value := v.(type) {
161 case int64:
162 return value, nil
163 case int:
164 return int64(value), nil
165 case float64:
166 return int64(value), nil
167 case string:
168 return strconv.ParseInt(value, 10, 64)
169 default:
170 return 0, errors.New("invalid MCP api key context")
171 }
172}
173
174// AddTypedMCPTool registers a typed MCP tool with the shared server.
175func AddTypedMCPTool[In, Out any](server *MCPServer, tool *mcp.Tool, handler mcp.ToolHandlerFor[In, Out]) {

Callers 1

Calls 1

NewMethod · 0.45

Tested by

no test coverage detected