@structured-world/gitlab-mcp-db 10.1.0 → 12.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/README.md +8 -8
  2. package/dist/generated/prisma/client.d.ts +2 -0
  3. package/dist/generated/prisma/commonInputTypes.d.ts +178 -9
  4. package/dist/generated/prisma/internal/class.d.ts +6 -0
  5. package/dist/generated/prisma/internal/class.js +6 -6
  6. package/dist/generated/prisma/internal/class.js.map +1 -1
  7. package/dist/generated/prisma/internal/prismaNamespace.d.ts +209 -1
  8. package/dist/generated/prisma/internal/prismaNamespace.js +56 -5
  9. package/dist/generated/prisma/internal/prismaNamespace.js.map +1 -1
  10. package/dist/generated/prisma/models/AccountSettings.d.ts +400 -0
  11. package/dist/generated/prisma/models/AccountSettings.js +3 -0
  12. package/dist/generated/prisma/models/AccountSettings.js.map +1 -0
  13. package/dist/generated/prisma/models/AuthCodeFlowState.d.ts +174 -2
  14. package/dist/generated/prisma/models/DeviceFlowState.d.ts +214 -2
  15. package/dist/generated/prisma/models/OAuthClient.d.ts +577 -0
  16. package/dist/generated/prisma/models/OAuthClient.js +3 -0
  17. package/dist/generated/prisma/models/OAuthClient.js.map +1 -0
  18. package/dist/generated/prisma/models/OAuthSession.d.ts +555 -3
  19. package/dist/generated/prisma/models.d.ts +2 -0
  20. package/dist/src/migrate.d.ts +16 -0
  21. package/dist/src/migrate.js +115 -0
  22. package/dist/src/migrate.js.map +1 -0
  23. package/dist/src/postgresql.d.ts +29 -1
  24. package/dist/src/postgresql.js +580 -86
  25. package/dist/src/postgresql.js.map +1 -1
  26. package/dist/tsconfig.tsbuildinfo +1 -1
  27. package/package.json +12 -6
  28. package/prisma/migrations/0_init/migration.sql +115 -0
  29. package/prisma/migrations/20261008000000_released_schema_columns/migration.sql +15 -0
  30. package/prisma/migrations/20261009000000_oauth_account_linking/migration.sql +47 -0
  31. package/prisma/migrations/20261010000000_account_settings/migration.sql +12 -0
  32. package/prisma/migrations/20261017000000_linked_accounts/migration.sql +15 -0
  33. package/prisma/migrations/migration_lock.toml +3 -0
  34. package/prisma/schema.prisma +66 -0
  35. package/prisma.config.ts +19 -0
