apcore-mcp 0.13.0 → 0.14.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.
Files changed (112) hide show
  1. package/LICENSE +190 -0
  2. package/README.md +165 -19
  3. package/dist/acl-builder.d.ts +43 -0
  4. package/dist/acl-builder.d.ts.map +1 -0
  5. package/dist/acl-builder.js +115 -0
  6. package/dist/acl-builder.js.map +1 -0
  7. package/dist/adapters/annotations.d.ts.map +1 -1
  8. package/dist/adapters/annotations.js +23 -2
  9. package/dist/adapters/annotations.js.map +1 -1
  10. package/dist/adapters/errors.d.ts +17 -0
  11. package/dist/adapters/errors.d.ts.map +1 -1
  12. package/dist/adapters/errors.js +146 -2
  13. package/dist/adapters/errors.js.map +1 -1
  14. package/dist/adapters/id-normalizer.d.ts +40 -0
  15. package/dist/adapters/id-normalizer.d.ts.map +1 -0
  16. package/dist/adapters/id-normalizer.js +59 -0
  17. package/dist/adapters/id-normalizer.js.map +1 -0
  18. package/dist/adapters/index.d.ts +2 -2
  19. package/dist/adapters/index.d.ts.map +1 -1
  20. package/dist/adapters/index.js +2 -2
  21. package/dist/adapters/index.js.map +1 -1
  22. package/dist/adapters/{mcpErrorFormatter.d.ts → mcp-error-formatter.d.ts} +1 -1
  23. package/dist/adapters/mcp-error-formatter.d.ts.map +1 -0
  24. package/dist/adapters/{mcpErrorFormatter.js → mcp-error-formatter.js} +1 -1
  25. package/dist/adapters/mcp-error-formatter.js.map +1 -0
  26. package/dist/adapters/schema.d.ts +21 -4
  27. package/dist/adapters/schema.d.ts.map +1 -1
  28. package/dist/adapters/schema.js +147 -13
  29. package/dist/adapters/schema.js.map +1 -1
  30. package/dist/apcore-mcp.d.ts +24 -2
  31. package/dist/apcore-mcp.d.ts.map +1 -1
  32. package/dist/apcore-mcp.js +8 -0
  33. package/dist/apcore-mcp.js.map +1 -1
  34. package/dist/auth/hooks.d.ts +1 -1
  35. package/dist/auth/hooks.d.ts.map +1 -1
  36. package/dist/auth/hooks.js +10 -3
  37. package/dist/auth/hooks.js.map +1 -1
  38. package/dist/auth/jwt.d.ts +1 -2
  39. package/dist/auth/jwt.d.ts.map +1 -1
  40. package/dist/auth/jwt.js +18 -10
  41. package/dist/auth/jwt.js.map +1 -1
  42. package/dist/auth/types.d.ts +6 -3
  43. package/dist/auth/types.d.ts.map +1 -1
  44. package/dist/cli.d.ts.map +1 -1
  45. package/dist/cli.js +12 -1
  46. package/dist/cli.js.map +1 -1
  47. package/dist/config.d.ts.map +1 -1
  48. package/dist/config.js +6 -0
  49. package/dist/config.js.map +1 -1
  50. package/dist/converters/openai.d.ts +10 -0
  51. package/dist/converters/openai.d.ts.map +1 -1
  52. package/dist/converters/openai.js +100 -5
  53. package/dist/converters/openai.js.map +1 -1
  54. package/dist/explorer/index.d.ts +2 -0
  55. package/dist/explorer/index.d.ts.map +1 -0
  56. package/dist/explorer/index.js +2 -0
  57. package/dist/explorer/index.js.map +1 -0
  58. package/dist/index.d.ts +55 -5
  59. package/dist/index.d.ts.map +1 -1
  60. package/dist/index.js +319 -107
  61. package/dist/index.js.map +1 -1
  62. package/dist/inspector/index.d.ts +2 -0
  63. package/dist/inspector/index.d.ts.map +1 -0
  64. package/dist/inspector/index.js +2 -0
  65. package/dist/inspector/index.js.map +1 -0
  66. package/dist/middleware-builder.d.ts +41 -0
  67. package/dist/middleware-builder.d.ts.map +1 -0
  68. package/dist/middleware-builder.js +129 -0
  69. package/dist/middleware-builder.js.map +1 -0
  70. package/dist/server/async-task-bridge.d.ts +190 -0
  71. package/dist/server/async-task-bridge.d.ts.map +1 -0
  72. package/dist/server/async-task-bridge.js +393 -0
  73. package/dist/server/async-task-bridge.js.map +1 -0
  74. package/dist/server/context.d.ts +9 -2
  75. package/dist/server/context.d.ts.map +1 -1
  76. package/dist/server/context.js +14 -6
  77. package/dist/server/context.js.map +1 -1
  78. package/dist/server/factory.d.ts +25 -2
  79. package/dist/server/factory.d.ts.map +1 -1
  80. package/dist/server/factory.js +127 -7
  81. package/dist/server/factory.js.map +1 -1
  82. package/dist/server/listener.d.ts +3 -0
  83. package/dist/server/listener.d.ts.map +1 -1
  84. package/dist/server/listener.js +13 -2
  85. package/dist/server/listener.js.map +1 -1
  86. package/dist/server/observability.d.ts +51 -0
  87. package/dist/server/observability.d.ts.map +1 -0
  88. package/dist/server/observability.js +96 -0
  89. package/dist/server/observability.js.map +1 -0
  90. package/dist/server/router.d.ts +77 -0
  91. package/dist/server/router.d.ts.map +1 -1
  92. package/dist/server/router.js +224 -10
  93. package/dist/server/router.js.map +1 -1
  94. package/dist/server/trace-context.d.ts +40 -0
  95. package/dist/server/trace-context.d.ts.map +1 -0
  96. package/dist/server/trace-context.js +67 -0
  97. package/dist/server/trace-context.js.map +1 -0
  98. package/dist/server/transport.d.ts +39 -0
  99. package/dist/server/transport.d.ts.map +1 -1
  100. package/dist/server/transport.js +134 -4
  101. package/dist/server/transport.js.map +1 -1
  102. package/dist/types.d.ts +14 -5
  103. package/dist/types.d.ts.map +1 -1
  104. package/dist/types.js +8 -0
  105. package/dist/types.js.map +1 -1
  106. package/package.json +11 -5
  107. package/dist/adapters/idNormalizer.d.ts +0 -22
  108. package/dist/adapters/idNormalizer.d.ts.map +0 -1
  109. package/dist/adapters/idNormalizer.js +0 -30
  110. package/dist/adapters/idNormalizer.js.map +0 -1
  111. package/dist/adapters/mcpErrorFormatter.d.ts.map +0 -1
  112. package/dist/adapters/mcpErrorFormatter.js.map +0 -1
