ebay-api-mcp-server-node-local 1.0.0 → 1.0.2
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/package.json +8 -2
- package/eslint.config.js +0 -58
- package/src/constant/constants.ts +0 -51
- package/src/helper/http-helper.ts +0 -154
- package/src/helper/openapi-helper.ts +0 -116
- package/src/helper/validation-helper.ts +0 -289
- package/src/index.ts +0 -75
- package/src/integration.test.ts +0 -140
- package/src/service/openapi-service.ts +0 -243
- package/tsconfig.build.json +0 -9
- package/tsconfig.json +0 -115
- package/tsconfig.node.json +0 -7
- package/vitest.config.ts +0 -20
- package/vitest.setup.ts +0 -6
package/package.json
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ebay-api-mcp-server-node-local",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "MCP server for eBay API with OpenAPI support",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
7
10
|
"scripts": {
|
|
8
11
|
"build": "tsc --project tsconfig.build.json",
|
|
9
12
|
"start": "node dist/index.js",
|
|
@@ -46,5 +49,8 @@
|
|
|
46
49
|
"typescript": "^5.3.3",
|
|
47
50
|
"vitest": "^3.1.3"
|
|
48
51
|
},
|
|
49
|
-
"packageManager": "yarn@3.6.1+sha512.de524adec81a6c3d7a26d936d439d2832e351cdfc5728f9d91f3fc85dd20b04391c038e9b4ecab11cae2b0dd9f0d55fd355af766bc5c1a7f8d25d96bb2a0b2ca"
|
|
52
|
+
"packageManager": "yarn@3.6.1+sha512.de524adec81a6c3d7a26d936d439d2832e351cdfc5728f9d91f3fc85dd20b04391c038e9b4ecab11cae2b0dd9f0d55fd355af766bc5c1a7f8d25d96bb2a0b2ca",
|
|
53
|
+
"bin": {
|
|
54
|
+
"ebay-mcp-server": "dist/index.js"
|
|
55
|
+
}
|
|
50
56
|
}
|
package/eslint.config.js
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import js from '@eslint/js';
|
|
2
|
-
import typescript from '@typescript-eslint/eslint-plugin';
|
|
3
|
-
import typescriptParser from '@typescript-eslint/parser';
|
|
4
|
-
import globals from 'globals';
|
|
5
|
-
|
|
6
|
-
export default [
|
|
7
|
-
// Base JavaScript recommended rules
|
|
8
|
-
js.configs.recommended,
|
|
9
|
-
|
|
10
|
-
// Global ignores
|
|
11
|
-
{
|
|
12
|
-
ignores: ['dist/**', 'node_modules/**', 'coverage/**', '*.config.js', '*.config.ts', 'vitest.setup.ts'],
|
|
13
|
-
},
|
|
14
|
-
|
|
15
|
-
// TypeScript configuration
|
|
16
|
-
{
|
|
17
|
-
files: ['**/*.ts', '**/*.tsx'],
|
|
18
|
-
languageOptions: {
|
|
19
|
-
parser: typescriptParser,
|
|
20
|
-
ecmaVersion: 'latest',
|
|
21
|
-
sourceType: 'module',
|
|
22
|
-
globals: {
|
|
23
|
-
...globals.node,
|
|
24
|
-
...globals.es2022,
|
|
25
|
-
},
|
|
26
|
-
parserOptions: {
|
|
27
|
-
project: ['./tsconfig.json', './tsconfig.node.json'],
|
|
28
|
-
},
|
|
29
|
-
},
|
|
30
|
-
plugins: {
|
|
31
|
-
'@typescript-eslint': typescript,
|
|
32
|
-
},
|
|
33
|
-
rules: {
|
|
34
|
-
// TypeScript rules
|
|
35
|
-
...typescript.configs.recommended.rules,
|
|
36
|
-
'@typescript-eslint/explicit-function-return-type': 'off',
|
|
37
|
-
'@typescript-eslint/no-explicit-any': 'warn',
|
|
38
|
-
'@typescript-eslint/no-unused-vars': ['warn', {
|
|
39
|
-
'argsIgnorePattern': '^_',
|
|
40
|
-
'varsIgnorePattern': '^_',
|
|
41
|
-
'caughtErrorsIgnorePattern': '^_',
|
|
42
|
-
}],
|
|
43
|
-
|
|
44
|
-
// General rules
|
|
45
|
-
'semi': ['error', 'always'],
|
|
46
|
-
'quotes': ['warn', 'double'],
|
|
47
|
-
'no-console': 'off', // Since console.error is used for logging
|
|
48
|
-
},
|
|
49
|
-
},
|
|
50
|
-
|
|
51
|
-
// Test files configuration
|
|
52
|
-
{
|
|
53
|
-
files: ['**/*.test.ts', '**/*.spec.ts'],
|
|
54
|
-
rules: {
|
|
55
|
-
'no-console': 'off',
|
|
56
|
-
},
|
|
57
|
-
},
|
|
58
|
-
];
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Constants used throughout the application
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Environment options for the eBay API
|
|
7
|
-
*/
|
|
8
|
-
export enum ApiEnvironment {
|
|
9
|
-
SANDBOX = "sandbox",
|
|
10
|
-
PRODUCTION = "production"
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Utility to find ApiEnvironment by string value
|
|
14
|
-
* Returns SANDBOX if no match is found
|
|
15
|
-
*/
|
|
16
|
-
export function findApiEnvironmentByValue(value: string): ApiEnvironment {
|
|
17
|
-
const lowercaseValue = value?.toLowerCase();
|
|
18
|
-
const matchedEnv = Object.entries(ApiEnvironment)
|
|
19
|
-
.find(([_key, val]) => typeof val === "string" && val.toLowerCase() === lowercaseValue);
|
|
20
|
-
return matchedEnv ? matchedEnv[1] as ApiEnvironment : ApiEnvironment.SANDBOX;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Recall apiDoc url by prompt
|
|
25
|
-
*/
|
|
26
|
-
export const RECALL_SPEC_BY_PROMPT_URL = "https://ebaypubapimcp3.vip.qa.ebay.com/developer-portal/api/v1/openapi-specs/search?query=%s";
|
|
27
|
-
/**
|
|
28
|
-
* url for query apiSpec with fields such as specTitle、operationId
|
|
29
|
-
*/
|
|
30
|
-
export const RECALL_SPEC_WITH_FIELD_URL = "https://ebaypubapimcp3.vip.qa.ebay.com/developer-portal/api/v1/openapi-specs/%s?operationId=%s";
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Required environment variable names for the application
|
|
34
|
-
*/
|
|
35
|
-
export const REQUIRED_ENV_VARS = ["EBAY_CLIENT_TOKEN", "EBAY_API_ENV"];
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* API domain name, differentiated by api environment
|
|
39
|
-
*/
|
|
40
|
-
export const DOMAIN_NAME = {
|
|
41
|
-
[ApiEnvironment.SANDBOX]: "api.sandbox.ebay.com",
|
|
42
|
-
[ApiEnvironment.PRODUCTION]: "api.ebay.com",
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* List of supported calling methods, differentiated by api environment
|
|
47
|
-
*/
|
|
48
|
-
export const SUPPORTED_CALLING_METHODS = {
|
|
49
|
-
[ApiEnvironment.SANDBOX]: ["get", "put", "post", "delete", "options", "head", "patch", "trace"],
|
|
50
|
-
[ApiEnvironment.PRODUCTION]: ["get"],
|
|
51
|
-
};
|
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Helper functions for HTTP requests
|
|
3
|
-
*/
|
|
4
|
-
import axios from "axios";
|
|
5
|
-
import { type OpenAPIV3 } from "openapi-types";
|
|
6
|
-
import https from "https";
|
|
7
|
-
import { DOMAIN_NAME, findApiEnvironmentByValue } from "../constant/constants.js";
|
|
8
|
-
|
|
9
|
-
const USER_ENVIRONMENT = findApiEnvironmentByValue(process.env.EBAY_API_ENV || "");
|
|
10
|
-
const USER_TOKEN = process.env.EBAY_CLIENT_TOKEN || "";
|
|
11
|
-
const SCHEMA_REQUEST_BODY = "requestBody";
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Format axios error message for consistent error output
|
|
16
|
-
*/
|
|
17
|
-
export function formatAxiosError(error: unknown): string {
|
|
18
|
-
let errorMessage = `Error in invokeAPI tool: ${error instanceof Error ? error.message : String(error)}`;
|
|
19
|
-
if (axios.isAxiosError(error)) {
|
|
20
|
-
if (error?.response?.data) {
|
|
21
|
-
errorMessage = JSON.stringify(error.response.data, null, 2);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
return errorMessage;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Build headers from input headers and fill with default headers
|
|
29
|
-
*/
|
|
30
|
-
export function buildHeadersFromInput(inputHeaders: Record<string, string[]> | undefined): Record<string, string> {
|
|
31
|
-
const headers: Record<string, string> = {};
|
|
32
|
-
if (inputHeaders) {
|
|
33
|
-
for (const [key, value] of Object.entries(inputHeaders)) {
|
|
34
|
-
headers[key] = Array.isArray(value) ? value[0] : value;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
// Add default headers
|
|
38
|
-
fillDefaultHeaderInfo(headers);
|
|
39
|
-
return headers;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export function fillDefaultHeaderInfo(headers: Record<string, string>): void {
|
|
43
|
-
headers["Host"] = DOMAIN_NAME[USER_ENVIRONMENT];
|
|
44
|
-
headers["User-Agent"] = "EBAY-API-MCP-Tool/1.0";
|
|
45
|
-
headers["Authorization"] = `Bearer ${USER_TOKEN}`;
|
|
46
|
-
headers["Content-Type"] = headers["Content-Type"] || "application/json";
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Build final URL by replacing path variables with their values
|
|
51
|
-
*/
|
|
52
|
-
export function buildFinalUrl(url: string, urlVariables: Record<string, unknown> | undefined): string {
|
|
53
|
-
if (urlVariables) {
|
|
54
|
-
for (const [key, value] of Object.entries(urlVariables)) {
|
|
55
|
-
url = url.replace(new RegExp(`%7B${key}%7D`, "g"), encodeURIComponent(String(value)));
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
return url;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* replace url domain name by environment
|
|
63
|
-
*/
|
|
64
|
-
export function replaceDomainNameByEnvironment(url: string): string {
|
|
65
|
-
try {
|
|
66
|
-
const urlObj = new URL(url);
|
|
67
|
-
const currentHostname = urlObj.hostname;
|
|
68
|
-
const expectedDomain = DOMAIN_NAME[USER_ENVIRONMENT];
|
|
69
|
-
if (currentHostname !== expectedDomain) {
|
|
70
|
-
urlObj.hostname = expectedDomain;
|
|
71
|
-
return urlObj.toString();
|
|
72
|
-
}
|
|
73
|
-
return url;
|
|
74
|
-
} catch (error) {
|
|
75
|
-
// Fallback to string replacement if URL parsing fails
|
|
76
|
-
const expectedDomain = DOMAIN_NAME[USER_ENVIRONMENT];
|
|
77
|
-
for (const [env, domain] of Object.entries(DOMAIN_NAME)) {
|
|
78
|
-
if (env !== USER_ENVIRONMENT && url.includes(domain)) {
|
|
79
|
-
return url.replace(domain, expectedDomain);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
return url;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Build base URL from OpenAPI servers object
|
|
88
|
-
*/
|
|
89
|
-
export function buildBaseUrlFromOpenApi(openapi: OpenAPIV3.Document): string {
|
|
90
|
-
const serverObj = openapi.servers?.[0] || { url: "" };
|
|
91
|
-
let baseUrl = serverObj.url;
|
|
92
|
-
if (serverObj.variables) {
|
|
93
|
-
for (const [key, value] of Object.entries(serverObj.variables)) {
|
|
94
|
-
baseUrl = baseUrl.replace(`{${key}}`, value.default);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
return replaceDomainNameByEnvironment(baseUrl);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* Resolve path variables in a URL pattern
|
|
102
|
-
*/
|
|
103
|
-
export function resolvePath(pathPattern: string, pathVariables?: Record<string, string | number>): string {
|
|
104
|
-
if (!pathVariables) {
|
|
105
|
-
return pathPattern;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
return pathPattern.replace(/{([^}]+)}/g, (match, key) => {
|
|
109
|
-
const value = pathVariables[key];
|
|
110
|
-
if (value === undefined) {
|
|
111
|
-
throw new Error(`Missing path variable: ${key}`);
|
|
112
|
-
}
|
|
113
|
-
return String(value);
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* Prepare request data
|
|
119
|
-
*/
|
|
120
|
-
export function prepareRequestData(
|
|
121
|
-
input: Record<string, unknown>,
|
|
122
|
-
operation: OpenAPIV3.OperationObject,
|
|
123
|
-
path: string,
|
|
124
|
-
): { resolvedPath: string; headers: Record<string, string>; params: Record<string, unknown>; data: unknown; } {
|
|
125
|
-
let resolvedPath = path;
|
|
126
|
-
const headers: Record<string, string> = {};
|
|
127
|
-
const params: Record<string, unknown> = {};
|
|
128
|
-
let data: unknown = undefined;
|
|
129
|
-
const pathParams: Record<string, string> = {};
|
|
130
|
-
|
|
131
|
-
let prop = input.properties as Record<string, unknown> || {};
|
|
132
|
-
Object.entries(prop).forEach(([key, value]) => {
|
|
133
|
-
if (key === SCHEMA_REQUEST_BODY) {
|
|
134
|
-
data = value;
|
|
135
|
-
} else {
|
|
136
|
-
const paramDef = operation.parameters?.find(p =>
|
|
137
|
-
!("$ref" in p) && p.name === key) as OpenAPIV3.ParameterObject | undefined;
|
|
138
|
-
if (paramDef) {
|
|
139
|
-
if (paramDef.in === "header") {
|
|
140
|
-
headers[key] = String(value);
|
|
141
|
-
} else if (paramDef.in === "query") {
|
|
142
|
-
params[key] = value;
|
|
143
|
-
} else if (paramDef.in === "path") {
|
|
144
|
-
pathParams[key] = String(value);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
});
|
|
149
|
-
fillDefaultHeaderInfo(headers);
|
|
150
|
-
if (Object.keys(pathParams).length > 0) {
|
|
151
|
-
resolvedPath = resolvePath(resolvedPath, pathParams);
|
|
152
|
-
}
|
|
153
|
-
return { resolvedPath, headers, params, data };
|
|
154
|
-
}
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* OpenAPI helper functions, including loading OpenAPI documents,
|
|
3
|
-
* parsing OpenAPI specs, building schemas, and converting to Zod schemas.
|
|
4
|
-
*/
|
|
5
|
-
import SwaggerParser from "@apidevtools/swagger-parser";
|
|
6
|
-
import { type OpenAPIV3 } from "openapi-types";
|
|
7
|
-
import * as fs from "fs";
|
|
8
|
-
import axios from "axios";
|
|
9
|
-
import * as yaml from "js-yaml";
|
|
10
|
-
import util from "util";
|
|
11
|
-
import { z, type ZodTypeAny } from "zod";
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const SCHEMA_REQUEST_BODY = "requestBody";
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Get OpenAPI docs from user config file, which contains urls or paths of OpenAPI specs.
|
|
18
|
-
*/
|
|
19
|
-
export async function getOpenApiDocumentsFromConfigFile(): Promise<OpenAPIV3.Document[]> {
|
|
20
|
-
const docs: OpenAPIV3.Document[] = [];
|
|
21
|
-
const urlFile = process.env.EBAY_API_DOC_URL_FILE;
|
|
22
|
-
let urls: string[] = [];
|
|
23
|
-
if (urlFile && fs.existsSync(urlFile)) {
|
|
24
|
-
// url or path each line in the file
|
|
25
|
-
urls = fs.readFileSync(urlFile, "utf-8").split(/\r?\n/)
|
|
26
|
-
.map(line => line.trim())
|
|
27
|
-
.filter(line => line.length > 0 && !line.startsWith("#"));
|
|
28
|
-
}
|
|
29
|
-
console.error("Loading OpenAPI specifications from:", urls);
|
|
30
|
-
// parse opebapi doc from url/path
|
|
31
|
-
for (const specPath of urls) {
|
|
32
|
-
try {
|
|
33
|
-
const doc = await SwaggerParser.dereference(specPath) as OpenAPIV3.Document;
|
|
34
|
-
docs.push(doc);
|
|
35
|
-
} catch (e) {
|
|
36
|
-
console.error(`getOpenApiDocumentsFromConfigFile#[Failed to load OpenAPI doc from the specPath : ${specPath}]`);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
return docs;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// Helper: remove ignored keys recursively
|
|
43
|
-
export function readSchema2Map(obj: unknown): unknown {
|
|
44
|
-
const SCHEMA_IGNORE_KEYS = ["style", "explode", "exampleSetFlag", "types", "in", "required"];
|
|
45
|
-
if (Array.isArray(obj)) {
|
|
46
|
-
return obj.map(readSchema2Map);
|
|
47
|
-
} else if (obj && typeof obj === "object") {
|
|
48
|
-
const out: Record<string, unknown> = {};
|
|
49
|
-
for (const [k, v] of Object.entries(obj as Record<string, unknown>)) {
|
|
50
|
-
if (!SCHEMA_IGNORE_KEYS.includes(k)) {
|
|
51
|
-
out[k] = readSchema2Map(v);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
return out;
|
|
55
|
-
}
|
|
56
|
-
return obj;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Parse OpenAPI document from string (supports both JSON and YAML)
|
|
61
|
-
*/
|
|
62
|
-
export async function parseOpenApiDoc(specTitle: string, operationId : string, specUrl: string): Promise<OpenAPIV3.Document> {
|
|
63
|
-
const url = util.format(specUrl, specTitle, operationId);
|
|
64
|
-
const apiSpecRes = await axios.get<string>(url, {
|
|
65
|
-
httpsAgent: new (await import("https")).Agent({
|
|
66
|
-
rejectUnauthorized: false,
|
|
67
|
-
})});
|
|
68
|
-
const docString = apiSpecRes.data;
|
|
69
|
-
try {
|
|
70
|
-
// Try parsing as JSON first
|
|
71
|
-
return JSON.parse(docString) as OpenAPIV3.Document;
|
|
72
|
-
} catch (jsonError) {
|
|
73
|
-
try {
|
|
74
|
-
// If JSON fails, try parsing as YAML
|
|
75
|
-
return yaml.load(docString) as OpenAPIV3.Document;
|
|
76
|
-
} catch (yamlError) {
|
|
77
|
-
const _jsonMsg = jsonError instanceof Error ? jsonError.message : String(jsonError);
|
|
78
|
-
const _yamlMsg = yamlError instanceof Error ? yamlError.message : String(yamlError);
|
|
79
|
-
console.error("failed to parse OpenAPI document !!!");
|
|
80
|
-
return {} as OpenAPIV3.Document;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Build schema for an operation's input parameters
|
|
87
|
-
*/
|
|
88
|
-
export function buildOperationSchema(operation: OpenAPIV3.OperationObject): { properties: Record<string, unknown> } {
|
|
89
|
-
const properties: Record<string, unknown> = {};
|
|
90
|
-
// handle request param
|
|
91
|
-
(operation.parameters || []).forEach(param => {
|
|
92
|
-
if ("$ref" in param) {return;}
|
|
93
|
-
const paramSchema = readSchema2Map(param);
|
|
94
|
-
properties[param.name] = paramSchema;
|
|
95
|
-
});
|
|
96
|
-
// handle request body
|
|
97
|
-
if (operation.requestBody && "content" in operation.requestBody &&
|
|
98
|
-
operation.requestBody.content?.["application/json"]?.schema) {
|
|
99
|
-
const requestBodySchema = readSchema2Map(operation.requestBody.content["application/json"].schema);
|
|
100
|
-
properties[SCHEMA_REQUEST_BODY] = requestBodySchema;
|
|
101
|
-
}
|
|
102
|
-
return { properties };
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Build Zod validation schema
|
|
107
|
-
*/
|
|
108
|
-
export function buildZodSchema(properties: Record<string, unknown>): Record<string, ZodTypeAny> {
|
|
109
|
-
const zodProperties: Record<string, ZodTypeAny> = {};
|
|
110
|
-
|
|
111
|
-
Object.keys(properties).forEach(key => {
|
|
112
|
-
zodProperties[key] = z.any();
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
return zodProperties;
|
|
116
|
-
}
|
|
@@ -1,289 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Validation helper functions for OpenAPI validation
|
|
3
|
-
*/
|
|
4
|
-
import { type OpenAPIV3 } from "openapi-types";
|
|
5
|
-
import AjvLib from "ajv";
|
|
6
|
-
const Ajv = AjvLib.default || AjvLib;
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Validate request parameters against OpenAPI specification
|
|
10
|
-
*/
|
|
11
|
-
export function validateRequestParameters(
|
|
12
|
-
url: string,
|
|
13
|
-
openApiDoc: OpenAPIV3.Document,
|
|
14
|
-
method: string,
|
|
15
|
-
input: {
|
|
16
|
-
urlVariables?: Record<string, unknown>;
|
|
17
|
-
urlQueryParams?: Record<string, unknown>;
|
|
18
|
-
headers?: Record<string, string>;
|
|
19
|
-
requestBody?: Record<string, unknown>;
|
|
20
|
-
},
|
|
21
|
-
): { isValid: boolean; errors: string[] } {
|
|
22
|
-
const errors: string[] = [];
|
|
23
|
-
|
|
24
|
-
// validate path
|
|
25
|
-
const {pathValidateRes, apiPath, specPath, specPathItem} = validatePath(openApiDoc, url);
|
|
26
|
-
if (!pathValidateRes || !specPathItem) {
|
|
27
|
-
errors.push(`API path ${apiPath} is not valid or not found in OpenAPI specification`);
|
|
28
|
-
return { isValid: false, errors };
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// Check if the method exists for the path
|
|
32
|
-
const operation = specPathItem[method.toLowerCase() as keyof typeof specPathItem] as OpenAPIV3.OperationObject;
|
|
33
|
-
if (!operation) {
|
|
34
|
-
errors.push(`Method ${method} not found for path ${specPath} in OpenAPI specification`);
|
|
35
|
-
return { isValid: false, errors };
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// Initialize AJV for schema validation
|
|
39
|
-
const _ajv = new Ajv({ allErrors: true });
|
|
40
|
-
|
|
41
|
-
validateUrlPathParam(input.urlVariables, operation.parameters, errors);
|
|
42
|
-
|
|
43
|
-
validateUrlQueryParam(input.urlQueryParams, operation.parameters, errors);
|
|
44
|
-
|
|
45
|
-
validateUrlHeaders(input.headers, operation.parameters, errors);
|
|
46
|
-
|
|
47
|
-
validateUrlRequestBody(input.requestBody, operation.requestBody, errors);
|
|
48
|
-
|
|
49
|
-
return { isValid: errors.length === 0, errors };
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Validate the API path against the OpenAPI document
|
|
54
|
-
*/
|
|
55
|
-
export function validatePath(openApiDoc: OpenAPIV3.Document, inputUrl: string): {
|
|
56
|
-
pathValidateRes : boolean,
|
|
57
|
-
apiPath : string,
|
|
58
|
-
specPath : string,
|
|
59
|
-
specPathItem?: OpenAPIV3.PathItemObject
|
|
60
|
-
} {
|
|
61
|
-
// Extract the path from the URL (remove base URL part)
|
|
62
|
-
const apiPath : string = parseApiPathFromUrl(inputUrl);
|
|
63
|
-
if (!apiPath) {
|
|
64
|
-
console.error(`input url ${inputUrl} is not valid, please check it.`);
|
|
65
|
-
return {pathValidateRes : false, apiPath:"", specPath: "", specPathItem: undefined};
|
|
66
|
-
}
|
|
67
|
-
// bathPath validation
|
|
68
|
-
const serverObj = openApiDoc.servers?.[0] || { url: "" };
|
|
69
|
-
let basePath : string = "";
|
|
70
|
-
if (serverObj?.variables) {
|
|
71
|
-
for (const [key, value] of Object.entries(serverObj.variables)) {
|
|
72
|
-
if (key === "basePath") {
|
|
73
|
-
basePath = value.default;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
const basePathRegex = new RegExp(`${basePath.replace(/\{[^}]+\}/g, "[^/]+") }$`);
|
|
78
|
-
if (basePath && !basePathRegex.test(apiPath)) {
|
|
79
|
-
console.error(`API path ${apiPath} does not match the base path ${basePath} in OpenAPI specification.`);
|
|
80
|
-
return {pathValidateRes : false, apiPath, specPath: "", specPathItem: undefined};
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// specPath validation
|
|
84
|
-
for (const specPath of Object.keys(openApiDoc.paths || {})) {
|
|
85
|
-
const specPathRegex = new RegExp(`${specPath.replace(/\{[^}]+\}/g, "[^/]+") }$`);
|
|
86
|
-
if (specPathRegex.test(apiPath) && openApiDoc.paths?.[specPath]) {
|
|
87
|
-
const specPathItem = openApiDoc.paths[specPath];
|
|
88
|
-
return { pathValidateRes: true, apiPath, specPath, specPathItem};
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
return {pathValidateRes : false, apiPath, specPath: "", specPathItem: undefined};
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* parse path from the given url by llm
|
|
97
|
-
*/
|
|
98
|
-
export function parseApiPathFromUrl(inputUrl: string): string {
|
|
99
|
-
try {
|
|
100
|
-
const urlObj = new URL(inputUrl);
|
|
101
|
-
return decodeURIComponent(urlObj.pathname); // Decode URL path
|
|
102
|
-
} catch (urlError) {
|
|
103
|
-
// If URL parsing fails, try to extract path manually
|
|
104
|
-
const pathMatch = inputUrl.match(/https?:\/\/[^/]+(.*)$/);
|
|
105
|
-
if (pathMatch) {
|
|
106
|
-
return pathMatch[1];
|
|
107
|
-
}
|
|
108
|
-
console.error(`Failed to parse API path from URL: ${inputUrl}`);
|
|
109
|
-
return "";
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* Validate URL path parameters against OpenAPI specification
|
|
115
|
-
*/
|
|
116
|
-
export function validateUrlPathParam(
|
|
117
|
-
urlVariables: Record<string, unknown> | undefined,
|
|
118
|
-
parameters: (OpenAPIV3.ReferenceObject | OpenAPIV3.ParameterObject)[] | undefined,
|
|
119
|
-
errors: string[],
|
|
120
|
-
): void {
|
|
121
|
-
// Initialize AJV for schema validation
|
|
122
|
-
const ajv = new Ajv({ allErrors: true });
|
|
123
|
-
if (urlVariables) {
|
|
124
|
-
const pathParams = (parameters || []).filter(
|
|
125
|
-
(param): param is OpenAPIV3.ParameterObject =>
|
|
126
|
-
!("$ref" in param) && param.in === "path",
|
|
127
|
-
);
|
|
128
|
-
|
|
129
|
-
for (const param of pathParams) {
|
|
130
|
-
const value = urlVariables[param.name];
|
|
131
|
-
|
|
132
|
-
if (param.required && (value === undefined || value === null)) {
|
|
133
|
-
errors.push(`Missing required path parameter: ${param.name}`);
|
|
134
|
-
continue;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
if (value !== undefined && param.schema) {
|
|
138
|
-
const validate = ajv.compile(param.schema);
|
|
139
|
-
if (!validate(value)) {
|
|
140
|
-
errors.push(`Invalid path parameter ${param.name}: ${ajv.errorsText(validate.errors)}`);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
// Check for extra path parameters not defined in spec
|
|
146
|
-
const definedPathParams = pathParams.map(p => p.name);
|
|
147
|
-
const extraParams = Object.keys(urlVariables).filter(key => !definedPathParams.includes(key));
|
|
148
|
-
if (extraParams.length > 0) {
|
|
149
|
-
errors.push(`Unknown path parameters: ${extraParams.join(", ")}`);
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
// Check for required path parameters that might be missing from urlVariables
|
|
153
|
-
const requiredPathParams = (parameters || [])
|
|
154
|
-
.filter((param): param is OpenAPIV3.ParameterObject =>
|
|
155
|
-
!("$ref" in param) && param.in === "path" && (param.required === true),
|
|
156
|
-
)
|
|
157
|
-
.map(param => param.name);
|
|
158
|
-
const providedPathParams = Object.keys(urlVariables || {});
|
|
159
|
-
const missingPathParams = requiredPathParams.filter(param => !providedPathParams.includes(param));
|
|
160
|
-
if (missingPathParams.length > 0) {
|
|
161
|
-
errors.push(`Missing required path parameters: ${missingPathParams.join(", ")}`);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
/**
|
|
167
|
-
* Validate URL query parameters against OpenAPI specification
|
|
168
|
-
*/
|
|
169
|
-
export function validateUrlQueryParam(
|
|
170
|
-
urlQueryParams: Record<string, unknown> | undefined,
|
|
171
|
-
parameters: (OpenAPIV3.ReferenceObject | OpenAPIV3.ParameterObject)[] | undefined,
|
|
172
|
-
errors: string[],
|
|
173
|
-
): void {
|
|
174
|
-
const ajv = new Ajv({ allErrors: true });
|
|
175
|
-
if (urlQueryParams) {
|
|
176
|
-
const queryParams = (parameters || []).filter(
|
|
177
|
-
(param): param is OpenAPIV3.ParameterObject =>
|
|
178
|
-
!("$ref" in param) && param.in === "query",
|
|
179
|
-
);
|
|
180
|
-
|
|
181
|
-
for (const param of queryParams) {
|
|
182
|
-
const value = urlQueryParams[param.name];
|
|
183
|
-
|
|
184
|
-
if (param.required && (value === undefined || value === null || value === "")) {
|
|
185
|
-
errors.push(`Missing required query parameter: ${param.name}`);
|
|
186
|
-
continue;
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
if (value !== undefined && param.schema) {
|
|
190
|
-
const validate = ajv.compile(param.schema);
|
|
191
|
-
// Convert string values to appropriate types for validation
|
|
192
|
-
let validationValue = value;
|
|
193
|
-
if (typeof value === "string" && param.schema && !("$ref" in param.schema) && (param.schema).type) {
|
|
194
|
-
const schemaObj = param.schema;
|
|
195
|
-
switch (schemaObj.type) {
|
|
196
|
-
case "integer":
|
|
197
|
-
case "number":
|
|
198
|
-
validationValue = Number(value);
|
|
199
|
-
break;
|
|
200
|
-
case "boolean":
|
|
201
|
-
validationValue = value.toLowerCase() === "true";
|
|
202
|
-
break;
|
|
203
|
-
case "array":
|
|
204
|
-
// Handle comma-separated values for arrays
|
|
205
|
-
if (param.style === "form" && !param.explode) {
|
|
206
|
-
validationValue = value.split(",");
|
|
207
|
-
}
|
|
208
|
-
break;
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
if (!validate(validationValue)) {
|
|
213
|
-
errors.push(`Invalid query parameter ${param.name}: ${ajv.errorsText(validate.errors)}`);
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
/**
|
|
221
|
-
* Validate URL headers against OpenAPI specification
|
|
222
|
-
*/
|
|
223
|
-
export function validateUrlHeaders(
|
|
224
|
-
headers: Record<string, string> | undefined,
|
|
225
|
-
parameters: (OpenAPIV3.ReferenceObject | OpenAPIV3.ParameterObject)[] | undefined,
|
|
226
|
-
errors: string[],
|
|
227
|
-
): void {
|
|
228
|
-
const ajv = new Ajv({ allErrors: true });
|
|
229
|
-
if (headers) {
|
|
230
|
-
const headerParams = (parameters || []).filter(
|
|
231
|
-
(param): param is OpenAPIV3.ParameterObject =>
|
|
232
|
-
!("$ref" in param) && param.in === "header",
|
|
233
|
-
);
|
|
234
|
-
|
|
235
|
-
for (const param of headerParams) {
|
|
236
|
-
const headerName = param.name.toLowerCase();
|
|
237
|
-
const value = headers[headerName] || headers[param.name];
|
|
238
|
-
|
|
239
|
-
if (param.required && (value === undefined || value === null || value === "")) {
|
|
240
|
-
errors.push(`Missing required header parameter: ${param.name}`);
|
|
241
|
-
continue;
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
if (value !== undefined && param.schema) {
|
|
245
|
-
const validate = ajv.compile(param.schema);
|
|
246
|
-
if (!validate(value)) {
|
|
247
|
-
errors.push(`Invalid header parameter ${param.name}: ${ajv.errorsText(validate.errors)}`);
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
/**
|
|
255
|
-
* Validate URL request body against OpenAPI specification
|
|
256
|
-
*/
|
|
257
|
-
export function validateUrlRequestBody(
|
|
258
|
-
inputBody: Record<string, unknown> | undefined,
|
|
259
|
-
operationBody: OpenAPIV3.ReferenceObject | OpenAPIV3.RequestBodyObject | undefined,
|
|
260
|
-
errors: string[],
|
|
261
|
-
): void {
|
|
262
|
-
const ajv = new Ajv({ allErrors: true, strict: false });
|
|
263
|
-
if (operationBody && !("$ref" in operationBody)) {
|
|
264
|
-
const requestBody = operationBody;
|
|
265
|
-
const isRequired = requestBody.required || false;
|
|
266
|
-
|
|
267
|
-
if (isRequired && (!inputBody || Object.keys(inputBody).length === 0)) {
|
|
268
|
-
errors.push("Missing required request body");
|
|
269
|
-
} else if (inputBody && Object.keys(inputBody).length > 0) {
|
|
270
|
-
// Find the appropriate content type schema
|
|
271
|
-
const contentTypes = ["application/json", "application/x-www-form-urlencoded", "multipart/form-data"];
|
|
272
|
-
let schema: OpenAPIV3.SchemaObject | undefined;
|
|
273
|
-
|
|
274
|
-
for (const contentType of contentTypes) {
|
|
275
|
-
if (requestBody.content?.[contentType]?.schema) {
|
|
276
|
-
schema = requestBody.content[contentType].schema as OpenAPIV3.SchemaObject;
|
|
277
|
-
break;
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
if (schema) {
|
|
282
|
-
const validate = ajv.compile(schema);
|
|
283
|
-
if (!validate(inputBody)) {
|
|
284
|
-
errors.push(`Invalid request body: ${ajv.errorsText(validate.errors)}`);
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
// Load environment variables from .env file
|
|
2
|
-
import * as dotenv from "dotenv";
|
|
3
|
-
dotenv.config();
|
|
4
|
-
|
|
5
|
-
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
6
|
-
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
7
|
-
import { registerOpenApiTools } from "./service/openapi-service.js";
|
|
8
|
-
import * as constants from "./constant/constants.js";
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Check if required environment variables are set for eBay API authentication
|
|
12
|
-
*/
|
|
13
|
-
function checkEnvironmentVariables(): void {
|
|
14
|
-
|
|
15
|
-
// environment vals check
|
|
16
|
-
const missingVars = constants.REQUIRED_ENV_VARS.filter(varName => !process.env[varName]);
|
|
17
|
-
|
|
18
|
-
if (missingVars.length > 0) {
|
|
19
|
-
console.error(`Missing required environment variables: ${missingVars.join(", ")}`);
|
|
20
|
-
process.exit(1);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
if (process.env.EBAY_ENVIRONMENT &&
|
|
24
|
-
!["sandbox", "production"].includes(process.env.EBAY_ENVIRONMENT.toLowerCase())) {
|
|
25
|
-
console.warn("Warning: EBAY_ENVIRONMENT must be either \"sandbox\" or \"production\"");
|
|
26
|
-
console.warn(`Current value "${process.env.EBAY_ENVIRONMENT}" is invalid, defaulting to "production"`);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Main function to initialize and run the eBay API MCP Server
|
|
32
|
-
* This server exposes eBay API endpoints as MCP tools for access via AI models
|
|
33
|
-
*/
|
|
34
|
-
async function main(): Promise<void> {
|
|
35
|
-
console.error("Starting eBay API MCP Server...");
|
|
36
|
-
// Check for required environment variables
|
|
37
|
-
checkEnvironmentVariables();
|
|
38
|
-
const server = initServer();
|
|
39
|
-
|
|
40
|
-
try {
|
|
41
|
-
// Register the OpenAPI tools with the server
|
|
42
|
-
await registerOpenApiTools(server);
|
|
43
|
-
console.error("Successfully registered OpenAPI tools");
|
|
44
|
-
|
|
45
|
-
// Create and connect server transport
|
|
46
|
-
const transport = new StdioServerTransport();
|
|
47
|
-
await server.connect(transport);
|
|
48
|
-
console.error("eBay API MCP Server running on stdio transport");
|
|
49
|
-
|
|
50
|
-
} catch (error) {
|
|
51
|
-
console.error("Error starting MCP server:", error instanceof Error ? error.message : String(error));
|
|
52
|
-
console.error("Stack trace:", error instanceof Error ? error.stack : "No stack trace available");
|
|
53
|
-
process.exit(1);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// Run the server
|
|
58
|
-
main().catch((error) => {
|
|
59
|
-
console.error("Fatal error:", error instanceof Error ? error.message : String(error));
|
|
60
|
-
console.error("Stack trace:", error instanceof Error ? error.stack : "No stack trace available");
|
|
61
|
-
process.exit(1);
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
// Create MCP server instance
|
|
66
|
-
function initServer(): McpServer {
|
|
67
|
-
return new McpServer({
|
|
68
|
-
name: "ebay-api-mcp-server",
|
|
69
|
-
version: "1.0.0",
|
|
70
|
-
capabilities: {
|
|
71
|
-
resources: {},
|
|
72
|
-
tools: {},
|
|
73
|
-
},
|
|
74
|
-
});
|
|
75
|
-
}
|
package/src/integration.test.ts
DELETED
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
import {afterAll, beforeAll, describe, expect, it} from "vitest";
|
|
2
|
-
import {Client} from "@modelcontextprotocol/sdk/client/index.js";
|
|
3
|
-
import {StdioClientTransport} from "@modelcontextprotocol/sdk/client/stdio.js";
|
|
4
|
-
import * as path from "path";
|
|
5
|
-
import * as fs from "fs";
|
|
6
|
-
|
|
7
|
-
// Define interfaces for type safety
|
|
8
|
-
interface ContentPart {
|
|
9
|
-
type: string;
|
|
10
|
-
text: string;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
interface CallToolResponse {
|
|
14
|
-
content: ContentPart[];
|
|
15
|
-
isError?: boolean;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
describe("MCP Server Integration Tests", () => {
|
|
19
|
-
let client: Client;
|
|
20
|
-
let transport: StdioClientTransport;
|
|
21
|
-
|
|
22
|
-
// Only setup the test environment if we're not skipping tests
|
|
23
|
-
beforeAll(async () => {
|
|
24
|
-
try {
|
|
25
|
-
console.log("Setting up test client...");
|
|
26
|
-
|
|
27
|
-
// Use the correct path to your server script
|
|
28
|
-
// Make sure we're using node with the compiled JS file instead of ts-node
|
|
29
|
-
const serverScriptPath = path.join(process.cwd(), "src", "index.ts");
|
|
30
|
-
|
|
31
|
-
// Check if the file exists
|
|
32
|
-
if (!fs.existsSync(serverScriptPath)) {
|
|
33
|
-
throw new Error(`Server script not found at: ${serverScriptPath}`);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
console.log(`Server script found at: ${serverScriptPath}`);
|
|
37
|
-
|
|
38
|
-
// Create the transport with the correct path to the server
|
|
39
|
-
transport = new StdioClientTransport({
|
|
40
|
-
command: "node",
|
|
41
|
-
args: [
|
|
42
|
-
"--loader", "ts-node/esm",
|
|
43
|
-
"--experimental-specifier-resolution=node",
|
|
44
|
-
serverScriptPath,
|
|
45
|
-
],
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
// Initialize the client
|
|
49
|
-
client = new Client({
|
|
50
|
-
name: "test-client",
|
|
51
|
-
version: "1.0.0",
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
console.log("Connecting to MCP server...");
|
|
55
|
-
|
|
56
|
-
// Add a timeout to the connection attempt
|
|
57
|
-
const connectionPromise = client.connect(transport);
|
|
58
|
-
const timeoutPromise = new Promise((_, reject) => {
|
|
59
|
-
setTimeout(() => reject(new Error("Connection timed out after 15 seconds")), 15000);
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
await Promise.race([connectionPromise, timeoutPromise]);
|
|
63
|
-
console.log("✅ Client connected successfully");
|
|
64
|
-
|
|
65
|
-
} catch (error) {
|
|
66
|
-
console.error("❌ Error during test setup:", error);
|
|
67
|
-
// Explicitly failing the test setup
|
|
68
|
-
throw error;
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
afterAll(async () => {
|
|
73
|
-
try {
|
|
74
|
-
if (client) {
|
|
75
|
-
console.log("Closing client connection...");
|
|
76
|
-
await client.close();
|
|
77
|
-
console.log("✅ Client closed successfully");
|
|
78
|
-
}
|
|
79
|
-
} catch (error) {
|
|
80
|
-
console.error("❌ Error during test cleanup:", error);
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
it("test list tools", async () => {
|
|
86
|
-
const result = await client.listTools();
|
|
87
|
-
console.log("Available tools:", result.tools.map(tool => tool.name));
|
|
88
|
-
expect(result.tools.length).toBeGreaterThan(1);
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
it("test query api", async () => {
|
|
92
|
-
const response = await client.callTool({
|
|
93
|
-
name: "queryAPI",
|
|
94
|
-
arguments: {
|
|
95
|
-
prompt : "i wanna order api",
|
|
96
|
-
},
|
|
97
|
-
}) as CallToolResponse;
|
|
98
|
-
|
|
99
|
-
expect(response).toBeDefined();
|
|
100
|
-
expect(response.content).toBeDefined();
|
|
101
|
-
expect(response.content.length).toBeGreaterThan(0);
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
it("test invoke api", async () => {
|
|
105
|
-
const response = await client.callTool({
|
|
106
|
-
name: "invokeAPI",
|
|
107
|
-
arguments: {
|
|
108
|
-
url: "https://api.sandbox.ebay.com/commerce/notification/v1/topic/MARKETPLACE_ACCOUNT_DELETION",
|
|
109
|
-
method: "GET",
|
|
110
|
-
headers: {},
|
|
111
|
-
urlVariables: {},
|
|
112
|
-
requestBody: {},
|
|
113
|
-
token : process.env.EBAY_CLIENT_TOKEN
|
|
114
|
-
},
|
|
115
|
-
}) as CallToolResponse;
|
|
116
|
-
|
|
117
|
-
expect(response).toBeDefined();
|
|
118
|
-
expect(response.content).toBeDefined();
|
|
119
|
-
expect(response.content.length).toBeGreaterThan(0);
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
it("test invoke api with pathVals", async () => {
|
|
123
|
-
const response = await client.callTool({
|
|
124
|
-
name: "invokeAPI",
|
|
125
|
-
arguments: {
|
|
126
|
-
url: "https://api.sandbox.ebay.com/commerce/notification/v1/subscription/{subscription_id}/test",
|
|
127
|
-
method: "POST",
|
|
128
|
-
headers: {},
|
|
129
|
-
urlVariables: {"subscription_id":"1000"},
|
|
130
|
-
requestBody: {},
|
|
131
|
-
token: process.env.EBAY_CLIENT_TOKEN
|
|
132
|
-
},
|
|
133
|
-
}) as CallToolResponse;
|
|
134
|
-
|
|
135
|
-
expect(response).toBeDefined();
|
|
136
|
-
expect(response.content).toBeDefined();
|
|
137
|
-
expect(response.content.length).toBeGreaterThan(0);
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
});
|
|
@@ -1,243 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* OpenAPI service for registering tools with MCP server
|
|
3
|
-
*/
|
|
4
|
-
import { type McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
5
|
-
import { type OpenAPIV3 } from "openapi-types";
|
|
6
|
-
import { type RequestHandlerExtra } from "@modelcontextprotocol/sdk/shared/protocol.js";
|
|
7
|
-
import { type ServerNotification, type ServerRequest } from "@modelcontextprotocol/sdk/types.js";
|
|
8
|
-
import { z, type ZodTypeAny } from "zod";
|
|
9
|
-
import axios from "axios";
|
|
10
|
-
import util from "util";
|
|
11
|
-
import { RECALL_SPEC_BY_PROMPT_URL, RECALL_SPEC_WITH_FIELD_URL, SUPPORTED_CALLING_METHODS, findApiEnvironmentByValue } from "../constant/constants.js";
|
|
12
|
-
import { getOpenApiDocumentsFromConfigFile, parseOpenApiDoc, buildOperationSchema, buildZodSchema } from "../helper/openapi-helper.js";
|
|
13
|
-
import { validateRequestParameters as validateRequestParametersFromHelper } from "../helper/validation-helper.js";
|
|
14
|
-
import { buildHeadersFromInput, buildFinalUrl, replaceDomainNameByEnvironment, formatAxiosError, buildBaseUrlFromOpenApi, prepareRequestData } from "../helper/http-helper.js";
|
|
15
|
-
|
|
16
|
-
const USER_ENVIRONMENT = findApiEnvironmentByValue(process.env.EBAY_API_ENV || "");
|
|
17
|
-
const QUERY_API_TOOL_DISCRIPTION = "Send user prompt to remote service and return recommended API spec info (GET, query param, path...). " +
|
|
18
|
-
"Only output the tool response. Don't add any unnecessary text to it.";
|
|
19
|
-
const INVOKE_API_TOOL_DISCRIPTION = "this tool requires the prior invocation of tool queryAPI to ensure proper context, please ensure tool queryAPI has been successfully executed before using this tool." +
|
|
20
|
-
"the output of tool queryAPI will be used to generate input parameter of this tool. please ensure each field type of input parameter complies with the specifications required by the api spec." +
|
|
21
|
-
"after validation , this tool will invoke eBay OpenAPI and return the result." +
|
|
22
|
-
"if the tool return error, please check the error info and give advice or fix it.";
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Register OpenAPI tools with MCP server
|
|
27
|
-
*/
|
|
28
|
-
export async function registerOpenApiTools(server: McpServer): Promise<void> {
|
|
29
|
-
// Load OpenAPI document
|
|
30
|
-
const openapis = await getOpenApiDocumentsFromConfigFile();
|
|
31
|
-
for (const doc of openapis) {
|
|
32
|
-
registerOpenApiDynamicTools(server, doc);
|
|
33
|
-
}
|
|
34
|
-
registerCustomTools(server);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* register OpenAPI tools dynamically based on the OpenAPI document
|
|
39
|
-
*/
|
|
40
|
-
function registerOpenApiDynamicTools(server: McpServer, openapi: OpenAPIV3.Document): void {
|
|
41
|
-
const baseUrl = buildBaseUrlFromOpenApi(openapi);
|
|
42
|
-
|
|
43
|
-
Object.entries(openapi.paths || {})
|
|
44
|
-
.filter(([_, pathItem]) => pathItem !== undefined)
|
|
45
|
-
.forEach(([path, pathItem]) => registerPathOperations(server, baseUrl, path, pathItem!));
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Register tools for operations in a specific path
|
|
51
|
-
*/
|
|
52
|
-
function registerPathOperations(
|
|
53
|
-
server: McpServer,
|
|
54
|
-
baseUrl: string,
|
|
55
|
-
path: string,
|
|
56
|
-
pathItem: OpenAPIV3.PathItemObject,
|
|
57
|
-
): void {
|
|
58
|
-
const supportedMethods = Object.keys(pathItem)
|
|
59
|
-
.filter(method => SUPPORTED_CALLING_METHODS[USER_ENVIRONMENT].includes(method));
|
|
60
|
-
|
|
61
|
-
supportedMethods.forEach(method => {
|
|
62
|
-
const operation = pathItem[method as keyof typeof pathItem] as OpenAPIV3.OperationObject;
|
|
63
|
-
if (operation && operation.operationId) {
|
|
64
|
-
registerOperation(server, baseUrl, path, method, operation);
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Register tool for a single API operation
|
|
71
|
-
*/
|
|
72
|
-
function registerOperation(
|
|
73
|
-
server: McpServer,
|
|
74
|
-
baseUrl: string,
|
|
75
|
-
path: string,
|
|
76
|
-
method: string,
|
|
77
|
-
operation: OpenAPIV3.OperationObject,
|
|
78
|
-
): void {
|
|
79
|
-
const properties = buildOperationSchema(operation);
|
|
80
|
-
const zodProperties = buildZodSchema(properties);
|
|
81
|
-
server.tool(
|
|
82
|
-
operation.operationId || "unknownOperation",
|
|
83
|
-
operation.description || "No description",
|
|
84
|
-
zodProperties,
|
|
85
|
-
async (input:Record<string, unknown>, _extra) => {
|
|
86
|
-
try {
|
|
87
|
-
const { resolvedPath, headers, params, data } = prepareRequestData(input, operation, path);
|
|
88
|
-
const url = baseUrl + resolvedPath;
|
|
89
|
-
const resp = await axios.request({
|
|
90
|
-
url,
|
|
91
|
-
method,
|
|
92
|
-
headers,
|
|
93
|
-
params,
|
|
94
|
-
data,
|
|
95
|
-
httpsAgent: new (await import("https")).Agent({
|
|
96
|
-
rejectUnauthorized: false,
|
|
97
|
-
})
|
|
98
|
-
});
|
|
99
|
-
return {
|
|
100
|
-
content: [
|
|
101
|
-
{ type: "text" as const, text: typeof resp.data === "string" ? resp.data : JSON.stringify(resp.data, null, 2) },
|
|
102
|
-
],
|
|
103
|
-
};
|
|
104
|
-
} catch (error) {
|
|
105
|
-
return {
|
|
106
|
-
content: [
|
|
107
|
-
{ type: "text" as const, text: `Error in invokeOpenAPI tool: ${formatAxiosError(error)}` },
|
|
108
|
-
],
|
|
109
|
-
isError: true,
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
},
|
|
113
|
-
);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* Register custom API tools to enable interaction with eBay OpenAPI services
|
|
118
|
-
* This function registers two primary tools:
|
|
119
|
-
* 1. queryAPI - For discovering API specifications
|
|
120
|
-
* 2. invokeAPI - For executing API calls with validation
|
|
121
|
-
*/
|
|
122
|
-
function registerCustomTools(server: McpServer): void {
|
|
123
|
-
registerQueryApiTool(server);
|
|
124
|
-
registerInvokeApiTool(server);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* Register a tool for querying API specifications based on natural language prompts
|
|
129
|
-
* Only registered when no custom API doc URL file is provided
|
|
130
|
-
*/
|
|
131
|
-
function registerQueryApiTool(server: McpServer): void {
|
|
132
|
-
const hasCustomDoc = process.env.EBAY_API_DOC_URL_FILE;
|
|
133
|
-
if (hasCustomDoc) {return;}
|
|
134
|
-
|
|
135
|
-
server.tool(
|
|
136
|
-
"queryAPI",
|
|
137
|
-
QUERY_API_TOOL_DISCRIPTION,
|
|
138
|
-
{ prompt: z.string() },
|
|
139
|
-
async (input) => {
|
|
140
|
-
try {
|
|
141
|
-
const url = util.format(RECALL_SPEC_BY_PROMPT_URL, encodeURIComponent(input.prompt));
|
|
142
|
-
const resp = await axios.get(url, {
|
|
143
|
-
httpsAgent: new (await import("https")).Agent({
|
|
144
|
-
rejectUnauthorized: false,
|
|
145
|
-
}),
|
|
146
|
-
});
|
|
147
|
-
return {
|
|
148
|
-
content: [
|
|
149
|
-
{ type: "text" as const, text: resp.data ? (typeof resp.data === "string" ? resp.data : JSON.stringify(resp.data, null, 2)) : "No response body" }
|
|
150
|
-
],
|
|
151
|
-
};
|
|
152
|
-
} catch (error) {
|
|
153
|
-
return {
|
|
154
|
-
content: [
|
|
155
|
-
{ type: "text", text: `Error: ${error instanceof Error ? error.message : String(error)}` },
|
|
156
|
-
],
|
|
157
|
-
isError: true,
|
|
158
|
-
};
|
|
159
|
-
}
|
|
160
|
-
},
|
|
161
|
-
);
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
/**
|
|
165
|
-
* Register a tool for executing API calls with proper validation and error handling
|
|
166
|
-
*/
|
|
167
|
-
function registerInvokeApiTool(server: McpServer): void {
|
|
168
|
-
server.tool(
|
|
169
|
-
"invokeAPI",
|
|
170
|
-
INVOKE_API_TOOL_DISCRIPTION,
|
|
171
|
-
getInvokeApiSchema(),
|
|
172
|
-
async (input, _extra: RequestHandlerExtra<ServerRequest, ServerNotification>) => {
|
|
173
|
-
try {
|
|
174
|
-
// Build headers
|
|
175
|
-
const headers = buildHeadersFromInput(input.headers);
|
|
176
|
-
// query and parse apiSpec by specTitle and operationId
|
|
177
|
-
const openApiDoc = await parseOpenApiDoc(input.specTitle, input.operationId, RECALL_SPEC_WITH_FIELD_URL);
|
|
178
|
-
const replacedDomainUrl = replaceDomainNameByEnvironment(input.url);
|
|
179
|
-
|
|
180
|
-
// Validate req parameters against OpenAPI spec
|
|
181
|
-
const reqParamValidation = validateRequestParametersFromHelper(replacedDomainUrl, openApiDoc, input.method, {
|
|
182
|
-
urlVariables: input.urlVariables,
|
|
183
|
-
urlQueryParams: input.urlQueryParams,
|
|
184
|
-
headers,
|
|
185
|
-
requestBody: input.requestBody,
|
|
186
|
-
});
|
|
187
|
-
if (!reqParamValidation.isValid) {
|
|
188
|
-
return {
|
|
189
|
-
content: [
|
|
190
|
-
{ type: "text" as const, text: "Request validation failed:" },
|
|
191
|
-
{ type: "text" as const, text: reqParamValidation.errors.join("\n") },
|
|
192
|
-
],
|
|
193
|
-
isError: true,
|
|
194
|
-
};
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
// Make the API request
|
|
198
|
-
const resp = await axios.request({
|
|
199
|
-
url : buildFinalUrl(replacedDomainUrl, input.urlVariables),
|
|
200
|
-
method: input.method,
|
|
201
|
-
headers,
|
|
202
|
-
params: input.urlQueryParams,
|
|
203
|
-
data : input.requestBody,
|
|
204
|
-
httpsAgent: new (await import("https")).Agent({
|
|
205
|
-
rejectUnauthorized: false,
|
|
206
|
-
}),
|
|
207
|
-
});
|
|
208
|
-
|
|
209
|
-
return {
|
|
210
|
-
content: [
|
|
211
|
-
{ type: "text" as const, text: resp.data ? (typeof resp.data === "string" ? resp.data : JSON.stringify(resp.data, null, 2)) : "No response body" },
|
|
212
|
-
],
|
|
213
|
-
};
|
|
214
|
-
} catch (error) {
|
|
215
|
-
return {
|
|
216
|
-
content: [
|
|
217
|
-
{ type: "text" as const, text: `Error in invokeOpenAPI tool: ${formatAxiosError(error)}` },
|
|
218
|
-
],
|
|
219
|
-
isError: true,
|
|
220
|
-
};
|
|
221
|
-
}
|
|
222
|
-
},
|
|
223
|
-
);
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
/**
|
|
227
|
-
* Define the schema for invokeAPI tool parameters
|
|
228
|
-
*/
|
|
229
|
-
function getInvokeApiSchema(): Record<string, ZodTypeAny> {
|
|
230
|
-
return {
|
|
231
|
-
url: z.string().describe("The complete request API URL, url and basePath need to be put in together. don't replace path variables, maintain variables such as {item_id}, the variable will be replaced by urlVariables input in tool."),
|
|
232
|
-
method: z.string().describe("The request API method (GET, POST, PUT, DELETE, ...)"),
|
|
233
|
-
headers: z.record(z.string(), z.array(z.string())).optional().describe("The API header params"),
|
|
234
|
-
urlVariables: z.record(z.string(), z.any()).optional().describe("The API path variables"),
|
|
235
|
-
urlQueryParams: z.record(z.string(), z.string()).optional().describe("The API query parameters"),
|
|
236
|
-
requestBody: z.record(z.string(), z.any()).optional().describe("The API request body"),
|
|
237
|
-
specTitle: z.string().describe("The OpenAPI spec title from info.title"),
|
|
238
|
-
operationId: z.string().describe("The OpenAPI operationId"),
|
|
239
|
-
};
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
package/tsconfig.build.json
DELETED
package/tsconfig.json
DELETED
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
/* Visit https://aka.ms/tsconfig to read more about this file */
|
|
4
|
-
|
|
5
|
-
/* Projects */
|
|
6
|
-
// "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */
|
|
7
|
-
// "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
|
|
8
|
-
// "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */
|
|
9
|
-
// "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */
|
|
10
|
-
// "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
|
|
11
|
-
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
|
|
12
|
-
|
|
13
|
-
/* Language and Environment */
|
|
14
|
-
"target": "ES2022", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
|
|
15
|
-
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
|
|
16
|
-
// "jsx": "preserve", /* Specify what JSX code is generated. */
|
|
17
|
-
// "libReplacement": true, /* Enable lib replacement. */
|
|
18
|
-
// "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */
|
|
19
|
-
// "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
|
|
20
|
-
// "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */
|
|
21
|
-
// "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
|
|
22
|
-
// "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */
|
|
23
|
-
// "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */
|
|
24
|
-
// "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
|
|
25
|
-
// "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
|
|
26
|
-
// "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
|
|
27
|
-
|
|
28
|
-
/* Modules */
|
|
29
|
-
"module": "NodeNext", /* Specify what module code is generated. */
|
|
30
|
-
"moduleResolution": "NodeNext", /* Specify how TypeScript looks up a file from a given module specifier. */
|
|
31
|
-
"rootDir": "./src", /* Specify the root folder within your source files. */
|
|
32
|
-
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
|
|
33
|
-
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
|
|
34
|
-
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
|
|
35
|
-
// "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
|
|
36
|
-
// "types": [], /* Specify type package names to be included without being referenced in a source file. */
|
|
37
|
-
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
|
38
|
-
// "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
|
|
39
|
-
// "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */
|
|
40
|
-
// "rewriteRelativeImportExtensions": true, /* Rewrite '.ts', '.tsx', '.mts', and '.cts' file extensions in relative import paths to their JavaScript equivalent in output files. */
|
|
41
|
-
// "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */
|
|
42
|
-
// "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */
|
|
43
|
-
// "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */
|
|
44
|
-
// "noUncheckedSideEffectImports": true, /* Check side effect imports. */
|
|
45
|
-
"resolveJsonModule": true, /* Enable importing .json files. */
|
|
46
|
-
// "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */
|
|
47
|
-
// "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */
|
|
48
|
-
|
|
49
|
-
/* JavaScript Support */
|
|
50
|
-
// "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
|
|
51
|
-
// "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
|
|
52
|
-
// "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */
|
|
53
|
-
|
|
54
|
-
/* Emit */
|
|
55
|
-
// "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
|
|
56
|
-
// "declarationMap": true, /* Create sourcemaps for d.ts files. */
|
|
57
|
-
// "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
|
|
58
|
-
"sourceMap": true, /* Create source map files for emitted JavaScript files. */
|
|
59
|
-
// "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
|
|
60
|
-
// "noEmit": true, /* Disable emitting files from a compilation. */
|
|
61
|
-
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
|
|
62
|
-
"outDir": "./dist", /* Specify an output folder for all emitted files. */
|
|
63
|
-
// "removeComments": true, /* Disable emitting comments. */
|
|
64
|
-
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
|
|
65
|
-
// "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
|
|
66
|
-
// "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
|
|
67
|
-
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
|
|
68
|
-
// "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
|
|
69
|
-
// "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
|
|
70
|
-
// "newLine": "crlf", /* Set the newline character for emitting files. */
|
|
71
|
-
// "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */
|
|
72
|
-
// "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */
|
|
73
|
-
// "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
|
|
74
|
-
// "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
|
|
75
|
-
// "declarationDir": "./", /* Specify the output directory for generated declaration files. */
|
|
76
|
-
|
|
77
|
-
/* Interop Constraints */
|
|
78
|
-
"isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
|
|
79
|
-
// "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */
|
|
80
|
-
// "isolatedDeclarations": true, /* Require sufficient annotation on exports so other tools can trivially generate declaration files. */
|
|
81
|
-
// "erasableSyntaxOnly": true, /* Do not allow runtime constructs that are not part of ECMAScript. */
|
|
82
|
-
// "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
|
|
83
|
-
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
|
|
84
|
-
// "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
|
|
85
|
-
"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
|
|
86
|
-
|
|
87
|
-
/* Type Checking */
|
|
88
|
-
"strict": true, /* Enable all strict type-checking options. */
|
|
89
|
-
// "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
|
|
90
|
-
// "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
|
|
91
|
-
// "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
|
|
92
|
-
// "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
|
|
93
|
-
// "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
|
|
94
|
-
// "strictBuiltinIteratorReturn": true, /* Built-in iterators are instantiated with a 'TReturn' type of 'undefined' instead of 'any'. */
|
|
95
|
-
// "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */
|
|
96
|
-
// "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */
|
|
97
|
-
// "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
|
|
98
|
-
// "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */
|
|
99
|
-
// "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */
|
|
100
|
-
// "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
|
|
101
|
-
// "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
|
|
102
|
-
// "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
|
|
103
|
-
// "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */
|
|
104
|
-
// "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
|
|
105
|
-
// "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */
|
|
106
|
-
// "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
|
|
107
|
-
// "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
|
|
108
|
-
|
|
109
|
-
/* Completeness */
|
|
110
|
-
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
|
|
111
|
-
"skipLibCheck": true /* Skip type checking all .d.ts files. */
|
|
112
|
-
},
|
|
113
|
-
"include": ["src/**/*"],
|
|
114
|
-
"exclude": ["node_modules"]
|
|
115
|
-
}
|
package/tsconfig.node.json
DELETED
package/vitest.config.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { defineConfig } from "vitest/config";
|
|
2
|
-
import { resolve } from "path";
|
|
3
|
-
|
|
4
|
-
export default defineConfig({
|
|
5
|
-
test: {
|
|
6
|
-
environment: "node",
|
|
7
|
-
include: ["src/**/*.test.ts"],
|
|
8
|
-
globals: true,
|
|
9
|
-
setupFiles: ["./vitest.setup.ts"],
|
|
10
|
-
alias: {
|
|
11
|
-
// This mimics the moduleNameMapper in your Jest config
|
|
12
|
-
"~/(.*)": resolve(__dirname, "src/$1"),
|
|
13
|
-
},
|
|
14
|
-
coverage: {
|
|
15
|
-
provider: "v8",
|
|
16
|
-
reporter: ["text", "json", "html"],
|
|
17
|
-
exclude: ["**/node_modules/**", "**/dist/**", "**/src/test/**"],
|
|
18
|
-
},
|
|
19
|
-
},
|
|
20
|
-
});
|