Document generate-cli shorthand support

This commit is contained in:
Peter Steinberger 2025-11-07 14:47:16 +00:00
parent 3fdb81d206
commit b5e1c5df84
5 changed files with 17 additions and 2 deletions

View File

@ -18,6 +18,7 @@
- Generated CLIs now embed their metadata (generator version, resolved server definition, invocation flags) behind a hidden `__mcporter_inspect` command. `mcporter inspect-cli` / `mcporter generate-cli --from <artifact>` read directly from the artifact, while legacy `.metadata.json` sidecars remain as a fallback for older binaries.
- Shared the TypeScript signature formatter between `mcporter list` and `mcporter generate-cli`, ensuring command summaries, CLI hints, and generator help stay pixel-perfect and are backed by new snapshot/unit tests.
- Introduced `mcporter emit-ts`, a codegen command that emits `.d.ts` tool interfaces or ready-to-run client wrappers (`--mode types|client`, `--include-optional`) using the same doc/comment data that powers the CLI, so agents/tests can consume MCP servers with strong TypeScript types.
- `mcporter generate-cli` now accepts inline stdio commands via `--command "npx -y package@latest"`, automatically splits the command/args, infers a friendly name from scripts or package scopes, and documents the chrome-devtools one-liner in the README; additional unit tests cover HTTP, stdio, and scoped package shorthands.
### Documentation & references
- Added `docs/tool-calling.md`, `docs/call-syntax.md`, and `docs/call-heuristic.md` to capture every invocation style (flags, function expressions, inferred verbs) plus the typo-correction rules.

View File

@ -22,6 +22,7 @@ Create an `mcporter generate-cli` command that produces a standalone CLI for a s
- If `--server` matches a configured name (via `loadServerDefinitions`), use that server definition.
- Otherwise, if the value looks like a file path, load a Cursor-style JSON definition from disk.
- Otherwise, attempt to parse inline JSON/JSON5.
- When `--command` is a raw HTTP selector or shell command, normalize scheme-less URLs to HTTPS and split stdio commands into `command` + `args` (e.g., `npx -y chrome-devtools-mcp@latest`).
- Validate that a definition is found; prompt on failure.
3. **Tool Introspection**
- Use `listTools(server, { includeSchema: true })` to inspect MCP tool schemas.
@ -69,6 +70,9 @@ npx mcporter generate-cli \
chmod +x context7
./context7 list-tools
# Shareable "one weird trick" for chrome-devtools (no config required)
npx mcporter generate-cli --command "npx -y chrome-devtools-mcp@latest"
- `--minify` shrinks the bundled output via esbuild (output defaults to `<server>.js`).
- `--compile [path]` implies bundling and invokes `bun build --compile` to create the native executable (Bun only). When you omit the path, the compiled binary inherits the server name.
- Use `--server '{...}'` when you need advanced configuration (headers, env vars, stdio commands, OAuth metadata).

View File

@ -27,6 +27,7 @@ A quick reference for the primary `mcporter` subcommands. Each command inherits
compiling with Bun).
- Key flags:
- `--server <name>` (or inline JSON) choose the server definition.
- `--command <url|command>` point at an ad-hoc HTTP endpoint or a stdio command (e.g., `"npx -y chrome-devtools-mcp@latest"`); mcporter infers the name when omitted.
- `--output <path>` where to write the TypeScript template.
- `--bundle <path>` emit a bundle (Node/Bun) ready for `bun x`.
- `--compile <path>` compile with Bun (implies `--runtime bun`).

View File

