siliconflow-image-mcp 1.0.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.
@@ -0,0 +1,115 @@
1
+ /**
2
+ * Type definitions for SiliconFlow Image MCP
3
+ */
4
+
5
+ import { z } from "zod";
6
+
7
+ // Image generation input schema
8
+ export const GenerateImageInputSchema = z.object({
9
+ prompt: z
10
+ .string()
11
+ .min(1, "Prompt is required")
12
+ .max(2000, "Prompt must be 2000 characters or less")
13
+ .describe("Detailed description of the image to generate"),
14
+
15
+ model: z
16
+ .string()
17
+ .optional()
18
+ .describe("Model to use for generation (defaults to black-forest-labs/FLUX.1-dev)"),
19
+
20
+ aspectRatio: z
21
+ .enum(["1:1", "2:3", "3:2", "3:4", "4:3", "4:5", "5:4", "9:16", "16:9", "21:9"])
22
+ .optional()
23
+ .describe("Aspect ratio for generated images"),
24
+
25
+ imageSize: z
26
+ .enum(["1K", "2K", "4K"])
27
+ .optional()
28
+ .describe("Image size (higher resolution)"),
29
+
30
+ count: z
31
+ .number()
32
+ .int()
33
+ .min(1)
34
+ .max(4)
35
+ .optional()
36
+ .default(1)
37
+ .describe("Number of images to generate (1-4)"),
38
+
39
+ negativePrompt: z
40
+ .string()
41
+ .optional()
42
+ .describe("Negative prompt - what to avoid in the image"),
43
+
44
+ seed: z
45
+ .number()
46
+ .int()
47
+ .min(0)
48
+ .max(9999999999)
49
+ .optional()
50
+ .describe("Seed for reproducible results"),
51
+ });
52
+
53
+ export type GenerateImageInput = z.infer<typeof GenerateImageInputSchema>;
54
+
55
+ // Image editing input schema
56
+ export const EditImageInputSchema = z.object({
57
+ image: z
58
+ .string()
59
+ .min(1, "Image data is required")
60
+ .describe("Base64 encoded image data, image URL, or local file path to edit"),
61
+
62
+ prompt: z
63
+ .string()
64
+ .min(1, "Edit prompt is required")
65
+ .max(2000, "Edit prompt must be 2000 characters or less")
66
+ .describe("Instructions for editing the image"),
67
+
68
+ model: z
69
+ .string()
70
+ .optional()
71
+ .describe("Model to use for editing (defaults to Qwen/Qwen-Image-Edit-2509)"),
72
+ });
73
+
74
+ export type EditImageInput = z.infer<typeof EditImageInputSchema>;
75
+
76
+ // List models input schema (empty)
77
+ export const ListModelsInputSchema = z.object({});
78
+
79
+ export type ListModelsInput = z.infer<typeof ListModelsInputSchema>;
80
+
81
+ // Image result type
82
+ export interface ImageResult {
83
+ data: string; // Base64 encoded image data
84
+ mimeType: string; // e.g., "image/png"
85
+ size?: number; // File size in bytes
86
+ width?: number; // Image width in pixels
87
+ height?: number; // Image height in pixels
88
+ }
89
+
90
+ // Model information type
91
+ export interface ModelInfo {
92
+ id: string;
93
+ name: string;
94
+ description?: string;
95
+ output_modalities?: string[];
96
+ pricing?: {
97
+ prompt?: number;
98
+ completion?: number;
99
+ image?: number;
100
+ };
101
+ context_length?: number;
102
+ }
103
+
104
+ // Tool response type
105
+ export interface ToolResponse {
106
+ content: Array<{
107
+ type: "text" | "image" | "resource";
108
+ text?: string;
109
+ data?: string;
110
+ mimeType?: string;
111
+ uri?: string;
112
+ name?: string;
113
+ }>;
114
+ isError?: boolean;
115
+ }
@@ -0,0 +1,54 @@
1
+ /**
2
+ * File utility functions for saving images
3
+ */
4
+
5
+ import { promises as fs } from "fs";
6
+ import path from "path";
7
+ import os from "os";
8
+
9
+ /**
10
+ * Get the base directory for storing images
11
+ * Uses SILICONFLOW_IMAGE_DIR env var if set, otherwise defaults to system temp dir
12
+ */
13
+ function getImageBaseDir(): string {
14
+ const customDir = process.env.SILICONFLOW_IMAGE_DIR;
15
+ if (customDir) {
16
+ return customDir;
17
+ }
18
+ return path.join(os.tmpdir(), "siliconflow-images");
19
+ }
20
+
21
+ /**
22
+ * Save base64 image data to a temporary file
23
+ * @param base64Data - Base64 encoded image data
24
+ * @param prefix - Prefix for the filename
25
+ * @param mimeType - MIME type to determine file extension
26
+ * @returns Path to the saved file
27
+ */
28
+ export async function saveImageToFile(
29
+ base64Data: string,
30
+ prefix: string,
31
+ mimeType: string
32
+ ): Promise<string> {
33
+ const tempDir = getImageBaseDir();
34
+ await fs.mkdir(tempDir, { recursive: true });
35
+
36
+ const extension = mimeType === "image/jpeg" ? "jpg" : "png";
37
+ const timestamp = Date.now();
38
+ const filename = `${prefix}_${timestamp}.${extension}`;
39
+ const filepath = path.join(tempDir, filename);
40
+
41
+ const buffer = Buffer.from(base64Data, 'base64');
42
+ await fs.writeFile(filepath, buffer);
43
+
44
+ return filepath;
45
+ }
46
+
47
+ /**
48
+ * Get the temporary directory path for siliconflow images
49
+ * Uses SILICONFLOW_IMAGE_DIR env var if set, otherwise defaults to system temp dir
50
+ * @returns The temporary directory path
51
+ */
52
+ export function getTempDir(): string {
53
+ return getImageBaseDir();
54
+ }