@tsed/platform-mcp 8.43.0 → 8.43.2

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.
@@ -29,6 +29,15 @@ export async function mcpStreamableServer(createServer) {
29
29
  await closeServer();
30
30
  }
31
31
  });
32
+ // the endpoint is stateless: there is no event stream to open nor session to delete
33
+ const methodNotAllowed = (_req, res) => {
34
+ res
35
+ .status(405)
36
+ .set("Allow", "POST")
37
+ .json({ jsonrpc: "2.0", error: { code: -32000, message: "Method not allowed." }, id: null });
38
+ };
39
+ app.get("/mcp", methodNotAllowed);
40
+ app.delete("/mcp", methodNotAllowed);
32
41
  const port = parseInt(process.env.PORT || "3000");
33
42
  return new Promise((resolve, reject) => {
34
43
  app
@@ -50,6 +50,9 @@ export class PlatformMcpModule {
50
50
  name: "PlatformMcpModule.dispatch()",
51
51
  url: path
52
52
  });
53
+ // the endpoint is stateless: there is no event stream to open nor session to delete
54
+ this.app.get(path, useContextHandler(($ctx) => this.methodNotAllowed($ctx)));
55
+ this.app.delete(path, useContextHandler(($ctx) => this.methodNotAllowed($ctx)));
53
56
  }
54
57
  this.loaded = true;
55
58
  }
@@ -71,6 +74,16 @@ export class PlatformMcpModule {
71
74
  throw new Error(`MCP endpoint "${path}": the upstream uses \${OAUTH_*} placeholders but the endpoint declares no auth.`);
72
75
  }
73
76
  }
77
+ /**
78
+ * Answers the methods of the Streamable HTTP transport that a stateless endpoint does not serve,
79
+ * so MCP clients know there is no event stream instead of receiving the application's 404 page.
80
+ */
81
+ methodNotAllowed($ctx) {
82
+ return $ctx.response
83
+ .status(405)
84
+ .setHeaders({ allow: "POST" })
85
+ .body({ jsonrpc: "2.0", error: { code: -32000, message: "Method not allowed." }, id: null });
86
+ }
74
87
  metadata(settings, $ctx) {
75
88
  const auth = settings.auth;
76
89
  const resource = this.platformAuthService.getResourceUrl(auth);