uiplug-mcp 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +33 -2
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -4,12 +4,38 @@ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"
4
4
  import { CallToolRequestSchema, ListToolsRequestSchema, } from "@modelcontextprotocol/sdk/types.js";
5
5
  import { createClient } from "@supabase/supabase-js";
6
6
  // ── Supabase client ───────────────────────────────────────────────────────────
7
- // Public anon key — safe to hardcode (read-only, RLS-protected).
8
- // Override with env vars to point at your own Supabase instance.
9
7
  const SUPABASE_URL = process.env.SUPABASE_URL ?? "https://uuoexpurygmgfouiawuc.supabase.co";
10
8
  const SUPABASE_ANON_KEY = process.env.SUPABASE_ANON_KEY ??
11
9
  "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InV1b2V4cHVyeWdtZ2ZvdWlhd3VjIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NzE2NzI5MTMsImV4cCI6MjA4NzI0ODkxM30.4gogFo90o8lfZ9_iKZfhXQ9QHtx2VKhMu9Hgy_2lI_g";
12
10
  const supabase = createClient(SUPABASE_URL, SUPABASE_ANON_KEY);
11
+ // ── API key validation ────────────────────────────────────────────────────────
12
+ async function validateApiKey(apiKey) {
13
+ if (!apiKey) {
14
+ return {
15
+ userId: null,
16
+ error: "No API key provided. Set UIPLUG_API_KEY in your MCP config. " +
17
+ "Generate one at https://uiplug.com/dashboard/settings",
18
+ };
19
+ }
20
+ const { createHash } = await import("crypto");
21
+ const keyHash = createHash("sha256").update(apiKey).digest("hex");
22
+ const { data, error } = await supabase
23
+ .from("api_keys")
24
+ .select("id, user_id, is_active")
25
+ .eq("key_hash", keyHash)
26
+ .eq("is_active", true)
27
+ .single();
28
+ if (error || !data) {
29
+ return { userId: null, error: "Invalid or revoked API key." };
30
+ }
31
+ // Fire-and-forget: update usage stats
32
+ supabase
33
+ .from("api_keys")
34
+ .update({ last_used_at: new Date().toISOString(), usage_total: data.usage_total + 1 })
35
+ .eq("id", data.id)
36
+ .then(() => { });
37
+ return { userId: data.user_id, error: null };
38
+ }
13
39
  // ── MCP Server ────────────────────────────────────────────────────────────────
14
40
  const server = new Server({ name: "uiplug", version: "1.0.0" }, { capabilities: { tools: {} } });
15
41
  // ── Tool definitions ──────────────────────────────────────────────────────────
@@ -79,6 +105,11 @@ server.setRequestHandler(ListToolsRequestSchema, async () => ({
79
105
  // ── Tool handlers ─────────────────────────────────────────────────────────────
80
106
  server.setRequestHandler(CallToolRequestSchema, async (request) => {
81
107
  const { name, arguments: args } = request.params;
108
+ // ── Validate API key ─────────────────────────────────────────────────────────
109
+ const { error: authError } = await validateApiKey(process.env.UIPLUG_API_KEY);
110
+ if (authError) {
111
+ return { content: [{ type: "text", text: authError }], isError: true };
112
+ }
82
113
  // ── list_components ─────────────────────────────────────────────────────────
83
114
  if (name === "list_components") {
84
115
  const { framework, category, limit = 20 } = (args ?? {});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "uiplug-mcp",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "MCP server for UIPlug — gives AI agents access to the UIPlug UI component marketplace",
5
5
  "type": "module",
6
6
  "bin": {