@agimon-ai/imagine-mcp 0.2.0 → 0.2.1
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 +2 -128
- package/dist/cli.mjs +2 -124
- package/dist/commands-Bda9LPMQ.cjs +1 -0
- package/dist/commands-c927CRZc.mjs +1 -83
- package/dist/index.cjs +1 -8
- package/dist/index.mjs +1 -3
- package/dist/stdio-CuIrQe3m.mjs +19 -885
- package/dist/stdio-qsNJYZZf.cjs +25 -0
- package/package.json +1 -1
- package/dist/cli.d.cts +0 -43
- package/dist/cli.d.mts +0 -43
- package/dist/commands-BlRAon0l.cjs +0 -83
- package/dist/index.d.cts +0 -150
- package/dist/index.d.mts +0 -150
- package/dist/stdio-D7OcvsZd.cjs +0 -957
package/dist/cli.cjs
CHANGED
|
@@ -1,129 +1,3 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
const
|
|
3
|
-
|
|
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;
|
package/dist/cli.mjs
CHANGED
|
@@ -1,125 +1,3 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import
|
|
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};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=require(`./stdio-qsNJYZZf.cjs`);let t=require(`commander`),n=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;
|
|
@@ -1,83 +1 @@
|
|
|
1
|
-
import
|
|
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};
|
package/dist/index.cjs
CHANGED
|
@@ -1,8 +1 @@
|
|
|
1
|
-
const
|
|
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
|
|
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};
|