apcore-mcp 0.13.0 → 0.15.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 +190 -0
- package/README.md +246 -19
- package/dist/acl-builder.d.ts +43 -0
- package/dist/acl-builder.d.ts.map +1 -0
- package/dist/acl-builder.js +115 -0
- package/dist/acl-builder.js.map +1 -0
- package/dist/adapters/annotations.d.ts.map +1 -1
- package/dist/adapters/annotations.js +23 -2
- package/dist/adapters/annotations.js.map +1 -1
- package/dist/adapters/errors.d.ts +37 -0
- package/dist/adapters/errors.d.ts.map +1 -1
- package/dist/adapters/errors.js +213 -17
- package/dist/adapters/errors.js.map +1 -1
- package/dist/adapters/id-normalizer.d.ts +41 -0
- package/dist/adapters/id-normalizer.d.ts.map +1 -0
- package/dist/adapters/id-normalizer.js +56 -0
- package/dist/adapters/id-normalizer.js.map +1 -0
- package/dist/adapters/index.d.ts +2 -2
- package/dist/adapters/index.d.ts.map +1 -1
- package/dist/adapters/index.js +2 -2
- package/dist/adapters/index.js.map +1 -1
- package/dist/adapters/{mcpErrorFormatter.d.ts → mcp-error-formatter.d.ts} +1 -1
- package/dist/adapters/mcp-error-formatter.d.ts.map +1 -0
- package/dist/adapters/{mcpErrorFormatter.js → mcp-error-formatter.js} +1 -1
- package/dist/adapters/mcp-error-formatter.js.map +1 -0
- package/dist/adapters/schema.d.ts +32 -4
- package/dist/adapters/schema.d.ts.map +1 -1
- package/dist/adapters/schema.js +190 -14
- package/dist/adapters/schema.js.map +1 -1
- package/dist/apcore-mcp.d.ts +25 -3
- package/dist/apcore-mcp.d.ts.map +1 -1
- package/dist/apcore-mcp.js +8 -0
- package/dist/apcore-mcp.js.map +1 -1
- package/dist/auth/hooks.d.ts +1 -1
- package/dist/auth/hooks.d.ts.map +1 -1
- package/dist/auth/hooks.js +10 -3
- package/dist/auth/hooks.js.map +1 -1
- package/dist/auth/index.d.ts +7 -0
- package/dist/auth/index.d.ts.map +1 -1
- package/dist/auth/index.js +7 -0
- package/dist/auth/index.js.map +1 -1
- package/dist/auth/jwt.d.ts +1 -2
- package/dist/auth/jwt.d.ts.map +1 -1
- package/dist/auth/jwt.js +22 -11
- package/dist/auth/jwt.js.map +1 -1
- package/dist/auth/types.d.ts +6 -3
- package/dist/auth/types.d.ts.map +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +21 -1
- package/dist/cli.js.map +1 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +6 -0
- package/dist/config.js.map +1 -1
- package/dist/constants.d.ts +37 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +43 -0
- package/dist/constants.js.map +1 -0
- package/dist/converters/openai.d.ts +22 -0
- package/dist/converters/openai.d.ts.map +1 -1
- package/dist/converters/openai.js +128 -8
- package/dist/converters/openai.js.map +1 -1
- package/dist/index.d.ts +62 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +329 -108
- package/dist/index.js.map +1 -1
- package/dist/markdown.d.ts +54 -0
- package/dist/markdown.d.ts.map +1 -0
- package/dist/markdown.js +125 -0
- package/dist/markdown.js.map +1 -0
- package/dist/middleware-builder.d.ts +41 -0
- package/dist/middleware-builder.d.ts.map +1 -0
- package/dist/middleware-builder.js +129 -0
- package/dist/middleware-builder.js.map +1 -0
- package/dist/server/async-task-bridge.d.ts +228 -0
- package/dist/server/async-task-bridge.d.ts.map +1 -0
- package/dist/server/async-task-bridge.js +579 -0
- package/dist/server/async-task-bridge.js.map +1 -0
- package/dist/server/context.d.ts +17 -2
- package/dist/server/context.d.ts.map +1 -1
- package/dist/server/context.js +29 -6
- package/dist/server/context.js.map +1 -1
- package/dist/server/factory.d.ts +57 -3
- package/dist/server/factory.d.ts.map +1 -1
- package/dist/server/factory.js +179 -9
- package/dist/server/factory.js.map +1 -1
- package/dist/server/listener.d.ts +3 -0
- package/dist/server/listener.d.ts.map +1 -1
- package/dist/server/listener.js +13 -2
- package/dist/server/listener.js.map +1 -1
- package/dist/server/observability.d.ts +51 -0
- package/dist/server/observability.d.ts.map +1 -0
- package/dist/server/observability.js +96 -0
- package/dist/server/observability.js.map +1 -0
- package/dist/server/router.d.ts +103 -3
- package/dist/server/router.d.ts.map +1 -1
- package/dist/server/router.js +289 -25
- package/dist/server/router.js.map +1 -1
- package/dist/server/trace-context.d.ts +40 -0
- package/dist/server/trace-context.d.ts.map +1 -0
- package/dist/server/trace-context.js +67 -0
- package/dist/server/trace-context.js.map +1 -0
- package/dist/server/transport.d.ts +47 -1
- package/dist/server/transport.d.ts.map +1 -1
- package/dist/server/transport.js +147 -4
- package/dist/server/transport.js.map +1 -1
- package/dist/types.d.ts +16 -5
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +12 -0
- package/dist/types.js.map +1 -1
- package/package.json +11 -8
- package/dist/adapters/idNormalizer.d.ts +0 -22
- package/dist/adapters/idNormalizer.d.ts.map +0 -1
- package/dist/adapters/idNormalizer.js +0 -30
- package/dist/adapters/idNormalizer.js.map +0 -1
- package/dist/adapters/mcpErrorFormatter.d.ts.map +0 -1
- package/dist/adapters/mcpErrorFormatter.js.map +0 -1
- package/dist/server/index.d.ts +0 -11
- package/dist/server/index.d.ts.map +0 -1
- package/dist/server/index.js +0 -8
- package/dist/server/index.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
|
@@ -12,6 +12,8 @@ Converts apcore module registries into [Model Context Protocol (MCP)](https://mo
|
|
|
12
12
|
|
|
13
13
|
- **MCP Server** — Expose apcore modules as MCP tools over stdio, Streamable HTTP, or SSE
|
|
14
14
|
- **OpenAI Tools** — Convert modules to OpenAI function calling format with strict mode support
|
|
15
|
+
- **Markdown tool descriptions** (`richDescription: true`, v0.15+) — render `Tool.description` and OpenAI `function.description` as canonical apcore-toolkit Markdown so LLMs get more decision-relevant signal per token. Requires `apcore-toolkit` (declared as `optionalDependencies`) and `await MCPServerFactory.prepare()` at startup.
|
|
16
|
+
- **Module preview meta-tool** (`__apcore_module_preview`, v0.15+) — drives `executor.validate()` to predict state changes WITHOUT executing the module (apcore PROTOCOL_SPEC §5.6). Returns `{valid, requires_approval, predicted_changes, checks}` so AI orchestrators can ask "what would change?" before invoking.
|
|
15
17
|
- **Schema Conversion** — Inline `$defs`/`$ref` from Pydantic-generated JSON Schema
|
|
16
18
|
- **Annotation Mapping** — Map module annotations to MCP hints and OpenAI description suffixes
|
|
17
19
|
- **Approval Mechanism** — Built-in elicitation-based approval flow for sensitive tool executions
|
|
@@ -30,7 +32,8 @@ For full documentation, including Quick Start guides for both Python and TypeScr
|
|
|
30
32
|
## Requirements
|
|
31
33
|
|
|
32
34
|
- Node.js >= 18.0.0
|
|
33
|
-
- `apcore-js >= 0.
|
|
35
|
+
- `apcore-js >= 0.21.1`
|
|
36
|
+
- Optional: `apcore-toolkit >= 0.6.1` for Markdown-rendered tool descriptions (declared under `optionalDependencies`).
|
|
34
37
|
|
|
35
38
|
## Installation
|
|
36
39
|
|
|
@@ -96,8 +99,10 @@ npx apcore-mcp --extensions-dir ./extensions --transport sse --port 8000
|
|
|
96
99
|
| `--jwt-algorithm` | `HS256` | JWT algorithm |
|
|
97
100
|
| `--jwt-audience` | — | Expected JWT audience claim |
|
|
98
101
|
| `--jwt-issuer` | — | Expected JWT issuer claim |
|
|
99
|
-
| `--jwt-require-auth` | `true` | Require auth (use `--
|
|
100
|
-
| `--
|
|
102
|
+
| `--jwt-require-auth` | `true` | Require auth (use `--jwt-permissive` to override and allow unauthenticated requests) |
|
|
103
|
+
| `--jwt-permissive` | `false` | Permissive mode: allow unauthenticated requests (overrides `--jwt-require-auth`) |
|
|
104
|
+
| `--exempt-paths` | `/health,/metrics,/usage` | Comma-separated paths exempt from auth |
|
|
105
|
+
| `--output-format` | `json` | Built-in output format: `json`, `csv`, or `jsonl` |
|
|
101
106
|
|
|
102
107
|
JWT key resolution priority: `--jwt-key-file` > `--jwt-secret` > `APCORE_JWT_SECRET` environment variable.
|
|
103
108
|
|
|
@@ -161,6 +166,79 @@ Connect any MCP client to `http://your-host:9000/mcp`.
|
|
|
161
166
|
|
|
162
167
|
## API Reference
|
|
163
168
|
|
|
169
|
+
### Programmatic API – `APCoreMCP` class
|
|
170
|
+
|
|
171
|
+
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.
|
|
172
|
+
|
|
173
|
+
```typescript
|
|
174
|
+
import { APCoreMCP } from "apcore-mcp";
|
|
175
|
+
|
|
176
|
+
// 1. Point at an extensions directory (lazy discovery on first use)
|
|
177
|
+
const mcp = new APCoreMCP("./extensions", {
|
|
178
|
+
name: "my-server",
|
|
179
|
+
tags: ["public"],
|
|
180
|
+
observability: true,
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
// 2. Launch as MCP server (blocks until shutdown)
|
|
184
|
+
await mcp.serve({ transport: "streamable-http", port: 8000, explorer: true });
|
|
185
|
+
|
|
186
|
+
// 3. Or export OpenAI tool definitions
|
|
187
|
+
const tools = mcp.toOpenaiTools({ strict: true });
|
|
188
|
+
|
|
189
|
+
// 4. Or embed into an existing HTTP server
|
|
190
|
+
const app = await mcp.asyncServe({ explorer: true });
|
|
191
|
+
// app.handler is a Node.js request handler; call app.close() on shutdown
|
|
192
|
+
|
|
193
|
+
// 5. Or pass an existing Registry / Executor
|
|
194
|
+
import { Registry } from "apcore-js";
|
|
195
|
+
const registry = new Registry({ extensionsDir: "./extensions" });
|
|
196
|
+
await registry.discover();
|
|
197
|
+
const mcp2 = new APCoreMCP(registry, { name: "my-server", tags: ["public"] });
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
**Constructor**
|
|
201
|
+
|
|
202
|
+
```typescript
|
|
203
|
+
new APCoreMCP(
|
|
204
|
+
extensionsDirOrBackend: string | Registry | Executor,
|
|
205
|
+
options?: APCoreMCPOptions,
|
|
206
|
+
);
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
The first argument is either a path to an apcore extensions directory (discovery is deferred to first use) or an existing `Registry` / `Executor` instance.
|
|
210
|
+
|
|
211
|
+
**`APCoreMCPOptions` fields**
|
|
212
|
+
|
|
213
|
+
- `name` — MCP server name. Default: `"apcore-mcp"`
|
|
214
|
+
- `version` — MCP server version. Default: package version
|
|
215
|
+
- `tags` — Filter modules by tag list
|
|
216
|
+
- `prefix` — Filter modules by ID prefix
|
|
217
|
+
- `logLevel` — Minimum log level (`DEBUG` | `INFO` | `WARNING` | `ERROR` | `CRITICAL`)
|
|
218
|
+
- `validateInputs` — Validate inputs against schemas. Default: `false`
|
|
219
|
+
- `metricsCollector` — `MetricsExporter` or `true` to auto-instantiate
|
|
220
|
+
- `observability` — Enable the full metrics + usage observability stack
|
|
221
|
+
- `async` — `boolean | { enabled?, maxConcurrent?, maxTasks? }` for the Async Task Bridge (F-043)
|
|
222
|
+
- `authenticator` — Optional `Authenticator` (HTTP transports only)
|
|
223
|
+
- `requireAuth` — If `true` (default), reject unauthenticated requests with 401
|
|
224
|
+
- `exemptPaths` — Paths exempt from authentication
|
|
225
|
+
- `approvalHandler` — Optional approval handler passed to the Executor
|
|
226
|
+
- `outputFormatter` — Custom function to format tool execution results
|
|
227
|
+
- `middleware` — Array of apcore `Middleware` installed via `executor.use()`
|
|
228
|
+
- `acl` — Optional apcore `ACL` instance installed via `executor.setAcl()`
|
|
229
|
+
|
|
230
|
+
**Properties**
|
|
231
|
+
|
|
232
|
+
- `.registry` — The underlying apcore `Registry` (resolved on first access)
|
|
233
|
+
- `.executor` — The underlying apcore `Executor` (populated after `serve()` / `asyncServe()`)
|
|
234
|
+
- `.tools` — List of discovered module IDs that will be exposed as tools (honours `tags` / `prefix`)
|
|
235
|
+
|
|
236
|
+
**Methods**
|
|
237
|
+
|
|
238
|
+
- `.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.
|
|
239
|
+
- `.asyncServe(options?)` — Build an embeddable Node.js HTTP request handler. Accepts `APCoreMCPAsyncServeOptions`: `explorer`, `explorerPrefix`, `allowExecute`, `explorerTitle`, `explorerProjectName`, `explorerProjectUrl`, `endpoint`. Returns `{ handler, close }`.
|
|
240
|
+
- `.toOpenaiTools(options?)` — Export modules as OpenAI-compatible tool definitions. Accepts `ToOpenaiToolsOptions`: `embedAnnotations`, `strict`. `tags` / `prefix` are inherited from the constructor.
|
|
241
|
+
|
|
164
242
|
### `serve(registryOrExecutor, options?)`
|
|
165
243
|
|
|
166
244
|
Launch an MCP Server that exposes all apcore modules as tools.
|
|
@@ -169,41 +247,112 @@ Launch an MCP Server that exposes all apcore modules as tools.
|
|
|
169
247
|
function serve(
|
|
170
248
|
registryOrExecutor: Registry | Executor,
|
|
171
249
|
options?: {
|
|
250
|
+
// Transport
|
|
172
251
|
transport?: "stdio" | "streamable-http" | "sse";
|
|
173
252
|
host?: string;
|
|
174
253
|
port?: number;
|
|
254
|
+
// Identity
|
|
175
255
|
name?: string;
|
|
176
256
|
version?: string;
|
|
177
|
-
|
|
178
|
-
|
|
257
|
+
// Lifecycle
|
|
258
|
+
onStartup?: () => void | Promise<void>;
|
|
259
|
+
onShutdown?: () => void | Promise<void>;
|
|
260
|
+
// Module filtering / discovery
|
|
179
261
|
tags?: string[] | null;
|
|
180
262
|
prefix?: string | null;
|
|
263
|
+
dynamic?: boolean;
|
|
264
|
+
validateInputs?: boolean;
|
|
181
265
|
logLevel?: "DEBUG" | "INFO" | "WARNING" | "ERROR" | "CRITICAL";
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
266
|
+
// Async Task Bridge (F-043)
|
|
267
|
+
async?: boolean | { enabled?: boolean; maxConcurrent?: number; maxTasks?: number };
|
|
268
|
+
// Executor wiring
|
|
269
|
+
middleware?: unknown[];
|
|
270
|
+
acl?: unknown;
|
|
271
|
+
approvalHandler?: unknown;
|
|
272
|
+
strategy?: string;
|
|
273
|
+
// Observability (F-044)
|
|
274
|
+
metricsCollector?: MetricsExporter | boolean;
|
|
275
|
+
observability?: ObservabilityFlag;
|
|
276
|
+
trace?: boolean;
|
|
277
|
+
// Output handling
|
|
278
|
+
outputFormatter?: (result: Record<string, unknown>) => string;
|
|
279
|
+
redactOutput?: boolean;
|
|
280
|
+
// Auth (HTTP transports only)
|
|
281
|
+
authenticator?: Authenticator;
|
|
282
|
+
requireAuth?: boolean;
|
|
283
|
+
exemptPaths?: string[];
|
|
284
|
+
// Tool Explorer UI
|
|
185
285
|
explorer?: boolean;
|
|
186
286
|
explorerPrefix?: string;
|
|
187
287
|
allowExecute?: boolean;
|
|
188
|
-
authenticator?: Authenticator;
|
|
189
|
-
exemptPaths?: string[];
|
|
190
|
-
approvalHandler?: unknown;
|
|
191
288
|
explorerTitle?: string;
|
|
192
289
|
explorerProjectName?: string;
|
|
193
290
|
explorerProjectUrl?: string;
|
|
194
|
-
|
|
195
|
-
|
|
291
|
+
// Adapter overrides (advanced — Extension Bridge)
|
|
292
|
+
schemaConverter?: SchemaConverter;
|
|
293
|
+
annotationMapper?: AnnotationMapper;
|
|
294
|
+
errorMapper?: ErrorMapper;
|
|
196
295
|
}
|
|
197
296
|
): Promise<void>;
|
|
198
297
|
```
|
|
199
298
|
|
|
200
|
-
**
|
|
299
|
+
**Options reference:**
|
|
300
|
+
|
|
301
|
+
*Transport*
|
|
302
|
+
- `transport` — `"stdio"` (default), `"streamable-http"`, or `"sse"`
|
|
303
|
+
- `host` — Host address for HTTP-based transports. Default: `"127.0.0.1"`
|
|
304
|
+
- `port` — Port for HTTP-based transports. Default: `8000`
|
|
305
|
+
|
|
306
|
+
*Identity*
|
|
307
|
+
- `name` — MCP server name. Default: `"apcore-mcp"`
|
|
308
|
+
- `version` — MCP server version. Default: package version
|
|
309
|
+
|
|
310
|
+
*Lifecycle*
|
|
311
|
+
- `onStartup` — Async callback invoked before the server starts
|
|
312
|
+
- `onShutdown` — Async callback invoked after the server stops (or on error)
|
|
313
|
+
|
|
314
|
+
*Module filtering / discovery*
|
|
315
|
+
- `tags` — Filter modules by tag list. Default: `null` (no filtering)
|
|
316
|
+
- `prefix` — Filter modules by ID prefix. Default: `null` (no filtering)
|
|
317
|
+
- `dynamic` — Enable dynamic tool registration via `RegistryListener`. Default: `false`
|
|
318
|
+
- `validateInputs` — Validate inputs against schemas before dispatch. Default: `false`
|
|
319
|
+
- `logLevel` — Minimum log level. Suppresses console methods below this level
|
|
201
320
|
|
|
321
|
+
*Async Task Bridge (F-043)*
|
|
322
|
+
- `async` — Enable the AsyncTaskBridge and `__apcore_task_*` meta-tools. Pass `false` to disable, or `{ maxConcurrent, maxTasks }` for fine-grained tuning. Default: `true`
|
|
323
|
+
|
|
324
|
+
*Executor wiring*
|
|
325
|
+
- `middleware` — Array of apcore `Middleware` instances installed via `executor.use()`. Appended to any middleware declared under Config Bus key `mcp.middleware`
|
|
326
|
+
- `acl` — Optional apcore `ACL` instance installed via `executor.setAcl()`. Caller-supplied ACL takes precedence over `mcp.acl` Config Bus entry
|
|
327
|
+
- `approvalHandler` — Optional approval handler passed to the Executor (e.g. `ElicitationApprovalHandler`)
|
|
328
|
+
- `strategy` — Execution strategy name passed to the Executor (e.g. `"standard"`, `"internal"`)
|
|
329
|
+
|
|
330
|
+
*Observability (F-044)*
|
|
331
|
+
- `metricsCollector` — `MetricsExporter` instance, or `true` to auto-instantiate apcore-js's `MetricsCollector` and install `MetricsMiddleware`
|
|
332
|
+
- `observability` — Enable the full observability stack (metrics + usage middleware) and expose `/metrics` + `/usage` endpoints
|
|
333
|
+
- `trace` — When `true`, enables pipeline trace via `callWithTrace()`. Adds `_meta.trace` to non-streaming tool responses. Default: `false`
|
|
334
|
+
|
|
335
|
+
*Output handling*
|
|
336
|
+
- `outputFormatter` — Custom function to format tool execution results. When undefined, results are serialized with `JSON.stringify(result)`
|
|
337
|
+
- `redactOutput` — When `true` (default), redact sensitive fields from tool output via apcore's `redactSensitive()` before formatting
|
|
338
|
+
|
|
339
|
+
*Auth (HTTP transports only)*
|
|
340
|
+
- `authenticator` — `Authenticator` instance for request authentication
|
|
341
|
+
- `requireAuth` — If `true` (default), unauthenticated requests are rejected with 401. Set to `false` for permissive mode
|
|
342
|
+
- `exemptPaths` — Paths exempt from authentication. Default: `["/health", "/metrics"]`
|
|
343
|
+
|
|
344
|
+
*Tool Explorer UI*
|
|
345
|
+
- `explorer` — Enable the browser-based Tool Explorer UI (HTTP only). Default: `false`
|
|
346
|
+
- `explorerPrefix` — URL prefix for the explorer. Default: `"/explorer"`
|
|
347
|
+
- `allowExecute` — Allow tool execution from the explorer UI. Default: `false`
|
|
202
348
|
- `explorerTitle` — Custom title for the Tool Explorer UI page
|
|
203
349
|
- `explorerProjectName` — Project name shown in the explorer UI footer
|
|
204
350
|
- `explorerProjectUrl` — Project URL shown in the explorer UI footer
|
|
205
|
-
|
|
206
|
-
|
|
351
|
+
|
|
352
|
+
*Adapter overrides (advanced — Extension Bridge, F-042)*
|
|
353
|
+
- `schemaConverter` — Override the default `SchemaConverter` (custom JSON Schema strictness/dialect)
|
|
354
|
+
- `annotationMapper` — Override the default `AnnotationMapper` (custom annotation wire format)
|
|
355
|
+
- `errorMapper` — Override the default `ErrorMapper` consumed by `ExecutionRouter`
|
|
207
356
|
|
|
208
357
|
### `asyncServe(registryOrExecutor, options?)`
|
|
209
358
|
|
|
@@ -228,6 +377,22 @@ await close();
|
|
|
228
377
|
|
|
229
378
|
Accepts the same options as `serve()` except `transport`, `host`, `port`, `onStartup`, and `onShutdown`.
|
|
230
379
|
|
|
380
|
+
### Output Formatting
|
|
381
|
+
|
|
382
|
+
By default, tool execution results are serialized as JSON (`JSON.stringify`). You can customize this by passing an `outputFormat` name or a custom `outputFormatter` function.
|
|
383
|
+
|
|
384
|
+
**Built-in formats** (requires `apcore-toolkit` 0.7.0+):
|
|
385
|
+
|
|
386
|
+
```typescript
|
|
387
|
+
// Via CLI
|
|
388
|
+
// npx apcore-mcp --extensions-dir ./extensions --output-format csv
|
|
389
|
+
|
|
390
|
+
// Via API
|
|
391
|
+
const mcp = new APCoreMCP("./extensions", { outputFormat: "csv" });
|
|
392
|
+
```
|
|
393
|
+
|
|
394
|
+
Supports `json`, `csv`, and `jsonl`. Non-tabular data gracefully falls back to JSON.
|
|
395
|
+
|
|
231
396
|
### Tool Explorer
|
|
232
397
|
|
|
233
398
|
When `explorer: true` is passed to `serve()`, a browser-based Tool Explorer UI is mounted on HTTP transports. It provides an interactive page for browsing tool schemas and testing tool execution.
|
|
@@ -265,7 +430,7 @@ apcore-mcp supports JWT Bearer token authentication for HTTP-based transports.
|
|
|
265
430
|
import { serve, JWTAuthenticator } from "apcore-mcp";
|
|
266
431
|
|
|
267
432
|
const authenticator = new JWTAuthenticator({
|
|
268
|
-
|
|
433
|
+
key: "your-secret-key",
|
|
269
434
|
algorithms: ["HS256"],
|
|
270
435
|
audience: "my-app",
|
|
271
436
|
issuer: "auth-service",
|
|
@@ -299,8 +464,9 @@ await serve(executor, {
|
|
|
299
464
|
| `--jwt-algorithm` | `HS256` | JWT algorithm |
|
|
300
465
|
| `--jwt-audience` | — | Expected audience claim |
|
|
301
466
|
| `--jwt-issuer` | — | Expected issuer claim |
|
|
302
|
-
| `--jwt-require-auth` | `true` | Require auth. Use `--
|
|
303
|
-
| `--
|
|
467
|
+
| `--jwt-require-auth` | `true` | Require auth. Use `--jwt-permissive` to allow unauthenticated requests |
|
|
468
|
+
| `--jwt-permissive` | `false` | Overrides `--jwt-require-auth` and allows unauthenticated requests |
|
|
469
|
+
| `--exempt-paths` | `/health,/metrics,/usage` | Comma-separated paths exempt from auth |
|
|
304
470
|
|
|
305
471
|
JWT key resolution priority: `--jwt-key-file` > `--jwt-secret` > `APCORE_JWT_SECRET` environment variable.
|
|
306
472
|
|
|
@@ -317,6 +483,67 @@ curl -X POST http://localhost:8000/mcp \
|
|
|
317
483
|
curl http://localhost:8000/health
|
|
318
484
|
```
|
|
319
485
|
|
|
486
|
+
#### Per-request identity helpers
|
|
487
|
+
|
|
488
|
+
When auth is enabled, each request runs inside an `AsyncLocalStorage`
|
|
489
|
+
context whose value is the verified `Identity`. Modules and middleware
|
|
490
|
+
read it with `getCurrentIdentity()` — no need to thread it through every
|
|
491
|
+
function.
|
|
492
|
+
|
|
493
|
+
```typescript
|
|
494
|
+
import { getCurrentIdentity, identityStorage } from "apcore-mcp";
|
|
495
|
+
import type { Identity } from "apcore-mcp";
|
|
496
|
+
|
|
497
|
+
// Inside a module / middleware called from a tool invocation:
|
|
498
|
+
const id: Identity | null = getCurrentIdentity();
|
|
499
|
+
if (id) {
|
|
500
|
+
// id.id (user id), id.type ("user" | "service" | ...), id.roles, id.attrs
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
// Lower-level access (e.g. for running custom code inside a known identity):
|
|
504
|
+
identityStorage.run(myIdentity, async () => {
|
|
505
|
+
/* code that calls getCurrentIdentity() */
|
|
506
|
+
});
|
|
507
|
+
```
|
|
508
|
+
|
|
509
|
+
Python parity: `apcore_mcp.get_current_identity()` / `auth_identity_var`.
|
|
510
|
+
Rust parity: `apcore_mcp::AUTH_IDENTITY` task-local.
|
|
511
|
+
|
|
512
|
+
#### Mounting the Explorer behind your own server
|
|
513
|
+
|
|
514
|
+
If you embed the bridge via `asyncServe(...)` instead of `serve(...)`,
|
|
515
|
+
gate the explorer routes behind an auth hook with
|
|
516
|
+
`buildExplorerAuthHook(authenticator)`:
|
|
517
|
+
|
|
518
|
+
```typescript
|
|
519
|
+
import { buildExplorerAuthHook } from "apcore-mcp";
|
|
520
|
+
import { JWTAuthenticator } from "apcore-mcp";
|
|
521
|
+
|
|
522
|
+
const auth = new JWTAuthenticator({ key: process.env.JWT_SECRET! });
|
|
523
|
+
const guard = buildExplorerAuthHook(auth);
|
|
524
|
+
|
|
525
|
+
// `guard` is a `(req, next) => Promise<Response>` hook accepted by
|
|
526
|
+
// mcp-embedded-ui's Hono router. Returns a 401 response when the
|
|
527
|
+
// Authorization header is missing or invalid; otherwise runs `next()`
|
|
528
|
+
// inside `identityStorage.run(identity, ...)` so the explorer's
|
|
529
|
+
// downstream handlers see the authenticated identity.
|
|
530
|
+
```
|
|
531
|
+
|
|
532
|
+
#### Custom observability stack (advanced)
|
|
533
|
+
|
|
534
|
+
For callers who don't want the `serve(... observability: true)` shorthand,
|
|
535
|
+
`installObservability` wires the metrics + usage middleware onto an
|
|
536
|
+
existing `Executor` directly. It is what `serve()` calls internally.
|
|
537
|
+
|
|
538
|
+
```typescript
|
|
539
|
+
import { installObservability } from "apcore-mcp";
|
|
540
|
+
import type { ObservabilityFlag } from "apcore-mcp";
|
|
541
|
+
|
|
542
|
+
const stack = await installObservability(executor, /* metricsCollector */ null, true satisfies ObservabilityFlag);
|
|
543
|
+
// stack.metricsCollector / stack.usageCollector are then exposed on
|
|
544
|
+
// the `/metrics` and `/usage` endpoints by your own HTTP wiring.
|
|
545
|
+
```
|
|
546
|
+
|
|
320
547
|
### `toOpenaiTools(registryOrExecutor, options?)`
|
|
321
548
|
|
|
322
549
|
Export apcore modules as OpenAI-compatible tool definitions.
|
|
@@ -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"}
|