@tsed/platform-mcp 8.38.0-beta.2 → 8.38.0-beta.4
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.
- package/.barrels.json +5 -0
- package/lib/esm/cli/exports.js +1 -0
- package/lib/esm/cli/index.js +7 -0
- package/lib/esm/cli/services/mcpServerConnect.js +15 -0
- package/lib/esm/cli/services/mcpStdioServer.js +7 -0
- package/lib/esm/cli/services/mcpStreamableServer.js +40 -0
- package/lib/esm/{index.js → common/index.js} +0 -1
- package/lib/esm/{services → common/services}/McpServerFactory.js +10 -11
- package/lib/esm/http/exports.js +1 -0
- package/lib/esm/http/index.js +5 -0
- package/lib/esm/{services → http/services}/PlatformMcpModule.js +1 -1
- package/lib/tsconfig.esm.tsbuildinfo +1 -1
- package/lib/types/cli/exports.d.ts +1 -0
- package/lib/types/cli/index.d.ts +7 -0
- package/lib/types/cli/services/mcpServerConnect.d.ts +1 -0
- package/lib/types/cli/services/mcpStdioServer.d.ts +2 -0
- package/lib/types/cli/services/mcpStreamableServer.d.ts +2 -0
- package/lib/types/{index.d.ts → common/index.d.ts} +0 -1
- package/lib/types/{services → common/services}/McpServerFactory.d.ts +1 -0
- package/lib/types/http/exports.d.ts +1 -0
- package/lib/types/http/index.d.ts +5 -0
- package/lib/types/{services → http/services}/PlatformMcpModule.d.ts +1 -1
- package/package.json +34 -16
- package/src/cli/exports.ts +1 -0
- package/src/cli/index.ts +7 -0
- package/src/cli/services/mcpServerConnect.spec.ts +37 -0
- package/src/cli/services/mcpServerConnect.ts +19 -0
- package/src/cli/services/mcpStdioServer.spec.ts +68 -0
- package/src/cli/services/mcpStdioServer.ts +12 -0
- package/src/cli/services/mcpStreamableServer.spec.ts +87 -0
- package/src/cli/services/mcpStreamableServer.ts +48 -0
- package/src/{index.ts → common/index.ts} +0 -1
- package/src/common/services/McpServerFactory.spec.ts +39 -0
- package/src/common/services/McpServerFactory.ts +78 -0
- package/src/http/exports.ts +1 -0
- package/src/http/index.ts +5 -0
- package/src/{services → http/services}/PlatformMcpModule.ts +3 -3
- package/src/services/McpServerFactory.ts +0 -81
- /package/lib/esm/{constants → common/constants}/constants.js +0 -0
- /package/lib/esm/{decorators → common/decorators}/prompt.js +0 -0
- /package/lib/esm/{decorators → common/decorators}/resource.js +0 -0
- /package/lib/esm/{decorators → common/decorators}/tool.js +0 -0
- /package/lib/esm/{fn → common/fn}/definePrompt.js +0 -0
- /package/lib/esm/{fn → common/fn}/defineResource.js +0 -0
- /package/lib/esm/{fn → common/fn}/defineTool.js +0 -0
- /package/lib/esm/{interfaces → common/interfaces}/PlatformMcpSettings.js +0 -0
- /package/lib/esm/{utils → common/utils}/asResourceResponse.js +0 -0
- /package/lib/esm/{utils → common/utils}/asToolResponse.js +0 -0
- /package/lib/esm/{utils → common/utils}/fromJsonSchema.js +0 -0
- /package/lib/types/{constants → common/constants}/constants.d.ts +0 -0
- /package/lib/types/{decorators → common/decorators}/prompt.d.ts +0 -0
- /package/lib/types/{decorators → common/decorators}/resource.d.ts +0 -0
- /package/lib/types/{decorators → common/decorators}/tool.d.ts +0 -0
- /package/lib/types/{fn → common/fn}/definePrompt.d.ts +0 -0
- /package/lib/types/{fn → common/fn}/defineResource.d.ts +0 -0
- /package/lib/types/{fn → common/fn}/defineTool.d.ts +0 -0
- /package/lib/types/{interfaces → common/interfaces}/PlatformMcpSettings.d.ts +0 -0
- /package/lib/types/{utils → common/utils}/asResourceResponse.d.ts +0 -0
- /package/lib/types/{utils → common/utils}/asToolResponse.d.ts +0 -0
- /package/lib/types/{utils → common/utils}/fromJsonSchema.d.ts +0 -0
- /package/src/{constants → common/constants}/constants.ts +0 -0
- /package/src/{decorators → common/decorators}/prompt.spec.ts +0 -0
- /package/src/{decorators → common/decorators}/prompt.ts +0 -0
- /package/src/{decorators → common/decorators}/resource.spec.ts +0 -0
- /package/src/{decorators → common/decorators}/resource.ts +0 -0
- /package/src/{decorators → common/decorators}/tool.spec.ts +0 -0
- /package/src/{decorators → common/decorators}/tool.ts +0 -0
- /package/src/{fn → common/fn}/definePrompt.spec.ts +0 -0
- /package/src/{fn → common/fn}/definePrompt.ts +0 -0
- /package/src/{fn → common/fn}/defineResource.spec.ts +0 -0
- /package/src/{fn → common/fn}/defineResource.ts +0 -0
- /package/src/{fn → common/fn}/defineTool.spec.ts +0 -0
- /package/src/{fn → common/fn}/defineTool.ts +0 -0
- /package/src/{interfaces → common/interfaces}/PlatformMcpSettings.ts +0 -0
- /package/src/{utils → common/utils}/asResourceResponse.spec.ts +0 -0
- /package/src/{utils → common/utils}/asResourceResponse.ts +0 -0
- /package/src/{utils → common/utils}/asToolResponse.spec.ts +0 -0
- /package/src/{utils → common/utils}/asToolResponse.ts +0 -0
- /package/src/{utils → common/utils}/fromJsonSchema.spec.ts +0 -0
- /package/src/{utils → common/utils}/fromJsonSchema.ts +0 -0
- /package/src/{services → http/services}/PlatformMcpModule.spec.ts +0 -0
package/.barrels.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "../common/index.js";
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { inject, logger } from "@tsed/di";
|
|
2
|
+
import { MCP_SERVER } from "../../common/index.js";
|
|
3
|
+
import { mcpStdioServer } from "./mcpStdioServer.js";
|
|
4
|
+
import { mcpStreamableServer } from "./mcpStreamableServer.js";
|
|
5
|
+
export async function mcpServerConnect(mode) {
|
|
6
|
+
const server = inject(MCP_SERVER);
|
|
7
|
+
if (mode === "streamable-http") {
|
|
8
|
+
logger().info({ event: "MCP_SERVER_CONNECT", mode });
|
|
9
|
+
await mcpStreamableServer(server);
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
await mcpStdioServer(server);
|
|
13
|
+
}
|
|
14
|
+
return server;
|
|
15
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { logger } from "@tsed/di";
|
|
2
|
+
export async function mcpStdioServer(server) {
|
|
3
|
+
const { StdioServerTransport } = await import("@modelcontextprotocol/server/stdio");
|
|
4
|
+
const transport = new StdioServerTransport();
|
|
5
|
+
logger().stop();
|
|
6
|
+
return server.connect(transport);
|
|
7
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { logger } from "@tsed/di";
|
|
2
|
+
export async function mcpStreamableServer(server) {
|
|
3
|
+
const { NodeStreamableHTTPServerTransport } = await import("@modelcontextprotocol/node");
|
|
4
|
+
// @ts-ignore
|
|
5
|
+
const { default: express } = await import("express");
|
|
6
|
+
const app = express();
|
|
7
|
+
app.use(express.json());
|
|
8
|
+
app.post("/mcp", async (req, res) => {
|
|
9
|
+
// Create a new transport for each request to prevent request ID collisions
|
|
10
|
+
const transport = new NodeStreamableHTTPServerTransport({
|
|
11
|
+
sessionIdGenerator: undefined,
|
|
12
|
+
enableJsonResponse: true
|
|
13
|
+
});
|
|
14
|
+
res.on("close", () => {
|
|
15
|
+
transport.close();
|
|
16
|
+
});
|
|
17
|
+
await server.connect(transport);
|
|
18
|
+
await transport.handleRequest(req, res, req.body);
|
|
19
|
+
});
|
|
20
|
+
const port = parseInt(process.env.PORT || "3000");
|
|
21
|
+
return new Promise((resolve, reject) => {
|
|
22
|
+
app
|
|
23
|
+
.listen(port, () => {
|
|
24
|
+
logger().info({
|
|
25
|
+
event: "MCP_STREAMABLE_SERVER",
|
|
26
|
+
state: "OK",
|
|
27
|
+
message: `Running http://localhost:${port}/mcp`
|
|
28
|
+
});
|
|
29
|
+
})
|
|
30
|
+
.on("close", () => resolve(true))
|
|
31
|
+
.on("error", (error) => {
|
|
32
|
+
logger().error({
|
|
33
|
+
event: "MCP_STREAMABLE_SERVER",
|
|
34
|
+
state: "KO",
|
|
35
|
+
message: error.message
|
|
36
|
+
});
|
|
37
|
+
reject(error);
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
}
|
|
@@ -10,7 +10,6 @@ export * from "./fn/defineResource.js";
|
|
|
10
10
|
export * from "./fn/defineTool.js";
|
|
11
11
|
export * from "./interfaces/PlatformMcpSettings.js";
|
|
12
12
|
export * from "./services/McpServerFactory.js";
|
|
13
|
-
export * from "./services/PlatformMcpModule.js";
|
|
14
13
|
export * from "./utils/asResourceResponse.js";
|
|
15
14
|
export * from "./utils/asToolResponse.js";
|
|
16
15
|
export * from "./utils/fromJsonSchema.js";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { constant, inject, injectable, injector } from "@tsed/di";
|
|
2
|
-
import { MCP_PROVIDER_TYPES } from "../
|
|
2
|
+
import { MCP_PROVIDER_TYPES } from "../index.js";
|
|
3
3
|
import { McpServer } from "@modelcontextprotocol/server";
|
|
4
4
|
function collectTokens(type, configured = []) {
|
|
5
5
|
const tokens = new Set(configured);
|
|
@@ -8,14 +8,7 @@ function collectTokens(type, configured = []) {
|
|
|
8
8
|
.forEach((provider) => tokens.add(provider.token));
|
|
9
9
|
return [...tokens];
|
|
10
10
|
}
|
|
11
|
-
|
|
12
|
-
* Injectable MCP server instance configured with registered tools, resources, and prompts.
|
|
13
|
-
*
|
|
14
|
-
* @module platform/mcp
|
|
15
|
-
* @since 8.17.0
|
|
16
|
-
*/
|
|
17
|
-
export const MCP_SERVER = injectable(McpServer)
|
|
18
|
-
.factory(() => {
|
|
11
|
+
export function createMcpServer() {
|
|
19
12
|
const settings = constant("mcp", {}) || {};
|
|
20
13
|
const name = settings.name || constant("name") || "tsed-mcp";
|
|
21
14
|
const version = settings.version || constant("version") || "0.0.0";
|
|
@@ -53,5 +46,11 @@ export const MCP_SERVER = injectable(McpServer)
|
|
|
53
46
|
server.registerPrompt(name || String(token), opts, handler);
|
|
54
47
|
});
|
|
55
48
|
return server;
|
|
56
|
-
}
|
|
57
|
-
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Injectable MCP server instance configured with registered tools, resources, and prompts.
|
|
52
|
+
*
|
|
53
|
+
* @module platform/mcp
|
|
54
|
+
* @since 8.17.0
|
|
55
|
+
*/
|
|
56
|
+
export const MCP_SERVER = injectable(McpServer).factory(createMcpServer).token();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "../common/index.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { application } from "@tsed/platform-http";
|
|
2
2
|
import { constant, inject, injectable } from "@tsed/di";
|
|
3
|
-
import { MCP_SERVER } from "
|
|
3
|
+
import { MCP_SERVER } from "../../common/services/McpServerFactory.js";
|
|
4
4
|
import { NodeStreamableHTTPServerTransport } from "@modelcontextprotocol/node";
|
|
5
5
|
import { useContextHandler } from "@tsed/platform-router";
|
|
6
6
|
/**
|