@supabase/mcp-server-supabase 0.3.6 → 0.4.0-alpha.1
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.
- package/dist/chunk-3UPSHB6J.js +296 -0
- package/dist/chunk-3UPSHB6J.js.map +1 -0
- package/dist/chunk-ZNWTP32U.cjs +296 -0
- package/dist/chunk-ZNWTP32U.cjs.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +7 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +1 -1
- package/dist/stdio.cjs +1 -1
- package/dist/stdio.cjs.map +1 -1
- package/dist/stdio.js +1 -1
- package/dist/stdio.js.map +1 -1
- package/package.json +2 -2
- package/dist/chunk-M3JU5DW7.cjs +0 -295
- package/dist/chunk-M3JU5DW7.cjs.map +0 -1
- package/dist/chunk-ZOKJ3UPH.js +0 -295
- package/dist/chunk-ZOKJ3UPH.js.map +0 -1
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
var L={name:"@supabase/mcp-server-supabase",version:"0.4.0-alpha.1",description:"MCP server for interacting with Supabase",license:"Apache-2.0",type:"module",main:"dist/index.cjs",types:"dist/index.d.ts",sideEffects:!1,scripts:{build:"tsup --clean",prepublishOnly:"npm run build",test:"vitest","test:e2e":"vitest --project e2e","test:unit":"vitest --project unit","generate:management-api-types":"openapi-typescript https://api.supabase.com/api/v1-json -o ./src/management-api/types.ts"},files:["dist/**/*"],bin:{"mcp-server-supabase":"./dist/stdio.js"},exports:{".":{import:"./dist/index.js",types:"./dist/index.d.ts",default:"./dist/index.cjs"}},dependencies:{"@deno/eszip":"^0.84.0","@modelcontextprotocol/sdk":"^1.4.1","@supabase/mcp-utils":"0.2.0","common-tags":"^1.8.2","openapi-fetch":"^0.13.5",zod:"^3.24.1"},devDependencies:{"@ai-sdk/anthropic":"^1.2.9","@electric-sql/pglite":"^0.2.17","@total-typescript/tsconfig":"^1.0.4","@types/common-tags":"^1.8.4","@types/node":"^22.8.6",ai:"^4.3.4","date-fns":"^4.1.0",dotenv:"^16.5.0",msw:"^2.7.3",nanoid:"^5.1.5","openapi-typescript":"^7.5.0","openapi-typescript-helpers":"^0.0.15",prettier:"^3.3.3",tsup:"^8.3.5",tsx:"^4.19.2",typescript:"^5.6.3",vitest:"^2.1.9"}};import{createMcpServer as Le}from"@supabase/mcp-utils";import pe from"openapi-fetch";import{z as F}from"zod";function D(e,o,t={}){return pe({baseUrl:e,headers:{Authorization:`Bearer ${o}`,...t}})}var ge=F.object({message:F.string()});function i(e,o){if("error"in e){if(e.response.status===401)throw new Error("Unauthorized. Please provide a valid access token to the MCP server via the --access-token flag or SUPABASE_ACCESS_TOKEN.");let{data:t}=ge.safeParse(e.error);throw t?new Error(t.message):new Error(o)}}import{tool as O}from"@supabase/mcp-utils";import{z as m}from"zod";var de=10,me=.01344;async function R(e,o){let t=await e.GET("/v1/organizations/{slug}",{params:{path:{slug:o}}});i(t,"Failed to fetch organization");let n=await e.GET("/v1/projects");i(n,"Failed to fetch projects");let a=t.data,r=n.data.filter(l=>l.organization_id===o&&!["INACTIVE","GOING_DOWN","REMOVED"].includes(l.status)),s=0;return a.plan!=="free"&&r.length>0&&(s=de),{type:"project",recurrence:"monthly",amount:s}}function w(){return{type:"branch",recurrence:"hourly",amount:me}}function P(e){return Object.fromEntries(e.split(`
|
|
2
|
+
`).map(o=>o.split(/=(.*)/)).filter(([o])=>o).map(([o,t])=>[o,t??""]))}async function j(e,o){let t=JSON.stringify(e,(r,s)=>s&&typeof s=="object"&&!Array.isArray(s)?Object.keys(s).sort().reduce((l,c)=>(l[c]=s[c],l),{}):s),n=await crypto.subtle.digest("SHA-256",new TextEncoder().encode(t));return btoa(String.fromCharCode(...new Uint8Array(n))).slice(0,o)}import{tool as U}from"@supabase/mcp-utils";import"zod";function g({description:e,parameters:o,inject:t,execute:n}){if(!t||Object.values(t).every(r=>r===void 0))return U({description:e,parameters:o,execute:n});let a=Object.fromEntries(Object.entries(t).filter(([r,s])=>s!==void 0).map(([r])=>[r,!0]));return U({description:e,parameters:o.omit(a),execute:r=>n({...r,...t})})}function k({managementApiClient:e,projectId:o}){let t=o;return{create_branch:g({description:"Creates a development branch on a Supabase project. This will apply all migrations from the main project to a fresh branch database. Note that production data will not carry over. The branch will get its own project_id via the resulting project_ref. Use this ID to execute queries and migrations on the branch.",parameters:m.object({project_id:m.string(),name:m.string().default("develop").describe("Name of the branch to create"),confirm_cost_id:m.string({required_error:"User must confirm understanding of costs before creating a branch."}).describe("The cost confirmation ID. Call `confirm_cost` first.")}),inject:{project_id:t},execute:async({project_id:n,name:a,confirm_cost_id:r})=>{let s=w();if(await j(s)!==r)throw new Error("Cost confirmation ID does not match the expected cost of creating a branch.");let c=await e.POST("/v1/projects/{ref}/branches",{params:{path:{ref:n}},body:{branch_name:a}});if(i(c,"Failed to create branch"),c.data.is_default){await e.PATCH("/v1/branches/{branch_id}",{params:{path:{branch_id:c.data.id}},body:{branch_name:"main"}});let d=await e.POST("/v1/projects/{ref}/branches",{params:{path:{ref:n}},body:{branch_name:a}});return i(d,"Failed to create branch"),d.data}return c.data}}),list_branches:g({description:"Lists all development branches of a Supabase project. This will return branch details including status which you can use to check when operations like merge/rebase/reset complete.",parameters:m.object({project_id:m.string()}),inject:{project_id:t},execute:async({project_id:n})=>{let a=await e.GET("/v1/projects/{ref}/branches",{params:{path:{ref:n}}});return a.response.status===422?[]:(i(a,"Failed to list branches"),a.data)}}),delete_branch:O({description:"Deletes a development branch.",parameters:m.object({branch_id:m.string()}),execute:async({branch_id:n})=>{let a=await e.DELETE("/v1/branches/{branch_id}",{params:{path:{branch_id:n}}});return i(a,"Failed to delete branch"),a.data}}),merge_branch:O({description:"Merges migrations and edge functions from a development branch to production.",parameters:m.object({branch_id:m.string()}),execute:async({branch_id:n})=>{let a=await e.POST("/v1/branches/{branch_id}/merge",{params:{path:{branch_id:n}},body:{}});return i(a,"Failed to merge branch"),a.data}}),reset_branch:O({description:"Resets migrations of a development branch. Any untracked data or schema changes will be lost.",parameters:m.object({branch_id:m.string(),migration_version:m.string().optional().describe("Reset your development branch to a specific migration version.")}),execute:async({branch_id:n,migration_version:a})=>{let r=await e.POST("/v1/branches/{branch_id}/reset",{params:{path:{branch_id:n}},body:{migration_version:a}});return i(r,"Failed to reset branch"),r.data}}),rebase_branch:O({description:"Rebases a development branch on production. This will effectively run any newer migrations from production onto this branch to help handle migration drift.",parameters:m.object({branch_id:m.string()}),execute:async({branch_id:n})=>{let a=await e.POST("/v1/branches/{branch_id}/push",{params:{path:{branch_id:n}},body:{}});return i(a,"Failed to rebase branch"),a.data}})}}import{z as u}from"zod";import{stripIndent as B}from"common-tags";var H=`-- Adapted from information_schema.columns
|
|
3
|
+
|
|
4
|
+
SELECT
|
|
5
|
+
c.oid :: int8 AS table_id,
|
|
6
|
+
nc.nspname AS schema,
|
|
7
|
+
c.relname AS table,
|
|
8
|
+
(c.oid || '.' || a.attnum) AS id,
|
|
9
|
+
a.attnum AS ordinal_position,
|
|
10
|
+
a.attname AS name,
|
|
11
|
+
CASE
|
|
12
|
+
WHEN a.atthasdef THEN pg_get_expr(ad.adbin, ad.adrelid)
|
|
13
|
+
ELSE NULL
|
|
14
|
+
END AS default_value,
|
|
15
|
+
CASE
|
|
16
|
+
WHEN t.typtype = 'd' THEN CASE
|
|
17
|
+
WHEN bt.typelem <> 0 :: oid
|
|
18
|
+
AND bt.typlen = -1 THEN 'ARRAY'
|
|
19
|
+
WHEN nbt.nspname = 'pg_catalog' THEN format_type(t.typbasetype, NULL)
|
|
20
|
+
ELSE 'USER-DEFINED'
|
|
21
|
+
END
|
|
22
|
+
ELSE CASE
|
|
23
|
+
WHEN t.typelem <> 0 :: oid
|
|
24
|
+
AND t.typlen = -1 THEN 'ARRAY'
|
|
25
|
+
WHEN nt.nspname = 'pg_catalog' THEN format_type(a.atttypid, NULL)
|
|
26
|
+
ELSE 'USER-DEFINED'
|
|
27
|
+
END
|
|
28
|
+
END AS data_type,
|
|
29
|
+
COALESCE(bt.typname, t.typname) AS format,
|
|
30
|
+
a.attidentity IN ('a', 'd') AS is_identity,
|
|
31
|
+
CASE
|
|
32
|
+
a.attidentity
|
|
33
|
+
WHEN 'a' THEN 'ALWAYS'
|
|
34
|
+
WHEN 'd' THEN 'BY DEFAULT'
|
|
35
|
+
ELSE NULL
|
|
36
|
+
END AS identity_generation,
|
|
37
|
+
a.attgenerated IN ('s') AS is_generated,
|
|
38
|
+
NOT (
|
|
39
|
+
a.attnotnull
|
|
40
|
+
OR t.typtype = 'd' AND t.typnotnull
|
|
41
|
+
) AS is_nullable,
|
|
42
|
+
(
|
|
43
|
+
c.relkind IN ('r', 'p')
|
|
44
|
+
OR c.relkind IN ('v', 'f') AND pg_column_is_updatable(c.oid, a.attnum, FALSE)
|
|
45
|
+
) AS is_updatable,
|
|
46
|
+
uniques.table_id IS NOT NULL AS is_unique,
|
|
47
|
+
check_constraints.definition AS "check",
|
|
48
|
+
array_to_json(
|
|
49
|
+
array(
|
|
50
|
+
SELECT
|
|
51
|
+
enumlabel
|
|
52
|
+
FROM
|
|
53
|
+
pg_catalog.pg_enum enums
|
|
54
|
+
WHERE
|
|
55
|
+
enums.enumtypid = coalesce(bt.oid, t.oid)
|
|
56
|
+
OR enums.enumtypid = coalesce(bt.typelem, t.typelem)
|
|
57
|
+
ORDER BY
|
|
58
|
+
enums.enumsortorder
|
|
59
|
+
)
|
|
60
|
+
) AS enums,
|
|
61
|
+
col_description(c.oid, a.attnum) AS comment
|
|
62
|
+
FROM
|
|
63
|
+
pg_attribute a
|
|
64
|
+
LEFT JOIN pg_attrdef ad ON a.attrelid = ad.adrelid
|
|
65
|
+
AND a.attnum = ad.adnum
|
|
66
|
+
JOIN (
|
|
67
|
+
pg_class c
|
|
68
|
+
JOIN pg_namespace nc ON c.relnamespace = nc.oid
|
|
69
|
+
) ON a.attrelid = c.oid
|
|
70
|
+
JOIN (
|
|
71
|
+
pg_type t
|
|
72
|
+
JOIN pg_namespace nt ON t.typnamespace = nt.oid
|
|
73
|
+
) ON a.atttypid = t.oid
|
|
74
|
+
LEFT JOIN (
|
|
75
|
+
pg_type bt
|
|
76
|
+
JOIN pg_namespace nbt ON bt.typnamespace = nbt.oid
|
|
77
|
+
) ON t.typtype = 'd'
|
|
78
|
+
AND t.typbasetype = bt.oid
|
|
79
|
+
LEFT JOIN (
|
|
80
|
+
SELECT DISTINCT ON (table_id, ordinal_position)
|
|
81
|
+
conrelid AS table_id,
|
|
82
|
+
conkey[1] AS ordinal_position
|
|
83
|
+
FROM pg_catalog.pg_constraint
|
|
84
|
+
WHERE contype = 'u' AND cardinality(conkey) = 1
|
|
85
|
+
) AS uniques ON uniques.table_id = c.oid AND uniques.ordinal_position = a.attnum
|
|
86
|
+
LEFT JOIN (
|
|
87
|
+
-- We only select the first column check
|
|
88
|
+
SELECT DISTINCT ON (table_id, ordinal_position)
|
|
89
|
+
conrelid AS table_id,
|
|
90
|
+
conkey[1] AS ordinal_position,
|
|
91
|
+
substring(
|
|
92
|
+
pg_get_constraintdef(pg_constraint.oid, true),
|
|
93
|
+
8,
|
|
94
|
+
length(pg_get_constraintdef(pg_constraint.oid, true)) - 8
|
|
95
|
+
) AS "definition"
|
|
96
|
+
FROM pg_constraint
|
|
97
|
+
WHERE contype = 'c' AND cardinality(conkey) = 1
|
|
98
|
+
ORDER BY table_id, ordinal_position, oid asc
|
|
99
|
+
) AS check_constraints ON check_constraints.table_id = c.oid AND check_constraints.ordinal_position = a.attnum
|
|
100
|
+
WHERE
|
|
101
|
+
NOT pg_is_other_temp_schema(nc.oid)
|
|
102
|
+
AND a.attnum > 0
|
|
103
|
+
AND NOT a.attisdropped
|
|
104
|
+
AND (c.relkind IN ('r', 'v', 'm', 'f', 'p'))
|
|
105
|
+
AND (
|
|
106
|
+
pg_has_role(c.relowner, 'USAGE')
|
|
107
|
+
OR has_column_privilege(
|
|
108
|
+
c.oid,
|
|
109
|
+
a.attnum,
|
|
110
|
+
'SELECT, INSERT, UPDATE, REFERENCES'
|
|
111
|
+
)
|
|
112
|
+
)
|
|
113
|
+
`;var G=`SELECT
|
|
114
|
+
e.name,
|
|
115
|
+
n.nspname AS schema,
|
|
116
|
+
e.default_version,
|
|
117
|
+
x.extversion AS installed_version,
|
|
118
|
+
e.comment
|
|
119
|
+
FROM
|
|
120
|
+
pg_available_extensions() e(name, default_version, comment)
|
|
121
|
+
LEFT JOIN pg_extension x ON e.name = x.extname
|
|
122
|
+
LEFT JOIN pg_namespace n ON x.extnamespace = n.oid
|
|
123
|
+
`;var z=`SELECT
|
|
124
|
+
c.oid :: int8 AS id,
|
|
125
|
+
nc.nspname AS schema,
|
|
126
|
+
c.relname AS name,
|
|
127
|
+
c.relrowsecurity AS rls_enabled,
|
|
128
|
+
c.relforcerowsecurity AS rls_forced,
|
|
129
|
+
CASE
|
|
130
|
+
WHEN c.relreplident = 'd' THEN 'DEFAULT'
|
|
131
|
+
WHEN c.relreplident = 'i' THEN 'INDEX'
|
|
132
|
+
WHEN c.relreplident = 'f' THEN 'FULL'
|
|
133
|
+
ELSE 'NOTHING'
|
|
134
|
+
END AS replica_identity,
|
|
135
|
+
pg_total_relation_size(format('%I.%I', nc.nspname, c.relname)) :: int8 AS bytes,
|
|
136
|
+
pg_size_pretty(
|
|
137
|
+
pg_total_relation_size(format('%I.%I', nc.nspname, c.relname))
|
|
138
|
+
) AS size,
|
|
139
|
+
pg_stat_get_live_tuples(c.oid) AS live_rows_estimate,
|
|
140
|
+
pg_stat_get_dead_tuples(c.oid) AS dead_rows_estimate,
|
|
141
|
+
obj_description(c.oid) AS comment,
|
|
142
|
+
coalesce(pk.primary_keys, '[]') as primary_keys,
|
|
143
|
+
coalesce(
|
|
144
|
+
jsonb_agg(relationships) filter (where relationships is not null),
|
|
145
|
+
'[]'
|
|
146
|
+
) as relationships
|
|
147
|
+
FROM
|
|
148
|
+
pg_namespace nc
|
|
149
|
+
JOIN pg_class c ON nc.oid = c.relnamespace
|
|
150
|
+
left join (
|
|
151
|
+
select
|
|
152
|
+
table_id,
|
|
153
|
+
jsonb_agg(_pk.*) as primary_keys
|
|
154
|
+
from (
|
|
155
|
+
select
|
|
156
|
+
n.nspname as schema,
|
|
157
|
+
c.relname as table_name,
|
|
158
|
+
a.attname as name,
|
|
159
|
+
c.oid :: int8 as table_id
|
|
160
|
+
from
|
|
161
|
+
pg_index i,
|
|
162
|
+
pg_class c,
|
|
163
|
+
pg_attribute a,
|
|
164
|
+
pg_namespace n
|
|
165
|
+
where
|
|
166
|
+
i.indrelid = c.oid
|
|
167
|
+
and c.relnamespace = n.oid
|
|
168
|
+
and a.attrelid = c.oid
|
|
169
|
+
and a.attnum = any (i.indkey)
|
|
170
|
+
and i.indisprimary
|
|
171
|
+
) as _pk
|
|
172
|
+
group by table_id
|
|
173
|
+
) as pk
|
|
174
|
+
on pk.table_id = c.oid
|
|
175
|
+
left join (
|
|
176
|
+
select
|
|
177
|
+
c.oid :: int8 as id,
|
|
178
|
+
c.conname as constraint_name,
|
|
179
|
+
nsa.nspname as source_schema,
|
|
180
|
+
csa.relname as source_table_name,
|
|
181
|
+
sa.attname as source_column_name,
|
|
182
|
+
nta.nspname as target_table_schema,
|
|
183
|
+
cta.relname as target_table_name,
|
|
184
|
+
ta.attname as target_column_name
|
|
185
|
+
from
|
|
186
|
+
pg_constraint c
|
|
187
|
+
join (
|
|
188
|
+
pg_attribute sa
|
|
189
|
+
join pg_class csa on sa.attrelid = csa.oid
|
|
190
|
+
join pg_namespace nsa on csa.relnamespace = nsa.oid
|
|
191
|
+
) on sa.attrelid = c.conrelid and sa.attnum = any (c.conkey)
|
|
192
|
+
join (
|
|
193
|
+
pg_attribute ta
|
|
194
|
+
join pg_class cta on ta.attrelid = cta.oid
|
|
195
|
+
join pg_namespace nta on cta.relnamespace = nta.oid
|
|
196
|
+
) on ta.attrelid = c.confrelid and ta.attnum = any (c.confkey)
|
|
197
|
+
where
|
|
198
|
+
c.contype = 'f'
|
|
199
|
+
) as relationships
|
|
200
|
+
on (relationships.source_schema = nc.nspname and relationships.source_table_name = c.relname)
|
|
201
|
+
or (relationships.target_table_schema = nc.nspname and relationships.target_table_name = c.relname)
|
|
202
|
+
WHERE
|
|
203
|
+
c.relkind IN ('r', 'p')
|
|
204
|
+
AND NOT pg_is_other_temp_schema(nc.oid)
|
|
205
|
+
AND (
|
|
206
|
+
pg_has_role(c.relowner, 'USAGE')
|
|
207
|
+
OR has_table_privilege(
|
|
208
|
+
c.oid,
|
|
209
|
+
'SELECT, INSERT, UPDATE, DELETE, TRUNCATE, REFERENCES, TRIGGER'
|
|
210
|
+
)
|
|
211
|
+
OR has_any_column_privilege(c.oid, 'SELECT, INSERT, UPDATE, REFERENCES')
|
|
212
|
+
)
|
|
213
|
+
group by
|
|
214
|
+
c.oid,
|
|
215
|
+
c.relname,
|
|
216
|
+
c.relrowsecurity,
|
|
217
|
+
c.relforcerowsecurity,
|
|
218
|
+
c.relreplident,
|
|
219
|
+
nc.nspname,
|
|
220
|
+
pk.primary_keys
|
|
221
|
+
`;var ye=["information_schema","pg_catalog","pg_toast","_timescaledb_internal"];function W(e=[]){let o=B`
|
|
222
|
+
with
|
|
223
|
+
tables as (${z}),
|
|
224
|
+
columns as (${H})
|
|
225
|
+
select
|
|
226
|
+
*,
|
|
227
|
+
${_e("columns","columns.table_id = tables.id")}
|
|
228
|
+
from tables
|
|
229
|
+
`;return o+=`
|
|
230
|
+
`,e.length>0?o+=`where schema in (${e.map(t=>`'${t}'`).join(",")})`:o+=`where schema not in (${ye.map(t=>`'${t}'`).join(",")})`,o}function q(){return G}var _e=(e,o)=>B`
|
|
231
|
+
COALESCE(
|
|
232
|
+
(
|
|
233
|
+
SELECT
|
|
234
|
+
array_agg(row_to_json(${e})) FILTER (WHERE ${o})
|
|
235
|
+
FROM
|
|
236
|
+
${e}
|
|
237
|
+
),
|
|
238
|
+
'{}'
|
|
239
|
+
) AS ${e}
|
|
240
|
+
`;function $({managementApiClient:e,projectId:o,readOnly:t}){async function n(s,l){let c=await e.POST("/v1/projects/{ref}/database/query",{params:{path:{ref:s}},body:{query:l,read_only:t}});return i(c,"Failed to execute SQL query"),c.data}let a=o;return{list_tables:g({description:"Lists all tables in one or more schemas.",parameters:u.object({project_id:u.string(),schemas:u.array(u.string()).describe("List of schemas to include. Defaults to all schemas.").default(["public"])}),inject:{project_id:a},execute:async({project_id:s,schemas:l})=>{let c=W(l);return await n(s,c)}}),list_extensions:g({description:"Lists all extensions in the database.",parameters:u.object({project_id:u.string()}),inject:{project_id:a},execute:async({project_id:s})=>{let l=q();return await n(s,l)}}),list_migrations:g({description:"Lists all migrations in the database.",parameters:u.object({project_id:u.string()}),inject:{project_id:a},execute:async({project_id:s})=>{let l=await e.GET("/v1/projects/{ref}/database/migrations",{params:{path:{ref:s}}});return i(l,"Failed to fetch migrations"),l.data}}),apply_migration:g({description:"Applies a migration to the database. Use this when executing DDL operations. Do not hardcode references to generated IDs in data migrations.",parameters:u.object({project_id:u.string(),name:u.string().describe("The name of the migration in snake_case"),query:u.string().describe("The SQL query to apply")}),inject:{project_id:a},execute:async({project_id:s,name:l,query:c})=>{if(t)throw new Error("Cannot apply migration in read-only mode.");let d=await e.POST("/v1/projects/{ref}/database/migrations",{params:{path:{ref:s}},body:{name:l,query:c}});return i(d,"Failed to apply migration"),d.data}}),execute_sql:g({description:"Executes raw SQL in the Postgres database. Use `apply_migration` instead for DDL operations.",parameters:u.object({project_id:u.string(),query:u.string().describe("The SQL query to execute")}),inject:{project_id:a},execute:async({query:s,project_id:l})=>await n(l,s)})}}import{z as C}from"zod";import{stripIndent as b}from"common-tags";function K(e,o=100){switch(e){case"api":return b`
|
|
241
|
+
select id, identifier, timestamp, event_message, request.method, request.path, response.status_code
|
|
242
|
+
from edge_logs
|
|
243
|
+
cross join unnest(metadata) as m
|
|
244
|
+
cross join unnest(m.request) as request
|
|
245
|
+
cross join unnest(m.response) as response
|
|
246
|
+
order by timestamp desc
|
|
247
|
+
limit ${o}
|
|
248
|
+
`;case"branch-action":return b`
|
|
249
|
+
select workflow_run, workflow_run_logs.timestamp, id, event_message from workflow_run_logs
|
|
250
|
+
order by timestamp desc
|
|
251
|
+
limit ${o}
|
|
252
|
+
`;case"postgres":return b`
|
|
253
|
+
select identifier, postgres_logs.timestamp, id, event_message, parsed.error_severity from postgres_logs
|
|
254
|
+
cross join unnest(metadata) as m
|
|
255
|
+
cross join unnest(m.parsed) as parsed
|
|
256
|
+
order by timestamp desc
|
|
257
|
+
limit ${o}
|
|
258
|
+
`;case"edge-function":return b`
|
|
259
|
+
select id, function_edge_logs.timestamp, event_message, response.status_code, request.method, m.function_id, m.execution_time_ms, m.deployment_id, m.version from function_edge_logs
|
|
260
|
+
cross join unnest(metadata) as m
|
|
261
|
+
cross join unnest(m.response) as response
|
|
262
|
+
cross join unnest(m.request) as request
|
|
263
|
+
order by timestamp desc
|
|
264
|
+
limit ${o}
|
|
265
|
+
`;case"auth":return b`
|
|
266
|
+
select id, auth_logs.timestamp, event_message, metadata.level, metadata.status, metadata.path, metadata.msg as msg, metadata.error from auth_logs
|
|
267
|
+
cross join unnest(metadata) as metadata
|
|
268
|
+
order by timestamp desc
|
|
269
|
+
limit ${o}
|
|
270
|
+
`;case"storage":return b`
|
|
271
|
+
select id, storage_logs.timestamp, event_message from storage_logs
|
|
272
|
+
order by timestamp desc
|
|
273
|
+
limit ${o}
|
|
274
|
+
`;case"realtime":return b`
|
|
275
|
+
select id, realtime_logs.timestamp, event_message from realtime_logs
|
|
276
|
+
order by timestamp desc
|
|
277
|
+
limit ${o}
|
|
278
|
+
`;default:throw new Error(`unsupported log service type: ${e}`)}}function J({managementApiClient:e,projectId:o}){let t=o;return{get_logs:g({description:"Gets logs for a Supabase project by service type. Use this to help debug problems with your app. This will only return logs within the last minute. If the logs you are looking for are older than 1 minute, re-run your test to reproduce them.",parameters:C.object({project_id:C.string(),service:C.enum(["api","branch-action","postgres","edge-function","auth","storage","realtime"]).describe("The service to fetch logs for")}),inject:{project_id:t},execute:async({project_id:n,service:a})=>{let r=a==="branch-action"?new Date(Date.now()-3e5):void 0,s=await e.GET("/v1/projects/{ref}/analytics/endpoints/logs.all",{params:{path:{ref:n},query:{iso_timestamp_start:r?.toISOString(),sql:K(a)}}});return i(s,"Failed to fetch logs"),s.data}})}}import{z as S}from"zod";function Y({managementApiClient:e,projectId:o}){let t=o;return{get_project_url:g({description:"Gets the API URL for a project.",parameters:S.object({project_id:S.string()}),inject:{project_id:t},execute:async({project_id:n})=>`https://${n}.supabase.co`}),get_anon_key:g({description:"Gets the anonymous API key for a project.",parameters:S.object({project_id:S.string()}),inject:{project_id:t},execute:async({project_id:n})=>{let a=await e.GET("/v1/projects/{ref}/api-keys",{params:{path:{ref:n},query:{reveal:!1}}});i(a,"Failed to fetch API keys");let r=a.data?.find(s=>s.name==="anon");if(!r)throw new Error("Anonymous key not found");return r.api_key}}),generate_typescript_types:g({description:"Generates TypeScript types for a project.",parameters:S.object({project_id:S.string()}),inject:{project_id:t},execute:async({project_id:n})=>{let a=await e.GET("/v1/projects/{ref}/types/typescript",{params:{path:{ref:n}}});return i(a,"Failed to fetch TypeScript types"),a.data}})}}import{z as f}from"zod";import{codeBlock as je}from"common-tags";import{fileURLToPath as Z}from"url";import{build as At,Parser as be}from"@deno/eszip";import{join as wt,relative as Ee}from"node:path";import{fileURLToPath as Se}from"node:url";import{z as y}from"zod";var A=await be.createInstance(),Te=y.object({version:y.number(),sources:y.array(y.string()),sourcesContent:y.array(y.string()).optional(),names:y.array(y.string()),mappings:y.string()});async function V(e,o="/"){let t=[];if(e instanceof ReadableStream){let r=e.getReader({mode:"byob"});t=await A.parse(r)}else t=await A.parseBytes(e);await A.load();let n=t.filter(r=>r.startsWith("file://"));return await Promise.all(n.map(async r=>{let s=await A.getModuleSource(r),l=await A.getModuleSourceMap(r),c=Ee(o,Se(r)),d=new File([s],c,{type:"text/plain"});if(!l)return d;let E=Te.parse(JSON.parse(l)),[h]=E.sourcesContent??[];return h?new File([h],c,{type:"application/typescript"}):d}))}function Ae(e,o,t){return`${e}_${o}_${t}`}function Ne(e){return`/tmp/user_fn_${e}/`}var Q=je`
|
|
279
|
+
import "jsr:@supabase/functions-js/edge-runtime.d.ts";
|
|
280
|
+
|
|
281
|
+
Deno.serve(async (req: Request) => {
|
|
282
|
+
const data = {
|
|
283
|
+
message: "Hello there!"
|
|
284
|
+
};
|
|
285
|
+
|
|
286
|
+
return new Response(JSON.stringify(data), {
|
|
287
|
+
headers: {
|
|
288
|
+
'Content-Type': 'application/json',
|
|
289
|
+
'Connection': 'keep-alive'
|
|
290
|
+
}
|
|
291
|
+
});
|
|
292
|
+
});
|
|
293
|
+
`;async function I(e,o,t){let n=await e.GET("/v1/projects/{ref}/functions/{function_slug}",{params:{path:{ref:o,function_slug:t}}});if(n.error)return{data:void 0,error:n.error};i(n,"Failed to fetch Edge Function");let a=n.data,r=Ae(o,a.id,a.version),s=Ne(r),l=a.entrypoint_path?Z(a.entrypoint_path).replace(s,""):void 0,c=a.import_map_path?Z(a.import_map_path).replace(s,""):void 0,d=await e.GET("/v1/projects/{ref}/functions/{function_slug}/body",{params:{path:{ref:o,function_slug:t}},parseAs:"arrayBuffer"});i(d,"Failed to fetch Edge Function eszip bundle");let E=await V(new Uint8Array(d.data),s),h=await Promise.all(E.map(async N=>({name:N.name,content:await N.text()})));return{data:{...a,entrypoint_path:l,import_map_path:c,files:h},error:void 0}}function X({managementApiClient:e,projectId:o}){let t=o;return{list_edge_functions:g({description:"Lists all Edge Functions in a Supabase project.",parameters:f.object({project_id:f.string()}),inject:{project_id:t},execute:async({project_id:n})=>{let a=await e.GET("/v1/projects/{ref}/functions",{params:{path:{ref:n}}});return i(a,"Failed to fetch Edge Functions"),await Promise.all(a.data.map(async s=>{let{data:l,error:c}=await I(e,n,s.slug);if(c)throw c;return l}))}}),deploy_edge_function:g({description:`Deploys an Edge Function to a Supabase project. If the function already exists, this will create a new version. Example:
|
|
294
|
+
|
|
295
|
+
${Q}`,parameters:f.object({project_id:f.string(),name:f.string().describe("The name of the function"),entrypoint_path:f.string().default("index.ts").describe("The entrypoint of the function"),import_map_path:f.string().describe("The import map for the function.").optional(),files:f.array(f.object({name:f.string(),content:f.string()})).describe("The files to upload. This should include the entrypoint and any relative dependencies.")}),inject:{project_id:t},execute:async({project_id:n,name:a,entrypoint_path:r,import_map_path:s,files:l})=>{let{data:c}=await I(e,n,a),d=l.find(h=>["deno.json","import_map.json"].includes(h.name));s??=c?.import_map_path??d?.name;let E=await e.POST("/v1/projects/{ref}/functions/deploy",{params:{path:{ref:n},query:{slug:a}},body:{metadata:{name:a,entrypoint_path:r,import_map_path:s},file:l},bodySerializer(h){let T=new FormData,N=new Blob([JSON.stringify(h.metadata)],{type:"application/json"});return T.append("metadata",N),h.file?.forEach(ie=>{let v=ie,le=new Blob([v.content],{type:"application/typescript"});T.append("file",le,v.name)}),T}});return i(E,"Failed to deploy Edge Function"),E.data}})}}import{tool as _}from"@supabase/mcp-utils";import{z as p}from"zod";var we="ABCDEFGHIJKLMNOPQRSTUVWXYZ",Oe="abcdefghijklmnopqrstuvwxyz",xe="0123456789",Re="!@#$%^&*()_+~`|}{[]:;?><,./-=",ee=({length:e=10,numbers:o=!1,symbols:t=!1,uppercase:n=!0,lowercase:a=!0}={})=>{let r="";if(n&&(r+=we),a&&(r+=Oe),o&&(r+=xe),t&&(r+=Re),r.length===0)throw new Error("at least one character set must be selected");let s=new Uint32Array(e);crypto.getRandomValues(s);let l="";for(let c=0;c<e;c++){let d=s[c]%r.length;l+=r.charAt(d)}return l};var Ce=6371,Ie="https://www.cloudflare.com/cdn-cgi/trace",Me={AF:{lat:33,lng:65},AX:{lat:60.116667,lng:19.9},AL:{lat:41,lng:20},DZ:{lat:28,lng:3},AS:{lat:-14.3333,lng:-170},AD:{lat:42.5,lng:1.6},AO:{lat:-12.5,lng:18.5},AI:{lat:18.25,lng:-63.1667},AQ:{lat:-90,lng:0},AG:{lat:17.05,lng:-61.8},AR:{lat:-34,lng:-64},AM:{lat:40,lng:45},AW:{lat:12.5,lng:-69.9667},AU:{lat:-27,lng:133},AT:{lat:47.3333,lng:13.3333},AZ:{lat:40.5,lng:47.5},BS:{lat:24.25,lng:-76},BH:{lat:26,lng:50.55},BD:{lat:24,lng:90},BB:{lat:13.1667,lng:-59.5333},BY:{lat:53,lng:28},BE:{lat:50.8333,lng:4},BZ:{lat:17.25,lng:-88.75},BJ:{lat:9.5,lng:2.25},BM:{lat:32.3333,lng:-64.75},BT:{lat:27.5,lng:90.5},BO:{lat:-17,lng:-65},BQ:{lat:12.183333,lng:-68.233333},BA:{lat:44,lng:18},BW:{lat:-22,lng:24},BV:{lat:-54.4333,lng:3.4},BR:{lat:-10,lng:-55},IO:{lat:-6,lng:71.5},BN:{lat:4.5,lng:114.6667},BG:{lat:43,lng:25},BF:{lat:13,lng:-2},MM:{lat:22,lng:98},BI:{lat:-3.5,lng:30},KH:{lat:13,lng:105},CM:{lat:6,lng:12},CA:{lat:60,lng:-95},CV:{lat:16,lng:-24},KY:{lat:19.5,lng:-80.5},CF:{lat:7,lng:21},TD:{lat:15,lng:19},CL:{lat:-30,lng:-71},CN:{lat:35,lng:105},CX:{lat:-10.5,lng:105.6667},CC:{lat:-12.5,lng:96.8333},CO:{lat:4,lng:-72},KM:{lat:-12.1667,lng:44.25},CD:{lat:0,lng:25},CG:{lat:-1,lng:15},CK:{lat:-21.2333,lng:-159.7667},CR:{lat:10,lng:-84},CI:{lat:8,lng:-5},HR:{lat:45.1667,lng:15.5},CU:{lat:21.5,lng:-80},CW:{lat:12.166667,lng:-68.966667},CY:{lat:35,lng:33},CZ:{lat:49.75,lng:15.5},DK:{lat:56,lng:10},DJ:{lat:11.5,lng:43},DM:{lat:15.4167,lng:-61.3333},DO:{lat:19,lng:-70.6667},EC:{lat:-2,lng:-77.5},EG:{lat:27,lng:30},SV:{lat:13.8333,lng:-88.9167},GQ:{lat:2,lng:10},ER:{lat:15,lng:39},EE:{lat:59,lng:26},ET:{lat:8,lng:38},FK:{lat:-51.75,lng:-59},FO:{lat:62,lng:-7},FJ:{lat:-18,lng:175},FI:{lat:64,lng:26},FR:{lat:46,lng:2},GF:{lat:4,lng:-53},PF:{lat:-15,lng:-140},TF:{lat:-43,lng:67},GA:{lat:-1,lng:11.75},GM:{lat:13.4667,lng:-16.5667},GE:{lat:42,lng:43.5},DE:{lat:51,lng:9},GH:{lat:8,lng:-2},GI:{lat:36.1833,lng:-5.3667},GR:{lat:39,lng:22},GL:{lat:72,lng:-40},GD:{lat:12.1167,lng:-61.6667},GP:{lat:16.25,lng:-61.5833},GU:{lat:13.4667,lng:144.7833},GT:{lat:15.5,lng:-90.25},GG:{lat:49.5,lng:-2.56},GW:{lat:12,lng:-15},GN:{lat:11,lng:-10},GY:{lat:5,lng:-59},HT:{lat:19,lng:-72.4167},HM:{lat:-53.1,lng:72.5167},VA:{lat:41.9,lng:12.45},HN:{lat:15,lng:-86.5},HK:{lat:22.25,lng:114.1667},HU:{lat:47,lng:20},IS:{lat:65,lng:-18},IN:{lat:20,lng:77},ID:{lat:-5,lng:120},IR:{lat:32,lng:53},IQ:{lat:33,lng:44},IE:{lat:53,lng:-8},IM:{lat:54.23,lng:-4.55},IL:{lat:31.5,lng:34.75},IT:{lat:42.8333,lng:12.8333},JM:{lat:18.25,lng:-77.5},JP:{lat:36,lng:138},JE:{lat:49.21,lng:-2.13},JO:{lat:31,lng:36},KZ:{lat:48,lng:68},KE:{lat:1,lng:38},KI:{lat:1.4167,lng:173},KP:{lat:40,lng:127},KR:{lat:37,lng:127.5},XK:{lat:42.583333,lng:21},KW:{lat:29.3375,lng:47.6581},KG:{lat:41,lng:75},LA:{lat:18,lng:105},LV:{lat:57,lng:25},LB:{lat:33.8333,lng:35.8333},LS:{lat:-29.5,lng:28.5},LR:{lat:6.5,lng:-9.5},LY:{lat:25,lng:17},LI:{lat:47.1667,lng:9.5333},LT:{lat:56,lng:24},LU:{lat:49.75,lng:6.1667},MO:{lat:22.1667,lng:113.55},MK:{lat:41.8333,lng:22},MG:{lat:-20,lng:47},MW:{lat:-13.5,lng:34},MY:{lat:2.5,lng:112.5},MV:{lat:3.25,lng:73},ML:{lat:17,lng:-4},MT:{lat:35.8333,lng:14.5833},MH:{lat:9,lng:168},MQ:{lat:14.6667,lng:-61},MR:{lat:20,lng:-12},MU:{lat:-20.2833,lng:57.55},YT:{lat:-12.8333,lng:45.1667},MX:{lat:23,lng:-102},FM:{lat:6.9167,lng:158.25},MD:{lat:47,lng:29},MC:{lat:43.7333,lng:7.4},MN:{lat:46,lng:105},ME:{lat:42,lng:19},MS:{lat:16.75,lng:-62.2},MA:{lat:32,lng:-5},MZ:{lat:-18.25,lng:35},NA:{lat:-22,lng:17},NR:{lat:-.5333,lng:166.9167},NP:{lat:28,lng:84},AN:{lat:12.25,lng:-68.75},NL:{lat:52.5,lng:5.75},NC:{lat:-21.5,lng:165.5},NZ:{lat:-41,lng:174},NI:{lat:13,lng:-85},NE:{lat:16,lng:8},NG:{lat:10,lng:8},NU:{lat:-19.0333,lng:-169.8667},NF:{lat:-29.0333,lng:167.95},MP:{lat:15.2,lng:145.75},NO:{lat:62,lng:10},OM:{lat:21,lng:57},PK:{lat:30,lng:70},PW:{lat:7.5,lng:134.5},PS:{lat:32,lng:35.25},PA:{lat:9,lng:-80},PG:{lat:-6,lng:147},PY:{lat:-23,lng:-58},PE:{lat:-10,lng:-76},PH:{lat:13,lng:122},PN:{lat:-24.7,lng:-127.4},PL:{lat:52,lng:20},PT:{lat:39.5,lng:-8},PR:{lat:18.25,lng:-66.5},QA:{lat:25.5,lng:51.25},RE:{lat:-21.1,lng:55.6},RO:{lat:46,lng:25},RU:{lat:60,lng:100},RW:{lat:-2,lng:30},BL:{lat:17.897728,lng:-62.834244},SH:{lat:-15.9333,lng:-5.7},KN:{lat:17.3333,lng:-62.75},LC:{lat:13.8833,lng:-61.1333},MF:{lat:18.075278,lng:-63.06},PM:{lat:46.8333,lng:-56.3333},VC:{lat:13.25,lng:-61.2},WS:{lat:-13.5833,lng:-172.3333},SM:{lat:43.7667,lng:12.4167},ST:{lat:1,lng:7},SA:{lat:25,lng:45},SN:{lat:14,lng:-14},RS:{lat:44,lng:21},SC:{lat:-4.5833,lng:55.6667},SL:{lat:8.5,lng:-11.5},SG:{lat:1.3667,lng:103.8},SX:{lat:18.033333,lng:-63.05},SK:{lat:48.6667,lng:19.5},SI:{lat:46,lng:15},SB:{lat:-8,lng:159},SO:{lat:10,lng:49},ZA:{lat:-29,lng:24},GS:{lat:-54.5,lng:-37},SS:{lat:8,lng:30},ES:{lat:40,lng:-4},LK:{lat:7,lng:81},SD:{lat:15,lng:30},SR:{lat:4,lng:-56},SJ:{lat:78,lng:20},SZ:{lat:-26.5,lng:31.5},SE:{lat:62,lng:15},CH:{lat:47,lng:8},SY:{lat:35,lng:38},TW:{lat:23.5,lng:121},TJ:{lat:39,lng:71},TZ:{lat:-6,lng:35},TH:{lat:15,lng:100},TL:{lat:-8.55,lng:125.5167},TG:{lat:8,lng:1.1667},TK:{lat:-9,lng:-172},TO:{lat:-20,lng:-175},TT:{lat:11,lng:-61},TN:{lat:34,lng:9},TR:{lat:39,lng:35},TM:{lat:40,lng:60},TC:{lat:21.75,lng:-71.5833},TV:{lat:-8,lng:178},UG:{lat:1,lng:32},UA:{lat:49,lng:32},AE:{lat:24,lng:54},GB:{lat:54,lng:-2},UM:{lat:19.2833,lng:166.6},US:{lat:38,lng:-97},UY:{lat:-33,lng:-56},UZ:{lat:41,lng:64},VU:{lat:-16,lng:167},VE:{lat:8,lng:-66},VN:{lat:16,lng:106},VG:{lat:18.5,lng:-64.5},VI:{lat:18.3333,lng:-64.8333},WF:{lat:-13.3,lng:-176.2},EH:{lat:24.5,lng:-13},YE:{lat:15,lng:48},ZM:{lat:-15,lng:30},ZW:{lat:-20,lng:30}},M={WEST_US:{code:"us-west-1",displayName:"West US (North California)",location:{lat:37.774929,lng:-122.419418}},EAST_US:{code:"us-east-1",displayName:"East US (North Virginia)",location:{lat:37.926868,lng:-78.024902}},EAST_US_2:{code:"us-east-2",displayName:"East US (Ohio)",location:{lat:39.9612,lng:-82.9988}},CENTRAL_CANADA:{code:"ca-central-1",displayName:"Canada (Central)",location:{lat:56.130367,lng:-106.346771}},WEST_EU:{code:"eu-west-1",displayName:"West EU (Ireland)",location:{lat:53.3498,lng:-6.2603}},WEST_EU_2:{code:"eu-west-2",displayName:"West Europe (London)",location:{lat:51.507351,lng:-.127758}},WEST_EU_3:{code:"eu-west-3",displayName:"West EU (Paris)",location:{lat:2.352222,lng:48.856613}},CENTRAL_EU:{code:"eu-central-1",displayName:"Central EU (Frankfurt)",location:{lat:50.110924,lng:8.682127}},CENTRAL_EU_2:{code:"eu-central-2",displayName:"Central Europe (Zurich)",location:{lat:47.3744489,lng:8.5410422}},NORTH_EU:{code:"eu-north-1",displayName:"North EU (Stockholm)",location:{lat:59.3251172,lng:18.0710935}},SOUTH_ASIA:{code:"ap-south-1",displayName:"South Asia (Mumbai)",location:{lat:18.9733536,lng:72.8281049}},SOUTHEAST_ASIA:{code:"ap-southeast-1",displayName:"Southeast Asia (Singapore)",location:{lat:1.357107,lng:103.8194992}},NORTHEAST_ASIA:{code:"ap-northeast-1",displayName:"Northeast Asia (Tokyo)",location:{lat:35.6895,lng:139.6917}},NORTHEAST_ASIA_2:{code:"ap-northeast-2",displayName:"Northeast Asia (Seoul)",location:{lat:37.5665,lng:126.978}},OCEANIA:{code:"ap-southeast-2",displayName:"Oceania (Sydney)",location:{lat:-33.8688,lng:151.2093}},SOUTH_AMERICA:{code:"sa-east-1",displayName:"South America (S\xE3o Paulo)",location:{lat:-1.2043218,lng:-47.1583944}}},te=Object.values(M).map(e=>e.code);function ae(e){let t=Object.entries(M).map(([a,r])=>[a,ve(e,r.location)]).reduce((a,r)=>a===void 0||r[1]<a[1]?r:a,void 0);if(!t)throw new Error("no closest region found");let[n]=t;return M[n]}async function ne(){let o=await(await fetch(Ie)).text(),n=P(o).loc;if(!n)throw new Error("location not found");return n}function oe(e){let o=Me[e];if(!o)throw new Error(`unknown location code: ${e}`);return o}function ve(e,o){let t=x(o.lat-e.lat),n=x(o.lng-e.lng),a=Math.sin(t/2)*Math.sin(t/2)+Math.cos(x(e.lat))*Math.cos(x(o.lat))*Math.sin(n/2)*Math.sin(n/2),r=2*Math.atan2(Math.sqrt(a),Math.sqrt(1-a));return Ce*r}function x(e){return e*(Math.PI/180)}function re({managementApiClient:e}){async function o(){return ae(oe(await ne())).code}return{list_organizations:_({description:"Lists all organizations that the user is a member of.",parameters:p.object({}),execute:async()=>{let t=await e.GET("/v1/organizations");return i(t,"Failed to fetch organizations"),t.data}}),get_organization:_({description:"Gets details for an organization. Includes subscription plan.",parameters:p.object({id:p.string().describe("The organization ID")}),execute:async({id:t})=>{let n=await e.GET("/v1/organizations/{slug}",{params:{path:{slug:t}}});return i(n,"Failed to fetch organization"),n.data}}),list_projects:_({description:"Lists all Supabase projects for the user. Use this to help discover the project ID of the project that the user is working on.",parameters:p.object({}),execute:async()=>{let t=await e.GET("/v1/projects");return i(t,"Failed to fetch projects"),t.data}}),get_project:_({description:"Gets details for a Supabase project.",parameters:p.object({id:p.string().describe("The project ID")}),execute:async({id:t})=>{let n=await e.GET("/v1/projects/{ref}",{params:{path:{ref:t}}});return i(n,"Failed to fetch project"),n.data}}),get_cost:_({description:"Gets the cost of creating a new project or branch. Never assume organization as costs can be different for each.",parameters:p.object({type:p.enum(["project","branch"]),organization_id:p.string().describe("The organization ID. Always ask the user.")}),execute:async({type:t,organization_id:n})=>{function a(r){return`The new ${t} will cost $${r.amount} ${r.recurrence}. You must repeat this to the user and confirm their understanding.`}switch(t){case"project":{let r=await R(e,n);return a(r)}case"branch":{let r=w();return a(r)}default:throw new Error(`Unknown cost type: ${t}`)}}}),confirm_cost:_({description:"Ask the user to confirm their understanding of the cost of creating a new project or branch. Call `get_cost` first. Returns a unique ID for this confirmation which should be passed to `create_project` or `create_branch`.",parameters:p.object({type:p.enum(["project","branch"]),recurrence:p.enum(["hourly","monthly"]),amount:p.number()}),execute:async t=>await j(t)}),create_project:_({description:"Creates a new Supabase project. Always ask the user which organization to create the project in. The project can take a few minutes to initialize - use `get_project` to check the status.",parameters:p.object({name:p.string().describe("The name of the project"),region:p.optional(p.enum(te).describe("The region to create the project in. Defaults to the closest region.")),organization_id:p.string(),confirm_cost_id:p.string({required_error:"User must confirm understanding of costs before creating a project."}).describe("The cost confirmation ID. Call `confirm_cost` first.")}),execute:async({name:t,region:n,organization_id:a,confirm_cost_id:r})=>{let s=await R(e,a);if(await j(s)!==r)throw new Error("Cost confirmation ID does not match the expected cost of creating a project.");let c=await e.POST("/v1/projects",{body:{name:t,region:n??await o(),organization_id:a,db_pass:ee({length:16,numbers:!0,uppercase:!0,lowercase:!0})}});return i(c,"Failed to create project"),c.data}}),pause_project:_({description:"Pauses a Supabase project.",parameters:p.object({project_id:p.string()}),execute:async({project_id:t})=>{let n=await e.POST("/v1/projects/{ref}/pause",{params:{path:{ref:t}}});i(n,"Failed to pause project")}}),restore_project:_({description:"Restores a Supabase project.",parameters:p.object({project_id:p.string()}),execute:async({project_id:t})=>{let n=await e.POST("/v1/projects/{ref}/restore",{params:{path:{ref:t}},body:{}});i(n,"Failed to restore project")}})}}var{version:se}=L;function sa(e){let o=e.platform.apiUrl??"https://api.supabase.com",t=e.projectId,n=e.readOnly,a;return Le({name:"supabase",version:se,onInitialize({clientInfo:s}){a=D(o,e.platform.accessToken,{"User-Agent":`supabase-mcp/${se} (${s.name}/${s.version})`})},tools:()=>{let s={};return t||Object.assign(s,re({managementApiClient:a})),Object.assign(s,$({managementApiClient:a,projectId:t,readOnly:n}),X({managementApiClient:a,projectId:t}),J({managementApiClient:a,projectId:t}),Y({managementApiClient:a,projectId:t}),k({managementApiClient:a,projectId:t})),s}})}export{L as a,sa as b};
|
|
296
|
+
//# sourceMappingURL=chunk-3UPSHB6J.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../package.json","../src/server.ts","../src/management-api/index.ts","../src/tools/branching-tools.ts","../src/pricing.ts","../src/util.ts","../src/tools/util.ts","../src/tools/database-operation-tools.ts","../src/pg-meta/index.ts","../src/pg-meta/columns.sql","../src/pg-meta/extensions.sql","../src/pg-meta/tables.sql","../src/tools/debugging-tools.ts","../src/logs.ts","../src/tools/development-tools.ts","../src/tools/edge-function-tools.ts","../src/edge-function.ts","../src/eszip.ts","../src/tools/project-management-tools.ts","../src/password.ts","../src/regions.ts"],"sourcesContent":["{\n \"name\": \"@supabase/mcp-server-supabase\",\n \"version\": \"0.4.0-alpha.1\",\n \"description\": \"MCP server for interacting with Supabase\",\n \"license\": \"Apache-2.0\",\n \"type\": \"module\",\n \"main\": \"dist/index.cjs\",\n \"types\": \"dist/index.d.ts\",\n \"sideEffects\": false,\n \"scripts\": {\n \"build\": \"tsup --clean\",\n \"prepublishOnly\": \"npm run build\",\n \"test\": \"vitest\",\n \"test:e2e\": \"vitest --project e2e\",\n \"test:unit\": \"vitest --project unit\",\n \"generate:management-api-types\": \"openapi-typescript https://api.supabase.com/api/v1-json -o ./src/management-api/types.ts\"\n },\n \"files\": [\n \"dist/**/*\"\n ],\n \"bin\": {\n \"mcp-server-supabase\": \"./dist/stdio.js\"\n },\n \"exports\": {\n \".\": {\n \"import\": \"./dist/index.js\",\n \"types\": \"./dist/index.d.ts\",\n \"default\": \"./dist/index.cjs\"\n }\n },\n \"dependencies\": {\n \"@deno/eszip\": \"^0.84.0\",\n \"@modelcontextprotocol/sdk\": \"^1.4.1\",\n \"@supabase/mcp-utils\": \"0.2.0\",\n \"common-tags\": \"^1.8.2\",\n \"openapi-fetch\": \"^0.13.5\",\n \"zod\": \"^3.24.1\"\n },\n \"devDependencies\": {\n \"@ai-sdk/anthropic\": \"^1.2.9\",\n \"@electric-sql/pglite\": \"^0.2.17\",\n \"@total-typescript/tsconfig\": \"^1.0.4\",\n \"@types/common-tags\": \"^1.8.4\",\n \"@types/node\": \"^22.8.6\",\n \"ai\": \"^4.3.4\",\n \"date-fns\": \"^4.1.0\",\n \"dotenv\": \"^16.5.0\",\n \"msw\": \"^2.7.3\",\n \"nanoid\": \"^5.1.5\",\n \"openapi-typescript\": \"^7.5.0\",\n \"openapi-typescript-helpers\": \"^0.0.15\",\n \"prettier\": \"^3.3.3\",\n \"tsup\": \"^8.3.5\",\n \"tsx\": \"^4.19.2\",\n \"typescript\": \"^5.6.3\",\n \"vitest\": \"^2.1.9\"\n }\n}\n","import { createMcpServer, type Tool } from '@supabase/mcp-utils';\nimport packageJson from '../package.json' with { type: 'json' };\nimport {\n createManagementApiClient,\n type ManagementApiClient,\n} from './management-api/index.js';\nimport { getBranchingTools } from './tools/branching-tools.js';\nimport { getDatabaseOperationTools } from './tools/database-operation-tools.js';\nimport { getDebuggingTools } from './tools/debugging-tools.js';\nimport { getDevelopmentTools } from './tools/development-tools.js';\nimport { getEdgeFunctionTools } from './tools/edge-function-tools.js';\nimport { getProjectManagementTools } from './tools/project-management-tools.js';\n\nconst { version } = packageJson;\n\nexport type SupabasePlatformOptions = {\n /**\n * The access token for the Supabase Management API.\n */\n accessToken: string;\n\n /**\n * The API URL for the Supabase Management API.\n */\n apiUrl?: string;\n};\n\nexport type SupabaseMcpServerOptions = {\n /**\n * Platform options for Supabase.\n */\n platform: SupabasePlatformOptions;\n\n /**\n * The project ID to scope the server to.\n *\n * If undefined, the server will have access\n * to all organizations and projects for the user.\n */\n projectId?: string;\n\n /**\n * Executes database queries in read-only mode if true.\n */\n readOnly?: boolean;\n};\n\n/**\n * Creates an MCP server for interacting with Supabase.\n */\nexport function createSupabaseMcpServer(options: SupabaseMcpServerOptions) {\n const managementApiUrl =\n options.platform.apiUrl ?? 'https://api.supabase.com';\n const projectId = options.projectId;\n const readOnly = options.readOnly;\n\n let managementApiClient: ManagementApiClient;\n\n const server = createMcpServer({\n name: 'supabase',\n version,\n onInitialize({ clientInfo }) {\n managementApiClient = createManagementApiClient(\n managementApiUrl,\n options.platform.accessToken,\n {\n 'User-Agent': `supabase-mcp/${version} (${clientInfo.name}/${clientInfo.version})`,\n }\n );\n },\n tools: () => {\n const tools: Record<string, Tool> = {};\n\n // Add account-level tools only if projectId is not provided\n if (!projectId) {\n Object.assign(\n tools,\n getProjectManagementTools({ managementApiClient })\n );\n }\n\n // Add project-level tools\n Object.assign(\n tools,\n getDatabaseOperationTools({\n managementApiClient,\n projectId,\n readOnly,\n }),\n getEdgeFunctionTools({\n managementApiClient,\n projectId,\n }),\n getDebuggingTools({\n managementApiClient,\n projectId,\n }),\n getDevelopmentTools({\n managementApiClient,\n projectId,\n }),\n getBranchingTools({\n managementApiClient,\n projectId,\n })\n );\n\n return tools;\n },\n });\n\n return server;\n}\n","import createClient, {\n type Client,\n type FetchResponse,\n type ParseAsResponse,\n} from 'openapi-fetch';\nimport type {\n MediaType,\n ResponseObjectMap,\n SuccessResponse,\n} from 'openapi-typescript-helpers';\nimport { z } from 'zod';\nimport type { paths } from './types.js';\n\nexport function createManagementApiClient(\n baseUrl: string,\n accessToken: string,\n headers: Record<string, string> = {}\n) {\n return createClient<paths>({\n baseUrl,\n headers: {\n Authorization: `Bearer ${accessToken}`,\n ...headers,\n },\n });\n}\n\nexport type ManagementApiClient = Client<paths>;\n\nexport type SuccessResponseType<\n T extends Record<string | number, any>,\n Options,\n Media extends MediaType,\n> = {\n data: ParseAsResponse<SuccessResponse<ResponseObjectMap<T>, Media>, Options>;\n error?: never;\n response: Response;\n};\n\nconst errorSchema = z.object({\n message: z.string(),\n});\n\nexport function assertSuccess<\n T extends Record<string | number, any>,\n Options,\n Media extends MediaType,\n>(\n response: FetchResponse<T, Options, Media>,\n fallbackMessage: string\n): asserts response is SuccessResponseType<T, Options, Media> {\n if ('error' in response) {\n if (response.response.status === 401) {\n throw new Error(\n 'Unauthorized. Please provide a valid access token to the MCP server via the --access-token flag or SUPABASE_ACCESS_TOKEN.'\n );\n }\n\n const { data: errorContent } = errorSchema.safeParse(response.error);\n\n if (errorContent) {\n throw new Error(errorContent.message);\n }\n\n throw new Error(fallbackMessage);\n }\n}\n","import { tool } from '@supabase/mcp-utils';\nimport { z } from 'zod';\nimport {\n assertSuccess,\n type ManagementApiClient,\n} from '../management-api/index.js';\nimport { getBranchCost } from '../pricing.js';\nimport { hashObject } from '../util.js';\nimport { injectableTool } from './util.js';\n\nexport type BranchingToolsOptions = {\n managementApiClient: ManagementApiClient;\n projectId?: string;\n};\n\nexport function getBranchingTools({\n managementApiClient,\n projectId,\n}: BranchingToolsOptions) {\n const project_id = projectId;\n\n return {\n create_branch: injectableTool({\n description:\n 'Creates a development branch on a Supabase project. This will apply all migrations from the main project to a fresh branch database. Note that production data will not carry over. The branch will get its own project_id via the resulting project_ref. Use this ID to execute queries and migrations on the branch.',\n parameters: z.object({\n project_id: z.string(),\n name: z\n .string()\n .default('develop')\n .describe('Name of the branch to create'),\n confirm_cost_id: z\n .string({\n required_error:\n 'User must confirm understanding of costs before creating a branch.',\n })\n .describe('The cost confirmation ID. Call `confirm_cost` first.'),\n }),\n inject: { project_id },\n execute: async ({ project_id, name, confirm_cost_id }) => {\n const cost = getBranchCost();\n const costHash = await hashObject(cost);\n if (costHash !== confirm_cost_id) {\n throw new Error(\n 'Cost confirmation ID does not match the expected cost of creating a branch.'\n );\n }\n\n const createBranchResponse = await managementApiClient.POST(\n '/v1/projects/{ref}/branches',\n {\n params: {\n path: {\n ref: project_id,\n },\n },\n body: {\n branch_name: name,\n },\n }\n );\n\n assertSuccess(createBranchResponse, 'Failed to create branch');\n\n // Creating a default branch means we just enabled branching\n // TODO: move this logic to API eventually.\n if (createBranchResponse.data.is_default) {\n await managementApiClient.PATCH('/v1/branches/{branch_id}', {\n params: {\n path: {\n branch_id: createBranchResponse.data.id,\n },\n },\n body: {\n branch_name: 'main',\n },\n });\n\n const response = await managementApiClient.POST(\n '/v1/projects/{ref}/branches',\n {\n params: {\n path: {\n ref: project_id,\n },\n },\n body: {\n branch_name: name,\n },\n }\n );\n\n assertSuccess(response, 'Failed to create branch');\n\n return response.data;\n }\n\n return createBranchResponse.data;\n },\n }),\n list_branches: injectableTool({\n description:\n 'Lists all development branches of a Supabase project. This will return branch details including status which you can use to check when operations like merge/rebase/reset complete.',\n parameters: z.object({\n project_id: z.string(),\n }),\n inject: { project_id },\n execute: async ({ project_id }) => {\n const response = await managementApiClient.GET(\n '/v1/projects/{ref}/branches',\n {\n params: {\n path: {\n ref: project_id,\n },\n },\n }\n );\n\n // There are no branches if branching is disabled\n if (response.response.status === 422) return [];\n assertSuccess(response, 'Failed to list branches');\n\n return response.data;\n },\n }),\n delete_branch: tool({\n description: 'Deletes a development branch.',\n parameters: z.object({\n branch_id: z.string(),\n }),\n execute: async ({ branch_id }) => {\n const response = await managementApiClient.DELETE(\n '/v1/branches/{branch_id}',\n {\n params: {\n path: {\n branch_id,\n },\n },\n }\n );\n\n assertSuccess(response, 'Failed to delete branch');\n\n return response.data;\n },\n }),\n merge_branch: tool({\n description:\n 'Merges migrations and edge functions from a development branch to production.',\n parameters: z.object({\n branch_id: z.string(),\n }),\n execute: async ({ branch_id }) => {\n const response = await managementApiClient.POST(\n '/v1/branches/{branch_id}/merge',\n {\n params: {\n path: {\n branch_id,\n },\n },\n body: {},\n }\n );\n\n assertSuccess(response, 'Failed to merge branch');\n\n return response.data;\n },\n }),\n reset_branch: tool({\n description:\n 'Resets migrations of a development branch. Any untracked data or schema changes will be lost.',\n parameters: z.object({\n branch_id: z.string(),\n migration_version: z\n .string()\n .optional()\n .describe(\n 'Reset your development branch to a specific migration version.'\n ),\n }),\n execute: async ({ branch_id, migration_version }) => {\n const response = await managementApiClient.POST(\n '/v1/branches/{branch_id}/reset',\n {\n params: {\n path: {\n branch_id,\n },\n },\n body: {\n migration_version,\n },\n }\n );\n\n assertSuccess(response, 'Failed to reset branch');\n\n return response.data;\n },\n }),\n rebase_branch: tool({\n description:\n 'Rebases a development branch on production. This will effectively run any newer migrations from production onto this branch to help handle migration drift.',\n parameters: z.object({\n branch_id: z.string(),\n }),\n execute: async ({ branch_id }) => {\n const response = await managementApiClient.POST(\n '/v1/branches/{branch_id}/push',\n {\n params: {\n path: {\n branch_id,\n },\n },\n body: {},\n }\n );\n\n assertSuccess(response, 'Failed to rebase branch');\n\n return response.data;\n },\n }),\n };\n}\n","import {\n assertSuccess,\n type ManagementApiClient,\n} from './management-api/index.js';\n\nexport const PROJECT_COST_MONTHLY = 10;\nexport const BRANCH_COST_HOURLY = 0.01344;\n\nexport type ProjectCost = {\n type: 'project';\n recurrence: 'monthly';\n amount: number;\n};\n\nexport type BranchCost = {\n type: 'branch';\n recurrence: 'hourly';\n amount: number;\n};\n\nexport type Cost = ProjectCost | BranchCost;\n\n/**\n * Gets the cost of the next project in an organization.\n */\nexport async function getNextProjectCost(\n managementApiClient: ManagementApiClient,\n orgId: string\n): Promise<Cost> {\n const orgResponse = await managementApiClient.GET(\n '/v1/organizations/{slug}',\n {\n params: {\n path: {\n slug: orgId,\n },\n },\n }\n );\n\n assertSuccess(orgResponse, 'Failed to fetch organization');\n\n const projectsResponse = await managementApiClient.GET('/v1/projects');\n\n assertSuccess(projectsResponse, 'Failed to fetch projects');\n\n const org = orgResponse.data;\n const activeProjects = projectsResponse.data.filter(\n (project) =>\n project.organization_id === orgId &&\n !['INACTIVE', 'GOING_DOWN', 'REMOVED'].includes(project.status)\n );\n\n let amount = 0;\n\n if (org.plan !== 'free') {\n // If the organization is on a paid plan, the first project is included\n if (activeProjects.length > 0) {\n amount = PROJECT_COST_MONTHLY;\n }\n }\n\n return { type: 'project', recurrence: 'monthly', amount };\n}\n\n/**\n * Gets the cost for a database branch.\n */\nexport function getBranchCost(): Cost {\n return { type: 'branch', recurrence: 'hourly', amount: BRANCH_COST_HOURLY };\n}\n","export type ValueOf<T> = T[keyof T];\n\n// UnionToIntersection<A | B> = A & B\nexport type UnionToIntersection<U> = (\n U extends unknown ? (arg: U) => 0 : never\n) extends (arg: infer I) => 0\n ? I\n : never;\n\n// LastInUnion<A | B> = B\nexport type LastInUnion<U> =\n UnionToIntersection<U extends unknown ? (x: U) => 0 : never> extends (\n x: infer L\n ) => 0\n ? L\n : never;\n\n// UnionToTuple<A, B> = [A, B]\nexport type UnionToTuple<T, Last = LastInUnion<T>> = [T] extends [never]\n ? []\n : [Last, ...UnionToTuple<Exclude<T, Last>>];\n\n/**\n * Parses a key-value string into an object.\n *\n * @returns An object representing the key-value pairs\n *\n * @example\n * const result = parseKeyValueList(\"key1=value1\\nkey2=value2\");\n * console.log(result); // { key1: \"value1\", key2: \"value2\" }\n */\nexport function parseKeyValueList(data: string): { [key: string]: string } {\n return Object.fromEntries(\n data\n .split('\\n')\n .map((item) => item.split(/=(.*)/)) // split only on the first '='\n .filter(([key]) => key) // filter out empty keys\n .map(([key, value]) => [key, value ?? '']) // ensure value is not undefined\n );\n}\n\n/**\n * Creates a unique hash from a JavaScript object.\n * @param obj - The object to hash\n * @param length - Optional length to truncate the hash (default: full length)\n */\nexport async function hashObject(\n obj: Record<string, any>,\n length?: number\n): Promise<string> {\n // Sort object keys to ensure consistent output regardless of original key order\n const str = JSON.stringify(obj, (_, value) => {\n if (value && typeof value === 'object' && !Array.isArray(value)) {\n return Object.keys(value)\n .sort()\n .reduce<Record<string, any>>((result, key) => {\n result[key] = value[key];\n return result;\n }, {});\n }\n return value;\n });\n\n const buffer = await crypto.subtle.digest(\n 'SHA-256',\n new TextEncoder().encode(str)\n );\n\n // Convert to base64\n const base64Hash = btoa(String.fromCharCode(...new Uint8Array(buffer)));\n return base64Hash.slice(0, length);\n}\n","import { type Tool, tool } from '@supabase/mcp-utils';\nimport { z } from 'zod';\n\ntype RequireKeys<Injected, Params> = {\n [K in keyof Injected]: K extends keyof Params ? Injected[K] : never;\n};\n\nexport type InjectableTool<\n Params extends z.ZodObject<any> = z.ZodObject<any>,\n Result = unknown,\n Injected extends Partial<z.infer<Params>> = {},\n> = Tool<Params, Result> & {\n /**\n * Optionally injects static parameter values into the tool's\n * execute function and removes them from the parameter schema.\n *\n * Useful to scope tools to a specific project at config time\n * without redefining the tool.\n */\n inject?: Injected & RequireKeys<Injected, z.infer<Params>>;\n};\n\nexport function injectableTool<\n Params extends z.ZodObject<any>,\n Result,\n Injected extends Partial<z.infer<Params>>,\n>({\n description,\n parameters,\n inject,\n execute,\n}: InjectableTool<Params, Result, Injected>) {\n // If all injected parameters are undefined, return the original tool\n if (!inject || Object.values(inject).every((value) => value === undefined)) {\n return tool({\n description,\n parameters,\n execute,\n });\n }\n\n // Create a mask used to remove injected parameters from the schema\n const mask = Object.fromEntries(\n Object.entries(inject)\n .filter(([_, value]) => value !== undefined)\n .map(([key]) => [key, true as const])\n );\n\n type NonNullableKeys = {\n [K in keyof Injected]: Injected[K] extends undefined ? never : K;\n }[keyof Injected];\n\n type CleanParams =\n z.infer<Params> extends any\n ? {\n [K in keyof z.infer<Params> as K extends NonNullableKeys\n ? never\n : K]: z.infer<Params>[K];\n }\n : never;\n\n return tool({\n description,\n parameters: parameters.omit(mask),\n execute: (args) => execute({ ...args, ...inject }),\n }) as Tool<z.ZodObject<any, any, any, CleanParams>, Result>;\n}\n","import { z } from 'zod';\nimport {\n assertSuccess,\n type ManagementApiClient,\n} from '../management-api/index.js';\nimport { listExtensionsSql, listTablesSql } from '../pg-meta/index.js';\nimport type { PostgresExtension, PostgresTable } from '../pg-meta/types.js';\nimport { injectableTool } from './util.js';\n\nexport type DatabaseOperationToolsOptions = {\n managementApiClient: ManagementApiClient;\n projectId?: string;\n readOnly?: boolean;\n};\n\nexport function getDatabaseOperationTools({\n managementApiClient,\n projectId,\n readOnly,\n}: DatabaseOperationToolsOptions) {\n async function executeSql<T>(projectId: string, query: string): Promise<T[]> {\n const response = await managementApiClient.POST(\n '/v1/projects/{ref}/database/query',\n {\n params: {\n path: {\n ref: projectId,\n },\n },\n body: {\n query,\n read_only: readOnly,\n },\n }\n );\n\n assertSuccess(response, 'Failed to execute SQL query');\n\n return response.data as unknown as T[];\n }\n\n const project_id = projectId;\n\n const databaseOperationTools = {\n list_tables: injectableTool({\n description: 'Lists all tables in one or more schemas.',\n parameters: z.object({\n project_id: z.string(),\n schemas: z\n .array(z.string())\n .describe('List of schemas to include. Defaults to all schemas.')\n .default(['public']),\n }),\n inject: { project_id },\n execute: async ({ project_id, schemas }) => {\n const sql = listTablesSql(schemas);\n const data = await executeSql<PostgresTable>(project_id, sql);\n return data;\n },\n }),\n list_extensions: injectableTool({\n description: 'Lists all extensions in the database.',\n parameters: z.object({\n project_id: z.string(),\n }),\n inject: { project_id },\n execute: async ({ project_id }) => {\n const sql = listExtensionsSql();\n const data = await executeSql<PostgresExtension>(project_id, sql);\n return data;\n },\n }),\n list_migrations: injectableTool({\n description: 'Lists all migrations in the database.',\n parameters: z.object({\n project_id: z.string(),\n }),\n inject: { project_id },\n execute: async ({ project_id }) => {\n const response = await managementApiClient.GET(\n '/v1/projects/{ref}/database/migrations',\n {\n params: {\n path: {\n ref: project_id,\n },\n },\n }\n );\n\n assertSuccess(response, 'Failed to fetch migrations');\n\n return response.data;\n },\n }),\n apply_migration: injectableTool({\n description:\n 'Applies a migration to the database. Use this when executing DDL operations. Do not hardcode references to generated IDs in data migrations.',\n parameters: z.object({\n project_id: z.string(),\n name: z.string().describe('The name of the migration in snake_case'),\n query: z.string().describe('The SQL query to apply'),\n }),\n inject: { project_id },\n execute: async ({ project_id, name, query }) => {\n if (readOnly) {\n throw new Error('Cannot apply migration in read-only mode.');\n }\n\n const response = await managementApiClient.POST(\n '/v1/projects/{ref}/database/migrations',\n {\n params: {\n path: {\n ref: project_id,\n },\n },\n body: {\n name,\n query,\n },\n }\n );\n\n assertSuccess(response, 'Failed to apply migration');\n\n return response.data;\n },\n }),\n execute_sql: injectableTool({\n description:\n 'Executes raw SQL in the Postgres database. Use `apply_migration` instead for DDL operations.',\n parameters: z.object({\n project_id: z.string(),\n query: z.string().describe('The SQL query to execute'),\n }),\n inject: { project_id },\n execute: async ({ query, project_id }) => {\n return await executeSql(project_id, query);\n },\n }),\n };\n\n type test = z.infer<\n (typeof databaseOperationTools)['list_tables']['parameters']\n >;\n\n return databaseOperationTools;\n}\n","import { stripIndent } from 'common-tags';\nimport columnsSql from './columns.sql';\nimport extensionsSql from './extensions.sql';\nimport tablesSql from './tables.sql';\n\nexport const SYSTEM_SCHEMAS = [\n 'information_schema',\n 'pg_catalog',\n 'pg_toast',\n '_timescaledb_internal',\n];\n\n/**\n * Generates the SQL query to list tables in the database.\n */\nexport function listTablesSql(schemas: string[] = []) {\n let sql = stripIndent`\n with\n tables as (${tablesSql}),\n columns as (${columnsSql})\n select\n *,\n ${coalesceRowsToArray('columns', 'columns.table_id = tables.id')}\n from tables\n `;\n\n sql += '\\n';\n\n if (schemas.length > 0) {\n sql += `where schema in (${schemas.map((s) => `'${s}'`).join(',')})`;\n } else {\n sql += `where schema not in (${SYSTEM_SCHEMAS.map((s) => `'${s}'`).join(',')})`;\n }\n\n return sql;\n}\n\n/**\n * Generates the SQL query to list all extensions in the database.\n */\nexport function listExtensionsSql() {\n return extensionsSql;\n}\n\n/**\n * Generates a SQL segment that coalesces rows into an array of JSON objects.\n */\nexport const coalesceRowsToArray = (source: string, filter: string) => {\n return stripIndent`\n COALESCE(\n (\n SELECT\n array_agg(row_to_json(${source})) FILTER (WHERE ${filter})\n FROM\n ${source}\n ),\n '{}'\n ) AS ${source}\n `;\n};\n","-- Adapted from information_schema.columns\n\nSELECT\n c.oid :: int8 AS table_id,\n nc.nspname AS schema,\n c.relname AS table,\n (c.oid || '.' || a.attnum) AS id,\n a.attnum AS ordinal_position,\n a.attname AS name,\n CASE\n WHEN a.atthasdef THEN pg_get_expr(ad.adbin, ad.adrelid)\n ELSE NULL\n END AS default_value,\n CASE\n WHEN t.typtype = 'd' THEN CASE\n WHEN bt.typelem <> 0 :: oid\n AND bt.typlen = -1 THEN 'ARRAY'\n WHEN nbt.nspname = 'pg_catalog' THEN format_type(t.typbasetype, NULL)\n ELSE 'USER-DEFINED'\n END\n ELSE CASE\n WHEN t.typelem <> 0 :: oid\n AND t.typlen = -1 THEN 'ARRAY'\n WHEN nt.nspname = 'pg_catalog' THEN format_type(a.atttypid, NULL)\n ELSE 'USER-DEFINED'\n END\n END AS data_type,\n COALESCE(bt.typname, t.typname) AS format,\n a.attidentity IN ('a', 'd') AS is_identity,\n CASE\n a.attidentity\n WHEN 'a' THEN 'ALWAYS'\n WHEN 'd' THEN 'BY DEFAULT'\n ELSE NULL\n END AS identity_generation,\n a.attgenerated IN ('s') AS is_generated,\n NOT (\n a.attnotnull\n OR t.typtype = 'd' AND t.typnotnull\n ) AS is_nullable,\n (\n c.relkind IN ('r', 'p')\n OR c.relkind IN ('v', 'f') AND pg_column_is_updatable(c.oid, a.attnum, FALSE)\n ) AS is_updatable,\n uniques.table_id IS NOT NULL AS is_unique,\n check_constraints.definition AS \"check\",\n array_to_json(\n array(\n SELECT\n enumlabel\n FROM\n pg_catalog.pg_enum enums\n WHERE\n enums.enumtypid = coalesce(bt.oid, t.oid)\n OR enums.enumtypid = coalesce(bt.typelem, t.typelem)\n ORDER BY\n enums.enumsortorder\n )\n ) AS enums,\n col_description(c.oid, a.attnum) AS comment\nFROM\n pg_attribute a\n LEFT JOIN pg_attrdef ad ON a.attrelid = ad.adrelid\n AND a.attnum = ad.adnum\n JOIN (\n pg_class c\n JOIN pg_namespace nc ON c.relnamespace = nc.oid\n ) ON a.attrelid = c.oid\n JOIN (\n pg_type t\n JOIN pg_namespace nt ON t.typnamespace = nt.oid\n ) ON a.atttypid = t.oid\n LEFT JOIN (\n pg_type bt\n JOIN pg_namespace nbt ON bt.typnamespace = nbt.oid\n ) ON t.typtype = 'd'\n AND t.typbasetype = bt.oid\n LEFT JOIN (\n SELECT DISTINCT ON (table_id, ordinal_position)\n conrelid AS table_id,\n conkey[1] AS ordinal_position\n FROM pg_catalog.pg_constraint\n WHERE contype = 'u' AND cardinality(conkey) = 1\n ) AS uniques ON uniques.table_id = c.oid AND uniques.ordinal_position = a.attnum\n LEFT JOIN (\n -- We only select the first column check\n SELECT DISTINCT ON (table_id, ordinal_position)\n conrelid AS table_id,\n conkey[1] AS ordinal_position,\n substring(\n pg_get_constraintdef(pg_constraint.oid, true),\n 8,\n length(pg_get_constraintdef(pg_constraint.oid, true)) - 8\n ) AS \"definition\"\n FROM pg_constraint\n WHERE contype = 'c' AND cardinality(conkey) = 1\n ORDER BY table_id, ordinal_position, oid asc\n ) AS check_constraints ON check_constraints.table_id = c.oid AND check_constraints.ordinal_position = a.attnum\nWHERE\n NOT pg_is_other_temp_schema(nc.oid)\n AND a.attnum > 0\n AND NOT a.attisdropped\n AND (c.relkind IN ('r', 'v', 'm', 'f', 'p'))\n AND (\n pg_has_role(c.relowner, 'USAGE')\n OR has_column_privilege(\n c.oid,\n a.attnum,\n 'SELECT, INSERT, UPDATE, REFERENCES'\n )\n )\n","SELECT\n e.name,\n n.nspname AS schema,\n e.default_version,\n x.extversion AS installed_version,\n e.comment\nFROM\n pg_available_extensions() e(name, default_version, comment)\n LEFT JOIN pg_extension x ON e.name = x.extname\n LEFT JOIN pg_namespace n ON x.extnamespace = n.oid\n","SELECT\n c.oid :: int8 AS id,\n nc.nspname AS schema,\n c.relname AS name,\n c.relrowsecurity AS rls_enabled,\n c.relforcerowsecurity AS rls_forced,\n CASE\n WHEN c.relreplident = 'd' THEN 'DEFAULT'\n WHEN c.relreplident = 'i' THEN 'INDEX'\n WHEN c.relreplident = 'f' THEN 'FULL'\n ELSE 'NOTHING'\n END AS replica_identity,\n pg_total_relation_size(format('%I.%I', nc.nspname, c.relname)) :: int8 AS bytes,\n pg_size_pretty(\n pg_total_relation_size(format('%I.%I', nc.nspname, c.relname))\n ) AS size,\n pg_stat_get_live_tuples(c.oid) AS live_rows_estimate,\n pg_stat_get_dead_tuples(c.oid) AS dead_rows_estimate,\n obj_description(c.oid) AS comment,\n coalesce(pk.primary_keys, '[]') as primary_keys,\n coalesce(\n jsonb_agg(relationships) filter (where relationships is not null),\n '[]'\n ) as relationships\nFROM\n pg_namespace nc\n JOIN pg_class c ON nc.oid = c.relnamespace\n left join (\n select\n table_id,\n jsonb_agg(_pk.*) as primary_keys\n from (\n select\n n.nspname as schema,\n c.relname as table_name,\n a.attname as name,\n c.oid :: int8 as table_id\n from\n pg_index i,\n pg_class c,\n pg_attribute a,\n pg_namespace n\n where\n i.indrelid = c.oid\n and c.relnamespace = n.oid\n and a.attrelid = c.oid\n and a.attnum = any (i.indkey)\n and i.indisprimary\n ) as _pk\n group by table_id\n ) as pk\n on pk.table_id = c.oid\n left join (\n select\n c.oid :: int8 as id,\n c.conname as constraint_name,\n nsa.nspname as source_schema,\n csa.relname as source_table_name,\n sa.attname as source_column_name,\n nta.nspname as target_table_schema,\n cta.relname as target_table_name,\n ta.attname as target_column_name\n from\n pg_constraint c\n join (\n pg_attribute sa\n join pg_class csa on sa.attrelid = csa.oid\n join pg_namespace nsa on csa.relnamespace = nsa.oid\n ) on sa.attrelid = c.conrelid and sa.attnum = any (c.conkey)\n join (\n pg_attribute ta\n join pg_class cta on ta.attrelid = cta.oid\n join pg_namespace nta on cta.relnamespace = nta.oid\n ) on ta.attrelid = c.confrelid and ta.attnum = any (c.confkey)\n where\n c.contype = 'f'\n ) as relationships\n on (relationships.source_schema = nc.nspname and relationships.source_table_name = c.relname)\n or (relationships.target_table_schema = nc.nspname and relationships.target_table_name = c.relname)\nWHERE\n c.relkind IN ('r', 'p')\n AND NOT pg_is_other_temp_schema(nc.oid)\n AND (\n pg_has_role(c.relowner, 'USAGE')\n OR has_table_privilege(\n c.oid,\n 'SELECT, INSERT, UPDATE, DELETE, TRUNCATE, REFERENCES, TRIGGER'\n )\n OR has_any_column_privilege(c.oid, 'SELECT, INSERT, UPDATE, REFERENCES')\n )\ngroup by\n c.oid,\n c.relname,\n c.relrowsecurity,\n c.relforcerowsecurity,\n c.relreplident,\n nc.nspname,\n pk.primary_keys\n","import { z } from 'zod';\nimport { getLogQuery } from '../logs.js';\nimport {\n assertSuccess,\n type ManagementApiClient,\n} from '../management-api/index.js';\nimport { injectableTool } from './util.js';\n\nexport type DebuggingToolsOptions = {\n managementApiClient: ManagementApiClient;\n projectId?: string;\n};\n\nexport function getDebuggingTools({\n managementApiClient,\n projectId,\n}: DebuggingToolsOptions) {\n const project_id = projectId;\n\n return {\n get_logs: injectableTool({\n description:\n 'Gets logs for a Supabase project by service type. Use this to help debug problems with your app. This will only return logs within the last minute. If the logs you are looking for are older than 1 minute, re-run your test to reproduce them.',\n parameters: z.object({\n project_id: z.string(),\n service: z\n .enum([\n 'api',\n 'branch-action',\n 'postgres',\n 'edge-function',\n 'auth',\n 'storage',\n 'realtime',\n ])\n .describe('The service to fetch logs for'),\n }),\n inject: { project_id },\n execute: async ({ project_id, service }) => {\n // Omitting start and end time defaults to the last minute.\n // But since branch actions are async, we need to wait longer\n // for jobs to be scheduled and run to completion.\n const timestamp =\n service === 'branch-action'\n ? new Date(Date.now() - 5 * 60 * 1000)\n : undefined;\n const response = await managementApiClient.GET(\n '/v1/projects/{ref}/analytics/endpoints/logs.all',\n {\n params: {\n path: {\n ref: project_id,\n },\n query: {\n iso_timestamp_start: timestamp?.toISOString(),\n sql: getLogQuery(service),\n },\n },\n }\n );\n\n assertSuccess(response, 'Failed to fetch logs');\n\n return response.data;\n },\n }),\n };\n}\n","import { stripIndent } from 'common-tags';\n\nexport function getLogQuery(\n service:\n | 'api'\n | 'branch-action'\n | 'postgres'\n | 'edge-function'\n | 'auth'\n | 'storage'\n | 'realtime',\n limit: number = 100\n) {\n switch (service) {\n case 'api':\n return stripIndent`\n select id, identifier, timestamp, event_message, request.method, request.path, response.status_code\n from edge_logs\n cross join unnest(metadata) as m\n cross join unnest(m.request) as request\n cross join unnest(m.response) as response\n order by timestamp desc\n limit ${limit}\n `;\n case 'branch-action':\n return stripIndent`\n select workflow_run, workflow_run_logs.timestamp, id, event_message from workflow_run_logs\n order by timestamp desc\n limit ${limit}\n `;\n case 'postgres':\n return stripIndent`\n select identifier, postgres_logs.timestamp, id, event_message, parsed.error_severity from postgres_logs\n cross join unnest(metadata) as m\n cross join unnest(m.parsed) as parsed\n order by timestamp desc\n limit ${limit}\n `;\n case 'edge-function':\n return stripIndent`\n select id, function_edge_logs.timestamp, event_message, response.status_code, request.method, m.function_id, m.execution_time_ms, m.deployment_id, m.version from function_edge_logs\n cross join unnest(metadata) as m\n cross join unnest(m.response) as response\n cross join unnest(m.request) as request\n order by timestamp desc\n limit ${limit}\n `;\n case 'auth':\n return stripIndent`\n select id, auth_logs.timestamp, event_message, metadata.level, metadata.status, metadata.path, metadata.msg as msg, metadata.error from auth_logs\n cross join unnest(metadata) as metadata\n order by timestamp desc\n limit ${limit}\n `;\n case 'storage':\n return stripIndent`\n select id, storage_logs.timestamp, event_message from storage_logs\n order by timestamp desc\n limit ${limit}\n `;\n case 'realtime':\n return stripIndent`\n select id, realtime_logs.timestamp, event_message from realtime_logs\n order by timestamp desc\n limit ${limit}\n `;\n default:\n throw new Error(`unsupported log service type: ${service}`);\n }\n}\n","import { z } from 'zod';\nimport {\n assertSuccess,\n type ManagementApiClient,\n} from '../management-api/index.js';\nimport { injectableTool } from './util.js';\n\nexport type DevelopmentToolsOptions = {\n managementApiClient: ManagementApiClient;\n projectId?: string;\n};\n\nexport function getDevelopmentTools({\n managementApiClient,\n projectId,\n}: DevelopmentToolsOptions) {\n const project_id = projectId;\n\n return {\n get_project_url: injectableTool({\n description: 'Gets the API URL for a project.',\n parameters: z.object({\n project_id: z.string(),\n }),\n inject: { project_id },\n execute: async ({ project_id }) => {\n return `https://${project_id}.supabase.co`;\n },\n }),\n get_anon_key: injectableTool({\n description: 'Gets the anonymous API key for a project.',\n parameters: z.object({\n project_id: z.string(),\n }),\n inject: { project_id },\n execute: async ({ project_id }) => {\n const response = await managementApiClient.GET(\n '/v1/projects/{ref}/api-keys',\n {\n params: {\n path: {\n ref: project_id,\n },\n query: {\n reveal: false,\n },\n },\n }\n );\n\n assertSuccess(response, 'Failed to fetch API keys');\n\n const anonKey = response.data?.find((key) => key.name === 'anon');\n\n if (!anonKey) {\n throw new Error('Anonymous key not found');\n }\n\n return anonKey.api_key;\n },\n }),\n generate_typescript_types: injectableTool({\n description: 'Generates TypeScript types for a project.',\n parameters: z.object({\n project_id: z.string(),\n }),\n inject: { project_id },\n execute: async ({ project_id }) => {\n const response = await managementApiClient.GET(\n '/v1/projects/{ref}/types/typescript',\n {\n params: {\n path: {\n ref: project_id,\n },\n },\n }\n );\n\n assertSuccess(response, 'Failed to fetch TypeScript types');\n\n return response.data;\n },\n }),\n };\n}\n","import { z } from 'zod';\nimport { edgeFunctionExample, getFullEdgeFunction } from '../edge-function.js';\nimport {\n assertSuccess,\n type ManagementApiClient,\n} from '../management-api/index.js';\nimport { injectableTool } from './util.js';\n\nexport type EdgeFunctionToolsOptions = {\n managementApiClient: ManagementApiClient;\n projectId?: string;\n};\n\nexport function getEdgeFunctionTools({\n managementApiClient,\n projectId,\n}: EdgeFunctionToolsOptions) {\n const project_id = projectId;\n\n return {\n list_edge_functions: injectableTool({\n description: 'Lists all Edge Functions in a Supabase project.',\n parameters: z.object({\n project_id: z.string(),\n }),\n inject: { project_id },\n execute: async ({ project_id }) => {\n const response = await managementApiClient.GET(\n '/v1/projects/{ref}/functions',\n {\n params: {\n path: {\n ref: project_id,\n },\n },\n }\n );\n\n assertSuccess(response, 'Failed to fetch Edge Functions');\n\n // Fetch files for each Edge Function\n const edgeFunctions = await Promise.all(\n response.data.map(async (listedFunction) => {\n const { data: edgeFunction, error } = await getFullEdgeFunction(\n managementApiClient,\n project_id,\n listedFunction.slug\n );\n\n if (error) {\n throw error;\n }\n\n return edgeFunction;\n })\n );\n\n return edgeFunctions;\n },\n }),\n deploy_edge_function: injectableTool({\n description: `Deploys an Edge Function to a Supabase project. If the function already exists, this will create a new version. Example:\\n\\n${edgeFunctionExample}`,\n parameters: z.object({\n project_id: z.string(),\n name: z.string().describe('The name of the function'),\n entrypoint_path: z\n .string()\n .default('index.ts')\n .describe('The entrypoint of the function'),\n import_map_path: z\n .string()\n .describe('The import map for the function.')\n .optional(),\n files: z\n .array(\n z.object({\n name: z.string(),\n content: z.string(),\n })\n )\n .describe(\n 'The files to upload. This should include the entrypoint and any relative dependencies.'\n ),\n }),\n inject: { project_id },\n execute: async ({\n project_id,\n name,\n entrypoint_path,\n import_map_path,\n files,\n }) => {\n const { data: existingEdgeFunction } = await getFullEdgeFunction(\n managementApiClient,\n project_id,\n name\n );\n\n const import_map_file = files.find((file) =>\n ['deno.json', 'import_map.json'].includes(file.name)\n );\n\n // Use existing import map path or file name heuristic if not provided\n import_map_path ??=\n existingEdgeFunction?.import_map_path ?? import_map_file?.name;\n\n const response = await managementApiClient.POST(\n '/v1/projects/{ref}/functions/deploy',\n {\n params: {\n path: {\n ref: project_id,\n },\n query: { slug: name },\n },\n body: {\n metadata: {\n name,\n entrypoint_path,\n import_map_path,\n },\n file: files as any, // We need to pass file name and content to our serializer\n },\n bodySerializer(body) {\n const formData = new FormData();\n\n const blob = new Blob([JSON.stringify(body.metadata)], {\n type: 'application/json',\n });\n formData.append('metadata', blob);\n\n body.file?.forEach((f: any) => {\n const file: { name: string; content: string } = f;\n const blob = new Blob([file.content], {\n type: 'application/typescript',\n });\n formData.append('file', blob, file.name);\n });\n\n return formData;\n },\n }\n );\n\n assertSuccess(response, 'Failed to deploy Edge Function');\n\n return response.data;\n },\n }),\n };\n}\n","import { codeBlock } from 'common-tags';\nimport { fileURLToPath } from 'url';\nimport { extractFiles } from './eszip.js';\nimport {\n assertSuccess,\n type ManagementApiClient,\n} from './management-api/index.js';\n\n/**\n * Gets the deployment ID for an Edge Function.\n */\nexport function getDeploymentId(\n projectId: string,\n functionId: string,\n functionVersion: number\n): string {\n return `${projectId}_${functionId}_${functionVersion}`;\n}\n\n/**\n * Gets the path prefix applied to each file in an Edge Function.\n */\nexport function getPathPrefix(deploymentId: string) {\n return `/tmp/user_fn_${deploymentId}/`;\n}\n\nexport const edgeFunctionExample = codeBlock`\n import \"jsr:@supabase/functions-js/edge-runtime.d.ts\";\n\n Deno.serve(async (req: Request) => {\n const data = {\n message: \"Hello there!\"\n };\n \n return new Response(JSON.stringify(data), {\n headers: {\n 'Content-Type': 'application/json',\n 'Connection': 'keep-alive'\n }\n });\n });\n`;\n\n/**\n * Fetches a full Edge Function from the Supabase Management API.\n\n * - Includes both function metadata and the contents of each file.\n * - Normalizes file paths to be relative to the project root.\n */\nexport async function getFullEdgeFunction(\n managementApiClient: ManagementApiClient,\n projectId: string,\n functionSlug: string\n) {\n const functionResponse = await managementApiClient.GET(\n '/v1/projects/{ref}/functions/{function_slug}',\n {\n params: {\n path: {\n ref: projectId,\n function_slug: functionSlug,\n },\n },\n }\n );\n\n if (functionResponse.error) {\n return {\n data: undefined,\n error: functionResponse.error as { message: string },\n };\n }\n\n assertSuccess(functionResponse, 'Failed to fetch Edge Function');\n\n const edgeFunction = functionResponse.data;\n\n const deploymentId = getDeploymentId(\n projectId,\n edgeFunction.id,\n edgeFunction.version\n );\n\n const pathPrefix = getPathPrefix(deploymentId);\n\n const entrypoint_path = edgeFunction.entrypoint_path\n ? fileURLToPath(edgeFunction.entrypoint_path).replace(pathPrefix, '')\n : undefined;\n\n const import_map_path = edgeFunction.import_map_path\n ? fileURLToPath(edgeFunction.import_map_path).replace(pathPrefix, '')\n : undefined;\n\n const eszipResponse = await managementApiClient.GET(\n '/v1/projects/{ref}/functions/{function_slug}/body',\n {\n params: {\n path: {\n ref: projectId,\n function_slug: functionSlug,\n },\n },\n parseAs: 'arrayBuffer',\n }\n );\n\n assertSuccess(eszipResponse, 'Failed to fetch Edge Function eszip bundle');\n\n const extractedFiles = await extractFiles(\n new Uint8Array(eszipResponse.data),\n pathPrefix\n );\n\n const files = await Promise.all(\n extractedFiles.map(async (file) => ({\n name: file.name,\n content: await file.text(),\n }))\n );\n\n const normalizedFunction = {\n ...edgeFunction,\n entrypoint_path,\n import_map_path,\n files,\n };\n\n return { data: normalizedFunction, error: undefined };\n}\n","import { build, Parser } from '@deno/eszip';\nimport { join, relative } from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport { z } from 'zod';\n\nconst parser = await Parser.createInstance();\nconst sourceMapSchema = z.object({\n version: z.number(),\n sources: z.array(z.string()),\n sourcesContent: z.array(z.string()).optional(),\n names: z.array(z.string()),\n mappings: z.string(),\n});\n\n/**\n * Extracts source files from an eszip archive.\n *\n * Optionally removes the given path prefix from file names.\n *\n * If a file contains a source map, it will return the\n * original TypeScript source instead of the transpiled file.\n */\nexport async function extractFiles(\n eszip: Uint8Array,\n pathPrefix: string = '/'\n) {\n let specifiers: string[] = [];\n\n if (eszip instanceof ReadableStream) {\n const reader = eszip.getReader({ mode: 'byob' });\n specifiers = await parser.parse(reader);\n } else {\n specifiers = await parser.parseBytes(eszip);\n }\n\n await parser.load();\n\n const fileSpecifiers = specifiers.filter((specifier) =>\n specifier.startsWith('file://')\n );\n\n const files = await Promise.all(\n fileSpecifiers.map(async (specifier) => {\n const source: string = await parser.getModuleSource(specifier);\n const sourceMapString: string =\n await parser.getModuleSourceMap(specifier);\n\n const filePath = relative(pathPrefix, fileURLToPath(specifier));\n\n const file = new File([source], filePath, {\n type: 'text/plain',\n });\n\n if (!sourceMapString) {\n return file;\n }\n\n const sourceMap = sourceMapSchema.parse(JSON.parse(sourceMapString));\n\n const [typeScriptSource] = sourceMap.sourcesContent ?? [];\n\n if (!typeScriptSource) {\n return file;\n }\n\n const sourceFile = new File([typeScriptSource], filePath, {\n type: 'application/typescript',\n });\n\n return sourceFile;\n })\n );\n\n return files;\n}\n\n/**\n * Bundles files into an eszip archive.\n *\n * Optionally prefixes the file names with a given path.\n */\nexport async function bundleFiles(files: File[], pathPrefix: string = '/') {\n const specifiers = files.map(\n (file) => `file://${join(pathPrefix, file.name)}`\n );\n const eszip = await build(specifiers, async (specifier: string) => {\n const url = new URL(specifier);\n const scheme = url.protocol;\n\n switch (scheme) {\n case 'file:': {\n const file = files.find(\n (file) => `file://${join(pathPrefix, file.name)}` === specifier\n );\n\n if (!file) {\n throw new Error(`File not found: ${specifier}`);\n }\n\n const headers = {\n 'content-type': file.type,\n };\n\n const content = await file.text();\n\n return {\n kind: 'module',\n specifier,\n headers,\n content,\n };\n }\n case 'http:':\n case 'https:': {\n const response = await fetch(specifier);\n if (!response.ok) {\n throw new Error(`Failed to fetch ${specifier}: ${response.status}`);\n }\n\n // Header keys must be lower case\n const headers = Object.fromEntries(\n Array.from(response.headers.entries()).map(([key, value]) => [\n key.toLowerCase(),\n value,\n ])\n );\n\n const content = await response.text();\n\n return {\n kind: 'module',\n specifier,\n headers,\n content,\n };\n }\n default: {\n throw new Error(`Unsupported scheme: ${scheme}`);\n }\n }\n });\n\n return eszip;\n}\n","import { tool } from '@supabase/mcp-utils';\nimport { z } from 'zod';\nimport {\n assertSuccess,\n type ManagementApiClient,\n} from '../management-api/index.js';\nimport { generatePassword } from '../password.js';\nimport { type Cost, getBranchCost, getNextProjectCost } from '../pricing.js';\nimport {\n AWS_REGION_CODES,\n getClosestAwsRegion,\n getCountryCode,\n getCountryCoordinates,\n} from '../regions.js';\nimport { hashObject } from '../util.js';\n\nexport type ProjectManagementToolsOptions = {\n managementApiClient: ManagementApiClient;\n};\n\nexport function getProjectManagementTools({\n managementApiClient,\n}: ProjectManagementToolsOptions) {\n async function getClosestRegion() {\n return getClosestAwsRegion(getCountryCoordinates(await getCountryCode()))\n .code;\n }\n\n return {\n list_organizations: tool({\n description: 'Lists all organizations that the user is a member of.',\n parameters: z.object({}),\n execute: async () => {\n const response = await managementApiClient.GET('/v1/organizations');\n\n assertSuccess(response, 'Failed to fetch organizations');\n\n return response.data;\n },\n }),\n get_organization: tool({\n description:\n 'Gets details for an organization. Includes subscription plan.',\n parameters: z.object({\n id: z.string().describe('The organization ID'),\n }),\n execute: async ({ id: organizationId }) => {\n const response = await managementApiClient.GET(\n '/v1/organizations/{slug}',\n {\n params: {\n path: {\n slug: organizationId,\n },\n },\n }\n );\n\n assertSuccess(response, 'Failed to fetch organization');\n\n return response.data;\n },\n }),\n list_projects: tool({\n description:\n 'Lists all Supabase projects for the user. Use this to help discover the project ID of the project that the user is working on.',\n parameters: z.object({}),\n execute: async () => {\n const response = await managementApiClient.GET('/v1/projects');\n\n assertSuccess(response, 'Failed to fetch projects');\n\n return response.data;\n },\n }),\n get_project: tool({\n description: 'Gets details for a Supabase project.',\n parameters: z.object({\n id: z.string().describe('The project ID'),\n }),\n execute: async ({ id }) => {\n const response = await managementApiClient.GET('/v1/projects/{ref}', {\n params: {\n path: {\n ref: id,\n },\n },\n });\n assertSuccess(response, 'Failed to fetch project');\n return response.data;\n },\n }),\n get_cost: tool({\n description:\n 'Gets the cost of creating a new project or branch. Never assume organization as costs can be different for each.',\n parameters: z.object({\n type: z.enum(['project', 'branch']),\n organization_id: z\n .string()\n .describe('The organization ID. Always ask the user.'),\n }),\n execute: async ({ type, organization_id }) => {\n function generateResponse(cost: Cost) {\n return `The new ${type} will cost $${cost.amount} ${cost.recurrence}. You must repeat this to the user and confirm their understanding.`;\n }\n switch (type) {\n case 'project': {\n const cost = await getNextProjectCost(\n managementApiClient,\n organization_id\n );\n return generateResponse(cost);\n }\n case 'branch': {\n const cost = getBranchCost();\n return generateResponse(cost);\n }\n default:\n throw new Error(`Unknown cost type: ${type}`);\n }\n },\n }),\n confirm_cost: tool({\n description:\n 'Ask the user to confirm their understanding of the cost of creating a new project or branch. Call `get_cost` first. Returns a unique ID for this confirmation which should be passed to `create_project` or `create_branch`.',\n parameters: z.object({\n type: z.enum(['project', 'branch']),\n recurrence: z.enum(['hourly', 'monthly']),\n amount: z.number(),\n }),\n execute: async (cost) => {\n return await hashObject(cost);\n },\n }),\n create_project: tool({\n description:\n 'Creates a new Supabase project. Always ask the user which organization to create the project in. The project can take a few minutes to initialize - use `get_project` to check the status.',\n parameters: z.object({\n name: z.string().describe('The name of the project'),\n region: z.optional(\n z\n .enum(AWS_REGION_CODES)\n .describe(\n 'The region to create the project in. Defaults to the closest region.'\n )\n ),\n organization_id: z.string(),\n confirm_cost_id: z\n .string({\n required_error:\n 'User must confirm understanding of costs before creating a project.',\n })\n .describe('The cost confirmation ID. Call `confirm_cost` first.'),\n }),\n execute: async ({ name, region, organization_id, confirm_cost_id }) => {\n const cost = await getNextProjectCost(\n managementApiClient,\n organization_id\n );\n const costHash = await hashObject(cost);\n if (costHash !== confirm_cost_id) {\n throw new Error(\n 'Cost confirmation ID does not match the expected cost of creating a project.'\n );\n }\n\n const response = await managementApiClient.POST('/v1/projects', {\n body: {\n name,\n region: region ?? (await getClosestRegion()),\n organization_id,\n db_pass: generatePassword({\n length: 16,\n numbers: true,\n uppercase: true,\n lowercase: true,\n }),\n },\n });\n\n assertSuccess(response, 'Failed to create project');\n\n return response.data;\n },\n }),\n pause_project: tool({\n description: 'Pauses a Supabase project.',\n parameters: z.object({\n project_id: z.string(),\n }),\n execute: async ({ project_id }) => {\n const response = await managementApiClient.POST(\n '/v1/projects/{ref}/pause',\n {\n params: {\n path: {\n ref: project_id,\n },\n },\n }\n );\n\n assertSuccess(response, 'Failed to pause project');\n },\n }),\n restore_project: tool({\n description: 'Restores a Supabase project.',\n parameters: z.object({\n project_id: z.string(),\n }),\n execute: async ({ project_id }) => {\n const response = await managementApiClient.POST(\n '/v1/projects/{ref}/restore',\n {\n params: {\n path: {\n ref: project_id,\n },\n },\n body: {},\n }\n );\n\n assertSuccess(response, 'Failed to restore project');\n },\n }),\n };\n}\n","const UPPERCASE_CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';\nconst LOWERCASE_CHARS = 'abcdefghijklmnopqrstuvwxyz';\nconst NUMBER_CHARS = '0123456789';\nconst SYMBOL_CHARS = '!@#$%^&*()_+~`|}{[]:;?><,./-=';\n\nexport type GeneratePasswordOptions = {\n length?: number;\n numbers?: boolean;\n uppercase?: boolean;\n lowercase?: boolean;\n symbols?: boolean;\n};\n\n/**\n * Generates a cryptographically secure random password.\n *\n * @returns The generated password\n */\nexport const generatePassword = ({\n length = 10,\n numbers = false,\n symbols = false,\n uppercase = true,\n lowercase = true,\n} = {}) => {\n // Build the character set based on options\n let chars = '';\n if (uppercase) {\n chars += UPPERCASE_CHARS;\n }\n if (lowercase) {\n chars += LOWERCASE_CHARS;\n }\n if (numbers) {\n chars += NUMBER_CHARS;\n }\n if (symbols) {\n chars += SYMBOL_CHARS;\n }\n\n if (chars.length === 0) {\n throw new Error('at least one character set must be selected');\n }\n\n const randomValues = new Uint32Array(length);\n crypto.getRandomValues(randomValues);\n\n // Map random values to our character set\n let password = '';\n for (let i = 0; i < length; i++) {\n const randomIndex = randomValues[i]! % chars.length;\n password += chars.charAt(randomIndex);\n }\n\n return password;\n};\n","import { parseKeyValueList, type UnionToTuple, type ValueOf } from './util.js';\n\nexport type AwsRegion = {\n code: string;\n displayName: string;\n location: Location;\n};\n\nexport type Location = {\n lat: number;\n lng: number;\n};\n\nexport const EARTH_RADIUS = 6371; // in kilometers\nexport const TRACE_URL = 'https://www.cloudflare.com/cdn-cgi/trace';\n\nexport const COUNTRY_COORDINATES = {\n AF: { lat: 33, lng: 65 },\n AX: { lat: 60.116667, lng: 19.9 },\n AL: { lat: 41, lng: 20 },\n DZ: { lat: 28, lng: 3 },\n AS: { lat: -14.3333, lng: -170 },\n AD: { lat: 42.5, lng: 1.6 },\n AO: { lat: -12.5, lng: 18.5 },\n AI: { lat: 18.25, lng: -63.1667 },\n AQ: { lat: -90, lng: 0 },\n AG: { lat: 17.05, lng: -61.8 },\n AR: { lat: -34, lng: -64 },\n AM: { lat: 40, lng: 45 },\n AW: { lat: 12.5, lng: -69.9667 },\n AU: { lat: -27, lng: 133 },\n AT: { lat: 47.3333, lng: 13.3333 },\n AZ: { lat: 40.5, lng: 47.5 },\n BS: { lat: 24.25, lng: -76 },\n BH: { lat: 26, lng: 50.55 },\n BD: { lat: 24, lng: 90 },\n BB: { lat: 13.1667, lng: -59.5333 },\n BY: { lat: 53, lng: 28 },\n BE: { lat: 50.8333, lng: 4 },\n BZ: { lat: 17.25, lng: -88.75 },\n BJ: { lat: 9.5, lng: 2.25 },\n BM: { lat: 32.3333, lng: -64.75 },\n BT: { lat: 27.5, lng: 90.5 },\n BO: { lat: -17, lng: -65 },\n BQ: { lat: 12.183333, lng: -68.233333 },\n BA: { lat: 44, lng: 18 },\n BW: { lat: -22, lng: 24 },\n BV: { lat: -54.4333, lng: 3.4 },\n BR: { lat: -10, lng: -55 },\n IO: { lat: -6, lng: 71.5 },\n BN: { lat: 4.5, lng: 114.6667 },\n BG: { lat: 43, lng: 25 },\n BF: { lat: 13, lng: -2 },\n MM: { lat: 22, lng: 98 },\n BI: { lat: -3.5, lng: 30 },\n KH: { lat: 13, lng: 105 },\n CM: { lat: 6, lng: 12 },\n CA: { lat: 60, lng: -95 },\n CV: { lat: 16, lng: -24 },\n KY: { lat: 19.5, lng: -80.5 },\n CF: { lat: 7, lng: 21 },\n TD: { lat: 15, lng: 19 },\n CL: { lat: -30, lng: -71 },\n CN: { lat: 35, lng: 105 },\n CX: { lat: -10.5, lng: 105.6667 },\n CC: { lat: -12.5, lng: 96.8333 },\n CO: { lat: 4, lng: -72 },\n KM: { lat: -12.1667, lng: 44.25 },\n CD: { lat: 0, lng: 25 },\n CG: { lat: -1, lng: 15 },\n CK: { lat: -21.2333, lng: -159.7667 },\n CR: { lat: 10, lng: -84 },\n CI: { lat: 8, lng: -5 },\n HR: { lat: 45.1667, lng: 15.5 },\n CU: { lat: 21.5, lng: -80 },\n CW: { lat: 12.166667, lng: -68.966667 },\n CY: { lat: 35, lng: 33 },\n CZ: { lat: 49.75, lng: 15.5 },\n DK: { lat: 56, lng: 10 },\n DJ: { lat: 11.5, lng: 43 },\n DM: { lat: 15.4167, lng: -61.3333 },\n DO: { lat: 19, lng: -70.6667 },\n EC: { lat: -2, lng: -77.5 },\n EG: { lat: 27, lng: 30 },\n SV: { lat: 13.8333, lng: -88.9167 },\n GQ: { lat: 2, lng: 10 },\n ER: { lat: 15, lng: 39 },\n EE: { lat: 59, lng: 26 },\n ET: { lat: 8, lng: 38 },\n FK: { lat: -51.75, lng: -59 },\n FO: { lat: 62, lng: -7 },\n FJ: { lat: -18, lng: 175 },\n FI: { lat: 64, lng: 26 },\n FR: { lat: 46, lng: 2 },\n GF: { lat: 4, lng: -53 },\n PF: { lat: -15, lng: -140 },\n TF: { lat: -43, lng: 67 },\n GA: { lat: -1, lng: 11.75 },\n GM: { lat: 13.4667, lng: -16.5667 },\n GE: { lat: 42, lng: 43.5 },\n DE: { lat: 51, lng: 9 },\n GH: { lat: 8, lng: -2 },\n GI: { lat: 36.1833, lng: -5.3667 },\n GR: { lat: 39, lng: 22 },\n GL: { lat: 72, lng: -40 },\n GD: { lat: 12.1167, lng: -61.6667 },\n GP: { lat: 16.25, lng: -61.5833 },\n GU: { lat: 13.4667, lng: 144.7833 },\n GT: { lat: 15.5, lng: -90.25 },\n GG: { lat: 49.5, lng: -2.56 },\n GW: { lat: 12, lng: -15 },\n GN: { lat: 11, lng: -10 },\n GY: { lat: 5, lng: -59 },\n HT: { lat: 19, lng: -72.4167 },\n HM: { lat: -53.1, lng: 72.5167 },\n VA: { lat: 41.9, lng: 12.45 },\n HN: { lat: 15, lng: -86.5 },\n HK: { lat: 22.25, lng: 114.1667 },\n HU: { lat: 47, lng: 20 },\n IS: { lat: 65, lng: -18 },\n IN: { lat: 20, lng: 77 },\n ID: { lat: -5, lng: 120 },\n IR: { lat: 32, lng: 53 },\n IQ: { lat: 33, lng: 44 },\n IE: { lat: 53, lng: -8 },\n IM: { lat: 54.23, lng: -4.55 },\n IL: { lat: 31.5, lng: 34.75 },\n IT: { lat: 42.8333, lng: 12.8333 },\n JM: { lat: 18.25, lng: -77.5 },\n JP: { lat: 36, lng: 138 },\n JE: { lat: 49.21, lng: -2.13 },\n JO: { lat: 31, lng: 36 },\n KZ: { lat: 48, lng: 68 },\n KE: { lat: 1, lng: 38 },\n KI: { lat: 1.4167, lng: 173 },\n KP: { lat: 40, lng: 127 },\n KR: { lat: 37, lng: 127.5 },\n XK: { lat: 42.583333, lng: 21 },\n KW: { lat: 29.3375, lng: 47.6581 },\n KG: { lat: 41, lng: 75 },\n LA: { lat: 18, lng: 105 },\n LV: { lat: 57, lng: 25 },\n LB: { lat: 33.8333, lng: 35.8333 },\n LS: { lat: -29.5, lng: 28.5 },\n LR: { lat: 6.5, lng: -9.5 },\n LY: { lat: 25, lng: 17 },\n LI: { lat: 47.1667, lng: 9.5333 },\n LT: { lat: 56, lng: 24 },\n LU: { lat: 49.75, lng: 6.1667 },\n MO: { lat: 22.1667, lng: 113.55 },\n MK: { lat: 41.8333, lng: 22 },\n MG: { lat: -20, lng: 47 },\n MW: { lat: -13.5, lng: 34 },\n MY: { lat: 2.5, lng: 112.5 },\n MV: { lat: 3.25, lng: 73 },\n ML: { lat: 17, lng: -4 },\n MT: { lat: 35.8333, lng: 14.5833 },\n MH: { lat: 9, lng: 168 },\n MQ: { lat: 14.6667, lng: -61 },\n MR: { lat: 20, lng: -12 },\n MU: { lat: -20.2833, lng: 57.55 },\n YT: { lat: -12.8333, lng: 45.1667 },\n MX: { lat: 23, lng: -102 },\n FM: { lat: 6.9167, lng: 158.25 },\n MD: { lat: 47, lng: 29 },\n MC: { lat: 43.7333, lng: 7.4 },\n MN: { lat: 46, lng: 105 },\n ME: { lat: 42, lng: 19 },\n MS: { lat: 16.75, lng: -62.2 },\n MA: { lat: 32, lng: -5 },\n MZ: { lat: -18.25, lng: 35 },\n NA: { lat: -22, lng: 17 },\n NR: { lat: -0.5333, lng: 166.9167 },\n NP: { lat: 28, lng: 84 },\n AN: { lat: 12.25, lng: -68.75 },\n NL: { lat: 52.5, lng: 5.75 },\n NC: { lat: -21.5, lng: 165.5 },\n NZ: { lat: -41, lng: 174 },\n NI: { lat: 13, lng: -85 },\n NE: { lat: 16, lng: 8 },\n NG: { lat: 10, lng: 8 },\n NU: { lat: -19.0333, lng: -169.8667 },\n NF: { lat: -29.0333, lng: 167.95 },\n MP: { lat: 15.2, lng: 145.75 },\n NO: { lat: 62, lng: 10 },\n OM: { lat: 21, lng: 57 },\n PK: { lat: 30, lng: 70 },\n PW: { lat: 7.5, lng: 134.5 },\n PS: { lat: 32, lng: 35.25 },\n PA: { lat: 9, lng: -80 },\n PG: { lat: -6, lng: 147 },\n PY: { lat: -23, lng: -58 },\n PE: { lat: -10, lng: -76 },\n PH: { lat: 13, lng: 122 },\n PN: { lat: -24.7, lng: -127.4 },\n PL: { lat: 52, lng: 20 },\n PT: { lat: 39.5, lng: -8 },\n PR: { lat: 18.25, lng: -66.5 },\n QA: { lat: 25.5, lng: 51.25 },\n RE: { lat: -21.1, lng: 55.6 },\n RO: { lat: 46, lng: 25 },\n RU: { lat: 60, lng: 100 },\n RW: { lat: -2, lng: 30 },\n BL: { lat: 17.897728, lng: -62.834244 },\n SH: { lat: -15.9333, lng: -5.7 },\n KN: { lat: 17.3333, lng: -62.75 },\n LC: { lat: 13.8833, lng: -61.1333 },\n MF: { lat: 18.075278, lng: -63.06 },\n PM: { lat: 46.8333, lng: -56.3333 },\n VC: { lat: 13.25, lng: -61.2 },\n WS: { lat: -13.5833, lng: -172.3333 },\n SM: { lat: 43.7667, lng: 12.4167 },\n ST: { lat: 1, lng: 7 },\n SA: { lat: 25, lng: 45 },\n SN: { lat: 14, lng: -14 },\n RS: { lat: 44, lng: 21 },\n SC: { lat: -4.5833, lng: 55.6667 },\n SL: { lat: 8.5, lng: -11.5 },\n SG: { lat: 1.3667, lng: 103.8 },\n SX: { lat: 18.033333, lng: -63.05 },\n SK: { lat: 48.6667, lng: 19.5 },\n SI: { lat: 46, lng: 15 },\n SB: { lat: -8, lng: 159 },\n SO: { lat: 10, lng: 49 },\n ZA: { lat: -29, lng: 24 },\n GS: { lat: -54.5, lng: -37 },\n SS: { lat: 8, lng: 30 },\n ES: { lat: 40, lng: -4 },\n LK: { lat: 7, lng: 81 },\n SD: { lat: 15, lng: 30 },\n SR: { lat: 4, lng: -56 },\n SJ: { lat: 78, lng: 20 },\n SZ: { lat: -26.5, lng: 31.5 },\n SE: { lat: 62, lng: 15 },\n CH: { lat: 47, lng: 8 },\n SY: { lat: 35, lng: 38 },\n TW: { lat: 23.5, lng: 121 },\n TJ: { lat: 39, lng: 71 },\n TZ: { lat: -6, lng: 35 },\n TH: { lat: 15, lng: 100 },\n TL: { lat: -8.55, lng: 125.5167 },\n TG: { lat: 8, lng: 1.1667 },\n TK: { lat: -9, lng: -172 },\n TO: { lat: -20, lng: -175 },\n TT: { lat: 11, lng: -61 },\n TN: { lat: 34, lng: 9 },\n TR: { lat: 39, lng: 35 },\n TM: { lat: 40, lng: 60 },\n TC: { lat: 21.75, lng: -71.5833 },\n TV: { lat: -8, lng: 178 },\n UG: { lat: 1, lng: 32 },\n UA: { lat: 49, lng: 32 },\n AE: { lat: 24, lng: 54 },\n GB: { lat: 54, lng: -2 },\n UM: { lat: 19.2833, lng: 166.6 },\n US: { lat: 38, lng: -97 },\n UY: { lat: -33, lng: -56 },\n UZ: { lat: 41, lng: 64 },\n VU: { lat: -16, lng: 167 },\n VE: { lat: 8, lng: -66 },\n VN: { lat: 16, lng: 106 },\n VG: { lat: 18.5, lng: -64.5 },\n VI: { lat: 18.3333, lng: -64.8333 },\n WF: { lat: -13.3, lng: -176.2 },\n EH: { lat: 24.5, lng: -13 },\n YE: { lat: 15, lng: 48 },\n ZM: { lat: -15, lng: 30 },\n ZW: { lat: -20, lng: 30 },\n} as const satisfies Record<string, Location>;\n\nexport const AWS_REGIONS = {\n WEST_US: {\n code: 'us-west-1',\n displayName: 'West US (North California)',\n location: { lat: 37.774929, lng: -122.419418 },\n },\n EAST_US: {\n code: 'us-east-1',\n displayName: 'East US (North Virginia)',\n location: { lat: 37.926868, lng: -78.024902 },\n },\n EAST_US_2: {\n code: 'us-east-2',\n displayName: 'East US (Ohio)',\n location: { lat: 39.9612, lng: -82.9988 },\n },\n CENTRAL_CANADA: {\n code: 'ca-central-1',\n displayName: 'Canada (Central)',\n location: { lat: 56.130367, lng: -106.346771 },\n },\n WEST_EU: {\n code: 'eu-west-1',\n displayName: 'West EU (Ireland)',\n location: { lat: 53.3498, lng: -6.2603 },\n },\n WEST_EU_2: {\n code: 'eu-west-2',\n displayName: 'West Europe (London)',\n location: { lat: 51.507351, lng: -0.127758 },\n },\n WEST_EU_3: {\n code: 'eu-west-3',\n displayName: 'West EU (Paris)',\n location: { lat: 2.352222, lng: 48.856613 },\n },\n CENTRAL_EU: {\n code: 'eu-central-1',\n displayName: 'Central EU (Frankfurt)',\n location: { lat: 50.110924, lng: 8.682127 },\n },\n CENTRAL_EU_2: {\n code: 'eu-central-2',\n displayName: 'Central Europe (Zurich)',\n location: { lat: 47.3744489, lng: 8.5410422 },\n },\n NORTH_EU: {\n code: 'eu-north-1',\n displayName: 'North EU (Stockholm)',\n location: { lat: 59.3251172, lng: 18.0710935 },\n },\n SOUTH_ASIA: {\n code: 'ap-south-1',\n displayName: 'South Asia (Mumbai)',\n location: { lat: 18.9733536, lng: 72.8281049 },\n },\n SOUTHEAST_ASIA: {\n code: 'ap-southeast-1',\n displayName: 'Southeast Asia (Singapore)',\n location: { lat: 1.357107, lng: 103.8194992 },\n },\n NORTHEAST_ASIA: {\n code: 'ap-northeast-1',\n displayName: 'Northeast Asia (Tokyo)',\n location: { lat: 35.6895, lng: 139.6917 },\n },\n NORTHEAST_ASIA_2: {\n code: 'ap-northeast-2',\n displayName: 'Northeast Asia (Seoul)',\n location: { lat: 37.5665, lng: 126.978 },\n },\n OCEANIA: {\n code: 'ap-southeast-2',\n displayName: 'Oceania (Sydney)',\n location: { lat: -33.8688, lng: 151.2093 },\n },\n SOUTH_AMERICA: {\n code: 'sa-east-1',\n displayName: 'South America (São Paulo)',\n location: { lat: -1.2043218, lng: -47.1583944 },\n },\n} as const satisfies Record<string, AwsRegion>;\n\nexport type RegionCodes = ValueOf<typeof AWS_REGIONS>['code'];\n\nexport const AWS_REGION_CODES = Object.values(AWS_REGIONS).map(\n (region) => region.code\n) as UnionToTuple<RegionCodes>;\n\n/**\n * Calculates the closest AWS region to a given location.\n */\nexport function getClosestAwsRegion(location: Location) {\n const distances = Object.entries(AWS_REGIONS).map<\n [region: string, distance: number]\n >(([name, region]) => {\n return [name, getDistance(location, region.location)] as const;\n });\n\n const closestRegion = distances.reduce<\n [region: string, distance: number] | undefined\n >(\n (min, current) =>\n min === undefined ? current : current[1] < min[1] ? current : min,\n undefined\n );\n\n if (!closestRegion) {\n throw new Error('no closest region found');\n }\n\n const [regionName] = closestRegion;\n\n return AWS_REGIONS[regionName as keyof typeof AWS_REGIONS];\n}\n\n/**\n * Fetches the user's country code based on their IP address.\n */\nexport async function getCountryCode() {\n const response = await fetch(TRACE_URL);\n const data = await response.text();\n const info = parseKeyValueList(data);\n const countryCode = info['loc'];\n\n if (!countryCode) {\n throw new Error('location not found');\n }\n\n return countryCode;\n}\n\n/**\n * Gets the approximate coordinates of a country based on its country code.\n */\nexport function getCountryCoordinates(countryCode: string) {\n const location: Location =\n COUNTRY_COORDINATES[countryCode as keyof typeof COUNTRY_COORDINATES];\n\n if (!location) {\n throw new Error(`unknown location code: ${countryCode}`);\n }\n\n return location;\n}\n\n/**\n * Calculates the distance between two points on Earth using the Haversine formula.\n *\n * @returns Distance between the points in kilometers\n */\nexport function getDistance(a: Location, b: Location): number {\n const lat = degreesToRadians(b.lat - a.lat);\n const lng = degreesToRadians(b.lng - a.lng);\n const a1 =\n Math.sin(lat / 2) * Math.sin(lat / 2) +\n Math.cos(degreesToRadians(a.lat)) *\n Math.cos(degreesToRadians(b.lat)) *\n Math.sin(lng / 2) *\n Math.sin(lng / 2);\n const c = 2 * Math.atan2(Math.sqrt(a1), Math.sqrt(1 - a1));\n return EARTH_RADIUS * c;\n}\n\n/**\n * Converts degrees to radians\n *\n * @returns The angle in radians\n */\nexport function degreesToRadians(deg: number): number {\n return deg * (Math.PI / 180);\n}\n"],"mappings":"AAAA,IAAAA,EAAA,CACE,KAAQ,gCACR,QAAW,gBACX,YAAe,2CACf,QAAW,aACX,KAAQ,SACR,KAAQ,iBACR,MAAS,kBACT,YAAe,GACf,QAAW,CACT,MAAS,eACT,eAAkB,gBAClB,KAAQ,SACR,WAAY,uBACZ,YAAa,wBACb,gCAAiC,0FACnC,EACA,MAAS,CACP,WACF,EACA,IAAO,CACL,sBAAuB,iBACzB,EACA,QAAW,CACT,IAAK,CACH,OAAU,kBACV,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AASC,GAAwBC,EAAmC,CACzE,IAAMC,EACJD,EAAQ,SAAS,QAAU,2BACvBE,EAAYF,EAAQ,UACpBG,EAAWH,EAAQ,SAErBI,EAuDJ,OArDeC,GAAgB,CAC7B,KAAM,WACN,QAAAR,GACA,aAAa,CAAE,WAAAS,CAAW,EAAG,CAC3BF,EAAsBG,EACpBN,EACAD,EAAQ,SAAS,YACjB,CACE,aAAc,gBAAgBH,EAAO,KAAKS,EAAW,IAAI,IAAIA,EAAW,OAAO,GACjF,CACF,CACF,EACA,MAAO,IAAM,CACX,IAAME,EAA8B,CAAC,EAGrC,OAAKN,GACH,OAAO,OACLM,EACAC,GAA0B,CAAE,oBAAAL,CAAoB,CAAC,CACnD,EAIF,OAAO,OACLI,EACAE,EAA0B,CACxB,oBAAAN,EACA,UAAAF,EACA,SAAAC,CACF,CAAC,EACDQ,EAAqB,CACnB,oBAAAP,EACA,UAAAF,CACF,CAAC,EACDU,EAAkB,CAChB,oBAAAR,EACA,UAAAF,CACF,CAAC,EACDW,EAAoB,CAClB,oBAAAT,EACA,UAAAF,CACF,CAAC,EACDY,EAAkB,CAChB,oBAAAV,EACA,UAAAF,CACF,CAAC,CACH,EAEOM,CACT,CACF,CAAC,CAGH","names":["package_default","createMcpServer","createClient","z","createManagementApiClient","baseUrl","accessToken","headers","errorSchema","assertSuccess","response","fallbackMessage","errorContent","tool","z","PROJECT_COST_MONTHLY","BRANCH_COST_HOURLY","getNextProjectCost","managementApiClient","orgId","orgResponse","assertSuccess","projectsResponse","org","activeProjects","project","amount","getBranchCost","parseKeyValueList","data","item","key","value","hashObject","obj","length","str","_","result","buffer","tool","injectableTool","description","parameters","inject","execute","value","mask","_","key","args","getBranchingTools","managementApiClient","projectId","project_id","injectableTool","z","name","confirm_cost_id","cost","getBranchCost","hashObject","createBranchResponse","assertSuccess","response","tool","branch_id","migration_version","z","stripIndent","columns_default","extensions_default","tables_default","SYSTEM_SCHEMAS","listTablesSql","schemas","sql","stripIndent","tables_default","columns_default","coalesceRowsToArray","s","listExtensionsSql","extensions_default","source","filter","getDatabaseOperationTools","managementApiClient","projectId","readOnly","executeSql","query","response","assertSuccess","project_id","injectableTool","z","schemas","sql","listTablesSql","listExtensionsSql","name","z","stripIndent","getLogQuery","service","limit","getDebuggingTools","managementApiClient","projectId","project_id","injectableTool","z","service","timestamp","response","getLogQuery","assertSuccess","z","getDevelopmentTools","managementApiClient","projectId","project_id","injectableTool","z","response","assertSuccess","anonKey","key","z","codeBlock","fileURLToPath","build","Parser","join","relative","fileURLToPath","z","parser","sourceMapSchema","extractFiles","eszip","pathPrefix","specifiers","reader","fileSpecifiers","specifier","source","sourceMapString","filePath","file","sourceMap","typeScriptSource","getDeploymentId","projectId","functionId","functionVersion","getPathPrefix","deploymentId","edgeFunctionExample","codeBlock","getFullEdgeFunction","managementApiClient","functionSlug","functionResponse","assertSuccess","edgeFunction","pathPrefix","entrypoint_path","fileURLToPath","import_map_path","eszipResponse","extractedFiles","extractFiles","files","file","getEdgeFunctionTools","managementApiClient","projectId","project_id","injectableTool","z","response","assertSuccess","listedFunction","edgeFunction","error","getFullEdgeFunction","edgeFunctionExample","name","entrypoint_path","import_map_path","files","existingEdgeFunction","import_map_file","file","body","formData","blob","f","tool","z","UPPERCASE_CHARS","LOWERCASE_CHARS","NUMBER_CHARS","SYMBOL_CHARS","generatePassword","length","numbers","symbols","uppercase","lowercase","chars","randomValues","password","i","randomIndex","EARTH_RADIUS","TRACE_URL","COUNTRY_COORDINATES","AWS_REGIONS","AWS_REGION_CODES","region","getClosestAwsRegion","location","closestRegion","name","getDistance","min","current","regionName","getCountryCode","data","countryCode","parseKeyValueList","getCountryCoordinates","a","b","lat","degreesToRadians","lng","a1","c","deg","getProjectManagementTools","managementApiClient","getClosestRegion","getClosestAwsRegion","getCountryCoordinates","getCountryCode","tool","z","response","assertSuccess","organizationId","id","type","organization_id","generateResponse","cost","getNextProjectCost","getBranchCost","hashObject","AWS_REGION_CODES","name","region","confirm_cost_id","generatePassword","project_id","version","package_default","createSupabaseMcpServer","options","managementApiUrl","projectId","readOnly","managementApiClient","createMcpServer","clientInfo","createManagementApiClient","tools","getProjectManagementTools","getDatabaseOperationTools","getEdgeFunctionTools","getDebuggingTools","getDevelopmentTools","getBranchingTools"]}
|