package/LICENSE ADDED
@@ -0,0 +1,190 @@
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 the 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 the 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 any 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
+ Copyright 2024 AI Perceivable
179
+
180
+ Licensed under the Apache License, Version 2.0 (the "License");
181
+ you may not use this file except in compliance with the License.
182
+ You may obtain a copy of the License at
183
+
184
+ http://www.apache.org/licenses/LICENSE-2.0
185
+
186
+ Unless required by applicable law or agreed to in writing, software
187
+ distributed under the License is distributed on an "AS IS" BASIS,
188
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+ See the License for the specific language governing permissions and
190
+ limitations under the License.
package/README.md CHANGED
@@ -30,7 +30,7 @@ For full documentation, including Quick Start guides for both Python and TypeScr
30
30
  ## Requirements
31
31
 
32
32
  - Node.js >= 18.0.0
33
- - `apcore-js >= 0.17.1`
33
+ - `apcore-js >= 0.19.0`
34
34
 
35
35
  ## Installation
36
36
 
@@ -96,8 +96,9 @@ npx apcore-mcp --extensions-dir ./extensions --transport sse --port 8000
96
96
  | `--jwt-algorithm` | `HS256` | JWT algorithm |
97
97
  | `--jwt-audience` | — | Expected JWT audience claim |
98
98
  | `--jwt-issuer` | — | Expected JWT issuer claim |
99
- | `--jwt-require-auth` | `true` | Require auth (use `--no-jwt-require-auth` for permissive mode) |
100
- | `--exempt-paths` | `/health,/metrics` | Comma-separated paths exempt from auth |
99
+ | `--jwt-require-auth` | `true` | Require auth (use `--jwt-permissive` to override and allow unauthenticated requests) |
100
+ | `--jwt-permissive` | `false` | Permissive mode: allow unauthenticated requests (overrides `--jwt-require-auth`) |
101
+ | `--exempt-paths` | `/health,/metrics,/usage` | Comma-separated paths exempt from auth |
101
102
 
