hono-apcore 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.
Files changed (139) hide show
  1. package/LICENSE +190 -0
  2. package/README.md +426 -0
  3. package/dist/a2a/apcore-a2a.service.d.ts +44 -0
  4. package/dist/a2a/apcore-a2a.service.d.ts.map +1 -0
  5. package/dist/a2a/apcore-a2a.service.js +82 -0
  6. package/dist/a2a/apcore-a2a.service.js.map +1 -0
  7. package/dist/a2a/index.d.ts +2 -0
  8. package/dist/a2a/index.d.ts.map +1 -0
  9. package/dist/a2a/index.js +2 -0
  10. package/dist/a2a/index.js.map +1 -0
  11. package/dist/bridge/binding-loader.d.ts +45 -0
  12. package/dist/bridge/binding-loader.d.ts.map +1 -0
  13. package/dist/bridge/binding-loader.js +84 -0
  14. package/dist/bridge/binding-loader.js.map +1 -0
  15. package/dist/bridge/index.d.ts +3 -0
  16. package/dist/bridge/index.d.ts.map +1 -0
  17. package/dist/bridge/index.js +2 -0
  18. package/dist/bridge/index.js.map +1 -0
  19. package/dist/cli/apcore-cli.service.d.ts +50 -0
  20. package/dist/cli/apcore-cli.service.d.ts.map +1 -0
  21. package/dist/cli/apcore-cli.service.js +76 -0
  22. package/dist/cli/apcore-cli.service.js.map +1 -0
  23. package/dist/cli/index.d.ts +2 -0
  24. package/dist/cli/index.d.ts.map +1 -0
  25. package/dist/cli/index.js +2 -0
  26. package/dist/cli/index.js.map +1 -0
  27. package/dist/cli.d.ts +4 -0
  28. package/dist/cli.d.ts.map +1 -0
  29. package/dist/cli.js +247 -0
  30. package/dist/cli.js.map +1 -0
  31. package/dist/config.d.ts +55 -0
  32. package/dist/config.d.ts.map +1 -0
  33. package/dist/config.js +86 -0
  34. package/dist/config.js.map +1 -0
  35. package/dist/constants.d.ts +27 -0
  36. package/dist/constants.d.ts.map +1 -0
  37. package/dist/constants.js +27 -0
  38. package/dist/constants.js.map +1 -0
  39. package/dist/context/hono-context.factory.d.ts +61 -0
  40. package/dist/context/hono-context.factory.d.ts.map +1 -0
  41. package/dist/context/hono-context.factory.js +117 -0
  42. package/dist/context/hono-context.factory.js.map +1 -0
  43. package/dist/context/index.d.ts +3 -0
  44. package/dist/context/index.d.ts.map +1 -0
  45. package/dist/context/index.js +2 -0
  46. package/dist/context/index.js.map +1 -0
  47. package/dist/core/apcore.d.ts +135 -0
  48. package/dist/core/apcore.d.ts.map +1 -0
  49. package/dist/core/apcore.js +257 -0
  50. package/dist/core/apcore.js.map +1 -0
  51. package/dist/core/executor.d.ts +32 -0
  52. package/dist/core/executor.d.ts.map +1 -0
  53. package/dist/core/executor.js +41 -0
  54. package/dist/core/executor.js.map +1 -0
  55. package/dist/core/middleware.d.ts +61 -0
  56. package/dist/core/middleware.d.ts.map +1 -0
  57. package/dist/core/middleware.js +51 -0
  58. package/dist/core/middleware.js.map +1 -0
  59. package/dist/core/registry.d.ts +79 -0
  60. package/dist/core/registry.d.ts.map +1 -0
  61. package/dist/core/registry.js +218 -0
  62. package/dist/core/registry.js.map +1 -0
  63. package/dist/index.d.ts +33 -0
  64. package/dist/index.d.ts.map +1 -0
  65. package/dist/index.js +71 -0
  66. package/dist/index.js.map +1 -0
  67. package/dist/mcp/apcore-mcp.service.d.ts +83 -0
  68. package/dist/mcp/apcore-mcp.service.d.ts.map +1 -0
  69. package/dist/mcp/apcore-mcp.service.js +189 -0
  70. package/dist/mcp/apcore-mcp.service.js.map +1 -0
  71. package/dist/mcp/index.d.ts +5 -0
  72. package/dist/mcp/index.d.ts.map +1 -0
  73. package/dist/mcp/index.js +3 -0
  74. package/dist/mcp/index.js.map +1 -0
  75. package/dist/mcp/mount.d.ts +51 -0
  76. package/dist/mcp/mount.d.ts.map +1 -0
  77. package/dist/mcp/mount.js +95 -0
  78. package/dist/mcp/mount.js.map +1 -0
  79. package/dist/output/index.d.ts +3 -0
  80. package/dist/output/index.d.ts.map +1 -0
  81. package/dist/output/index.js +2 -0
  82. package/dist/output/index.js.map +1 -0
  83. package/dist/output/yaml-writer.d.ts +31 -0
  84. package/dist/output/yaml-writer.d.ts.map +1 -0
  85. package/dist/output/yaml-writer.js +49 -0
  86. package/dist/output/yaml-writer.js.map +1 -0
  87. package/dist/scanners/hono-route-scanner.d.ts +60 -0
  88. package/dist/scanners/hono-route-scanner.d.ts.map +1 -0
  89. package/dist/scanners/hono-route-scanner.js +217 -0
  90. package/dist/scanners/hono-route-scanner.js.map +1 -0
  91. package/dist/scanners/index.d.ts +3 -0
  92. package/dist/scanners/index.d.ts.map +1 -0
  93. package/dist/scanners/index.js +2 -0
  94. package/dist/scanners/index.js.map +1 -0
  95. package/dist/schema/adapters/json-schema.adapter.d.ts +23 -0
  96. package/dist/schema/adapters/json-schema.adapter.d.ts.map +1 -0
  97. package/dist/schema/adapters/json-schema.adapter.js +40 -0
  98. package/dist/schema/adapters/json-schema.adapter.js.map +1 -0
  99. package/dist/schema/adapters/schema-adapter.interface.d.ts +24 -0
  100. package/dist/schema/adapters/schema-adapter.interface.d.ts.map +1 -0
  101. package/dist/schema/adapters/schema-adapter.interface.js +2 -0
  102. package/dist/schema/adapters/schema-adapter.interface.js.map +1 -0
  103. package/dist/schema/adapters/typebox.adapter.d.ts +26 -0
  104. package/dist/schema/adapters/typebox.adapter.d.ts.map +1 -0
  105. package/dist/schema/adapters/typebox.adapter.js +39 -0
  106. package/dist/schema/adapters/typebox.adapter.js.map +1 -0
  107. package/dist/schema/adapters/zod.adapter.d.ts +17 -0
  108. package/dist/schema/adapters/zod.adapter.d.ts.map +1 -0
  109. package/dist/schema/adapters/zod.adapter.js +372 -0
  110. package/dist/schema/adapters/zod.adapter.js.map +1 -0
  111. package/dist/schema/index.d.ts +6 -0
  112. package/dist/schema/index.d.ts.map +1 -0
  113. package/dist/schema/index.js +5 -0
  114. package/dist/schema/index.js.map +1 -0
  115. package/dist/schema/schema-extractor.d.ts +51 -0
  116. package/dist/schema/schema-extractor.d.ts.map +1 -0
  117. package/dist/schema/schema-extractor.js +89 -0
  118. package/dist/schema/schema-extractor.js.map +1 -0
  119. package/dist/tools/define-tool.d.ts +68 -0
  120. package/dist/tools/define-tool.d.ts.map +1 -0
  121. package/dist/tools/define-tool.js +122 -0
  122. package/dist/tools/define-tool.js.map +1 -0
  123. package/dist/tools/index.d.ts +3 -0
  124. package/dist/tools/index.d.ts.map +1 -0
  125. package/dist/tools/index.js +2 -0
  126. package/dist/tools/index.js.map +1 -0
  127. package/dist/types.d.ts +246 -0
  128. package/dist/types.d.ts.map +1 -0
  129. package/dist/types.js +2 -0
  130. package/dist/types.js.map +1 -0
  131. package/dist/utils/id-generator.d.ts +52 -0
  132. package/dist/utils/id-generator.d.ts.map +1 -0
  133. package/dist/utils/id-generator.js +87 -0
  134. package/dist/utils/id-generator.js.map +1 -0
  135. package/dist/utils/module-factory.d.ts +34 -0
  136. package/dist/utils/module-factory.d.ts.map +1 -0
  137. package/dist/utils/module-factory.js +59 -0
  138. package/dist/utils/module-factory.js.map +1 -0
  139. package/package.json +109 -0
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 ADDED
@@ -0,0 +1,426 @@
1
+ # hono-apcore
2
+
3
+ Hono adapter for the [apcore](https://github.com/aiperceivable/apcore-typescript)
4
+ AI-Perceivable module ecosystem. Turn a Hono app into
5
+ [MCP](https://modelcontextprotocol.io/) tools and OpenAI-compatible function
6
+ definitions — either by declaring tools explicitly, or by scanning the routes
7
+ you already have.
8
+
9
+ ## Features
10
+
11
+ - **Two ways in** — declare tools with `defineTool()` / `defineToolset()`, or scan your existing routes with zero code changes
12
+ - **Route replay** — a scanned route becomes a module that calls back through `app.request()`, so middleware, validators, and error handlers all still run
13
+ - **One port** — `mountMcp()` serves the MCP endpoint, the Tool Explorer, and `/health` from the same Hono app
14
+ - **Annotation inference** — `GET` → readonly + cacheable, `PUT` → idempotent, `DELETE` → destructive (RFC 9110 safe-method semantics)
15
+ - **Multi-schema** — TypeBox, Zod 3, Zod 4, and plain JSON Schema, auto-detected through a priority chain
16
+ - **Context, ACL, and identity** — the `apcore()` middleware builds a per-request apcore `Context` with W3C trace propagation, so ACL rules govern your routes too
17
+ - **Runtime-agnostic core** — `apcore-mcp`, `apcore-cli`, and `apcore-a2a` are optional peers loaded lazily, so importing `hono-apcore` never drags `node:http` into an edge build
18
+ - **CLI** — `hono-apcore scan | serve | export` works against a plain Hono app
19
+ - **YAML bindings** — register modules declaratively, without touching source
20
+
21
+ ## Installation
22
+
23
+ ```bash
24
+ npm install hono-apcore hono
25
+ ```
26
+
27
+ Optional peers, installed only for the surfaces you use:
28
+
29
+ ```bash
30
+ npm install apcore-mcp @modelcontextprotocol/sdk # MCP server + Tool Explorer
31
+ npm install @hono/node-server # mountMcp() on the Node runtime
32
+ npm install apcore-cli # CLI surface
33
+ npm install apcore-a2a # A2A agent surface
34
+ npm install @sinclair/typebox # TypeBox schemas (recommended)
35
+ npm install zod # Zod schemas
36
+ ```
37
+
38
+ **Requirements:** Node.js >= 18, Hono >= 4 (tested with Hono 4.13).
39
+
40
+ ## Quick start
41
+
42
+ ### 1. Declare some tools
43
+
44
+ ```ts
45
+ // todo.tools.ts
46
+ import { Type } from '@sinclair/typebox';
47
+ import { defineToolset } from 'hono-apcore';
48
+
49
+ export const todoTools = defineToolset({
50
+ namespace: 'todo',
51
+ description: 'Todo list management',
52
+ tags: ['todo'],
53
+ tools: {
54
+ list: {
55
+ description: 'List all todos, optionally filtered by status',
56
+ inputSchema: Type.Object({ done: Type.Optional(Type.Boolean()) }),
57
+ annotations: { readonly: true, idempotent: true },
58
+ handler: (inputs) => ({ todos: store.list(inputs.done as boolean | undefined) }),
59
+ },
60
+ add: {
61
+ description: 'Add a new todo item',
62
+ inputSchema: Type.Object({ title: Type.String() }),
63
+ annotations: { readonly: false },
64
+ handler: (inputs) => ({ todo: store.add(String(inputs.title)) }),
65
+ },
66
+ },
67
+ });
68
+ ```
69
+
70
+ ### 2. Wire it into the app
71
+
72
+ ```ts
73
+ // app.ts
74
+ import { Hono } from 'hono';
75
+ import { apcore, createApcore } from 'hono-apcore';
76
+ import { todoTools } from './todo.tools.js';
77
+
78
+ export const ap = createApcore({
79
+ tools: todoTools,
80
+ mcp: { name: 'my-app', explorer: true, allowExecute: true },
81
+ });
82
+
83
+ export const app = new Hono();
84
+ app.use('*', apcore(ap));
85
+ app.get('/todos', (c) => c.json(store.list()));
86
+ ```
87
+
88
+ ### 3. Boot
89
+
90
+ ```ts
91
+ // main.ts
92
+ import { serve } from '@hono/node-server';
93
+ import { app, ap } from './app.js';
94
+
95
+ await ap.init(app); // register tools + scan routes
96
+ await ap.mountMcp(app); // mount /mcp, /explorer, /health
97
+
98
+ serve({ fetch: app.fetch, port: 3000 });
99
+ ```
100
+
101
+ Your app now answers:
102
+
103
+ - **REST** at `http://localhost:3000/todos`
104
+ - **MCP** at `http://localhost:3000/mcp`
105
+ - **Tool Explorer** at `http://localhost:3000/explorer/`
106
+
107
+ ## Two ways to expose a capability
108
+
109
+ ### `defineTool()` — explicit tools
110
+
111
+ The Hono counterpart to NestJS's `@ApTool` decorator. Hono has no classes or DI
112
+ container to decorate, so a tool is a plain object that carries its own
113
+ metadata and handler.
114
+
115
+ ```ts
116
+ import { defineTool } from 'hono-apcore';
117
+
118
+ const sendEmail = defineTool({
119
+ namespace: 'email',
120
+ name: 'send', // -> module id "email.send"
121
+ description: 'Send an email',
122
+ inputSchema: Type.Object({ to: Type.String(), body: Type.String() }),
123
+ outputSchema: Type.Object({ messageId: Type.String() }),
124
+ annotations: { readonly: false, destructive: false, requiresApproval: true },
125
+ tags: ['email'],
126
+ params: { to: 'Recipient address' }, // merged into the schema descriptions
127
+ handler: async (inputs, context) => mailer.send(inputs, context),
128
+ });
129
+ ```
130
+
131
+ | Field | Notes |
132
+ | --- | --- |
133
+ | `id` | Used verbatim. Otherwise `"<namespace>.<name>"`, with `name` snake-cased |
134
+ | `inputSchema` / `outputSchema` | TypeBox, Zod, or plain JSON Schema |
135
+ | `annotations` | `readonly`, `destructive`, `idempotent`, `requiresApproval`, `openWorld`, `streaming`, `cacheable`, … |
136
+ | `params` | Per-parameter prose merged into the input schema. JavaScript cannot read a function's leading comments at run time the way Python reads a docstring, so this is explicit |
137
+ | `handler` | `(inputs, context) => result`. A non-object result is wrapped as `{ result }` |
138
+
139
+ ### Route scanning — zero-intrusion tools
140
+
141
+ Point the scanner at an app and every route becomes a module that replays it
142
+ in-process through `app.request()`:
143
+
144
+ ```ts
145
+ const ap = createApcore({
146
+ routes: {
147
+ excludePaths: ['/health', '/mcp*', '/explorer*'],
148
+ modulePrefix: 'api',
149
+ },
150
+ });
151
+
152
+ await ap.init(app); // -> api.todos.list, api.todos.get, api.todos.create, …
153
+ ```
154
+
155
+ Module IDs come from the path and the HTTP verb:
156
+
157
+ | Route | Module ID | Inferred annotations |
158
+ | --- | --- | --- |
159
+ | `GET /todos` | `todos.list` | `readonly`, `cacheable` |
160
+ | `GET /todos/:id` | `todos.get` | `readonly`, `cacheable` |
161
+ | `POST /todos` | `todos.create` | — |
162
+ | `PUT /todos/:id` | `todos.update` | `idempotent` |
163
+ | `DELETE /todos/:id` | `todos.delete` | `destructive` |
164
+
165
+ The generated input schema carries one required string property per path
166
+ parameter, plus a free-form `query` object (GET/DELETE) or `body` object
167
+ (POST/PUT/PATCH). Override any of it per route:
168
+
169
+ ```ts
170
+ routes: {
171
+ overrides: {
172
+ 'GET /todos': {
173
+ id: 'todo.all',
174
+ description: 'Every todo, newest first',
175
+ inputSchema: Type.Object({ done: Type.Optional(Type.Boolean()) }),
176
+ annotations: { readonly: true, idempotent: true },
177
+ },
178
+ 'DELETE /admin/wipe': { skip: true },
179
+ },
180
+ }
181
+ ```
182
+
183
+ Because execution goes back through `app.request()`, an AI call runs the *same*
184
+ code path as an HTTP call — auth middleware, validators, error handlers and all.
185
+ Identity and W3C trace headers from the apcore `Context` are forwarded onto the
186
+ replayed request.
187
+
188
+ ## API reference
189
+
190
+ ### `createApcore(options)`
191
+
192
+ Returns a `HonoApcore` — the Registry, the Executor, and every surface hang off
193
+ it.
194
+
195
+ ```ts
196
+ createApcore({
197
+ extensionsDir?: string | null, // scanned by Registry.discover()
198
+ acl?: ACL, // enforced by the Executor on every call
199
+ middleware?: Middleware[], // apcore middleware installed on the Executor
200
+ bindings?: string, // YAML bindings file loaded during init()
201
+ tools?: ApToolDefinition[], // registered during init()
202
+ routes?: RouteScanOptions, // route-scanner configuration
203
+ settings?: Partial<ApcoreSettings>, // overrides for the APCORE_* settings
204
+ mcp?: ApcoreMcpOptions, // presence enables the MCP surface
205
+ cli?: ApcoreCliOptions, // presence enables the CLI surface
206
+ a2a?: ApcoreA2aOptions, // presence enables the A2A surface
207
+ })
208
+ ```
209
+
210
+ | Method | Description |
211
+ | --- | --- |
212
+ | `init(app?, routeOptions?)` | Discover, register tools and bindings, scan routes, start standalone surfaces. Idempotent |
213
+ | `ready()` | Await an in-flight `init()` |
214
+ | `registerTool(tool)` / `registerTools(tools)` | Register tool definitions at run time |
215
+ | `registerMethod(opts)` / `registerObject(opts)` | Register the methods of a plain service object |
216
+ | `scanRoutes(app, opts?)` | Scan and register an app's routes |
217
+ | `routeOptions` | The merged route-scan options this instance would use |
218
+ | `loadBindings(path?, resolver?)` | Load a YAML bindings file |
219
+ | `mountMcp(app, opts?)` | Mount `/mcp`, the Explorer, and `/health` into the app |
220
+ | `toOpenaiTools(opts?)` | OpenAI-compatible function definitions |
221
+ | `close()` | Shut down the MCP and A2A surfaces |
222
+
223
+ ### `apcore(instance | options, middlewareOptions?)`
224
+
225
+ Hono middleware that puts the instance and a per-request apcore `Context` on the
226
+ Hono context.
227
+
228
+ ```ts
229
+ app.use('*', apcore(ap));
230
+
231
+ app.get('/orders', async (c) =>
232
+ c.json(await getApcore(c).executor.call('orders.list', {}, getApcoreContext(c))),
233
+ );
234
+ ```
235
+
236
+ The variable map is augmented, so `c.get('apcore')` and `c.get('apcoreContext')`
237
+ are typed too. Pass `{ skipContext: true }` on routes that never call modules,
238
+ or `{ contextFactory }` to plug in real authentication.
239
+
240
+ ### `HonoContextFactory`
241
+
242
+ Builds the apcore `Context` from a Hono context, a `Request`, or bare `Headers`.
243
+
244
+ Identity resolution, in order: `x-user-id` → `Authorization: Bearer …` (identity
245
+ id `"bearer"`) → a bare `x-roles` header (a demo shortcut) → anonymous. A
246
+ `traceparent` header supplies the trace id; `x-correlation-id` (or
247
+ `x-request-id`) lands in `context.data`.
248
+
249
+ ```ts
250
+ new HonoContextFactory({
251
+ resolveIdentity: (headers) => identityFromSession(headers), // wins over the above
252
+ data: (headers) => ({ tenant: headers.get('x-tenant') }),
253
+ });
254
+ ```
255
+
256
+ ### MCP
257
+
258
+ `ApcoreMcpService` runs the MCP server two ways.
259
+
260
+ **Embedded** — one process, one port:
261
+
262
+ ```ts
263
+ await ap.mountMcp(app, { endpoint: '/mcp', explorer: true, allowExecute: true });
264
+ ```
265
+
266
+ This needs the raw Node request and response objects that `@hono/node-server`
267
+ exposes on `c.env`, so it is Node-only; a mounted handler on another runtime
268
+ answers `501` with that explanation. `endpoint` must be the path as the HTTP
269
+ server sees it — include the prefix if the app sits under a `basePath`.
270
+
271
+ **Standalone** — a separate port, or stdio for a CLI-launched server:
272
+
273
+ ```ts
274
+ createApcore({ mcp: { transport: 'streamable-http', host: '0.0.0.0', port: 8000 } });
275
+ // init() starts it, because `transport` was set explicitly
276
+ ```
277
+
278
+ Key MCP options:
279
+
280
+ | Field | Type | Description |
281
+ | --- | --- | --- |
282
+ | `transport` | `'stdio' \| 'streamable-http' \| 'sse'` | Standalone transport. Setting it makes `init()` start the server |
283
+ | `host` / `port` | `string` / `number` | Bind address for HTTP transports |
284
+ | `name` / `version` | `string` | Server identity |
285
+ | `explorer` / `explorerPrefix` / `allowExecute` | | Tool Explorer web UI |
286
+ | `authenticator` / `requireAuth` / `exemptPaths` | | JWT or custom auth |
287
+ | `tags` / `prefix` | | Expose only matching modules |
288
+ | `validateInputs` | `boolean` | Enforce input schemas on every call |
289
+ | `observability` | | Metrics + usage middleware and their endpoints |
290
+ | `outputFormat` / `outputFormatter` / `redactOutput` / `trace` | | Result serialisation |
291
+ | `approvalHandler` / `approvalStore` / `approvalNotify` | | Approval gate for destructive tools |
292
+ | `mcpMiddleware` / `mcpAcl` | | Extra apcore middleware / ACL for the MCP executor |
293
+
294
+ ### Schema adapters
295
+
296
+ Schemas are auto-detected and converted through a priority chain:
297
+
298
+ | Adapter | Priority | Input |
299
+ | --- | --- | --- |
300
+ | `TypeBoxAdapter` | 100 | `@sinclair/typebox` schemas |
301
+ | `ZodAdapter` | 50 | Zod 3 (`_def.typeName`) and Zod 4 (`_zod.def.type`) |
302
+ | `JsonSchemaAdapter` | 30 | Plain JSON Schema objects |
303
+
304
+ Detection is structural — neither TypeBox nor Zod is imported at run time — so
305
+ whichever the host app installs (or neither) is fine. Register your own with
306
+ `SchemaExtractor.registerAdapter()`.
307
+
308
+ ### YAML bindings
309
+
310
+ Register modules without touching source:
311
+
312
+ ```yaml
313
+ bindings:
314
+ - module_id: email.send
315
+ target: EmailService.send
316
+ description: Send an email
317
+ input_schema:
318
+ type: object
319
+ properties:
320
+ to: { type: string }
321
+ tags: [email, mutate]
322
+ annotations:
323
+ readonly: false
324
+ ```
325
+
326
+ ```ts
327
+ import { resolverFromObjects } from 'hono-apcore';
328
+
329
+ await ap.loadBindings('./bindings.yaml', resolverFromObjects({ EmailService: mailer }));
330
+ ```
331
+
332
+ Going the other way, `writeBindingsFile()` serialises scanned modules back out —
333
+ which is what `hono-apcore scan --format yaml` does.
334
+
335
+ ### CLI
336
+
337
+ ```bash
338
+ hono-apcore scan ./src/app.ts # print the modules a scan would produce
339
+ hono-apcore scan ./src/app.ts --format yaml --out bindings.yaml
340
+ hono-apcore serve ./src/app.ts --transport http --port 8000 --explorer
341
+ hono-apcore export ./src/app.ts --out tools.json
342
+ ```
343
+
344
+ The entry is `path[:export]`; the export defaults to `default`, then `app`. If
345
+ the module exports a `HonoApcore` under **any** name, its configuration — route
346
+ filters, module prefix, MCP options — is honoured, so `scan` reports exactly the
347
+ modules the app itself registers; CLI flags override it. An entry with no
348
+ instance still works, so `serve` runs against an app that has never heard of
349
+ apcore. TypeScript entries need a loader:
350
+
351
+ ```bash
352
+ npx tsx node_modules/.bin/hono-apcore scan ./src/app.ts
353
+ ```
354
+
355
+ ### Configuration (`APCORE_*`)
356
+
357
+ The canonical settings every apcore integration implements, read from the
358
+ environment and overridable via `settings`:
359
+
360
+ | Variable | Type | Default | Purpose |
361
+ | --- | --- | --- | --- |
362
+ | `APCORE_ENABLED` | bool | `true` | Master switch — `false` makes `init()` a no-op |
363
+ | `APCORE_DEBUG` | bool | `false` | Verbose logging / introspection |
364
+ | `APCORE_SCANNERS` | list | `["auto"]` | Enabled scanner identifiers |
365
+ | `APCORE_INCLUDE_PATHS` | list | `[]` | Route patterns to include (empty = all) |
366
+ | `APCORE_EXCLUDE_PATHS` | list | `[]` | Route patterns to exclude |
367
+ | `APCORE_MODULE_PREFIX` | str | `""` | Prefix prepended to generated module IDs |
368
+ | `APCORE_AUTH_ENABLED` | bool | `false` | Require auth for MCP/A2A endpoints |
369
+ | `APCORE_AUTH_STRATEGY` | str | `"bearer"` | `bearer` / `session` / `custom` |
370
+ | `APCORE_TRANSPORT` | str | `"stdio"` | MCP transport: `stdio` / `http` / `sse` |
371
+ | `APCORE_HOST` | str | `"0.0.0.0"` | Bind address when the transport is not stdio |
372
+ | `APCORE_PORT` | int | `8808` | Bind port when the transport is not stdio |
373
+
374
+ ### Optional peers are not re-exported
375
+
376
+ Unlike the NestJS adapter, `hono-apcore` does **not** re-export the `apcore-mcp`
377
+ / `apcore-cli` / `apcore-a2a` surfaces. Doing so would make them load eagerly,
378
+ and `apcore-mcp` pulls in `node:http` — which breaks a Workers, Deno, or Bun
379
+ build of an app that never uses the MCP surface. Import those symbols from their
380
+ own packages:
381
+
382
+ ```ts
383
+ import { JWTAuthenticator, getCurrentIdentity } from 'apcore-mcp';
384
+ import { createCli } from 'apcore-cli';
385
+ import { A2AClient } from 'apcore-a2a';
386
+ ```
387
+
388
+ `apcore-js` and `apcore-toolkit` *are* hard dependencies, so their common
389
+ symbols (`ACL`, `Config`, `registerSysModules`, `TraceContext`, `BaseScanner`,
390
+ `formatModules`, …) re-export from `hono-apcore` directly.
391
+
392
+ ## Examples
393
+
394
+ | Example | Shows |
395
+ | --- | --- |
396
+ | [`examples/demo`](./examples/demo) | Full app: hand-written tools *and* route scanning, JWT, ACL, system modules, Docker |
397
+ | [`examples/acl_demo`](./examples/acl_demo) | Routes governed by apcore ACL — `orders.delete` for admins only |
398
+
399
+ ```bash
400
+ pnpm install && pnpm build
401
+ cd examples/demo && pnpm install && pnpm dev
402
+ ```
403
+
404
+ ## Detailed documentation
405
+
406
+ - [Feature overview](./docs/features/overview.md) — architecture and dependency graph
407
+ - [Tool definition](./docs/features/tool-definition.md) — `defineTool`, `defineToolset`, module IDs
408
+ - [Route scanner](./docs/features/route-scanner.md) — how routes become modules, and what replay costs
409
+ - [MCP integration](./docs/features/mcp-server-integration.md) — embedded vs standalone, the Node bridge
410
+ - [Schema extraction](./docs/features/schema-extraction.md) — the adapter chain and custom adapters
411
+ - [Context and ACL](./docs/features/context-and-acl.md) — identity, tracing, and governing routes
412
+
413
+ ## Scripts
414
+
415
+ | Command | Description |
416
+ | --- | --- |
417
+ | `pnpm build` | Compile TypeScript |
418
+ | `pnpm dev` | Watch-mode compilation |
419
+ | `pnpm test` | Run the test suite (vitest) |
420
+ | `pnpm test:coverage` | Tests with coverage (90% thresholds) |
421
+ | `pnpm typecheck` | Type-check without emitting |
422
+ | `pnpm lint` | Lint source and tests |
423
+
424
+ ## License
425
+
426
+ Apache-2.0
@@ -0,0 +1,44 @@
1
+ import type { ApcoreExecutor } from '../core/executor.js';
2
+ import type { ApcoreRegistry } from '../core/registry.js';
3
+ import type { ApcoreA2aOptions } from '../types.js';
4
+ /**
5
+ * Manages the A2A (Agent-to-Agent) server that exposes the registered apcore
6
+ * modules as agent skills.
7
+ *
8
+ * `apcore-a2a` is an **optional** peer dependency, loaded lazily.
9
+ *
10
+ * - **Standalone** — set `port` and call {@link start}; the A2A server binds
11
+ * its own port alongside the Hono HTTP server.
12
+ * - **Embedded** — {@link asyncServe} returns an Express-compatible app you
13
+ * can mount behind a reverse proxy or inside a Node server.
14
+ */
15
+ export declare class ApcoreA2aService {
16
+ private readonly registry;
17
+ private readonly executor;
18
+ private readonly options;
19
+ private _isRunning;
20
+ constructor(registry: ApcoreRegistry, executor: ApcoreExecutor, options?: ApcoreA2aOptions);
21
+ /** Whether the standalone A2A server has been started. */
22
+ get isRunning(): boolean;
23
+ /** Number of skills (modules) exposed to A2A clients. */
24
+ get skillCount(): number;
25
+ /**
26
+ * Start a standalone A2A HTTP server with the configured options.
27
+ *
28
+ * Called automatically by {@link HonoApcore.init} when `port` is set.
29
+ */
30
+ start(): Promise<void>;
31
+ /**
32
+ * Build an embeddable A2A application without binding a port.
33
+ *
34
+ * @param overrides - Option overrides merged over the configured values.
35
+ */
36
+ asyncServe(overrides?: Partial<ApcoreA2aOptions>): Promise<unknown>;
37
+ /**
38
+ * Mark the service stopped. The underlying HTTP server owns its own
39
+ * lifecycle and shuts down with the process.
40
+ */
41
+ stop(): void;
42
+ private serveOptions;
43
+ }
44
+ //# sourceMappingURL=apcore-a2a.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"apcore-a2a.service.d.ts","sourceRoot":"","sources":["../../src/a2a/apcore-a2a.service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAEpD;;;;;;;;;;GAUG;AACH,qBAAa,gBAAgB;IAIzB,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACzB,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACzB,OAAO,CAAC,QAAQ,CAAC,OAAO;IAL1B,OAAO,CAAC,UAAU,CAAS;gBAGR,QAAQ,EAAE,cAAc,EACxB,QAAQ,EAAE,cAAc,EACxB,OAAO,GAAE,gBAAqB;IAGjD,0DAA0D;IAC1D,IAAI,SAAS,IAAI,OAAO,CAEvB;IAED,yDAAyD;IACzD,IAAI,UAAU,IAAI,MAAM,CAEvB;IAED;;;;OAIG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAS5B;;;;OAIG;IACG,UAAU,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC,gBAAgB,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC;IAQzE;;;OAGG;IACH,IAAI,IAAI,IAAI;IAIZ,OAAO,CAAC,YAAY;CA0BrB"}