toolception 0.1.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.
- package/LICENSE +201 -0
- package/README.md +292 -0
- package/dist/index.js +671 -0
- package/dist/index.js.map +1 -0
- package/package.json +66 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
# Toolception – Dynamic MCP Tooling Library
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/toolception)
|
|
4
|
+
[](LICENSE)
|
|
5
|
+
|
|
6
|
+
## Table of Contents
|
|
7
|
+
|
|
8
|
+
- [Starter guide](#starter-guide)
|
|
9
|
+
- [Static startup](#static-startup)
|
|
10
|
+
- [API](#api)
|
|
11
|
+
- [Client ID lifecycle](#client-id-lifecycle)
|
|
12
|
+
- [Session ID lifecycle](#session-id-lifecycle)
|
|
13
|
+
- [Tool types](#tool-types)
|
|
14
|
+
- [Startup modes](#startup-modes)
|
|
15
|
+
- [License](#license)
|
|
16
|
+
|
|
17
|
+
## Starter guide
|
|
18
|
+
|
|
19
|
+
### Step 1: Install
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npm i toolception
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
### Step 2: Import Toolception
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
import { createMcpServer } from "toolception";
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### Step 3: Define a toolset catalog
|
|
32
|
+
|
|
33
|
+
```ts
|
|
34
|
+
const catalog = {
|
|
35
|
+
quotes: { name: "Quotes", description: "Market quotes", modules: ["quotes"] },
|
|
36
|
+
};
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### Step 4: Define a tool
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
const quoteTool = {
|
|
43
|
+
name: "price",
|
|
44
|
+
description: "Return a fake price",
|
|
45
|
+
inputSchema: {
|
|
46
|
+
type: "object",
|
|
47
|
+
properties: { symbol: { type: "string" } },
|
|
48
|
+
required: ["symbol"],
|
|
49
|
+
},
|
|
50
|
+
handler: async ({ symbol }: { symbol: string }) => ({
|
|
51
|
+
content: [{ type: "text", text: `${symbol}: 123.45` }],
|
|
52
|
+
}),
|
|
53
|
+
} as const;
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### Step 5: Provide module loaders
|
|
57
|
+
|
|
58
|
+
```ts
|
|
59
|
+
const moduleLoaders = {
|
|
60
|
+
quotes: async () => [quoteTool],
|
|
61
|
+
};
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### Step 6: (Optional) Configuration schema
|
|
65
|
+
|
|
66
|
+
```ts
|
|
67
|
+
const configSchema = {
|
|
68
|
+
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
69
|
+
type: "object",
|
|
70
|
+
properties: {
|
|
71
|
+
REQUIRED_PARAM: { type: "string", title: "Required Param" },
|
|
72
|
+
OPTIONAL_PARAM: { type: "string", title: "Optional Param" },
|
|
73
|
+
},
|
|
74
|
+
required: ["REQUIRED_PARAM"],
|
|
75
|
+
} as const;
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Step 7: Create and start the MCP server
|
|
79
|
+
|
|
80
|
+
```ts
|
|
81
|
+
const { start, close } = await createMcpServer({
|
|
82
|
+
catalog,
|
|
83
|
+
moduleLoaders,
|
|
84
|
+
startup: { mode: "DYNAMIC" },
|
|
85
|
+
http: { port: 3000 },
|
|
86
|
+
// configSchema, // uncomment to expose at /.well-known/mcp-config
|
|
87
|
+
});
|
|
88
|
+
await start();
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### Step 8: Graceful shutdown
|
|
92
|
+
|
|
93
|
+
```ts
|
|
94
|
+
process.on("SIGINT", async () => {
|
|
95
|
+
await close();
|
|
96
|
+
process.exit(0);
|
|
97
|
+
});
|
|
98
|
+
process.on("SIGTERM", async () => {
|
|
99
|
+
await close();
|
|
100
|
+
process.exit(0);
|
|
101
|
+
});
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## Static startup
|
|
105
|
+
|
|
106
|
+
Enable some or ALL toolsets at bootstrap:
|
|
107
|
+
|
|
108
|
+
```ts
|
|
109
|
+
const staticCatalog = {
|
|
110
|
+
search: { name: "Search", description: "Search tools", modules: ["search"] },
|
|
111
|
+
quotes: { name: "Quotes", description: "Market quotes", modules: ["quotes"] },
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
createMcpServer({
|
|
115
|
+
catalog: staticCatalog,
|
|
116
|
+
startup: { mode: "STATIC", toolsets: ["search", "quotes"] },
|
|
117
|
+
http: { port: 3001 },
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
createMcpServer({
|
|
121
|
+
catalog: staticCatalog,
|
|
122
|
+
startup: { mode: "STATIC", toolsets: "ALL" },
|
|
123
|
+
http: { port: 3002 },
|
|
124
|
+
});
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## API
|
|
128
|
+
|
|
129
|
+
### createMcpServer(options)
|
|
130
|
+
|
|
131
|
+
Creates an MCP server with dynamic/static tool management and Fastify HTTP transport.
|
|
132
|
+
|
|
133
|
+
#### options.catalog (required)
|
|
134
|
+
|
|
135
|
+
`Record<string, ToolSetDefinition>`
|
|
136
|
+
|
|
137
|
+
- Defines available toolsets to expose. Each item includes `name`, `description`, optional inline `tools`, optional `modules` (for lazy loaders), and optional `decisionCriteria`.
|
|
138
|
+
|
|
139
|
+
#### options.moduleLoaders (optional)
|
|
140
|
+
|
|
141
|
+
`Record<string, ModuleLoader>`
|
|
142
|
+
|
|
143
|
+
- Maps module keys to async loaders returning `McpToolDefinition[]`. Referenced by toolsets via `modules: [key]`.
|
|
144
|
+
|
|
145
|
+
#### options.startup (optional)
|
|
146
|
+
|
|
147
|
+
`{ mode?: "DYNAMIC" | "STATIC"; toolsets?: string[] | "ALL" }`
|
|
148
|
+
|
|
149
|
+
- Controls startup behavior. In STATIC mode, pre-load specific toolsets (or ALL). In DYNAMIC, register meta-tools and load on demand.
|
|
150
|
+
|
|
151
|
+
#### options.registerMetaTools (optional)
|
|
152
|
+
|
|
153
|
+
`boolean` (default: true in DYNAMIC mode; false in STATIC unless explicitly set)
|
|
154
|
+
|
|
155
|
+
- Whether to register management tools like `enable_toolset`, `disable_toolset`, `list_tools`.
|
|
156
|
+
|
|
157
|
+
#### options.exposurePolicy (optional)
|
|
158
|
+
|
|
159
|
+
`ExposurePolicy`
|
|
160
|
+
|
|
161
|
+
- Limits and namespacing for registered tools (e.g., `maxActiveToolsets`, `namespaceToolsWithSetKey`, `allowlist`/`denylist`).
|
|
162
|
+
|
|
163
|
+
#### options.context (optional)
|
|
164
|
+
|
|
165
|
+
`unknown`
|
|
166
|
+
|
|
167
|
+
- Arbitrary context passed to `moduleLoaders` during tool resolution.
|
|
168
|
+
|
|
169
|
+
#### options.http (optional)
|
|
170
|
+
|
|
171
|
+
`{ host?: string; port?: number; basePath?: string; cors?: boolean; logger?: boolean }`
|
|
172
|
+
|
|
173
|
+
- Fastify transport configuration. Defaults: host `0.0.0.0`, port `3000`, basePath `/`, CORS enabled, logger disabled.
|
|
174
|
+
|
|
175
|
+
#### options.mcp (optional)
|
|
176
|
+
|
|
177
|
+
`{ name?: string; version?: string; capabilities?: Record<string, unknown> }`
|
|
178
|
+
|
|
179
|
+
- Overrides MCP server identity and capabilities; `tools.listChanged` is set automatically based on mode.
|
|
180
|
+
|
|
181
|
+
#### options.configSchema (optional)
|
|
182
|
+
|
|
183
|
+
`object`
|
|
184
|
+
|
|
185
|
+
- JSON Schema exposed at `GET /.well-known/mcp-config` for client discovery.
|
|
186
|
+
|
|
187
|
+
### Meta-tools
|
|
188
|
+
|
|
189
|
+
Enabled by default when mode is DYNAMIC (or when `registerMetaTools` is true):
|
|
190
|
+
|
|
191
|
+
- `enable_toolset`, `disable_toolset`, `list_tools`
|
|
192
|
+
Only in DYNAMIC mode:
|
|
193
|
+
- `list_toolsets`, `describe_toolset`
|
|
194
|
+
|
|
195
|
+
## Client ID lifecycle
|
|
196
|
+
|
|
197
|
+
- **What**: Clients identify themselves via the `mcp-client-id` HTTP header on every request.
|
|
198
|
+
- **Who generates it**: The client. Use a stable identifier (e.g., UUID persisted locally).
|
|
199
|
+
- **If omitted**: The server assigns a one-off `anon-<uuid>` and skips caching; this is unsuitable for multi-request flows and SSE.
|
|
200
|
+
|
|
201
|
+
Examples (official MCP client)
|
|
202
|
+
|
|
203
|
+
```ts
|
|
204
|
+
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
205
|
+
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
206
|
+
|
|
207
|
+
// Create a stable client id (persist it for reuse across runs)
|
|
208
|
+
const clientId = "my-stable-client-id"; // e.g., from disk/env
|
|
209
|
+
|
|
210
|
+
// Transport manages HTTP, including SSE and JSON-RPC framing
|
|
211
|
+
const transport = new StreamableHTTPClientTransport(
|
|
212
|
+
new URL("http://localhost:3000/mcp"),
|
|
213
|
+
{
|
|
214
|
+
requestInit: { headers: { "mcp-client-id": clientId } },
|
|
215
|
+
}
|
|
216
|
+
);
|
|
217
|
+
|
|
218
|
+
// High-level MCP client
|
|
219
|
+
const client = new Client({ name: "example-client", version: "1.0.0" });
|
|
220
|
+
|
|
221
|
+
// Connect negotiates capabilities and establishes a session. Transport handles session id.
|
|
222
|
+
await client.connect(transport);
|
|
223
|
+
|
|
224
|
+
// Call a tool (example)
|
|
225
|
+
const res = await client.listTools();
|
|
226
|
+
console.log(res);
|
|
227
|
+
|
|
228
|
+
// Close when done
|
|
229
|
+
await client.close();
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
## Session ID lifecycle
|
|
233
|
+
|
|
234
|
+
- **What**: A per-session identifier returned by the server on initialize.
|
|
235
|
+
- **Who generates it**: The server during initialize. The client must read it from the initialize response headers and send it back on subsequent requests via `mcp-session-id`.
|
|
236
|
+
- **Used for**: Follow-up JSON-RPC requests (POST `/mcp`), SSE stream (GET `/mcp`), and termination (DELETE `/mcp`).
|
|
237
|
+
|
|
238
|
+
Examples (official MCP client)
|
|
239
|
+
|
|
240
|
+
```ts
|
|
241
|
+
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
242
|
+
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
243
|
+
|
|
244
|
+
const clientId = "my-stable-client-id";
|
|
245
|
+
const transport = new StreamableHTTPClientTransport(
|
|
246
|
+
new URL("http://localhost:3000/mcp"),
|
|
247
|
+
{
|
|
248
|
+
requestInit: { headers: { "mcp-client-id": clientId } },
|
|
249
|
+
}
|
|
250
|
+
);
|
|
251
|
+
|
|
252
|
+
const client = new Client({ name: "example-client", version: "1.0.0" });
|
|
253
|
+
await client.connect(transport);
|
|
254
|
+
|
|
255
|
+
// Session id is handled by the transport. No need to manually set mcp-session-id.
|
|
256
|
+
|
|
257
|
+
// Call tools
|
|
258
|
+
await client.callTool({ name: "enable_toolset", arguments: { name: "core" } });
|
|
259
|
+
const ping = await client.callTool({ name: "core.ping", arguments: {} });
|
|
260
|
+
console.log(ping);
|
|
261
|
+
|
|
262
|
+
// When finished
|
|
263
|
+
await client.close();
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
## Tool types
|
|
267
|
+
|
|
268
|
+
- Direct tools: defined inline under `catalog[toolset].tools` and registered when that toolset is enabled.
|
|
269
|
+
- Module-produced tools: returned by `moduleLoaders[moduleKey]()` and registered when enabling a toolset that references `modules: [moduleKey]`.
|
|
270
|
+
|
|
271
|
+
Use direct tools for simple/local utilities; use module-produced tools to share tools across multiple toolsets or lazily load heavier definitions.
|
|
272
|
+
|
|
273
|
+
Note on dynamic mode: Both direct and module-produced tools are supported. Module-produced tools help minimize startup footprint by enabling on-demand loading at enable-time.
|
|
274
|
+
|
|
275
|
+
## Startup modes
|
|
276
|
+
|
|
277
|
+
The server operates in one of two primary modes (legacy load-all is not recommended here):
|
|
278
|
+
|
|
279
|
+
1. Dynamic mode (startup.mode = "DYNAMIC")
|
|
280
|
+
|
|
281
|
+
- Starts with meta-tools for runtime management: `enable_toolset`, `disable_toolset`, `list_toolsets`, `describe_toolset`, and `list_tools` (always available)
|
|
282
|
+
- Tools are loaded on-demand via meta-tool calls
|
|
283
|
+
- Best for flexible, task-specific workflows where tool needs change
|
|
284
|
+
|
|
285
|
+
2. Static mode (startup.mode = "STATIC")
|
|
286
|
+
- Pre-loads specific toolsets at startup (`toolsets` array or "ALL")
|
|
287
|
+
- Meta-tools limited to `list_tools` by default
|
|
288
|
+
- Best for known, consistent tool requirements
|
|
289
|
+
|
|
290
|
+
## License
|
|
291
|
+
|
|
292
|
+
Apache-2.0. See `LICENSE` for details.
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,671 @@
|
|
|
1
|
+
import { McpServer as y } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
+
import { z as g } from "zod";
|
|
3
|
+
import S from "fastify";
|
|
4
|
+
import I from "@fastify/cors";
|
|
5
|
+
import { randomUUID as T } from "node:crypto";
|
|
6
|
+
import { StreamableHTTPServerTransport as $ } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
|
|
7
|
+
import { isInitializeRequest as L } from "@modelcontextprotocol/sdk/types.js";
|
|
8
|
+
const p = {
|
|
9
|
+
dynamic: ["dynamic-tool-discovery", "dynamicToolDiscovery", "DYNAMIC_TOOL_DISCOVERY"],
|
|
10
|
+
toolsets: ["tool-sets", "toolSets", "FMP_TOOL_SETS"]
|
|
11
|
+
};
|
|
12
|
+
class D {
|
|
13
|
+
constructor(e = {}) {
|
|
14
|
+
this.keys = {
|
|
15
|
+
dynamic: e.keys?.dynamic ?? p.dynamic,
|
|
16
|
+
toolsets: e.keys?.toolsets ?? p.toolsets
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
resolveMode(e, s) {
|
|
20
|
+
return this.isDynamicEnabled(s) ? "DYNAMIC" : this.getToolsetsString(s) ? "STATIC" : this.isDynamicEnabled(e) ? "DYNAMIC" : this.getToolsetsString(e) ? "STATIC" : null;
|
|
21
|
+
}
|
|
22
|
+
parseCommaSeparatedToolSets(e, s) {
|
|
23
|
+
if (!e || typeof e != "string") return [];
|
|
24
|
+
const t = e.split(",").map((r) => r.trim()).filter((r) => r.length > 0), o = new Set(Object.keys(s)), i = [];
|
|
25
|
+
for (const r of t)
|
|
26
|
+
o.has(r) ? i.push(r) : console.warn(`Invalid toolset '${r}' ignored. Available: ${Array.from(o).join(", ")}`);
|
|
27
|
+
return i;
|
|
28
|
+
}
|
|
29
|
+
getModulesForToolSets(e, s) {
|
|
30
|
+
const t = /* @__PURE__ */ new Set();
|
|
31
|
+
for (const o of e) {
|
|
32
|
+
const i = s[o];
|
|
33
|
+
i && (i.modules || []).forEach((r) => t.add(r));
|
|
34
|
+
}
|
|
35
|
+
return Array.from(t);
|
|
36
|
+
}
|
|
37
|
+
validateToolsetName(e, s) {
|
|
38
|
+
if (!e || typeof e != "string")
|
|
39
|
+
return { isValid: !1, error: `Invalid toolset name provided. Must be a non-empty string. Available toolsets: ${Object.keys(s).join(", ")}` };
|
|
40
|
+
const t = e.trim();
|
|
41
|
+
return t.length === 0 ? { isValid: !1, error: `Empty toolset name provided. Available toolsets: ${Object.keys(s).join(", ")}` } : s[t] ? { isValid: !0, sanitized: t } : { isValid: !1, error: `Toolset '${t}' not found. Available toolsets: ${Object.keys(s).join(", ")}` };
|
|
42
|
+
}
|
|
43
|
+
validateToolsetModules(e, s) {
|
|
44
|
+
try {
|
|
45
|
+
const t = this.getModulesForToolSets(e, s);
|
|
46
|
+
return !t || t.length === 0 ? { isValid: !1, error: `No modules found for toolsets: ${e.join(", ")}` } : { isValid: !0, modules: t };
|
|
47
|
+
} catch (t) {
|
|
48
|
+
return { isValid: !1, error: `Error resolving modules for ${e.join(", ")}: ${t instanceof Error ? t.message : "Unknown error"}` };
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
isDynamicEnabled(e) {
|
|
52
|
+
if (!e) return !1;
|
|
53
|
+
for (const s of this.keys.dynamic) {
|
|
54
|
+
const t = e[s];
|
|
55
|
+
if (t === !0 || typeof t == "string" && t.trim().toLowerCase() === "true")
|
|
56
|
+
return !0;
|
|
57
|
+
}
|
|
58
|
+
return !1;
|
|
59
|
+
}
|
|
60
|
+
getToolsetsString(e) {
|
|
61
|
+
if (e)
|
|
62
|
+
for (const s of this.keys.toolsets) {
|
|
63
|
+
const t = e[s];
|
|
64
|
+
if (typeof t == "string" && t.trim().length > 0) return t;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
class E {
|
|
69
|
+
constructor(e) {
|
|
70
|
+
this.catalog = e.catalog, this.moduleLoaders = e.moduleLoaders ?? {};
|
|
71
|
+
}
|
|
72
|
+
getAvailableToolsets() {
|
|
73
|
+
return Object.keys(this.catalog);
|
|
74
|
+
}
|
|
75
|
+
getToolsetDefinition(e) {
|
|
76
|
+
return this.catalog[e];
|
|
77
|
+
}
|
|
78
|
+
validateToolsetName(e) {
|
|
79
|
+
if (!e || typeof e != "string")
|
|
80
|
+
return {
|
|
81
|
+
isValid: !1,
|
|
82
|
+
error: `Invalid toolset name provided. Must be a non-empty string. Available toolsets: ${this.getAvailableToolsets().join(
|
|
83
|
+
", "
|
|
84
|
+
)}`
|
|
85
|
+
};
|
|
86
|
+
const s = e.trim();
|
|
87
|
+
return s.length === 0 ? {
|
|
88
|
+
isValid: !1,
|
|
89
|
+
error: `Empty toolset name provided. Available toolsets: ${this.getAvailableToolsets().join(
|
|
90
|
+
", "
|
|
91
|
+
)}`
|
|
92
|
+
} : this.catalog[s] ? { isValid: !0, sanitized: s } : {
|
|
93
|
+
isValid: !1,
|
|
94
|
+
error: `Toolset '${s}' not found. Available toolsets: ${this.getAvailableToolsets().join(
|
|
95
|
+
", "
|
|
96
|
+
)}`
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
async resolveToolsForToolsets(e, s) {
|
|
100
|
+
const t = [];
|
|
101
|
+
for (const o of e) {
|
|
102
|
+
const i = this.catalog[o];
|
|
103
|
+
if (i && (Array.isArray(i.tools) && i.tools.length > 0 && t.push(...i.tools), Array.isArray(i.modules) && i.modules.length > 0))
|
|
104
|
+
for (const r of i.modules) {
|
|
105
|
+
const l = this.moduleLoaders[r];
|
|
106
|
+
if (l)
|
|
107
|
+
try {
|
|
108
|
+
const a = await l(s);
|
|
109
|
+
Array.isArray(a) && a.length > 0 && t.push(...a);
|
|
110
|
+
} catch (a) {
|
|
111
|
+
console.warn(
|
|
112
|
+
`Module loader '${r}' failed for toolset '${o}':`,
|
|
113
|
+
a
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return t;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
class v extends Error {
|
|
122
|
+
constructor(e, s, t, o) {
|
|
123
|
+
super(e), this.name = "ToolingError", this.code = s, this.details = t;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
class A {
|
|
127
|
+
constructor(e = {}) {
|
|
128
|
+
this.names = /* @__PURE__ */ new Set(), this.toolsetToNames = /* @__PURE__ */ new Map(), this.options = {
|
|
129
|
+
namespaceWithToolset: e.namespaceWithToolset ?? !0
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
getSafeName(e, s) {
|
|
133
|
+
return !this.options.namespaceWithToolset || s.startsWith(`${e}.`) ? s : `${e}.${s}`;
|
|
134
|
+
}
|
|
135
|
+
has(e) {
|
|
136
|
+
return this.names.has(e);
|
|
137
|
+
}
|
|
138
|
+
add(e) {
|
|
139
|
+
if (this.names.has(e))
|
|
140
|
+
throw new v(
|
|
141
|
+
`Tool name collision: '${e}' already registered`,
|
|
142
|
+
"E_TOOL_NAME_CONFLICT"
|
|
143
|
+
);
|
|
144
|
+
this.names.add(e);
|
|
145
|
+
}
|
|
146
|
+
addForToolset(e, s) {
|
|
147
|
+
this.add(s);
|
|
148
|
+
const t = this.toolsetToNames.get(e) ?? /* @__PURE__ */ new Set();
|
|
149
|
+
t.add(s), this.toolsetToNames.set(e, t);
|
|
150
|
+
}
|
|
151
|
+
mapAndValidate(e, s) {
|
|
152
|
+
return s.map((t) => {
|
|
153
|
+
const o = this.getSafeName(e, t.name);
|
|
154
|
+
if (this.has(o))
|
|
155
|
+
throw new v(
|
|
156
|
+
`Tool name collision for '${o}'`,
|
|
157
|
+
"E_TOOL_NAME_CONFLICT"
|
|
158
|
+
);
|
|
159
|
+
return { ...t, name: o };
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
list() {
|
|
163
|
+
return Array.from(this.names);
|
|
164
|
+
}
|
|
165
|
+
listByToolset() {
|
|
166
|
+
const e = {};
|
|
167
|
+
for (const [s, t] of this.toolsetToNames.entries())
|
|
168
|
+
e[s] = Array.from(t);
|
|
169
|
+
return e;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
class N {
|
|
173
|
+
constructor(e) {
|
|
174
|
+
this.activeToolsets = /* @__PURE__ */ new Set(), this.server = e.server, this.resolver = e.resolver, this.context = e.context, this.onToolsListChanged = e.onToolsListChanged, this.exposurePolicy = e.exposurePolicy, this.toolRegistry = e.toolRegistry ?? new A({ namespaceWithToolset: !0 });
|
|
175
|
+
}
|
|
176
|
+
getAvailableToolsets() {
|
|
177
|
+
return this.resolver.getAvailableToolsets();
|
|
178
|
+
}
|
|
179
|
+
getActiveToolsets() {
|
|
180
|
+
return Array.from(this.activeToolsets);
|
|
181
|
+
}
|
|
182
|
+
getToolsetDefinition(e) {
|
|
183
|
+
return this.resolver.getToolsetDefinition(e);
|
|
184
|
+
}
|
|
185
|
+
isActive(e) {
|
|
186
|
+
return this.activeToolsets.has(e);
|
|
187
|
+
}
|
|
188
|
+
async enableToolset(e) {
|
|
189
|
+
const s = this.resolver.validateToolsetName(e);
|
|
190
|
+
if (!s.isValid || !s.sanitized)
|
|
191
|
+
return {
|
|
192
|
+
success: !1,
|
|
193
|
+
message: s.error || "Unknown validation error"
|
|
194
|
+
};
|
|
195
|
+
const t = s.sanitized;
|
|
196
|
+
if (this.activeToolsets.has(t))
|
|
197
|
+
return {
|
|
198
|
+
success: !1,
|
|
199
|
+
message: `Toolset '${t}' is already enabled.`
|
|
200
|
+
};
|
|
201
|
+
try {
|
|
202
|
+
const o = await this.resolver.resolveToolsForToolsets(
|
|
203
|
+
[t],
|
|
204
|
+
this.context
|
|
205
|
+
);
|
|
206
|
+
if (this.exposurePolicy?.allowlist && !this.exposurePolicy.allowlist.includes(t))
|
|
207
|
+
return {
|
|
208
|
+
success: !1,
|
|
209
|
+
message: `Toolset '${t}' is not allowed by policy.`
|
|
210
|
+
};
|
|
211
|
+
if (this.exposurePolicy?.denylist && this.exposurePolicy.denylist.includes(t))
|
|
212
|
+
return {
|
|
213
|
+
success: !1,
|
|
214
|
+
message: `Toolset '${t}' is denied by policy.`
|
|
215
|
+
};
|
|
216
|
+
if (this.exposurePolicy?.maxActiveToolsets !== void 0 && this.activeToolsets.size + 1 > this.exposurePolicy.maxActiveToolsets)
|
|
217
|
+
return this.exposurePolicy.onLimitExceeded?.(
|
|
218
|
+
[t],
|
|
219
|
+
Array.from(this.activeToolsets)
|
|
220
|
+
), {
|
|
221
|
+
success: !1,
|
|
222
|
+
message: `Activation exceeds maxActiveToolsets (${this.exposurePolicy.maxActiveToolsets}).`
|
|
223
|
+
};
|
|
224
|
+
if (o && o.length > 0) {
|
|
225
|
+
const i = this.toolRegistry.mapAndValidate(
|
|
226
|
+
t,
|
|
227
|
+
o
|
|
228
|
+
);
|
|
229
|
+
this.registerDirectTools(i, t);
|
|
230
|
+
}
|
|
231
|
+
this.activeToolsets.add(t);
|
|
232
|
+
try {
|
|
233
|
+
await this.onToolsListChanged?.();
|
|
234
|
+
} catch (i) {
|
|
235
|
+
console.warn("Failed to send tool list change notification:", i);
|
|
236
|
+
}
|
|
237
|
+
return {
|
|
238
|
+
success: !0,
|
|
239
|
+
message: `Toolset '${t}' enabled successfully. Registered ${o?.length ?? 0} tools.`
|
|
240
|
+
};
|
|
241
|
+
} catch (o) {
|
|
242
|
+
return this.activeToolsets.delete(t), {
|
|
243
|
+
success: !1,
|
|
244
|
+
message: `Failed to enable toolset '${t}': ${o instanceof Error ? o.message : "Unknown error"}`
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
async disableToolset(e) {
|
|
249
|
+
const s = this.resolver.validateToolsetName(e);
|
|
250
|
+
if (!s.isValid || !s.sanitized) {
|
|
251
|
+
const o = Array.from(this.activeToolsets).join(", ") || "none";
|
|
252
|
+
return {
|
|
253
|
+
success: !1,
|
|
254
|
+
message: `${s.error || "Unknown validation error"} Active toolsets: ${o}`
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
const t = s.sanitized;
|
|
258
|
+
if (!this.activeToolsets.has(t))
|
|
259
|
+
return {
|
|
260
|
+
success: !1,
|
|
261
|
+
message: `Toolset '${t}' is not currently active. Active toolsets: ${Array.from(this.activeToolsets).join(", ") || "none"}`
|
|
262
|
+
};
|
|
263
|
+
this.activeToolsets.delete(t);
|
|
264
|
+
try {
|
|
265
|
+
await this.onToolsListChanged?.();
|
|
266
|
+
} catch (o) {
|
|
267
|
+
console.warn("Failed to send tool list change notification:", o);
|
|
268
|
+
}
|
|
269
|
+
return {
|
|
270
|
+
success: !0,
|
|
271
|
+
message: `Toolset '${t}' disabled successfully. Individual tools remain registered due to MCP limitations.`
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
getStatus() {
|
|
275
|
+
return {
|
|
276
|
+
availableToolsets: this.getAvailableToolsets(),
|
|
277
|
+
activeToolsets: this.getActiveToolsets(),
|
|
278
|
+
registeredModules: [],
|
|
279
|
+
totalToolsets: this.getAvailableToolsets().length,
|
|
280
|
+
activeCount: this.activeToolsets.size,
|
|
281
|
+
tools: this.toolRegistry.list(),
|
|
282
|
+
toolsetToTools: this.toolRegistry.listByToolset()
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
async enableToolsets(e) {
|
|
286
|
+
const s = [];
|
|
287
|
+
for (const i of e)
|
|
288
|
+
try {
|
|
289
|
+
const r = await this.enableToolset(i);
|
|
290
|
+
s.push({ name: i, ...r });
|
|
291
|
+
} catch (r) {
|
|
292
|
+
s.push({
|
|
293
|
+
name: i,
|
|
294
|
+
success: !1,
|
|
295
|
+
message: r instanceof Error ? r.message : "Unknown error",
|
|
296
|
+
code: "E_INTERNAL"
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
const t = s.every((i) => i.success), o = t ? "All toolsets enabled" : "Some toolsets failed to enable";
|
|
300
|
+
if (s.length > 0)
|
|
301
|
+
try {
|
|
302
|
+
await this.onToolsListChanged?.();
|
|
303
|
+
} catch {
|
|
304
|
+
}
|
|
305
|
+
return { success: t, results: s, message: o };
|
|
306
|
+
}
|
|
307
|
+
registerDirectTools(e, s) {
|
|
308
|
+
for (const t of e)
|
|
309
|
+
try {
|
|
310
|
+
this.server.tool(
|
|
311
|
+
t.name,
|
|
312
|
+
t.description,
|
|
313
|
+
t.inputSchema,
|
|
314
|
+
async (o) => await t.handler(o)
|
|
315
|
+
), s ? this.toolRegistry.addForToolset(s, t.name) : this.toolRegistry.add(t.name);
|
|
316
|
+
} catch (o) {
|
|
317
|
+
throw console.error(`Failed to register direct tool '${t.name}':`, o), o;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
async enableAllToolsets() {
|
|
321
|
+
const e = this.getAvailableToolsets();
|
|
322
|
+
return this.enableToolsets(e);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
function P(n, e, s) {
|
|
326
|
+
const t = s?.mode ?? "DYNAMIC";
|
|
327
|
+
n.tool(
|
|
328
|
+
"enable_toolset",
|
|
329
|
+
"Enable a toolset by name",
|
|
330
|
+
{ name: g.string().describe("Toolset name") },
|
|
331
|
+
async (o) => {
|
|
332
|
+
const { name: i } = o, r = await e.enableToolset(i);
|
|
333
|
+
return {
|
|
334
|
+
content: [{ type: "text", text: JSON.stringify(r) }]
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
), n.tool(
|
|
338
|
+
"disable_toolset",
|
|
339
|
+
"Disable a toolset by name (state only)",
|
|
340
|
+
{ name: g.string().describe("Toolset name") },
|
|
341
|
+
async (o) => {
|
|
342
|
+
const { name: i } = o, r = await e.disableToolset(i);
|
|
343
|
+
return {
|
|
344
|
+
content: [{ type: "text", text: JSON.stringify(r) }]
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
), t === "DYNAMIC" && (n.tool(
|
|
348
|
+
"list_toolsets",
|
|
349
|
+
"List available toolsets with active status and definitions",
|
|
350
|
+
{},
|
|
351
|
+
async () => {
|
|
352
|
+
const o = e.getAvailableToolsets(), i = e.getStatus().toolsetToTools, r = o.map((l) => {
|
|
353
|
+
const a = e.getToolsetDefinition(l);
|
|
354
|
+
return {
|
|
355
|
+
key: l,
|
|
356
|
+
active: e.isActive(l),
|
|
357
|
+
definition: a ? {
|
|
358
|
+
name: a.name,
|
|
359
|
+
description: a.description,
|
|
360
|
+
modules: a.modules ?? [],
|
|
361
|
+
decisionCriteria: a.decisionCriteria ?? void 0
|
|
362
|
+
} : null,
|
|
363
|
+
tools: i[l] ?? []
|
|
364
|
+
};
|
|
365
|
+
});
|
|
366
|
+
return {
|
|
367
|
+
content: [
|
|
368
|
+
{ type: "text", text: JSON.stringify({ toolsets: r }) }
|
|
369
|
+
]
|
|
370
|
+
};
|
|
371
|
+
}
|
|
372
|
+
), n.tool(
|
|
373
|
+
"describe_toolset",
|
|
374
|
+
"Describe a toolset with definition, active status and tools",
|
|
375
|
+
{ name: g.string().describe("Toolset name") },
|
|
376
|
+
async (o) => {
|
|
377
|
+
const { name: i } = o, r = e.getToolsetDefinition(i), l = e.getStatus().toolsetToTools;
|
|
378
|
+
if (!r)
|
|
379
|
+
return {
|
|
380
|
+
content: [
|
|
381
|
+
{
|
|
382
|
+
type: "text",
|
|
383
|
+
text: JSON.stringify({ error: `Unknown toolset '${i}'` })
|
|
384
|
+
}
|
|
385
|
+
]
|
|
386
|
+
};
|
|
387
|
+
const a = {
|
|
388
|
+
key: i,
|
|
389
|
+
active: e.isActive(i),
|
|
390
|
+
definition: {
|
|
391
|
+
name: r.name,
|
|
392
|
+
description: r.description,
|
|
393
|
+
modules: r.modules ?? [],
|
|
394
|
+
decisionCriteria: r.decisionCriteria ?? void 0
|
|
395
|
+
},
|
|
396
|
+
tools: l[i] ?? []
|
|
397
|
+
};
|
|
398
|
+
return {
|
|
399
|
+
content: [{ type: "text", text: JSON.stringify(a) }]
|
|
400
|
+
};
|
|
401
|
+
}
|
|
402
|
+
)), n.tool(
|
|
403
|
+
"list_tools",
|
|
404
|
+
"List currently registered tool names (best effort)",
|
|
405
|
+
{},
|
|
406
|
+
async () => {
|
|
407
|
+
const o = e.getStatus(), i = {
|
|
408
|
+
tools: o.tools,
|
|
409
|
+
toolsetToTools: o.toolsetToTools
|
|
410
|
+
};
|
|
411
|
+
return {
|
|
412
|
+
content: [{ type: "text", text: JSON.stringify(i) }]
|
|
413
|
+
};
|
|
414
|
+
}
|
|
415
|
+
);
|
|
416
|
+
}
|
|
417
|
+
class b {
|
|
418
|
+
constructor(e) {
|
|
419
|
+
new D();
|
|
420
|
+
const s = e.startup ?? {};
|
|
421
|
+
this.mode = s.mode ?? "DYNAMIC", this.resolver = new E({
|
|
422
|
+
catalog: e.catalog,
|
|
423
|
+
moduleLoaders: e.moduleLoaders
|
|
424
|
+
});
|
|
425
|
+
const t = new A({
|
|
426
|
+
namespaceWithToolset: e.exposurePolicy?.namespaceToolsWithSetKey ?? !0
|
|
427
|
+
});
|
|
428
|
+
this.manager = new N({
|
|
429
|
+
server: e.server,
|
|
430
|
+
resolver: this.resolver,
|
|
431
|
+
context: e.context,
|
|
432
|
+
onToolsListChanged: e.notifyToolsListChanged,
|
|
433
|
+
exposurePolicy: e.exposurePolicy,
|
|
434
|
+
toolRegistry: t
|
|
435
|
+
}), e.registerMetaTools !== !1 && P(e.server, this.manager, { mode: this.mode });
|
|
436
|
+
const o = s.toolsets;
|
|
437
|
+
o === "ALL" ? this.manager.enableToolsets(this.resolver.getAvailableToolsets()) : Array.isArray(o) && o.length > 0 && this.manager.enableToolsets(o);
|
|
438
|
+
}
|
|
439
|
+
getMode() {
|
|
440
|
+
return this.mode;
|
|
441
|
+
}
|
|
442
|
+
getManager() {
|
|
443
|
+
return this.manager;
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
class j {
|
|
447
|
+
constructor(e = {}) {
|
|
448
|
+
this.storage = /* @__PURE__ */ new Map(), this.maxSize = e.maxSize ?? 1e3, this.ttlMs = e.ttlMs ?? 1e3 * 60 * 60;
|
|
449
|
+
const s = e.pruneIntervalMs ?? 1e3 * 60 * 10;
|
|
450
|
+
this.pruneInterval = setInterval(() => this.pruneExpired(), s);
|
|
451
|
+
}
|
|
452
|
+
getEntryCount() {
|
|
453
|
+
return this.storage.size;
|
|
454
|
+
}
|
|
455
|
+
getMaxSize() {
|
|
456
|
+
return this.maxSize;
|
|
457
|
+
}
|
|
458
|
+
getTtl() {
|
|
459
|
+
return this.ttlMs;
|
|
460
|
+
}
|
|
461
|
+
get(e) {
|
|
462
|
+
const s = this.storage.get(e);
|
|
463
|
+
return s ? Date.now() - s.lastAccessed > this.ttlMs ? (this.delete(e), null) : (s.lastAccessed = Date.now(), this.storage.delete(e), this.storage.set(e, s), s.resource) : null;
|
|
464
|
+
}
|
|
465
|
+
set(e, s) {
|
|
466
|
+
this.storage.size >= this.maxSize && this.evictLeastRecentlyUsed();
|
|
467
|
+
const t = { resource: s, lastAccessed: Date.now() };
|
|
468
|
+
this.storage.set(e, t);
|
|
469
|
+
}
|
|
470
|
+
delete(e) {
|
|
471
|
+
this.storage.delete(e);
|
|
472
|
+
}
|
|
473
|
+
stop() {
|
|
474
|
+
this.pruneInterval && (clearInterval(this.pruneInterval), this.pruneInterval = void 0);
|
|
475
|
+
}
|
|
476
|
+
evictLeastRecentlyUsed() {
|
|
477
|
+
const e = this.storage.keys().next().value;
|
|
478
|
+
e && this.delete(e);
|
|
479
|
+
}
|
|
480
|
+
pruneExpired() {
|
|
481
|
+
const e = Date.now();
|
|
482
|
+
for (const [s, t] of this.storage.entries())
|
|
483
|
+
e - t.lastAccessed > this.ttlMs && this.delete(s);
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
class O {
|
|
487
|
+
constructor(e, s, t = {}, o) {
|
|
488
|
+
this.app = null, this.clientCache = new j(), this.defaultManager = e, this.createBundle = s, this.options = {
|
|
489
|
+
host: t.host ?? "0.0.0.0",
|
|
490
|
+
port: t.port ?? 3e3,
|
|
491
|
+
basePath: t.basePath ?? "/",
|
|
492
|
+
cors: t.cors ?? !0,
|
|
493
|
+
logger: t.logger ?? !1,
|
|
494
|
+
app: t.app
|
|
495
|
+
}, this.configSchema = o;
|
|
496
|
+
}
|
|
497
|
+
async start() {
|
|
498
|
+
if (this.app) return;
|
|
499
|
+
const e = this.options.app ?? S({ logger: this.options.logger });
|
|
500
|
+
this.options.cors && await e.register(I, { origin: !0 });
|
|
501
|
+
const s = this.options.basePath.endsWith("/") ? this.options.basePath.slice(0, -1) : this.options.basePath;
|
|
502
|
+
e.get(`${s}/healthz`, async () => ({ ok: !0 })), e.get(`${s}/tools`, async () => this.defaultManager.getStatus()), e.get(`${s}/.well-known/mcp-config`, async (t, o) => (o.header("Content-Type", "application/schema+json; charset=utf-8"), this.configSchema ?? {
|
|
503
|
+
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
504
|
+
title: "MCP Session Configuration",
|
|
505
|
+
description: "Schema for the /mcp endpoint configuration",
|
|
506
|
+
type: "object",
|
|
507
|
+
properties: {},
|
|
508
|
+
required: [],
|
|
509
|
+
"x-mcp-version": "1.0",
|
|
510
|
+
"x-query-style": "dot+bracket"
|
|
511
|
+
})), e.post(
|
|
512
|
+
`${s}/mcp`,
|
|
513
|
+
async (t, o) => {
|
|
514
|
+
const i = t.headers["mcp-client-id"]?.trim(), r = i && i.length > 0 ? i : `anon-${T()}`, l = !r.startsWith("anon-");
|
|
515
|
+
let a = l ? this.clientCache.get(r) : null;
|
|
516
|
+
if (!a) {
|
|
517
|
+
const u = this.createBundle();
|
|
518
|
+
a = {
|
|
519
|
+
server: u.server,
|
|
520
|
+
orchestrator: u.orchestrator,
|
|
521
|
+
sessions: /* @__PURE__ */ new Map()
|
|
522
|
+
}, l && this.clientCache.set(r, a);
|
|
523
|
+
}
|
|
524
|
+
const d = t.headers["mcp-session-id"];
|
|
525
|
+
let h;
|
|
526
|
+
if (d && a.sessions.get(d))
|
|
527
|
+
h = a.sessions.get(d);
|
|
528
|
+
else if (!d && L(t.body)) {
|
|
529
|
+
const u = T();
|
|
530
|
+
h = new $({
|
|
531
|
+
sessionIdGenerator: () => u,
|
|
532
|
+
onsessioninitialized: (c) => {
|
|
533
|
+
a.sessions.set(c, h);
|
|
534
|
+
}
|
|
535
|
+
});
|
|
536
|
+
try {
|
|
537
|
+
await a.server.connect(h);
|
|
538
|
+
} catch {
|
|
539
|
+
return o.code(500), {
|
|
540
|
+
jsonrpc: "2.0",
|
|
541
|
+
error: { code: -32603, message: "Error initializing server." },
|
|
542
|
+
id: null
|
|
543
|
+
};
|
|
544
|
+
}
|
|
545
|
+
h.onclose = () => {
|
|
546
|
+
h?.sessionId && a.sessions.delete(h.sessionId);
|
|
547
|
+
};
|
|
548
|
+
} else
|
|
549
|
+
return o.code(400), {
|
|
550
|
+
jsonrpc: "2.0",
|
|
551
|
+
error: { code: -32e3, message: "Session not found or expired" },
|
|
552
|
+
id: null
|
|
553
|
+
};
|
|
554
|
+
return await h.handleRequest(
|
|
555
|
+
t.raw,
|
|
556
|
+
o.raw,
|
|
557
|
+
t.body
|
|
558
|
+
), o;
|
|
559
|
+
}
|
|
560
|
+
), e.get(`${s}/mcp`, async (t, o) => {
|
|
561
|
+
const i = t.headers["mcp-client-id"]?.trim(), r = i && i.length > 0 ? i : "";
|
|
562
|
+
if (!r)
|
|
563
|
+
return o.code(400), "Missing mcp-client-id";
|
|
564
|
+
const l = this.clientCache.get(r);
|
|
565
|
+
if (!l)
|
|
566
|
+
return o.code(400), "Invalid or expired client";
|
|
567
|
+
const a = t.headers["mcp-session-id"];
|
|
568
|
+
if (!a)
|
|
569
|
+
return o.code(400), "Missing mcp-session-id";
|
|
570
|
+
const d = l.sessions.get(a);
|
|
571
|
+
return d ? (await d.handleRequest(t.raw, o.raw), o) : (o.code(400), "Invalid or expired session ID");
|
|
572
|
+
}), e.delete(
|
|
573
|
+
`${s}/mcp`,
|
|
574
|
+
async (t, o) => {
|
|
575
|
+
const i = t.headers["mcp-client-id"]?.trim(), r = i && i.length > 0 ? i : "", l = t.headers["mcp-session-id"];
|
|
576
|
+
if (!r || !l)
|
|
577
|
+
return o.code(400), {
|
|
578
|
+
jsonrpc: "2.0",
|
|
579
|
+
error: {
|
|
580
|
+
code: -32600,
|
|
581
|
+
message: "Missing mcp-client-id or mcp-session-id header"
|
|
582
|
+
},
|
|
583
|
+
id: null
|
|
584
|
+
};
|
|
585
|
+
const a = this.clientCache.get(r), d = a?.sessions.get(l);
|
|
586
|
+
return !a || !d ? (o.code(404), {
|
|
587
|
+
jsonrpc: "2.0",
|
|
588
|
+
error: { code: -32e3, message: "Session not found or expired" },
|
|
589
|
+
id: null
|
|
590
|
+
}) : (o.code(204).send(), o);
|
|
591
|
+
}
|
|
592
|
+
), this.options.app || await e.listen({ host: this.options.host, port: this.options.port }), this.app = e;
|
|
593
|
+
}
|
|
594
|
+
async stop() {
|
|
595
|
+
this.app && (this.options.app || await this.app.close(), this.app = null);
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
async function U(n) {
|
|
599
|
+
const e = n.startup?.mode ?? "DYNAMIC", s = n.mcp?.name ?? "mcp-dynamic-tooling", t = n.mcp?.version ?? "0.0.0", o = n.mcp?.capabilities ?? {}, i = {
|
|
600
|
+
...o,
|
|
601
|
+
tools: {
|
|
602
|
+
...typeof o.tools == "object" ? o.tools : {},
|
|
603
|
+
// listChanged is internal-only and computed by mode
|
|
604
|
+
listChanged: e === "DYNAMIC"
|
|
605
|
+
}
|
|
606
|
+
}, r = new y({
|
|
607
|
+
name: s,
|
|
608
|
+
version: t,
|
|
609
|
+
capabilities: i
|
|
610
|
+
}), l = (c) => typeof c?.server?.notification == "function", a = (c) => typeof c?.notifyToolsListChanged == "function", d = async (c) => {
|
|
611
|
+
try {
|
|
612
|
+
if (l(c)) {
|
|
613
|
+
await c.server.notification({
|
|
614
|
+
method: "notifications/tools/list_changed"
|
|
615
|
+
});
|
|
616
|
+
return;
|
|
617
|
+
}
|
|
618
|
+
a(c) && await c.notifyToolsListChanged();
|
|
619
|
+
} catch {
|
|
620
|
+
}
|
|
621
|
+
}, h = new b({
|
|
622
|
+
server: r,
|
|
623
|
+
catalog: n.catalog,
|
|
624
|
+
moduleLoaders: n.moduleLoaders,
|
|
625
|
+
exposurePolicy: n.exposurePolicy,
|
|
626
|
+
context: n.context,
|
|
627
|
+
notifyToolsListChanged: async () => d(r),
|
|
628
|
+
startup: n.startup,
|
|
629
|
+
registerMetaTools: n.registerMetaTools !== void 0 ? n.registerMetaTools : e === "DYNAMIC"
|
|
630
|
+
}), u = new O(
|
|
631
|
+
h.getManager(),
|
|
632
|
+
() => {
|
|
633
|
+
const c = n.startup?.mode ?? "DYNAMIC", w = n.mcp?.name ?? s, x = n.mcp?.version ?? t, f = n.mcp?.capabilities ?? o, M = {
|
|
634
|
+
...f,
|
|
635
|
+
tools: {
|
|
636
|
+
...typeof f.tools == "object" ? f.tools : {},
|
|
637
|
+
listChanged: c === "DYNAMIC"
|
|
638
|
+
}
|
|
639
|
+
}, m = new y({
|
|
640
|
+
name: w,
|
|
641
|
+
version: x,
|
|
642
|
+
capabilities: M
|
|
643
|
+
}), C = new b({
|
|
644
|
+
server: m,
|
|
645
|
+
catalog: n.catalog,
|
|
646
|
+
moduleLoaders: n.moduleLoaders,
|
|
647
|
+
exposurePolicy: n.exposurePolicy,
|
|
648
|
+
context: n.context,
|
|
649
|
+
notifyToolsListChanged: async () => d(m),
|
|
650
|
+
startup: n.startup,
|
|
651
|
+
registerMetaTools: n.registerMetaTools !== void 0 ? n.registerMetaTools : c === "DYNAMIC"
|
|
652
|
+
});
|
|
653
|
+
return { server: m, orchestrator: C };
|
|
654
|
+
},
|
|
655
|
+
n.http,
|
|
656
|
+
n.configSchema
|
|
657
|
+
);
|
|
658
|
+
return {
|
|
659
|
+
server: r,
|
|
660
|
+
start: async () => {
|
|
661
|
+
await u.start();
|
|
662
|
+
},
|
|
663
|
+
close: async () => {
|
|
664
|
+
await u.stop();
|
|
665
|
+
}
|
|
666
|
+
};
|
|
667
|
+
}
|
|
668
|
+
export {
|
|
669
|
+
U as createMcpServer
|
|
670
|
+
};
|
|
671
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/mode/ModeResolver.ts","../src/mode/ModuleResolver.ts","../src/errors/ToolingError.ts","../src/core/ToolRegistry.ts","../src/core/DynamicToolManager.ts","../src/meta/registerMetaTools.ts","../src/core/ServerOrchestrator.ts","../src/session/ClientResourceCache.ts","../src/http/FastifyTransport.ts","../src/server/createMcpServer.ts"],"sourcesContent":["import type { Mode, ToolSetCatalog } from \"../types/index.js\";\n\nexport interface ModeResolverKeys {\n dynamic?: string[]; // keys that, when present/true, enable dynamic mode\n toolsets?: string[]; // keys that carry comma-separated toolsets\n}\n\nexport interface ModeResolverOptions {\n keys?: ModeResolverKeys;\n}\n\nconst DEFAULT_KEYS: Required<ModeResolverKeys> = {\n dynamic: [\"dynamic-tool-discovery\", \"dynamicToolDiscovery\", \"DYNAMIC_TOOL_DISCOVERY\"],\n toolsets: [\"tool-sets\", \"toolSets\", \"FMP_TOOL_SETS\"],\n};\n\nexport class ModeResolver {\n private readonly keys: Required<ModeResolverKeys>;\n\n constructor(options: ModeResolverOptions = {}) {\n this.keys = {\n dynamic: options.keys?.dynamic ?? DEFAULT_KEYS.dynamic,\n toolsets: options.keys?.toolsets ?? DEFAULT_KEYS.toolsets,\n };\n }\n\n public resolveMode(env?: Record<string, string | undefined>, args?: Record<string, unknown>): Mode | null {\n // Check args first\n if (this.isDynamicEnabled(args)) return \"DYNAMIC\";\n\n const toolsetsFromArgs = this.getToolsetsString(args);\n if (toolsetsFromArgs) return \"STATIC\";\n\n // Check env next\n if (this.isDynamicEnabled(env)) return \"DYNAMIC\";\n\n const toolsetsFromEnv = this.getToolsetsString(env);\n if (toolsetsFromEnv) return \"STATIC\";\n\n return null; // no override\n }\n\n public parseCommaSeparatedToolSets(input: string, catalog: ToolSetCatalog): string[] {\n if (!input || typeof input !== \"string\") return [];\n const raw = input\n .split(\",\")\n .map((s) => s.trim())\n .filter((s) => s.length > 0);\n\n const valid = new Set(Object.keys(catalog));\n const result: string[] = [];\n for (const name of raw) {\n if (valid.has(name)) result.push(name);\n else console.warn(`Invalid toolset '${name}' ignored. Available: ${Array.from(valid).join(\", \")}`);\n }\n return result;\n }\n\n public getModulesForToolSets(toolsets: string[], catalog: ToolSetCatalog): string[] {\n const modules = new Set<string>();\n for (const name of toolsets) {\n const def = catalog[name];\n if (!def) continue;\n (def.modules || []).forEach((m) => modules.add(m));\n }\n return Array.from(modules);\n }\n\n public validateToolsetName(name: unknown, catalog: ToolSetCatalog): { isValid: boolean; sanitized?: string; error?: string } {\n if (!name || typeof name !== \"string\") {\n return { isValid: false, error: `Invalid toolset name provided. Must be a non-empty string. Available toolsets: ${Object.keys(catalog).join(\", \")}` };\n }\n const sanitized = name.trim();\n if (sanitized.length === 0) {\n return { isValid: false, error: `Empty toolset name provided. Available toolsets: ${Object.keys(catalog).join(\", \")}` };\n }\n if (!catalog[sanitized]) {\n return { isValid: false, error: `Toolset '${sanitized}' not found. Available toolsets: ${Object.keys(catalog).join(\", \")}` };\n }\n return { isValid: true, sanitized };\n }\n\n public validateToolsetModules(toolsetNames: string[], catalog: ToolSetCatalog): { isValid: boolean; modules?: string[]; error?: string } {\n try {\n const modules = this.getModulesForToolSets(toolsetNames, catalog);\n if (!modules || modules.length === 0) {\n return { isValid: false, error: `No modules found for toolsets: ${toolsetNames.join(\", \")}` };\n }\n return { isValid: true, modules };\n } catch (error) {\n return { isValid: false, error: `Error resolving modules for ${toolsetNames.join(\", \")}: ${error instanceof Error ? error.message : \"Unknown error\"}` };\n }\n }\n\n private isDynamicEnabled(source?: Record<string, unknown> | Record<string, string | undefined>): boolean {\n if (!source) return false;\n for (const key of this.keys.dynamic) {\n const value = (source as any)[key];\n if (value === true) return true;\n if (typeof value === \"string\") {\n const v = value.trim().toLowerCase();\n if (v === \"true\") return true;\n }\n }\n return false;\n }\n\n private getToolsetsString(source?: Record<string, unknown> | Record<string, string | undefined>): string | undefined {\n if (!source) return undefined;\n for (const key of this.keys.toolsets) {\n const value = (source as any)[key];\n if (typeof value === \"string\" && value.trim().length > 0) return value as string;\n }\n return undefined;\n }\n}\n\n","import type {\n ToolSetCatalog,\n ToolSetDefinition,\n McpToolDefinition,\n ModuleLoader,\n} from \"../types/index.js\";\n\nexport interface ModuleResolverOptions {\n catalog: ToolSetCatalog;\n moduleLoaders?: Record<string, ModuleLoader>;\n}\n\nexport class ModuleResolver {\n private readonly catalog: ToolSetCatalog;\n private readonly moduleLoaders: Record<string, ModuleLoader>;\n\n constructor(options: ModuleResolverOptions) {\n this.catalog = options.catalog;\n this.moduleLoaders = options.moduleLoaders ?? {};\n }\n\n public getAvailableToolsets(): string[] {\n return Object.keys(this.catalog);\n }\n\n public getToolsetDefinition(name: string): ToolSetDefinition | undefined {\n return this.catalog[name];\n }\n\n public validateToolsetName(name: unknown): {\n isValid: boolean;\n sanitized?: string;\n error?: string;\n } {\n if (!name || typeof name !== \"string\") {\n return {\n isValid: false,\n error: `Invalid toolset name provided. Must be a non-empty string. Available toolsets: ${this.getAvailableToolsets().join(\n \", \"\n )}`,\n };\n }\n const sanitized = name.trim();\n if (sanitized.length === 0) {\n return {\n isValid: false,\n error: `Empty toolset name provided. Available toolsets: ${this.getAvailableToolsets().join(\n \", \"\n )}`,\n };\n }\n if (!this.catalog[sanitized]) {\n return {\n isValid: false,\n error: `Toolset '${sanitized}' not found. Available toolsets: ${this.getAvailableToolsets().join(\n \", \"\n )}`,\n };\n }\n return { isValid: true, sanitized };\n }\n\n public async resolveToolsForToolsets(\n toolsets: string[],\n context?: unknown\n ): Promise<McpToolDefinition[]> {\n const collected: McpToolDefinition[] = [];\n for (const name of toolsets) {\n const def = this.catalog[name];\n if (!def) continue;\n if (Array.isArray(def.tools) && def.tools.length > 0) {\n collected.push(...def.tools);\n }\n if (Array.isArray(def.modules) && def.modules.length > 0) {\n for (const modKey of def.modules) {\n const loader = this.moduleLoaders[modKey];\n if (!loader) continue;\n try {\n const loaded = await loader(context);\n if (Array.isArray(loaded) && loaded.length > 0) {\n collected.push(...loaded);\n }\n } catch (err) {\n console.warn(\n `Module loader '${modKey}' failed for toolset '${name}':`,\n err\n );\n }\n }\n }\n }\n return collected;\n }\n}\n","import type { ToolingErrorCode } from \"../types/index.js\";\n\nexport class ToolingError extends Error {\n public readonly code: ToolingErrorCode;\n public readonly details?: Record<string, unknown>;\n\n constructor(\n message: string,\n code: ToolingErrorCode,\n details?: Record<string, unknown>,\n _options?: unknown\n ) {\n super(message);\n this.name = \"ToolingError\";\n this.code = code;\n this.details = details;\n }\n}\n","import type { McpToolDefinition } from \"../types/index.js\";\nimport { ToolingError } from \"../errors/ToolingError.js\";\n\nexport interface ToolRegistryOptions {\n namespaceWithToolset?: boolean;\n}\n\nexport class ToolRegistry {\n private readonly options: Required<ToolRegistryOptions>;\n private readonly names = new Set<string>();\n private readonly toolsetToNames = new Map<string, Set<string>>();\n\n constructor(options: ToolRegistryOptions = {}) {\n this.options = {\n namespaceWithToolset: options.namespaceWithToolset ?? true,\n };\n }\n\n public getSafeName(toolsetKey: string, toolName: string): string {\n if (!this.options.namespaceWithToolset) return toolName;\n if (toolName.startsWith(`${toolsetKey}.`)) return toolName;\n return `${toolsetKey}.${toolName}`;\n }\n\n public has(name: string): boolean {\n return this.names.has(name);\n }\n\n public add(name: string): void {\n if (this.names.has(name)) {\n throw new ToolingError(\n `Tool name collision: '${name}' already registered`,\n \"E_TOOL_NAME_CONFLICT\"\n );\n }\n this.names.add(name);\n }\n\n public addForToolset(toolsetKey: string, name: string): void {\n this.add(name);\n const set = this.toolsetToNames.get(toolsetKey) ?? new Set<string>();\n set.add(name);\n this.toolsetToNames.set(toolsetKey, set);\n }\n\n public mapAndValidate(\n toolsetKey: string,\n tools: McpToolDefinition[]\n ): McpToolDefinition[] {\n return tools.map((t) => {\n const safe = this.getSafeName(toolsetKey, t.name);\n if (this.has(safe)) {\n throw new ToolingError(\n `Tool name collision for '${safe}'`,\n \"E_TOOL_NAME_CONFLICT\"\n );\n }\n return { ...t, name: safe };\n });\n }\n\n public list(): string[] {\n return Array.from(this.names);\n }\n\n public listByToolset(): Record<string, string[]> {\n const result: Record<string, string[]> = {};\n for (const [k, v] of this.toolsetToNames.entries()) {\n result[k] = Array.from(v);\n }\n return result;\n }\n}\n","import type { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\";\nimport type {\n ExposurePolicy,\n McpToolDefinition,\n ToolSetDefinition,\n ToolingErrorCode,\n} from \"../types/index.js\";\nimport { ModuleResolver } from \"../mode/ModuleResolver.js\";\nimport { ToolRegistry } from \"./ToolRegistry.js\";\n\nexport interface DynamicToolManagerOptions {\n server: McpServer;\n resolver: ModuleResolver;\n context?: unknown;\n onToolsListChanged?: () => Promise<void> | void;\n exposurePolicy?: ExposurePolicy;\n toolRegistry?: ToolRegistry;\n}\n\nexport class DynamicToolManager {\n private readonly server: McpServer;\n private readonly resolver: ModuleResolver;\n private readonly context?: unknown;\n private readonly onToolsListChanged?: () => Promise<void> | void;\n private readonly exposurePolicy?: ExposurePolicy;\n private readonly toolRegistry: ToolRegistry;\n\n private readonly activeToolsets = new Set<string>();\n\n constructor(options: DynamicToolManagerOptions) {\n this.server = options.server;\n this.resolver = options.resolver;\n this.context = options.context;\n this.onToolsListChanged = options.onToolsListChanged;\n this.exposurePolicy = options.exposurePolicy;\n this.toolRegistry =\n options.toolRegistry ?? new ToolRegistry({ namespaceWithToolset: true });\n }\n\n public getAvailableToolsets(): string[] {\n return this.resolver.getAvailableToolsets();\n }\n\n public getActiveToolsets(): string[] {\n return Array.from(this.activeToolsets);\n }\n\n public getToolsetDefinition(name: string): ToolSetDefinition | undefined {\n return this.resolver.getToolsetDefinition(name);\n }\n\n public isActive(name: string): boolean {\n return this.activeToolsets.has(name);\n }\n\n public async enableToolset(\n toolsetName: string\n ): Promise<{ success: boolean; message: string }> {\n const validation = this.resolver.validateToolsetName(toolsetName);\n if (!validation.isValid || !validation.sanitized) {\n return {\n success: false,\n message: validation.error || \"Unknown validation error\",\n };\n }\n const sanitized = validation.sanitized;\n if (this.activeToolsets.has(sanitized)) {\n return {\n success: false,\n message: `Toolset '${sanitized}' is already enabled.`,\n };\n }\n\n try {\n const resolvedTools = await this.resolver.resolveToolsForToolsets(\n [sanitized],\n this.context\n );\n\n // Exposure policy checks\n if (\n this.exposurePolicy?.allowlist &&\n !this.exposurePolicy.allowlist.includes(sanitized)\n ) {\n return {\n success: false,\n message: `Toolset '${sanitized}' is not allowed by policy.`,\n };\n }\n if (\n this.exposurePolicy?.denylist &&\n this.exposurePolicy.denylist.includes(sanitized)\n ) {\n return {\n success: false,\n message: `Toolset '${sanitized}' is denied by policy.`,\n };\n }\n if (this.exposurePolicy?.maxActiveToolsets !== undefined) {\n const next = this.activeToolsets.size + 1;\n if (next > this.exposurePolicy.maxActiveToolsets) {\n this.exposurePolicy.onLimitExceeded?.(\n [sanitized],\n Array.from(this.activeToolsets)\n );\n return {\n success: false,\n message: `Activation exceeds maxActiveToolsets (${this.exposurePolicy.maxActiveToolsets}).`,\n };\n }\n }\n\n // Register all resolved tools (direct + module-derived)\n if (resolvedTools && resolvedTools.length > 0) {\n const mapped = this.toolRegistry.mapAndValidate(\n sanitized,\n resolvedTools\n );\n this.registerDirectTools(mapped, sanitized);\n }\n\n // Track state (modules no longer tracked)\n this.activeToolsets.add(sanitized);\n\n // Notify list change\n try {\n await this.onToolsListChanged?.();\n } catch (err) {\n console.warn(`Failed to send tool list change notification:`, err);\n }\n\n return {\n success: true,\n message: `Toolset '${sanitized}' enabled successfully. Registered ${\n resolvedTools?.length ?? 0\n } tools.`,\n };\n } catch (error) {\n this.activeToolsets.delete(sanitized);\n return {\n success: false,\n message: `Failed to enable toolset '${sanitized}': ${\n error instanceof Error ? error.message : \"Unknown error\"\n }`,\n };\n }\n }\n\n public async disableToolset(\n toolsetName: string\n ): Promise<{ success: boolean; message: string }> {\n const validation = this.resolver.validateToolsetName(toolsetName);\n if (!validation.isValid || !validation.sanitized) {\n const activeToolsets =\n Array.from(this.activeToolsets).join(\", \") || \"none\";\n const base = validation.error || \"Unknown validation error\";\n return {\n success: false,\n message: `${base} Active toolsets: ${activeToolsets}`,\n };\n }\n const sanitized = validation.sanitized;\n if (!this.activeToolsets.has(sanitized)) {\n return {\n success: false,\n message: `Toolset '${sanitized}' is not currently active. Active toolsets: ${\n Array.from(this.activeToolsets).join(\", \") || \"none\"\n }`,\n };\n }\n\n // State-only disable; no unregistration support in MCP\n this.activeToolsets.delete(sanitized);\n\n try {\n await this.onToolsListChanged?.();\n } catch (err) {\n console.warn(`Failed to send tool list change notification:`, err);\n }\n\n return {\n success: true,\n message: `Toolset '${sanitized}' disabled successfully. Individual tools remain registered due to MCP limitations.`,\n };\n }\n\n public getStatus() {\n return {\n availableToolsets: this.getAvailableToolsets(),\n activeToolsets: this.getActiveToolsets(),\n registeredModules: [],\n totalToolsets: this.getAvailableToolsets().length,\n activeCount: this.activeToolsets.size,\n tools: this.toolRegistry.list(),\n toolsetToTools: this.toolRegistry.listByToolset(),\n };\n }\n\n public async enableToolsets(toolsetNames: string[]): Promise<{\n success: boolean;\n results: Array<{\n name: string;\n success: boolean;\n message: string;\n code?: ToolingErrorCode;\n }>;\n message: string;\n }> {\n const results: Array<{\n name: string;\n success: boolean;\n message: string;\n code?: ToolingErrorCode;\n }> = [];\n for (const name of toolsetNames) {\n try {\n const res = await this.enableToolset(name);\n results.push({ name, ...res });\n } catch (err) {\n results.push({\n name,\n success: false,\n message: err instanceof Error ? err.message : \"Unknown error\",\n code: \"E_INTERNAL\",\n });\n }\n }\n const successAll = results.every((r) => r.success);\n const message = successAll\n ? \"All toolsets enabled\"\n : \"Some toolsets failed to enable\";\n if (results.length > 0) {\n try {\n await this.onToolsListChanged?.();\n } catch {}\n }\n return { success: successAll, results, message };\n }\n\n private registerDirectTools(\n tools: McpToolDefinition[],\n toolsetKey?: string\n ): void {\n for (const tool of tools) {\n try {\n this.server.tool(\n tool.name,\n tool.description,\n tool.inputSchema as any,\n async (args: any) => {\n return await tool.handler(args);\n }\n );\n if (toolsetKey) this.toolRegistry.addForToolset(toolsetKey, tool.name);\n else this.toolRegistry.add(tool.name);\n } catch (err) {\n console.error(`Failed to register direct tool '${tool.name}':`, err);\n throw err;\n }\n }\n }\n\n public async enableAllToolsets(): Promise<{\n success: boolean;\n results: Array<{\n name: string;\n success: boolean;\n message: string;\n code?: ToolingErrorCode;\n }>;\n message: string;\n }> {\n const all = this.getAvailableToolsets();\n return this.enableToolsets(all);\n }\n}\n","import type { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\";\nimport type { Mode } from \"../types/index.js\";\nimport { z } from \"zod\";\nimport { DynamicToolManager } from \"../core/DynamicToolManager.js\";\n\nexport function registerMetaTools(\n server: McpServer,\n manager: DynamicToolManager,\n options?: { mode?: Exclude<Mode, \"ALL\"> }\n): void {\n const mode = options?.mode ?? \"DYNAMIC\";\n // list_tools is always available\n server.tool(\n \"enable_toolset\",\n \"Enable a toolset by name\",\n { name: z.string().describe(\"Toolset name\") },\n async (args: any) => {\n const { name } = args as { name: string };\n const result = await manager.enableToolset(name);\n return {\n content: [{ type: \"text\", text: JSON.stringify(result) }],\n } as any;\n }\n );\n\n server.tool(\n \"disable_toolset\",\n \"Disable a toolset by name (state only)\",\n { name: z.string().describe(\"Toolset name\") },\n async (args: any) => {\n const { name } = args as { name: string };\n const result = await manager.disableToolset(name);\n return {\n content: [{ type: \"text\", text: JSON.stringify(result) }],\n } as any;\n }\n );\n\n if (mode === \"DYNAMIC\") {\n server.tool(\n \"list_toolsets\",\n \"List available toolsets with active status and definitions\",\n {},\n async () => {\n const available = manager.getAvailableToolsets();\n const byToolset = manager.getStatus().toolsetToTools;\n const items = available.map((key) => {\n const def = manager.getToolsetDefinition(key);\n return {\n key,\n active: manager.isActive(key),\n definition: def\n ? {\n name: def.name,\n description: def.description,\n modules: def.modules ?? [],\n decisionCriteria: def.decisionCriteria ?? undefined,\n }\n : null,\n tools: byToolset[key] ?? [],\n };\n });\n return {\n content: [\n { type: \"text\", text: JSON.stringify({ toolsets: items }) },\n ],\n } as any;\n }\n );\n\n server.tool(\n \"describe_toolset\",\n \"Describe a toolset with definition, active status and tools\",\n { name: z.string().describe(\"Toolset name\") },\n async (args: any) => {\n const { name } = args as { name: string };\n const def = manager.getToolsetDefinition(name);\n const byToolset = manager.getStatus().toolsetToTools;\n if (!def) {\n return {\n content: [\n {\n type: \"text\",\n text: JSON.stringify({ error: `Unknown toolset '${name}'` }),\n },\n ],\n } as any;\n }\n const payload = {\n key: name,\n active: manager.isActive(name),\n definition: {\n name: def.name,\n description: def.description,\n modules: def.modules ?? [],\n decisionCriteria: def.decisionCriteria ?? undefined,\n },\n tools: byToolset[name] ?? [],\n };\n return {\n content: [{ type: \"text\", text: JSON.stringify(payload) }],\n } as any;\n }\n );\n }\n\n server.tool(\n \"list_tools\",\n \"List currently registered tool names (best effort)\",\n {},\n async () => {\n const status = manager.getStatus();\n const payload = {\n tools: status.tools,\n toolsetToTools: status.toolsetToTools,\n };\n return {\n content: [{ type: \"text\", text: JSON.stringify(payload) }],\n } as any;\n }\n );\n}\n","import type { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\";\nimport { ModeResolver } from \"../mode/ModeResolver.js\";\nimport { ModuleResolver } from \"../mode/ModuleResolver.js\";\nimport { DynamicToolManager } from \"./DynamicToolManager.js\";\nimport { registerMetaTools } from \"../meta/registerMetaTools.js\";\nimport type { ExposurePolicy, Mode, ToolSetCatalog } from \"../types/index.js\";\nimport { ToolRegistry } from \"./ToolRegistry.js\";\n\nexport interface ServerOrchestratorOptions {\n server: McpServer;\n catalog: ToolSetCatalog;\n moduleLoaders?: Record<string, any>;\n exposurePolicy?: ExposurePolicy;\n context?: unknown;\n notifyToolsListChanged?: () => Promise<void> | void;\n startup?: { mode?: Exclude<Mode, \"ALL\">; toolsets?: string[] | \"ALL\" };\n registerMetaTools?: boolean;\n}\n\nexport class ServerOrchestrator {\n private readonly mode: Exclude<Mode, \"ALL\">;\n private readonly resolver: ModuleResolver;\n private readonly manager: DynamicToolManager;\n\n constructor(options: ServerOrchestratorOptions) {\n const modeResolver = new ModeResolver();\n const startup = options.startup ?? {};\n this.mode = startup.mode ?? \"DYNAMIC\";\n this.resolver = new ModuleResolver({\n catalog: options.catalog,\n moduleLoaders: options.moduleLoaders as any,\n });\n const toolRegistry = new ToolRegistry({\n namespaceWithToolset:\n options.exposurePolicy?.namespaceToolsWithSetKey ?? true,\n });\n this.manager = new DynamicToolManager({\n server: options.server,\n resolver: this.resolver,\n context: options.context,\n onToolsListChanged: options.notifyToolsListChanged,\n exposurePolicy: options.exposurePolicy,\n toolRegistry,\n });\n\n // Register meta-tools only if requested (default true)\n if (options.registerMetaTools !== false) {\n registerMetaTools(options.server, this.manager, { mode: this.mode });\n }\n\n // Startup behavior\n const initial = startup.toolsets;\n if (initial === \"ALL\") {\n void this.manager.enableToolsets(this.resolver.getAvailableToolsets());\n } else if (Array.isArray(initial) && initial.length > 0) {\n void this.manager.enableToolsets(initial);\n }\n }\n\n public getMode(): Exclude<Mode, \"ALL\"> {\n return this.mode;\n }\n\n public getManager(): DynamicToolManager {\n return this.manager;\n }\n}\n","export interface ClientResourceCacheOptions {\n maxSize?: number;\n ttlMs?: number; // ms\n pruneIntervalMs?: number;\n}\n\ninterface Entry<T> {\n resource: T;\n lastAccessed: number;\n}\n\nexport class ClientResourceCache<T> {\n private storage = new Map<string, Entry<T>>();\n private maxSize: number;\n private ttlMs: number;\n // Use ReturnType<typeof setInterval> for cross-env typings without NodeJS namespace\n private pruneInterval?: ReturnType<typeof setInterval>;\n\n constructor(options: ClientResourceCacheOptions = {}) {\n this.maxSize = options.maxSize ?? 1000;\n this.ttlMs = options.ttlMs ?? 1000 * 60 * 60;\n const pruneEvery = options.pruneIntervalMs ?? 1000 * 60 * 10;\n this.pruneInterval = setInterval(() => this.pruneExpired(), pruneEvery);\n }\n\n public getEntryCount(): number {\n return this.storage.size;\n }\n\n public getMaxSize(): number {\n return this.maxSize;\n }\n\n public getTtl(): number {\n return this.ttlMs;\n }\n\n public get(key: string): T | null {\n const entry = this.storage.get(key);\n if (!entry) return null;\n if (Date.now() - entry.lastAccessed > this.ttlMs) {\n this.delete(key);\n return null;\n }\n entry.lastAccessed = Date.now();\n this.storage.delete(key);\n this.storage.set(key, entry);\n return entry.resource;\n }\n\n public set(key: string, resource: T): void {\n if (this.storage.size >= this.maxSize) {\n this.evictLeastRecentlyUsed();\n }\n const newEntry: Entry<T> = { resource, lastAccessed: Date.now() };\n this.storage.set(key, newEntry);\n }\n\n public delete(key: string): void {\n this.storage.delete(key);\n }\n\n public stop(): void {\n if (this.pruneInterval) {\n clearInterval(this.pruneInterval);\n this.pruneInterval = undefined;\n }\n }\n\n private evictLeastRecentlyUsed(): void {\n const lruKey = this.storage.keys().next().value as string | undefined;\n if (lruKey) {\n this.delete(lruKey);\n }\n }\n\n private pruneExpired(): void {\n const now = Date.now();\n for (const [key, entry] of this.storage.entries()) {\n if (now - entry.lastAccessed > this.ttlMs) {\n this.delete(key);\n }\n }\n }\n}\n","import Fastify, {\n type FastifyInstance,\n type FastifyReply,\n type FastifyRequest,\n} from \"fastify\";\nimport cors from \"@fastify/cors\";\nimport { randomUUID } from \"node:crypto\";\nimport type { DynamicToolManager } from \"../core/DynamicToolManager.js\";\nimport type { ServerOrchestrator } from \"../core/ServerOrchestrator.js\";\nimport { ClientResourceCache } from \"../session/ClientResourceCache.js\";\nimport { StreamableHTTPServerTransport } from \"@modelcontextprotocol/sdk/server/streamableHttp.js\";\nimport { isInitializeRequest } from \"@modelcontextprotocol/sdk/types.js\";\nimport type { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\";\n\nexport interface FastifyTransportOptions {\n host?: string;\n port?: number;\n basePath?: string; // e.g. \"/\" or \"/api\"\n cors?: boolean;\n logger?: boolean;\n // Optional DI: provide a Fastify instance (e.g., for tests). If provided, start() will not listen.\n app?: FastifyInstance;\n}\n\nexport class FastifyTransport {\n private readonly options: {\n host: string;\n port: number;\n basePath: string;\n cors: boolean;\n logger: boolean;\n app?: FastifyInstance;\n };\n private readonly defaultManager: DynamicToolManager;\n private readonly createBundle: () => {\n server: McpServer;\n orchestrator: ServerOrchestrator;\n };\n private app: FastifyInstance | null = null;\n private readonly configSchema?: object;\n\n // Per-client server bundles and per-client session transports\n private readonly clientCache = new ClientResourceCache<{\n server: McpServer;\n orchestrator: ServerOrchestrator;\n sessions: Map<string, StreamableHTTPServerTransport>;\n }>();\n\n constructor(\n defaultManager: DynamicToolManager,\n createBundle: () => { server: McpServer; orchestrator: ServerOrchestrator },\n options: FastifyTransportOptions = {},\n configSchema?: object\n ) {\n this.defaultManager = defaultManager;\n this.createBundle = createBundle;\n this.options = {\n host: options.host ?? \"0.0.0.0\",\n port: options.port ?? 3000,\n basePath: options.basePath ?? \"/\",\n cors: options.cors ?? true,\n logger: options.logger ?? false,\n app: options.app,\n };\n this.configSchema = configSchema;\n }\n\n public async start(): Promise<void> {\n if (this.app) return;\n const app = this.options.app ?? Fastify({ logger: this.options.logger });\n if (this.options.cors) {\n await app.register(cors, { origin: true });\n }\n\n const base = this.options.basePath.endsWith(\"/\")\n ? this.options.basePath.slice(0, -1)\n : this.options.basePath;\n\n app.get(`${base}/healthz`, async () => ({ ok: true }));\n\n app.get(`${base}/tools`, async () => this.defaultManager.getStatus());\n\n // Config discovery (placeholder schema)\n app.get(`${base}/.well-known/mcp-config`, async (_req, reply) => {\n reply.header(\"Content-Type\", \"application/schema+json; charset=utf-8\");\n const baseSchema = this.configSchema ?? {\n $schema: \"https://json-schema.org/draft/2020-12/schema\",\n title: \"MCP Session Configuration\",\n description: \"Schema for the /mcp endpoint configuration\",\n type: \"object\",\n properties: {},\n required: [],\n \"x-mcp-version\": \"1.0\",\n \"x-query-style\": \"dot+bracket\",\n };\n return baseSchema;\n });\n\n // POST /mcp - JSON-RPC\n app.post(\n `${base}/mcp`,\n async (req: FastifyRequest, reply: FastifyReply) => {\n const clientIdHeader = (\n req.headers[\"mcp-client-id\"] as string | undefined\n )?.trim();\n const clientId =\n clientIdHeader && clientIdHeader.length > 0\n ? clientIdHeader\n : `anon-${randomUUID()}`;\n\n // When anon id, avoid caching (one-off)\n const useCache = !clientId.startsWith(\"anon-\");\n\n let bundle = useCache ? this.clientCache.get(clientId) : null;\n if (!bundle) {\n const created = this.createBundle();\n bundle = {\n server: created.server,\n orchestrator: created.orchestrator,\n sessions: new Map(),\n };\n if (useCache) this.clientCache.set(clientId, bundle);\n }\n\n const sessionId = req.headers[\"mcp-session-id\"] as string | undefined;\n\n let transport: StreamableHTTPServerTransport | undefined;\n if (sessionId && bundle.sessions.get(sessionId)) {\n transport = bundle.sessions.get(sessionId)!;\n } else if (!sessionId && isInitializeRequest((req as any).body)) {\n const newSessionId = randomUUID();\n transport = new StreamableHTTPServerTransport({\n sessionIdGenerator: () => newSessionId,\n onsessioninitialized: (sid: string) => {\n bundle!.sessions.set(sid, transport!);\n },\n });\n try {\n await bundle.server.connect(transport);\n } catch (error) {\n reply.code(500);\n return {\n jsonrpc: \"2.0\",\n error: { code: -32603, message: \"Error initializing server.\" },\n id: null,\n };\n }\n transport.onclose = () => {\n if (transport?.sessionId)\n bundle!.sessions.delete(transport.sessionId);\n };\n } else {\n reply.code(400);\n return {\n jsonrpc: \"2.0\",\n error: { code: -32000, message: \"Session not found or expired\" },\n id: null,\n };\n }\n\n // Delegate handling to SDK transport using raw Node req/res\n await transport.handleRequest(\n (req as any).raw,\n (reply as any).raw,\n (req as any).body\n );\n // Fastify will consider the response already sent by transport\n return reply;\n }\n );\n\n // GET /mcp - SSE notifications\n app.get(`${base}/mcp`, async (req: FastifyRequest, reply: FastifyReply) => {\n const clientIdHeader = (\n req.headers[\"mcp-client-id\"] as string | undefined\n )?.trim();\n const clientId =\n clientIdHeader && clientIdHeader.length > 0 ? clientIdHeader : \"\";\n if (!clientId) {\n reply.code(400);\n return \"Missing mcp-client-id\";\n }\n const bundle = this.clientCache.get(clientId);\n if (!bundle) {\n reply.code(400);\n return \"Invalid or expired client\";\n }\n const sessionId = req.headers[\"mcp-session-id\"] as string | undefined;\n if (!sessionId) {\n reply.code(400);\n return \"Missing mcp-session-id\";\n }\n const transport = bundle.sessions.get(sessionId);\n if (!transport) {\n reply.code(400);\n return \"Invalid or expired session ID\";\n }\n await transport.handleRequest((req as any).raw, (reply as any).raw);\n return reply;\n });\n\n // DELETE /mcp - terminate session\n app.delete(\n `${base}/mcp`,\n async (req: FastifyRequest, reply: FastifyReply) => {\n const clientIdHeader = (\n req.headers[\"mcp-client-id\"] as string | undefined\n )?.trim();\n const clientId =\n clientIdHeader && clientIdHeader.length > 0 ? clientIdHeader : \"\";\n const sessionId = req.headers[\"mcp-session-id\"] as string | undefined;\n if (!clientId || !sessionId) {\n reply.code(400);\n return {\n jsonrpc: \"2.0\",\n error: {\n code: -32600,\n message: \"Missing mcp-client-id or mcp-session-id header\",\n },\n id: null,\n };\n }\n const bundle = this.clientCache.get(clientId);\n const transport = bundle?.sessions.get(sessionId);\n if (!bundle || !transport) {\n reply.code(404);\n return {\n jsonrpc: \"2.0\",\n error: { code: -32000, message: \"Session not found or expired\" },\n id: null,\n };\n }\n reply.code(204).send();\n return reply;\n }\n );\n\n // Only listen if we created the app\n if (!this.options.app) {\n await app.listen({ host: this.options.host, port: this.options.port });\n }\n this.app = app;\n }\n\n public async stop(): Promise<void> {\n if (!this.app) return;\n if (!this.options.app) {\n await this.app.close();\n }\n this.app = null;\n }\n}\n","import { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\";\nimport type { ExposurePolicy, Mode, ToolSetCatalog } from \"../types/index.js\";\nimport { ServerOrchestrator } from \"../core/ServerOrchestrator.js\";\nimport {\n FastifyTransport,\n type FastifyTransportOptions,\n} from \"../http/FastifyTransport.js\";\n\nexport interface CreateMcpServerOptions {\n catalog: ToolSetCatalog;\n moduleLoaders?: Record<string, any>;\n exposurePolicy?: ExposurePolicy;\n context?: unknown;\n startup?: { mode?: Exclude<Mode, \"ALL\">; toolsets?: string[] | \"ALL\" };\n registerMetaTools?: boolean;\n http?: FastifyTransportOptions;\n mcp?: {\n name?: string;\n version?: string;\n capabilities?: Record<string, unknown>;\n };\n configSchema?: object;\n}\n\nexport async function createMcpServer(options: CreateMcpServerOptions) {\n const mode: Exclude<Mode, \"ALL\"> = options.startup?.mode ?? \"DYNAMIC\";\n const name = options.mcp?.name ?? \"mcp-dynamic-tooling\";\n const version = options.mcp?.version ?? \"0.0.0\";\n const baseCaps = options.mcp?.capabilities ?? {};\n const mergedCaps = {\n ...baseCaps,\n tools: {\n ...(typeof (baseCaps as any).tools === \"object\"\n ? (baseCaps as any).tools\n : {}),\n // listChanged is internal-only and computed by mode\n listChanged: mode === \"DYNAMIC\",\n },\n } as any;\n const server = new McpServer({\n name,\n version,\n capabilities: mergedCaps,\n });\n\n // Typed, guarded notifier\n type NotifierA = {\n server: { notification: (msg: { method: string }) => Promise<void> | void };\n };\n type NotifierB = { notifyToolsListChanged: () => Promise<void> | void };\n const hasNotifierA = (s: unknown): s is NotifierA =>\n typeof (s as any)?.server?.notification === \"function\";\n const hasNotifierB = (s: unknown): s is NotifierB =>\n typeof (s as any)?.notifyToolsListChanged === \"function\";\n const notifyToolsChanged = async (target: unknown) => {\n try {\n if (hasNotifierA(target)) {\n await target.server.notification({\n method: \"notifications/tools/list_changed\",\n });\n return;\n }\n if (hasNotifierB(target)) {\n await target.notifyToolsListChanged();\n }\n } catch {}\n };\n\n const orchestrator = new ServerOrchestrator({\n server,\n catalog: options.catalog,\n moduleLoaders: options.moduleLoaders,\n exposurePolicy: options.exposurePolicy,\n context: options.context,\n notifyToolsListChanged: async () => notifyToolsChanged(server),\n startup: options.startup,\n registerMetaTools:\n options.registerMetaTools !== undefined\n ? options.registerMetaTools\n : mode === \"DYNAMIC\",\n });\n\n const transport = new FastifyTransport(\n orchestrator.getManager(),\n () => {\n // Create a fresh server + orchestrator bundle for a new client when needed\n const innerMode: Exclude<Mode, \"ALL\"> =\n options.startup?.mode ?? \"DYNAMIC\";\n const innerName = options.mcp?.name ?? name;\n const innerVersion = options.mcp?.version ?? version;\n const innerBaseCaps = options.mcp?.capabilities ?? baseCaps;\n const innerMergedCaps = {\n ...innerBaseCaps,\n tools: {\n ...(typeof (innerBaseCaps as any).tools === \"object\"\n ? (innerBaseCaps as any).tools\n : {}),\n listChanged: innerMode === \"DYNAMIC\",\n },\n } as any;\n const server = new McpServer({\n name: innerName,\n version: innerVersion,\n capabilities: innerMergedCaps,\n });\n const orchestrator = new ServerOrchestrator({\n server,\n catalog: options.catalog,\n moduleLoaders: options.moduleLoaders,\n exposurePolicy: options.exposurePolicy,\n context: options.context,\n notifyToolsListChanged: async () => notifyToolsChanged(server),\n startup: options.startup,\n registerMetaTools:\n options.registerMetaTools !== undefined\n ? options.registerMetaTools\n : innerMode === \"DYNAMIC\",\n });\n return { server, orchestrator };\n },\n options.http,\n options.configSchema\n );\n\n return {\n server,\n start: async () => {\n await transport.start();\n },\n close: async () => {\n await transport.stop();\n },\n };\n}\n"],"names":["DEFAULT_KEYS","ModeResolver","options","env","args","input","catalog","raw","s","valid","result","name","toolsets","modules","def","m","sanitized","toolsetNames","error","source","key","value","ModuleResolver","context","collected","modKey","loader","loaded","err","ToolingError","message","code","details","_options","ToolRegistry","toolsetKey","toolName","set","tools","safe","k","v","DynamicToolManager","toolsetName","validation","resolvedTools","mapped","activeToolsets","results","res","successAll","r","tool","all","registerMetaTools","server","manager","mode","z","available","byToolset","items","payload","status","ServerOrchestrator","startup","toolRegistry","initial","ClientResourceCache","pruneEvery","entry","resource","newEntry","lruKey","now","FastifyTransport","defaultManager","createBundle","configSchema","app","Fastify","cors","base","_req","reply","req","clientIdHeader","clientId","randomUUID","useCache","bundle","created","sessionId","transport","isInitializeRequest","newSessionId","StreamableHTTPServerTransport","sid","createMcpServer","version","baseCaps","mergedCaps","McpServer","hasNotifierA","hasNotifierB","notifyToolsChanged","target","orchestrator","innerMode","innerName","innerVersion","innerBaseCaps","innerMergedCaps"],"mappings":";;;;;;;AAWA,MAAMA,IAA2C;AAAA,EAC/C,SAAS,CAAC,0BAA0B,wBAAwB,wBAAwB;AAAA,EACpF,UAAU,CAAC,aAAa,YAAY,eAAe;AACrD;AAEO,MAAMC,EAAa;AAAA,EAGxB,YAAYC,IAA+B,IAAI;AAC7C,SAAK,OAAO;AAAA,MACV,SAASA,EAAQ,MAAM,WAAWF,EAAa;AAAA,MAC/C,UAAUE,EAAQ,MAAM,YAAYF,EAAa;AAAA,IAAA;AAAA,EAErD;AAAA,EAEO,YAAYG,GAA0CC,GAA6C;AAExG,WAAI,KAAK,iBAAiBA,CAAI,IAAU,YAEf,KAAK,kBAAkBA,CAAI,IACvB,WAGzB,KAAK,iBAAiBD,CAAG,IAAU,YAEf,KAAK,kBAAkBA,CAAG,IACtB,WAErB;AAAA,EACT;AA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5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"module": "dist/index.js",
|
|
8
|
+
"types": "dist/index.d.ts",
|
|
9
|
+
"files": [
|
|
10
|
+
"dist",
|
|
11
|
+
"README.md",
|
|
12
|
+
"LICENSE"
|
|
13
|
+
],
|
|
14
|
+
"scripts": {
|
|
15
|
+
"build": "vite build",
|
|
16
|
+
"dev": "vite build --watch",
|
|
17
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
18
|
+
"test": "vitest",
|
|
19
|
+
"test:run": "vitest run",
|
|
20
|
+
"test:coverage": "vitest run --coverage",
|
|
21
|
+
"prepublishOnly": "npm run typecheck && npm run build && npm run test:run"
|
|
22
|
+
},
|
|
23
|
+
"peerDependencies": {},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@fastify/cors": "^10.0.1",
|
|
26
|
+
"@modelcontextprotocol/sdk": "^1.0.0",
|
|
27
|
+
"fastify": "^5.0.0",
|
|
28
|
+
"zod": "^3.22.4"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@types/connect": "^3.4.38",
|
|
32
|
+
"@types/node": "^20.11.5",
|
|
33
|
+
"@vitest/coverage-v8": "^3.2.4",
|
|
34
|
+
"tsx": "^4.19.0",
|
|
35
|
+
"typescript": "^5.3.3",
|
|
36
|
+
"vite": "^5.3.1",
|
|
37
|
+
"vitest": "^3.2.4"
|
|
38
|
+
},
|
|
39
|
+
"engines": {
|
|
40
|
+
"node": ">=20.0.0"
|
|
41
|
+
},
|
|
42
|
+
"license": "Apache-2.0",
|
|
43
|
+
"description": "Dynamic MCP server toolkit for runtime toolset management with Fastify transport and meta-tools",
|
|
44
|
+
"author": "code-rabi",
|
|
45
|
+
"sideEffects": false,
|
|
46
|
+
"exports": {
|
|
47
|
+
".": {
|
|
48
|
+
"types": "./dist/index.d.ts",
|
|
49
|
+
"import": "./dist/index.js"
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
"keywords": [
|
|
53
|
+
"model-context-protocol",
|
|
54
|
+
"mcp",
|
|
55
|
+
"mcp-server",
|
|
56
|
+
"dynamic-tools",
|
|
57
|
+
"toolset",
|
|
58
|
+
"tool-management",
|
|
59
|
+
"json-rpc",
|
|
60
|
+
"fastify",
|
|
61
|
+
"zod",
|
|
62
|
+
"ai",
|
|
63
|
+
"llm",
|
|
64
|
+
"agents"
|
|
65
|
+
]
|
|
66
|
+
}
|