@ieranama/discomcp 0.5.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/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ /node_modules
2
+
package/CHANGELOG.md ADDED
@@ -0,0 +1,56 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
+
7
+ ## [Unreleased]
8
+
9
+ ## [0.4.0] - 2026-07-11
10
+
11
+ ### Added
12
+
13
+ - Adaptive exploration: every `execute_probe` result and a new `session_status` tool carry a `gaps` report so the agent can decide how deep to explore. The report is computed purely from in-session state (no extra target calls) and lists unsampled structures, unexecuted safe-read tools, untraversed identifiers (with the tools likely to consume them), sampling hints (schema params like `orderBy`/`pageSize`/`q`/`filter` that enable most-recent/most-relevant sampling), and a pure-count `depth_signal`. DiscoMCP reports; the agent decides when to stop. Hint lists only surface onboarding-allowed tools, so following a gap never leads into a rejected probe.
14
+ - Background-subagent profiling guidance: the MCP `instructions` and the generated `SKILL.md`/`AGENTS.md` now tell a host agent to profile (and refresh) in a non-blocking background subagent, driven by the gap report, so the user's foreground work is never blocked.
15
+
16
+ ## [0.3.0] - 2026-07-11
17
+
18
+ ### Added
19
+
20
+ - `discomcp serve` now runs a real newline-delimited JSON-RPC stdio MCP server, so any MCP client agent can drive profiling directly: `list_targets`, `lookup_target`, `inspect_target`, `execute_probe`, `finalize_profile`, and `generate_skill`. The agent proposes probes; the runtime enforces risk class, argument schema, identifier provenance, budgets, and redaction. No reasoning backend is needed in serve mode.
21
+ - `discomcp lookup <target>` and `DiscoMcp::lookup` gate exploration by catalogue fingerprint: they report an existing matching skill without executing any probe.
22
+ - `ProfilingSession` in `discomcp-core` for step-wise, agent-driven profiling sessions.
23
+
24
+ ### Changed
25
+
26
+ - Tool results are unwrapped from the MCP content envelope before redaction, normalization and inference, so the workspace model describes the target's real payload instead of the `content`/`text` wrapper. A payload carried as JSON inside a string — including the `structuredContent: {"content": "<json>"}` shape emitted by servers that declare the MCP TypeScript SDK's default `outputSchema` — is parsed too.
27
+ - Relationships are now also derived from accepted identifier provenance: an identifier observed in one probe and accepted as an argument of the next is recorded as an observed relationship between the structures involved.
28
+ - Redaction: values under identifier keys (`id`, `*_id`, `*Id`, `*_uri`, ...) keep their exact value under `local_trusted` and `balanced`, because a redacted primary key is uncitable and kills list -> get traversal (a Google calendar id literally is an email address). They are still redacted when they look like a secret, under every mode, and `strict` redacts email/phone-shaped identifiers as well — choosing privacy over traversal.
29
+ - Static discovery now treats a target's missing `resources/list` or `prompts/list` method (JSON-RPC -32601) as "none declared" instead of failing, matching real-world tools-only MCP servers.
30
+ - Risk classification recognizes read-verb tool names (`calendar_events_list`, `gmail_users_getProfile`) as whole segments, and no longer classifies a metadata read as `administrative` merely because it returns a `permissions` field.
31
+
32
+ ### Removed
33
+
34
+ - The speculative `PublicTool` metadata surface in `discomcp-server`; the served tool list is now the single source of truth.
35
+
36
+ ## [0.2.0] - 2026-07-10
37
+
38
+ ### Changed
39
+
40
+ - `examples/config.toml` and the Quick Start now configure a real stdio MCP target instead of the deterministic mock fixture; the mock transport remains internal to the test suite only.
41
+
42
+ ### Removed
43
+
44
+ - Checked-in `examples/profiles/mock-collection` example profile output (generated artifact, not source).
45
+
46
+ ## [0.1.0] - 2026-07-10
47
+
48
+ ### Added
49
+
50
+ - Initial open-source project scaffold and dual licensing.
51
+ - Generic DiscoMCP core with provider-neutral MCP and reasoning contracts.
52
+ - Deterministic mock collection target, safe probe runtime, redaction, workspace inference, and profile artifact exporters.
53
+ - `discomcp` CLI commands for inspect, plan, profile, refresh, generate-skill, and public server-surface inspection.
54
+ - Checked-in redacted example profile, safety tests, CI, threat model, and extension guide.
55
+ - Newline-delimited stdio JSON-RPC MCP transport and local real-process integration coverage.
56
+ - Generic command reasoning backend using a documented stdin/stdout JSON contract.
package/LICENSE-APACHE 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 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
+ 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 [yyyy] [name of copyright owner]
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/LICENSE-MIT ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 DiscoMCP contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,199 @@
1
+ <div align="center">
2
+
3
+ # 🪩 DiscoMCP
4
+
5
+ **Turn an unknown MCP into a reusable, workspace-aware operational skill for AI agents.**
6
+
7
+ [![CI](https://github.com/ieranama/discomcp/actions/workflows/ci.yml/badge.svg)](https://github.com/ieranama/discomcp/actions/workflows/ci.yml)
8
+ [![Release](https://img.shields.io/github/v/release/ieranama/discomcp?label=release)](https://github.com/ieranama/discomcp/releases)
9
+ [![License](https://img.shields.io/badge/license-MIT%20OR%20Apache--2.0-blue)](#license)
10
+ [![LinkedIn](https://img.shields.io/badge/LinkedIn-Follow-0A66C2?logo=linkedin&logoColor=white)](http://linkedin.com/in/inigo-erana/)
11
+
12
+ </div>
13
+
14
+ No agent should walk onto the dance floor blind — DiscoMCP checks the room, learns the moves, and only then cuts in.
15
+
16
+ DiscoMCP turns an unknown Model Context Protocol (MCP) connection into a reusable, workspace-aware operational skill for AI agents.
17
+
18
+ It connects to a target MCP, collects its declared capabilities and configured documentation, safely explores only permitted read or harmless computation paths, and produces a profile with a workspace-specific `SKILL.md`.
19
+
20
+ DiscoMCP makes your agent be the one in the room you would like to dance with — not the one who shows up, starts flailing at every button on the mixing desk, and calls it improvisation. It learns the playlist first, asks before it touches the decks, and never, ever pulls the fire alarm to see what happens.
21
+
22
+ ## Why DiscoMCP
23
+
24
+ An MCP tool catalogue alone does not explain how a particular user's accessible workspace is organized or which tool sequence solves a real task. DiscoMCP keeps the target catalogue internal, records evidence for every important claim, and generates an operational model that agents can use without guessing.
25
+
26
+ The result answers questions such as:
27
+
28
+ - What does this MCP expose, and what platform or data source does it represent?
29
+ - Which tools are safe to call during discovery, and which require explicit confirmation later?
30
+ - Which structures, fields, identifiers, and relationships were actually observed?
31
+ - What workflow should an agent follow to answer a user request safely?
32
+ - What remains uncertain?
33
+
34
+ ## Safety Contract
35
+
36
+ DiscoMCP separates model reasoning from deterministic runtime control. A reasoning backend may propose a probe, but the runtime validates the target tool, JSON arguments, identifier provenance, policy, budgets, response limits, and redaction before any call is made.
37
+
38
+ During profiling, the runtime never automatically executes tools classified as:
39
+
40
+ - mutation
41
+ - external side effect
42
+ - destructive
43
+ - administrative
44
+ - arbitrary execution
45
+ - unknown risk
46
+
47
+ Sensitive reads are additionally constrained by the configured privacy policy. Secrets are redacted before logs, persistence, generated artifacts, and reasoning-provider requests.
48
+
49
+ ## Quick Start
50
+
51
+ Run it with no install — `npx` fetches the right prebuilt binary for your platform:
52
+
53
+ ```bash
54
+ npx @ieranama/discomcp --help
55
+ ```
56
+
57
+ Or install the binary once (no Rust toolchain required):
58
+
59
+ ```bash
60
+ curl --proto '=https' --tlsv1.2 -LsSf https://github.com/ieranama/discomcp/releases/latest/download/discomcp-installer.sh | sh
61
+ ```
62
+
63
+ (Windows: `powershell -ExecutionPolicy Bypass -c "irm https://github.com/ieranama/discomcp/releases/latest/download/discomcp-installer.ps1 | iex"`. All platform archives are on the [releases page](https://github.com/ieranama/discomcp/releases).)
64
+
65
+ Point a config at any MCP server you can run locally over stdio — this is the whole file:
66
+
67
+ ```toml
68
+ [targets.example]
69
+ transport = "stdio"
70
+ command = "npx"
71
+ args = ["-y", "example-mcp"]
72
+
73
+ [profiles]
74
+ privacy_mode = "balanced"
75
+ ```
76
+
77
+ Then add DiscoMCP to your agent as a regular MCP server. Your agent is the brain; the DiscoMCP runtime enforces every safety check:
78
+
79
+ ```bash
80
+ claude mcp add discomcp -- discomcp serve --config ./discomcp.toml
81
+ ```
82
+
83
+ The agent drives profiling through six tools — `list_targets`, `lookup_target`, `inspect_target`, `execute_probe`, `finalize_profile`, `generate_skill` — and the runtime validates every probe (risk class, argument schema, identifier provenance, budgets, redaction) before anything touches the target. Mutating, destructive, and administrative tools are always rejected during onboarding. `lookup_target` tells the agent whether a fresh skill already exists for the target's current catalogue, so exploration only runs when something actually changed.
84
+
85
+ No agent connected? The standalone CLI does the same job with a configured reasoning backend (see [examples/config.toml](examples/config.toml)):
86
+
87
+ ```bash
88
+ discomcp profile example \
89
+ --config ./examples/config.toml \
90
+ --mode standard \
91
+ --goal "Understand this MCP, safely explore my accessible workspace, and generate an operational skill"
92
+ ```
93
+
94
+ Profiles are written below `.discomcp/profiles/<target-id>/`. The canonical outputs are:
95
+
96
+ - `capability-profile.json`
97
+ - `workspace-model.json`
98
+ - `operational-model.json`
99
+
100
+ `SKILL.md` and `AGENTS.md` are generated exports of that canonical state.
101
+
102
+ ## Configuration
103
+
104
+ Start with [examples/config.toml](examples/config.toml). Targets are owned by DiscoMCP; it does not inherit servers from another agent host automatically. `stdio` launches a real MCP subprocess and communicates using newline-delimited JSON-RPC.
105
+
106
+ ```toml
107
+ [targets.example]
108
+ transport = "stdio"
109
+ command = "npx"
110
+ args = ["-y", "example-mcp"]
111
+ docs = ["./docs/example-mcp.md"]
112
+
113
+ [targets.example.env]
114
+ EXAMPLE_API_KEY = "${EXAMPLE_API_KEY}"
115
+
116
+ [reasoning]
117
+ routing = "single"
118
+ everyday_backend = "primary"
119
+
120
+ [reasoning.backends.primary]
121
+ type = "command"
122
+ command = "some-agent-cli"
123
+ args = ["exec", "--model", "{model}"]
124
+ model = "your-configured-model"
125
+ input = "stdin_json"
126
+ output = "stdout_json"
127
+ ```
128
+
129
+ The command receives one serialized `ReasoningRequest` on stdin and must emit either a `ReasoningResponse` JSON object or the raw JSON value for its `output` on stdout. No target credentials or unredacted MCP response are interpolated into the command line.
130
+
131
+ Environment interpolation fails clearly when a required variable is missing and never prints the resolved secret. Do not commit credentials, profile output containing sensitive workspace material, or `.env` files.
132
+
133
+ ## Evidence
134
+
135
+ Every material claim in a generated profile carries one of these statuses:
136
+
137
+ | Status | Meaning |
138
+ | --- | --- |
139
+ | `declared` | Exposed directly through MCP metadata, schemas, or annotations. |
140
+ | `documented` | Found in configured or MCP-exposed documentation. |
141
+ | `observed` | Confirmed by a successful permitted MCP call. |
142
+ | `inferred` | Reasoned from declarations, documentation, and observations. |
143
+ | `user_defined` | Explicitly supplied by the user. |
144
+ | `unknown` | Insufficient evidence. |
145
+ | `contradicted` | Relevant sources disagree. |
146
+
147
+ Inferences include their confidence, supporting evidence, source references, and contradictions. DiscoMCP does not present an inferred relationship as an observed fact.
148
+
149
+ ## Development
150
+
151
+ Want to contribute, or run an unreleased change? Build from source instead of installing the binary.
152
+
153
+ Prerequisites: Rust stable with `rustfmt` and `clippy`, and `cargo-audit` for the full local quality gate.
154
+
155
+ ```bash
156
+ git clone https://github.com/ieranama/discomcp.git
157
+ cd discomcp
158
+ cargo run -p discomcp -- profile example --config ./examples/config.toml --mode standard --goal "..."
159
+ ```
160
+
161
+ Run the local quality gate before opening a pull request:
162
+
163
+ ```bash
164
+ cargo fmt --check
165
+ cargo clippy --all-targets --all-features -- -D warnings
166
+ cargo test --all
167
+ cargo audit
168
+ ```
169
+
170
+ Install the audit tool once if needed:
171
+
172
+ ```bash
173
+ cargo install cargo-audit --locked
174
+ ```
175
+
176
+ The repository includes a generic collection-oriented mock MCP fixture so tests do not require credentials or external services.
177
+
178
+ ## Documentation
179
+
180
+ - [Architecture](docs/ARCHITECTURE.md)
181
+ - [Threat model](docs/THREAT_MODEL.md)
182
+ - [Extension guide](docs/EXTENDING.md)
183
+ - [Contributing](CONTRIBUTING.md)
184
+ - [Security policy](SECURITY.md)
185
+
186
+ ## Contributing
187
+
188
+ See [CONTRIBUTING.md](CONTRIBUTING.md). By participating, you agree to follow the [Code of Conduct](CODE_OF_CONDUCT.md).
189
+
190
+ ## License
191
+
192
+ Licensed under either of
193
+
194
+ - [Apache License, Version 2.0](LICENSE-APACHE)
195
+ - [MIT License](LICENSE-MIT)
196
+
197
+ at your option.
198
+
199
+ Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in DiscoMCP by you, as defined in the Apache-2.0 license, shall be dual-licensed as above, without any additional terms or conditions.
@@ -0,0 +1,348 @@
1
+ const {
2
+ createWriteStream,
3
+ existsSync,
4
+ mkdirSync,
5
+ mkdtemp,
6
+ rmSync,
7
+ } = require("fs");
8
+ const { join, sep } = require("path");
9
+ const { spawnSync } = require("child_process");
10
+ const { tmpdir } = require("os");
11
+
12
+ const https = require("node:https");
13
+ const http = require("node:http");
14
+
15
+ const tmpDir = tmpdir();
16
+
17
+ const error = (msg) => {
18
+ console.error(msg);
19
+ process.exit(1);
20
+ };
21
+
22
+ function getProxyForUrl(urlString) {
23
+ const url = new URL(urlString);
24
+ const isHttps = url.protocol === "https:";
25
+
26
+ const noProxy = process.env.NO_PROXY || process.env.no_proxy || "";
27
+ if (noProxy === "*") return null;
28
+ if (noProxy) {
29
+ const hostname = url.hostname.toLowerCase();
30
+ const noProxyList = noProxy.split(",").map((s) => s.trim().toLowerCase());
31
+ for (const entry of noProxyList) {
32
+ if (hostname === entry || hostname.endsWith("." + entry)) {
33
+ return null;
34
+ }
35
+ }
36
+ }
37
+
38
+ const proxyEnv = isHttps
39
+ ? process.env.HTTPS_PROXY || process.env.https_proxy
40
+ : process.env.HTTP_PROXY || process.env.http_proxy;
41
+
42
+ if (!proxyEnv) return null;
43
+
44
+ const proxyUrl = new URL(proxyEnv);
45
+
46
+ let auth = null;
47
+ if (proxyUrl.username || proxyUrl.password) {
48
+ auth = `${proxyUrl.username}:${proxyUrl.password}`;
49
+ }
50
+
51
+ return {
52
+ hostname: proxyUrl.hostname,
53
+ port: proxyUrl.port || (proxyUrl.protocol === "https:" ? 443 : 80),
54
+ auth: auth,
55
+ };
56
+ }
57
+
58
+ function connectThroughProxy(proxy, target) {
59
+ return new Promise((resolve, reject) => {
60
+ const headers = {};
61
+ if (proxy.auth) {
62
+ headers["Proxy-Authorization"] =
63
+ "Basic " + Buffer.from(proxy.auth).toString("base64");
64
+ }
65
+
66
+ const connectReq = http.request({
67
+ hostname: proxy.hostname,
68
+ port: proxy.port,
69
+ method: "CONNECT",
70
+ path: `${target.hostname}:${target.port || 443}`,
71
+ headers,
72
+ });
73
+ connectReq.on("connect", (res, socket) => {
74
+ if (res.statusCode === 200) {
75
+ resolve(socket);
76
+ } else {
77
+ reject(new Error(`Proxy CONNECT failed with status ${res.statusCode}`));
78
+ }
79
+ });
80
+ connectReq.on("error", reject);
81
+ connectReq.end();
82
+ });
83
+ }
84
+
85
+ function download(urlString, maxRedirects) {
86
+ if (maxRedirects === undefined) maxRedirects = 5;
87
+ return new Promise((resolve, reject) => {
88
+ if (maxRedirects < 0) {
89
+ return reject(new Error("Too many redirects"));
90
+ }
91
+
92
+ const parsed = new URL(urlString);
93
+ const isHttps = parsed.protocol === "https:";
94
+ const mod = isHttps ? https : http;
95
+ const proxy = getProxyForUrl(urlString);
96
+
97
+ const doRequest = (extraOptions) => {
98
+ const options = Object.assign(
99
+ {
100
+ hostname: parsed.hostname,
101
+ port: parsed.port || (isHttps ? 443 : 80),
102
+ path: parsed.pathname + parsed.search,
103
+ method: "GET",
104
+ headers: { "User-Agent": "cargo-dist-npm-installer" },
105
+ },
106
+ extraOptions || {},
107
+ );
108
+
109
+ if (proxy && !isHttps) {
110
+ // HTTP through HTTP proxy: request the full URL via the proxy
111
+ options.hostname = proxy.hostname;
112
+ options.port = proxy.port;
113
+ options.path = urlString;
114
+ if (proxy.auth) {
115
+ options.headers["Proxy-Authorization"] =
116
+ "Basic " + Buffer.from(proxy.auth).toString("base64");
117
+ }
118
+ }
119
+
120
+ const req = mod.request(options, (res) => {
121
+ if (
122
+ res.statusCode >= 300 &&
123
+ res.statusCode < 400 &&
124
+ res.headers.location
125
+ ) {
126
+ res.resume();
127
+ const nextUrl = new URL(res.headers.location, urlString).toString();
128
+ return download(nextUrl, maxRedirects - 1).then(resolve, reject);
129
+ }
130
+ if (res.statusCode < 200 || res.statusCode >= 300) {
131
+ res.resume();
132
+ return reject(new Error(`HTTP ${res.statusCode} from ${urlString}`));
133
+ }
134
+ resolve(res);
135
+ });
136
+ req.on("error", reject);
137
+ req.end();
138
+ };
139
+
140
+ if (proxy && isHttps) {
141
+ connectThroughProxy(proxy, parsed).then(
142
+ (socket) => doRequest({ socket, agent: false }),
143
+ reject,
144
+ );
145
+ } else {
146
+ doRequest();
147
+ }
148
+ });
149
+ }
150
+
151
+ class Package {
152
+ constructor(platform, name, url, filename, zipExt, binaries) {
153
+ let errors = [];
154
+ if (typeof url !== "string") {
155
+ errors.push("url must be a string");
156
+ } else {
157
+ try {
158
+ new URL(url);
159
+ } catch (e) {
160
+ errors.push(e);
161
+ }
162
+ }
163
+ if (name && typeof name !== "string") {
164
+ errors.push("package name must be a string");
165
+ }
166
+ if (!name) {
167
+ errors.push("You must specify the name of your package");
168
+ }
169
+ if (binaries && typeof binaries !== "object") {
170
+ errors.push("binaries must be a string => string map");
171
+ }
172
+ if (!binaries) {
173
+ errors.push("You must specify the binaries in the package");
174
+ }
175
+
176
+ if (errors.length > 0) {
177
+ let errorMsg =
178
+ "One or more of the parameters you passed to the Binary constructor are invalid:\n";
179
+ errors.forEach((error) => {
180
+ errorMsg += error;
181
+ });
182
+ errorMsg +=
183
+ '\n\nCorrect usage: new Package("my-binary", "https://example.com/binary/download.tar.gz", {"my-binary": "my-binary"})';
184
+ error(errorMsg);
185
+ }
186
+
187
+ this.platform = platform;
188
+ this.url = url;
189
+ this.name = name;
190
+ this.filename = filename;
191
+ this.zipExt = zipExt;
192
+ this.installDirectory = join(__dirname, "node_modules", ".bin_real");
193
+ this.binaries = binaries;
194
+
195
+ if (!existsSync(this.installDirectory)) {
196
+ mkdirSync(this.installDirectory, { recursive: true });
197
+ }
198
+ }
199
+
200
+ exists() {
201
+ for (const binaryName in this.binaries) {
202
+ const binRelPath = this.binaries[binaryName];
203
+ const binPath = join(this.installDirectory, binRelPath);
204
+ if (!existsSync(binPath)) {
205
+ return false;
206
+ }
207
+ }
208
+ return true;
209
+ }
210
+
211
+ install(suppressLogs = false) {
212
+ if (this.exists()) {
213
+ if (!suppressLogs) {
214
+ console.error(
215
+ `${this.name} is already installed, skipping installation.`,
216
+ );
217
+ }
218
+ return Promise.resolve();
219
+ }
220
+
221
+ try {
222
+ rmSync(this.installDirectory, { recursive: true, force: true });
223
+ } catch {
224
+ // ignore - directory may not exist
225
+ }
226
+
227
+ mkdirSync(this.installDirectory, { recursive: true });
228
+
229
+ if (!suppressLogs) {
230
+ console.error(`Downloading release from ${this.url}`);
231
+ }
232
+
233
+ return download(this.url)
234
+ .then((res) => {
235
+ return new Promise((resolve, reject) => {
236
+ mkdtemp(`${tmpDir}${sep}`, (err, directory) => {
237
+ if (err) return reject(err);
238
+ let tempFile = join(directory, this.filename);
239
+ const sink = res.pipe(createWriteStream(tempFile));
240
+ sink.on("error", (err) => reject(err));
241
+ sink.on("close", () => {
242
+ if (/\.tar\.*/.test(this.zipExt)) {
243
+ const result = spawnSync("tar", [
244
+ "xf",
245
+ tempFile,
246
+ // The tarballs are stored with a leading directory
247
+ // component; we strip one component in the
248
+ // shell installers too.
249
+ "--strip-components",
250
+ "1",
251
+ "-C",
252
+ this.installDirectory,
253
+ ]);
254
+ if (result.status == 0) {
255
+ resolve();
256
+ } else if (result.error) {
257
+ reject(result.error);
258
+ } else {
259
+ reject(
260
+ new Error(
261
+ `An error occurred untarring the artifact: stdout: ${result.stdout}; stderr: ${result.stderr}`,
262
+ ),
263
+ );
264
+ }
265
+ } else if (this.zipExt == ".zip") {
266
+ let result;
267
+ if (this.platform.artifactName.includes("windows")) {
268
+ // Windows does not have "unzip" by default on many installations, instead
269
+ // we use Expand-Archive from powershell
270
+ result = spawnSync("powershell.exe", [
271
+ "-NoProfile",
272
+ "-NonInteractive",
273
+ "-Command",
274
+ `& {
275
+ param([string]$LiteralPath, [string]$DestinationPath)
276
+ Expand-Archive -LiteralPath $LiteralPath -DestinationPath $DestinationPath -Force
277
+ }`,
278
+ tempFile,
279
+ this.installDirectory,
280
+ ]);
281
+ } else {
282
+ result = spawnSync("unzip", [
283
+ "-q",
284
+ tempFile,
285
+ "-d",
286
+ this.installDirectory,
287
+ ]);
288
+ }
289
+
290
+ if (result.status == 0) {
291
+ resolve();
292
+ } else if (result.error) {
293
+ reject(result.error);
294
+ } else {
295
+ reject(
296
+ new Error(
297
+ `An error occurred unzipping the artifact: stdout: ${result.stdout}; stderr: ${result.stderr}`,
298
+ ),
299
+ );
300
+ }
301
+ } else {
302
+ reject(
303
+ new Error(`Unrecognized file extension: ${this.zipExt}`),
304
+ );
305
+ }
306
+ });
307
+ });
308
+ });
309
+ })
310
+ .then(() => {
311
+ if (!suppressLogs) {
312
+ console.error(`${this.name} has been installed!`);
313
+ }
314
+ })
315
+ .catch((e) => {
316
+ error(`Error fetching release: ${e.message}`);
317
+ });
318
+ }
319
+
320
+ run(binaryName) {
321
+ const promise = !this.exists() ? this.install(true) : Promise.resolve();
322
+
323
+ promise
324
+ .then(() => {
325
+ const [, , ...args] = process.argv;
326
+
327
+ const options = { cwd: process.cwd(), stdio: "inherit" };
328
+
329
+ const binRelPath = this.binaries[binaryName];
330
+ if (!binRelPath) {
331
+ error(`${binaryName} is not a known binary in ${this.name}`);
332
+ }
333
+ const binPath = join(this.installDirectory, binRelPath);
334
+ const result = spawnSync(binPath, args, options);
335
+
336
+ if (result.error) {
337
+ error(result.error);
338
+ }
339
+
340
+ process.exit(result.status);
341
+ })
342
+ .catch((e) => {
343
+ error(e.message);
344
+ });
345
+ }
346
+ }
347
+
348
+ module.exports.Package = Package;
package/binary.js ADDED
@@ -0,0 +1,124 @@
1
+ const { Package } = require("./binary-install");
2
+ const os = require("os");
3
+ const libc = require("detect-libc");
4
+
5
+ const error = (msg) => {
6
+ console.error(msg);
7
+ process.exit(1);
8
+ };
9
+
10
+ const {
11
+ name,
12
+ artifactDownloadUrls,
13
+ supportedPlatforms,
14
+ glibcMinimum,
15
+ } = require("./package.json");
16
+
17
+ // FIXME: implement NPM installer handling of fallback download URLs
18
+ const artifactDownloadUrl = artifactDownloadUrls[0];
19
+ const builderGlibcMajorVersion = glibcMinimum.major;
20
+ const builderGlibcMinorVersion = glibcMinimum.series;
21
+
22
+ const getPlatform = () => {
23
+ const rawOsType = os.type();
24
+ const rawArchitecture = os.arch();
25
+
26
+ // We want to use rust-style target triples as the canonical key
27
+ // for a platform, so translate the "os" library's concepts into rust ones
28
+ let osType = "";
29
+ switch (rawOsType) {
30
+ case "Windows_NT":
31
+ osType = "pc-windows-msvc";
32
+ break;
33
+ case "Darwin":
34
+ osType = "apple-darwin";
35
+ break;
36
+ case "Linux":
37
+ osType = "unknown-linux-gnu";
38
+ break;
39
+ }
40
+
41
+ let arch = "";
42
+ switch (rawArchitecture) {
43
+ case "x64":
44
+ arch = "x86_64";
45
+ break;
46
+ case "arm64":
47
+ arch = "aarch64";
48
+ break;
49
+ }
50
+
51
+ if (rawOsType === "Linux") {
52
+ if (libc.familySync() == "musl") {
53
+ osType = "unknown-linux-musl-dynamic";
54
+ } else if (libc.isNonGlibcLinuxSync()) {
55
+ console.warn(
56
+ "Your libc is neither glibc nor musl; trying static musl binary instead",
57
+ );
58
+ osType = "unknown-linux-musl-static";
59
+ } else {
60
+ let libcVersion = libc.versionSync();
61
+ let splitLibcVersion = libcVersion.split(".");
62
+ let libcMajorVersion = splitLibcVersion[0];
63
+ let libcMinorVersion = splitLibcVersion[1];
64
+ if (
65
+ libcMajorVersion != builderGlibcMajorVersion ||
66
+ libcMinorVersion < builderGlibcMinorVersion
67
+ ) {
68
+ // We can't run the glibc binaries, but we can run the static musl ones
69
+ // if they exist
70
+ console.warn(
71
+ "Your glibc isn't compatible; trying static musl binary instead",
72
+ );
73
+ osType = "unknown-linux-musl-static";
74
+ }
75
+ }
76
+ }
77
+
78
+ // Assume the above succeeded and build a target triple to look things up with.
79
+ // If any of it failed, this lookup will fail and we'll handle it like normal.
80
+ let targetTriple = `${arch}-${osType}`;
81
+ let platform = supportedPlatforms[targetTriple];
82
+
83
+ if (!platform) {
84
+ error(
85
+ `Platform with type "${rawOsType}" and architecture "${rawArchitecture}" is not supported by ${name}.\nYour system must be one of the following:\n\n${Object.keys(
86
+ supportedPlatforms,
87
+ ).join(",")}`,
88
+ );
89
+ }
90
+
91
+ return platform;
92
+ };
93
+
94
+ const getPackage = () => {
95
+ const platform = getPlatform();
96
+ const url = `${artifactDownloadUrl}/${platform.artifactName}`;
97
+ let filename = platform.artifactName;
98
+ let ext = platform.zipExt;
99
+ let binary = new Package(platform, name, url, filename, ext, platform.bins);
100
+
101
+ return binary;
102
+ };
103
+
104
+ const install = (suppressLogs) => {
105
+ if (!artifactDownloadUrl || artifactDownloadUrl.length === 0) {
106
+ console.warn("in demo mode, not installing binaries");
107
+ return;
108
+ }
109
+ const pkg = getPackage();
110
+
111
+ return pkg.install(suppressLogs);
112
+ };
113
+
114
+ const run = (binaryName) => {
115
+ const pkg = getPackage();
116
+
117
+ pkg.run(binaryName);
118
+ };
119
+
120
+ module.exports = {
121
+ install,
122
+ run,
123
+ getPackage,
124
+ };
package/install.js ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env node
2
+
3
+ const { install } = require("./binary");
4
+ install(false);
@@ -0,0 +1,52 @@
1
+ {
2
+ "lockfileVersion": 3,
3
+ "name": "@ieranama/discomcp",
4
+ "packages": {
5
+ "": {
6
+ "bin": {
7
+ "discomcp": "run-discomcp.js"
8
+ },
9
+ "dependencies": {
10
+ "detect-libc": "^2.1.2"
11
+ },
12
+ "devDependencies": {
13
+ "prettier": "^3.8.3"
14
+ },
15
+ "engines": {
16
+ "node": ">=14.14",
17
+ "npm": ">=6"
18
+ },
19
+ "hasInstallScript": true,
20
+ "license": "MIT OR Apache-2.0",
21
+ "name": "@ieranama/discomcp",
22
+ "version": "0.5.0"
23
+ },
24
+ "node_modules/detect-libc": {
25
+ "engines": {
26
+ "node": ">=8"
27
+ },
28
+ "integrity": "sha512-Btj2BOOO83o3WyH59e8MgXsxEQVcarkUOpEYrubB0urwnN10yQ364rsiByU11nZlqWYZm05i/of7io4mzihBtQ==",
29
+ "license": "Apache-2.0",
30
+ "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-2.1.2.tgz",
31
+ "version": "2.1.2"
32
+ },
33
+ "node_modules/prettier": {
34
+ "bin": {
35
+ "prettier": "bin/prettier.cjs"
36
+ },
37
+ "dev": true,
38
+ "engines": {
39
+ "node": ">=14"
40
+ },
41
+ "funding": {
42
+ "url": "https://github.com/prettier/prettier?sponsor=1"
43
+ },
44
+ "integrity": "sha512-7igPTM53cGHMW8xWuVTydi2KO233VFiTNyF5hLJqpilHfmn8C8gPf+PS7dUT64YcXFbiMGZxS9pCSxL/Dxm/Jw==",
45
+ "license": "MIT",
46
+ "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.8.3.tgz",
47
+ "version": "3.8.3"
48
+ }
49
+ },
50
+ "requires": true,
51
+ "version": "0.5.0"
52
+ }
package/package.json ADDED
@@ -0,0 +1,88 @@
1
+ {
2
+ "artifactDownloadUrls": [
3
+ "https://github.com/ieranama/discomcp/releases/download/v0.5.0"
4
+ ],
5
+ "bin": {
6
+ "discomcp": "run-discomcp.js"
7
+ },
8
+ "dependencies": {
9
+ "detect-libc": "^2.1.2"
10
+ },
11
+ "description": "CLI for safety-first MCP profiling with DiscoMCP",
12
+ "devDependencies": {
13
+ "prettier": "^3.8.3"
14
+ },
15
+ "engines": {
16
+ "node": ">=14.14",
17
+ "npm": ">=6"
18
+ },
19
+ "glibcMinimum": {
20
+ "major": 2,
21
+ "series": 35
22
+ },
23
+ "license": "MIT OR Apache-2.0",
24
+ "name": "@ieranama/discomcp",
25
+ "preferUnplugged": true,
26
+ "repository": "https://github.com/ieranama/discomcp",
27
+ "scripts": {
28
+ "fmt": "prettier --write **/*.js",
29
+ "fmt:check": "prettier --check **/*.js",
30
+ "postinstall": "node ./install.js"
31
+ },
32
+ "supportedPlatforms": {
33
+ "aarch64-apple-darwin": {
34
+ "artifactName": "discomcp-aarch64-apple-darwin.tar.xz",
35
+ "bins": {
36
+ "discomcp": "discomcp"
37
+ },
38
+ "zipExt": ".tar.xz"
39
+ },
40
+ "aarch64-pc-windows-msvc": {
41
+ "artifactName": "discomcp-x86_64-pc-windows-msvc.zip",
42
+ "bins": {
43
+ "discomcp": "discomcp.exe"
44
+ },
45
+ "zipExt": ".zip"
46
+ },
47
+ "aarch64-unknown-linux-gnu": {
48
+ "artifactName": "discomcp-aarch64-unknown-linux-gnu.tar.xz",
49
+ "bins": {
50
+ "discomcp": "discomcp"
51
+ },
52
+ "zipExt": ".tar.xz"
53
+ },
54
+ "x86_64-apple-darwin": {
55
+ "artifactName": "discomcp-x86_64-apple-darwin.tar.xz",
56
+ "bins": {
57
+ "discomcp": "discomcp"
58
+ },
59
+ "zipExt": ".tar.xz"
60
+ },
61
+ "x86_64-pc-windows-gnu": {
62
+ "artifactName": "discomcp-x86_64-pc-windows-msvc.zip",
63
+ "bins": {
64
+ "discomcp": "discomcp.exe"
65
+ },
66
+ "zipExt": ".zip"
67
+ },
68
+ "x86_64-pc-windows-msvc": {
69
+ "artifactName": "discomcp-x86_64-pc-windows-msvc.zip",
70
+ "bins": {
71
+ "discomcp": "discomcp.exe"
72
+ },
73
+ "zipExt": ".zip"
74
+ },
75
+ "x86_64-unknown-linux-gnu": {
76
+ "artifactName": "discomcp-x86_64-unknown-linux-gnu.tar.xz",
77
+ "bins": {
78
+ "discomcp": "discomcp"
79
+ },
80
+ "zipExt": ".tar.xz"
81
+ }
82
+ },
83
+ "version": "0.5.0",
84
+ "volta": {
85
+ "node": "18.14.1",
86
+ "npm": "9.5.0"
87
+ }
88
+ }
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env node
2
+
3
+ const { run } = require("./binary");
4
+ run("discomcp");