@agimon-ai/imagine-mcp 0.2.0 → 0.2.2

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/dist/cli.cjs CHANGED
@@ -1,129 +1,4 @@
1
1
  #!/usr/bin/env node
2
- const require_stdio = require('./stdio-D7OcvsZd.cjs');
3
- let commander = require("commander");
4
-
5
- //#region src/cli.ts
6
- /**
7
- * MCP Server Entry Point
8
- *
9
- * DESIGN PATTERNS:
10
- * - CLI pattern with Commander for argument parsing
11
- * - Lazy command loading for fast startup
12
- * - Transport abstraction for multiple communication methods
13
- *
14
- * CODING STANDARDS:
15
- * - Use async/await for asynchronous operations
16
- * - Handle errors gracefully with try-catch
17
- * - Log important events for debugging
18
- * - Load commands lazily to minimize startup time
19
- *
20
- * AVOID:
21
- * - Hardcoding command logic in index.ts (use separate command files)
22
- * - Missing error handling for command execution
23
- * - Eager loading of all commands at startup
24
- */
25
- const packageJson = { version: "0.1.0" };
26
- const commandDefinitions = [{
27
- name: "mcp-serve",
28
- description: "Start MCP server with specified transport",
29
- loader: () => Promise.resolve().then(() => require("./commands-BlRAon0l.cjs")).then((m) => m.mcpServeCommand)
30
- }];
31
- /**
32
- * Custom error for CLI execution failures with error codes and cause chaining.
33
- */
34
- var CLIExecutionError = class extends Error {
35
- code;
36
- recovery;
37
- constructor(message, code = "CLI_EXECUTION_FAILED", options) {
38
- super(message, options);
39
- this.name = "CLIExecutionError";
40
- this.code = code;
41
- this.recovery = options?.recovery;
42
- }
43
- };
44
- /**
45
- * Error thrown when a command fails to load dynamically.
46
- * Provides error code, command name context, and recovery suggestion.
47
- */
48
- var CommandLoadError = class extends Error {
49
- code = "COMMAND_LOAD_ERROR";
50
- recovery;
51
- commandName;
52
- constructor(commandName, message, options) {
53
- super(`Failed to load command '${commandName}': ${message}`, options);
54
- this.name = "CommandLoadError";
55
- this.commandName = commandName;
56
- this.recovery = `Check that the command module exists and exports the expected command. Run with --help to see available commands.`;
57
- }
58
- };
59
- /**
60
- * Creates a lazy-loading command wrapper.
61
- * The actual command is only imported when invoked.
62
- * Includes error handling for dynamic import failures.
63
- */
64
- function createLazyCommand(def) {
65
- const command = new commander.Command(def.name).description(def.description).allowUnknownOption(true).allowExcessArguments(true);
66
- command.action(async () => {
67
- let realCommand;
68
- try {
69
- realCommand = await def.loader();
70
- } catch (error) {
71
- if (error instanceof CommandLoadError) throw error;
72
- throw new CommandLoadError(def.name, error instanceof Error ? error.message : String(error), { cause: error });
73
- }
74
- const parentArgs = process.argv.slice(2);
75
- await new commander.Command().addCommand(realCommand).parseAsync([
76
- "node",
77
- "imagine-mcp",
78
- ...parentArgs
79
- ]);
80
- });
81
- return command;
82
- }
83
- /**
84
- * Main entry point with lazy command loading for fast startup.
85
- */
86
- async function main() {
87
- const invokedCommand = process.argv[2] ?? "unknown";
88
- try {
89
- const program = new commander.Command();
90
- program.name("imagine").description("MCP server for AI image generation and manipulation").version(packageJson.version);
91
- for (const def of commandDefinitions) program.addCommand(createLazyCommand(def));
92
- await program.parseAsync(process.argv);
93
- } catch (error) {
94
- if (error instanceof CLIExecutionError) {
95
- process.stderr.write(`Error [${error.code}] ${JSON.stringify({
96
- command: invokedCommand,
97
- recovery: error.recovery,
98
- message: error.message,
99
- cause: error.cause instanceof Error ? error.cause.message : error.cause
100
- })}\n`);
101
- if (error.recovery) process.stderr.write(`Recovery: ${error.recovery}\n`);
102
- if (error.cause) process.stderr.write(`Caused by: ${error.cause instanceof Error ? error.cause.message : String(error.cause)}\n`);
103
- } else if (error instanceof CommandLoadError) {
104
- process.stderr.write(`Error [${error.code}] ${JSON.stringify({
105
- command: invokedCommand,
106
- recovery: error.recovery,
107
- message: error.message
108
- })}\n`);
109
- if (error.recovery) process.stderr.write(`Recovery: ${error.recovery}\n`);
110
- if (error.cause) process.stderr.write(`Caused by: ${error.cause instanceof Error ? error.cause.message : String(error.cause)}\n`);
111
- } else {
112
- const errorCode = error.code ?? "CLI_EXECUTION_FAILED";
113
- process.stderr.write(`Error [${errorCode}] ${JSON.stringify({
114
- command: invokedCommand,
115
- message: error instanceof Error ? error.message : String(error)
116
- })}\n`);
117
- process.stderr.write("Recovery: Run with --help for usage information.\n");
118
- if (error instanceof Error && error.cause) process.stderr.write(`Caused by: ${error.cause instanceof Error ? error.cause.message : String(error.cause)}\n`);
119
- }
120
- process.exit(1);
121
- }
122
- }
123
- main();
124
-
125
- //#endregion
126
- exports.CLIExecutionError = CLIExecutionError;
127
- exports.CommandLoadError = CommandLoadError;
128
- exports.commandDefinitions = commandDefinitions;
129
- exports.createLazyCommand = createLazyCommand;
2
+ const e=require(`./stdio-qsNJYZZf.cjs`);let t=require(`commander`);const n={version:`0.1.0`},r=[{name:`mcp-serve`,description:`Start MCP server with specified transport`,loader:()=>Promise.resolve().then(()=>require(`./commands-Bda9LPMQ.cjs`)).then(e=>e.mcpServeCommand)}];var i=class extends Error{code;recovery;constructor(e,t=`CLI_EXECUTION_FAILED`,n){super(e,n),this.name=`CLIExecutionError`,this.code=t,this.recovery=n?.recovery}},a=class extends Error{code=`COMMAND_LOAD_ERROR`;recovery;commandName;constructor(e,t,n){super(`Failed to load command '${e}': ${t}`,n),this.name=`CommandLoadError`,this.commandName=e,this.recovery=`Check that the command module exists and exports the expected command. Run with --help to see available commands.`}};function o(e){let n=new t.Command(e.name).description(e.description).allowUnknownOption(!0).allowExcessArguments(!0);return n.action(async()=>{let n;try{n=await e.loader()}catch(t){throw t instanceof a?t:new a(e.name,t instanceof Error?t.message:String(t),{cause:t})}let r=process.argv.slice(2);await new t.Command().addCommand(n).parseAsync([`node`,`imagine-mcp`,...r])}),n}async function s(){let e=process.argv[2]??`unknown`;try{let e=new t.Command;e.name(`imagine`).description(`MCP server for AI image generation and manipulation`).version(n.version);for(let t of r)e.addCommand(o(t));await e.parseAsync(process.argv)}catch(t){if(t instanceof i)process.stderr.write(`Error [${t.code}] ${JSON.stringify({command:e,recovery:t.recovery,message:t.message,cause:t.cause instanceof Error?t.cause.message:t.cause})}\n`),t.recovery&&process.stderr.write(`Recovery: ${t.recovery}\n`),t.cause&&process.stderr.write(`Caused by: ${t.cause instanceof Error?t.cause.message:String(t.cause)}\n`);else if(t instanceof a)process.stderr.write(`Error [${t.code}] ${JSON.stringify({command:e,recovery:t.recovery,message:t.message})}\n`),t.recovery&&process.stderr.write(`Recovery: ${t.recovery}\n`),t.cause&&process.stderr.write(`Caused by: ${t.cause instanceof Error?t.cause.message:String(t.cause)}\n`);else{let n=t.code??`CLI_EXECUTION_FAILED`;process.stderr.write(`Error [${n}] ${JSON.stringify({command:e,message:t instanceof Error?t.message:String(t)})}\n`),process.stderr.write(`Recovery: Run with --help for usage information.
3
+ `),t instanceof Error&&t.cause&&process.stderr.write(`Caused by: ${t.cause instanceof Error?t.cause.message:String(t.cause)}\n`)}process.exit(1)}}s(),exports.CLIExecutionError=i,exports.CommandLoadError=a,exports.commandDefinitions=r,exports.createLazyCommand=o;
4
+ //# sourceMappingURL=cli.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.cjs","names":["commandDefinitions: CommandDef[]","Command","realCommand: Command"],"sources":["../src/cli.ts"],"sourcesContent":["#!/usr/bin/env node\n/**\n * MCP Server Entry Point\n *\n * DESIGN PATTERNS:\n * - CLI pattern with Commander for argument parsing\n * - Lazy command loading for fast startup\n * - Transport abstraction for multiple communication methods\n *\n * CODING STANDARDS:\n * - Use async/await for asynchronous operations\n * - Handle errors gracefully with try-catch\n * - Log important events for debugging\n * - Load commands lazily to minimize startup time\n *\n * AVOID:\n * - Hardcoding command logic in index.ts (use separate command files)\n * - Missing error handling for command execution\n * - Eager loading of all commands at startup\n */\nimport { Command } from 'commander';\n\nconst packageJson = { version: '0.1.0' };\n\n/**\n * Command metadata for lazy loading.\n * Definitions are inline to avoid importing command modules at startup.\n */\nexport interface CommandDef {\n name: string;\n description: string;\n loader: () => Promise<Command>;\n}\n\nexport const commandDefinitions: CommandDef[] = [\n {\n name: 'mcp-serve',\n description: 'Start MCP server with specified transport',\n loader: () => import('./commands').then((m) => m.mcpServeCommand),\n },\n];\n\n/**\n * Custom error for CLI execution failures with error codes and cause chaining.\n */\nexport class CLIExecutionError extends Error {\n readonly code: string;\n readonly recovery?: string;\n\n constructor(message: string, code = 'CLI_EXECUTION_FAILED', options?: ErrorOptions & { recovery?: string }) {\n super(message, options);\n this.name = 'CLIExecutionError';\n this.code = code;\n this.recovery = options?.recovery;\n }\n}\n\n/**\n * Error thrown when a command fails to load dynamically.\n * Provides error code, command name context, and recovery suggestion.\n */\nexport class CommandLoadError extends Error {\n readonly code = 'COMMAND_LOAD_ERROR';\n readonly recovery: string;\n readonly commandName: string;\n\n constructor(commandName: string, message: string, options?: ErrorOptions) {\n super(`Failed to load command '${commandName}': ${message}`, options);\n this.name = 'CommandLoadError';\n this.commandName = commandName;\n this.recovery = `Check that the command module exists and exports the expected command. Run with --help to see available commands.`;\n }\n}\n\n/**\n * Creates a lazy-loading command wrapper.\n * The actual command is only imported when invoked.\n * Includes error handling for dynamic import failures.\n */\nexport function createLazyCommand(def: CommandDef): Command {\n const command = new Command(def.name)\n .description(def.description)\n .allowUnknownOption(true)\n .allowExcessArguments(true);\n\n command.action(async () => {\n let realCommand: Command;\n try {\n realCommand = await def.loader();\n } catch (error) {\n if (error instanceof CommandLoadError) {\n throw error;\n }\n throw new CommandLoadError(def.name, error instanceof Error ? error.message : String(error), { cause: error });\n }\n\n const parentArgs = process.argv.slice(2);\n const program = new Command().addCommand(realCommand);\n await program.parseAsync(['node', 'imagine-mcp', ...parentArgs]);\n });\n\n return command;\n}\n\n/**\n * Main entry point with lazy command loading for fast startup.\n */\nasync function main() {\n const invokedCommand = process.argv[2] ?? 'unknown';\n\n try {\n const program = new Command();\n\n program\n .name('imagine')\n .description('MCP server for AI image generation and manipulation')\n .version(packageJson.version);\n\n for (const def of commandDefinitions) {\n program.addCommand(createLazyCommand(def));\n }\n\n await program.parseAsync(process.argv);\n } catch (error) {\n if (error instanceof CLIExecutionError) {\n process.stderr.write(\n `Error [${error.code}] ${JSON.stringify({\n command: invokedCommand,\n recovery: error.recovery,\n message: error.message,\n cause: error.cause instanceof Error ? error.cause.message : error.cause,\n })}\\n`,\n );\n if (error.recovery) {\n process.stderr.write(`Recovery: ${error.recovery}\\n`);\n }\n if (error.cause) {\n process.stderr.write(\n `Caused by: ${error.cause instanceof Error ? error.cause.message : String(error.cause)}\\n`,\n );\n }\n } else if (error instanceof CommandLoadError) {\n process.stderr.write(\n `Error [${error.code}] ${JSON.stringify({\n command: invokedCommand,\n recovery: error.recovery,\n message: error.message,\n })}\\n`,\n );\n if (error.recovery) {\n process.stderr.write(`Recovery: ${error.recovery}\\n`);\n }\n if (error.cause) {\n process.stderr.write(\n `Caused by: ${error.cause instanceof Error ? error.cause.message : String(error.cause)}\\n`,\n );\n }\n } else {\n const errorCode = (error as { code?: string }).code ?? 'CLI_EXECUTION_FAILED';\n process.stderr.write(\n `Error [${errorCode}] ${JSON.stringify({\n command: invokedCommand,\n message: error instanceof Error ? error.message : String(error),\n })}\\n`,\n );\n process.stderr.write('Recovery: Run with --help for usage information.\\n');\n if (error instanceof Error && error.cause) {\n process.stderr.write(\n `Caused by: ${error.cause instanceof Error ? error.cause.message : String(error.cause)}\\n`,\n );\n }\n }\n process.exit(1);\n }\n}\n\nmain();\n"],"mappings":";mEAsBA,MAAM,EAAc,CAAE,QAAS,QAAS,CAY3BA,EAAmC,CAC9C,CACE,KAAM,YACN,YAAa,4CACb,WAAA,QAAA,SAAA,CAAA,SAAA,QAAc,0BAAA,CAAA,CAAqB,KAAM,GAAM,EAAE,gBAAgB,CAClE,CACF,CAKD,IAAa,EAAb,cAAuC,KAAM,CAC3C,KACA,SAEA,YAAY,EAAiB,EAAO,uBAAwB,EAAgD,CAC1G,MAAM,EAAS,EAAQ,CACvB,KAAK,KAAO,oBACZ,KAAK,KAAO,EACZ,KAAK,SAAW,GAAS,WAQhB,EAAb,cAAsC,KAAM,CAC1C,KAAgB,qBAChB,SACA,YAEA,YAAY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AO,MACb,cAAc,EAAM,iBAAiB,MAAQ,EAAM,MAAM,QAAU,OAAO,EAAM,MAAM,CAAC,IACxF,SAEM,aAAiB,EAC1B,QAAQ,OAAO,MACb,UAAU,EAAM,KAAK,IAAI,KAAK,UAAU,CACtC,QAAS,EACT,SAAU,EAAM,SAChB,QAAS,EAAM,QAChB,CAAC,CAAC,IACJ,CACG,EAAM,UACR,QAAQ,OAAO,MAAM,aAAa,EAAM,SAAS,IAAI,CAEnD,EAAM,OACR,QAAQ,OAAO,MACb,cAAc,EAAM,iBAAiB,MAAQ,EAAM,MAAM,QAAU,OAAO,EAAM,MAAM,CAAC,IACxF,KAEE,CACL,IAAM,EAAa,EAA4B,MAAQ,uBACvD,QAAQ,OAAO,MACb,UAAU,EAAU,IAAI,KAAK,UAAU,CACrC,QAAS,EACT,QAAS,aAAiB,MAAQ,EAAM,QAAU,OAAO,EAAM,CAChE,CAAC,CAAC,IACJ,CACD,QAAQ,OAAO,MAAM;EAAqD,CACtE,aAAiB,OAAS,EAAM,OAClC,QAAQ,OAAO,MACb,cAAc,EAAM,iBAAiB,MAAQ,EAAM,MAAM,QAAU,OAAO,EAAM,MAAM,CAAC,IACxF,CAGL,QAAQ,KAAK,EAAE,EAInB,GAAM"}
package/dist/cli.mjs CHANGED
@@ -1,125 +1,4 @@
1
1
  #!/usr/bin/env node
