@aventara/mcp 0.0.0-stage → 1.0.0-rc.10
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/CHANGELOG.md +184 -0
- package/LICENSE +91 -0
- package/LICENSE-ADDITIONAL-PERMISSION.md +9 -0
- package/README.md +166 -2
- package/dist/av-mcp.d.ts +5 -0
- package/dist/av-mcp.js +1 -0
- package/dist/endpoint-access.policy.d.ts +35 -0
- package/dist/endpoint-access.policy.js +110 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +1 -0
- package/dist/json-text.writer.d.ts +7 -0
- package/dist/json-text.writer.js +44 -0
- package/dist/mcp.binder.d.ts +74 -0
- package/dist/mcp.binder.js +295 -0
- package/dist/tool-call.translator.d.ts +33 -0
- package/dist/tool-call.translator.js +172 -0
- package/dist/tool-catalog.compiler.d.ts +49 -0
- package/dist/tool-catalog.compiler.js +226 -0
- package/dist/tool-result.encoder.d.ts +28 -0
- package/dist/tool-result.encoder.js +29 -0
- package/package.json +38 -3
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
# @aventara/mcp
|
|
2
|
+
|
|
3
|
+
## 1.0.0-rc.10
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 04bb39a: `engines.node` is now `^22.23.4 || >=24.22.1`, the Node security releases of 2026-10-20 (CVE-2026-105481,
|
|
8
|
+
CVE-2026-105482, CVE-2026-105483, CVE-2026-106069, CVE-2026-106072, CVE-2026-106073, CVE-2026-106074,
|
|
9
|
+
CVE-2026-111497). The bins refuse an older Node in one sentence naming that range.
|
|
10
|
+
- d7e7369: - The tool `me`, offered when the framework's `access` provider states its `client`: it takes `{}` and answers the
|
|
11
|
+
identity Aventara Access resolves from the request's credentials (`{ sub, claims }`, or `null`) as the protocol
|
|
12
|
+
envelope's data, projected onto the `access` section's `me` schema (an identity it does not describe answers
|
|
13
|
+
`A3000`).
|
|
14
|
+
- An endpoint without `authorization` now also requires a loopback `Host` header (`localhost`, `127.x.x.x` or
|
|
15
|
+
`[::1]`, any port); any other `Host`, or none, is `403`. This closes DNS rebinding (the class of CVE-2025-66414): a
|
|
16
|
+
page whose domain is rebound to `127.0.0.1` still names its own domain as `Host`.
|
|
17
|
+
An HTTP/2 caller (`:authority`, no `Host`) is refused by the open endpoint.
|
|
18
|
+
- 3fb3333: `@aventara/mcp` pins `@modelcontextprotocol/sdk` 1.32.2 (was 1.30.1) and `zod` `^4.6.7` (was `^4.6.5`); `@aventara/core`
|
|
19
|
+
also takes `zod` `^4.6.7`. This clears the advisories against those versions:
|
|
20
|
+
|
|
21
|
+
| Advisory | Severity | Package | What it was |
|
|
22
|
+
| ------------------------------------- | -------- | ------------------- | -------------------------------------------------------------------------------------------------------- |
|
|
23
|
+
| GHSA-46jr-4wx8-v453 (CVE-2026-111768) | high | sdk < 1.32.0 | One HTTP request within the default size limit could exhaust server memory during validation |
|
|
24
|
+
| GHSA-22jm-h49p-29qw (CVE-2026-111767) | high | sdk 1.24.0 – 1.31.x | Experimental tasks were not tied to the session that created them |
|
|
25
|
+
| GHSA-6qxp-vccf-f47h (CVE-2026-104850) | high | sdk 1.12.0 – 1.30.x | The OAuth client could send credentials to an authorization server chosen by the MCP server |
|
|
26
|
+
| GHSA-mrhx-c7xc-m3w5 | high | zod ≤ 4.6.5 | Validating an oversized unconstrained array could exhaust memory |
|
|
27
|
+
| GHSA-rvq5-wwqv-78pq (CVE-2026-111771) | moderate | sdk 1.6.0 – 1.31.x | Server bearer authentication accepted tokens issued for another service |
|
|
28
|
+
| GHSA-6prh-2h8m-c8cw (CVE-2026-111769) | moderate | sdk < 1.32.0 | HTTP client transports and OAuth requests followed cross-origin redirects with custom headers and bodies |
|
|
29
|
+
|
|
30
|
+
Aventara's MCP server was already outside most of these: it uses the low-level `Server` (no `taskStore`, no
|
|
31
|
+
`requireBearerAuth`, no SDK OAuth client), and its transport's `maxRequestBodySize` is the agent layer's
|
|
32
|
+
`limits.maxRequestBytes`. No API of `@aventara/mcp` changes.
|
|
33
|
+
|
|
34
|
+
- 88263a1: Documentation: `$access.can([])` answers `[]`, not a refusal; the MCP README states the query and fragment rule for
|
|
35
|
+
every authorization server.
|
|
36
|
+
- Updated dependencies [587dd01]
|
|
37
|
+
- Updated dependencies [d7e7369]
|
|
38
|
+
- Updated dependencies [7ee547b]
|
|
39
|
+
- Updated dependencies [f52c499]
|
|
40
|
+
- Updated dependencies [2907484]
|
|
41
|
+
- Updated dependencies [a6bbdf0]
|
|
42
|
+
- Updated dependencies [3e26549]
|
|
43
|
+
- Updated dependencies [a6bbdf0]
|
|
44
|
+
- Updated dependencies [6f3f6f6]
|
|
45
|
+
- Updated dependencies [04bb39a]
|
|
46
|
+
- Updated dependencies [3fb3333]
|
|
47
|
+
- Updated dependencies [827ccb6]
|
|
48
|
+
- Updated dependencies [7f5abc3]
|
|
49
|
+
- Updated dependencies [88263a1]
|
|
50
|
+
- Updated dependencies [10341d5]
|
|
51
|
+
- Updated dependencies [8129844]
|
|
52
|
+
- Updated dependencies [88263a1]
|
|
53
|
+
- Updated dependencies [3020b5c]
|
|
54
|
+
- Updated dependencies [88263a1]
|
|
55
|
+
- Updated dependencies [88263a1]
|
|
56
|
+
- @aventara/core@1.0.0-rc.10
|
|
57
|
+
|
|
58
|
+
## 1.0.0-rc.9
|
|
59
|
+
|
|
60
|
+
### Patch Changes
|
|
61
|
+
|
|
62
|
+
- Updated dependencies [205a379]
|
|
63
|
+
- Updated dependencies [a0bb05e]
|
|
64
|
+
- Updated dependencies [86ab319]
|
|
65
|
+
- Updated dependencies [fdf52e6]
|
|
66
|
+
- @aventara/core@1.0.0-rc.9
|
|
67
|
+
|
|
68
|
+
## 1.0.0-rc.8
|
|
69
|
+
|
|
70
|
+
1.0.0-rc.5, rc.6 and rc.7 were tagged but never published; 1.0.0-rc.8 contains everything listed under them and the changes below.
|
|
71
|
+
|
|
72
|
+
### Patch Changes
|
|
73
|
+
|
|
74
|
+
- Updated dependencies [1c8e4ee]
|
|
75
|
+
- @aventara/core@1.0.0-rc.8
|
|
76
|
+
|
|
77
|
+
## 1.0.0-rc.7
|
|
78
|
+
|
|
79
|
+
1.0.0-rc.5 and 1.0.0-rc.6 were tagged but never published; 1.0.0-rc.7 contains everything listed under them and the changes below.
|
|
80
|
+
|
|
81
|
+
### Patch Changes
|
|
82
|
+
|
|
83
|
+
- Updated dependencies [f917c1c]
|
|
84
|
+
- @aventara/core@1.0.0-rc.7
|
|
85
|
+
|
|
86
|
+
## 1.0.0-rc.6
|
|
87
|
+
|
|
88
|
+
1.0.0-rc.5 was tagged but never published. 1.0.0-rc.6 contains everything listed under 1.0.0-rc.5 and the fix below.
|
|
89
|
+
|
|
90
|
+
### Patch Changes
|
|
91
|
+
|
|
92
|
+
- Updated dependencies [1cf72e0]
|
|
93
|
+
- @aventara/core@1.0.0-rc.6
|
|
94
|
+
|
|
95
|
+
## 1.0.0-rc.5
|
|
96
|
+
|
|
97
|
+
### Patch Changes
|
|
98
|
+
|
|
99
|
+
- Updated dependencies [4795ff1]
|
|
100
|
+
- Updated dependencies [9e178ca]
|
|
101
|
+
- @aventara/core@1.0.0-rc.5
|
|
102
|
+
|
|
103
|
+
## 1.0.0-rc.4
|
|
104
|
+
|
|
105
|
+
### Patch Changes
|
|
106
|
+
|
|
107
|
+
- d10639a: Faster reads. The read-only copies stages are told cost about half what they did: a read with a computed field
|
|
108
|
+
copies each row in one pass, a row with several computed fields shares its nested objects between the stages'
|
|
109
|
+
copies, and after hooks share one frozen copy of the result. A row whose computed field returns a value at once no
|
|
110
|
+
longer waits a turn per row. The MCP endpoint builds its JSON Schema validator once instead of on every request.
|
|
111
|
+
What stages are told, the order they run in and what a request answers are unchanged.
|
|
112
|
+
- Updated dependencies [e3d03a7]
|
|
113
|
+
- Updated dependencies [d10639a]
|
|
114
|
+
- Updated dependencies [f67e68c]
|
|
115
|
+
- Updated dependencies [708556c]
|
|
116
|
+
- Updated dependencies [3a0dfca]
|
|
117
|
+
- Updated dependencies [99169d2]
|
|
118
|
+
- Updated dependencies [0fd2608]
|
|
119
|
+
- Updated dependencies [154e440]
|
|
120
|
+
- Updated dependencies [2fcffdb]
|
|
121
|
+
- @aventara/core@1.0.0-rc.4
|
|
122
|
+
|
|
123
|
+
## 1.0.0-rc.3
|
|
124
|
+
|
|
125
|
+
### Patch Changes
|
|
126
|
+
|
|
127
|
+
- Updated dependencies [b38034d]
|
|
128
|
+
- Updated dependencies [b38034d]
|
|
129
|
+
- Updated dependencies [b38034d]
|
|
130
|
+
- Updated dependencies [b38034d]
|
|
131
|
+
- Updated dependencies [b38034d]
|
|
132
|
+
- Updated dependencies [b38034d]
|
|
133
|
+
- @aventara/core@1.0.0-rc.3
|
|
134
|
+
|
|
135
|
+
## 1.0.0-rc.2
|
|
136
|
+
|
|
137
|
+
### Patch Changes
|
|
138
|
+
|
|
139
|
+
- 9366e16: MCP endpoint polish:
|
|
140
|
+
|
|
141
|
+
- A request with no bearer credentials (no `Authorization` header, or another scheme such as `Basic`) is answered
|
|
142
|
+
`401` with `WWW-Authenticate: Bearer resource_metadata="…"` and no error code, as RFC 6750 §3.1 asks; its body no
|
|
143
|
+
longer says "Missing Authorization header". A bad bearer token keeps `error="invalid_token"`.
|
|
144
|
+
- A `mcp.authorization.verify` that throws is still answered `401`, and is now reported to the `diagnostics` sink as
|
|
145
|
+
an `AvMcpDiagnostic` holding the error.
|
|
146
|
+
- With `mcp` configured and `@aventara/mcp` missing, the startup error names the command that installs it at the
|
|
147
|
+
installed `@aventara/core`'s exact version: `npm install --save-exact @aventara/mcp@<version>`.
|
|
148
|
+
|
|
149
|
+
- A tool call whose `resource` or `variant` holds a lone surrogate (JSON can carry one, a URL cannot) is answered as
|
|
150
|
+
the unknown name it is, as an HTTP call answers it: `fetch` spells a lone surrogate in a URL as U+FFFD, and so does
|
|
151
|
+
the tool call, so the agent gets `A2001` (`A2002` for the variant). In rc.1 the name could not be encoded, and the
|
|
152
|
+
call answered the generic `A3000` and reported a diagnostic of kind `mcp`. A `transaction` step that has no canonical
|
|
153
|
+
form (a lone surrogate in a name or a value) is sent with a `null` fingerprint, as core's plan builders and the
|
|
154
|
+
generated client send it, so it is judged as over HTTP: an unknown name is `A2001`/`A2002`, a value `A2004` `V1001`
|
|
155
|
+
at the step's `args`. It answered `V1000` for a missing `fingerprint`, a member the tool does not take.
|
|
156
|
+
- Updated dependencies [9366e16]
|
|
157
|
+
- Updated dependencies [9366e16]
|
|
158
|
+
- Updated dependencies [9366e16]
|
|
159
|
+
- Updated dependencies [9366e16]
|
|
160
|
+
- @aventara/core@1.0.0-rc.2
|
|
161
|
+
|
|
162
|
+
## 1.0.0-rc.1
|
|
163
|
+
|
|
164
|
+
### Minor Changes
|
|
165
|
+
|
|
166
|
+
- New package: the MCP server of an Aventara application. With `mcp` in the configuration, `@aventara/nest` mounts it
|
|
167
|
+
at that path over the Streamable HTTP transport, stateless. Its tools are the operation families the `agent` layer
|
|
168
|
+
exposes (`find`, `create`, `update`, `delete`, `upsert`) and `transaction`, each taking `{ resource, variant, args }`
|
|
169
|
+
(`transaction`: `{ steps }`, with `$ref` between steps). Every call runs as the `agent` origin through the protocol's
|
|
170
|
+
own decoding and validation; a success answers the envelope as structured content, a failure an MCP tool error
|
|
171
|
+
carrying the envelope and its issues. The Agent Contract is the resource `aventara://contract`.
|
|
172
|
+
- With `mcp.authorization`, the endpoint is an OAuth 2.1 protected resource: it publishes its metadata at
|
|
173
|
+
`/.well-known/oauth-protected-resource` plus the endpoint's path, answers a request without a good bearer token `401`
|
|
174
|
+
with a `WWW-Authenticate` challenge, and puts what `verify` returned into `ctx.$state.mcp.claims`. Without it, the
|
|
175
|
+
endpoint answers callers on the same machine only.
|
|
176
|
+
- A failure of the endpoint itself (the MCP SDK's server or transport) is answered `500` with no detail and reported to
|
|
177
|
+
the Framework's diagnostics sink as an `AvMcpDiagnostic`, so the raw error is not lost.
|
|
178
|
+
- A throw inside a tool or resource handler no longer reaches the agent with its raw message. A tool call answers the
|
|
179
|
+
generic `A3000` envelope as a tool error (`isError: true`), the form the protocol's own `A3000` takes; a resource or
|
|
180
|
+
list request answers a JSON-RPC internal error with the same generic message. The raw error goes to the diagnostics
|
|
181
|
+
sink as an `AvMcpDiagnostic`.
|
|
182
|
+
- A tool call's arguments nested deeper than the protocol allows are refused as the protocol refuses them from a
|
|
183
|
+
client (`A2009` with `V1013`, or `V1021` for a `json` value, at the arguments' path), as a tool error. The server
|
|
184
|
+
writes the arguments on without recursing on their depth, so a deep value no longer overflows the stack.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
Required Notice: Copyright 2026 Mohamed Ragheb
|
|
2
|
+
|
|
3
|
+
# PolyForm Shield License 1.0.0
|
|
4
|
+
|
|
5
|
+
<https://polyformproject.org/licenses/shield/1.0.0>
|
|
6
|
+
|
|
7
|
+
## Acceptance
|
|
8
|
+
|
|
9
|
+
In order to get any license under these terms, you must agree to them as both strict obligations and conditions to all your licenses.
|
|
10
|
+
|
|
11
|
+
## Copyright License
|
|
12
|
+
|
|
13
|
+
The licensor grants you a copyright license for the software to do everything you might do with the software that would otherwise infringe the licensor's copyright in it for any permitted purpose. However, you may only distribute the software according to [Distribution License](#distribution-license) and make changes or new works based on the software according to [Changes and New Works License](#changes-and-new-works-license).
|
|
14
|
+
|
|
15
|
+
## Distribution License
|
|
16
|
+
|
|
17
|
+
The licensor grants you an additional copyright license to distribute copies of the software. Your license to distribute covers distributing the software with changes and new works permitted by [Changes and New Works License](#changes-and-new-works-license).
|
|
18
|
+
|
|
19
|
+
## Notices
|
|
20
|
+
|
|
21
|
+
You must ensure that anyone who gets a copy of any part of the software from you also gets a copy of these terms or the URL for them above, as well as copies of any plain-text lines beginning with `Required Notice:` that the licensor provided with the software. For example:
|
|
22
|
+
|
|
23
|
+
> Required Notice: Copyright Yoyodyne, Inc. (http://example.com)
|
|
24
|
+
|
|
25
|
+
## Changes and New Works License
|
|
26
|
+
|
|
27
|
+
The licensor grants you an additional copyright license to make changes and new works based on the software for any permitted purpose.
|
|
28
|
+
|
|
29
|
+
## Patent License
|
|
30
|
+
|
|
31
|
+
The licensor grants you a patent license for the software that covers patent claims the licensor can license, or becomes able to license, that you would infringe by using the software.
|
|
32
|
+
|
|
33
|
+
## Noncompete
|
|
34
|
+
|
|
35
|
+
Any purpose is a permitted purpose, except for providing any product that competes with the software or any product the licensor or any of its affiliates provides using the software.
|
|
36
|
+
|
|
37
|
+
## Competition
|
|
38
|
+
|
|
39
|
+
Goods and services compete even when they provide functionality through different kinds of interfaces or for different technical platforms. Applications can compete with services, libraries with plugins, frameworks with development tools, and so on, even if they're written in different programming languages or for different computer architectures. Goods and services compete even when provided free of charge. If you market a product as a practical substitute for the software or another product, it definitely competes.
|
|
40
|
+
|
|
41
|
+
## New Products
|
|
42
|
+
|
|
43
|
+
If you are using the software to provide a product that does not compete, but the licensor or any of its affiliates brings your product into competition by providing a new version of the software or another product using the software, you may continue using versions of the software available under these terms beforehand to provide your competing product, but not any later versions.
|
|
44
|
+
|
|
45
|
+
## Discontinued Products
|
|
46
|
+
|
|
47
|
+
You may begin using the software to compete with a product or service that the licensor or any of its affiliates has stopped providing, unless the licensor includes a plain-text line beginning with `Licensor Line of Business:` with the software that mentions that line of business. For example:
|
|
48
|
+
|
|
49
|
+
> Licensor Line of Business: YoyodyneCMS Content Management System (http://example.com/cms)
|
|
50
|
+
|
|
51
|
+
## Sales of Business
|
|
52
|
+
|
|
53
|
+
If the licensor or any of its affiliates sells a line of business developing the software or using the software to provide a product, the buyer can also enforce [Noncompete](#noncompete) for that product.
|
|
54
|
+
|
|
55
|
+
## Fair Use
|
|
56
|
+
|
|
57
|
+
You may have "fair use" rights for the software under the law. These terms do not limit them.
|
|
58
|
+
|
|
59
|
+
## No Other Rights
|
|
60
|
+
|
|
61
|
+
These terms do not allow you to sublicense or transfer any of your licenses to anyone else, or prevent the licensor from granting licenses to anyone else. These terms do not imply any other licenses.
|
|
62
|
+
|
|
63
|
+
## Patent Defense
|
|
64
|
+
|
|
65
|
+
If you make any written claim that the software infringes or contributes to infringement of any patent, your patent license for the software granted under these terms ends immediately. If your company makes such a claim, your patent license ends immediately for work on behalf of your company.
|
|
66
|
+
|
|
67
|
+
## Violations
|
|
68
|
+
|
|
69
|
+
The first time you are notified in writing that you have violated any of these terms, or done anything with the software not covered by your licenses, your licenses can nonetheless continue if you come into full compliance with these terms, and take practical steps to correct past violations, within 32 days of receiving notice. Otherwise, all your licenses end immediately.
|
|
70
|
+
|
|
71
|
+
## No Liability
|
|
72
|
+
|
|
73
|
+
***As far as the law allows, the software comes as is, without any warranty or condition, and the licensor will not be liable to you for any damages arising out of these terms or the use or nature of the software, under any kind of legal claim.***
|
|
74
|
+
|
|
75
|
+
## Definitions
|
|
76
|
+
|
|
77
|
+
The **licensor** is the individual or entity offering these terms, and the **software** is the software the licensor makes available under these terms.
|
|
78
|
+
|
|
79
|
+
A **product** can be a good or service, or a combination of them.
|
|
80
|
+
|
|
81
|
+
**You** refers to the individual or entity agreeing to these terms.
|
|
82
|
+
|
|
83
|
+
**Your company** is any legal entity, sole proprietorship, or other kind of organization that you work for, plus all its affiliates.
|
|
84
|
+
|
|
85
|
+
**Affiliates** means the other organizations than an organization has control over, is under the control of, or is under common control with.
|
|
86
|
+
|
|
87
|
+
**Control** means ownership of substantially all the assets of an entity, or the power to direct its management and policies by vote, contract, or otherwise. Control can be direct or indirect.
|
|
88
|
+
|
|
89
|
+
**Your licenses** are all the licenses granted to you for the software under these terms.
|
|
90
|
+
|
|
91
|
+
**Use** means anything you do with the software requiring one of your licenses.
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# Additional Permission — Aventara
|
|
2
|
+
|
|
3
|
+
Copyright 2026 Mohamed Ragheb
|
|
4
|
+
|
|
5
|
+
In addition to the permissions of the PolyForm Shield License 1.0.0 in `LICENSE`, the licensor grants the following additional permission:
|
|
6
|
+
|
|
7
|
+
The Noncompete section applies only to providing a product that competes with the software itself — the Aventara framework, its packages and its tooling. Providing a product that competes with any other product the licensor or its affiliates provide using the software is a permitted purpose.
|
|
8
|
+
|
|
9
|
+
This additional permission only adds to your permissions; it does not restrict or replace any term of `LICENSE`.
|
package/README.md
CHANGED
|
@@ -1,3 +1,167 @@
|
|
|
1
|
-
#
|
|
1
|
+
# `@aventara/mcp`
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The MCP server of an Aventara application. It turns the configuration's `agent` layer into
|
|
4
|
+
[Model Context Protocol](https://modelcontextprotocol.io) tools, so an AI agent (Claude Desktop, Claude Code, any MCP
|
|
5
|
+
client) can read and write the application's data under the same validation, exposure and pipelines as every other
|
|
6
|
+
caller.
|
|
7
|
+
|
|
8
|
+
The server lives inside your application. `@aventara/nest` mounts it at the path the configuration's `mcp` key names,
|
|
9
|
+
over the Streamable HTTP transport, stateless. You install this package beside `@aventara/nest`; you do not call it
|
|
10
|
+
yourself.
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npm install --save-exact @aventara/mcp@<your @aventara/core version>
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
It depends on `@aventara/core` and the official MCP TypeScript SDK (`@modelcontextprotocol/sdk`).
|
|
17
|
+
|
|
18
|
+
## Turning it on
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
// src/aventara.config.ts
|
|
22
|
+
export async function aventaraConfig(prisma: PrismaService) {
|
|
23
|
+
return {
|
|
24
|
+
api: "/api",
|
|
25
|
+
mcp: "/mcp",
|
|
26
|
+
adapter: await createPrismaAdapter({ client: prisma, discovery, provider: "postgresql", driver: "@prisma/adapter-pg" }),
|
|
27
|
+
// What the agent may reach: by default exactly what the client may.
|
|
28
|
+
agent: {
|
|
29
|
+
exposed: true,
|
|
30
|
+
exemptions: { resources: { AuditLog: true } },
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
When the configuration has `mcp`, `AventaraModule` mounts the endpoint and logs it:
|
|
37
|
+
`Aventara mounted the MCP endpoint at /mcp (…)`. With `mcp` set and this package missing, the application refuses to
|
|
38
|
+
start and names the package.
|
|
39
|
+
|
|
40
|
+
## The tools
|
|
41
|
+
|
|
42
|
+
One tool per operation family the agent layer exposes, and none for a family nothing exposes:
|
|
43
|
+
|
|
44
|
+
| Tool | Input | Hints |
|
|
45
|
+
|---|---|---|
|
|
46
|
+
| `find` | `{ resource, variant, args? }` | read-only |
|
|
47
|
+
| `create` | `{ resource, variant, args }` | not destructive |
|
|
48
|
+
| `update` | `{ resource, variant, args }` | destructive |
|
|
49
|
+
| `delete` | `{ resource, variant, args }` | destructive |
|
|
50
|
+
| `upsert` | `{ resource, variant, args }` | destructive |
|
|
51
|
+
| `transaction` | `{ steps: [{ resource, family, variant, args? }] }` | destructive |
|
|
52
|
+
| `me` | `{}` | read-only |
|
|
53
|
+
|
|
54
|
+
`resource` and `variant` are enums read from the agent layer, so a resource the agent layer hides is not offered (and is
|
|
55
|
+
refused with `A2001` if an agent names it anyway). `args` is the operation's arguments as the protocol defines them
|
|
56
|
+
(`where`, `select`, `data`, …). `transaction` is offered when the agent layer's transactions are interactive. A step can
|
|
57
|
+
use a value an earlier step returned with `{ "$ref": { "operation": 0, "path": ["id"] } }`; the server adds the
|
|
58
|
+
fingerprints the protocol requires. `me` is offered when the framework's `access` provider states its `client`: it
|
|
59
|
+
answers the identity Aventara Access resolves from the request's credentials (`{ sub, claims }`, or `null`) as the
|
|
60
|
+
envelope's data, holding only what the `access` section's `me` schema declares (an identity the schema does not
|
|
61
|
+
describe is the server's own failure, `A3000`). There is no sign-in tool.
|
|
62
|
+
|
|
63
|
+
Every call runs as the `agent` origin, through the same decoding and validation as an HTTP call, with the agent
|
|
64
|
+
layer's pipelines. A success answers the protocol's envelope (`{ data, code, cause }`) as structured content and as
|
|
65
|
+
text. A failure answers an MCP tool error (`isError: true`) carrying the envelope, its cause and its issues (`path`,
|
|
66
|
+
`code`, `check`, `params`, `message`), so the agent can fix its arguments and call again.
|
|
67
|
+
|
|
68
|
+
## The contract resource
|
|
69
|
+
|
|
70
|
+
The server exposes the Agent Contract as the MCP resource `aventara://contract`: every resource, its fields and their
|
|
71
|
+
types, what can be filtered, selected, created and updated, and the request limits. The tool descriptions and the
|
|
72
|
+
server's instructions tell the agent to read it first.
|
|
73
|
+
|
|
74
|
+
## Write safety
|
|
75
|
+
|
|
76
|
+
What an agent can do is decided where everything else is: exposure (the `agent` layer, which can only narrow the layer
|
|
77
|
+
it extends) and guards. A guard can tell an agent's call by its origin:
|
|
78
|
+
|
|
79
|
+
```ts
|
|
80
|
+
const humansOnly: AvGuard = (ctx) => ctx.$origin !== "agent";
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
The tool hints (`readOnlyHint`, `destructiveHint`) are hints for the client; they enforce nothing.
|
|
84
|
+
|
|
85
|
+
## Authorization
|
|
86
|
+
|
|
87
|
+
With `mcp.authorization`, the endpoint is an OAuth 2.1 protected resource. It never issues tokens: your authorization
|
|
88
|
+
server does.
|
|
89
|
+
|
|
90
|
+
```ts
|
|
91
|
+
import { createRemoteJWKSet, jwtVerify } from "jose";
|
|
92
|
+
|
|
93
|
+
const jwks = createRemoteJWKSet(new URL("https://auth.example.com/.well-known/jwks.json"));
|
|
94
|
+
|
|
95
|
+
mcp: {
|
|
96
|
+
path: "/mcp",
|
|
97
|
+
authorization: {
|
|
98
|
+
servers: ["https://auth.example.com"],
|
|
99
|
+
verify: async (token) => {
|
|
100
|
+
try {
|
|
101
|
+
const { payload } = await jwtVerify(token, jwks, {
|
|
102
|
+
issuer: "https://auth.example.com",
|
|
103
|
+
audience: "https://api.example.com/mcp",
|
|
104
|
+
});
|
|
105
|
+
return payload;
|
|
106
|
+
} catch {
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
},
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
Each server is an https URL. One on your own machine may be http instead, so a local setup needs no TLS:
|
|
115
|
+
`http://127.0.0.1:4000` or `http://[::1]:4000`, with any port and path. That is the whole list. Use the address, not
|
|
116
|
+
`localhost`: a name is looked up, and `localhost` can resolve somewhere else (RFC 8252, section 8.3), so
|
|
117
|
+
`http://localhost:4000` is refused with the spelling to use, `http://127.0.0.1:4000`. `0.0.0.0`, `[::]`, other
|
|
118
|
+
`127.x` addresses, IPv4-mapped addresses, names such as `auth.localhost` and URLs with credentials are refused like
|
|
119
|
+
any other http URL. Write the URL the way a browser would show it: `http://127.1:4000` is refused, and the error gives
|
|
120
|
+
the spelling to use. No server URL, https included, may have a query or fragment (an issuer has neither), an empty
|
|
121
|
+
path segment (`//`) or port 0.
|
|
122
|
+
|
|
123
|
+
An http authorization server is for local development only. Tokens and authorization codes cross it unencrypted, and
|
|
124
|
+
only clients on the same machine can reach it. Deploy with an https server.
|
|
125
|
+
|
|
126
|
+
- `GET /.well-known/oauth-protected-resource/mcp` answers the protected-resource metadata (RFC 9728): the endpoint's
|
|
127
|
+
URL as `resource`, your `servers` as `authorization_servers`, and `bearer_methods_supported: ["header"]`.
|
|
128
|
+
- A request without `Authorization: Bearer <token>` is `401` with `WWW-Authenticate: Bearer resource_metadata="…"`
|
|
129
|
+
naming that metadata, which is how an MCP client discovers where to sign in. As RFC 6750 asks, it carries no error
|
|
130
|
+
code: the request had no token to be wrong.
|
|
131
|
+
- Each token goes to `verify`. `null` (or `undefined`, or a throw) is `401` with `error="invalid_token"`. A `verify`
|
|
132
|
+
that throws is also reported to your `diagnostics` sink (an `AvMcpDiagnostic` holding the error), so an outage of
|
|
133
|
+
your token check shows in your logs rather than as a run of rejected agents. Anything else lets the request in, and
|
|
134
|
+
what `verify` returned is the request's `ctx.$state.mcp.claims`, beside what the host's `state` option seeds. Declare
|
|
135
|
+
its type with the rest of your state:
|
|
136
|
+
|
|
137
|
+
```ts
|
|
138
|
+
declare module "@aventara/core" {
|
|
139
|
+
interface AvState {
|
|
140
|
+
mcp?: { claims: JWTPayload };
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
The endpoint's URL comes from the request as your platform reports it, so behind a proxy set Express's `trust proxy`
|
|
146
|
+
or Fastify's `trustProxy` for `https` and the public host to appear in the metadata.
|
|
147
|
+
|
|
148
|
+
## Without authorization
|
|
149
|
+
|
|
150
|
+
An endpoint without `authorization` takes no token, so it answers callers on the same machine only: a loopback peer
|
|
151
|
+
address, no proxy forwarding header (`Forwarded`, `X-Forwarded-For`, `X-Real-IP`), a loopback `Host` (`localhost`,
|
|
152
|
+
`127.x.x.x` or `[::1]`, any port), and no `Origin` header but a loopback one. Every other caller gets `403`. The `Host`
|
|
153
|
+
rule closes DNS rebinding: a page whose domain is rebound to `127.0.0.1` still sends its own domain as `Host`. An HTTP/2
|
|
154
|
+
caller sends `:authority` instead of `Host`, so the open endpoint refuses it too; serve it over HTTP/1.1, or configure
|
|
155
|
+
`authorization`. This is for local development and for an agent running beside the
|
|
156
|
+
application. To serve remote agents, configure `authorization`.
|
|
157
|
+
|
|
158
|
+
## The transport
|
|
159
|
+
|
|
160
|
+
Streamable HTTP, stateless: every `POST` is answered on its own with a JSON response, and no session is kept. `GET` and
|
|
161
|
+
`DELETE` answer `405`. A request body is limited to the agent layer's `maxRequestBytes`.
|
|
162
|
+
|
|
163
|
+
## License
|
|
164
|
+
|
|
165
|
+
PolyForm Shield 1.0.0 with an additional permission. It is free to use, including in commercial applications, but you
|
|
166
|
+
may not use it to build a product that competes with Aventara itself. See `LICENSE` and
|
|
167
|
+
`LICENSE-ADDITIONAL-PERMISSION.md`.
|
package/dist/av-mcp.d.ts
ADDED
package/dist/av-mcp.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { bind } from "./mcp.binder.js";
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { AvMcpEndpoint } from "@aventara/core";
|
|
2
|
+
import type { AvProtocolResponse } from "@aventara/core/protocol";
|
|
3
|
+
/** The authorization `mcp.authorization` configures. */
|
|
4
|
+
type EndpointAuthorization = NonNullable<AvMcpEndpoint["authorization"]>;
|
|
5
|
+
/** What a request to the endpoint is let through with, or the answer that refuses it. */
|
|
6
|
+
export type EndpointAccess = {
|
|
7
|
+
readonly ok: true;
|
|
8
|
+
/** What `verify` resolved the token to; absent on an open endpoint. */
|
|
9
|
+
readonly caller?: {
|
|
10
|
+
readonly claims: unknown;
|
|
11
|
+
};
|
|
12
|
+
} | {
|
|
13
|
+
readonly ok: false;
|
|
14
|
+
readonly response: AvProtocolResponse;
|
|
15
|
+
};
|
|
16
|
+
/** The protected-resource metadata path for an endpoint at `endpointPath` (canonical, `""` at the root). */
|
|
17
|
+
export declare function metadataPathOf(endpointPath: string): string;
|
|
18
|
+
/** One JSON answer. */
|
|
19
|
+
export declare function jsonAnswer(status: number, body: unknown, headers?: Readonly<Record<string, string>>): AvProtocolResponse;
|
|
20
|
+
/**
|
|
21
|
+
* The protected-resource metadata document (RFC 9728 §2): the endpoint's URL as
|
|
22
|
+
* `resource`, the configured servers, and the one bearer method the endpoint
|
|
23
|
+
* reads, the `Authorization` header. Public, and readable from any origin.
|
|
24
|
+
*/
|
|
25
|
+
export declare function metadataAnswer(method: string, origin: string, endpointPath: string, authorization: EndpointAuthorization): AvProtocolResponse;
|
|
26
|
+
/**
|
|
27
|
+
* A protected endpoint's check: the request's bearer token, verified. No bearer
|
|
28
|
+
* token, one `verify` rejects (`null`, `undefined`) and a `verify` that throws
|
|
29
|
+
* are each `401`; a good one passes with what `verify` resolved it to. A throw
|
|
30
|
+
* is handed to `reportFailure` (the diagnostics sink) as well.
|
|
31
|
+
*/
|
|
32
|
+
export declare function authorizedAccess(authorizationHeader: string | undefined, origin: string, endpointPath: string, authorization: EndpointAuthorization, reportFailure: (error: unknown) => void): Promise<EndpointAccess>;
|
|
33
|
+
/** An open endpoint's check: the caller is on this machine. */
|
|
34
|
+
export declare function loopbackAccess(remoteAddress: string | undefined, header: (name: string) => string | undefined): EndpointAccess;
|
|
35
|
+
export {};
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
const METADATA_PREFIX = "/.well-known/oauth-protected-resource";
|
|
2
|
+
export function metadataPathOf(endpointPath) {
|
|
3
|
+
return `${METADATA_PREFIX}${endpointPath}`;
|
|
4
|
+
}
|
|
5
|
+
export function jsonAnswer(status, body, headers = {}) {
|
|
6
|
+
return {
|
|
7
|
+
status,
|
|
8
|
+
headers: { "Content-Type": "application/json", ...headers },
|
|
9
|
+
body: JSON.stringify(body),
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
export function metadataAnswer(method, origin, endpointPath, authorization) {
|
|
13
|
+
if (method !== "GET") {
|
|
14
|
+
return jsonAnswer(405, { error: "method_not_allowed", error_description: "Use GET." }, { Allow: "GET" });
|
|
15
|
+
}
|
|
16
|
+
return jsonAnswer(200, {
|
|
17
|
+
resource: `${origin}${endpointPath}`,
|
|
18
|
+
authorization_servers: [...authorization.servers],
|
|
19
|
+
bearer_methods_supported: ["header"],
|
|
20
|
+
}, { "Access-Control-Allow-Origin": "*", "Cache-Control": "no-cache" });
|
|
21
|
+
}
|
|
22
|
+
function bearerTokenOf(header) {
|
|
23
|
+
const match = /^Bearer[ \t]+([^ \t].*?)[ \t]*$/i.exec(header ?? "");
|
|
24
|
+
return match?.[1];
|
|
25
|
+
}
|
|
26
|
+
function challenge(origin, endpointPath, invalid) {
|
|
27
|
+
const metadata = `resource_metadata="${origin}${metadataPathOf(endpointPath)}"`;
|
|
28
|
+
if (invalid === undefined) {
|
|
29
|
+
return jsonAnswer(401, {
|
|
30
|
+
error: "unauthorized",
|
|
31
|
+
error_description: "This MCP endpoint requires a bearer token in the Authorization header.",
|
|
32
|
+
}, { "WWW-Authenticate": `Bearer ${metadata}` });
|
|
33
|
+
}
|
|
34
|
+
return jsonAnswer(401, { error: "invalid_token", error_description: invalid.description }, {
|
|
35
|
+
"WWW-Authenticate": `Bearer error="invalid_token", error_description="${invalid.description}", ${metadata}`,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
export async function authorizedAccess(authorizationHeader, origin, endpointPath, authorization, reportFailure) {
|
|
39
|
+
const token = bearerTokenOf(authorizationHeader);
|
|
40
|
+
if (token === undefined) {
|
|
41
|
+
return { ok: false, response: challenge(origin, endpointPath) };
|
|
42
|
+
}
|
|
43
|
+
let claims;
|
|
44
|
+
try {
|
|
45
|
+
claims = await authorization.verify(token);
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
reportFailure(error);
|
|
49
|
+
claims = null;
|
|
50
|
+
}
|
|
51
|
+
if (claims === null || claims === undefined) {
|
|
52
|
+
return {
|
|
53
|
+
ok: false,
|
|
54
|
+
response: challenge(origin, endpointPath, {
|
|
55
|
+
description: "The access token is invalid",
|
|
56
|
+
}),
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
return { ok: true, caller: { claims } };
|
|
60
|
+
}
|
|
61
|
+
const FORWARDING_HEADERS = ["forwarded", "x-forwarded-for", "x-real-ip"];
|
|
62
|
+
function isLoopbackAddress(address) {
|
|
63
|
+
if (address === undefined) {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
const v4 = address.startsWith("::ffff:") ? address.slice(7) : address;
|
|
67
|
+
return address === "::1" || /^127\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(v4);
|
|
68
|
+
}
|
|
69
|
+
function isLoopbackOrigin(origin) {
|
|
70
|
+
try {
|
|
71
|
+
const { hostname } = new URL(origin);
|
|
72
|
+
return (hostname === "localhost" ||
|
|
73
|
+
hostname === "[::1]" ||
|
|
74
|
+
isLoopbackAddress(hostname));
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
const LOOPBACK_ONLY = "This MCP endpoint has no authorization, so it answers callers on this machine only. Configure mcp.authorization to serve remote agents.";
|
|
81
|
+
function isLoopbackHost(host) {
|
|
82
|
+
if (host === undefined || host === "" || /[\s/?#@\\,]/.test(host)) {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
try {
|
|
86
|
+
const { hostname } = new URL(`http://${host}`);
|
|
87
|
+
return (hostname === "localhost" ||
|
|
88
|
+
hostname === "[::1]" ||
|
|
89
|
+
isLoopbackAddress(hostname));
|
|
90
|
+
}
|
|
91
|
+
catch {
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
export function loopbackAccess(remoteAddress, header) {
|
|
96
|
+
const origin = header("origin");
|
|
97
|
+
const local = isLoopbackAddress(remoteAddress) &&
|
|
98
|
+
FORWARDING_HEADERS.every((name) => header(name) === undefined) &&
|
|
99
|
+
isLoopbackHost(header("host")) &&
|
|
100
|
+
(origin === undefined || isLoopbackOrigin(origin));
|
|
101
|
+
return local
|
|
102
|
+
? { ok: true }
|
|
103
|
+
: {
|
|
104
|
+
ok: false,
|
|
105
|
+
response: jsonAnswer(403, {
|
|
106
|
+
error: "forbidden",
|
|
107
|
+
error_description: LOOPBACK_ONLY,
|
|
108
|
+
}),
|
|
109
|
+
};
|
|
110
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@aventara/mcp`: the MCP server for an Aventara application. A host (the
|
|
3
|
+
* Nest module) mounts it at `framework.mcp.path`; it mounts nothing itself.
|
|
4
|
+
*/
|
|
5
|
+
export * as AvMcp from "./av-mcp.js";
|
|
6
|
+
export type { AvMcpBinding, AvMcpRequest } from "./mcp.binder.js";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * as AvMcp from "./av-mcp.js";
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `JSON.stringify(value)`'s text for JSON data (what an MCP message parses to),
|
|
3
|
+
* written without recursing on its depth: object members in their own order,
|
|
4
|
+
* a member whose value has no JSON form left out, and such a value in a list
|
|
5
|
+
* written `null`, as `JSON.stringify` does.
|
|
6
|
+
*/
|
|
7
|
+
export declare function jsonTextOf(value: unknown): string;
|