@agimon-ai/imagine-mcp 0.2.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/LICENSE +52 -0
- package/README.md +144 -0
- package/dist/cli.cjs +129 -0
- package/dist/cli.d.cts +43 -0
- package/dist/cli.d.mts +43 -0
- package/dist/cli.mjs +125 -0
- package/dist/commands-BlRAon0l.cjs +83 -0
- package/dist/commands-c927CRZc.mjs +83 -0
- package/dist/index.cjs +8 -0
- package/dist/index.d.cts +150 -0
- package/dist/index.d.mts +150 -0
- package/dist/index.mjs +3 -0
- package/dist/stdio-CuIrQe3m.mjs +891 -0
- package/dist/stdio-D7OcvsZd.cjs +957 -0
- package/package.json +59 -0
|
@@ -0,0 +1,83 @@
|
|
|
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 };
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
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;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
2
|
+
import { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
|
|
3
|
+
|
|
4
|
+
//#region src/server/index.d.ts
|
|
5
|
+
|
|
6
|
+
declare function createServer(): Server;
|
|
7
|
+
//#endregion
|
|
8
|
+
//#region src/types/index.d.ts
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Tool definition for MCP
|
|
12
|
+
*/
|
|
13
|
+
interface ToolDefinition {
|
|
14
|
+
name: string;
|
|
15
|
+
description: string;
|
|
16
|
+
inputSchema: {
|
|
17
|
+
type: string;
|
|
18
|
+
properties: Record<string, any>;
|
|
19
|
+
required?: string[];
|
|
20
|
+
additionalProperties?: boolean;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Base tool interface following MCP SDK patterns
|
|
25
|
+
*/
|
|
26
|
+
interface Tool<TInput = any> {
|
|
27
|
+
getDefinition(): ToolDefinition;
|
|
28
|
+
execute(input: TInput): Promise<CallToolResult>;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Transport mode types
|
|
32
|
+
*/
|
|
33
|
+
declare enum TransportMode {
|
|
34
|
+
STDIO = "stdio",
|
|
35
|
+
HTTP = "http",
|
|
36
|
+
SSE = "sse",
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Transport configuration options
|
|
40
|
+
*/
|
|
41
|
+
interface TransportConfig {
|
|
42
|
+
mode: TransportMode;
|
|
43
|
+
port?: number;
|
|
44
|
+
host?: string;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Base interface for all transport handlers
|
|
48
|
+
*/
|
|
49
|
+
interface TransportHandler {
|
|
50
|
+
start(): Promise<void>;
|
|
51
|
+
stop(): Promise<void>;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* HTTP transport specific types
|
|
55
|
+
*/
|
|
56
|
+
interface HttpTransportHandler$1 extends TransportHandler {
|
|
57
|
+
getPort(): number;
|
|
58
|
+
getHost(): string;
|
|
59
|
+
}
|
|
60
|
+
//#endregion
|
|
61
|
+
//#region src/tools/ReadImageTool.d.ts
|
|
62
|
+
interface ReadImageToolInput {
|
|
63
|
+
source: string;
|
|
64
|
+
includeBase64?: boolean;
|
|
65
|
+
}
|
|
66
|
+
declare class ReadImageTool implements Tool<ReadImageToolInput> {
|
|
67
|
+
static readonly TOOL_NAME = "read-image";
|
|
68
|
+
private service;
|
|
69
|
+
getDefinition(): ToolDefinition;
|
|
70
|
+
execute(input: ReadImageToolInput): Promise<CallToolResult>;
|
|
71
|
+
}
|
|
72
|
+
//#endregion
|
|
73
|
+
//#region src/tools/UnsplashSearchTool.d.ts
|
|
74
|
+
interface UnsplashSearchToolInput {
|
|
75
|
+
query: string;
|
|
76
|
+
perPage?: number;
|
|
77
|
+
page?: number;
|
|
78
|
+
orientation?: 'landscape' | 'portrait' | 'squarish';
|
|
79
|
+
color?: 'black_and_white' | 'black' | 'white' | 'yellow' | 'orange' | 'red' | 'purple' | 'magenta' | 'green' | 'teal' | 'blue';
|
|
80
|
+
}
|
|
81
|
+
declare class UnsplashSearchTool implements Tool<UnsplashSearchToolInput> {
|
|
82
|
+
static readonly TOOL_NAME = "unsplash_search";
|
|
83
|
+
private service;
|
|
84
|
+
private readonly accessKey?;
|
|
85
|
+
constructor(accessKey?: string);
|
|
86
|
+
private getService;
|
|
87
|
+
getDefinition(): ToolDefinition;
|
|
88
|
+
execute(input: UnsplashSearchToolInput): Promise<CallToolResult>;
|
|
89
|
+
}
|
|
90
|
+
//#endregion
|
|
91
|
+
//#region src/transports/http.d.ts
|
|
92
|
+
/**
|
|
93
|
+
* HTTP transport handler using Streamable HTTP (protocol version 2025-03-26)
|
|
94
|
+
* Provides stateful session management with resumability support
|
|
95
|
+
*/
|
|
96
|
+
declare class HttpTransportHandler implements HttpTransportHandler$1 {
|
|
97
|
+
private serverFactory;
|
|
98
|
+
private app;
|
|
99
|
+
private server;
|
|
100
|
+
private sessionManager;
|
|
101
|
+
private config;
|
|
102
|
+
constructor(serverFactory: Server | (() => Server), config: TransportConfig);
|
|
103
|
+
private setupMiddleware;
|
|
104
|
+
private setupRoutes;
|
|
105
|
+
private handlePostRequest;
|
|
106
|
+
private handleGetRequest;
|
|
107
|
+
private handleDeleteRequest;
|
|
108
|
+
start(): Promise<void>;
|
|
109
|
+
stop(): Promise<void>;
|
|
110
|
+
getPort(): number;
|
|
111
|
+
getHost(): string;
|
|
112
|
+
}
|
|
113
|
+
//#endregion
|
|
114
|
+
//#region src/transports/sse.d.ts
|
|
115
|
+
/**
|
|
116
|
+
* SSE (Server-Sent Events) transport handler
|
|
117
|
+
* Legacy transport for backwards compatibility (protocol version 2024-11-05)
|
|
118
|
+
* Uses separate endpoints: /sse for SSE stream (GET) and /messages for client messages (POST)
|
|
119
|
+
*/
|
|
120
|
+
declare class SseTransportHandler implements HttpTransportHandler$1 {
|
|
121
|
+
private serverFactory;
|
|
122
|
+
private app;
|
|
123
|
+
private server;
|
|
124
|
+
private sessionManager;
|
|
125
|
+
private config;
|
|
126
|
+
constructor(serverFactory: Server | (() => Server), config: TransportConfig);
|
|
127
|
+
private setupMiddleware;
|
|
128
|
+
private setupRoutes;
|
|
129
|
+
private handleSseConnection;
|
|
130
|
+
private handlePostMessage;
|
|
131
|
+
start(): Promise<void>;
|
|
132
|
+
stop(): Promise<void>;
|
|
133
|
+
getPort(): number;
|
|
134
|
+
getHost(): string;
|
|
135
|
+
}
|
|
136
|
+
//#endregion
|
|
137
|
+
//#region src/transports/stdio.d.ts
|
|
138
|
+
/**
|
|
139
|
+
* Stdio transport handler for MCP server
|
|
140
|
+
* Used for command-line and direct integrations
|
|
141
|
+
*/
|
|
142
|
+
declare class StdioTransportHandler implements TransportHandler {
|
|
143
|
+
private server;
|
|
144
|
+
private transport;
|
|
145
|
+
constructor(server: Server);
|
|
146
|
+
start(): Promise<void>;
|
|
147
|
+
stop(): Promise<void>;
|
|
148
|
+
}
|
|
149
|
+
//#endregion
|
|
150
|
+
export { HttpTransportHandler, ReadImageTool, SseTransportHandler, StdioTransportHandler, Tool, ToolDefinition, TransportConfig, TransportHandler, TransportMode, UnsplashSearchTool, createServer };
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
2
|
+
import { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
|
|
3
|
+
|
|
4
|
+
//#region src/server/index.d.ts
|
|
5
|
+
|
|
6
|
+
declare function createServer(): Server;
|
|
7
|
+
//#endregion
|
|
8
|
+
//#region src/types/index.d.ts
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Tool definition for MCP
|
|
12
|
+
*/
|
|
13
|
+
interface ToolDefinition {
|
|
14
|
+
name: string;
|
|
15
|
+
description: string;
|
|
16
|
+
inputSchema: {
|
|
17
|
+
type: string;
|
|
18
|
+
properties: Record<string, any>;
|
|
19
|
+
required?: string[];
|
|
20
|
+
additionalProperties?: boolean;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Base tool interface following MCP SDK patterns
|
|
25
|
+
*/
|
|
26
|
+
interface Tool<TInput = any> {
|
|
27
|
+
getDefinition(): ToolDefinition;
|
|
28
|
+
execute(input: TInput): Promise<CallToolResult>;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Transport mode types
|
|
32
|
+
*/
|
|
33
|
+
declare enum TransportMode {
|
|
34
|
+
STDIO = "stdio",
|
|
35
|
+
HTTP = "http",
|
|
36
|
+
SSE = "sse",
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Transport configuration options
|
|
40
|
+
*/
|
|
41
|
+
interface TransportConfig {
|
|
42
|
+
mode: TransportMode;
|
|
43
|
+
port?: number;
|
|
44
|
+
host?: string;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Base interface for all transport handlers
|
|
48
|
+
*/
|
|
49
|
+
interface TransportHandler {
|
|
50
|
+
start(): Promise<void>;
|
|
51
|
+
stop(): Promise<void>;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* HTTP transport specific types
|
|
55
|
+
*/
|
|
56
|
+
interface HttpTransportHandler$1 extends TransportHandler {
|
|
57
|
+
getPort(): number;
|
|
58
|
+
getHost(): string;
|
|
59
|
+
}
|
|
60
|
+
//#endregion
|
|
61
|
+
//#region src/tools/ReadImageTool.d.ts
|
|
62
|
+
interface ReadImageToolInput {
|
|
63
|
+
source: string;
|
|
64
|
+
includeBase64?: boolean;
|
|
65
|
+
}
|
|
66
|
+
declare class ReadImageTool implements Tool<ReadImageToolInput> {
|
|
67
|
+
static readonly TOOL_NAME = "read-image";
|
|
68
|
+
private service;
|
|
69
|
+
getDefinition(): ToolDefinition;
|
|
70
|
+
execute(input: ReadImageToolInput): Promise<CallToolResult>;
|
|
71
|
+
}
|
|
72
|
+
//#endregion
|
|
73
|
+
//#region src/tools/UnsplashSearchTool.d.ts
|
|
74
|
+
interface UnsplashSearchToolInput {
|
|
75
|
+
query: string;
|
|
76
|
+
perPage?: number;
|
|
77
|
+
page?: number;
|
|
78
|
+
orientation?: 'landscape' | 'portrait' | 'squarish';
|
|
79
|
+
color?: 'black_and_white' | 'black' | 'white' | 'yellow' | 'orange' | 'red' | 'purple' | 'magenta' | 'green' | 'teal' | 'blue';
|
|
80
|
+
}
|
|
81
|
+
declare class UnsplashSearchTool implements Tool<UnsplashSearchToolInput> {
|
|
82
|
+
static readonly TOOL_NAME = "unsplash_search";
|
|
83
|
+
private service;
|
|
84
|
+
private readonly accessKey?;
|
|
85
|
+
constructor(accessKey?: string);
|
|
86
|
+
private getService;
|
|
87
|
+
getDefinition(): ToolDefinition;
|
|
88
|
+
execute(input: UnsplashSearchToolInput): Promise<CallToolResult>;
|
|
89
|
+
}
|
|
90
|
+
//#endregion
|
|
91
|
+
//#region src/transports/http.d.ts
|
|
92
|
+
/**
|
|
93
|
+
* HTTP transport handler using Streamable HTTP (protocol version 2025-03-26)
|
|
94
|
+
* Provides stateful session management with resumability support
|
|
95
|
+
*/
|
|
96
|
+
declare class HttpTransportHandler implements HttpTransportHandler$1 {
|
|
97
|
+
private serverFactory;
|
|
98
|
+
private app;
|
|
99
|
+
private server;
|
|
100
|
+
private sessionManager;
|
|
101
|
+
private config;
|
|
102
|
+
constructor(serverFactory: Server | (() => Server), config: TransportConfig);
|
|
103
|
+
private setupMiddleware;
|
|
104
|
+
private setupRoutes;
|
|
105
|
+
private handlePostRequest;
|
|
106
|
+
private handleGetRequest;
|
|
107
|
+
private handleDeleteRequest;
|
|
108
|
+
start(): Promise<void>;
|
|
109
|
+
stop(): Promise<void>;
|
|
110
|
+
getPort(): number;
|
|
111
|
+
getHost(): string;
|
|
112
|
+
}
|
|
113
|
+
//#endregion
|
|
114
|
+
//#region src/transports/sse.d.ts
|
|
115
|
+
/**
|
|
116
|
+
* SSE (Server-Sent Events) transport handler
|
|
117
|
+
* Legacy transport for backwards compatibility (protocol version 2024-11-05)
|
|
118
|
+
* Uses separate endpoints: /sse for SSE stream (GET) and /messages for client messages (POST)
|
|
119
|
+
*/
|
|
120
|
+
declare class SseTransportHandler implements HttpTransportHandler$1 {
|
|
121
|
+
private serverFactory;
|
|
122
|
+
private app;
|
|
123
|
+
private server;
|
|
124
|
+
private sessionManager;
|
|
125
|
+
private config;
|
|
126
|
+
constructor(serverFactory: Server | (() => Server), config: TransportConfig);
|
|
127
|
+
private setupMiddleware;
|
|
128
|
+
private setupRoutes;
|
|
129
|
+
private handleSseConnection;
|
|
130
|
+
private handlePostMessage;
|
|
131
|
+
start(): Promise<void>;
|
|
132
|
+
stop(): Promise<void>;
|
|
133
|
+
getPort(): number;
|
|
134
|
+
getHost(): string;
|
|
135
|
+
}
|
|
136
|
+
//#endregion
|
|
137
|
+
//#region src/transports/stdio.d.ts
|
|
138
|
+
/**
|
|
139
|
+
* Stdio transport handler for MCP server
|
|
140
|
+
* Used for command-line and direct integrations
|
|
141
|
+
*/
|
|
142
|
+
declare class StdioTransportHandler implements TransportHandler {
|
|
143
|
+
private server;
|
|
144
|
+
private transport;
|
|
145
|
+
constructor(server: Server);
|
|
146
|
+
start(): Promise<void>;
|
|
147
|
+
stop(): Promise<void>;
|
|
148
|
+
}
|
|
149
|
+
//#endregion
|
|
150
|
+
export { HttpTransportHandler, ReadImageTool, SseTransportHandler, StdioTransportHandler, Tool, ToolDefinition, TransportConfig, TransportHandler, TransportMode, UnsplashSearchTool, createServer };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
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 };
|