Skip to content

Commit 09235a9

Browse files
author
Lasim
committed
Enhance documentation for database connection patterns and MCP endpoint integration, emphasizing best practices for dynamic database access and security improvements in device registration processes.
1 parent c69668a commit 09235a9

3 files changed

Lines changed: 40 additions & 5 deletions

File tree

docs/development/backend/database.mdx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,29 @@ import { drizzle } from 'drizzle-orm/better-sqlite3';
147147
import { drizzle } from 'drizzle-orm/libsql';
148148
```
149149

150+
### Database Connection Patterns
151+
152+
When accessing the database in route handlers, always use `getDb()` to obtain the database connection dynamically:
153+
154+
```typescript
155+
import { getDb } from '../../../db';
156+
import { YourService } from '../../../services/yourService';
157+
158+
export default async function yourRoute(server: FastifyInstance) {
159+
const db = getDb();
160+
const yourService = new YourService(db);
161+
// ... rest of route handler
162+
}
163+
```
164+
165+
**Why this pattern is required:**
166+
- `server.db` may be `null` during certain initialization states
167+
- `getDb()` always returns the active database connection
168+
- This ensures consistent behavior across all endpoints
169+
- Other working endpoints already follow this pattern
170+
171+
**Avoid:** Direct usage of `server.db` as it can cause "Cannot read properties of null" errors.
172+
150173
## Database Structure
151174

152175
The database schema is defined in `src/db/schema.sqlite.ts`. This is the **single source of truth** for all database schema definitions and works across all supported database types.

docs/development/gateway/mcp.mdx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,20 @@ The Gateway implements a sophisticated MCP configuration system that:
2020

2121
## API Integration
2222

23-
### Endpoint
24-
The Gateway fetches MCP installations from:
23+
### Legacy Team-Based Endpoint
24+
The Gateway can fetch MCP installations from the legacy team-based endpoint:
2525
```
2626
GET /api/teams/{teamId}/mcp/installations
2727
```
2828

29+
### Modern Three-Tier Gateway Endpoint
30+
For optimal performance and device-specific configurations, the Gateway uses the modern three-tier endpoint:
31+
```
32+
GET /api/gateway/me/mcp-configurations?hardware_id={hardwareId}
33+
```
34+
35+
This endpoint automatically merges Template + Team + User configurations and returns ready-to-use server configurations with device-specific user arguments and environment variables. For detailed information about this endpoint, see the [Backend API Documentation](/development/backend/api).
36+
2937
### Response Structure
3038
The API returns team MCP installations with this interface:
3139
```typescript

docs/development/gateway/oauth.mdx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,10 @@ During the token exchange process, the gateway automatically registers the curre
8787

8888
**Security Benefits:**
8989
- Device registration happens only during authenticated login sessions
90-
- No separate device registration endpoints (enhanced security)
90+
- **No separate device registration endpoints exist** - this prevents unauthorized device registration and enhances security
9191
- Hardware fingerprinting provides unique device identification
9292
- Enables device management and access control in the backend
93+
- Eliminates the need for manual device registration API calls
9394

9495
**Process Flow:**
9596
1. Gateway detects current device information using system APIs
@@ -289,9 +290,12 @@ When device registration succeeds, the backend includes device information in th
289290

290291
**Security Design:**
291292
- Device registration only occurs during authenticated OAuth2 flows
292-
- No separate device creation endpoints exist (prevents unauthorized device registration)
293-
- Hardware fingerprinting ensures unique device identification
293+
- **No separate device creation endpoints exist** - this architectural decision prevents unauthorized device registration and eliminates potential security vulnerabilities
294+
- Hardware fingerprinting ensures unique device identification across multiple login sessions
294295
- Device information is validated using JSON schema before processing
296+
- Gateway automatically handles device lookup using hardware fingerprints without requiring manual registration
297+
298+
For comprehensive information about device management and hardware fingerprinting, see the [Device Management Documentation](/device-management).
295299

296300
## Security Considerations
297301

0 commit comments

Comments
 (0)