ebay-mcp 1.13.2 → 1.14.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/README.de.md +3 -3
- package/README.es.md +3 -3
- package/README.fr.md +3 -3
- package/README.ja.md +3 -3
- package/README.ko.md +3 -3
- package/README.md +163 -41
- package/README.pt-BR.md +3 -3
- package/README.ru.md +3 -3
- package/README.zh-CN.md +3 -3
- package/build/api/account-management/account.js +633 -297
- package/build/api/analytics-and-report/analytics.js +111 -65
- package/build/api/client.js +199 -140
- package/build/api/clientRequestError.js +23 -0
- package/build/api/clientTrading.js +213 -0
- package/build/api/clientTradingError.js +4 -0
- package/build/api/communication/feedback.js +147 -59
- package/build/api/communication/message.js +134 -81
- package/build/api/communication/negotiation.js +65 -53
- package/build/api/communication/notification.js +458 -164
- package/build/api/developer/developer.js +99 -45
- package/build/api/index.js +23 -8
- package/build/api/listing-management/inventory.js +884 -338
- package/build/api/listing-metadata/metadata.js +416 -170
- package/build/api/listing-metadata/taxonomy.js +187 -42
- package/build/api/marketing-and-promotions/marketing.js +1392 -598
- package/build/api/marketing-and-promotions/recommendation.js +49 -24
- package/build/api/order-management/dispute.js +226 -45
- package/build/api/order-management/fulfillment.js +144 -71
- package/build/api/order-management/orderIssueHelpers.js +61 -0
- package/build/api/other/compliance.js +50 -38
- package/build/api/other/edelivery.js +603 -159
- package/build/api/other/finding.js +280 -0
- package/build/api/other/identity.js +30 -15
- package/build/api/other/translation.js +29 -14
- package/build/api/other/vero.js +113 -27
- package/build/api/rateLimitTracker.js +55 -0
- package/build/api/shared/request.js +189 -98
- package/build/api/trading/trading.js +154 -87
- package/build/auth/credentialSession.js +250 -0
- package/build/auth/oauth.js +298 -171
- package/build/auth/{oauth-metadata.js → oauthMetadata.js} +22 -6
- package/build/auth/oauthMiddleware.js +104 -0
- package/build/auth/{scope-utils.js → scopeUtils.js} +101 -28
- package/build/auth/tokenVerifier.js +243 -0
- package/build/auth/tokenVerifierError.js +21 -0
- package/build/config/environment.js +148 -113
- package/build/config/{tool-families.js → toolFamilies.js} +30 -14
- package/build/index.js +25 -19
- package/build/mcp/{http-transport.js → httpTransport.js} +102 -52
- package/build/mcp/readOnlyFilter.js +67 -0
- package/build/mcp/runtime.js +31 -13
- package/build/mcp/{tool-gating.js → toolGating.js} +77 -49
- package/build/mcp/{ui-bridge.js → uiBridge.js} +80 -23
- package/build/schemas/account-management/account.js +144 -6
- package/build/schemas/analytics/analytics.js +33 -19
- package/build/schemas/communication/messages.js +12 -42
- package/build/schemas/developer/developer.js +135 -0
- package/build/schemas/fulfillment/orders.js +183 -21
- package/build/schemas/index.js +27 -19
- package/build/schemas/inventory-management/inventory.js +17 -9
- package/build/schemas/marketing/marketing.js +480 -25
- package/build/schemas/metadata/metadata.js +11 -6
- package/build/schemas/other/finding.js +27 -0
- package/build/schemas/other/otherApis.js +424 -0
- package/build/schemas/taxonomy/taxonomy.js +11 -5
- package/build/scripts/{auto-setup.js → autoSetup.js} +87 -74
- package/build/scripts/{build-ui.js → buildUi.js} +6 -1
- package/build/scripts/{dev-sync.js → devSync.js} +169 -110
- package/build/scripts/diagnostics.js +52 -44
- package/build/scripts/{download-specs.js → downloadSpecs.js} +29 -21
- package/build/scripts/{interactive-setup.js → interactiveSetup.js} +84 -78
- package/build/scripts/setup.js +241 -178
- package/build/scripts/{setup-shared.js → setupShared.js} +29 -7
- package/build/scripts/skills.js +35 -27
- package/build/scripts/updateApiStatusDoc.js +71 -0
- package/build/serverHttp.js +90 -0
- package/build/skills/content.js +124 -118
- package/build/skills/index.js +22 -10
- package/build/skills/install.js +21 -10
- package/build/skills/markers.js +50 -15
- package/build/skills/{registry-snapshot.js → registrySnapshot.js} +8 -2
- package/build/skills/render.js +41 -14
- package/build/skills/targets.js +49 -17
- package/build/tools/categories/account.js +166 -264
- package/build/tools/categories/analytics.js +11 -22
- package/build/tools/categories/browse.js +17 -0
- package/build/tools/categories/communication.js +124 -399
- package/build/tools/categories/connector.js +23 -20
- package/build/tools/categories/developer.js +46 -159
- package/build/tools/categories/fulfillment.js +84 -215
- package/build/tools/categories/index.js +6 -14
- package/build/tools/categories/inventory.js +238 -293
- package/build/tools/categories/marketing.js +677 -39
- package/build/tools/categories/metadata.js +190 -117
- package/build/tools/categories/other.js +81 -208
- package/build/tools/categories/taxonomy.js +29 -20
- package/build/tools/categories/{token-management.js → tokenManagement.js} +187 -192
- package/build/tools/categories/trading.js +16 -47
- package/build/tools/contracts.js +34 -24
- package/build/tools/{define-tool.js → defineTool.js} +44 -29
- package/build/tools/registry.js +87 -29
- package/build/tools/schemas.js +3 -57
- package/build/tools/ui/archetypes.js +1 -0
- package/build/tools/ui/{map-helpers.js → mapHelpers.js} +69 -19
- package/build/tools/ui/maps.js +294 -80
- package/build/types/index.js +1 -1
- package/build/ui/card.html +14 -14
- package/build/ui/chart.html +14 -14
- package/build/ui/stat.html +87 -0
- package/build/ui/table.html +14 -14
- package/build/utils/apiStatusFeed.js +95 -0
- package/build/utils/cliOutput.js +15 -0
- package/build/utils/cliUi.js +108 -0
- package/build/utils/communication/feedback.js +57 -77
- package/build/utils/communication/message.js +69 -98
- package/build/utils/communication/negotiation.js +30 -57
- package/build/utils/communication/notification.js +112 -252
- package/build/utils/{date-converter.js → dateConverter.js} +62 -30
- package/build/utils/effectSchema.js +203 -0
- package/build/utils/effectSchemaAdapter.js +121 -0
- package/build/utils/effectSchemaChainMethods.js +146 -0
- package/build/utils/effectSchemaRefinements.js +104 -0
- package/build/utils/effectSchemaStringMethods.js +63 -0
- package/build/utils/effectSchemaTypes.js +47 -0
- package/build/utils/{env-parser.js → envParser.js} +10 -2
- package/build/utils/errors.js +7 -3
- package/build/utils/http.js +148 -89
- package/build/utils/{llm-client-detector.js → llmClientDetector.js} +295 -274
- package/build/utils/logger.js +127 -51
- package/build/utils/{oauth-helper.js → oauthHelper.js} +127 -90
- package/build/utils/other/compliance.js +18 -38
- package/build/utils/other/identity.js +2 -2
- package/build/utils/other/translation.js +4 -4
- package/build/utils/other/vero.js +36 -20
- package/build/utils/schemaHelpers.js +22 -0
- package/build/utils/scopeHelper.js +270 -0
- package/build/utils/securityChecker.js +316 -0
- package/build/utils/{setup-validator.js → setupValidator.js} +113 -94
- package/build/utils/{setup-wizard.js → setupWizard.js} +57 -46
- package/build/utils/{token-utils.js → tokenUtils.js} +2 -2
- package/build/utils/trading/trading.js +35 -0
- package/build/utils/typeGuards.js +12 -0
- package/build/utils/version.js +65 -29
- package/package.json +10 -8
- package/build/api/client-trading.js +0 -124
- package/build/api/communication/shared.js +0 -59
- package/build/api/shared/query-params.js +0 -16
- package/build/auth/credential-session.js +0 -166
- package/build/auth/oauth-middleware.js +0 -100
- package/build/auth/token-verifier.js +0 -186
- package/build/schemas/other/other-apis.js +0 -390
- package/build/scripts/update-api-status-doc.js +0 -44
- package/build/server-http.js +0 -85
- package/build/tools/definitions/marketing.js +0 -1381
- package/build/tools/tool-handlers/marketing.js +0 -312
- package/build/utils/account-management/account.js +0 -818
- package/build/utils/api-status-feed.js +0 -84
- package/build/utils/cli-ui.js +0 -47
- package/build/utils/order-management/dispute.js +0 -369
- package/build/utils/order-management/fulfillment.js +0 -205
- package/build/utils/other/edelivery.js +0 -235
- package/build/utils/schema-helpers.js +0 -13
- package/build/utils/scope-helper.js +0 -207
- package/build/utils/security-checker.js +0 -248
- package/build/utils/type-guards.js +0 -6
- /package/build/auth/{oauth-types.js → oauthTypes.js} +0 -0
- /package/build/{server-http.d.ts → serverHttp.d.ts} +0 -0
- /package/build/tools/ui/{view-models.js → viewModels.js} +0 -0
- /package/build/types/{ebay-enums.js → ebayEnums.js} +0 -0
|
@@ -6,54 +6,79 @@ import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/
|
|
|
6
6
|
import { isInitializeRequest } from '@modelcontextprotocol/sdk/types.js';
|
|
7
7
|
import { dirname, join } from 'path';
|
|
8
8
|
import { fileURLToPath } from 'url';
|
|
9
|
-
import { createBearerAuthMiddleware } from '../auth/
|
|
10
|
-
import { createMetadataRouter, getProtectedResourceMetadataUrl } from '../auth/
|
|
11
|
-
import { TokenVerifier } from '../auth/
|
|
9
|
+
import { createBearerAuthMiddleware } from '../auth/oauthMiddleware.js';
|
|
10
|
+
import { createMetadataRouter, getProtectedResourceMetadataUrl } from '../auth/oauthMetadata.js';
|
|
11
|
+
import { TokenVerifier } from '../auth/tokenVerifier.js';
|
|
12
12
|
import { getDefaultScopes, getEbayConfig } from '../config/environment.js';
|
|
13
13
|
import { createEbayMcpRuntime } from '../mcp/runtime.js';
|
|
14
14
|
import { getErrorMessage } from '../utils/errors.js';
|
|
15
|
+
import { serverLogger } from '../utils/logger.js';
|
|
15
16
|
import { getVersion } from '../utils/version.js';
|
|
16
|
-
|
|
17
|
+
import { Effect, Either } from 'effect';
|
|
18
|
+
const getProjectRoot = () => {
|
|
17
19
|
const filename = fileURLToPath(import.meta.url);
|
|
18
20
|
const directory = dirname(filename);
|
|
19
21
|
return join(directory, '../..');
|
|
20
|
-
}
|
|
22
|
+
};
|
|
21
23
|
/**
|
|
22
24
|
* Build HTTP transport configuration from process environment variables.
|
|
25
|
+
*
|
|
26
|
+
* @param env - Environment object to read transport and OAuth settings from.
|
|
27
|
+
* @returns HTTP transport config with defaults filled in.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* const config = createHttpTransportConfigFromEnv(process.env);
|
|
32
|
+
* ```
|
|
23
33
|
*/
|
|
24
|
-
export
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
34
|
+
export const createHttpTransportConfigFromEnv = (env) => ({
|
|
35
|
+
// Cloud platforms (Railway, Render, Fly, etc.) inject PORT; bind all interfaces
|
|
36
|
+
// by default so the container is reachable unless MCP_HOST is set explicitly.
|
|
37
|
+
host: env.MCP_HOST || (env.PORT ? '0.0.0.0' : 'localhost'),
|
|
38
|
+
port: Number(env.MCP_PORT) || Number(env.PORT) || 3000,
|
|
39
|
+
oauth: {
|
|
40
|
+
authServerUrl: env.OAUTH_AUTH_SERVER_URL ?? 'http://localhost:8080/realms/master',
|
|
41
|
+
clientId: env.OAUTH_CLIENT_ID,
|
|
42
|
+
clientSecret: env.OAUTH_CLIENT_SECRET,
|
|
43
|
+
requiredScopes: (env.OAUTH_REQUIRED_SCOPES || 'mcp:tools')
|
|
44
|
+
.split(',')
|
|
45
|
+
.map((scope) => scope.trim()),
|
|
46
|
+
useIntrospection: env.OAUTH_USE_INTROSPECTION !== 'false',
|
|
47
|
+
},
|
|
48
|
+
authEnabled: env.OAUTH_ENABLED !== 'false',
|
|
49
|
+
projectRoot: getProjectRoot(),
|
|
50
|
+
staticAuthToken: env.MCP_AUTH_TOKEN,
|
|
51
|
+
});
|
|
41
52
|
/**
|
|
42
53
|
* Build the public server URL used for MCP metadata and OAuth audience checks.
|
|
54
|
+
*
|
|
55
|
+
* @param config - HTTP host and port values.
|
|
56
|
+
* @returns Public HTTP server URL.
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```ts
|
|
60
|
+
* const url = getHttpServerUrl({ host: 'localhost', port: 3000 });
|
|
61
|
+
* ```
|
|
43
62
|
*/
|
|
44
|
-
export
|
|
45
|
-
return `http://${config.host}:${config.port}`;
|
|
46
|
-
}
|
|
63
|
+
export const getHttpServerUrl = (config) => `http://${config.host}:${config.port}`;
|
|
47
64
|
/**
|
|
48
65
|
* Resolve the OAuth authorization-server metadata endpoint for the configured issuer.
|
|
66
|
+
*
|
|
67
|
+
* @param config - HTTP OAuth config containing the authorization server URL.
|
|
68
|
+
* @returns Well-known OAuth/OIDC metadata URL for the issuer.
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```ts
|
|
72
|
+
* const metadataUrl = getAuthServerMetadataUrl({ oauth: config.oauth });
|
|
73
|
+
* ```
|
|
49
74
|
*/
|
|
50
|
-
export
|
|
75
|
+
export const getAuthServerMetadataUrl = (config) => {
|
|
51
76
|
const baseUrl = config.oauth.authServerUrl;
|
|
52
77
|
if (baseUrl.includes('/realms/')) {
|
|
53
78
|
return `${baseUrl}/.well-known/openid-configuration`;
|
|
54
79
|
}
|
|
55
80
|
return `${baseUrl}/.well-known/oauth-authorization-server`;
|
|
56
|
-
}
|
|
81
|
+
};
|
|
57
82
|
function createServerConfig(serverUrl) {
|
|
58
83
|
const iconBaseUrl = `${serverUrl}/icons`;
|
|
59
84
|
const iconSizes = ['16x16', '32x32', '48x48', '128x128', '256x256', '512x512', '1024x1024'];
|
|
@@ -73,22 +98,38 @@ async function createMcpServer(serverUrl) {
|
|
|
73
98
|
const runtime = createEbayMcpRuntime({
|
|
74
99
|
serverConfig: createServerConfig(serverUrl),
|
|
75
100
|
});
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
101
|
+
const initialized = await Effect.runPromise(Effect.either(Effect.tryPromise({
|
|
102
|
+
try: () => runtime.initializeApi(),
|
|
103
|
+
catch: (error) => error,
|
|
104
|
+
})));
|
|
105
|
+
if (Either.isLeft(initialized)) {
|
|
106
|
+
const error = initialized.left;
|
|
80
107
|
const message = getErrorMessage(error, String(error));
|
|
81
|
-
|
|
108
|
+
serverLogger.error(`Failed to initialize eBay API client: ${message}`);
|
|
82
109
|
throw error;
|
|
83
110
|
}
|
|
84
111
|
return runtime.server;
|
|
85
112
|
}
|
|
86
113
|
async function createAuthMiddleware(config, serverUrl) {
|
|
114
|
+
if (config.staticAuthToken) {
|
|
115
|
+
const staticToken = config.staticAuthToken;
|
|
116
|
+
serverLogger.info('Static bearer auth enabled via MCP_AUTH_TOKEN.');
|
|
117
|
+
return (req, res, next) => {
|
|
118
|
+
if (req.headers.authorization === `Bearer ${staticToken}`) {
|
|
119
|
+
next();
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
res.status(401).json({
|
|
123
|
+
error: 'unauthorized',
|
|
124
|
+
error_description: 'Missing or invalid bearer token',
|
|
125
|
+
});
|
|
126
|
+
};
|
|
127
|
+
}
|
|
87
128
|
if (!config.authEnabled) {
|
|
88
|
-
|
|
89
|
-
return
|
|
129
|
+
serverLogger.warn('OAuth is disabled. Server running in unauthenticated mode.');
|
|
130
|
+
return;
|
|
90
131
|
}
|
|
91
|
-
|
|
132
|
+
serverLogger.info('Initializing OAuth token verifier...');
|
|
92
133
|
const tokenVerifier = new TokenVerifier({
|
|
93
134
|
authServerMetadata: getAuthServerMetadataUrl(config),
|
|
94
135
|
clientId: config.oauth.clientId,
|
|
@@ -97,26 +138,27 @@ async function createAuthMiddleware(config, serverUrl) {
|
|
|
97
138
|
requiredScopes: config.oauth.requiredScopes,
|
|
98
139
|
useIntrospection: config.oauth.useIntrospection,
|
|
99
140
|
});
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
resourceMetadataUrl: getProtectedResourceMetadataUrl(serverUrl),
|
|
106
|
-
realm: 'ebay-mcp',
|
|
141
|
+
const initialized = await Effect.runPromise(Effect.either(tokenVerifier.initialize()));
|
|
142
|
+
if (Either.isLeft(initialized)) {
|
|
143
|
+
const error = initialized.left;
|
|
144
|
+
serverLogger.error('Failed to initialize token verifier', {
|
|
145
|
+
error: getErrorMessage(error, String(error)),
|
|
107
146
|
});
|
|
108
|
-
}
|
|
109
|
-
catch (error) {
|
|
110
|
-
console.error('Failed to initialize token verifier:', error);
|
|
111
147
|
throw error;
|
|
112
148
|
}
|
|
149
|
+
serverLogger.info('Token verifier initialized');
|
|
150
|
+
return createBearerAuthMiddleware({
|
|
151
|
+
verifier: tokenVerifier,
|
|
152
|
+
resourceMetadataUrl: getProtectedResourceMetadataUrl(serverUrl),
|
|
153
|
+
realm: 'ebay-mcp',
|
|
154
|
+
});
|
|
113
155
|
}
|
|
114
156
|
function createRequestLogger() {
|
|
115
157
|
return (req, res, next) => {
|
|
116
158
|
const start = Date.now();
|
|
117
159
|
res.on('finish', () => {
|
|
118
160
|
const duration = Date.now() - start;
|
|
119
|
-
|
|
161
|
+
serverLogger.http(`${req.method} ${req.path} -> ${res.statusCode} (${duration}ms)`);
|
|
120
162
|
});
|
|
121
163
|
next();
|
|
122
164
|
};
|
|
@@ -129,8 +171,16 @@ function sendInvalidSession(res) {
|
|
|
129
171
|
}
|
|
130
172
|
/**
|
|
131
173
|
* Create the Express app that serves OAuth metadata and streamable HTTP MCP sessions.
|
|
174
|
+
*
|
|
175
|
+
* @param config - HTTP transport config including OAuth and static asset settings.
|
|
176
|
+
* @returns Express application with MCP, metadata, health, and icon routes.
|
|
177
|
+
*
|
|
178
|
+
* @example
|
|
179
|
+
* ```ts
|
|
180
|
+
* const app = await createHttpMcpApp(createHttpTransportConfigFromEnv());
|
|
181
|
+
* ```
|
|
132
182
|
*/
|
|
133
|
-
export async
|
|
183
|
+
export const createHttpMcpApp = async (config) => {
|
|
134
184
|
const app = express();
|
|
135
185
|
const serverUrl = getHttpServerUrl(config);
|
|
136
186
|
const ebayConfig = config.ebayConfig ?? getEbayConfig();
|
|
@@ -172,13 +222,13 @@ export async function createHttpMcpApp(config) {
|
|
|
172
222
|
sessionIdGenerator: () => randomUUID(),
|
|
173
223
|
onsessioninitialized: (initializedSessionId) => {
|
|
174
224
|
transports.set(initializedSessionId, transport);
|
|
175
|
-
|
|
225
|
+
serverLogger.info(`New MCP session initialized: ${initializedSessionId}`);
|
|
176
226
|
},
|
|
177
227
|
});
|
|
178
228
|
transport.onclose = () => {
|
|
179
229
|
if (transport.sessionId) {
|
|
180
230
|
transports.delete(transport.sessionId);
|
|
181
|
-
|
|
231
|
+
serverLogger.info(`MCP session closed: ${transport.sessionId}`);
|
|
182
232
|
}
|
|
183
233
|
};
|
|
184
234
|
const server = await createMcpServer(serverUrl);
|
|
@@ -188,7 +238,7 @@ export async function createHttpMcpApp(config) {
|
|
|
188
238
|
res.status(400).json({
|
|
189
239
|
jsonrpc: '2.0',
|
|
190
240
|
error: {
|
|
191
|
-
code: -
|
|
241
|
+
code: -32_000,
|
|
192
242
|
message: 'Bad Request: No valid session ID provided',
|
|
193
243
|
},
|
|
194
244
|
id: null,
|
|
@@ -200,7 +250,7 @@ export async function createHttpMcpApp(config) {
|
|
|
200
250
|
const handleSessionRequest = async (req, res) => {
|
|
201
251
|
const sessionHeader = req.headers['mcp-session-id'];
|
|
202
252
|
const sessionId = typeof sessionHeader === 'string' ? sessionHeader : undefined;
|
|
203
|
-
if (!sessionId
|
|
253
|
+
if (!(sessionId && transports.has(sessionId))) {
|
|
204
254
|
sendInvalidSession(res);
|
|
205
255
|
return;
|
|
206
256
|
}
|
|
@@ -215,4 +265,4 @@ export async function createHttpMcpApp(config) {
|
|
|
215
265
|
app.get('/', ...sessionMiddleware);
|
|
216
266
|
app.delete('/', ...sessionMiddleware);
|
|
217
267
|
return app;
|
|
218
|
-
}
|
|
268
|
+
};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* EBAY_READ_ONLY mode: classify and filter tools that are safe under a
|
|
3
|
+
* read-only deployment (no create/update/delete side effects).
|
|
4
|
+
*
|
|
5
|
+
* Classification prefers MCP annotations when present, then falls back to a
|
|
6
|
+
* conservative name heuristic so unannotated tools (many inventory/fulfillment
|
|
7
|
+
* endpoints) still gate correctly.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Write-oriented name segments. Matched as whole underscore-delimited tokens
|
|
11
|
+
* so substrings like `markdown` or `setup` do not false-positive.
|
|
12
|
+
*
|
|
13
|
+
* Note: `bulk` and bare `offer` are intentionally omitted — `bulk_get_*` and
|
|
14
|
+
* `get_offer(s)` are reads; bulk/write verbs still match via create/update/etc.
|
|
15
|
+
*/
|
|
16
|
+
const WRITE_NAME_PATTERN = /(^|_)(create|update|delete|issue|publish|end|revise|upload|accept|contest|send|mark|provide|appeal|escalate|close|add|remove|set|relish|withdraw|complete|confirm|cancel|void|replace|move|enable|disable|assign|unassign|transfer|relinquish|relist|promote|pause|resume|launch|clone)(_|$)/;
|
|
17
|
+
/** Common read-oriented name segments (whole underscore-delimited tokens). */
|
|
18
|
+
const READ_NAME_PATTERN = /(^|_)(get|list|find|search|fetch|check|read|view|describe|status|health)(_|$)/;
|
|
19
|
+
/**
|
|
20
|
+
* Whether a tool is safe to expose when `EBAY_READ_ONLY` is enabled.
|
|
21
|
+
*
|
|
22
|
+
* @param definition - Tool name plus optional MCP annotations.
|
|
23
|
+
* @returns `true` when the tool is classified as read-only.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* isReadOnlyTool({ name: 'ebay_get_orders' }); // true
|
|
28
|
+
* isReadOnlyTool({ name: 'ebay_create_offer' }); // false
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export const isReadOnlyTool = (definition) => {
|
|
32
|
+
if (definition.annotations?.readOnlyHint === true)
|
|
33
|
+
return true;
|
|
34
|
+
if (definition.annotations?.readOnlyHint === false)
|
|
35
|
+
return false;
|
|
36
|
+
if (definition.annotations?.destructiveHint === true)
|
|
37
|
+
return false;
|
|
38
|
+
const name = definition.name.toLowerCase();
|
|
39
|
+
if (WRITE_NAME_PATTERN.test(name))
|
|
40
|
+
return false;
|
|
41
|
+
if (READ_NAME_PATTERN.test(name))
|
|
42
|
+
return true;
|
|
43
|
+
// Connector tools without the ebay_ prefix
|
|
44
|
+
if (name === 'search' || name === 'fetch')
|
|
45
|
+
return true;
|
|
46
|
+
// Default: exclude from read-only mode (safer)
|
|
47
|
+
return false;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Whether `EBAY_READ_ONLY` is enabled in the given environment.
|
|
51
|
+
*
|
|
52
|
+
* Accepts `true`, `1`, and `yes` (case-insensitive). Any other value (including
|
|
53
|
+
* unset) leaves read-only mode off.
|
|
54
|
+
*
|
|
55
|
+
* @param env - Environment map (defaults to `process.env`).
|
|
56
|
+
* @returns `true` when read-only mode should filter registered tools.
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```ts
|
|
60
|
+
* isReadOnlyModeEnabled({ EBAY_READ_ONLY: 'true' }); // true
|
|
61
|
+
* isReadOnlyModeEnabled({ EBAY_READ_ONLY: '0' }); // false
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
export const isReadOnlyModeEnabled = (env = process.env) => {
|
|
65
|
+
const raw = env.EBAY_READ_ONLY?.trim().toLowerCase();
|
|
66
|
+
return raw === 'true' || raw === '1' || raw === 'yes';
|
|
67
|
+
};
|
package/build/mcp/runtime.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
2
|
import { EbaySellerApi } from '../api/index.js';
|
|
3
3
|
import { getEbayConfig, mcpConfig } from '../config/environment.js';
|
|
4
|
-
import { resolveToolGatingMode } from '../config/
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
4
|
+
import { resolveToolGatingMode } from '../config/toolFamilies.js';
|
|
5
|
+
import { isReadOnlyModeEnabled, isReadOnlyTool } from '../mcp/readOnlyFilter.js';
|
|
6
|
+
import { createToolGatingController, DYNAMIC_MODE_INSTRUCTIONS, registerMetaTools, toolNamesInFamilies, } from '../mcp/toolGating.js';
|
|
7
|
+
import { buildUiToolResult, createUiBridge } from '../mcp/uiBridge.js';
|
|
7
8
|
import { getToolEntries } from '../tools/registry.js';
|
|
8
9
|
import { getErrorMessage } from '../utils/errors.js';
|
|
9
10
|
import { serverLogger, toolLogger } from '../utils/logger.js';
|
|
11
|
+
import { Effect } from 'effect';
|
|
10
12
|
function formatToolSuccess(result) {
|
|
11
13
|
return {
|
|
12
14
|
content: [
|
|
@@ -40,30 +42,40 @@ function registerTool(server, api, entry, logToolExecution, ui) {
|
|
|
40
42
|
if (logToolExecution) {
|
|
41
43
|
toolLogger.debug(`Executing tool: ${definition.name}`, { args });
|
|
42
44
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
+
return await Effect.runPromise(Effect.tryPromise({
|
|
46
|
+
try: () => Promise.resolve(handler(api, args)),
|
|
47
|
+
catch: (error) => error,
|
|
48
|
+
}).pipe(Effect.map((result) => {
|
|
45
49
|
if (logToolExecution) {
|
|
46
50
|
toolLogger.debug(`Tool ${definition.name} completed successfully`);
|
|
47
51
|
}
|
|
48
52
|
return ui.shouldRender(entry)
|
|
49
53
|
? buildUiToolResult(entry.ui, result)
|
|
50
54
|
: formatToolSuccess(result);
|
|
51
|
-
}
|
|
52
|
-
catch (error) {
|
|
55
|
+
}), Effect.catchAll((error) => {
|
|
53
56
|
const errorMessage = getErrorMessage(error);
|
|
54
57
|
if (logToolExecution) {
|
|
55
58
|
toolLogger.error(`Tool ${definition.name} failed`, { error: errorMessage });
|
|
56
59
|
}
|
|
57
|
-
return formatToolFailure(error);
|
|
58
|
-
}
|
|
60
|
+
return Effect.succeed(formatToolFailure(error));
|
|
61
|
+
})));
|
|
59
62
|
});
|
|
60
63
|
ui.register(entry, registered);
|
|
61
64
|
return registered;
|
|
62
65
|
}
|
|
63
66
|
/**
|
|
64
67
|
* Create an MCP server runtime and register all eBay tool handlers.
|
|
68
|
+
*
|
|
69
|
+
* @param options - Optional runtime dependencies and metadata overrides.
|
|
70
|
+
* @returns Initialized runtime wrapper containing the MCP server and API facade.
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```ts
|
|
74
|
+
* const runtime = createEbayMcpRuntime({ logToolExecution: true });
|
|
75
|
+
* await runtime.initializeApi();
|
|
76
|
+
* ```
|
|
65
77
|
*/
|
|
66
|
-
export
|
|
78
|
+
export const createEbayMcpRuntime = (options = {}) => {
|
|
67
79
|
const api = options.api ?? new EbaySellerApi(getEbayConfig());
|
|
68
80
|
const serverInfo = options.serverConfig ?? mcpConfig;
|
|
69
81
|
const mode = resolveToolGatingMode();
|
|
@@ -77,12 +89,18 @@ export function createEbayMcpRuntime(options = {}) {
|
|
|
77
89
|
// Static mode registers only the named families; all and dynamic register the
|
|
78
90
|
// full catalogue (dynamic then disables it below, before the transport connects).
|
|
79
91
|
const allEntries = getToolEntries();
|
|
80
|
-
|
|
92
|
+
let entries = mode.kind === 'static'
|
|
81
93
|
? (() => {
|
|
82
94
|
const names = toolNamesInFamilies(mode.families);
|
|
83
95
|
return allEntries.filter((entry) => names.has(entry.definition.name));
|
|
84
96
|
})()
|
|
85
97
|
: allEntries;
|
|
98
|
+
// Optional second gate: drop any non-read-only tools after family selection so
|
|
99
|
+
// EBAY_READ_ONLY composes with all / static / dynamic modes.
|
|
100
|
+
if (isReadOnlyModeEnabled()) {
|
|
101
|
+
entries = entries.filter((entry) => isReadOnlyTool(entry.definition));
|
|
102
|
+
serverLogger.info(`EBAY_READ_ONLY: filtered to ${entries.length} read-only tools`);
|
|
103
|
+
}
|
|
86
104
|
const handles = new Map();
|
|
87
105
|
for (const entry of entries) {
|
|
88
106
|
handles.set(entry.definition.name, registerTool(server, api, entry, options.logToolExecution ?? false, ui));
|
|
@@ -110,7 +128,7 @@ export function createEbayMcpRuntime(options = {}) {
|
|
|
110
128
|
api,
|
|
111
129
|
server,
|
|
112
130
|
async initializeApi() {
|
|
113
|
-
await api.initialize();
|
|
131
|
+
await Effect.runPromise(api.initialize());
|
|
114
132
|
},
|
|
115
133
|
};
|
|
116
|
-
}
|
|
134
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { z } from '
|
|
2
|
-
import { TOOL_FAMILY_KEYS } from '../config/
|
|
1
|
+
import { decodeEffectSchemaSync, z } from '../utils/effectSchema.js';
|
|
2
|
+
import { TOOL_FAMILY_KEYS } from '../config/toolFamilies.js';
|
|
3
3
|
import { toolCategories } from '../tools/categories/index.js';
|
|
4
4
|
/**
|
|
5
5
|
* Tool gating: the runtime half of the `EBAY_MCP_TOOLS=dynamic` feature.
|
|
@@ -12,7 +12,7 @@ import { toolCategories } from '../tools/categories/index.js';
|
|
|
12
12
|
* real input schemas and validation. This keeps advertised context proportional
|
|
13
13
|
* to what the agent actually uses instead of the full ~187-tool catalogue.
|
|
14
14
|
*
|
|
15
|
-
* The pure env parsing/validation lives in `@/config/
|
|
15
|
+
* The pure env parsing/validation lives in `@/config/toolFamilies.ts`; this
|
|
16
16
|
* module owns everything that needs the live tool registry.
|
|
17
17
|
*/
|
|
18
18
|
/** Default page size for {@link ToolGatingController.list} when `limit` is omitted. */
|
|
@@ -29,14 +29,14 @@ export const DYNAMIC_MODE_INSTRUCTIONS = 'This eBay server keeps its full tool c
|
|
|
29
29
|
'then `enable_ebay_tools` with the tool names you need — they will appear as normal tools you can call. ' +
|
|
30
30
|
'Call `disable_ebay_tools` to remove tools you no longer need and reclaim context.';
|
|
31
31
|
/** Condenses a tool description to a single sentence for the discovery listing. */
|
|
32
|
-
|
|
32
|
+
const toSummary = (description) => {
|
|
33
33
|
const firstLine = description.split('\n', 1)[0].trim();
|
|
34
34
|
const sentenceEnd = firstLine.indexOf('. ');
|
|
35
35
|
const sentence = sentenceEnd === -1 ? firstLine : firstLine.slice(0, sentenceEnd + 1);
|
|
36
36
|
return sentence.length > 160 ? `${sentence.slice(0, 157)}...` : sentence;
|
|
37
|
-
}
|
|
37
|
+
};
|
|
38
38
|
/** Builds the discovery catalogue (tool rows, family overview, name→family index). */
|
|
39
|
-
|
|
39
|
+
const buildCatalog = () => {
|
|
40
40
|
const rows = [];
|
|
41
41
|
const families = [];
|
|
42
42
|
const familyByToolName = new Map();
|
|
@@ -49,14 +49,45 @@ function buildCatalog() {
|
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
51
|
return { rows, families, familyByToolName };
|
|
52
|
-
}
|
|
52
|
+
};
|
|
53
53
|
const CATALOG = buildCatalog();
|
|
54
|
+
/** Input accepted by the lightweight dynamic-mode tool catalogue. */
|
|
55
|
+
const listEbayToolsInputSchema = z.object({
|
|
56
|
+
family: z.string().optional().describe('Restrict results to one family key (e.g. "inventory").'),
|
|
57
|
+
query: z
|
|
58
|
+
.string()
|
|
59
|
+
.optional()
|
|
60
|
+
.describe('Case-insensitive keyword matched against tool name, summary, and family.'),
|
|
61
|
+
cursor: z.string().optional().describe('Pagination cursor from a prior call.'),
|
|
62
|
+
limit: z
|
|
63
|
+
.number()
|
|
64
|
+
.int()
|
|
65
|
+
.positive()
|
|
66
|
+
.max(MAX_LIST_LIMIT)
|
|
67
|
+
.optional()
|
|
68
|
+
.describe(`Max rows per page (default ${DEFAULT_LIST_LIMIT}, max ${MAX_LIST_LIMIT}).`),
|
|
69
|
+
});
|
|
70
|
+
/** Input accepted by the dynamic-mode enable/disable meta-tools. */
|
|
71
|
+
const dynamicToolNamesInputSchema = z.object({
|
|
72
|
+
names: z
|
|
73
|
+
.array(z.string())
|
|
74
|
+
.min(1)
|
|
75
|
+
.describe('Exact tool names to enable or disable, as returned by list_ebay_tools.'),
|
|
76
|
+
});
|
|
54
77
|
/**
|
|
55
78
|
* Resolves the tool names belonging to the given families, preserving the caller's
|
|
56
79
|
* ability to filter registry entries for static mode. Unknown family keys
|
|
57
80
|
* contribute nothing (they are rejected earlier by env validation).
|
|
81
|
+
*
|
|
82
|
+
* @param families - Tool family keys requested by static tool gating mode.
|
|
83
|
+
* @returns Tool names that belong to the requested families.
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* ```ts
|
|
87
|
+
* const names = toolNamesInFamilies(['inventory', 'account']);
|
|
88
|
+
* ```
|
|
58
89
|
*/
|
|
59
|
-
export
|
|
90
|
+
export const toolNamesInFamilies = (families) => {
|
|
60
91
|
const wanted = new Set(families);
|
|
61
92
|
const names = new Set();
|
|
62
93
|
for (const [name, family] of CATALOG.familyByToolName) {
|
|
@@ -65,23 +96,29 @@ export function toolNamesInFamilies(families) {
|
|
|
65
96
|
}
|
|
66
97
|
}
|
|
67
98
|
return names;
|
|
68
|
-
}
|
|
99
|
+
};
|
|
69
100
|
/** Parses an opaque list cursor (a stringified offset) back into a non-negative offset. */
|
|
70
|
-
|
|
101
|
+
const parseCursor = (cursor) => {
|
|
71
102
|
if (!cursor) {
|
|
72
103
|
return 0;
|
|
73
104
|
}
|
|
74
105
|
const offset = Number.parseInt(cursor, 10);
|
|
75
106
|
return Number.isInteger(offset) && offset > 0 ? offset : 0;
|
|
76
|
-
}
|
|
107
|
+
};
|
|
77
108
|
/**
|
|
78
109
|
* Creates the controller backing the discovery meta-tools.
|
|
79
110
|
*
|
|
80
111
|
* @param handles - Map of eBay tool name → its registered handle. Only these tools
|
|
81
112
|
* are gateable; the meta-tools themselves are intentionally absent so they can
|
|
82
113
|
* never be disabled and are excluded from `activeCount`.
|
|
114
|
+
* @returns Controller used by the discovery meta-tools.
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* ```ts
|
|
118
|
+
* const controller = createToolGatingController(handles);
|
|
119
|
+
* ```
|
|
83
120
|
*/
|
|
84
|
-
export
|
|
121
|
+
export const createToolGatingController = (handles) => {
|
|
85
122
|
const activeCount = () => [...handles.values()].filter((handle) => handle.enabled).length;
|
|
86
123
|
const mutate = (names, enable) => {
|
|
87
124
|
const changed = [];
|
|
@@ -108,7 +145,7 @@ export function createToolGatingController(handles) {
|
|
|
108
145
|
};
|
|
109
146
|
return {
|
|
110
147
|
list({ family, query, cursor, limit }) {
|
|
111
|
-
if (!family
|
|
148
|
+
if (!(family || query)) {
|
|
112
149
|
return {
|
|
113
150
|
families: CATALOG.families.map((row) => ({
|
|
114
151
|
...row,
|
|
@@ -148,51 +185,42 @@ export function createToolGatingController(handles) {
|
|
|
148
185
|
enable: (names) => mutate(names, true),
|
|
149
186
|
disable: (names) => mutate(names, false),
|
|
150
187
|
};
|
|
151
|
-
}
|
|
188
|
+
};
|
|
152
189
|
/** Wraps controller output as a standard text tool result. */
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
}
|
|
190
|
+
const toToolResult = (data) => ({
|
|
191
|
+
content: [{ type: 'text', text: JSON.stringify(data, null, 2) }],
|
|
192
|
+
});
|
|
156
193
|
/**
|
|
157
194
|
* Registers the three discovery meta-tools on the server. Called only in dynamic
|
|
158
195
|
* mode, after the eBay tools are registered and disabled, so the controller sees
|
|
159
196
|
* every gateable handle.
|
|
197
|
+
*
|
|
198
|
+
* @param server - MCP server receiving the discovery meta-tools.
|
|
199
|
+
* @param controller - Dynamic tool gating controller backing the meta-tools.
|
|
200
|
+
* @returns Nothing; the server is mutated through MCP SDK registration calls.
|
|
201
|
+
*
|
|
202
|
+
* @example
|
|
203
|
+
* ```ts
|
|
204
|
+
* registerMetaTools(server, createToolGatingController(handles));
|
|
205
|
+
* ```
|
|
160
206
|
*/
|
|
161
|
-
export
|
|
207
|
+
export const registerMetaTools = (server, controller) => {
|
|
162
208
|
server.registerTool('list_ebay_tools', {
|
|
163
209
|
description: "Discover eBay tools without loading them into context. Call with no arguments to list the tool families; pass `family` to list a family's tools, or `query` to keyword-search across all tools. Returns lightweight rows (name, family, summary) — enable a tool with enable_ebay_tools to get its full schema and call it.",
|
|
164
|
-
inputSchema:
|
|
165
|
-
|
|
166
|
-
.string()
|
|
167
|
-
.optional()
|
|
168
|
-
.describe('Restrict results to one family key (e.g. "inventory").'),
|
|
169
|
-
query: z
|
|
170
|
-
.string()
|
|
171
|
-
.optional()
|
|
172
|
-
.describe('Case-insensitive keyword matched against tool name, summary, and family.'),
|
|
173
|
-
cursor: z.string().optional().describe('Pagination cursor from a prior call.'),
|
|
174
|
-
limit: z
|
|
175
|
-
.number()
|
|
176
|
-
.int()
|
|
177
|
-
.positive()
|
|
178
|
-
.max(MAX_LIST_LIMIT)
|
|
179
|
-
.optional()
|
|
180
|
-
.describe(`Max rows per page (default ${DEFAULT_LIST_LIMIT}, max ${MAX_LIST_LIMIT}).`),
|
|
181
|
-
},
|
|
182
|
-
}, (args) => toToolResult(controller.list(args)));
|
|
210
|
+
inputSchema: listEbayToolsInputSchema.shape,
|
|
211
|
+
}, (args) => toToolResult(controller.list(decodeEffectSchemaSync(listEbayToolsInputSchema, args))));
|
|
183
212
|
server.registerTool('enable_ebay_tools', {
|
|
184
213
|
description: 'Load specific eBay tools into context so they can be called. Pass the exact tool names from list_ebay_tools. Returns the names enabled, any unknown names, and the active tool count.',
|
|
185
|
-
inputSchema:
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
},
|
|
191
|
-
}, ({ names }) => toToolResult(controller.enable(names)));
|
|
214
|
+
inputSchema: dynamicToolNamesInputSchema.shape,
|
|
215
|
+
}, (args) => {
|
|
216
|
+
const { names } = decodeEffectSchemaSync(dynamicToolNamesInputSchema, args);
|
|
217
|
+
return toToolResult(controller.enable(names));
|
|
218
|
+
});
|
|
192
219
|
server.registerTool('disable_ebay_tools', {
|
|
193
220
|
description: 'Unload eBay tools previously enabled, reclaiming their context. Pass the exact tool names. Returns the names disabled, any unknown names, and the active tool count.',
|
|
194
|
-
inputSchema:
|
|
195
|
-
|
|
196
|
-
},
|
|
197
|
-
|
|
198
|
-
}
|
|
221
|
+
inputSchema: dynamicToolNamesInputSchema.shape,
|
|
222
|
+
}, (args) => {
|
|
223
|
+
const { names } = decodeEffectSchemaSync(dynamicToolNamesInputSchema, args);
|
|
224
|
+
return toToolResult(controller.disable(names));
|
|
225
|
+
});
|
|
226
|
+
};
|