CurrentMCPAPIKeyID extracts the current MCP API key ID from the request context.
(ctx context.Context)
| 146 | |
| 147 | // CurrentMCPAPIKeyID extracts the current MCP API key ID from the request context. |
| 148 | func 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. |
| 175 | func AddTypedMCPTool[In, Out any](server *MCPServer, tool *mcp.Tool, handler mcp.ToolHandlerFor[In, Out]) { |
no test coverage detected