Skip to content

Commit b498d5c

Browse files
authored
Merge pull request #21 from supabase-community/feat/project-cost-prompt
feat: cost confirmation flows
2 parents 7a7625a + 8430ed1 commit b498d5c

File tree

7 files changed

+486
-13
lines changed

7 files changed

+486
-13
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,11 @@ The following Supabase tools are available to the LLM:
154154

155155
- `generate_typescript_types`: Generates TypeScript types based on the database schema. LLMs can save this to a file and use it in their code.
156156

157+
#### Cost Confirmation
158+
159+
- `get_cost`: Gets the cost of a new project or branch for an organization.
160+
- `confirm_cost`: Confirms the user's understanding of new project or branch costs. This is required to create a new project or branch.
161+
157162
## Other MCP servers
158163

159164
### `@supabase/mcp-server-postgrest`
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import {
2+
assertSuccess,
3+
type ManagementApiClient,
4+
} from './management-api/index.js';
5+
6+
export const PROJECT_COST_MONTHLY = 10;
7+
export const BRANCH_COST_HOURLY = 0.01344;
8+
9+
export type ProjectCost = {
10+
type: 'project';
11+
recurrence: 'monthly';
12+
amount: number;
13+
};
14+
15+
export type BranchCost = {
16+
type: 'branch';
17+
recurrence: 'hourly';
18+
amount: number;
19+
};
20+
21+
export type Cost = ProjectCost | BranchCost;
22+
23+
/**
24+
* Gets the cost of the next project in an organization.
25+
*/
26+
export async function getNextProjectCost(
27+
managementApiClient: ManagementApiClient,
28+
orgId: string
29+
): Promise<Cost> {
30+
const orgResponse = await managementApiClient.GET(
31+
'/v1/organizations/{slug}',
32+
{
33+
params: {
34+
path: {
35+
slug: orgId,
36+
},
37+
},
38+
}
39+
);
40+
41+
assertSuccess(orgResponse, 'Failed to fetch organization');
42+
43+
const projectsResponse = await managementApiClient.GET('/v1/projects');
44+
45+
assertSuccess(projectsResponse, 'Failed to fetch projects');
46+
47+
const org = orgResponse.data;
48+
const activeProjects = projectsResponse.data.filter(
49+
(project) =>
50+
project.organization_id === orgId &&
51+
!['INACTIVE', 'GOING_DOWN', 'REMOVED'].includes(project.status)
52+
);
53+
54+
let amount = 0;
55+
56+
if (org.plan !== 'free') {
57+
// If the organization is on a paid plan, the first project is included
58+
if (activeProjects.length > 0) {
59+
amount = PROJECT_COST_MONTHLY;
60+
}
61+
}
62+
63+
return { type: 'project', recurrence: 'monthly', amount };
64+
}
65+
66+
/**
67+
* Gets the cost for a database branch.
68+
*/
69+
export function getBranchCost(): Cost {
70+
return { type: 'branch', recurrence: 'hourly', amount: BRANCH_COST_HOURLY };
71+
}

0 commit comments

Comments
 (0)