@ -18,7 +18,7 @@ summary: 'Plan for the mcporter package replacing the Sweetistics pnpm MCP helpe
- Typed utilities for env/header resolution and stdio command execution.
- CLI entry point (`npx mcporter list|call`) built on the same runtime with configurable log levels (`--log-level` flag, `MCPORTER_LOG_LEVEL` env) defaulting to `warn`. Single-server listings must render as TypeScript-style headers: dimmed `/** ... */` doc blocks followed by `function name(...)` signatures, inferred return annotations when schemas expose a `title`, inline enum/format hints, and an optional-parameter summary (`// optional (N): a, b, ...`). Optional fields are hidden by default (unless there are ≤2 of them and <4 required parameters) and the CLI should tell users to run `--all-parameters` whenever anything is suppressed. The CLI should also infer the verb when users omit it: bare server names run `list <server>` (with the same typo-friendly heuristic used by `mcporter list`), while dotted tokens such as `linear.list_issues` dispatch to `call` automatically. Anonymous HTTP MCP servers (e.g., shadcn) must be auto-detected: if an ad-hoc URL returns MCP-shaped JSON even with a non-200 status, mcporter treats it as authenticated instead of launching the OAuth flow. Likewise, `call` must recognise HTTP selectors that inline the tool name (e.g., `https://www.shadcn.io/api/mcp.getComponent(...)`), strip the `.tool` suffix to derive the base server, parse any function-call arguments, and reuse an existing definition when the base URL matches a configured server. Selectors may omit the protocol entirelywe assume HTTPS when no scheme is present and treat hosts that only differ by a leading `www.` as identical for reuse purposes. See [docs/cli-reference.md](./cli-reference.md) for day-to-day usage/flag details.
- CLI generator (`npx mcporter generate-cli`) that emits standalone CLIs (plain TypeScript or bundled JS) with embedded schemas and Commander-based subcommands, targeting Node or Bun.
- CLI generator (`npx mcporter generate-cli`) that emits standalone CLIs (plain TypeScript or bundled JS) with embedded schemas and Commander-based subcommands, targeting Node or Bun. It must accept server references by name (positional), JSON, or HTTP URL (with optional `.tool` suffix / missing scheme) just like the main CLI.
- CLI generator (`npx mcporter generate-cli`) that emits standalone CLIs (plain TypeScript or bundled JS) with embedded schemas and Commander-based subcommands, targeting Node or Bun. It must accept server references by name (positional), JSON, HTTP URL (with optional `.tool` suffix / missing scheme), or inline stdio commands (split into `command` + `args` so invocations like `--command "npx -y chrome-devtools-mcp@latest"` work without a config entry) just like the main CLI.
- Test harness using the Sweetistics MCP fixtures to validate every configured server definition.
- Documentation: README, usage examples, migration guide for replacing `pnpm mcp:*`.
@ -47,7 +47,7 @@ summary: 'Plan for the mcporter package replacing the Sweetistics pnpm MCP helpe
- Back the proxy with targeted unit tests that cover primitive-only calls, positional tuples + option bags, and error fallbacks when schemas are missing.
## Standalone CLI Generation
- `generate-cli` should accept inline JSON, file paths, or existing config names and produce a ready-to-run CLI that maps tools to Commander subcommands.
- `generate-cli` should accept inline JSON, file paths, inline stdio commands, or existing config names and produce a ready-to-run CLI that maps tools to Commander subcommands.
- Embed schemas (via `listTools { includeSchema: true }`) directly in the generated source so repeat executions avoid additional metadata calls.
- Support optional bundling through esbuild, producing Node-friendly `.cjs` files or Bun-ready `.js` binaries with executable shebangs.
- Surface flags for output path, runtime target (`node` or `bun`), bundle destination, and per-call timeout (default 30s).

View File

@ -60,6 +60,15 @@ describe('generate-cli runner internals', () => {
expect(inferred).toBe('demo-tools');
});
it('normalizes scheme-less HTTP selectors passed to --command', () => {
const args = ['--command', 'shadcn.io/api/mcp.getComponents'];
const parsed = generateInternals.parseGenerateFlags([...args]);
expect(typeof parsed.command).toBe('string');
expect((parsed.command as string).startsWith('https://')).toBe(true);
const inferred = parsed.command !== undefined ? generateInternals.inferNameFromCommand(parsed.command) : undefined;
expect(inferred).toBe('shadcn');
});
it('builds regenerate commands honoring global flags and invocation overrides', () => {
const definition: SerializedServerDefinition = {
name: 'demo',