fix(observability): include MCP session ID in access logs
Some checks failed
CI / build-and-test (push) Failing after -32m50s

* Add function to extract MCP session ID from request headers and query parameters
* Update access log to include MCP session ID
fix(cli): simplify project lookup logic
* Refactor project retrieval to prefer GUID lookup when input is a valid UUID
* Introduce separate functions for fetching projects by GUID and name
This commit is contained in:
2026-04-21 23:04:46 +02:00
parent 512b16f8fe
commit 3dfed9c986
5 changed files with 101 additions and 24 deletions

View File

@@ -26,21 +26,42 @@ func (db *DB) CreateProject(ctx context.Context, name, description string) (thou
}
func (db *DB) GetProject(ctx context.Context, nameOrID string) (thoughttypes.Project, error) {
var row pgx.Row
if parsedID, err := uuid.Parse(strings.TrimSpace(nameOrID)); err == nil {
row = db.pool.QueryRow(ctx, `
select guid, name, description, created_at, last_active_at
from projects
where guid = $1
`, parsedID)
} else {
row = db.pool.QueryRow(ctx, `
select guid, name, description, created_at, last_active_at
from projects
where name = $1
`, strings.TrimSpace(nameOrID))
lookup := strings.TrimSpace(nameOrID)
// Prefer guid lookup when input parses as UUID, but fall back to name lookup
// so UUID-shaped project names can still be resolved by name.
if parsedID, err := uuid.Parse(lookup); err == nil {
project, queryErr := db.getProjectByGUID(ctx, parsedID)
if queryErr == nil {
return project, nil
}
if queryErr != pgx.ErrNoRows {
return thoughttypes.Project{}, queryErr
}
}
return db.getProjectByName(ctx, lookup)
}
func (db *DB) getProjectByGUID(ctx context.Context, id uuid.UUID) (thoughttypes.Project, error) {
row := db.pool.QueryRow(ctx, `
select guid, name, description, created_at, last_active_at
from projects
where guid = $1
`, id)
return scanProject(row)
}
func (db *DB) getProjectByName(ctx context.Context, name string) (thoughttypes.Project, error) {
row := db.pool.QueryRow(ctx, `
select guid, name, description, created_at, last_active_at
from projects
where name = $1
`, name)
return scanProject(row)
}
func scanProject(row pgx.Row) (thoughttypes.Project, error) {
var project thoughttypes.Project
if err := row.Scan(&project.ID, &project.Name, &project.Description, &project.CreatedAt, &project.LastActiveAt); err != nil {
if err == pgx.ErrNoRows {