102
103
  JWT key resolution priority: `--jwt-key-file` > `--jwt-secret` > `APCORE_JWT_SECRET` environment variable.
103
104
 
@@ -161,6 +162,79 @@ Connect any MCP client to `http://your-host:9000/mcp`.
161
162
 
162
163
  ## API Reference
163
164
 
165
+ ### Programmatic API – `APCoreMCP` class
166
+
167
+ The `APCoreMCP` class is the recommended OOP entry point. It bundles a unified configuration object, lazy backend resolution (path / `Registry` / `Executor`), and exposes `serve` / `asyncServe` / `toOpenaiTools` as instance methods so you configure once and use everywhere.
168
+
169
+ ```typescript
170
+ import { APCoreMCP } from "apcore-mcp";
171
+
172
+ // 1. Point at an extensions directory (lazy discovery on first use)
173
+ const mcp = new APCoreMCP("./extensions", {
174
+ name: "my-server",
175
+ tags: ["public"],
176
+ observability: true,
177
+ });
178
+
179
+ // 2. Launch as MCP server (blocks until shutdown)
180
+ await mcp.serve({ transport: "streamable-http", port: 8000, explorer: true });
181
+
182
+ // 3. Or export OpenAI tool definitions
183
+ const tools = mcp.toOpenaiTools({ strict: true });
184
+
185
+ // 4. Or embed into an existing HTTP server
186
+ const app = await mcp.asyncServe({ explorer: true });
187
+ // app.handler is a Node.js request handler; call app.close() on shutdown
188
+
189
+ // 5. Or pass an existing Registry / Executor
190
+ import { Registry } from "apcore-js";
191
+ const registry = new Registry({ extensionsDir: "./extensions" });
192
+ await registry.discover();
193
+ const mcp2 = new APCoreMCP(registry, { name: "my-server", tags: ["public"] });
194
+ ```
195
+
196
+ **Constructor**
197
+
198
+ ```typescript
199
+ new APCoreMCP(
200
+ extensionsDirOrBackend: string | Registry | Executor,
201
+ options?: APCoreMCPOptions,
202
+ );
203
+ ```
204
+
205
+ The first argument is either a path to an apcore extensions directory (discovery is deferred to first use) or an existing `Registry` / `Executor` instance.
206
+
207
+ **`APCoreMCPOptions` fields**
208
+
209
+ - `name` — MCP server name. Default: `"apcore-mcp"`
210
+ - `version` — MCP server version. Default: package version
211
+ - `tags` — Filter modules by tag list
212
+ - `prefix` — Filter modules by ID prefix
213
+ - `logLevel` — Minimum log level (`DEBUG` | `INFO` | `WARNING` | `ERROR` | `CRITICAL`)
214
+ - `validateInputs` — Validate inputs against schemas. Default: `false`
215
+ - `metricsCollector` — `MetricsExporter` or `true` to auto-instantiate
216
+ - `observability` — Enable the full metrics + usage observability stack
217
+ - `async` — `boolean | { enabled?, maxConcurrent?, maxTasks? }` for the Async Task Bridge (F-043)
218
+ - `authenticator` — Optional `Authenticator` (HTTP transports only)
219
+ - `requireAuth` — If `true` (default), reject unauthenticated requests with 401
220
+ - `exemptPaths` — Paths exempt from authentication
221
+ - `approvalHandler` — Optional approval handler passed to the Executor
222
+ - `outputFormatter` — Custom function to format tool execution results
223
+ - `middleware` — Array of apcore `Middleware` installed via `executor.use()`
224
+ - `acl` — Optional apcore `ACL` instance installed via `executor.setAcl()`
225
+
226
+ **Properties**
227
+
228
+ - `.registry` — The underlying apcore `Registry` (resolved on first access)
229
+ - `.executor` — The underlying apcore `Executor` (populated after `serve()` / `asyncServe()`)
230
+ - `.tools` — List of discovered module IDs that will be exposed as tools (honours `tags` / `prefix`)
231
+
232
+ **Methods**
233
+
234
+ - `.serve(options?)` — Launch an MCP server. Accepts `APCoreMCPServeOptions`: `transport`, `host`, `port`, `onStartup`, `onShutdown`, `explorer`, `explorerPrefix`, `allowExecute`, `explorerTitle`, `explorerProjectName`, `explorerProjectUrl`. Constructor-level options (auth, observability, middleware, acl, async, etc.) are applied automatically.
235
+ - `.asyncServe(options?)` — Build an embeddable Node.js HTTP request handler. Accepts `APCoreMCPAsyncServeOptions`: `explorer`, `explorerPrefix`, `allowExecute`, `explorerTitle`, `explorerProjectName`, `explorerProjectUrl`, `endpoint`. Returns `{ handler, close }`.
236
+ - `.toOpenaiTools(options?)` — Export modules as OpenAI-compatible tool definitions. Accepts `ToOpenaiToolsOptions`: `embedAnnotations`, `strict`. `tags` / `prefix` are inherited from the constructor.
237
+
164
238
  ### `serve(registryOrExecutor, options?)`
