@ttoss/http-server-mcp 0.3.0 → 0.3.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.
- package/dist/index.d.cts +61 -0
- package/dist/index.js +87 -0
- package/package.json +3 -2
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import * as _koa_router from '@koa/router';
|
|
2
|
+
import * as koa from 'koa';
|
|
3
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
4
|
+
export { McpServer, McpServer as Server } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
5
|
+
export { z } from 'zod';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Options for configuring the MCP router
|
|
9
|
+
*/
|
|
10
|
+
interface McpRouterOptions {
|
|
11
|
+
/**
|
|
12
|
+
* The HTTP path where the MCP server will be mounted
|
|
13
|
+
* @default '/mcp'
|
|
14
|
+
*/
|
|
15
|
+
path?: string;
|
|
16
|
+
/**
|
|
17
|
+
* Optional session ID generator for stateful MCP servers
|
|
18
|
+
* Set to undefined for stateless servers
|
|
19
|
+
*/
|
|
20
|
+
sessionIdGenerator?: () => string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Creates a Koa router configured to handle MCP protocol requests
|
|
24
|
+
*
|
|
25
|
+
* @param server - The MCP server instance with registered tools and resources
|
|
26
|
+
* @param options - Configuration options for the router
|
|
27
|
+
* @returns A Koa Router instance configured for MCP
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* import { App, bodyParser } from '@ttoss/http-server';
|
|
32
|
+
* import { createMcpRouter, Server as McpServer, z } from '@ttoss/http-server-mcp';
|
|
33
|
+
*
|
|
34
|
+
* const mcpServer = new McpServer({
|
|
35
|
+
* name: 'my-server',
|
|
36
|
+
* version: '1.0.0',
|
|
37
|
+
* });
|
|
38
|
+
*
|
|
39
|
+
* mcpServer.registerTool(
|
|
40
|
+
* 'hello',
|
|
41
|
+
* {
|
|
42
|
+
* description: 'Say hello',
|
|
43
|
+
* inputSchema: { name: z.string() },
|
|
44
|
+
* },
|
|
45
|
+
* async ({ name }) => ({
|
|
46
|
+
* content: [{ type: 'text', text: `Hello, ${name}!` }],
|
|
47
|
+
* })
|
|
48
|
+
* );
|
|
49
|
+
*
|
|
50
|
+
* const app = new App();
|
|
51
|
+
* app.use(bodyParser());
|
|
52
|
+
*
|
|
53
|
+
* const mcpRouter = createMcpRouter(mcpServer);
|
|
54
|
+
* app.use(mcpRouter.routes());
|
|
55
|
+
*
|
|
56
|
+
* app.listen(3000);
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
declare const createMcpRouter: (server: McpServer, options?: McpRouterOptions) => _koa_router.RouterInstance<koa.DefaultState, koa.DefaultContext>;
|
|
60
|
+
|
|
61
|
+
export { type McpRouterOptions, createMcpRouter };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
|
|
2
|
+
"use strict";
|
|
3
|
+
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __name = (target, value) => __defProp(target, "name", {
|
|
9
|
+
value,
|
|
10
|
+
configurable: true
|
|
11
|
+
});
|
|
12
|
+
var __export = (target, all) => {
|
|
13
|
+
for (var name in all) __defProp(target, name, {
|
|
14
|
+
get: all[name],
|
|
15
|
+
enumerable: true
|
|
16
|
+
});
|
|
17
|
+
};
|
|
18
|
+
var __copyProps = (to, from, except, desc) => {
|
|
19
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
20
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
21
|
+
get: () => from[key],
|
|
22
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
return to;
|
|
26
|
+
};
|
|
27
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
28
|
+
value: true
|
|
29
|
+
}), mod);
|
|
30
|
+
|
|
31
|
+
// src/index.ts
|
|
32
|
+
var index_exports = {};
|
|
33
|
+
__export(index_exports, {
|
|
34
|
+
Server: () => import_mcp.McpServer,
|
|
35
|
+
createMcpRouter: () => createMcpRouter,
|
|
36
|
+
z: () => import_zod.z
|
|
37
|
+
});
|
|
38
|
+
module.exports = __toCommonJS(index_exports);
|
|
39
|
+
var import_streamableHttp = require("@modelcontextprotocol/sdk/server/streamableHttp.js");
|
|
40
|
+
var import_http_server = require("@ttoss/http-server");
|
|
41
|
+
var import_mcp = require("@modelcontextprotocol/sdk/server/mcp.js");
|
|
42
|
+
var import_zod = require("zod");
|
|
43
|
+
var createMcpRouter = /* @__PURE__ */__name((server, options = {}) => {
|
|
44
|
+
const {
|
|
45
|
+
path = "/mcp",
|
|
46
|
+
sessionIdGenerator
|
|
47
|
+
} = options;
|
|
48
|
+
const transport = new import_streamableHttp.StreamableHTTPServerTransport({
|
|
49
|
+
sessionIdGenerator,
|
|
50
|
+
enableJsonResponse: true
|
|
51
|
+
});
|
|
52
|
+
server.connect(transport);
|
|
53
|
+
const router = new import_http_server.Router();
|
|
54
|
+
router.post(path, async ctx => {
|
|
55
|
+
try {
|
|
56
|
+
await transport.handleRequest(ctx.req, ctx.res, ctx.request.body);
|
|
57
|
+
ctx.respond = false;
|
|
58
|
+
} catch (error) {
|
|
59
|
+
if (!ctx.res.headersSent) {
|
|
60
|
+
ctx.status = 500;
|
|
61
|
+
ctx.body = {
|
|
62
|
+
error: error instanceof Error ? error.message : "Internal server error"
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
router.delete(path, async ctx => {
|
|
68
|
+
try {
|
|
69
|
+
await transport.handleRequest(ctx.req, ctx.res, void 0);
|
|
70
|
+
ctx.respond = false;
|
|
71
|
+
} catch (error) {
|
|
72
|
+
if (!ctx.res.headersSent) {
|
|
73
|
+
ctx.status = 500;
|
|
74
|
+
ctx.body = {
|
|
75
|
+
error: error instanceof Error ? error.message : "Internal server error"
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
return router;
|
|
81
|
+
}, "createMcpRouter");
|
|
82
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
83
|
+
0 && (module.exports = {
|
|
84
|
+
Server,
|
|
85
|
+
createMcpRouter,
|
|
86
|
+
z
|
|
87
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ttoss/http-server-mcp",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"description": "Model Context Protocol (MCP) server integration for @ttoss/http-server",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "ttoss",
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
"exports": {
|
|
17
17
|
".": {
|
|
18
18
|
"import": "./dist/esm/index.js",
|
|
19
|
+
"require": "./dist/index.js",
|
|
19
20
|
"types": "./dist/index.d.ts"
|
|
20
21
|
}
|
|
21
22
|
},
|
|
@@ -26,7 +27,7 @@
|
|
|
26
27
|
"dependencies": {
|
|
27
28
|
"@modelcontextprotocol/sdk": "^1.0.4",
|
|
28
29
|
"zod": "^3.25.76",
|
|
29
|
-
"@ttoss/http-server": "^0.3.
|
|
30
|
+
"@ttoss/http-server": "^0.3.2"
|
|
30
31
|
},
|
|
31
32
|
"devDependencies": {
|
|
32
33
|
"@types/koa": "^3.0.1",
|