@mseep/supabase-mcp
Version:
MCP server for Supabase CRUD operations
147 lines • 5.14 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const stdio_js_1 = require("@modelcontextprotocol/sdk/server/stdio.js");
const mcp_js_1 = require("@modelcontextprotocol/sdk/server/mcp.js");
const config_js_1 = require("./config.js");
const supabase_js_1 = require("./services/supabase.js");
const zod_1 = require("zod");
// Validate the configuration
try {
(0, config_js_1.validateConfig)();
}
catch (error) {
console.error('Configuration error:', error instanceof Error ? error.message : String(error));
process.exit(1);
}
// Create the MCP server
const server = new mcp_js_1.McpServer({
name: "Supabase MCP",
version: "1.5.0",
description: "MCP server for Supabase database CRUD operations"
});
// ==== Database Tools ====
// Query Database Tool
server.tool("queryDatabase", {
table: zod_1.z.string().describe("Name of the table to query"),
select: zod_1.z.string().optional().describe("Comma-separated list of columns to select (default: *)"),
query: zod_1.z.record(zod_1.z.any()).optional().describe("Filter conditions")
}, async ({ table, select = "*", query = {} }) => {
const result = await supabase_js_1.supabaseService.queryData(table, query, select);
if (result.error) {
return {
content: [{
type: "text",
text: `Error querying table ${table}: ${JSON.stringify(result.error)}`
}],
isError: true
};
}
return {
content: [{
type: "text",
text: JSON.stringify(result.data, null, 2)
}]
};
});
// Insert Data Tool
server.tool("insertData", {
table: zod_1.z.string().describe("Name of the table"),
data: zod_1.z.union([
zod_1.z.record(zod_1.z.any()),
zod_1.z.array(zod_1.z.record(zod_1.z.any()))
]).describe("Data to insert")
}, async ({ table, data }) => {
const result = await supabase_js_1.supabaseService.insertData(table, data);
if (result.error) {
return {
content: [{
type: "text",
text: `Error inserting data into table ${table}: ${JSON.stringify(result.error)}`
}],
isError: true
};
}
return {
content: [{
type: "text",
text: `Successfully inserted data into ${table}. Result: ${JSON.stringify(result.data, null, 2)}`
}]
};
});
// Update Data Tool
server.tool("updateData", {
table: zod_1.z.string().describe("Name of the table"),
data: zod_1.z.record(zod_1.z.any()).describe("Data to update as key-value pairs"),
query: zod_1.z.record(zod_1.z.any()).describe("Filter conditions for the update")
}, async ({ table, data, query }) => {
const result = await supabase_js_1.supabaseService.updateData(table, data, query);
if (result.error) {
return {
content: [{
type: "text",
text: `Error updating data in table ${table}: ${JSON.stringify(result.error)}`
}],
isError: true
};
}
return {
content: [{
type: "text",
text: `Successfully updated data in ${table}. Result: ${JSON.stringify(result.data, null, 2)}`
}]
};
});
// Delete Data Tool
server.tool("deleteData", {
table: zod_1.z.string().describe("Name of the table"),
query: zod_1.z.record(zod_1.z.any()).describe("Filter conditions for deletion")
}, async ({ table, query }) => {
const result = await supabase_js_1.supabaseService.deleteData(table, query);
if (result.error) {
return {
content: [{
type: "text",
text: `Error deleting data from table ${table}: ${JSON.stringify(result.error)}`
}],
isError: true
};
}
return {
content: [{
type: "text",
text: `Successfully deleted data from ${table}. Result: ${JSON.stringify(result.data, null, 2)}`
}]
};
});
// List Tables Tool
server.tool("listTables", {}, async () => {
const result = await supabase_js_1.supabaseService.listTables();
if (result.error) {
return {
content: [{
type: "text",
text: `Error fetching tables: ${JSON.stringify(result.error)}`
}],
isError: true
};
}
return {
content: [{
type: "text",
text: JSON.stringify(result.tables, null, 2)
}]
};
});
// Create transport and connect
const transport = new stdio_js_1.StdioServerTransport();
console.error("Supabase MCP server initializing..."); // Using console.error to send to stderr
server.connect(transport)
.then(() => {
console.error("Supabase MCP server connected and ready"); // Using console.error to send to stderr
})
.catch((error) => {
console.error("Error starting Supabase MCP server:", error);
process.exit(1);
});
//# sourceMappingURL=claude-entry.js.map