unicommand 0.0.3 → 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/README.md +46 -0
- package/dist/index.d.ts +160 -105
- package/dist/index.js +287 -49
- package/dist/index.js.map +1 -1
- package/package.json +7 -5
package/README.md
CHANGED
|
@@ -164,6 +164,51 @@ The generated shim runs `src/cli.ts`, sets the package program-name env var, and
|
|
|
164
164
|
|
|
165
165
|
</div>
|
|
166
166
|
|
|
167
|
+
<div align="center">
|
|
168
|
+
|
|
169
|
+
<details>
|
|
170
|
+
<summary>Show MCP server options</summary>
|
|
171
|
+
<br />
|
|
172
|
+
|
|
173
|
+
<div align="left">
|
|
174
|
+
|
|
175
|
+
Bind values to the whole MCP server process, such as the account a server acts as:
|
|
176
|
+
|
|
177
|
+
```ts
|
|
178
|
+
import { startPackageCommandMcpServer } from 'unicommand';
|
|
179
|
+
|
|
180
|
+
await startPackageCommandMcpServer({
|
|
181
|
+
importMetaUrl: import.meta.url,
|
|
182
|
+
serverOptions: [{ name: 'account', description: 'Account email', required: true }],
|
|
183
|
+
instructions: ({ account }) => `This server acts as ${account}.`,
|
|
184
|
+
getContext: ({ account }) => createContext(account),
|
|
185
|
+
});
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
- A value comes from `--account <value>` or, when absent, from `<PACKAGE>_ACCOUNT` (for example `GSHEETS_ACCOUNT`). Set `env` on the option to use another variable.
|
|
189
|
+
- A bound option disappears from every tool input schema and is injected into each call. A call that passes a different value fails.
|
|
190
|
+
- A missing required option stops the server at startup with a message on stderr.
|
|
191
|
+
|
|
192
|
+
Choose where each command option appears:
|
|
193
|
+
|
|
194
|
+
- `mcp: false` keeps an option CLI only, such as an output format or a local export path.
|
|
195
|
+
- `mcp: 'required'` makes an option required in the MCP schema while the CLI keeps it optional.
|
|
196
|
+
|
|
197
|
+
Run one MCP tool command without starting the server by appending its name and flags. The JSON result goes to stdout; failures exit non-zero with a message on stderr:
|
|
198
|
+
|
|
199
|
+
```sh
|
|
200
|
+
my-mcp --account me@example.com auth status
|
|
201
|
+
my-mcp --account me@example.com auth begin --redirect-uri http://127.0.0.1:4000/callback
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
The server negotiates the protocol version, answers `ping`, handles requests concurrently, reports tool failures with `isError: true` and unknown tools as JSON-RPC errors, and only emits standard tool annotations. Side effects and confirmation needs are added to the tool description.
|
|
205
|
+
|
|
206
|
+
</div>
|
|
207
|
+
|
|
208
|
+
</details>
|
|
209
|
+
|
|
210
|
+
</div>
|
|
211
|
+
|
|
167
212
|
## 🛠 Development
|
|
168
213
|
|
|
169
214
|
<div align="center">
|
|
@@ -185,6 +230,7 @@ Run checks:
|
|
|
185
230
|
```sh
|
|
186
231
|
pnpm check:fix
|
|
187
232
|
pnpm typecheck
|
|
233
|
+
pnpm test
|
|
188
234
|
pnpm build
|
|
189
235
|
pnpm knip
|
|
190
236
|
```
|
package/dist/index.d.ts
CHANGED
|
@@ -23,6 +23,7 @@ type CommandOptionDefinition = {
|
|
|
23
23
|
description: string;
|
|
24
24
|
aliases?: readonly string[];
|
|
25
25
|
config?: CreateOptionCommandOpts;
|
|
26
|
+
mcp?: boolean | 'required';
|
|
26
27
|
negated?: boolean;
|
|
27
28
|
schema?: JsonSchemaProperty;
|
|
28
29
|
value?: string;
|
|
@@ -94,6 +95,7 @@ declare const commandDefinitionToInputSchema: (definition: CommandDefinition) =>
|
|
|
94
95
|
additionalProperties: boolean;
|
|
95
96
|
};
|
|
96
97
|
declare const commandOptionSynopsis: (option: CommandOptionDefinition) => string;
|
|
98
|
+
declare const optionInputName: (option: CommandOptionDefinition) => string;
|
|
97
99
|
|
|
98
100
|
type ProgramHelpData = {
|
|
99
101
|
binName: string;
|
|
@@ -106,90 +108,28 @@ declare const setProgramHelpData: (program: Program, data: ProgramHelpData) => v
|
|
|
106
108
|
declare const isGlobalHelpRequest: (args: readonly string[]) => boolean;
|
|
107
109
|
declare const printProgramHelp: (program: Program) => Promise<void>;
|
|
108
110
|
|
|
109
|
-
type
|
|
110
|
-
|
|
111
|
-
getContext?: () => Promise<TContext> | TContext;
|
|
112
|
-
};
|
|
113
|
-
type CommandRegistrar<TContext> = (program: Program, context: CommandRegistrarContext$1<TContext>) => void;
|
|
114
|
-
type RegisterCliCommandsFromDirectoryOptions<TContext> = {
|
|
115
|
-
binName: string;
|
|
116
|
-
commandsDir: string;
|
|
117
|
-
getContext?: () => Promise<TContext> | TContext;
|
|
118
|
-
program: Program;
|
|
119
|
-
};
|
|
120
|
-
type CreateCommandProgramOptions<TContext> = {
|
|
121
|
-
binName: string;
|
|
122
|
-
binNames?: readonly string[];
|
|
123
|
-
commandsDir?: string;
|
|
124
|
-
description: string;
|
|
125
|
-
getContext?: () => Promise<TContext> | TContext;
|
|
126
|
-
importMetaUrl: string;
|
|
127
|
-
isDevRun?: boolean;
|
|
128
|
-
packageName?: string;
|
|
129
|
-
printVersion?: (version: string) => void;
|
|
130
|
-
version?: string;
|
|
131
|
-
};
|
|
132
|
-
type RegisterParentCommandsFromDefinitionsOptions = {
|
|
133
|
-
description?: (name: string) => string;
|
|
134
|
-
print?: (message: string) => void;
|
|
135
|
-
};
|
|
136
|
-
declare const createCommandProgram: <TContext>({ binName, binNames, commandsDir, description, getContext, importMetaUrl, isDevRun, packageName, printVersion, version, }: CreateCommandProgramOptions<TContext>) => Promise<Program>;
|
|
137
|
-
declare const registerParentCommandsFromDefinitions: (program: Program, definitions: readonly CommandDefinition[], options?: RegisterParentCommandsFromDefinitionsOptions) => void;
|
|
138
|
-
declare const registerCliCommandsFromDirectory: <TContext>({ binName, commandsDir, getContext, program, }: RegisterCliCommandsFromDirectoryOptions<TContext>) => Promise<CommandDefinition[]>;
|
|
139
|
-
declare const getProgramConstructor: () => new () => Program;
|
|
140
|
-
|
|
141
|
-
type CliConfig<TProgram> = {
|
|
142
|
-
createProgram: (binName: string) => TProgram | Promise<TProgram>;
|
|
143
|
-
defaultBinName: string;
|
|
144
|
-
envBinName: string;
|
|
145
|
-
importMetaUrl: string;
|
|
146
|
-
};
|
|
147
|
-
declare const getProgramBin: (config: Pick<CliConfig<unknown>, "defaultBinName" | "envBinName" | "importMetaUrl">) => string;
|
|
148
|
-
declare const isDirectRun: (importMetaUrl: string) => boolean;
|
|
149
|
-
|
|
150
|
-
type CreateCommandCliRunnerOptions<TContext> = {
|
|
151
|
-
binNames?: readonly string[];
|
|
152
|
-
commandsDir?: string;
|
|
153
|
-
defaultBinName: string;
|
|
111
|
+
type McpServerOptionDefinition = {
|
|
112
|
+
name: string;
|
|
154
113
|
description: string;
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
};
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
isDirectRun: () => boolean;
|
|
174
|
-
runCli: (args?: string[]) => Promise<number>;
|
|
175
|
-
};
|
|
176
|
-
declare const createCommandCliRunner: <TContext>({ binNames, commandsDir, defaultBinName, description, envBinName, getContext, importMetaUrl, isDevRun, packageName, printVersion, version, }: CreateCommandCliRunnerOptions<TContext>) => {
|
|
177
|
-
isDirectRun: () => boolean;
|
|
178
|
-
runCli: (args?: string[]) => Promise<number>;
|
|
179
|
-
};
|
|
180
|
-
|
|
181
|
-
declare enum PackageManager {
|
|
182
|
-
Npm = "npm",
|
|
183
|
-
Pnpm = "pnpm",
|
|
184
|
-
Yarn = "yarn"
|
|
185
|
-
}
|
|
186
|
-
type RegisterUpdateCommandOptions = {
|
|
187
|
-
isDevRun: boolean;
|
|
188
|
-
packageName: string;
|
|
189
|
-
version?: string;
|
|
114
|
+
env?: string;
|
|
115
|
+
required?: boolean;
|
|
116
|
+
};
|
|
117
|
+
type McpServerOptionValues = Record<string, string>;
|
|
118
|
+
type McpServerArgv = {
|
|
119
|
+
flags: Record<string, string>;
|
|
120
|
+
positionals: string[];
|
|
121
|
+
};
|
|
122
|
+
declare const parseMcpServerArgv: (argv: readonly string[]) => McpServerArgv;
|
|
123
|
+
declare const mcpServerOptionEnvName: (envPrefix: string, option: McpServerOptionDefinition) => string;
|
|
124
|
+
declare const resolveMcpServerOptions: ({ argvFlags, definitions, env, envPrefix, }: {
|
|
125
|
+
argvFlags: Record<string, string>;
|
|
126
|
+
definitions: readonly McpServerOptionDefinition[];
|
|
127
|
+
env: NodeJS.ProcessEnv;
|
|
128
|
+
envPrefix: string;
|
|
129
|
+
}) => McpServerOptionValues;
|
|
130
|
+
declare const withoutMcpServerOptionFlags: (flags: Record<string, string>, definitions: readonly McpServerOptionDefinition[]) => {
|
|
131
|
+
[k: string]: string;
|
|
190
132
|
};
|
|
191
|
-
declare const registerUpdateCommand: (program: Program, options: RegisterUpdateCommandOptions) => void;
|
|
192
|
-
declare function getPackageManagerFromPath(globalBinPath: string): PackageManager | null;
|
|
193
133
|
|
|
194
134
|
type McpToolDefinition = {
|
|
195
135
|
name: string;
|
|
@@ -201,8 +141,6 @@ type McpToolDefinition = {
|
|
|
201
141
|
destructiveHint?: boolean;
|
|
202
142
|
idempotentHint?: boolean;
|
|
203
143
|
openWorldHint?: boolean;
|
|
204
|
-
requiresConfirmation?: boolean;
|
|
205
|
-
sideEffects?: string[];
|
|
206
144
|
};
|
|
207
145
|
};
|
|
208
146
|
type JsonRpcRequest = {
|
|
@@ -244,6 +182,8 @@ type CommandResourceRoute = {
|
|
|
244
182
|
};
|
|
245
183
|
type CreateMcpServerOptions = {
|
|
246
184
|
name: string;
|
|
185
|
+
version?: string;
|
|
186
|
+
instructions?: string;
|
|
247
187
|
tools: McpToolDefinition[];
|
|
248
188
|
resources?: McpResourceDefinition[];
|
|
249
189
|
resourceTemplates?: McpResourceTemplateDefinition[];
|
|
@@ -255,12 +195,21 @@ type CreateSingleToolMcpServerOptions = {
|
|
|
255
195
|
tool: McpToolDefinition;
|
|
256
196
|
callTool: (args: Record<string, unknown>) => Promise<unknown> | unknown;
|
|
257
197
|
};
|
|
198
|
+
type McpServerContextFactory<TContext> = (serverOptions: McpServerOptionValues) => Promise<TContext> | TContext;
|
|
199
|
+
type McpServerInstructions = string | ((serverOptions: McpServerOptionValues) => string);
|
|
258
200
|
type CreateCommandMcpServerOptions<TContext> = {
|
|
201
|
+
argv?: readonly string[];
|
|
259
202
|
commandsDir?: string;
|
|
260
|
-
|
|
203
|
+
env?: NodeJS.ProcessEnv;
|
|
204
|
+
envPrefix?: string;
|
|
205
|
+
getContext?: McpServerContextFactory<TContext>;
|
|
206
|
+
importCommandModule?: CommandModuleImporter;
|
|
261
207
|
importMetaUrl: string;
|
|
208
|
+
instructions?: McpServerInstructions;
|
|
262
209
|
name: string;
|
|
263
210
|
prefix?: string;
|
|
211
|
+
serverOptions?: readonly McpServerOptionDefinition[];
|
|
212
|
+
version?: string;
|
|
264
213
|
};
|
|
265
214
|
type CreatePackageCommandMcpServerOptions<TContext> = Omit<CreateCommandMcpServerOptions<TContext>, 'name' | 'prefix'> & {
|
|
266
215
|
mcpServerPrefix?: string;
|
|
@@ -275,6 +224,7 @@ type CommandMcpRoute = {
|
|
|
275
224
|
};
|
|
276
225
|
type CommandMcpRouteFactory<TContext> = (getContext: () => Promise<TContext> | TContext) => CommandMcpRoute;
|
|
277
226
|
type CreateCommandMcpRouterOptions = {
|
|
227
|
+
boundOptions?: McpServerOptionValues;
|
|
278
228
|
prefix?: string;
|
|
279
229
|
routes: readonly CommandMcpRoute[];
|
|
280
230
|
};
|
|
@@ -286,12 +236,12 @@ type Handler<TInput, TResult> = {
|
|
|
286
236
|
type ContextHandler<TContext, TInput, TResult> = {
|
|
287
237
|
handle(context: TContext, input: TInput): Promise<TResult> | TResult;
|
|
288
238
|
}['handle'];
|
|
289
|
-
type CommandRegistrarContext<TContext> = {
|
|
239
|
+
type CommandRegistrarContext$1<TContext> = {
|
|
290
240
|
binName?: string;
|
|
291
241
|
getContext?: ContextFactory<TContext>;
|
|
292
242
|
};
|
|
293
243
|
type CommandAdaptersReturn<TContext, THandler> = {
|
|
294
|
-
cli: (program: Program, context?: CommandRegistrarContext<TContext>) => void;
|
|
244
|
+
cli: (program: Program, context?: CommandRegistrarContext$1<TContext>) => void;
|
|
295
245
|
handler: THandler;
|
|
296
246
|
mcp: (getContext?: ContextFactory<TContext>) => CommandMcpRoute;
|
|
297
247
|
metadata: CommandDefinition;
|
|
@@ -312,13 +262,102 @@ declare function createCommandAdapters<TInputSchema extends ZodType = ZodType<Re
|
|
|
312
262
|
declare function createCommandAdapters<TContext, TInputSchema extends ZodType = ZodType<Record<string, unknown>>, TOutputSchema extends ZodType = ZodType, TResult = unknown>(options: ContextCommandAdaptersOptions<TContext, TInputSchema, TOutputSchema, TResult>): CommandAdaptersReturn<TContext, ContextHandler<TContext, z.infer<TInputSchema>, TResult>>;
|
|
313
263
|
|
|
314
264
|
type CommandModule = Record<string, unknown>;
|
|
265
|
+
type CommandModuleImporter = (file: string) => Promise<CommandModule>;
|
|
315
266
|
type CommandAdapterExport = Pick<CommandAdaptersReturn<unknown, unknown>, 'cli'> & Partial<Pick<CommandAdaptersReturn<unknown, unknown>, 'mcp' | 'metadata'>>;
|
|
316
|
-
declare const loadCommandModules: (commandsDir: string) => Promise<CommandModule[]>;
|
|
317
|
-
declare const loadCommandModulesFromFiles: (files: readonly string[]) => Promise<CommandModule[]>;
|
|
267
|
+
declare const loadCommandModules: (commandsDir: string, importModule?: CommandModuleImporter) => Promise<CommandModule[]>;
|
|
268
|
+
declare const loadCommandModulesFromFiles: (files: readonly string[], importModule?: CommandModuleImporter) => Promise<CommandModule[]>;
|
|
318
269
|
declare const commandDefinitionsFromModules: (modules: readonly CommandModule[]) => CommandDefinition[];
|
|
319
270
|
declare const commandExportsFromModules: <TExport>(modules: readonly CommandModule[], isExport: (name: string, value: unknown) => boolean) => TExport[];
|
|
320
271
|
declare const isCommandAdapterExport: (value: unknown) => value is CommandAdapterExport;
|
|
321
272
|
|
|
273
|
+
type CommandRegistrarContext<TContext> = {
|
|
274
|
+
binName: string;
|
|
275
|
+
getContext?: () => Promise<TContext> | TContext;
|
|
276
|
+
};
|
|
277
|
+
type CommandRegistrar<TContext> = (program: Program, context: CommandRegistrarContext<TContext>) => void;
|
|
278
|
+
type RegisterCliCommandsFromDirectoryOptions<TContext> = {
|
|
279
|
+
binName: string;
|
|
280
|
+
commandsDir: string;
|
|
281
|
+
getContext?: () => Promise<TContext> | TContext;
|
|
282
|
+
importCommandModule?: CommandModuleImporter;
|
|
283
|
+
program: Program;
|
|
284
|
+
};
|
|
285
|
+
type CreateCommandProgramOptions<TContext> = {
|
|
286
|
+
binName: string;
|
|
287
|
+
binNames?: readonly string[];
|
|
288
|
+
commandsDir?: string;
|
|
289
|
+
description: string;
|
|
290
|
+
getContext?: () => Promise<TContext> | TContext;
|
|
291
|
+
importCommandModule?: CommandModuleImporter;
|
|
292
|
+
importMetaUrl: string;
|
|
293
|
+
isDevRun?: boolean;
|
|
294
|
+
packageName?: string;
|
|
295
|
+
printVersion?: (version: string) => void;
|
|
296
|
+
version?: string;
|
|
297
|
+
};
|
|
298
|
+
type RegisterParentCommandsFromDefinitionsOptions = {
|
|
299
|
+
description?: (name: string) => string;
|
|
300
|
+
print?: (message: string) => void;
|
|
301
|
+
};
|
|
302
|
+
declare const createCommandProgram: <TContext>({ binName, binNames, commandsDir, description, getContext, importCommandModule, importMetaUrl, isDevRun, packageName, printVersion, version, }: CreateCommandProgramOptions<TContext>) => Promise<Program>;
|
|
303
|
+
declare const registerParentCommandsFromDefinitions: (program: Program, definitions: readonly CommandDefinition[], options?: RegisterParentCommandsFromDefinitionsOptions) => void;
|
|
304
|
+
declare const registerCliCommandsFromDirectory: <TContext>({ binName, commandsDir, getContext, importCommandModule, program, }: RegisterCliCommandsFromDirectoryOptions<TContext>) => Promise<CommandDefinition[]>;
|
|
305
|
+
declare const getProgramConstructor: () => new () => Program;
|
|
306
|
+
|
|
307
|
+
type CliConfig<TProgram> = {
|
|
308
|
+
createProgram: (binName: string) => TProgram | Promise<TProgram>;
|
|
309
|
+
defaultBinName: string;
|
|
310
|
+
envBinName: string;
|
|
311
|
+
importMetaUrl: string;
|
|
312
|
+
};
|
|
313
|
+
declare const getProgramBin: (config: Pick<CliConfig<unknown>, "defaultBinName" | "envBinName" | "importMetaUrl">) => string;
|
|
314
|
+
declare const isDirectRun: (importMetaUrl: string) => boolean;
|
|
315
|
+
|
|
316
|
+
type CreateCommandCliRunnerOptions<TContext> = {
|
|
317
|
+
binNames?: readonly string[];
|
|
318
|
+
commandsDir?: string;
|
|
319
|
+
defaultBinName: string;
|
|
320
|
+
description: string;
|
|
321
|
+
envBinName: string;
|
|
322
|
+
getContext?: () => Promise<TContext> | TContext;
|
|
323
|
+
importCommandModule?: CommandModuleImporter;
|
|
324
|
+
importMetaUrl: string;
|
|
325
|
+
isDevRun?: boolean;
|
|
326
|
+
packageName?: string;
|
|
327
|
+
printVersion?: (version: string) => void;
|
|
328
|
+
version?: string;
|
|
329
|
+
};
|
|
330
|
+
type CreatePackageCommandCliRunnerOptions<TContext> = Omit<CreateCommandCliRunnerOptions<TContext>, 'defaultBinName' | 'description' | 'envBinName'> & {
|
|
331
|
+
defaultBinName?: string;
|
|
332
|
+
description?: string;
|
|
333
|
+
envBinName?: string;
|
|
334
|
+
};
|
|
335
|
+
declare const createCliRunner: (config: CliConfig<Program>) => {
|
|
336
|
+
isDirectRun: () => boolean;
|
|
337
|
+
runCli: (args?: string[]) => Promise<number>;
|
|
338
|
+
};
|
|
339
|
+
declare const createPackageCommandCliRunner: <TContext>({ defaultBinName, envBinName, importMetaUrl, ...options }: CreatePackageCommandCliRunnerOptions<TContext>) => {
|
|
340
|
+
isDirectRun: () => boolean;
|
|
341
|
+
runCli: (args?: string[]) => Promise<number>;
|
|
342
|
+
};
|
|
343
|
+
declare const createCommandCliRunner: <TContext>({ binNames, commandsDir, defaultBinName, description, envBinName, getContext, importCommandModule, importMetaUrl, isDevRun, packageName, printVersion, version, }: CreateCommandCliRunnerOptions<TContext>) => {
|
|
344
|
+
isDirectRun: () => boolean;
|
|
345
|
+
runCli: (args?: string[]) => Promise<number>;
|
|
346
|
+
};
|
|
347
|
+
|
|
348
|
+
declare enum PackageManager {
|
|
349
|
+
Npm = "npm",
|
|
350
|
+
Pnpm = "pnpm",
|
|
351
|
+
Yarn = "yarn"
|
|
352
|
+
}
|
|
353
|
+
type RegisterUpdateCommandOptions = {
|
|
354
|
+
isDevRun: boolean;
|
|
355
|
+
packageName: string;
|
|
356
|
+
version?: string;
|
|
357
|
+
};
|
|
358
|
+
declare const registerUpdateCommand: (program: Program, options: RegisterUpdateCommandOptions) => void;
|
|
359
|
+
declare function getPackageManagerFromPath(globalBinPath: string): PackageManager | null;
|
|
360
|
+
|
|
322
361
|
declare const DEFAULT_COMMANDS_DIR = "commands";
|
|
323
362
|
declare const PROGRAM_NAME_ENV_SUFFIX = "_PROG_NAME";
|
|
324
363
|
|
|
@@ -326,19 +365,34 @@ type GenerateReadmeCommandDocsOptions = {
|
|
|
326
365
|
binName: string;
|
|
327
366
|
commandDefinitions?: readonly CommandDefinition[];
|
|
328
367
|
commandsDir?: string;
|
|
368
|
+
importCommandModule?: CommandModuleImporter;
|
|
329
369
|
markerName?: string;
|
|
330
370
|
readmePath?: string;
|
|
331
371
|
};
|
|
332
|
-
declare const generateReadmeCommandDocs: ({ binName, commandDefinitions, commandsDir, markerName, readmePath, }: GenerateReadmeCommandDocsOptions) => Promise<void>;
|
|
372
|
+
declare const generateReadmeCommandDocs: ({ binName, commandDefinitions, commandsDir, importCommandModule, markerName, readmePath, }: GenerateReadmeCommandDocsOptions) => Promise<void>;
|
|
333
373
|
declare const formatCommandDocs: (commands: readonly CommandDefinition[], binName: string) => string;
|
|
334
374
|
|
|
335
|
-
declare const loadCommandMcpRoutes: <TContext>(commandsDir: string, getContext?: () => Promise<TContext> | TContext) => Promise<CommandMcpRoute[]>;
|
|
336
|
-
declare const createCommandMcpServer: <TContext>({ commandsDir, getContext, importMetaUrl, name, prefix, }: CreateCommandMcpServerOptions<TContext>) => Promise<{
|
|
375
|
+
declare const loadCommandMcpRoutes: <TContext>(commandsDir: string, getContext?: () => Promise<TContext> | TContext, importCommandModule?: CommandModuleImporter) => Promise<CommandMcpRoute[]>;
|
|
376
|
+
declare const createCommandMcpServer: <TContext>({ argv, commandsDir, env, envPrefix, getContext, importCommandModule, importMetaUrl, instructions, name, prefix, serverOptions, version, }: CreateCommandMcpServerOptions<TContext>) => Promise<{
|
|
377
|
+
boundOptions: McpServerOptionValues;
|
|
378
|
+
command: string | undefined;
|
|
379
|
+
runCommand: (commandName: string, flags?: Record<string, string>) => Promise<unknown>;
|
|
380
|
+
commandFlags: {
|
|
381
|
+
[k: string]: string;
|
|
382
|
+
};
|
|
383
|
+
handleRequest: (request: JsonRpcRequest) => Promise<void>;
|
|
337
384
|
start: () => Promise<void>;
|
|
338
385
|
}>;
|
|
386
|
+
declare const runMcpCommandOnce: (routes: readonly CommandMcpRoute[], commandName: string, flags: Record<string, string>, { boundOptions }: {
|
|
387
|
+
boundOptions: McpServerOptionValues;
|
|
388
|
+
}) => Promise<unknown>;
|
|
339
389
|
declare const startCommandMcpServer: <TContext>(options: CreateCommandMcpServerOptions<TContext>) => Promise<void>;
|
|
340
|
-
declare const startPackageCommandMcpServer: <TContext>({ importMetaUrl, mcpServerPrefix, name, prefix, ...options }: CreatePackageCommandMcpServerOptions<TContext>) => Promise<void>;
|
|
390
|
+
declare const startPackageCommandMcpServer: <TContext>({ envPrefix, importMetaUrl, mcpServerPrefix, name, prefix, version, ...options }: CreatePackageCommandMcpServerOptions<TContext>) => Promise<void>;
|
|
341
391
|
|
|
392
|
+
declare class McpProtocolError extends Error {
|
|
393
|
+
readonly code: number;
|
|
394
|
+
constructor(code: number, message: string);
|
|
395
|
+
}
|
|
342
396
|
declare const assertToolName: (expectedName: string, actualName: string | undefined) => void;
|
|
343
397
|
declare const throwUnknownTool: (name: string | undefined) => never;
|
|
344
398
|
|
|
@@ -358,14 +412,14 @@ declare const resourceResult: (params: unknown, data: unknown) => {
|
|
|
358
412
|
};
|
|
359
413
|
|
|
360
414
|
declare const createCommandMcpRoute: ({ command, handler, inputSchema, outputSchema, }: CommandMcpRoute) => CommandMcpRoute;
|
|
361
|
-
declare const commandMcpRouteToTool: (route: CommandMcpRoute, prefix?: string) => {
|
|
415
|
+
declare const commandMcpRouteToTool: (route: CommandMcpRoute, prefix?: string, boundOptions?: McpServerOptionValues) => {
|
|
362
416
|
name: string;
|
|
363
417
|
description: string;
|
|
364
|
-
inputSchema: z.core.ZodStandardJSONSchemaPayload<
|
|
418
|
+
inputSchema: z.core.ZodStandardJSONSchemaPayload<ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>;
|
|
365
419
|
outputSchema: {
|
|
366
420
|
type: string;
|
|
367
421
|
properties: {
|
|
368
|
-
data: z.core.ZodStandardJSONSchemaPayload<
|
|
422
|
+
data: z.core.ZodStandardJSONSchemaPayload<ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>;
|
|
369
423
|
progress: {
|
|
370
424
|
type: string;
|
|
371
425
|
properties: {
|
|
@@ -413,20 +467,20 @@ declare const commandMcpRouteToTool: (route: CommandMcpRoute, prefix?: string) =
|
|
|
413
467
|
destructiveHint: boolean;
|
|
414
468
|
idempotentHint: boolean;
|
|
415
469
|
openWorldHint: boolean;
|
|
416
|
-
requiresConfirmation: boolean;
|
|
417
|
-
sideEffects: string[] | undefined;
|
|
418
470
|
} | undefined;
|
|
419
471
|
};
|
|
420
472
|
declare const commandNameToMcpToolName: (name: string, prefix?: string) => string;
|
|
421
|
-
declare const
|
|
473
|
+
declare const commandMcpInputSchema: (route: CommandMcpRoute, boundOptions?: McpServerOptionValues) => ZodType;
|
|
474
|
+
declare const commandMcpInput: (route: CommandMcpRoute, args: Record<string, unknown>, boundOptions?: McpServerOptionValues) => Record<string, unknown>;
|
|
475
|
+
declare const createCommandMcpRouter: ({ boundOptions, prefix, routes, }: CreateCommandMcpRouterOptions) => {
|
|
422
476
|
tools: {
|
|
423
477
|
name: string;
|
|
424
478
|
description: string;
|
|
425
|
-
inputSchema: z.core.ZodStandardJSONSchemaPayload<
|
|
479
|
+
inputSchema: z.core.ZodStandardJSONSchemaPayload<ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>;
|
|
426
480
|
outputSchema: {
|
|
427
481
|
type: string;
|
|
428
482
|
properties: {
|
|
429
|
-
data: z.core.ZodStandardJSONSchemaPayload<
|
|
483
|
+
data: z.core.ZodStandardJSONSchemaPayload<ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>;
|
|
430
484
|
progress: {
|
|
431
485
|
type: string;
|
|
432
486
|
properties: {
|
|
@@ -474,8 +528,6 @@ declare const createCommandMcpRouter: ({ prefix, routes }: CreateCommandMcpRoute
|
|
|
474
528
|
destructiveHint: boolean;
|
|
475
529
|
idempotentHint: boolean;
|
|
476
530
|
openWorldHint: boolean;
|
|
477
|
-
requiresConfirmation: boolean;
|
|
478
|
-
sideEffects: string[] | undefined;
|
|
479
531
|
} | undefined;
|
|
480
532
|
}[];
|
|
481
533
|
resources: McpResourceDefinition[];
|
|
@@ -546,9 +598,12 @@ declare const emptyMcpInputSchema: {
|
|
|
546
598
|
};
|
|
547
599
|
|
|
548
600
|
declare const createSingleToolMcpServer: ({ serverName, tool, callTool, }: CreateSingleToolMcpServerOptions) => {
|
|
601
|
+
handleRequest: (request: JsonRpcRequest) => Promise<void>;
|
|
549
602
|
start: () => Promise<void>;
|
|
550
603
|
};
|
|
551
|
-
declare const
|
|
604
|
+
declare const negotiateMcpProtocolVersion: (params: unknown) => string;
|
|
605
|
+
declare const createMcpServer: ({ name, version, instructions, tools, resources, resourceTemplates, callTool, readResource, }: CreateMcpServerOptions) => {
|
|
606
|
+
handleRequest: (request: JsonRpcRequest) => Promise<void>;
|
|
552
607
|
start: () => Promise<void>;
|
|
553
608
|
};
|
|
554
609
|
|
|
@@ -613,4 +668,4 @@ type DevCommandShimConfig = {
|
|
|
613
668
|
declare const installCommandShim: (binDir: string, config: DevCommandShimConfig) => void;
|
|
614
669
|
declare const getBinDir: (envName: string) => string;
|
|
615
670
|
|
|
616
|
-
export { type CliConfig, type CommandAdapterExport, type CommandAdaptersReturn, type CommandArgumentDefinition, type CommandCompletionDefinition, type CommandDefinition, type CommandExamplesDefinition, type CommandMcpMetadata, type CommandMcpResourceMetadata, type CommandMcpRoute, type CommandMcpRouteFactory, type CommandMcpToolMetadata, type CommandModule, type CommandOptionDefinition, type CommandRegistrar, type CommandRegistrarContext
|
|
671
|
+
export { type CliConfig, type CommandAdapterExport, type CommandAdaptersReturn, type CommandArgumentDefinition, type CommandCompletionDefinition, type CommandDefinition, type CommandExamplesDefinition, type CommandMcpMetadata, type CommandMcpResourceMetadata, type CommandMcpRoute, type CommandMcpRouteFactory, type CommandMcpToolMetadata, type CommandModule, type CommandModuleImporter, type CommandOptionDefinition, type CommandRegistrar, type CommandRegistrarContext, type CommandResourceRoute, type CompletionConfig, type CreateCommandMcpRouterOptions, type CreateCommandMcpServerOptions, type CreateCommandProgramOptions, type CreateMcpServerOptions, type CreatePackageCommandMcpServerOptions, type CreateSingleToolMcpServerOptions, DEFAULT_COMMANDS_DIR, type DefineCommandDefinition, type DevCommandShimConfig, type GenerateReadmeCommandDocsOptions, type JsonRpcRequest, type JsonSchemaProperty, McpProtocolError, type McpResourceDefinition, type McpResourceTemplateDefinition, type McpResultEnvelope, type McpServerArgv, type McpServerContextFactory, type McpServerInstructions, type McpServerOptionDefinition, type McpServerOptionValues, type McpToolDefinition, PROGRAM_NAME_ENV_SUFFIX, type PackageBinEntry, type PackageCommandMetadata, type PackageJson, PackageManager, type RegisterCliCommandsFromDirectoryOptions, type RegisterParentCommandsFromDefinitionsOptions, type RegisterUpdateCommandOptions, type ResourceReadParams, type ShellCompletionSnippet, type ToolCallParams, assertToolName, commandActionInput, commandDefinitionToInputSchema, commandDefinitionToZodInputSchema, commandDefinitionsFromModules, commandExportsFromModules, commandInputString, commandInputValue, commandMcpInput, commandMcpInputSchema, commandMcpRouteToResourceRoute, commandMcpRouteToTool, commandNameToMcpToolName, commandOptionSynopsis, commandResourceInput, commandResourceRouteToResource, commandResourceRouteToResourceTemplate, createCliRunner, createCommandAdapters, createCommandCliRunner, createCommandMcpRoute, createCommandMcpRouter, createCommandMcpServer, createCommandProgram, createMcpServer, createPackageCommandCliRunner, createSingleToolMcpServer, defineCommand, emptyMcpInputSchema, formatCommandDocs, generateReadmeCommandDocs, getBinDir, getPackageManagerFromPath, getProgramBin, getProgramConstructor, installCommandShim, installDevCommand, installPackageDevCommand, installPackageDevCommands, isCommandAdapterExport, isCommandMcpResourceMetadata, isCommandMcpToolMetadata, isDirectRun, isGlobalHelpRequest, isResourceTemplate, loadCommandMcpRoutes, loadCommandModules, loadCommandModulesFromFiles, mcpServerOptionEnvName, mcpToolOutputSchema, negotiateMcpProtocolVersion, normalizeCommandInputAliases, optionInputName, packageBinEntry, packageCommandMetadata, packageEnvPrefix, packageRoot, parseMcpServerArgv, printProgramHelp, readPackageJson, registerCliCommandsFromDirectory, registerCommand, registerCompletionCommand, registerParentCommandsFromDefinitions, registerUpdateCommand, resolveMcpServerOptions, resourceResult, runMcpCommandOnce, setProgramHelpData, shortPackageName, startCommandMcpServer, startPackageCommandMcpServer, throwUnknownTool, uninstallDevCommand, uninstallPackageDevCommand, uninstallPackageDevCommands, withoutMcpServerOptionFlags };
|