165
239
 
166
240
  Launch an MCP Server that exposes all apcore modules as tools.
@@ -169,41 +243,112 @@ Launch an MCP Server that exposes all apcore modules as tools.
169
243
  function serve(
170
244
  registryOrExecutor: Registry | Executor,
171
245
  options?: {
246
+ // Transport
172
247
  transport?: "stdio" | "streamable-http" | "sse";
173
248
  host?: string;
174
249
  port?: number;
250
+ // Identity
175
251
  name?: string;
176
252
  version?: string;
177
- dynamic?: boolean;
178
- validateInputs?: boolean;
253
+ // Lifecycle
254
+ onStartup?: () => void | Promise<void>;
255
+ onShutdown?: () => void | Promise<void>;
256
+ // Module filtering / discovery
179
257
  tags?: string[] | null;
180
258
  prefix?: string | null;
259
+ dynamic?: boolean;
260
+ validateInputs?: boolean;
181
261
  logLevel?: "DEBUG" | "INFO" | "WARNING" | "ERROR" | "CRITICAL";
182
- onStartup?: () => void | Promise<void>;
183
- onShutdown?: () => void | Promise<void>;
184
- metricsCollector?: MetricsExporter;
262
+ // Async Task Bridge (F-043)
263
+ async?: boolean | { enabled?: boolean; maxConcurrent?: number; maxTasks?: number };
264
+ // Executor wiring
265
+ middleware?: unknown[];
266
+ acl?: unknown;
267
+ approvalHandler?: unknown;
268
+ strategy?: string;
269
+ // Observability (F-044)
270
+ metricsCollector?: MetricsExporter | boolean;
271
+ observability?: ObservabilityFlag;
272
+ trace?: boolean;
273
+ // Output handling
274
+ outputFormatter?: (result: Record<string, unknown>) => string;
275
+ redactOutput?: boolean;
276
+ // Auth (HTTP transports only)
277
+ authenticator?: Authenticator;
278
+ requireAuth?: boolean;
279
+ exemptPaths?: string[];
280
+ // Tool Explorer UI
185
281
  explorer?: boolean;
186
282
  explorerPrefix?: string;
187
283
  allowExecute?: boolean;
188
- authenticator?: Authenticator;
189
- exemptPaths?: string[];
190
- approvalHandler?: unknown;
191
284
  explorerTitle?: string;
192
285
  explorerProjectName?: string;
193
286
  explorerProjectUrl?: string;
194
- requireAuth?: boolean;
195
- outputFormatter?: (result: Record<string, unknown>) => string;
287
+ // Adapter overrides (advanced — Extension Bridge)
288
+ schemaConverter?: SchemaConverter;
289
+ annotationMapper?: AnnotationMapper;
290
+ errorMapper?: ErrorMapper;
196
291
  }
197
292
  ): Promise<void>;
