Skip to content

Commit a135f13

Browse files
authored
Fix/app kit integration without mcp (#17)
* refactor(plugin): conditionally apply databricks client middleware per plugin * refactor(server): server plugin dont have env deps, already have defaults * refactor(server): auto detect static path from common build directories
1 parent 2b30ae2 commit a135f13

File tree

6 files changed

+39
-10
lines changed

6 files changed

+39
-10
lines changed

apps/dev-playground/server/.env.dist

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
DATABRICKS_HOST=
22
DATABRICKS_WAREHOUSE_ID=
33
DATABRICKS_WORKSPACE_ID=
4-
DATABRICKS_APP_PORT=8000
5-
FLASK_RUN_HOST=0.0.0.0
64
NODE_ENV='development'
75
OTEL_EXPORTER_OTLP_ENDPOINT='http://localhost:4318'
86
OTEL_RESOURCE_ATTRIBUTES='service.sample_attribute=dev'

packages/app-kit/src/analytics/analytics.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import type {
2020
export class AnalyticsPlugin extends Plugin {
2121
name = "analytics";
2222
envVars = [];
23+
requiresDatabricksClient = true;
2324

2425
protected static description = "Analytics plugin for data analysis";
2526
protected declare config: IAnalyticsConfig;

packages/app-kit/src/plugin/plugin.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ export abstract class Plugin<
4141
protected telemetry: ITelemetry;
4242
protected abstract envVars: string[];
4343

44+
/** If the plugin requires the Databricks client to be set in the request context */
45+
requiresDatabricksClient = false;
46+
4447
static phase: PluginPhase = "normal";
4548
name: string;
4649

packages/app-kit/src/plugin/tests/plugin.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,22 @@ describe("Plugin", () => {
571571
});
572572
});
573573

574+
describe("requiresDatabricksClient", () => {
575+
test("should default to false", () => {
576+
const plugin = new TestPlugin(config);
577+
expect(plugin.requiresDatabricksClient).toBe(false);
578+
});
579+
580+
test("should allow plugins to override to true", () => {
581+
class PluginWithDatabricksClient extends TestPlugin {
582+
requiresDatabricksClient = true;
583+
}
584+
585+
const plugin = new PluginWithDatabricksClient(config);
586+
expect(plugin.requiresDatabricksClient).toBe(true);
587+
});
588+
});
589+
574590
describe("integration scenarios", () => {
575591
test("should handle complex execution flow with all interceptors", async () => {
576592
const plugin = new TestPlugin({

packages/app-kit/src/server/index.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ dotenv.config({ path: path.resolve(process.cwd(), "./server/.env") });
1616
export class ServerPlugin extends Plugin {
1717
public static DEFAULT_CONFIG = {
1818
autoStart: true,
19-
staticPath: path.resolve(process.cwd(), "client", "dist"),
19+
staticPath: ServerPlugin.findDefaultStaticPath(),
2020
host: process.env.FLASK_RUN_HOST || "0.0.0.0",
2121
port: Number(process.env.DATABRICKS_APP_PORT) || 8000,
2222
watch: process.env.NODE_ENV === "development",
2323
};
2424

2525
public name = "server" as const;
26-
public envVars = ["DATABRICKS_APP_PORT", "FLASK_RUN_HOST"];
26+
public envVars: string[] = [];
2727
private serverApplication: express.Application;
2828
private server: HTTPServer | null;
2929
private devModeManager?: DevModeManager;
@@ -65,9 +65,8 @@ export class ServerPlugin extends Plugin {
6565

6666
async start(): Promise<express.Application> {
6767
this.serverApplication.use(express.json());
68-
this.serverApplication.use(await databricksClientMiddleware());
6968

70-
this.extendRoutes();
69+
await this.extendRoutes();
7170

7271
for (const extension of this.serverExtensions) {
7372
extension(this.serverApplication);
@@ -156,7 +155,7 @@ export class ServerPlugin extends Plugin {
156155
return this;
157156
}
158157

159-
private extendRoutes() {
158+
private async extendRoutes() {
160159
if (!this.config.plugins) return;
161160

162161
this.serverApplication.get("/health", (_, res) => {
@@ -169,6 +168,10 @@ export class ServerPlugin extends Plugin {
169168
if (plugin?.injectRoutes && typeof plugin.injectRoutes === "function") {
170169
const router = express.Router();
171170

171+
// add databricks client middleware to the router if the plugin needs the request context
172+
if (plugin.requiresDatabricksClient)
173+
router.use(await databricksClientMiddleware());
174+
172175
plugin.injectRoutes(router);
173176

174177
this.serverApplication.use(`/api/${plugin.name}`, router);
@@ -222,6 +225,17 @@ export class ServerPlugin extends Plugin {
222225
return configObject;
223226
}
224227

228+
private static findDefaultStaticPath() {
229+
const staticPaths = ["dist", "client/dist", "build", "public", "out"];
230+
const cwd = process.cwd();
231+
for (const p of staticPaths) {
232+
if (fs.existsSync(path.resolve(cwd, p, "index.html"))) {
233+
return path.resolve(cwd, p);
234+
}
235+
}
236+
return undefined;
237+
}
238+
225239
private _gracefulShutdown() {
226240
console.log("Starting graceful shutdown...");
227241

packages/app-kit/src/telemetry/telemetry-manager.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,6 @@ export class TelemetryManager {
6666
if (this.sdk) return;
6767

6868
if (!process.env.OTEL_EXPORTER_OTLP_ENDPOINT) {
69-
console.log(
70-
"[Telemetry] OTEL_EXPORTER_OTLP_ENDPOINT not set; telemetry disabled",
71-
);
7269
return;
7370
}
7471

0 commit comments

Comments
 (0)