2
- import { Command } from "commander";
3
-
4
- //#region src/cli.ts
5
- /**
6
- * MCP Server Entry Point
7
- *
8
- * DESIGN PATTERNS:
9
- * - CLI pattern with Commander for argument parsing
10
- * - Lazy command loading for fast startup
11
- * - Transport abstraction for multiple communication methods
12
- *
13
- * CODING STANDARDS:
14
- * - Use async/await for asynchronous operations
15
- * - Handle errors gracefully with try-catch
16
- * - Log important events for debugging
17
- * - Load commands lazily to minimize startup time
18
- *
19
- * AVOID:
20
- * - Hardcoding command logic in index.ts (use separate command files)
21
- * - Missing error handling for command execution
22
- * - Eager loading of all commands at startup
23
- */
24
- const packageJson = { version: "0.1.0" };
25
- const commandDefinitions = [{
26
- name: "mcp-serve",
27
- description: "Start MCP server with specified transport",
28
- loader: () => import("./commands-c927CRZc.mjs").then((m) => m.mcpServeCommand)
29
- }];
30
- /**
31
- * Custom error for CLI execution failures with error codes and cause chaining.
32
- */
33
- var CLIExecutionError = class extends Error {
34
- code;
35
- recovery;
36
- constructor(message, code = "CLI_EXECUTION_FAILED", options) {
37
- super(message, options);
38
- this.name = "CLIExecutionError";
39
- this.code = code;
40
- this.recovery = options?.recovery;
41
- }
42
- };
43
- /**
44
- * Error thrown when a command fails to load dynamically.
45
- * Provides error code, command name context, and recovery suggestion.
46
- */
47
- var CommandLoadError = class extends Error {
48
- code = "COMMAND_LOAD_ERROR";
49
- recovery;
50
- commandName;
51
- constructor(commandName, message, options) {
52
- super(`Failed to load command '${commandName}': ${message}`, options);
53
- this.name = "CommandLoadError";
54
- this.commandName = commandName;
55
- this.recovery = `Check that the command module exists and exports the expected command. Run with --help to see available commands.`;
56
- }
57
- };
58
- /**
59
- * Creates a lazy-loading command wrapper.
60
- * The actual command is only imported when invoked.
61
- * Includes error handling for dynamic import failures.
62
- */
63
- function createLazyCommand(def) {
64
- const command = new Command(def.name).description(def.description).allowUnknownOption(true).allowExcessArguments(true);
65
- command.action(async () => {
66
- let realCommand;
67
- try {
68
- realCommand = await def.loader();
69
- } catch (error) {
70
- if (error instanceof CommandLoadError) throw error;
71
- throw new CommandLoadError(def.name, error instanceof Error ? error.message : String(error), { cause: error });
72
- }
73
- const parentArgs = process.argv.slice(2);
74
- await new Command().addCommand(realCommand).parseAsync([
75
- "node",
76
- "imagine-mcp",
77
- ...parentArgs
78
- ]);
79
- });
80
- return command;
81
- }
82
- /**
83
- * Main entry point with lazy command loading for fast startup.
84
- */
85
- async function main() {
86
- const invokedCommand = process.argv[2] ?? "unknown";
87
- try {
88
- const program = new Command();
89
- program.name("imagine").description("MCP server for AI image generation and manipulation").version(packageJson.version);
90
- for (const def of commandDefinitions) program.addCommand(createLazyCommand(def));
91
- await program.parseAsync(process.argv);
92
- } catch (error) {
93
- if (error instanceof CLIExecutionError) {
94
- process.stderr.write(`Error [${error.code}] ${JSON.stringify({
95
- command: invokedCommand,
96
- recovery: error.recovery,
97
- message: error.message,
98
- cause: error.cause instanceof Error ? error.cause.message : error.cause
99
- })}\n`);
100
- if (error.recovery) process.stderr.write(`Recovery: ${error.recovery}\n`);
101
- if (error.cause) process.stderr.write(`Caused by: ${error.cause instanceof Error ? error.cause.message : String(error.cause)}\n`);
102
- } else if (error instanceof CommandLoadError) {
103
- process.stderr.write(`Error [${error.code}] ${JSON.stringify({
104
- command: invokedCommand,
105
- recovery: error.recovery,
106
- message: error.message
107
- })}\n`);
108
- if (error.recovery) process.stderr.write(`Recovery: ${error.recovery}\n`);
109
- if (error.cause) process.stderr.write(`Caused by: ${error.cause instanceof Error ? error.cause.message : String(error.cause)}\n`);
110
- } else {
111
- const errorCode = error.code ?? "CLI_EXECUTION_FAILED";
112
- process.stderr.write(`Error [${errorCode}] ${JSON.stringify({
113
- command: invokedCommand,
114
- message: error instanceof Error ? error.message : String(error)
115
- })}\n`);
116
- process.stderr.write("Recovery: Run with --help for usage information.\n");
117
- if (error instanceof Error && error.cause) process.stderr.write(`Caused by: ${error.cause instanceof Error ? error.cause.message : String(error.cause)}\n`);
118
- }
119
- process.exit(1);
120
- }
121
- }
122
- main();
123
-
124
- //#endregion
125
- export { CLIExecutionError, CommandLoadError, commandDefinitions, createLazyCommand };
2
+ import{Command as e}from"commander";const t={version:`0.1.0`},n=[{name:`mcp-serve`,description:`Start MCP server with specified transport`,loader:()=>import(`./commands-c927CRZc.mjs`).then(e=>e.mcpServeCommand)}];var r=class extends Error{code;recovery;constructor(e,t=`CLI_EXECUTION_FAILED`,n){super(e,n),this.name=`CLIExecutionError`,this.code=t,this.recovery=n?.recovery}},i=class extends Error{code=`COMMAND_LOAD_ERROR`;recovery;commandName;constructor(e,t,n){super(`Failed to load command '${e}': ${t}`,n),this.name=`CommandLoadError`,this.commandName=e,this.recovery=`Check that the command module exists and exports the expected command. Run with --help to see available commands.`}};function a(t){let n=new e(t.name).description(t.description).allowUnknownOption(!0).allowExcessArguments(!0);return n.action(async()=>{let n;try{n=await t.loader()}catch(e){throw e instanceof i?e:new i(t.name,e instanceof Error?e.message:String(e),{cause:e})}let r=process.argv.slice(2);await new e().addCommand(n).parseAsync([`node`,`imagine-mcp`,...r])}),n}async function o(){let o=process.argv[2]??`unknown`;try{let r=new e;r.name(`imagine`).description(`MCP server for AI image generation and manipulation`).version(t.version);for(let e of n)r.addCommand(a(e));await r.parseAsync(process.argv)}catch(e){if(e instanceof r)process.stderr.write(`Error [${e.code}] ${JSON.stringify({command:o,recovery:e.recovery,message:e.message,cause:e.cause instanceof Error?e.cause.message:e.cause})}\n`),e.recovery&&process.stderr.write(`Recovery: ${e.recovery}\n`),e.cause&&process.stderr.write(`Caused by: ${e.cause instanceof Error?e.cause.message:String(e.cause)}\n`);else if(e instanceof i)process.stderr.write(`Error [${e.code}] ${JSON.stringify({command:o,recovery:e.recovery,message:e.message})}\n`),e.recovery&&process.stderr.write(`Recovery: ${e.recovery}\n`),e.cause&&process.stderr.write(`Caused by: ${e.cause instanceof Error?e.cause.message:String(e.cause)}\n`);else{let t=e.code??`CLI_EXECUTION_FAILED`;process.stderr.write(`Error [${t}] ${JSON.stringify({command:o,message:e instanceof Error?e.message:String(e)})}\n`),process.stderr.write(`Recovery: Run with --help for usage information.
3
+ `),e instanceof Error&&e.cause&&process.stderr.write(`Caused by: ${e.cause instanceof Error?e.cause.message:String(e.cause)}\n`)}process.exit(1)}}o();export{r as CLIExecutionError,i as CommandLoadError,n as commandDefinitions,a as createLazyCommand};
4
+ //# sourceMappingURL=cli.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.mjs","names":["commandDefinitions: CommandDef[]","realCommand: Command"],"sources":["../src/cli.ts"],"sourcesContent":["#!/usr/bin/env node\n/**\n * MCP Server Entry Point\n *\n * DESIGN PATTERNS:\n * - CLI pattern with Commander for argument parsing\n * - Lazy command loading for fast startup\n * - Transport abstraction for multiple communication methods\n *\n * CODING STANDARDS:\n * - Use async/await for asynchronous operations\n * - Handle errors gracefully with try-catch\n * - Log important events for debugging\n * - Load commands lazily to minimize startup time\n *\n * AVOID:\n * - Hardcoding command logic in index.ts (use separate command files)\n * - Missing error handling for command execution\n * - Eager loading of all commands at startup\n */\nimport { Command } from 'commander';\n\nconst packageJson = { version: '0.1.0' };\n\n/**\n * Command metadata for lazy loading.\n * Definitions are inline to avoid importing command modules at startup.\n */\nexport interface CommandDef {\n name: string;\n description: string;\n loader: () => Promise<Command>;\n}\n\nexport const commandDefinitions: CommandDef[] = [\n {\n name: 'mcp-serve',\n description: 'Start MCP server with specified transport',\n loader: () => import('./commands').then((m) => m.mcpServeCommand),\n },\n];\n\n/**\n * Custom error for CLI execution failures with error codes and cause chaining.\n */\nexport class CLIExecutionError extends Error {\n readonly code: string;\n readonly recovery?: string;\n\n constructor(message: string, code = 'CLI_EXECUTION_FAILED', options?: ErrorOptions & { recovery?: string }) {\n super(message, options);\n this.name = 'CLIExecutionError';\n this.code = code;\n this.recovery = options?.recovery;\n }\n}\n\n/**\n * Error thrown when a command fails to load dynamically.\n * Provides error code, command name context, and recovery suggestion.\n */\nexport class CommandLoadError extends Error {\n readonly code = 'COMMAND_LOAD_ERROR';\n readonly recovery: string;\n readonly commandName: string;\n\n constructor(commandName: string, message: string, options?: ErrorOptions) {\n super(`Failed to load command '${commandName}': ${message}`, options);\n this.name = 'CommandLoadError';\n this.commandName = commandName;\n this.recovery = `Check that the command module exists and exports the expected command. Run with --help to see available commands.`;\n }\n}\n\n/**\n * Creates a lazy-loading command wrapper.\n * The actual command is only imported when invoked.\n * Includes error handling for dynamic import failures.\n */\nexport function createLazyCommand(def: CommandDef): Command {\n const command = new Command(def.name)\n .description(def.description)\n .allowUnknownOption(true)\n .allowExcessArguments(true);\n\n command.action(async () => {\n let realCommand: Command;\n try {\n realCommand = await def.loader();\n } catch (error) {\n if (error instanceof CommandLoadError) {\n throw error;\n }\n throw new CommandLoadError(def.name, error instanceof Error ? error.message : String(error), { cause: error });\n }\n\n const parentArgs = process.argv.slice(2);\n const program = new Command().addCommand(realCommand);\n await program.parseAsync(['node', 'imagine-mcp', ...parentArgs]);\n });\n\n return command;\n}\n\n/**\n * Main entry point with lazy command loading for fast startup.\n */\nasync function main() {\n const invokedCommand = process.argv[2] ?? 'unknown';\n\n try {\n const program = new Command();\n\n program\n .name('imagine')\n .description('MCP server for AI image generation and manipulation')\n .version(packageJson.version);\n\n for (const def of commandDefinitions) {\n program.addCommand(createLazyCommand(def));\n }\n\n await program.parseAsync(process.argv);\n } catch (error) {\n if (error instanceof CLIExecutionError) {\n process.stderr.write(\n `Error [${error.code}] ${JSON.stringify({\n command: invokedCommand,\n recovery: error.recovery,\n message: error.message,\n cause: error.cause instanceof Error ? error.cause.message : error.cause,\n })}\\n`,\n );\n if (error.recovery) {\n process.stderr.write(`Recovery: ${error.recovery}\\n`);\n }\n if (error.cause) {\n process.stderr.write(\n `Caused by: ${error.cause instanceof Error ? error.cause.message : String(error.cause)}\\n`,\n );\n }\n } else if (error instanceof CommandLoadError) {\n process.stderr.write(\n `Error [${error.code}] ${JSON.stringify({\n command: invokedCommand,\n recovery: error.recovery,\n message: error.message,\n })}\\n`,\n );\n if (error.recovery) {\n process.stderr.write(`Recovery: ${error.recovery}\\n`);\n }\n if (error.cause) {\n process.stderr.write(\n `Caused by: ${error.cause instanceof Error ? error.cause.message : String(error.cause)}\\n`,\n );\n }\n } else {\n const errorCode = (error as { code?: string }).code ?? 'CLI_EXECUTION_FAILED';\n process.stderr.write(\n `Error [${errorCode}] ${JSON.stringify({\n command: invokedCommand,\n message: error instanceof Error ? error.message : String(error),\n })}\\n`,\n );\n process.stderr.write('Recovery: Run with --help for usage information.\\n');\n if (error instanceof Error && error.cause) {\n process.stderr.write(\n `Caused by: ${error.cause instanceof Error ? error.cause.message : String(error.cause)}\\n`,\n );\n }\n }\n process.exit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function(e){return e.STDIO=`stdio`,e.HTTP=`http`,e.SSE=`sse`,e}({});async function r(e){await e.start();let t=async t=>{process.stderr.write(`\nReceived ${t}, shutting down gracefully...\n`);try{await e.stop(),process.exit(0)}catch(e){process.stderr.write(`Error during shutdown: ${e instanceof Error?e.message:String(e)}\n`),process.exit(1)}};process.on(`SIGINT`,()=>t(`SIGINT`)),process.on(`SIGTERM`,()=>t(`SIGTERM`))}const i=new t.Command(`mcp-serve`).description(`Start MCP server with specified transport`).option(`-t, --type <type>`,`Transport type: stdio, http, or sse`,`stdio`).option(`-p, --port <port>`,`Port to listen on (http/sse only)`,e=>parseInt(e,10),3e3).option(`--host <host>`,`Host to bind to (http/sse only)`,`localhost`).action(async t=>{try{let i=t.type.toLowerCase();i===`stdio`?await r(new e.t(e.i())):i===`http`?await r(new e.r(()=>e.i(),{mode:n.HTTP,port:t.port||Number(process.env.MCP_PORT)||3e3,host:t.host||process.env.MCP_HOST||`localhost`})):i===`sse`?await r(new e.n(()=>e.i(),{mode:n.SSE,port:t.port||Number(process.env.MCP_PORT)||3e3,host:t.host||process.env.MCP_HOST||`localhost`})):(process.stderr.write(`Unknown transport type: ${i}. Use: stdio, http, or sse\n`),process.exit(1))}catch(e){process.stderr.write(`Failed to start MCP server: ${e instanceof Error?e.message:String(e)}\n`),process.exit(1)}});exports.mcpServeCommand=i;
2
+ //# sourceMappingURL=commands-Bda9LPMQ.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"commands-Bda9LPMQ.cjs","names":["Command","StdioTransportHandler","createServer","HttpTransportHandler","SseTransportHandler"],"sources":["../src/types/index.ts","../src/commands/mcp-serve.ts"],"sourcesContent":["/**\n * Shared TypeScript Types\n *\n * DESIGN PATTERNS:\n * - Type-first development\n * - Interface segregation\n *\n * CODING STANDARDS:\n * - Export all shared types from this file\n * - Use descriptive names for types and interfaces\n */\n\nimport type { CallToolResult } from '@modelcontextprotocol/sdk/types.js';\n\n/**\n * Tool definition for MCP\n */\nexport interface ToolDefinition {\n name: string;\n description: string;\n inputSchema: {\n type: string;\n properties: Record<string, any>;\n required?: string[];\n additionalProperties?: boolean;\n };\n}\n\n/**\n * Base tool interface following MCP SDK patterns\n */\nexport interface Tool<TInput = any> {\n getDefinition(): ToolDefinition;\n execute(input: TInput): Promise<CallToolResult>;\n}\n\n/**\n * Transport mode types\n */\nexport enum TransportMode {\n STDIO = 'stdio',\n HTTP = 'http',\n SSE = 'sse',\n}\n\n/**\n * Transport configuration options\n */\nexport interface TransportConfig {\n mode: TransportMode;\n port?: number;\n host?: string;\n}\n\n/**\n * Base interface for all transport handlers\n */\nexport interface TransportHandler {\n start(): Promise<void>;\n stop(): Promise<void>;\n}\n\n/**\n * HTTP transport specific types\n */\nexport interface HttpTransportHandler extends TransportHandler {\n getPort(): number;\n getHost(): string;\n}\n","/**\n * MCP Serve Command\n *\n * DESIGN PATTERNS:\n * - Command pattern with Commander for CLI argument parsing\n * - Transport abstraction pattern for flexible deployment (stdio, HTTP, SSE)\n * - Factory pattern for creating transport handlers\n * - Graceful shutdown pattern with signal handling\n *\n * CODING STANDARDS:\n * - Use async/await for asynchronous operations\n * - Implement proper error handling with try-catch blocks\n * - Handle process signals for graceful shutdown\n * - Provide clear CLI options and help messages\n *\n * AVOID:\n * - Hardcoded configuration values (use CLI options or environment variables)\n * - Missing error handling for transport startup\n * - Not cleaning up resources on shutdown\n */\n\nimport { Command } from 'commander';\nimport { createServer } from '../server';\nimport { HttpTransportHandler } from '../transports/http';\nimport { SseTransportHandler } from '../transports/sse';\nimport { StdioTransportHandler } from '../transports/stdio';\nimport { type TransportConfig, TransportMode } from '../types';\n\n/**\n * Start MCP server with given transport handler\n */\nasync function startServer(handler: any) {\n await handler.start();\n\n // Handle graceful shutdown\n const shutdown = async (signal: string) => {\n process.stderr.write(`\\nReceived ${signal}, shutting down gracefully...\\n`);\n try {\n await handler.stop();\n process.exit(0);\n } catch (error) {\n process.stderr.write(`Error during shutdown: ${error instanceof Error ? error.message : String(error)}\\n`);\n process.exit(1);\n }\n };\n\n process.on('SIGINT', () => shutdown('SIGINT'));\n process.on('SIGTERM', () => shutdown('SIGTERM'));\n}\n\n/**\n * MCP Serve command\n */\nexport const mcpServeCommand = new Command('mcp-serve')\n .description('Start MCP server with specified transport')\n .option('-t, --type <type>', 'Transport type: stdio, http, or sse', 'stdio')\n .option('-p, --port <port>', 'Port to listen on (http/sse only)', (val) => parseInt(val, 10), 3000)\n .option('--host <host>', 'Host to bind to (http/sse only)', 'localhost')\n .action(async (options) => {\n try {\n const transportType = options.type.toLowerCase();\n\n if (transportType === 'stdio') {\n const server = createServer();\n const handler = new StdioTransportHandler(server);\n await startServer(handler);\n } else if (transportType === 'http') {\n // For HTTP, pass a factory function to create new server instances per session\n const config: TransportConfig = {\n mode: TransportMode.HTTP,\n port: options.port || Number(process.env.MCP_PORT) || 3000,\n host: options.host || process.env.MCP_HOST || 'localhost',\n };\n const handler = new HttpTransportHandler(() => createServer(), config);\n await startServer(handler);\n } else if (transportType === 'sse') {\n // For SSE, pass a factory function to create new server instances per connection\n const config: TransportConfig = {\n mode: TransportMode.SSE,\n port: options.port || Number(process.env.MCP_PORT) || 3000,\n host: options.host || process.env.MCP_HOST || 'localhost',\n };\n const handler = new SseTransportHandler(() => createServer(), config);\n await startServer(handler);\n } else {\n process.stderr.write(`Unknown transport type: ${transportType}. Use: stdio, http, or sse\\n`);\n process.exit(1);\n }\n } catch (error) {\n process.stderr.write(`Failed to start MCP server: ${error instanceof Error ? error.message : String(error)}\\n`);\n process.exit(1);\n }\n });\n"],"mappings":"mEAuCY,EAAA,SAAA,EAAL,OACL,GAAA,MAAA,QACA,EAAA,KAAA,OACA,EAAA,IAAA,aCXF,eAAe,EAAY,EAAc,CACvC,MAAM,EAAQ,OAAO,CAGrB,IAAM,EAAW,KAAO,IAAmB,CACzC,QAAQ,OAAO,MAAM,cAAc,EAAO,iCAAiC,CAC3E,GAAI,CACF,MAAM,EAAQ,MAAM,CACpB,QAAQ,KAAK,EAAE,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
1
- import { i as createServer, n as SseTransportHandler, r as HttpTransportHandler, t as StdioTransportHandler } from "./stdio-CuIrQe3m.mjs";
2
- import { Command } from "commander";
3
-
4
- //#region src/types/index.ts
5
- /**
6
- * Transport mode types
7
- */
8
- let TransportMode = /* @__PURE__ */ function(TransportMode$1) {
9
- TransportMode$1["STDIO"] = "stdio";
10
- TransportMode$1["HTTP"] = "http";
11
- TransportMode$1["SSE"] = "sse";
12
- return TransportMode$1;
13
- }({});
14
-
15
- //#endregion
16
- //#region src/commands/mcp-serve.ts
17
- /**
18
- * MCP Serve Command
19
- *
20
- * DESIGN PATTERNS:
21
- * - Command pattern with Commander for CLI argument parsing
22
- * - Transport abstraction pattern for flexible deployment (stdio, HTTP, SSE)
23
- * - Factory pattern for creating transport handlers
24
- * - Graceful shutdown pattern with signal handling
25
- *
26
- * CODING STANDARDS:
27
- * - Use async/await for asynchronous operations
28
- * - Implement proper error handling with try-catch blocks
29
- * - Handle process signals for graceful shutdown
30
- * - Provide clear CLI options and help messages
31
- *
32
- * AVOID:
33
- * - Hardcoded configuration values (use CLI options or environment variables)
34
- * - Missing error handling for transport startup
35
- * - Not cleaning up resources on shutdown
36
- */
37
- /**
38
- * Start MCP server with given transport handler
39
- */
40
- async function startServer(handler) {
41
- await handler.start();
42
- const shutdown = async (signal) => {
43
- process.stderr.write(`\nReceived ${signal}, shutting down gracefully...\n`);
44
- try {
45
- await handler.stop();
46
- process.exit(0);
47
- } catch (error) {
48
- process.stderr.write(`Error during shutdown: ${error instanceof Error ? error.message : String(error)}\n`);
49
- process.exit(1);
50
- }
51
- };
52
- process.on("SIGINT", () => shutdown("SIGINT"));
53
- process.on("SIGTERM", () => shutdown("SIGTERM"));
54
- }
55
- /**
56
- * MCP Serve command
57
- */
58
- const mcpServeCommand = new Command("mcp-serve").description("Start MCP server with specified transport").option("-t, --type <type>", "Transport type: stdio, http, or sse", "stdio").option("-p, --port <port>", "Port to listen on (http/sse only)", (val) => parseInt(val, 10), 3e3).option("--host <host>", "Host to bind to (http/sse only)", "localhost").action(async (options) => {
59
- try {
60
- const transportType = options.type.toLowerCase();
61
- if (transportType === "stdio") await startServer(new StdioTransportHandler(createServer()));
62
- else if (transportType === "http") await startServer(new HttpTransportHandler(() => createServer(), {
63
- mode: TransportMode.HTTP,
64
- port: options.port || Number(process.env.MCP_PORT) || 3e3,
65
- host: options.host || process.env.MCP_HOST || "localhost"
66
- }));
67
- else if (transportType === "sse") await startServer(new SseTransportHandler(() => createServer(), {
68
- mode: TransportMode.SSE,
69
- port: options.port || Number(process.env.MCP_PORT) || 3e3,
70
- host: options.host || process.env.MCP_HOST || "localhost"
71
- }));
72
- else {
73
- process.stderr.write(`Unknown transport type: ${transportType}. Use: stdio, http, or sse\n`);
74
- process.exit(1);
75
- }
76
- } catch (error) {
77
- process.stderr.write(`Failed to start MCP server: ${error instanceof Error ? error.message : String(error)}\n`);
78
- process.exit(1);
79
- }
80
- });
81
-
82
- //#endregion
83
- export { mcpServeCommand };
1
+ import{i as e,n as t,r as n,t as r}from"./stdio-CuIrQe3m.mjs";import{Command as i}from"commander";let a=function(e){return e.STDIO=`stdio`,e.HTTP=`http`,e.SSE=`sse`,e}({});async function o(e){await e.start();let t=async t=>{process.stderr.write(`\nReceived ${t}, shutting down gracefully...\n`);try{await e.stop(),process.exit(0)}catch(e){process.stderr.write(`Error during shutdown: ${e instanceof Error?e.message:String(e)}\n`),process.exit(1)}};process.on(`SIGINT`,()=>t(`SIGINT`)),process.on(`SIGTERM`,()=>t(`SIGTERM`))}const s=new i(`mcp-serve`).description(`Start MCP server with specified transport`).option(`-t, --type <type>`,`Transport type: stdio, http, or sse`,`stdio`).option(`-p, --port <port>`,`Port to listen on (http/sse only)`,e=>parseInt(e,10),3e3).option(`--host <host>`,`Host to bind to (http/sse only)`,`localhost`).action(async i=>{try{let s=i.type.toLowerCase();s===`stdio`?await o(new r(e())):s===`http`?await o(new n(()=>e(),{mode:a.HTTP,port:i.port||Number(process.env.MCP_PORT)||3e3,host:i.host||process.env.MCP_HOST||`localhost`})):s===`sse`?await o(new t(()=>e(),{mode:a.SSE,port:i.port||Number(process.env.MCP_PORT)||3e3,host:i.host||process.env.MCP_HOST||`localhost`})):(process.stderr.write(`Unknown transport type: ${s}. Use: stdio, http, or sse\n`),process.exit(1))}catch(e){process.stderr.write(`Failed to start MCP server: ${e instanceof Error?e.message:String(e)}\n`),process.exit(1)}});export{s as mcpServeCommand};
2
+ //# sourceMappingURL=commands-c927CRZc.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"commands-c927CRZc.mjs","names":[],"sources":["../src/types/index.ts","../src/commands/mcp-serve.ts"],"sourcesContent":["/**\n * Shared TypeScript Types\n *\n * DESIGN PATTERNS:\n * - Type-first development\n * - Interface segregation\n *\n * CODING STANDARDS:\n * - Export all shared types from this file\n * - Use descriptive names for types and interfaces\n */\n\nimport type { CallToolResult } from '@modelcontextprotocol/sdk/types.js';\n\n/**\n * Tool definition for MCP\n */\nexport interface ToolDefinition {\n name: string;\n description: string;\n inputSchema: {\n type: string;\n properties: Record<string, any>;\n required?: string[];\n additionalProperties?: boolean;\n };\n}\n\n/**\n * Base tool interface following MCP SDK patterns\n */\nexport interface Tool<TInput = any> {\n getDefinition(): ToolDefinition;\n execute(input: TInput): Promise<CallToolResult>;\n}\n\n/**\n * Transport mode types\n */\nexport enum TransportMode {\n STDIO = 'stdio',\n HTTP = 'http',\n SSE = 'sse',\n}\n\n/**\n * Transport configuration options\n */\nexport interface TransportConfig {\n mode: TransportMode;\n port?: number;\n host?: string;\n}\n\n/**\n * Base interface for all transport handlers\n */\nexport interface TransportHandler {\n start(): Promise<void>;\n stop(): Promise<void>;\n}\n\n/**\n * HTTP transport specific types\n */\nexport interface HttpTransportHandler extends TransportHandler {\n getPort(): number;\n getHost(): string;\n}\n","/**\n * MCP Serve Command\n *\n * DESIGN PATTERNS:\n * - Command pattern with Commander for CLI argument parsing\n * - Transport abstraction pattern for flexible deployment (stdio, HTTP, SSE)\n * - Factory pattern for creating transport handlers\n * - Graceful shutdown pattern with signal handling\n *\n * CODING STANDARDS:\n * - Use async/await for asynchronous operations\n * - Implement proper error handling with try-catch blocks\n * - Handle process signals for graceful shutdown\n * - Provide clear CLI options and help messages\n *\n * AVOID:\n * - Hardcoded configuration values (use CLI options or environment variables)\n * - Missing error handling for transport startup\n * - Not cleaning up resources on shutdown\n */\n\nimport { Command } from 'commander';\nimport { createServer } from '../server';\nimport { HttpTransportHandler } from '../transports/http';\nimport { SseTransportHandler } from '../transports/sse';\nimport { StdioTransportHandler } from '../transports/stdio';\nimport { type TransportConfig, TransportMode } from '../types';\n\n/**\n * Start MCP server with given transport handler\n */\nasync function startServer(handler: any) {\n await handler.start();\n\n // Handle graceful shutdown\n const shutdown = async (signal: string) => {\n process.stderr.write(`\\nReceived ${signal}, shutting down gracefully...\\n`);\n try {\n await handler.stop();\n process.exit(0);\n } catch (error) {\n process.stderr.write(`Error during shutdown: ${error instanceof Error ? error.message : String(error)}\\n`);\n process.exit(1);\n }\n };\n\n process.on('SIGINT', () => shutdown('SIGINT'));\n process.on('SIGTERM', () => shutdown('SIGTERM'));\n}\n\n/**\n * MCP Serve command\n */\nexport const mcpServeCommand = new Command('mcp-serve')\n .description('Start MCP server with specified transport')\n .option('-t, --type <type>', 'Transport type: stdio, http, or sse', 'stdio')\n .option('-p, --port <port>', 'Port to listen on (http/sse only)', (val) => parseInt(val, 10), 3000)\n .option('--host <host>', 'Host to bind to (http/sse only)', 'localhost')\n .action(async (options) => {\n try {\n const transportType = options.type.toLowerCase();\n\n if (transportType === 'stdio') {\n const server = createServer();\n const handler = new StdioTransportHandler(server);\n await startServer(handler);\n } else if (transportType === 'http') {\n // For HTTP, pass a factory function to create new server instances per session\n const config: TransportConfig = {\n mode: TransportMode.HTTP,\n port: options.port || Number(process.env.MCP_PORT) || 3000,\n host: options.host || process.env.MCP_HOST || 'localhost',\n };\n const handler = new HttpTransportHandler(() => createServer(), config);\n await startServer(handler);\n } else if (transportType === 'sse') {\n // For SSE, pass a factory function to create new server instances per connection\n const config: TransportConfig = {\n mode: TransportMode.SSE,\n port: options.port || Number(process.env.MCP_PORT) || 3000,\n host: options.host || process.env.MCP_HOST || 'localhost',\n };\n const handler = new SseTransportHandler(() => createServer(), config);\n await startServer(handler);\n } else {\n process.stderr.write(`Unknown transport type: ${transportType}. Use: stdio, http, or sse\\n`);\n process.exit(1);\n }\n } catch (error) {\n process.stderr.write(`Failed to start MCP server: ${error instanceof Error ? error.message : String(error)}\\n`);\n process.exit(1);\n }\n });\n"],"mappings":"kGAuCA,IAAY,EAAA,SAAA,EAAL,OACL,GAAA,MAAA,QACA,EAAA,KAAA,OACA,EAAA,IAAA,aCXF,eAAe,EAAY,EAAc,CACvC,MAAM,EAAQ,OAAO,CAGrB,IAAM,EAAW,KAAO,IAAmB,CACzC,QAAQ,OAAO,MAAM,cAAc,EAAO,iCAAiC,CAC3E,GAAI,CACF,MAAM,EAAQ,MAAM,CACpB,QAAQ,KAAK,EAAE,OACR,EAAO,CACd,QAAQ,OAAO,MAAM,0BAA0B,aAAiB,MAAQ,EAAM,QAAU,OAAO,EAAM,CAAC,IAAI,CAC1G,QAAQ,KAAK,EAAE,GAInB,QAAQ,GAAG,aAAgB,EAAS,SAAS,CAAC,CAC9C,QAAQ,GAAG,cAAiB,EAAS,UAAU,CAAC,CAMlD,MAAa,EAAkB,IAAI,EAAQ,YAAY,CACpD,YAAY,4CAA4C,CACxD,OAAO,oBAAqB,sCAAuC,QAAQ,CAC3E,OAAO,oBAAqB,oCAAsC,GAAQ,SAAS,EAAK,GAAG,CAAE,IAAK,CAClG,OAAO,gBAAiB,kCAAmC,YAAY,CACvE,OAAO,KAAO,IAAY,CACzB,GAAI,CACF,IAAM,EAAgB,EAAQ,KAAK,aAAa,CAE5C,IAAkB,QAGpB,MAAM,EADU,IAAI,EADL,GAAc,CACoB,CACvB,CACjB,IAAkB,OAQ3B,MAAM,EADU,IAAI,MAA2B,GAAc,CAL7B,CAC9B,KAAM,EAAc,KACpB,KAAM,EAAQ,MAAQ,OAAO,QAAQ,IAAI,SAAS,EAAI,IACtD,KAAM,EAAQ,MAAQ,QAAQ,IAAI,UAAY,YAC/C,CACqE,CAC5C,CACjB,IAAkB,MAQ3B,MAAM,EADU,IAAI,MAA0B,GAAc,CAL5B,CAC9B,KAAM,EAAc,IACpB,KAAM,EAAQ,MAAQ,OAAO,QAAQ,IAAI,SAAS,EAAI,IACtD,KAAM,EAAQ,MAAQ,QAAQ,IAAI,UAAY,YAC/C,CACoE,CAC3C,EAE1B,QAAQ,OAAO,MAAM,2BAA2B,EAAc,8BAA8B,CAC5F,QAAQ,KAAK,EAAE,QAEV,EAAO,CACd,QAAQ,OAAO,MAAM,+BAA+B,aAAiB,MAAQ,EAAM,QAAU,OAAO,EAAM,CAAC,IAAI,CAC/G,QAAQ,KAAK,EAAE,GAEjB"}
package/dist/index.cjs CHANGED
@@ -1,8 +1 @@
1
- const require_stdio = require('./stdio-D7OcvsZd.cjs');
2
-
3
- exports.HttpTransportHandler = require_stdio.HttpTransportHandler;
4
- exports.ReadImageTool = require_stdio.ReadImageTool;
5
- exports.SseTransportHandler = require_stdio.SseTransportHandler;
6
- exports.StdioTransportHandler = require_stdio.StdioTransportHandler;
7
- exports.UnsplashSearchTool = require_stdio.UnsplashSearchTool;
8
- exports.createServer = require_stdio.createServer;
1
+ const e=require(`./stdio-qsNJYZZf.cjs`);exports.HttpTransportHandler=e.r,exports.ReadImageTool=e.o,exports.SseTransportHandler=e.n,exports.StdioTransportHandler=e.t,exports.UnsplashSearchTool=e.a,exports.createServer=e.i;
package/dist/index.mjs CHANGED
@@ -1,3 +1 @@
1
- import { a as UnsplashSearchTool, i as createServer, n as SseTransportHandler, o as ReadImageTool, r as HttpTransportHandler, t as StdioTransportHandler } from "./stdio-CuIrQe3m.mjs";
2
-
3
- export { HttpTransportHandler, ReadImageTool, SseTransportHandler, StdioTransportHandler, UnsplashSearchTool, createServer };
1
+ import{a as e,i as t,n,o as r,r as i,t as a}from"./stdio-CuIrQe3m.mjs";export{i as HttpTransportHandler,r as ReadImageTool,n as SseTransportHandler,a as StdioTransportHandler,e as UnsplashSearchTool,t as createServer};