198
293
  ```
199
294
 
200
- **Additional options:**
295
+ **Options reference:**
296
+
297
+ *Transport*
298
+ - `transport` — `"stdio"` (default), `"streamable-http"`, or `"sse"`
299
+ - `host` — Host address for HTTP-based transports. Default: `"127.0.0.1"`
300
+ - `port` — Port for HTTP-based transports. Default: `8000`
201
301
 
302
+ *Identity*
303
+ - `name` — MCP server name. Default: `"apcore-mcp"`
304
+ - `version` — MCP server version. Default: package version
305
+
306
+ *Lifecycle*
307
+ - `onStartup` — Async callback invoked before the server starts
308
+ - `onShutdown` — Async callback invoked after the server stops (or on error)
309
+
310
+ *Module filtering / discovery*
311
+ - `tags` — Filter modules by tag list. Default: `null` (no filtering)
312
+ - `prefix` — Filter modules by ID prefix. Default: `null` (no filtering)
313
+ - `dynamic` — Enable dynamic tool registration via `RegistryListener`. Default: `false`
314
+ - `validateInputs` — Validate inputs against schemas before dispatch. Default: `false`
315
+ - `logLevel` — Minimum log level. Suppresses console methods below this level
316
+
317
+ *Async Task Bridge (F-043)*
318
+ - `async` — Enable the AsyncTaskBridge and `__apcore_task_*` meta-tools. Pass `false` to disable, or `{ maxConcurrent, maxTasks }` for fine-grained tuning. Default: `true`
319
+
320
+ *Executor wiring*
321
+ - `middleware` — Array of apcore `Middleware` instances installed via `executor.use()`. Appended to any middleware declared under Config Bus key `mcp.middleware`
322
+ - `acl` — Optional apcore `ACL` instance installed via `executor.setAcl()`. Caller-supplied ACL takes precedence over `mcp.acl` Config Bus entry
323
+ - `approvalHandler` — Optional approval handler passed to the Executor (e.g. `ElicitationApprovalHandler`)
324
+ - `strategy` — Execution strategy name passed to the Executor (e.g. `"standard"`, `"internal"`)
325
+
326
+ *Observability (F-044)*
327
+ - `metricsCollector` — `MetricsExporter` instance, or `true` to auto-instantiate apcore-js's `MetricsCollector` and install `MetricsMiddleware`
328
+ - `observability` — Enable the full observability stack (metrics + usage middleware) and expose `/metrics` + `/usage` endpoints
329
+ - `trace` — When `true`, enables pipeline trace via `callWithTrace()`. Adds `_meta.trace` to non-streaming tool responses. Default: `false`
330
+
331
+ *Output handling*
332
+ - `outputFormatter` — Custom function to format tool execution results. When undefined, results are serialized with `JSON.stringify(result)`
333
+ - `redactOutput` — When `true` (default), redact sensitive fields from tool output via apcore's `redactSensitive()` before formatting
334
+
335
+ *Auth (HTTP transports only)*
336
+ - `authenticator` — `Authenticator` instance for request authentication
337
+ - `requireAuth` — If `true` (default), unauthenticated requests are rejected with 401. Set to `false` for permissive mode
338
+ - `exemptPaths` — Paths exempt from authentication. Default: `["/health", "/metrics"]`
339
+
340
+ *Tool Explorer UI*
341
+ - `explorer` — Enable the browser-based Tool Explorer UI (HTTP only). Default: `false`
342
+ - `explorerPrefix` — URL prefix for the explorer. Default: `"/explorer"`
343
+ - `allowExecute` — Allow tool execution from the explorer UI. Default: `false`
202
344
  - `explorerTitle` — Custom title for the Tool Explorer UI page
203
345
  - `explorerProjectName` — Project name shown in the explorer UI footer
204
346
  - `explorerProjectUrl` — Project URL shown in the explorer UI footer
205
- - `requireAuth` — If `true` (default), unauthenticated requests are rejected with 401. Set to `false` for permissive mode
206
- - `outputFormatter`Custom function to format tool execution results. When undefined, results are serialized with `JSON.stringify(result)`
347
+
348
+ *Adapter overrides (advanced Extension Bridge, F-042)*
349
+ - `schemaConverter` — Override the default `SchemaConverter` (custom JSON Schema strictness/dialect)
350
+ - `annotationMapper` — Override the default `AnnotationMapper` (custom annotation wire format)
351
+ - `errorMapper` — Override the default `ErrorMapper` consumed by `ExecutionRouter`
207
352
 
208
353
  ### `asyncServe(registryOrExecutor, options?)`
209
354
 
@@ -265,7 +410,7 @@ apcore-mcp supports JWT Bearer token authentication for HTTP-based transports.
265
410
  import { serve, JWTAuthenticator } from "apcore-mcp";
266
411
 
267
412
  const authenticator = new JWTAuthenticator({
268
- secret: "your-secret-key",
413
+ key: "your-secret-key",
269
414
  algorithms: ["HS256"],
270
415
  audience: "my-app",
271
416
  issuer: "auth-service",
@@ -299,8 +444,9 @@ await serve(executor, {
299
444
  | `--jwt-algorithm` | `HS256` | JWT algorithm |
300
445
  | `--jwt-audience` | — | Expected audience claim |
301
446
  | `--jwt-issuer` | — | Expected issuer claim |
302
- | `--jwt-require-auth` | `true` | Require auth. Use `--no-jwt-require-auth` for permissive mode |
303
- | `--exempt-paths` | `/health,/metrics` | Comma-separated paths exempt from auth |
447
+ | `--jwt-require-auth` | `true` | Require auth. Use `--jwt-permissive` to allow unauthenticated requests |
448
+ | `--jwt-permissive` | `false` | Overrides `--jwt-require-auth` and allows unauthenticated requests |
449
+ | `--exempt-paths` | `/health,/metrics,/usage` | Comma-separated paths exempt from auth |
304
450
 
305
451
  JWT key resolution priority: `--jwt-key-file` > `--jwt-secret` > `APCORE_JWT_SECRET` environment variable.
306
452
 
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Build an apcore `ACL` instance from a Config Bus `mcp.acl` section.
3
+ *
4
+ * Config Bus schema (YAML, shared across Python/TS/Rust bridges):
5
+ *
6
+ * ```yaml
7
+ * mcp:
8
+ * acl:
9
+ * default_effect: deny # or "allow" — default "deny" (fail-secure)
10
+ * rules:
11
+ * - callers: ["role:admin"]
12
+ * targets: ["sys.*"]
13
+ * effect: allow
14
+ * description: "Admins can reach system modules"
15
+ * - callers: ["*"]
16
+ * targets: ["sys.reload", "sys.toggle"]
17
+ * effect: deny
18
+ * conditions:
19
+ * identity_types: ["human", "system"]
20
+ * ```
21
+ *
22
+ * Mirrors the Python `acl_builder.build_acl_from_config` contract. Invalid
23
+ * entries throw so misconfiguration fails loudly at startup.
24
+ */
25
+ export interface AclConfigRule {
26
+ callers: string[];
27
+ targets: string[];
28
+ effect: string;
29
+ description?: string;
30
+ conditions?: Record<string, unknown> | null;
31
+ }
32
+ export interface AclConfigSection {
33
+ default_effect?: string;
34
+ rules?: AclConfigRule[];
35
+ }
36
+ /**
37
+ * Construct an apcore `ACL` from a Config Bus `mcp.acl` mapping.
38
+ *
39
+ * Returns `null` when `aclConfig` is falsy (no ACL section configured).
40
+ * Throws on malformed entries.
41
+ */
42
+ export declare function buildAclFromConfig(aclConfig: unknown): Promise<unknown | null>;
43
+ //# sourceMappingURL=acl-builder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"acl-builder.d.ts","sourceRoot":"","sources":["../src/acl-builder.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAWH,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;CAC7C;AAED,MAAM,WAAW,gBAAgB;IAC/B,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,KAAK,CAAC,EAAE,aAAa,EAAE,CAAC;CACzB;AAED;;;;;GAKG;AACH,wBAAsB,kBAAkB,CACtC,SAAS,EAAE,OAAO,GACjB,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC,CA+GzB"}
@@ -0,0 +1,115 @@
1
+ /**
2
+ * Build an apcore `ACL` instance from a Config Bus `mcp.acl` section.
3
+ *
4
+ * Config Bus schema (YAML, shared across Python/TS/Rust bridges):
5
+ *
6
+ * ```yaml
7
+ * mcp:
8
+ * acl:
9
+ * default_effect: deny # or "allow" — default "deny" (fail-secure)
10
+ * rules:
11
+ * - callers: ["role:admin"]
12
+ * targets: ["sys.*"]
13
+ * effect: allow
14
+ * description: "Admins can reach system modules"
15
+ * - callers: ["*"]
16
+ * targets: ["sys.reload", "sys.toggle"]
17
+ * effect: deny
18
+ * conditions:
19
+ * identity_types: ["human", "system"]
20
+ * ```
21
+ *
22
+ * Mirrors the Python `acl_builder.build_acl_from_config` contract. Invalid
23
+ * entries throw so misconfiguration fails loudly at startup.
24
+ */
25
+ const ALLOWED_EFFECTS = new Set(["allow", "deny"]);
26
+ const ALLOWED_RULE_KEYS = new Set([
27
+ "callers",
28
+ "targets",
29
+ "effect",
30
+ "description",
31
+ "conditions",
32
+ ]);
33
+ /**
34
+ * Construct an apcore `ACL` from a Config Bus `mcp.acl` mapping.
35
+ *
36
+ * Returns `null` when `aclConfig` is falsy (no ACL section configured).
37
+ * Throws on malformed entries.
38
+ */
39
+ export async function buildAclFromConfig(aclConfig) {
40
+ if (aclConfig === null || aclConfig === undefined)
41
+ return null;
42
+ if (typeof aclConfig !== "object" || Array.isArray(aclConfig)) {
43
+ throw new Error(`mcp.acl must be a mapping with 'rules' and optional 'default_effect', ` +
44
+ `got ${Array.isArray(aclConfig) ? "array" : typeof aclConfig}`);
45
+ }
46
+ const cfg = aclConfig;
47
+ const rulesRaw = cfg.rules;
48
+ // Validate rules type up-front — even for empty configs — to keep errors
49
+ // visible at startup rather than silently returning null.
50
+ if (rulesRaw !== undefined && !Array.isArray(rulesRaw)) {
51
+ throw new Error(`mcp.acl.rules must be a list, got ${typeof rulesRaw}`);
52
+ }
53
+ const hasRules = Array.isArray(rulesRaw) && rulesRaw.length > 0;
54
+ const hasDefault = cfg.default_effect !== undefined;
55
+ if (!hasRules && !hasDefault) {
56
+ return null; // Empty config section — treat as no ACL
57
+ }
58
+ let apcore;
59
+ try {
60
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
61
+ apcore = (await import("apcore-js"));
62
+ }
63
+ catch (err) {
64
+ throw new Error(`Config Bus 'mcp.acl' requires apcore-js>=0.18 with ACL support: ${err.message}`);
65
+ }
66
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
67
+ const ACL = (apcore.ACL ?? apcore.default?.ACL);
68
+ if (!ACL) {
69
+ throw new Error("apcore-js does not export ACL");
70
+ }
71
+ const defaultEffect = (cfg.default_effect ?? "deny");
72
+ if (!ALLOWED_EFFECTS.has(defaultEffect)) {
73
+ throw new Error(`mcp.acl.default_effect must be 'allow' or 'deny', got '${defaultEffect}'`);
74
+ }
75
+ const rawRules = (rulesRaw ?? []);
76
+ const rules = [];
77
+ for (let idx = 0; idx < rawRules.length; idx += 1) {
78
+ const entry = rawRules[idx];
79
+ if (!entry || typeof entry !== "object" || Array.isArray(entry)) {
80
+ throw new Error(`mcp.acl.rules[${idx}] must be an object, got ${Array.isArray(entry) ? "array" : typeof entry}`);
81
+ }
82
+ const rec = entry;
83
+ const extra = Object.keys(rec).filter((k) => !ALLOWED_RULE_KEYS.has(k));
84
+ if (extra.length) {
85
+ throw new Error(`mcp.acl.rules[${idx}] got unexpected keys: ${extra.sort().join(", ")}`);
86
+ }
87
+ const callers = rec.callers;
88
+ const targets = rec.targets;
89
+ const effect = rec.effect;
90
+ if (!Array.isArray(callers) || callers.length === 0) {
91
+ throw new Error(`mcp.acl.rules[${idx}] 'callers' must be a non-empty list`);
92
+ }
93
+ if (!Array.isArray(targets) || targets.length === 0) {
94
+ throw new Error(`mcp.acl.rules[${idx}] 'targets' must be a non-empty list`);
95
+ }
96
+ if (typeof effect !== "string" || !ALLOWED_EFFECTS.has(effect)) {
97
+ throw new Error(`mcp.acl.rules[${idx}] 'effect' must be 'allow' or 'deny', got '${effect}'`);
98
+ }
99
+ const rule = {
100
+ callers: [...callers],
101
+ targets: [...targets],
102
+ effect: effect,
103
+ description: typeof rec.description === "string" ? rec.description : "",
104
+ };
105
+ if (rec.conditions !== undefined && rec.conditions !== null) {
106
+ if (typeof rec.conditions !== "object" || Array.isArray(rec.conditions)) {
107
+ throw new Error(`mcp.acl.rules[${idx}] 'conditions' must be an object or null`);
108
+ }
109
+ rule.conditions = rec.conditions;
110
+ }
111
+ rules.push(rule);
112
+ }
113
+ return new ACL(rules, defaultEffect);
114
+ }
115
+ //# sourceMappingURL=acl-builder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"acl-builder.js","sourceRoot":"","sources":["../src/acl-builder.ts"],"names":[],"mappings":"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"}
@@ -1 +1 @@
1
- {"version":3,"file":"annotations.d.ts","sourceRoot":"","sources":["../../src/adapters/annotations.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAczE,qBAAa,gBAAgB;IAC3B;;;;;;;;;OASG;IACH,gBAAgB,CAAC,WAAW,EAAE,iBAAiB,GAAG,IAAI,GAAG,kBAAkB;IAoB3E;;;;;;OAMG;IACH,mBAAmB,CAAC,WAAW,EAAE,iBAAiB,GAAG,IAAI,GAAG,MAAM;IAkElE;;;;OAIG;IACH,mBAAmB,CAAC,WAAW,EAAE,iBAAiB,GAAG,IAAI,GAAG,OAAO;CAOpE"}
1
+ {"version":3,"file":"annotations.d.ts","sourceRoot":"","sources":["../../src/adapters/annotations.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAkBzE,qBAAa,gBAAgB;IAC3B;;;;;;;;;OASG;IACH,gBAAgB,CAAC,WAAW,EAAE,iBAAiB,GAAG,IAAI,GAAG,kBAAkB;IAoB3E;;;;;;OAMG;IACH,mBAAmB,CAAC,WAAW,EAAE,iBAAiB,GAAG,IAAI,GAAG,MAAM;IAyFlE;;;;OAIG;IACH,mBAAmB,CAAC,WAAW,EAAE,iBAAiB,GAAG,IAAI,GAAG,OAAO;CAOpE"}
@@ -15,6 +15,10 @@ const DEFAULT_ANNOTATIONS = {
15
15
  streaming: false,
16
16
  cacheable: false,
17
17
  paginated: false,
18
+ // [AM-2] Numeric/string defaults for cache_ttl and pagination_style.
19
+ // Spec: default values omitted from suffix.
20
+ cacheTtl: 0,
21
+ paginationStyle: "cursor",
18
22
  };
19
23
  export class AnnotationMapper {
20
24
  /**
@@ -79,12 +83,29 @@ export class AnnotationMapper {
79
83
  parts.push(`streaming=${annotations.streaming}`);
80
84
  if ((annotations.cacheable ?? false) !== DEFAULT_ANNOTATIONS.cacheable)
81
85
  parts.push(`cacheable=${annotations.cacheable}`);
86
+ // [AM-2] Skip cache_ttl when equal to default (0). Spec: "Default
87
+ // values omitted from suffix". Pre-fix TS emitted any non-null
88
+ // value including the default, diverging from Python+Rust.
89
+ if (annotations.cacheTtl !== undefined &&
90
+ annotations.cacheTtl !== null &&
91
+ annotations.cacheTtl !== DEFAULT_ANNOTATIONS.cacheTtl)
92
+ parts.push(`cache_ttl=${annotations.cacheTtl}`);
93
+ if (annotations.cacheKeyFields !== undefined &&
94
+ annotations.cacheKeyFields !== null &&
95
+ annotations.cacheKeyFields.length > 0)
96
+ parts.push(`cache_key_fields=[${annotations.cacheKeyFields.join(",")}]`);
82
97
  if ((annotations.paginated ?? false) !== DEFAULT_ANNOTATIONS.paginated)
83
98
  parts.push(`paginated=${annotations.paginated}`);
84
- // Append mcp_-prefixed extra fields
99
+ // [AM-2] Skip pagination_style when equal to default ("cursor").
100
+ if (annotations.paginationStyle !== undefined &&
101
+ annotations.paginationStyle !== null &&
102
+ annotations.paginationStyle !== DEFAULT_ANNOTATIONS.paginationStyle)
103
+ parts.push(`pagination_style=${annotations.paginationStyle}`);
104
+ // Append mcp_-prefixed extra fields (sorted alphabetically for deterministic output,
105
+ // matching Python+Rust sort behavior). [D11-022]
85
106
  const extraLines = [];
86
107
  if (annotations.extra && typeof annotations.extra === "object") {
87
- for (const [key, value] of Object.entries(annotations.extra)) {
108
+ for (const [key, value] of Object.entries(annotations.extra).sort(([a], [b]) => a.localeCompare(b))) {
88
109
  if (key.startsWith("mcp_") && typeof value === "string") {
89
110
  const strippedKey = key.slice(4); // remove "mcp_" prefix
90
111
  extraLines.push(`${strippedKey}: ${value}`);