instant-mcp 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +55 -2
- package/dist/catalog/index.d.ts +89 -0
- package/dist/catalog/index.js +230 -0
- package/dist/catalog/index.js.map +1 -0
- package/dist/cli/main.d.ts +2 -0
- package/dist/cli/main.js +11 -0
- package/dist/cli/main.js.map +1 -0
- package/dist/cli/run.d.ts +14 -0
- package/dist/cli/run.js +204 -0
- package/dist/cli/run.js.map +1 -0
- package/dist/cli/version.d.ts +2 -0
- package/dist/cli/version.js +8 -0
- package/dist/cli/version.js.map +1 -0
- package/dist/config/errors.d.ts +16 -0
- package/dist/config/errors.js +16 -0
- package/dist/config/errors.js.map +1 -0
- package/dist/config/index.d.ts +3 -0
- package/dist/config/index.js +5 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config/loader.d.ts +44 -0
- package/dist/config/loader.js +215 -0
- package/dist/config/loader.js.map +1 -0
- package/dist/config/schema.d.ts +84 -0
- package/dist/config/schema.js +145 -0
- package/dist/config/schema.js.map +1 -0
- package/dist/executor/address.d.ts +5 -0
- package/dist/executor/address.js +83 -0
- package/dist/executor/address.js.map +1 -0
- package/dist/executor/arguments.d.ts +45 -0
- package/dist/executor/arguments.js +236 -0
- package/dist/executor/arguments.js.map +1 -0
- package/dist/executor/defaults.d.ts +19 -0
- package/dist/executor/defaults.js +41 -0
- package/dist/executor/defaults.js.map +1 -0
- package/dist/executor/executor.d.ts +36 -0
- package/dist/executor/executor.js +168 -0
- package/dist/executor/executor.js.map +1 -0
- package/dist/executor/index.d.ts +8 -0
- package/dist/executor/index.js +11 -0
- package/dist/executor/index.js.map +1 -0
- package/dist/executor/node-http-client.d.ts +17 -0
- package/dist/executor/node-http-client.js +144 -0
- package/dist/executor/node-http-client.js.map +1 -0
- package/dist/executor/own.d.ts +6 -0
- package/dist/executor/own.js +14 -0
- package/dist/executor/own.js.map +1 -0
- package/dist/executor/request.d.ts +28 -0
- package/dist/executor/request.js +187 -0
- package/dist/executor/request.js.map +1 -0
- package/dist/executor/result.d.ts +23 -0
- package/dist/executor/result.js +78 -0
- package/dist/executor/result.js.map +1 -0
- package/dist/executor/types.d.ts +87 -0
- package/dist/executor/types.js +10 -0
- package/dist/executor/types.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/openapi/index.d.ts +5 -0
- package/dist/openapi/index.js +8 -0
- package/dist/openapi/index.js.map +1 -0
- package/dist/openapi/normalize.d.ts +19 -0
- package/dist/openapi/normalize.js +403 -0
- package/dist/openapi/normalize.js.map +1 -0
- package/dist/openapi/parse.d.ts +10 -0
- package/dist/openapi/parse.js +96 -0
- package/dist/openapi/parse.js.map +1 -0
- package/dist/openapi/refs.d.ts +67 -0
- package/dist/openapi/refs.js +315 -0
- package/dist/openapi/refs.js.map +1 -0
- package/dist/openapi/sanitize.d.ts +13 -0
- package/dist/openapi/sanitize.js +61 -0
- package/dist/openapi/sanitize.js.map +1 -0
- package/dist/openapi/source.d.ts +13 -0
- package/dist/openapi/source.js +17 -0
- package/dist/openapi/source.js.map +1 -0
- package/dist/openapi/types.d.ts +77 -0
- package/dist/openapi/types.js +20 -0
- package/dist/openapi/types.js.map +1 -0
- package/dist/policy/index.d.ts +34 -0
- package/dist/policy/index.js +43 -0
- package/dist/policy/index.js.map +1 -0
- package/dist/runtime/index.d.ts +1 -0
- package/dist/runtime/index.js +4 -0
- package/dist/runtime/index.js.map +1 -0
- package/dist/runtime/runtime.d.ts +73 -0
- package/dist/runtime/runtime.js +166 -0
- package/dist/runtime/runtime.js.map +1 -0
- package/dist/transport/index.d.ts +2 -0
- package/dist/transport/index.js +6 -0
- package/dist/transport/index.js.map +1 -0
- package/dist/transport/server.d.ts +15 -0
- package/dist/transport/server.js +35 -0
- package/dist/transport/server.js.map +1 -0
- package/dist/transport/stdio.d.ts +22 -0
- package/dist/transport/stdio.js +40 -0
- package/dist/transport/stdio.js.map +1 -0
- package/package.json +56 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing
|
|
141
|
+
the origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 AI Product Labs
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,56 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Instant MCP
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Instant MCP is an open-source CLI and runtime for turning configured APIs into tools that MCP-compatible agents can discover and call. It is a shared, reusable utility for developers and technical users who want to connect an agent to an API they can access.
|
|
4
|
+
|
|
5
|
+
The project is designed to run locally beside an agent and in operator-managed environments. Configuration is explicit and portable, so the same API connection can be inspected, validated, and served across supported deployment modes.
|
|
6
|
+
|
|
7
|
+
## Product direction
|
|
8
|
+
|
|
9
|
+
- **CLI for operators:** initialize, inspect, validate, test, and run configurations from the command line.
|
|
10
|
+
- **MCP for agents:** connect the runtime to a local agent over stdio or to a remote-capable client through Streamable HTTP.
|
|
11
|
+
- **Self-hostable:** use the same runtime configuration in a Docker container and deploy it on a container platform of choice.
|
|
12
|
+
- **Spec-led:** start from OpenAPI descriptions and expose selected operations as tools.
|
|
13
|
+
- **Safe by configuration:** make exposed operations explicit; keep write access and result caching opt-in.
|
|
14
|
+
- **Reusable by design:** keep runtime capabilities behind small interfaces so operators can adapt configuration, credentials, caching, and telemetry to their environment.
|
|
15
|
+
|
|
16
|
+
## Quick start
|
|
17
|
+
|
|
18
|
+
Instant MCP is on npm as [`instant-mcp`](https://www.npmjs.com/package/instant-mcp). With Node.js 22.12 or later, there is nothing to build:
|
|
19
|
+
|
|
20
|
+
```sh
|
|
21
|
+
npx instant-mcp --help
|
|
22
|
+
npx instant-mcp validate --config /path/to/instant-mcp.yaml
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
An MCP client starts the server with the same package:
|
|
26
|
+
|
|
27
|
+
```json
|
|
28
|
+
{
|
|
29
|
+
"mcpServers": {
|
|
30
|
+
"my-api": {
|
|
31
|
+
"command": "npx",
|
|
32
|
+
"args": ["-y", "instant-mcp", "serve", "--config", "/path/to/instant-mcp.yaml"]
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
**Start here:** [Getting started](docs/getting-started.md) takes you from an empty machine to an agent calling the US National Weather Service API, and has an offline example that runs entirely on your machine.
|
|
39
|
+
|
|
40
|
+
## Project status
|
|
41
|
+
|
|
42
|
+
Early. `instant-mcp validate` and `instant-mcp serve` load a [configuration file](docs/configuration.md) and a local OpenAPI 3.0 or 3.1 document, and serve the allowlisted operations as MCP tools over stdio. Releases are listed in the [changelog](CHANGELOG.md); until 1.0 the configuration schema may still change. Streamable HTTP, the container image, and the other CLI commands are planned; see [the roadmap](docs/roadmap.md).
|
|
43
|
+
|
|
44
|
+
## Architecture
|
|
45
|
+
|
|
46
|
+
The runtime is intended to remain portable across transports and deployment models. Local files and environment variables are the initial configuration sources. A separate, optional builder MCP may later help an agent inspect API descriptions and prepare configuration. The execution core stays independent of any particular cloud provider or deployment environment.
|
|
47
|
+
|
|
48
|
+
See [architecture decisions](docs/architecture.md) and [product direction](docs/product-direction.md).
|
|
49
|
+
|
|
50
|
+
## Contributing
|
|
51
|
+
|
|
52
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md) for how feature specs are organized and how releases are made. To run from a checkout, see [Build from source](docs/getting-started.md#build-from-source).
|
|
53
|
+
|
|
54
|
+
## License
|
|
55
|
+
|
|
56
|
+
Instant MCP is licensed under the Apache License, Version 2.0. See [LICENSE](LICENSE).
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import type { OperationPolicy } from "../config/index.js";
|
|
2
|
+
import type { ApiDescription, JsonSchema, NormalizedOperation, ParameterLocation } from "../openapi/index.js";
|
|
3
|
+
import { type PolicyDenialReason, type PolicyProvider } from "../policy/index.js";
|
|
4
|
+
/** MCP tool names: 1-128 of A-Z a-z 0-9 _ - . (case-sensitive). */
|
|
5
|
+
export declare const TOOL_NAME_PATTERN: RegExp;
|
|
6
|
+
/** Longest MCP tool name. */
|
|
7
|
+
export declare const MAX_TOOL_NAME_LENGTH = 128;
|
|
8
|
+
/**
|
|
9
|
+
* Derive the MCP tool name for an operationId: every character outside
|
|
10
|
+
* `[A-Za-z0-9_.-]` becomes `_` (one per code point), then the result is cut
|
|
11
|
+
* to 128 characters. An operationId that is already a valid tool name is
|
|
12
|
+
* returned unchanged.
|
|
13
|
+
*/
|
|
14
|
+
export declare function toolNameFor(operationId: string): string;
|
|
15
|
+
/** Upper bound on a generated tool description, in characters. */
|
|
16
|
+
export declare const MAX_TOOL_DESCRIPTION_LENGTH = 4096;
|
|
17
|
+
/** Argument that carries the JSON request body, when an operation has one. */
|
|
18
|
+
export declare const BODY_ARGUMENT = "body";
|
|
19
|
+
/** JSON Schema object for a tool's arguments, as MCP `tools/list` reports it. */
|
|
20
|
+
export interface ToolInputSchema {
|
|
21
|
+
readonly type: "object";
|
|
22
|
+
readonly properties: {
|
|
23
|
+
readonly [argument: string]: JsonSchema;
|
|
24
|
+
};
|
|
25
|
+
readonly required?: readonly string[];
|
|
26
|
+
readonly additionalProperties: false;
|
|
27
|
+
}
|
|
28
|
+
/** MCP tool annotations. Descriptive hints only; never used to enforce anything. */
|
|
29
|
+
export interface ToolAnnotations {
|
|
30
|
+
readonly title?: string;
|
|
31
|
+
readonly readOnlyHint: boolean;
|
|
32
|
+
readonly destructiveHint: boolean;
|
|
33
|
+
readonly idempotentHint: boolean;
|
|
34
|
+
readonly openWorldHint: boolean;
|
|
35
|
+
}
|
|
36
|
+
/** Where one tool argument goes in the upstream request. */
|
|
37
|
+
export type ArgumentBinding = {
|
|
38
|
+
readonly argument: string;
|
|
39
|
+
readonly in: ParameterLocation;
|
|
40
|
+
/** Parameter name as written in the API description. */
|
|
41
|
+
readonly name: string;
|
|
42
|
+
} | {
|
|
43
|
+
readonly argument: string;
|
|
44
|
+
readonly in: "body";
|
|
45
|
+
};
|
|
46
|
+
export interface CatalogTool {
|
|
47
|
+
/** MCP tool name, derived from the operationId by {@link toolNameFor}. */
|
|
48
|
+
readonly name: string;
|
|
49
|
+
readonly title?: string;
|
|
50
|
+
readonly description: string;
|
|
51
|
+
readonly inputSchema: ToolInputSchema;
|
|
52
|
+
readonly annotations: ToolAnnotations;
|
|
53
|
+
/** The operation this tool invokes. */
|
|
54
|
+
readonly operation: NormalizedOperation;
|
|
55
|
+
/** How each argument maps onto the request, in a stable order. */
|
|
56
|
+
readonly bindings: readonly ArgumentBinding[];
|
|
57
|
+
}
|
|
58
|
+
/** An allowlisted operation that policy kept out of the catalog. */
|
|
59
|
+
export interface ExcludedOperation {
|
|
60
|
+
readonly operationId: string;
|
|
61
|
+
readonly reason: PolicyDenialReason;
|
|
62
|
+
}
|
|
63
|
+
export interface ToolCatalog {
|
|
64
|
+
/** Sorted by name. */
|
|
65
|
+
readonly tools: readonly CatalogTool[];
|
|
66
|
+
/** Allowlisted operations policy denied (for example writes without `allowWrite`). */
|
|
67
|
+
readonly excluded: readonly ExcludedOperation[];
|
|
68
|
+
get(name: string): CatalogTool | undefined;
|
|
69
|
+
}
|
|
70
|
+
/** The catalog cannot be built from this description and configuration. */
|
|
71
|
+
export declare class CatalogError extends Error {
|
|
72
|
+
readonly issues: readonly string[];
|
|
73
|
+
readonly name = "CatalogError";
|
|
74
|
+
constructor(issues: readonly string[]);
|
|
75
|
+
}
|
|
76
|
+
export interface BuildToolCatalogOptions {
|
|
77
|
+
readonly description: ApiDescription;
|
|
78
|
+
/** The validated allowlist (`RuntimeConfig.operations`). */
|
|
79
|
+
readonly operations: ReadonlyMap<string, OperationPolicy>;
|
|
80
|
+
/** Defaults to an `AllowlistPolicyProvider` over `operations`. */
|
|
81
|
+
readonly policy?: PolicyProvider;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Build the tool catalog. Throws `CatalogError` when an allowlisted
|
|
85
|
+
* operationId is not in the description, two allowlisted operationIds derive
|
|
86
|
+
* the same tool name, or an allowlisted operation cannot be turned into a
|
|
87
|
+
* tool.
|
|
88
|
+
*/
|
|
89
|
+
export declare function buildToolCatalog(options: BuildToolCatalogOptions): ToolCatalog;
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import { MAX_DESCRIPTION_LENGTH, MAX_SUMMARY_LENGTH, quote, sanitizeLine, sanitizeText, } from "../openapi/sanitize.js";
|
|
2
|
+
import { AllowlistPolicyProvider, } from "../policy/index.js";
|
|
3
|
+
/** MCP tool names: 1-128 of A-Z a-z 0-9 _ - . (case-sensitive). */
|
|
4
|
+
export const TOOL_NAME_PATTERN = /^[A-Za-z0-9_.-]{1,128}$/;
|
|
5
|
+
/** Longest MCP tool name. */
|
|
6
|
+
export const MAX_TOOL_NAME_LENGTH = 128;
|
|
7
|
+
/**
|
|
8
|
+
* Derive the MCP tool name for an operationId: every character outside
|
|
9
|
+
* `[A-Za-z0-9_.-]` becomes `_` (one per code point), then the result is cut
|
|
10
|
+
* to 128 characters. An operationId that is already a valid tool name is
|
|
11
|
+
* returned unchanged.
|
|
12
|
+
*/
|
|
13
|
+
export function toolNameFor(operationId) {
|
|
14
|
+
return Array.from(operationId, (ch) => /^[A-Za-z0-9_.-]$/.test(ch) ? ch : "_")
|
|
15
|
+
.join("")
|
|
16
|
+
.slice(0, MAX_TOOL_NAME_LENGTH);
|
|
17
|
+
}
|
|
18
|
+
/** Upper bound on a generated tool description, in characters. */
|
|
19
|
+
export const MAX_TOOL_DESCRIPTION_LENGTH = MAX_DESCRIPTION_LENGTH;
|
|
20
|
+
/** Argument that carries the JSON request body, when an operation has one. */
|
|
21
|
+
export const BODY_ARGUMENT = "body";
|
|
22
|
+
/** The catalog cannot be built from this description and configuration. */
|
|
23
|
+
export class CatalogError extends Error {
|
|
24
|
+
issues;
|
|
25
|
+
name = "CatalogError";
|
|
26
|
+
constructor(issues) {
|
|
27
|
+
super(`Cannot build the tool catalog:\n${issues.map((i) => ` - ${i}`).join("\n")}`);
|
|
28
|
+
this.issues = issues;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Build the tool catalog. Throws `CatalogError` when an allowlisted
|
|
33
|
+
* operationId is not in the description, two allowlisted operationIds derive
|
|
34
|
+
* the same tool name, or an allowlisted operation cannot be turned into a
|
|
35
|
+
* tool.
|
|
36
|
+
*/
|
|
37
|
+
export function buildToolCatalog(options) {
|
|
38
|
+
const { description, operations } = options;
|
|
39
|
+
const policy = options.policy ?? new AllowlistPolicyProvider(operations);
|
|
40
|
+
const issues = [];
|
|
41
|
+
const byId = new Map();
|
|
42
|
+
for (const operation of description.operations) {
|
|
43
|
+
if (byId.has(operation.operationId)) {
|
|
44
|
+
if (operations.has(operation.operationId))
|
|
45
|
+
issues.push(`operationId ${quote(operation.operationId)} appears more than once in the API description`);
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
byId.set(operation.operationId, operation);
|
|
49
|
+
}
|
|
50
|
+
const missing = [...operations.keys()].filter((id) => !byId.has(id)).sort();
|
|
51
|
+
for (const id of missing) {
|
|
52
|
+
issues.push(`allowlisted operationId ${quote(id)} is not in the API description (or was skipped while loading it)`);
|
|
53
|
+
}
|
|
54
|
+
// Two allowlisted operationIds that derive the same tool name are a
|
|
55
|
+
// configuration error. Checked before policy, so the outcome never depends
|
|
56
|
+
// on allowWrite, and never resolved with a suffix, so names stay stable as
|
|
57
|
+
// the API description grows.
|
|
58
|
+
const byName = new Map();
|
|
59
|
+
for (const id of [...operations.keys()].sort()) {
|
|
60
|
+
if (!byId.has(id))
|
|
61
|
+
continue;
|
|
62
|
+
const name = toolNameFor(id);
|
|
63
|
+
const ids = byName.get(name);
|
|
64
|
+
if (ids === undefined)
|
|
65
|
+
byName.set(name, [id]);
|
|
66
|
+
else
|
|
67
|
+
ids.push(id);
|
|
68
|
+
}
|
|
69
|
+
for (const [name, ids] of byName) {
|
|
70
|
+
if (ids.length > 1)
|
|
71
|
+
issues.push(`allowlisted operationIds ${ids.map((id) => quote(id)).join(", ")} all map to tool name ${quote(name)}; allowlist only one of them`);
|
|
72
|
+
}
|
|
73
|
+
const tools = [];
|
|
74
|
+
const excluded = [];
|
|
75
|
+
for (const id of [...operations.keys()].sort()) {
|
|
76
|
+
const operation = byId.get(id);
|
|
77
|
+
if (operation === undefined)
|
|
78
|
+
continue;
|
|
79
|
+
const decision = policy.evaluate(operation);
|
|
80
|
+
if (!decision.allowed) {
|
|
81
|
+
excluded.push({ operationId: id, reason: decision.reason });
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
const tool = buildTool(operation, issues);
|
|
85
|
+
if (tool !== undefined)
|
|
86
|
+
tools.push(tool);
|
|
87
|
+
}
|
|
88
|
+
if (issues.length > 0)
|
|
89
|
+
throw new CatalogError(issues);
|
|
90
|
+
tools.sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0));
|
|
91
|
+
const index = new Map(tools.map((t) => [t.name, t]));
|
|
92
|
+
return Object.freeze({
|
|
93
|
+
tools: Object.freeze(tools),
|
|
94
|
+
excluded: Object.freeze(excluded),
|
|
95
|
+
get: (name) => index.get(name),
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
function buildTool(operation, issues) {
|
|
99
|
+
const name = toolNameFor(operation.operationId);
|
|
100
|
+
if (!TOOL_NAME_PATTERN.test(name)) {
|
|
101
|
+
issues.push(`operationId ${quote(operation.operationId)} does not yield a valid MCP tool name`);
|
|
102
|
+
return undefined;
|
|
103
|
+
}
|
|
104
|
+
const bindings = bindArguments(operation, issues);
|
|
105
|
+
if (bindings === undefined)
|
|
106
|
+
return undefined;
|
|
107
|
+
const title = sanitizeLine(operation.summary, MAX_SUMMARY_LENGTH);
|
|
108
|
+
return Object.freeze({
|
|
109
|
+
name,
|
|
110
|
+
...(title === undefined ? {} : { title }),
|
|
111
|
+
description: toolDescription(operation, title),
|
|
112
|
+
inputSchema: inputSchema(operation, bindings),
|
|
113
|
+
annotations: annotations(operation.method, operation.isWrite, title),
|
|
114
|
+
operation,
|
|
115
|
+
bindings: Object.freeze(bindings),
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Parameters keep their own name as the argument name. When two locations
|
|
120
|
+
* share a name (or a parameter is called `body` and there is a request body),
|
|
121
|
+
* each clashing parameter is qualified as `<in>.<name>`.
|
|
122
|
+
*/
|
|
123
|
+
function bindArguments(operation, issues) {
|
|
124
|
+
const counts = new Map();
|
|
125
|
+
const bump = (n) => counts.set(n, (counts.get(n) ?? 0) + 1);
|
|
126
|
+
for (const p of operation.parameters)
|
|
127
|
+
bump(p.name);
|
|
128
|
+
if (operation.requestBody !== undefined)
|
|
129
|
+
bump(BODY_ARGUMENT);
|
|
130
|
+
const bindings = operation.parameters.map((p) => ({
|
|
131
|
+
argument: (counts.get(p.name) ?? 0) > 1 ? `${p.in}.${p.name}` : p.name,
|
|
132
|
+
in: p.in,
|
|
133
|
+
name: p.name,
|
|
134
|
+
}));
|
|
135
|
+
if (operation.requestBody !== undefined)
|
|
136
|
+
bindings.push({ argument: BODY_ARGUMENT, in: "body" });
|
|
137
|
+
const seen = new Set();
|
|
138
|
+
for (const b of bindings) {
|
|
139
|
+
if (seen.has(b.argument)) {
|
|
140
|
+
issues.push(`operation ${quote(operation.operationId)} has more than one argument named ${quote(b.argument)}`);
|
|
141
|
+
return undefined;
|
|
142
|
+
}
|
|
143
|
+
seen.add(b.argument);
|
|
144
|
+
}
|
|
145
|
+
return bindings;
|
|
146
|
+
}
|
|
147
|
+
function inputSchema(operation, bindings) {
|
|
148
|
+
const entries = [];
|
|
149
|
+
const required = [];
|
|
150
|
+
operation.parameters.forEach((parameter, i) => {
|
|
151
|
+
const argument = bindings[i]?.argument ?? parameter.name;
|
|
152
|
+
entries.push([argument, parameterSchema(parameter)]);
|
|
153
|
+
if (parameter.required || parameter.in === "path")
|
|
154
|
+
required.push(argument);
|
|
155
|
+
});
|
|
156
|
+
const body = operation.requestBody;
|
|
157
|
+
if (body !== undefined) {
|
|
158
|
+
entries.push([
|
|
159
|
+
BODY_ARGUMENT,
|
|
160
|
+
withMeta(body.schema, body.description, undefined),
|
|
161
|
+
]);
|
|
162
|
+
if (body.required)
|
|
163
|
+
required.push(BODY_ARGUMENT);
|
|
164
|
+
}
|
|
165
|
+
// Object.fromEntries defines own data properties, so a parameter named
|
|
166
|
+
// `__proto__` stays an ordinary property.
|
|
167
|
+
return deepFreeze({
|
|
168
|
+
type: "object",
|
|
169
|
+
properties: Object.fromEntries(entries),
|
|
170
|
+
...(required.length > 0 ? { required } : {}),
|
|
171
|
+
additionalProperties: false,
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
function parameterSchema(parameter) {
|
|
175
|
+
return withMeta(parameter.schema, parameter.description, parameter.deprecated);
|
|
176
|
+
}
|
|
177
|
+
/** Copy a schema, adding a description and deprecation flag the schema lacks. */
|
|
178
|
+
function withMeta(schema, description, deprecated) {
|
|
179
|
+
if (schema === false)
|
|
180
|
+
return false;
|
|
181
|
+
const copy = schema === true ? {} : structuredClone(schema);
|
|
182
|
+
const text = sanitizeText(description, MAX_DESCRIPTION_LENGTH);
|
|
183
|
+
if (text !== undefined && !Object.hasOwn(copy, "description"))
|
|
184
|
+
copy["description"] = text;
|
|
185
|
+
if (deprecated === true)
|
|
186
|
+
copy["deprecated"] = true;
|
|
187
|
+
return copy;
|
|
188
|
+
}
|
|
189
|
+
function toolDescription(operation, summary) {
|
|
190
|
+
const detail = sanitizeText(operation.description, MAX_DESCRIPTION_LENGTH);
|
|
191
|
+
const parts = [];
|
|
192
|
+
if (operation.deprecated === true)
|
|
193
|
+
parts.push("Deprecated.");
|
|
194
|
+
if (summary !== undefined)
|
|
195
|
+
parts.push(summary);
|
|
196
|
+
if (detail !== undefined && detail !== summary)
|
|
197
|
+
parts.push(detail);
|
|
198
|
+
if (summary === undefined && detail === undefined)
|
|
199
|
+
parts.push(`${operation.method} ${operation.pathTemplate}`);
|
|
200
|
+
return (sanitizeText(parts.join("\n\n"), MAX_TOOL_DESCRIPTION_LENGTH) ??
|
|
201
|
+
`${operation.method} ${operation.pathTemplate}`);
|
|
202
|
+
}
|
|
203
|
+
const DESTRUCTIVE_METHODS = new Set([
|
|
204
|
+
"PUT",
|
|
205
|
+
"PATCH",
|
|
206
|
+
"DELETE",
|
|
207
|
+
]);
|
|
208
|
+
const IDEMPOTENT_WRITE_METHODS = new Set([
|
|
209
|
+
"PUT",
|
|
210
|
+
"DELETE",
|
|
211
|
+
]);
|
|
212
|
+
/** Hints derived from the HTTP method. Policy, not these, decides what runs. */
|
|
213
|
+
function annotations(method, isWrite, title) {
|
|
214
|
+
return Object.freeze({
|
|
215
|
+
...(title === undefined ? {} : { title }),
|
|
216
|
+
readOnlyHint: !isWrite,
|
|
217
|
+
destructiveHint: isWrite && DESTRUCTIVE_METHODS.has(method),
|
|
218
|
+
idempotentHint: !isWrite || IDEMPOTENT_WRITE_METHODS.has(method),
|
|
219
|
+
openWorldHint: true,
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
function deepFreeze(value) {
|
|
223
|
+
if (typeof value === "object" && value !== null && !Object.isFrozen(value)) {
|
|
224
|
+
Object.freeze(value);
|
|
225
|
+
for (const key of Reflect.ownKeys(value))
|
|
226
|
+
deepFreeze(value[key]);
|
|
227
|
+
}
|
|
228
|
+
return value;
|
|
229
|
+
}
|
|
230
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/catalog/index.ts"],"names":[],"mappings":"AAaA,OAAO,EACL,sBAAsB,EACtB,kBAAkB,EAClB,KAAK,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AO;QACtB,eAAe,EAAE,OAAO,IAAI,mBAAmB,CAAC,GAAG,CAAC,MAAM,CAAC;QAC3D,cAAc,EAAE,CAAC,OAAO,IAAI,wBAAwB,CAAC,GAAG,CAAC,MAAM,CAAC;QAChE,aAAa,EAAE,IAAI;KACpB,CAAC,CAAC;AACL,CAAC;AAED,SAAS,UAAU,CAAI,KAAQ;IAC7B,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;QAC3E,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACrB,KAAK,MAAM,GAAG,IAAI,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC;YACtC,UAAU,CAAE,KAAsC,CAAC,GAAG,CAAC,CAAC,CAAC;IAC7D,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
package/dist/cli/main.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { run } from "./run.js";
|
|
3
|
+
run(process.argv.slice(2)).then((code) => {
|
|
4
|
+
process.exitCode = code;
|
|
5
|
+
}, (error) => {
|
|
6
|
+
// Name and message only: no stack, no request data.
|
|
7
|
+
const message = error instanceof Error ? error.message : "unknown error";
|
|
8
|
+
process.stderr.write(`instant-mcp: unexpected error: ${message}\n`);
|
|
9
|
+
process.exitCode = 1;
|
|
10
|
+
});
|
|
11
|
+
//# sourceMappingURL=main.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main.js","sourceRoot":"","sources":["../../src/cli/main.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAE/B,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAC7B,CAAC,IAAI,EAAE,EAAE;IACP,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC;AAC1B,CAAC,EACD,CAAC,KAAc,EAAE,EAAE;IACjB,oDAAoD;IACpD,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe,CAAC;IACzE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,kCAAkC,OAAO,IAAI,CAAC,CAAC;IACpE,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;AACvB,CAAC,CACF,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type TransportAdapter } from "../transport/index.js";
|
|
2
|
+
export interface CliIo {
|
|
3
|
+
stdout: (text: string) => void;
|
|
4
|
+
stderr: (text: string) => void;
|
|
5
|
+
}
|
|
6
|
+
/** Process-level dependencies, injectable for tests. */
|
|
7
|
+
export interface CliDeps {
|
|
8
|
+
readonly env?: Readonly<Record<string, string | undefined>>;
|
|
9
|
+
readonly cwd?: string;
|
|
10
|
+
/** Default: stdio on the current process. */
|
|
11
|
+
readonly transport?: () => TransportAdapter;
|
|
12
|
+
}
|
|
13
|
+
/** Runs the CLI with the given arguments (excluding node and script path) and resolves to an exit code. */
|
|
14
|
+
export declare function run(argv: readonly string[], io?: CliIo, deps?: CliDeps): Promise<number>;
|