stackby-mcp-server 0.2.8 → 0.3.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.
@@ -1,7 +1,3 @@
1
- /**
2
- * Stackby API client for MCP server.
3
- * Uses dedicated MCP API only: /api/v1/mcp/* (existing developer API is unchanged).
4
- */
5
1
  export declare function hasApiKey(): boolean;
6
2
  /** Returns the base URL actually in use (for error messages). */
7
3
  export declare function getApiBaseUrl(): string;
@@ -1,21 +1,35 @@
1
1
  /**
2
2
  * Stackby API client for MCP server.
3
3
  * Uses dedicated MCP API only: /api/v1/mcp/* (existing developer API is unchanged).
4
+ * In HTTP (hosted) mode, API key and URL come from request context; in stdio mode from process.env.
4
5
  */
5
- const BASE_URL = process.env.STACKBY_API_URL || "https://stackby.com";
6
- const API_KEY = process.env.STACKBY_API_KEY || "";
6
+ import { getApiKeyFromContext, getApiUrlFromContext } from "./request-context.js";
7
+ const DEFAULT_BASE_URL = process.env.STACKBY_API_URL || "https://stackby.com";
8
+ const ENV_API_KEY = process.env.STACKBY_API_KEY || "";
7
9
  const MCP_API = "/api/v1/mcp";
10
+ function getEffectiveApiKey() {
11
+ const fromContext = getApiKeyFromContext();
12
+ if (fromContext)
13
+ return fromContext;
14
+ return ENV_API_KEY.trim();
15
+ }
16
+ function getEffectiveBaseUrl() {
17
+ const fromContext = getApiUrlFromContext();
18
+ if (fromContext)
19
+ return fromContext.replace(/\/$/, "");
20
+ return DEFAULT_BASE_URL.replace(/\/$/, "");
21
+ }
8
22
  export function hasApiKey() {
9
- return Boolean(API_KEY && API_KEY.trim().length > 0);
23
+ return Boolean(getEffectiveApiKey());
10
24
  }
11
25
  /** Returns the base URL actually in use (for error messages). */
12
26
  export function getApiBaseUrl() {
13
- return BASE_URL.replace(/\/$/, "");
27
+ return getEffectiveBaseUrl();
14
28
  }
15
29
  function authHeaders() {
16
- const key = API_KEY.trim();
30
+ const key = getEffectiveApiKey();
17
31
  if (!key) {
18
- throw new Error("STACKBY_API_KEY is not set. Set it in your MCP config (e.g. Cursor mcp.json env).");
32
+ throw new Error("STACKBY_API_KEY is not set. Set it in your MCP config (e.g. Cursor mcp.json env) or send header X-Stackby-API-Key (hosted).");
19
33
  }
20
34
  return {
21
35
  "Content-Type": "application/json",
@@ -34,7 +48,8 @@ function normalizeResponse(body) {
34
48
  return { data: body };
35
49
  }
36
50
  async function request(path, options = {}) {
37
- const url = path.startsWith("http") ? path : `${BASE_URL.replace(/\/$/, "")}${path.startsWith("/") ? path : `/${path}`}`;
51
+ const base = getEffectiveBaseUrl();
52
+ const url = path.startsWith("http") ? path : `${base}${path.startsWith("/") ? path : `/${path}`}`;
38
53
  const res = await fetch(url, {
39
54
  ...options,
40
55
  headers: { ...authHeaders(), ...options.headers },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "stackby-mcp-server",
3
- "version": "0.2.8",
3
+ "version": "0.3.0",
4
4
  "description": "MCP server for Stackby — list stacks, tables, records; create/update/delete rows and schema via AI clients (Cursor, Claude, Cline).",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
@@ -12,6 +12,7 @@
12
12
  "scripts": {
13
13
  "build": "tsc && node -e \"console.log('\\nBuild OK. Output in dist/'); console.log('Run npm start to run the server.');\"",
14
14
  "start": "node dist/index.js",
15
+ "start:http": "node dist/server-http.js",
15
16
  "dev": "tsc && node dist/index.js",
16
17
  "prepare": "npm run build"
17
18
  },