@modeltoolsprotocol/sdk 0.2.0 → 0.3.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/README.md +49 -4
- package/package.json +1 -1
- package/src/index.ts +2 -2
- package/src/introspect.ts +4 -1
- package/src/types.ts +1 -0
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @modeltoolsprotocol/sdk
|
|
2
2
|
|
|
3
|
-
Add MTP `--describe` support to any Commander.js CLI. One function call, zero boilerplate.
|
|
3
|
+
Add MTP `--mtp-describe` support to any Commander.js CLI. One function call, zero boilerplate.
|
|
4
4
|
|
|
5
5
|
## Install
|
|
6
6
|
|
|
@@ -42,7 +42,7 @@ program.parse();
|
|
|
42
42
|
```
|
|
43
43
|
|
|
44
44
|
```bash
|
|
45
|
-
$ filetool --describe # MTP JSON schema
|
|
45
|
+
$ filetool --mtp-describe # MTP JSON schema
|
|
46
46
|
$ filetool convert data.csv # normal operation
|
|
47
47
|
```
|
|
48
48
|
|
|
@@ -50,7 +50,7 @@ $ filetool convert data.csv # normal operation
|
|
|
50
50
|
|
|
51
51
|
### `withDescribe(program, options?)`
|
|
52
52
|
|
|
53
|
-
Adds `--describe` to an existing Commander program. When invoked, outputs MTP-compliant JSON and exits.
|
|
53
|
+
Adds `--mtp-describe` to an existing Commander program. When invoked, outputs MTP-compliant JSON and exits.
|
|
54
54
|
|
|
55
55
|
- **program** — a Commander `Command` instance (your root program)
|
|
56
56
|
- **options.commands** — per-command annotations keyed by command name (stdin, stdout, examples, argTypes)
|
|
@@ -67,6 +67,8 @@ The SDK introspects Commander's own data structures — `cmd.options`, `cmd.regi
|
|
|
67
67
|
|
|
68
68
|
### Type Inference
|
|
69
69
|
|
|
70
|
+
Arg types describe flags and positional arguments, which are always scalar on the command line:
|
|
71
|
+
|
|
70
72
|
| Commander signal | MTP type |
|
|
71
73
|
|---|---|
|
|
72
74
|
| `option.isBoolean()` | `"boolean"` |
|
|
@@ -75,6 +77,49 @@ The SDK introspects Commander's own data structures — `cmd.options`, `cmd.regi
|
|
|
75
77
|
| explicit `argTypes` override | whatever you say |
|
|
76
78
|
| everything else | `"string"` |
|
|
77
79
|
|
|
80
|
+
For structured data flowing through stdin/stdout, use the `schema` field in IO descriptors. This supports full JSON Schema (draft 2020-12): nested objects, arrays, unions, pattern validation, conditional fields.
|
|
81
|
+
|
|
82
|
+
### Structured IO
|
|
83
|
+
|
|
84
|
+
When a command accepts or produces JSON, describe the shape with a JSON Schema:
|
|
85
|
+
|
|
86
|
+
```typescript
|
|
87
|
+
withDescribe(program, {
|
|
88
|
+
commands: {
|
|
89
|
+
process: {
|
|
90
|
+
stdin: {
|
|
91
|
+
contentType: "application/json",
|
|
92
|
+
description: "Configuration to process",
|
|
93
|
+
schema: {
|
|
94
|
+
type: "object",
|
|
95
|
+
properties: {
|
|
96
|
+
name: { type: "string" },
|
|
97
|
+
settings: {
|
|
98
|
+
type: "object",
|
|
99
|
+
properties: {
|
|
100
|
+
retries: { type: "integer" },
|
|
101
|
+
endpoints: { type: "array", items: { type: "string", format: "uri" } },
|
|
102
|
+
},
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
required: ["name"],
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
stdout: {
|
|
109
|
+
contentType: "application/json",
|
|
110
|
+
schema: {
|
|
111
|
+
type: "object",
|
|
112
|
+
properties: {
|
|
113
|
+
status: { type: "string", enum: ["ok", "error"] },
|
|
114
|
+
results: { type: "array", items: { type: "object" } },
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
},
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
});
|
|
121
|
+
```
|
|
122
|
+
|
|
78
123
|
### Command Naming
|
|
79
124
|
|
|
80
125
|
- Programs with subcommands: each leaf command gets a space-separated path (e.g., `"auth login"`)
|
|
@@ -83,7 +128,7 @@ The SDK introspects Commander's own data structures — `cmd.options`, `cmd.regi
|
|
|
83
128
|
|
|
84
129
|
### Filtered Options
|
|
85
130
|
|
|
86
|
-
These are automatically excluded from schema output: `--help`, `--version`, `--describe`, and any hidden options.
|
|
131
|
+
These are automatically excluded from schema output: `--help`, `--version`, `--mtp-describe`, and any hidden options.
|
|
87
132
|
|
|
88
133
|
## Single-Command Tools
|
|
89
134
|
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -10,9 +10,9 @@ export function withDescribe(
|
|
|
10
10
|
program: Command,
|
|
11
11
|
options?: DescribeOptions,
|
|
12
12
|
): Command {
|
|
13
|
-
program.option("--describe", "Output machine-readable MTP JSON schema");
|
|
13
|
+
program.option("--mtp-describe", "Output machine-readable MTP JSON schema");
|
|
14
14
|
|
|
15
|
-
program.on("option:describe", () => {
|
|
15
|
+
program.on("option:mtp-describe", () => {
|
|
16
16
|
const schema = describe(program, options);
|
|
17
17
|
const clean = JSON.parse(JSON.stringify(schema));
|
|
18
18
|
console.log(JSON.stringify(clean, null, 2));
|
package/src/introspect.ts
CHANGED
|
@@ -7,6 +7,8 @@ import type {
|
|
|
7
7
|
ToolSchema,
|
|
8
8
|
} from "./types.js";
|
|
9
9
|
|
|
10
|
+
const MTP_SPEC_VERSION = "2026-02-07";
|
|
11
|
+
|
|
10
12
|
// Commander stores these as private fields. We access them for filtering.
|
|
11
13
|
interface CommandInternals {
|
|
12
14
|
_helpOption?: Option | null;
|
|
@@ -202,6 +204,7 @@ export function generateSchema(
|
|
|
202
204
|
const internals = program as unknown as CommandInternals;
|
|
203
205
|
|
|
204
206
|
const schema: ToolSchema = {
|
|
207
|
+
specVersion: MTP_SPEC_VERSION,
|
|
205
208
|
name: program.name(),
|
|
206
209
|
version: internals._version || "",
|
|
207
210
|
description: program.description() || "",
|
|
@@ -209,7 +212,7 @@ export function generateSchema(
|
|
|
209
212
|
program,
|
|
210
213
|
options?.commands,
|
|
211
214
|
undefined,
|
|
212
|
-
"
|
|
215
|
+
"mtpDescribe",
|
|
213
216
|
),
|
|
214
217
|
};
|
|
215
218
|
|