fastmcp 3.11.0 → 3.13.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.
@@ -3123,3 +3123,115 @@ test("uses `formatInvalidParamsErrorMessage` callback to build ErrorCode.Invalid
3123
3123
  },
3124
3124
  });
3125
3125
  });
3126
+
3127
+ test("stateless mode works correctly", async () => {
3128
+ const port = await getRandomPort();
3129
+
3130
+ const server = new FastMCP({
3131
+ name: "Test server",
3132
+ version: "1.0.0",
3133
+ });
3134
+
3135
+ server.addTool({
3136
+ description: "Add two numbers",
3137
+ execute: async (args) => {
3138
+ return String(args.a + args.b);
3139
+ },
3140
+ name: "add",
3141
+ parameters: z.object({
3142
+ a: z.number(),
3143
+ b: z.number(),
3144
+ }),
3145
+ });
3146
+
3147
+ await server.start({
3148
+ httpStream: {
3149
+ port,
3150
+ stateless: true,
3151
+ },
3152
+ transportType: "httpStream",
3153
+ });
3154
+
3155
+ try {
3156
+ const client = new Client(
3157
+ {
3158
+ name: "Test client",
3159
+ version: "1.0.0",
3160
+ },
3161
+ {
3162
+ capabilities: {},
3163
+ },
3164
+ );
3165
+
3166
+ const transport = new StreamableHTTPClientTransport(
3167
+ new URL(`http://localhost:${port}/mcp`),
3168
+ );
3169
+
3170
+ await client.connect(transport);
3171
+
3172
+ // Tool call should work in stateless mode
3173
+ const result = await client.callTool({
3174
+ arguments: { a: 5, b: 7 },
3175
+ name: "add",
3176
+ });
3177
+
3178
+ expect(result.content).toEqual([
3179
+ {
3180
+ text: "12",
3181
+ type: "text",
3182
+ },
3183
+ ]);
3184
+
3185
+ // Multiple calls should work independently in stateless mode
3186
+ const result2 = await client.callTool({
3187
+ arguments: { a: 10, b: 20 },
3188
+ name: "add",
3189
+ });
3190
+
3191
+ expect(result2.content).toEqual([
3192
+ {
3193
+ text: "30",
3194
+ type: "text",
3195
+ },
3196
+ ]);
3197
+
3198
+ // Server should not track sessions in stateless mode
3199
+ expect(server.sessions.length).toBe(0);
3200
+
3201
+ await client.close();
3202
+ } finally {
3203
+ await server.stop();
3204
+ }
3205
+ });
3206
+
3207
+ test("stateless mode health check includes mode indicator", async () => {
3208
+ const port = await getRandomPort();
3209
+
3210
+ const server = new FastMCP({
3211
+ name: "Test server",
3212
+ version: "1.0.0",
3213
+ });
3214
+
3215
+ await server.start({
3216
+ httpStream: {
3217
+ port,
3218
+ stateless: true,
3219
+ },
3220
+ transportType: "httpStream",
3221
+ });
3222
+
3223
+ try {
3224
+ const response = await fetch(`http://localhost:${port}/ready`);
3225
+ expect(response.status).toBe(200);
3226
+
3227
+ const json = await response.json();
3228
+ expect(json).toEqual({
3229
+ mode: "stateless",
3230
+ ready: 1,
3231
+ status: "ready",
3232
+ total: 1,
3233
+ });
3234
+ } finally {
3235
+ await server.stop();
3236
+ }
3237
+ });