@@ -0,0 +1,47 @@
1
+ -- OAuth account linking: resource/scope/instance binding of flows and sessions, the
2
+ -- device flow's client state, poll cadence and issued GitLab tokens, the GitLab refresh
3
+ -- lease, and durable
4
+ -- client registrations.
5
+ -- Additive only: new nullable columns and a new table; existing rows stay valid.
6
+
7
+ -- AlterTable
8
+ ALTER TABLE "oauth_sessions" ADD COLUMN "gitlab_refresh_lease_until" BIGINT,
9
+ ADD COLUMN "resource" TEXT;
10
+
11
+ -- AlterTable
12
+ ALTER TABLE "oauth_device_flows" ADD COLUMN "client_state" TEXT,
13
+ ADD COLUMN "gitlab_tokens" JSONB,
14
+ ADD COLUMN "mcp_scopes" JSONB,
15
+ ADD COLUMN "next_poll_at" BIGINT,
16
+ ADD COLUMN "resource" TEXT,
17
+ ADD COLUMN "selected_instance" TEXT,
18
+ ADD COLUMN "selected_instance_label" TEXT;
19
+
20
+ -- AlterTable
21
+ ALTER TABLE "oauth_auth_code_flows" ADD COLUMN "gitlab_tokens" JSONB,
22
+ ADD COLUMN "mcp_scopes" JSONB,
23
+ ADD COLUMN "resource" TEXT,
24
+ ADD COLUMN "selected_instance" TEXT,
25
+ ADD COLUMN "selected_instance_label" TEXT;
26
+
27
+ -- CreateTable
28
+ CREATE TABLE "oauth_clients" (
29
+ "client_id" TEXT NOT NULL,
30
+ "client_secret" TEXT,
31
+ "redirect_uris" TEXT[],
32
+ "client_name" TEXT,
33
+ "token_endpoint_auth_method" TEXT NOT NULL,
34
+ "grant_types" TEXT[],
35
+ "response_types" TEXT[],
36
+ "created_at" BIGINT NOT NULL,
37
+ "registered_from" TEXT,
38
+ "expires_at" BIGINT,
39
+
40
+ CONSTRAINT "oauth_clients_pkey" PRIMARY KEY ("client_id")
41
+ );
42
+
43
+ -- CreateIndex
44
+ CREATE INDEX "idx_oauth_clients_registered_from" ON "oauth_clients"("registered_from");
45
+
46
+ -- CreateIndex
47
+ CREATE INDEX "idx_oauth_clients_expires_at" ON "oauth_clients"("expires_at");
@@ -0,0 +1,12 @@
1
+ -- Account settings: what an account chose in the settings page or through manage_context,
2
+ -- shared by every replica. Additive only: a new table.
3
+
4
+ -- CreateTable
5
+ CREATE TABLE "oauth_account_settings" (
6
+ "account_key" TEXT NOT NULL,
7
+ "settings" JSONB NOT NULL,
8
+ "version" INTEGER NOT NULL,
9
+ "updated_at" BIGINT NOT NULL,
10
+
11
+ CONSTRAINT "oauth_account_settings_pkey" PRIMARY KEY ("account_key")
12
+ );
@@ -0,0 +1,15 @@
1
+ -- Linked GitLab accounts: a session row can belong to another session, and an
2
+ -- authorization flow can link an account instead of signing a client in.
3
+ -- Additive only: new nullable columns, an index and a foreign key; existing rows stay valid.
4
+
5
+ -- AlterTable
6
+ ALTER TABLE "oauth_sessions" ADD COLUMN "linked_to_session_id" TEXT;
7
+
8
+ -- AlterTable
9
+ ALTER TABLE "oauth_auth_code_flows" ADD COLUMN "link" JSONB;
10
+
11
+ -- CreateIndex
12
+ CREATE INDEX "idx_oauth_sessions_linked_to_session_id" ON "oauth_sessions"("linked_to_session_id");
13
+
14
+ -- AddForeignKey
15
+ ALTER TABLE "oauth_sessions" ADD CONSTRAINT "oauth_sessions_linked_to_session_id_fkey" FOREIGN KEY ("linked_to_session_id") REFERENCES "oauth_sessions"("id") ON DELETE CASCADE ON UPDATE CASCADE;
@@ -0,0 +1,3 @@
1
+ # Please do not edit this file manually
2
+ # It should be added in your version-control system (e.g., Git)
3
+ provider = "postgresql"
@@ -23,6 +23,10 @@ model OAuthSession {
23
23
  gitlabAccessToken String @map("gitlab_access_token")
24
24
  gitlabRefreshToken String @map("gitlab_refresh_token")
25
25
  gitlabTokenExpiry BigInt @map("gitlab_token_expiry")
26
+ // Null means the upstream grant was not reported; [] means no grants.
27
+ gitlabScopes Json? @map("gitlab_scopes")
28
+ // End of the lease of the replica refreshing the single-use GitLab refresh token.
29
+ gitlabRefreshLeaseUntil BigInt? @map("gitlab_refresh_lease_until")
26
30
 
27
31
  // User info from GitLab
28
32
  gitlabUserId Int @map("gitlab_user_id")
@@ -35,17 +39,24 @@ model OAuthSession {
35
39
  // Session metadata
36
40
  clientId String @map("client_id")
37
41
  scopes String[] @default([])
42
+ // RFC 8707 resource the session's tokens are issued for; null for older sessions.
43
+ resource String?
44
+ // Set on a GitLab account linked to another session; removed with that session.
45
+ linkedToSessionId String? @map("linked_to_session_id")
38
46
  createdAt BigInt @map("created_at")
39
47
  updatedAt BigInt @map("updated_at")
40
48
 
41
49
  // Relations
42
50
  authorizationCodes AuthorizationCode[]
43
51
  mcpSessionMappings McpSessionMapping[]
52
+ linkedTo OAuthSession? @relation("LinkedAccounts", fields: [linkedToSessionId], references: [id], onDelete: Cascade)
53
+ linkedAccounts OAuthSession[] @relation("LinkedAccounts")
44
54
 
45
55
  @@map("oauth_sessions")
46
56
  @@index([mcpAccessToken], map: "idx_oauth_sessions_mcp_access_token")
47
57
  @@index([mcpRefreshToken], map: "idx_oauth_sessions_mcp_refresh_token")
48
58
  @@index([gitlabUserId], map: "idx_oauth_sessions_gitlab_user_id")
59
+ @@index([linkedToSessionId], map: "idx_oauth_sessions_linked_to_session_id")
49
60
  }
50
61
 
51
62
  // State for tracking in-progress Device Flow authorization
@@ -61,6 +72,19 @@ model DeviceFlowState {
61
72
  codeChallenge String @map("code_challenge")
62
73
  codeChallengeMethod String @map("code_challenge_method")
63
74
  redirectUri String? @map("redirect_uri")
75
+ // The original GitLab grant request, retained across polling on another replica.
76
+ requestedGitlabScopes Json? @map("requested_gitlab_scopes")
77
+ // The client's own state value; `state` above is the storage key.
78
+ clientState String? @map("client_state")
79
+ // Earliest next GitLab poll (RFC 8628 3.5), shared by all replicas.
80
+ nextPollAt BigInt? @map("next_poll_at")
81
+ selectedInstance String? @map("selected_instance")
82
+ selectedInstanceLabel String? @map("selected_instance_label")
83
+ // MCP scopes granted at /authorize; null means the full default set.
84
+ mcpScopes Json? @map("mcp_scopes")
85
+ resource String?
86
+ // Tokens GitLab issued on approval, kept until the account is set up.
87
+ gitlabTokens Json? @map("gitlab_tokens")
64
88
 
65
89
  @@map("oauth_device_flows")
66
90
  @@index([deviceCode], map: "idx_oauth_device_flows_device_code")
@@ -77,6 +101,17 @@ model AuthCodeFlowState {
77
101
  clientRedirectUri String @map("client_redirect_uri")
78
102
  callbackUri String @map("callback_uri")
79
103
  expiresAt BigInt @map("expires_at")
104
+ // OAuth §5.1 lets the token response omit scope when this grant is unchanged.
105
+ requestedGitlabScopes Json? @map("requested_gitlab_scopes")
106
+ selectedInstance String? @map("selected_instance")
107
+ selectedInstanceLabel String? @map("selected_instance_label")
108
+ // MCP scopes granted at /authorize; null means the full default set.
109
+ mcpScopes Json? @map("mcp_scopes")
110
+ resource String?
111
+ // Tokens GitLab issued for the callback's code, kept until the account is set up.
112
+ gitlabTokens Json? @map("gitlab_tokens")
113
+ // Set when the flow links another account to a session (session, stage, instance).
114
+ link Json?
80
115
 
81
116
  @@map("oauth_auth_code_flows")
82
117
  @@index([expiresAt], map: "idx_oauth_auth_code_flows_expires_at")
@@ -100,6 +135,37 @@ model AuthorizationCode {
100
135
  @@index([expiresAt], map: "idx_oauth_authorization_codes_expires_at")
101
136
  }
102
137
 
138
+ // OAuth client registered through Dynamic Client Registration (RFC 7591)
139
+ model OAuthClient {
140
+ clientId String @id @map("client_id")
141
+ clientSecret String? @map("client_secret")
142
+ redirectUris String[] @map("redirect_uris")
143
+ clientName String? @map("client_name")
144
+ tokenEndpointAuthMethod String @map("token_endpoint_auth_method")
145
+ grantTypes String[] @map("grant_types")
146
+ responseTypes String[] @map("response_types")
147
+ createdAt BigInt @map("created_at")
148
+ // Keyed hash of the registering address; never-used registrations are capped per source
149
+ registeredFrom String? @map("registered_from")
150
+ // Removal time of a registration that never completed an authorization
151
+ expiresAt BigInt? @map("expires_at")
152
+
153
+ @@map("oauth_clients")
154
+ @@index([registeredFrom], map: "idx_oauth_clients_registered_from")
155
+ @@index([expiresAt], map: "idx_oauth_clients_expires_at")
156
+ }
157
+
158
+ // Settings an account keeps across its sessions and restarts
159
+ model AccountSettings {
160
+ accountKey String @id @map("account_key")
161
+ settings Json
162
+ // Grows with every write; writes are compare-and-set on it.
163
+ version Int
164
+ updatedAt BigInt @map("updated_at")
165
+
166
+ @@map("oauth_account_settings")
167
+ }
168
+
103
169
  // MCP session to OAuth session mapping
104
170
  model McpSessionMapping {
105
171
  mcpSessionId String @id @map("mcp_session_id")
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Prisma Configuration for gitlab-mcp OAuth Storage
3
+ *
4
+ * Uses OAUTH_STORAGE_POSTGRESQL_URL environment variable.
5
+ * If not set, Prisma client will not be initialized.
6
+ */
7
+ import "dotenv/config";
8
+ import { defineConfig } from "prisma/config";
9
+
10
+ export default defineConfig({
11
+ schema: "prisma/schema.prisma",
12
+ migrations: {
13
+ path: "prisma/migrations",
14
+ },
15
+ datasource: {
16
+ // Use our consistent env variable naming
17
+ url: process.env["OAUTH_STORAGE_POSTGRESQL_URL"] ?? process.env["DATABASE_URL"],
18
+ },
19
+ });