woo-mcp-server 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.
- package/LICENSE +21 -0
- package/README.md +389 -0
- package/dist/cli.js +3021 -0
- package/dist/cli.js.map +1 -0
- package/dist/server.cjs +3061 -0
- package/dist/server.cjs.map +1 -0
- package/dist/server.d.cts +151 -0
- package/dist/server.d.ts +151 -0
- package/dist/server.js +3021 -0
- package/dist/server.js.map +1 -0
- package/package.json +68 -0
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { WooCommerceApiResponse } from 'woocommerce-rest-ts-api';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Environment-based configuration for the WooCommerce MCP server.
|
|
7
|
+
* Validates required credentials at startup — no silent fallbacks.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Zod schema for MCP server environment configuration.
|
|
12
|
+
* WC_URL, WC_KEY, and WC_SECRET are mandatory; the server refuses to start without them.
|
|
13
|
+
*/
|
|
14
|
+
declare const ConfigSchema: z.ZodObject<{
|
|
15
|
+
WC_URL: z.ZodString;
|
|
16
|
+
WC_KEY: z.ZodString;
|
|
17
|
+
WC_SECRET: z.ZodString;
|
|
18
|
+
WC_VERSION: z.ZodDefault<z.ZodString>;
|
|
19
|
+
WC_RATE_LIMIT_PER_SECOND: z.ZodDefault<z.ZodNumber>;
|
|
20
|
+
WC_QUERY_STRING_AUTH: z.ZodEffects<z.ZodOptional<z.ZodEnum<["true", "false", "1", "0", ""]>>, boolean, "" | "0" | "true" | "false" | "1" | undefined>;
|
|
21
|
+
}, "strip", z.ZodTypeAny, {
|
|
22
|
+
WC_URL: string;
|
|
23
|
+
WC_KEY: string;
|
|
24
|
+
WC_SECRET: string;
|
|
25
|
+
WC_VERSION: string;
|
|
26
|
+
WC_RATE_LIMIT_PER_SECOND: number;
|
|
27
|
+
WC_QUERY_STRING_AUTH: boolean;
|
|
28
|
+
}, {
|
|
29
|
+
WC_URL: string;
|
|
30
|
+
WC_KEY: string;
|
|
31
|
+
WC_SECRET: string;
|
|
32
|
+
WC_VERSION?: string | undefined;
|
|
33
|
+
WC_RATE_LIMIT_PER_SECOND?: number | undefined;
|
|
34
|
+
WC_QUERY_STRING_AUTH?: "" | "0" | "true" | "false" | "1" | undefined;
|
|
35
|
+
}>;
|
|
36
|
+
type McpConfig = z.infer<typeof ConfigSchema>;
|
|
37
|
+
/**
|
|
38
|
+
* Load and validate config from process.env.
|
|
39
|
+
* Throws a clear, actionable error if required vars are missing.
|
|
40
|
+
*/
|
|
41
|
+
declare function loadConfig(env?: NodeJS.ProcessEnv): McpConfig;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* WooCommerce API client factory with rate limiting.
|
|
45
|
+
*
|
|
46
|
+
* Uses the library's built-in Throttler (via maxConcurrentRequests) and an
|
|
47
|
+
* additional token-bucket style limiter driven by WC_RATE_LIMIT_PER_SECOND.
|
|
48
|
+
* Does NOT rewrite OAuth/HTTP — delegates entirely to WooCommerceRestApi.
|
|
49
|
+
*/
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Rate limiter: enforces a maximum number of operations per second
|
|
53
|
+
* using a sliding window + the Throttler concurrency gate.
|
|
54
|
+
*/
|
|
55
|
+
declare class RateLimiter {
|
|
56
|
+
private readonly intervalMs;
|
|
57
|
+
private readonly throttler;
|
|
58
|
+
private lastRequestAt;
|
|
59
|
+
private chain;
|
|
60
|
+
constructor(requestsPerSecond: number, maxConcurrent?: number);
|
|
61
|
+
/**
|
|
62
|
+
* Schedule `fn` to run respecting both rate and concurrency limits.
|
|
63
|
+
*/
|
|
64
|
+
schedule<T>(fn: () => Promise<T>): Promise<T>;
|
|
65
|
+
}
|
|
66
|
+
/** Minimal surface we need from WooCommerceRestApi (avoids default-export type issues). */
|
|
67
|
+
interface WooApi {
|
|
68
|
+
get<T = unknown>(endpoint: string, params?: Record<string, unknown>): Promise<WooCommerceApiResponse<T>>;
|
|
69
|
+
post<T = unknown>(endpoint: string, data: Record<string, unknown>, params?: Record<string, unknown>): Promise<WooCommerceApiResponse<T>>;
|
|
70
|
+
put<T = unknown>(endpoint: string, data: Record<string, unknown>, params?: Record<string, unknown>): Promise<WooCommerceApiResponse<T>>;
|
|
71
|
+
delete<T = unknown>(endpoint: string, data?: {
|
|
72
|
+
force?: boolean;
|
|
73
|
+
}, params?: {
|
|
74
|
+
id?: number;
|
|
75
|
+
}): Promise<WooCommerceApiResponse<T>>;
|
|
76
|
+
options<T = unknown>(endpoint: string, params?: Record<string, unknown>): Promise<WooCommerceApiResponse<T>>;
|
|
77
|
+
}
|
|
78
|
+
interface WooClient {
|
|
79
|
+
api: WooApi;
|
|
80
|
+
rateLimiter: RateLimiter;
|
|
81
|
+
config: McpConfig;
|
|
82
|
+
/** Rate-limited GET */
|
|
83
|
+
get<T = unknown>(endpoint: string, params?: Record<string, unknown>): Promise<WooCommerceApiResponse<T>>;
|
|
84
|
+
/** Rate-limited POST */
|
|
85
|
+
post<T = unknown>(endpoint: string, data: Record<string, unknown>, params?: Record<string, unknown>): Promise<WooCommerceApiResponse<T>>;
|
|
86
|
+
/** Rate-limited PUT */
|
|
87
|
+
put<T = unknown>(endpoint: string, data: Record<string, unknown>, params?: Record<string, unknown>): Promise<WooCommerceApiResponse<T>>;
|
|
88
|
+
/** Rate-limited DELETE */
|
|
89
|
+
delete<T = unknown>(endpoint: string, data?: {
|
|
90
|
+
force?: boolean;
|
|
91
|
+
}, params?: {
|
|
92
|
+
id?: number;
|
|
93
|
+
}): Promise<WooCommerceApiResponse<T>>;
|
|
94
|
+
/** Extract pagination meta from a list response */
|
|
95
|
+
pagination(response: WooCommerceApiResponse<unknown>, page: number, perPage: number): {
|
|
96
|
+
total: number;
|
|
97
|
+
totalPages: number;
|
|
98
|
+
currentPage: number;
|
|
99
|
+
perPage: number;
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Create a rate-limited WooCommerce client from validated config.
|
|
104
|
+
*/
|
|
105
|
+
declare function createWooClient(config: McpConfig): WooClient;
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Registers all MCP tools, resources, and prompts on the server instance.
|
|
109
|
+
*/
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Auto-register every tool, resource, and prompt.
|
|
113
|
+
*/
|
|
114
|
+
declare function registerAll(server: McpServer, client: WooClient): void;
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* WooCommerce MCP server bootstrap (STDIO transport).
|
|
118
|
+
*
|
|
119
|
+
* Creates a configured McpServer, wires the WooCommerce client, and registers
|
|
120
|
+
* all tools/resources/prompts. The CLI entrypoint connects STDIO transport.
|
|
121
|
+
*/
|
|
122
|
+
|
|
123
|
+
declare const SERVER_NAME = "woo-mcp-server";
|
|
124
|
+
declare const SERVER_VERSION = "1.0.0";
|
|
125
|
+
interface CreateServerOptions {
|
|
126
|
+
/** Pre-validated config; if omitted, loaded from process.env */
|
|
127
|
+
config?: McpConfig;
|
|
128
|
+
/** Inject a pre-built client (tests) */
|
|
129
|
+
client?: WooClient;
|
|
130
|
+
}
|
|
131
|
+
interface CreatedServer {
|
|
132
|
+
server: McpServer;
|
|
133
|
+
client: WooClient;
|
|
134
|
+
config: McpConfig;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Build an MCP server instance with all capabilities registered.
|
|
138
|
+
* Does not connect transport — call connectStdio() or use startServer().
|
|
139
|
+
*/
|
|
140
|
+
declare function createServer(options?: CreateServerOptions): CreatedServer;
|
|
141
|
+
/**
|
|
142
|
+
* Connect the server to STDIO transport (Claude Desktop compatible).
|
|
143
|
+
*/
|
|
144
|
+
declare function connectStdio(server: McpServer): Promise<void>;
|
|
145
|
+
/**
|
|
146
|
+
* Full startup: validate env, create server, connect STDIO.
|
|
147
|
+
* Exits process with code 1 on configuration failure.
|
|
148
|
+
*/
|
|
149
|
+
declare function startServer(): Promise<CreatedServer>;
|
|
150
|
+
|
|
151
|
+
export { type CreateServerOptions, type CreatedServer, type McpConfig, SERVER_NAME, SERVER_VERSION, type WooClient, connectStdio, createServer, createWooClient, loadConfig, registerAll, startServer };
|
package/dist/server.d.ts
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { WooCommerceApiResponse } from 'woocommerce-rest-ts-api';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Environment-based configuration for the WooCommerce MCP server.
|
|
7
|
+
* Validates required credentials at startup — no silent fallbacks.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Zod schema for MCP server environment configuration.
|
|
12
|
+
* WC_URL, WC_KEY, and WC_SECRET are mandatory; the server refuses to start without them.
|
|
13
|
+
*/
|
|
14
|
+
declare const ConfigSchema: z.ZodObject<{
|
|
15
|
+
WC_URL: z.ZodString;
|
|
16
|
+
WC_KEY: z.ZodString;
|
|
17
|
+
WC_SECRET: z.ZodString;
|
|
18
|
+
WC_VERSION: z.ZodDefault<z.ZodString>;
|
|
19
|
+
WC_RATE_LIMIT_PER_SECOND: z.ZodDefault<z.ZodNumber>;
|
|
20
|
+
WC_QUERY_STRING_AUTH: z.ZodEffects<z.ZodOptional<z.ZodEnum<["true", "false", "1", "0", ""]>>, boolean, "" | "0" | "true" | "false" | "1" | undefined>;
|
|
21
|
+
}, "strip", z.ZodTypeAny, {
|
|
22
|
+
WC_URL: string;
|
|
23
|
+
WC_KEY: string;
|
|
24
|
+
WC_SECRET: string;
|
|
25
|
+
WC_VERSION: string;
|
|
26
|
+
WC_RATE_LIMIT_PER_SECOND: number;
|
|
27
|
+
WC_QUERY_STRING_AUTH: boolean;
|
|
28
|
+
}, {
|
|
29
|
+
WC_URL: string;
|
|
30
|
+
WC_KEY: string;
|
|
31
|
+
WC_SECRET: string;
|
|
32
|
+
WC_VERSION?: string | undefined;
|
|
33
|
+
WC_RATE_LIMIT_PER_SECOND?: number | undefined;
|
|
34
|
+
WC_QUERY_STRING_AUTH?: "" | "0" | "true" | "false" | "1" | undefined;
|
|
35
|
+
}>;
|
|
36
|
+
type McpConfig = z.infer<typeof ConfigSchema>;
|
|
37
|
+
/**
|
|
38
|
+
* Load and validate config from process.env.
|
|
39
|
+
* Throws a clear, actionable error if required vars are missing.
|
|
40
|
+
*/
|
|
41
|
+
declare function loadConfig(env?: NodeJS.ProcessEnv): McpConfig;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* WooCommerce API client factory with rate limiting.
|
|
45
|
+
*
|
|
46
|
+
* Uses the library's built-in Throttler (via maxConcurrentRequests) and an
|
|
47
|
+
* additional token-bucket style limiter driven by WC_RATE_LIMIT_PER_SECOND.
|
|
48
|
+
* Does NOT rewrite OAuth/HTTP — delegates entirely to WooCommerceRestApi.
|
|
49
|
+
*/
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Rate limiter: enforces a maximum number of operations per second
|
|
53
|
+
* using a sliding window + the Throttler concurrency gate.
|
|
54
|
+
*/
|
|
55
|
+
declare class RateLimiter {
|
|
56
|
+
private readonly intervalMs;
|
|
57
|
+
private readonly throttler;
|
|
58
|
+
private lastRequestAt;
|
|
59
|
+
private chain;
|
|
60
|
+
constructor(requestsPerSecond: number, maxConcurrent?: number);
|
|
61
|
+
/**
|
|
62
|
+
* Schedule `fn` to run respecting both rate and concurrency limits.
|
|
63
|
+
*/
|
|
64
|
+
schedule<T>(fn: () => Promise<T>): Promise<T>;
|
|
65
|
+
}
|
|
66
|
+
/** Minimal surface we need from WooCommerceRestApi (avoids default-export type issues). */
|
|
67
|
+
interface WooApi {
|
|
68
|
+
get<T = unknown>(endpoint: string, params?: Record<string, unknown>): Promise<WooCommerceApiResponse<T>>;
|
|
69
|
+
post<T = unknown>(endpoint: string, data: Record<string, unknown>, params?: Record<string, unknown>): Promise<WooCommerceApiResponse<T>>;
|
|
70
|
+
put<T = unknown>(endpoint: string, data: Record<string, unknown>, params?: Record<string, unknown>): Promise<WooCommerceApiResponse<T>>;
|
|
71
|
+
delete<T = unknown>(endpoint: string, data?: {
|
|
72
|
+
force?: boolean;
|
|
73
|
+
}, params?: {
|
|
74
|
+
id?: number;
|
|
75
|
+
}): Promise<WooCommerceApiResponse<T>>;
|
|
76
|
+
options<T = unknown>(endpoint: string, params?: Record<string, unknown>): Promise<WooCommerceApiResponse<T>>;
|
|
77
|
+
}
|
|
78
|
+
interface WooClient {
|
|
79
|
+
api: WooApi;
|
|
80
|
+
rateLimiter: RateLimiter;
|
|
81
|
+
config: McpConfig;
|
|
82
|
+
/** Rate-limited GET */
|
|
83
|
+
get<T = unknown>(endpoint: string, params?: Record<string, unknown>): Promise<WooCommerceApiResponse<T>>;
|
|
84
|
+
/** Rate-limited POST */
|
|
85
|
+
post<T = unknown>(endpoint: string, data: Record<string, unknown>, params?: Record<string, unknown>): Promise<WooCommerceApiResponse<T>>;
|
|
86
|
+
/** Rate-limited PUT */
|
|
87
|
+
put<T = unknown>(endpoint: string, data: Record<string, unknown>, params?: Record<string, unknown>): Promise<WooCommerceApiResponse<T>>;
|
|
88
|
+
/** Rate-limited DELETE */
|
|
89
|
+
delete<T = unknown>(endpoint: string, data?: {
|
|
90
|
+
force?: boolean;
|
|
91
|
+
}, params?: {
|
|
92
|
+
id?: number;
|
|
93
|
+
}): Promise<WooCommerceApiResponse<T>>;
|
|
94
|
+
/** Extract pagination meta from a list response */
|
|
95
|
+
pagination(response: WooCommerceApiResponse<unknown>, page: number, perPage: number): {
|
|
96
|
+
total: number;
|
|
97
|
+
totalPages: number;
|
|
98
|
+
currentPage: number;
|
|
99
|
+
perPage: number;
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Create a rate-limited WooCommerce client from validated config.
|
|
104
|
+
*/
|
|
105
|
+
declare function createWooClient(config: McpConfig): WooClient;
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Registers all MCP tools, resources, and prompts on the server instance.
|
|
109
|
+
*/
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Auto-register every tool, resource, and prompt.
|
|
113
|
+
*/
|
|
114
|
+
declare function registerAll(server: McpServer, client: WooClient): void;
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* WooCommerce MCP server bootstrap (STDIO transport).
|
|
118
|
+
*
|
|
119
|
+
* Creates a configured McpServer, wires the WooCommerce client, and registers
|
|
120
|
+
* all tools/resources/prompts. The CLI entrypoint connects STDIO transport.
|
|
121
|
+
*/
|
|
122
|
+
|
|
123
|
+
declare const SERVER_NAME = "woo-mcp-server";
|
|
124
|
+
declare const SERVER_VERSION = "1.0.0";
|
|
125
|
+
interface CreateServerOptions {
|
|
126
|
+
/** Pre-validated config; if omitted, loaded from process.env */
|
|
127
|
+
config?: McpConfig;
|
|
128
|
+
/** Inject a pre-built client (tests) */
|
|
129
|
+
client?: WooClient;
|
|
130
|
+
}
|
|
131
|
+
interface CreatedServer {
|
|
132
|
+
server: McpServer;
|
|
133
|
+
client: WooClient;
|
|
134
|
+
config: McpConfig;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Build an MCP server instance with all capabilities registered.
|
|
138
|
+
* Does not connect transport — call connectStdio() or use startServer().
|
|
139
|
+
*/
|
|
140
|
+
declare function createServer(options?: CreateServerOptions): CreatedServer;
|
|
141
|
+
/**
|
|
142
|
+
* Connect the server to STDIO transport (Claude Desktop compatible).
|
|
143
|
+
*/
|
|
144
|
+
declare function connectStdio(server: McpServer): Promise<void>;
|
|
145
|
+
/**
|
|
146
|
+
* Full startup: validate env, create server, connect STDIO.
|
|
147
|
+
* Exits process with code 1 on configuration failure.
|
|
148
|
+
*/
|
|
149
|
+
declare function startServer(): Promise<CreatedServer>;
|
|
150
|
+
|
|
151
|
+
export { type CreateServerOptions, type CreatedServer, type McpConfig, SERVER_NAME, SERVER_VERSION, type WooClient, connectStdio, createServer, createWooClient, loadConfig, registerAll, startServer };
|