@smithery/sdk 1.4.1 → 1.4.3

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,4 +1,5 @@
1
1
  import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
2
+ import express from "express";
2
3
  import type { z } from "zod";
3
4
  import type { Server } from "@modelcontextprotocol/sdk/server/index.js";
4
5
  import { type SessionStore } from "./session.js";
@@ -22,14 +23,18 @@ export interface StatefulServerOptions<T = Record<string, unknown>> {
22
23
  * Zod schema for config validation
23
24
  */
24
25
  schema?: z.ZodSchema<T>;
26
+ /**
27
+ * Express app instance to use (optional)
28
+ */
29
+ app?: express.Application;
25
30
  }
26
31
  /**
27
32
  * Creates a stateful server for handling MCP requests.
28
33
  * For every new session, we invoke createMcpServer to create a new instance of the server.
29
34
  * @param createMcpServer Function to create an MCP server
30
- * @param options Configuration options including optional schema validation
35
+ * @param options Configuration options including optional schema validation and Express app
31
36
  * @returns Express app
32
37
  */
33
38
  export declare function createStatefulServer<T = Record<string, unknown>>(createMcpServer: CreateServerFn<T>, options?: StatefulServerOptions<T>): {
34
- app: import("express-serve-static-core").Express;
39
+ app: express.Application;
35
40
  };
@@ -8,12 +8,12 @@ import { createLRUStore } from "./session.js";
8
8
  * Creates a stateful server for handling MCP requests.
9
9
  * For every new session, we invoke createMcpServer to create a new instance of the server.
10
10
  * @param createMcpServer Function to create an MCP server
11
- * @param options Configuration options including optional schema validation
11
+ * @param options Configuration options including optional schema validation and Express app
12
12
  * @returns Express app
13
13
  */
14
14
  export function createStatefulServer(createMcpServer, options) {
15
- const app = express();
16
- app.use(express.json());
15
+ const app = options?.app ?? express();
16
+ app.use("/mcp", express.json());
17
17
  const sessionStore = options?.sessionStore ?? createLRUStore();
18
18
  // Handle POST requests for client-to-server communication
19
19
  app.post("/mcp", async (req, res) => {
@@ -1,3 +1,4 @@
1
+ import express from "express";
1
2
  import type { z } from "zod";
2
3
  import type { Server } from "@modelcontextprotocol/sdk/server/index.js";
3
4
  /**
@@ -9,6 +10,7 @@ export interface CreateServerArg<T = Record<string, unknown>> {
9
10
  export type CreateServerFn<T = Record<string, unknown>> = (arg: CreateServerArg<T>) => Server;
10
11
  export interface CreateStatelessServerOptions<T> {
11
12
  schema?: z.ZodSchema<T>;
13
+ app?: express.Application;
12
14
  }
13
15
  /**
14
16
  * Creates a stateless server for handling MCP requests
@@ -18,5 +20,5 @@ export interface CreateStatelessServerOptions<T> {
18
20
  * @returns Express app
19
21
  */
20
22
  export declare function createStatelessServer<T = Record<string, unknown>>(createMcpServer: CreateServerFn<T>, options?: CreateStatelessServerOptions<T>): {
21
- app: import("express-serve-static-core").Express;
23
+ app: express.Application;
22
24
  };
@@ -9,8 +9,8 @@ import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/
9
9
  * @returns Express app
10
10
  */
11
11
  export function createStatelessServer(createMcpServer, options) {
12
- const app = express();
13
- app.use(express.json());
12
+ const app = options?.app ?? express();
13
+ app.use("/mcp", express.json());
14
14
  app.post("/mcp", async (req, res) => {
15
15
  // In stateless mode, create a new instance of transport and server for each request
16
16
  // to ensure complete isolation. A single instance would cause request ID collisions
@@ -81,10 +81,7 @@ export function parseAndValidateConfig(req, schema) {
81
81
  if (schema) {
82
82
  const result = schema.safeParse(config);
83
83
  if (!result.success) {
84
- const jsonSchema = zodToJsonSchema(schema, {
85
- name: "ConfigSchema",
86
- $refStrategy: "none",
87
- });
84
+ const jsonSchema = zodToJsonSchema(schema);
88
85
  const errors = result.error.issues.map((issue) => {
89
86
  // Safely traverse the config object to get the received value
90
87
  let received = config;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smithery/sdk",
3
- "version": "1.4.1",
3
+ "version": "1.4.3",
4
4
  "description": "SDK to develop with Smithery",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",