@yirifi-org/mcp-server 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,73 @@
1
+ /**
2
+ * HTTP client for making authenticated requests to Yirifi APIs.
3
+ */
4
+ /**
5
+ * Structured API error with status code and response details.
6
+ * Enables the executor to provide actionable error messages to the LLM.
7
+ */
8
+ export declare class YirifiApiError extends Error {
9
+ readonly status: number;
10
+ readonly statusText: string;
11
+ readonly responseBody: unknown;
12
+ readonly method: string;
13
+ readonly url: string;
14
+ constructor(status: number, statusText: string, responseBody: unknown, method: string, url: string);
15
+ }
16
+ export interface YirifiClientOptions {
17
+ /** Base URL for all API requests (e.g., https://dev-api.yirifi.ai) */
18
+ baseUrl: string;
19
+ /** API key for authentication */
20
+ apiKey: string;
21
+ /** Request timeout in milliseconds (default: 30000) */
22
+ timeout?: number;
23
+ }
24
+ /**
25
+ * HTTP client wrapper for making authenticated API requests to Yirifi services.
26
+ *
27
+ * This client handles:
28
+ * - API key authentication
29
+ * - Request/response formatting
30
+ * - Error handling and logging
31
+ * - Timeout management
32
+ */
33
+ export declare class YirifiClient {
34
+ private readonly client;
35
+ private readonly baseUrl;
36
+ constructor(options: YirifiClientOptions);
37
+ /**
38
+ * Make an authenticated API request.
39
+ *
40
+ * @param method - HTTP method (GET, POST, etc.)
41
+ * @param endpoint - API endpoint path (e.g., /regdb/v1/regulations/country/list)
42
+ * @param params - Query parameters
43
+ * @param data - JSON request body
44
+ * @returns JSON response from the API
45
+ * @throws Error if the request fails
46
+ */
47
+ request<T = unknown>(method: string, endpoint: string, params?: Record<string, unknown>, data?: Record<string, unknown>): Promise<T>;
48
+ /**
49
+ * Make a GET request.
50
+ *
51
+ * @param endpoint - API endpoint path
52
+ * @param params - Query parameters
53
+ * @returns JSON response from the API
54
+ */
55
+ get<T = unknown>(endpoint: string, params?: Record<string, unknown>): Promise<T>;
56
+ /**
57
+ * Make a POST request.
58
+ *
59
+ * @param endpoint - API endpoint path
60
+ * @param data - JSON request body
61
+ * @param params - Query parameters
62
+ * @returns JSON response from the API
63
+ */
64
+ post<T = unknown>(endpoint: string, data?: Record<string, unknown>, params?: Record<string, unknown>): Promise<T>;
65
+ /**
66
+ * Format API response data as pretty-printed JSON.
67
+ *
68
+ * @param data - Response data to format
69
+ * @returns Formatted JSON string
70
+ */
71
+ static formatResponse(data: unknown): string;
72
+ }
73
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH;;;GAGG;AACH,qBAAa,cAAe,SAAQ,KAAK;aAErB,MAAM,EAAE,MAAM;aACd,UAAU,EAAE,MAAM;aAClB,YAAY,EAAE,OAAO;aACrB,MAAM,EAAE,MAAM;aACd,GAAG,EAAE,MAAM;gBAJX,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,MAAM,EAClB,YAAY,EAAE,OAAO,EACrB,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,MAAM;CAS9B;AAED,MAAM,WAAW,mBAAmB;IAClC,sEAAsE;IACtE,OAAO,EAAE,MAAM,CAAC;IAChB,iCAAiC;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,uDAAuD;IACvD,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;;;GAQG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAgB;IACvC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;gBAErB,OAAO,EAAE,mBAAmB;IAaxC;;;;;;;;;OASG;IACG,OAAO,CAAC,CAAC,GAAG,OAAO,EACvB,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,EAChB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC7B,OAAO,CAAC,CAAC,CAAC;IA4Bb;;;;;;OAMG;IACG,GAAG,CAAC,CAAC,GAAG,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;IAItF;;;;;;;OAOG;IACG,IAAI,CAAC,CAAC,GAAG,OAAO,EACpB,QAAQ,EAAE,MAAM,EAChB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC9B,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC/B,OAAO,CAAC,CAAC,CAAC;IAIb;;;;;OAKG;IACH,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM;CAG7C"}
package/dist/client.js ADDED
@@ -0,0 +1,116 @@
1
+ /**
2
+ * HTTP client for making authenticated requests to Yirifi APIs.
3
+ */
4
+ import axios from "axios";
5
+ /**
6
+ * Structured API error with status code and response details.
7
+ * Enables the executor to provide actionable error messages to the LLM.
8
+ */
9
+ export class YirifiApiError extends Error {
10
+ status;
11
+ statusText;
12
+ responseBody;
13
+ method;
14
+ url;
15
+ constructor(status, statusText, responseBody, method, url) {
16
+ const bodyMsg = typeof responseBody === "object" && responseBody !== null
17
+ ? (responseBody.message ?? JSON.stringify(responseBody))
18
+ : String(responseBody ?? "Unknown error");
19
+ super(`${status} ${statusText}: ${bodyMsg}`);
20
+ this.status = status;
21
+ this.statusText = statusText;
22
+ this.responseBody = responseBody;
23
+ this.method = method;
24
+ this.url = url;
25
+ this.name = "YirifiApiError";
26
+ }
27
+ }
28
+ /**
29
+ * HTTP client wrapper for making authenticated API requests to Yirifi services.
30
+ *
31
+ * This client handles:
32
+ * - API key authentication
33
+ * - Request/response formatting
34
+ * - Error handling and logging
35
+ * - Timeout management
36
+ */
37
+ export class YirifiClient {
38
+ client;
39
+ baseUrl;
40
+ constructor(options) {
41
+ this.baseUrl = options.baseUrl.replace(/\/$/, "");
42
+ this.client = axios.create({
43
+ baseURL: this.baseUrl,
44
+ timeout: options.timeout ?? 30000,
45
+ headers: {
46
+ "api-key": options.apiKey,
47
+ "Content-Type": "application/json",
48
+ },
49
+ });
50
+ }
51
+ /**
52
+ * Make an authenticated API request.
53
+ *
54
+ * @param method - HTTP method (GET, POST, etc.)
55
+ * @param endpoint - API endpoint path (e.g., /regdb/v1/regulations/country/list)
56
+ * @param params - Query parameters
57
+ * @param data - JSON request body
58
+ * @returns JSON response from the API
59
+ * @throws Error if the request fails
60
+ */
61
+ async request(method, endpoint, params, data) {
62
+ const url = `${this.baseUrl}${endpoint}`;
63
+ try {
64
+ const config = {
65
+ method,
66
+ url: endpoint,
67
+ params,
68
+ data,
69
+ };
70
+ const response = await this.client.request(config);
71
+ return response.data;
72
+ }
73
+ catch (error) {
74
+ if (axios.isAxiosError(error)) {
75
+ const status = error.response?.status ?? 0;
76
+ const statusText = error.response?.statusText ?? "Unknown";
77
+ const responseBody = error.response?.data;
78
+ console.error(`API request failed: ${method} ${url} - Status: ${status}, Message: ${responseBody?.message || error.message}`);
79
+ throw new YirifiApiError(status, statusText, responseBody, method, url);
80
+ }
81
+ console.error(`API request failed: ${method} ${url} - ${error}`);
82
+ throw error;
83
+ }
84
+ }
85
+ /**
86
+ * Make a GET request.
87
+ *
88
+ * @param endpoint - API endpoint path
89
+ * @param params - Query parameters
90
+ * @returns JSON response from the API
91
+ */
92
+ async get(endpoint, params) {
93
+ return this.request("GET", endpoint, params);
94
+ }
95
+ /**
96
+ * Make a POST request.
97
+ *
98
+ * @param endpoint - API endpoint path
99
+ * @param data - JSON request body
100
+ * @param params - Query parameters
101
+ * @returns JSON response from the API
102
+ */
103
+ async post(endpoint, data, params) {
104
+ return this.request("POST", endpoint, params, data);
105
+ }
106
+ /**
107
+ * Format API response data as pretty-printed JSON.
108
+ *
109
+ * @param data - Response data to format
110
+ * @returns Formatted JSON string
111
+ */
112
+ static formatResponse(data) {
113
+ return JSON.stringify(data, null, 2);
114
+ }
115
+ }
116
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAsD,MAAM,OAAO,CAAC;AAE3E;;;GAGG;AACH,MAAM,OAAO,cAAe,SAAQ,KAAK;IAErB;IACA;IACA;IACA;IACA;IALlB,YACkB,MAAc,EACd,UAAkB,EAClB,YAAqB,EACrB,MAAc,EACd,GAAW;QAE3B,MAAM,OAAO,GACX,OAAO,YAAY,KAAK,QAAQ,IAAI,YAAY,KAAK,IAAI;YACvD,CAAC,CAAC,CAAE,YAAwC,CAAC,OAAO,IAAI,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC;YACrF,CAAC,CAAC,MAAM,CAAC,YAAY,IAAI,eAAe,CAAC,CAAC;QAC9C,KAAK,CAAC,GAAG,MAAM,IAAI,UAAU,KAAK,OAAO,EAAE,CAAC,CAAC;QAV7B,WAAM,GAAN,MAAM,CAAQ;QACd,eAAU,GAAV,UAAU,CAAQ;QAClB,iBAAY,GAAZ,YAAY,CAAS;QACrB,WAAM,GAAN,MAAM,CAAQ;QACd,QAAG,GAAH,GAAG,CAAQ;QAO3B,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC;IAC/B,CAAC;CACF;AAWD;;;;;;;;GAQG;AACH,MAAM,OAAO,YAAY;IACN,MAAM,CAAgB;IACtB,OAAO,CAAS;IAEjC,YAAY,OAA4B;QACtC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QAElD,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC;YACzB,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,OAAO,EAAE,OAAO,CAAC,OAAO,IAAI,KAAK;YACjC,OAAO,EAAE;gBACP,SAAS,EAAE,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EAAE,MAAgC;QACvE,OAAO,IAAI,CAAC,OAAO,CAAI,KAAK,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;IAClD,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,IAAI,CACR,QAAgB,EAChB,IAA8B,EAC9B,MAAgC;QAEhC,OAAO,IAAI,CAAC,OAAO,CAAI,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;IACzD,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,cAAc,CAAC,IAAa;QACjC,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;IACvC,CAAC;CACF"}
@@ -0,0 +1,99 @@
1
+ /**
2
+ * Configuration management for Yirifi MCP server.
3
+ * Loads and validates settings from environment variables and .env file.
4
+ */
5
+ import { z } from "zod";
6
+ /**
7
+ * STDIO mode settings (requires API key from environment)
8
+ */
9
+ declare const StdioSettingsSchema: z.ZodObject<{
10
+ /** Base URL for all Yirifi services (RegDB and Web3GRC) */
11
+ yirifiBaseUrl: z.ZodDefault<z.ZodString>;
12
+ /** Comma-separated list of tool patterns to expose (e.g., "regdb:*,web3grc:knowledge:*") */
13
+ yirifiTools: z.ZodOptional<z.ZodString>;
14
+ /**
15
+ * Comma-separated list of tool patterns to defer load (e.g., "web3grc:marketplace:*").
16
+ * Deferred tools are marked with defer_loading: true and excluded from initial context.
17
+ * They can still be discovered on-demand by Claude's Tool Search Tool.
18
+ * This reduces token usage while maintaining access to the full tool library.
19
+ */
20
+ yirifiDeferTools: z.ZodOptional<z.ZodString>;
21
+ /** Maximum response length in characters before truncation (default: 50000) */
22
+ yirifiResponseMaxChars: z.ZodOptional<z.ZodNumber>;
23
+ /** Maximum pagination limit to prevent huge payloads (default: 50) */
24
+ yirifiMaxPaginationLimit: z.ZodOptional<z.ZodNumber>;
25
+ } & {
26
+ /** API key for authenticating with Yirifi external APIs */
27
+ yirifiApiKey: z.ZodString;
28
+ }, "strip", z.ZodTypeAny, {
29
+ yirifiBaseUrl: string;
30
+ yirifiApiKey: string;
31
+ yirifiTools?: string | undefined;
32
+ yirifiDeferTools?: string | undefined;
33
+ yirifiResponseMaxChars?: number | undefined;
34
+ yirifiMaxPaginationLimit?: number | undefined;
35
+ }, {
36
+ yirifiApiKey: string;
37
+ yirifiBaseUrl?: string | undefined;
38
+ yirifiTools?: string | undefined;
39
+ yirifiDeferTools?: string | undefined;
40
+ yirifiResponseMaxChars?: number | undefined;
41
+ yirifiMaxPaginationLimit?: number | undefined;
42
+ }>;
43
+ /**
44
+ * HTTP mode settings (API key from request headers, not environment)
45
+ */
46
+ declare const HttpSettingsSchema: z.ZodObject<{
47
+ /** Base URL for all Yirifi services (RegDB and Web3GRC) */
48
+ yirifiBaseUrl: z.ZodDefault<z.ZodString>;
49
+ /** Comma-separated list of tool patterns to expose (e.g., "regdb:*,web3grc:knowledge:*") */
50
+ yirifiTools: z.ZodOptional<z.ZodString>;
51
+ /**
52
+ * Comma-separated list of tool patterns to defer load (e.g., "web3grc:marketplace:*").
53
+ * Deferred tools are marked with defer_loading: true and excluded from initial context.
54
+ * They can still be discovered on-demand by Claude's Tool Search Tool.
55
+ * This reduces token usage while maintaining access to the full tool library.
56
+ */
57
+ yirifiDeferTools: z.ZodOptional<z.ZodString>;
58
+ /** Maximum response length in characters before truncation (default: 50000) */
59
+ yirifiResponseMaxChars: z.ZodOptional<z.ZodNumber>;
60
+ /** Maximum pagination limit to prevent huge payloads (default: 50) */
61
+ yirifiMaxPaginationLimit: z.ZodOptional<z.ZodNumber>;
62
+ } & {
63
+ /** HTTP server port */
64
+ port: z.ZodDefault<z.ZodNumber>;
65
+ }, "strip", z.ZodTypeAny, {
66
+ yirifiBaseUrl: string;
67
+ port: number;
68
+ yirifiTools?: string | undefined;
69
+ yirifiDeferTools?: string | undefined;
70
+ yirifiResponseMaxChars?: number | undefined;
71
+ yirifiMaxPaginationLimit?: number | undefined;
72
+ }, {
73
+ yirifiBaseUrl?: string | undefined;
74
+ yirifiTools?: string | undefined;
75
+ yirifiDeferTools?: string | undefined;
76
+ yirifiResponseMaxChars?: number | undefined;
77
+ yirifiMaxPaginationLimit?: number | undefined;
78
+ port?: number | undefined;
79
+ }>;
80
+ export type Settings = z.infer<typeof StdioSettingsSchema>;
81
+ export type HttpSettings = z.infer<typeof HttpSettingsSchema>;
82
+ /**
83
+ * Load and validate settings for STDIO mode.
84
+ * Requires YIRIFI_API_KEY environment variable.
85
+ *
86
+ * @returns Validated settings instance
87
+ * @throws Error if required settings are missing or invalid
88
+ */
89
+ export declare function loadSettings(): Settings;
90
+ /**
91
+ * Load and validate settings for HTTP mode.
92
+ * API key is extracted from request headers, not environment.
93
+ *
94
+ * @returns Validated settings instance
95
+ * @throws Error if settings are invalid
96
+ */
97
+ export declare function loadHttpSettings(): HttpSettings;
98
+ export {};
99
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AA8BxB;;GAEG;AACH,QAAA,MAAM,mBAAmB;IAxBvB,2DAA2D;;IAG3D,4FAA4F;;IAG5F;;;;;OAKG;;IAGH,+EAA+E;;IAG/E,sEAAsE;;;IAQtE,2DAA2D;;;;;;;;;;;;;;;;EAE3D,CAAC;AAEH;;GAEG;AACH,QAAA,MAAM,kBAAkB;IAhCtB,2DAA2D;;IAG3D,4FAA4F;;IAG5F;;;;;OAKG;;IAGH,+EAA+E;;IAG/E,sEAAsE;;;IAgBtE,uBAAuB;;;;;;;;;;;;;;;;EAEvB,CAAC;AAEH,MAAM,MAAM,QAAQ,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAC3D,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAE9D;;;;;;GAMG;AACH,wBAAgB,YAAY,IAAI,QAAQ,CAuBvC;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,IAAI,YAAY,CAuB/C"}
package/dist/config.js ADDED
@@ -0,0 +1,105 @@
1
+ /**
2
+ * Configuration management for Yirifi MCP server.
3
+ * Loads and validates settings from environment variables and .env file.
4
+ */
5
+ import { config } from "dotenv";
6
+ import { z } from "zod";
7
+ // Load .env file
8
+ config();
9
+ /**
10
+ * Base settings schema (shared between STDIO and HTTP modes)
11
+ */
12
+ const BaseSettingsSchema = z.object({
13
+ /** Base URL for all Yirifi services (RegDB and Web3GRC) */
14
+ yirifiBaseUrl: z.string().url("Invalid base URL format").default("https://dev-api.yirifi.ai"),
15
+ /** Comma-separated list of tool patterns to expose (e.g., "regdb:*,web3grc:knowledge:*") */
16
+ yirifiTools: z.string().optional(),
17
+ /**
18
+ * Comma-separated list of tool patterns to defer load (e.g., "web3grc:marketplace:*").
19
+ * Deferred tools are marked with defer_loading: true and excluded from initial context.
20
+ * They can still be discovered on-demand by Claude's Tool Search Tool.
21
+ * This reduces token usage while maintaining access to the full tool library.
22
+ */
23
+ yirifiDeferTools: z.string().optional(),
24
+ /** Maximum response length in characters before truncation (default: 50000) */
25
+ yirifiResponseMaxChars: z.number().int().positive().optional(),
26
+ /** Maximum pagination limit to prevent huge payloads (default: 50) */
27
+ yirifiMaxPaginationLimit: z.number().int().positive().optional(),
28
+ });
29
+ /**
30
+ * STDIO mode settings (requires API key from environment)
31
+ */
32
+ const StdioSettingsSchema = BaseSettingsSchema.extend({
33
+ /** API key for authenticating with Yirifi external APIs */
34
+ yirifiApiKey: z.string().min(1, "API key is required"),
35
+ });
36
+ /**
37
+ * HTTP mode settings (API key from request headers, not environment)
38
+ */
39
+ const HttpSettingsSchema = BaseSettingsSchema.extend({
40
+ /** HTTP server port */
41
+ port: z.number().int().positive().default(8002),
42
+ });
43
+ /**
44
+ * Load and validate settings for STDIO mode.
45
+ * Requires YIRIFI_API_KEY environment variable.
46
+ *
47
+ * @returns Validated settings instance
48
+ * @throws Error if required settings are missing or invalid
49
+ */
50
+ export function loadSettings() {
51
+ try {
52
+ const rawSettings = {
53
+ yirifiApiKey: process.env.YIRIFI_API_KEY,
54
+ yirifiBaseUrl: process.env.YIRIFI_BASE_URL,
55
+ yirifiTools: process.env.YIRIFI_TOOLS,
56
+ yirifiDeferTools: process.env.YIRIFI_DEFER_TOOLS,
57
+ yirifiResponseMaxChars: process.env.YIRIFI_RESPONSE_MAX_CHARS
58
+ ? Number.parseInt(process.env.YIRIFI_RESPONSE_MAX_CHARS, 10)
59
+ : undefined,
60
+ yirifiMaxPaginationLimit: process.env.YIRIFI_MAX_PAGINATION_LIMIT
61
+ ? Number.parseInt(process.env.YIRIFI_MAX_PAGINATION_LIMIT, 10)
62
+ : undefined,
63
+ };
64
+ return StdioSettingsSchema.parse(rawSettings);
65
+ }
66
+ catch (error) {
67
+ if (error instanceof z.ZodError) {
68
+ const messages = error.errors.map((e) => `${e.path.join(".")}: ${e.message}`).join(", ");
69
+ throw new Error(`Failed to load settings: ${messages}`);
70
+ }
71
+ throw new Error(`Failed to load settings: ${error}`);
72
+ }
73
+ }
74
+ /**
75
+ * Load and validate settings for HTTP mode.
76
+ * API key is extracted from request headers, not environment.
77
+ *
78
+ * @returns Validated settings instance
79
+ * @throws Error if settings are invalid
80
+ */
81
+ export function loadHttpSettings() {
82
+ try {
83
+ const rawSettings = {
84
+ yirifiBaseUrl: process.env.YIRIFI_BASE_URL,
85
+ yirifiTools: process.env.YIRIFI_TOOLS,
86
+ yirifiDeferTools: process.env.YIRIFI_DEFER_TOOLS,
87
+ port: process.env.PORT ? Number.parseInt(process.env.PORT, 10) : undefined,
88
+ yirifiResponseMaxChars: process.env.YIRIFI_RESPONSE_MAX_CHARS
89
+ ? Number.parseInt(process.env.YIRIFI_RESPONSE_MAX_CHARS, 10)
90
+ : undefined,
91
+ yirifiMaxPaginationLimit: process.env.YIRIFI_MAX_PAGINATION_LIMIT
92
+ ? Number.parseInt(process.env.YIRIFI_MAX_PAGINATION_LIMIT, 10)
93
+ : undefined,
94
+ };
95
+ return HttpSettingsSchema.parse(rawSettings);
96
+ }
97
+ catch (error) {
98
+ if (error instanceof z.ZodError) {
99
+ const messages = error.errors.map((e) => `${e.path.join(".")}: ${e.message}`).join(", ");
100
+ throw new Error(`Failed to load settings: ${messages}`);
101
+ }
102
+ throw new Error(`Failed to load settings: ${error}`);
103
+ }
104
+ }
105
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,iBAAiB;AACjB,MAAM,EAAE,CAAC;AAET;;GAEG;AACH,MAAM,kBAAkB,GAAG,CAAC,CAAC,MAAM,CAAC;IAClC,2DAA2D;IAC3D,aAAa,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,yBAAyB,CAAC,CAAC,OAAO,CAAC,2BAA2B,CAAC;IAE7F,4FAA4F;IAC5F,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAElC;;;;;OAKG;IACH,gBAAgB,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAEvC,+EAA+E;IAC/E,sBAAsB,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE;IAE9D,sEAAsE;IACtE,wBAAwB,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE;CACjE,CAAC,CAAC;AAEH;;GAEG;AACH,MAAM,mBAAmB,GAAG,kBAAkB,CAAC,MAAM,CAAC;IACpD,2DAA2D;IAC3D,Y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C,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACzF,MAAM,IAAI,KAAK,CAAC,4BAA4B,QAAQ,EAAE,CAAC,CAAC;QAC1D,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,4BAA4B,KAAK,EAAE,CAAC,CAAC;IACvD,CAAC;AACH,CAAC"}
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * CLI entry point for Yirifi MCP Server (STDIO transport).
4
+ * This file imports and runs the STDIO server for Claude Desktop integration.
5
+ *
6
+ * For HTTP transport, use: node dist/server-http.js
7
+ */
8
+ import "./server-stdio.js";
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA;;;;;GAKG;AAEH,OAAO,mBAAmB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * CLI entry point for Yirifi MCP Server (STDIO transport).
4
+ * This file imports and runs the STDIO server for Claude Desktop integration.
5
+ *
6
+ * For HTTP transport, use: node dist/server-http.js
7
+ */
8
+ import "./server-stdio.js";
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA;;;;;GAKG;AAEH,OAAO,mBAAmB,CAAC"}
@@ -0,0 +1,73 @@
1
+ /**
2
+ * Shared MCP server core logic.
3
+ * Provides context creation and server setup for both STDIO and HTTP transports.
4
+ */
5
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
6
+ import type { YirifiClient } from "./client.js";
7
+ import { type HttpSettings, type Settings } from "./config.js";
8
+ import { type ExecuteToolOptions } from "./tools/executor.js";
9
+ import { type DeferredTool } from "./tools/filter.js";
10
+ import { type GeneratedTool } from "./tools/generator.js";
11
+ /**
12
+ * Base MCP context containing all pre-computed tool data.
13
+ * Shared across requests for efficiency.
14
+ */
15
+ export interface McpContextBase {
16
+ /** Base URL for Yirifi APIs */
17
+ yirifiBaseUrl: string;
18
+ /** All generated tools before filtering */
19
+ allTools: GeneratedTool[];
20
+ /** Tools after whitelist and defer-loading applied */
21
+ filteredTools: DeferredTool[];
22
+ /** Quick lookup map by tool name */
23
+ toolMap: Map<string, GeneratedTool>;
24
+ /** Category metadata for each tool */
25
+ toolCategories: Record<string, {
26
+ service: string;
27
+ category: string;
28
+ }>;
29
+ }
30
+ /**
31
+ * STDIO mode context (includes full settings with API key)
32
+ */
33
+ export interface McpContext extends McpContextBase {
34
+ /** Validated settings from environment */
35
+ settings: Settings;
36
+ }
37
+ /**
38
+ * HTTP mode context (settings without API key requirement)
39
+ */
40
+ export interface HttpMcpContext extends McpContextBase {
41
+ /** Validated HTTP settings */
42
+ settings: HttpSettings;
43
+ }
44
+ /**
45
+ * Create MCP context with tools generated from swagger specs.
46
+ * This should be called once at startup and reused.
47
+ *
48
+ * @returns MCP context with generated tools
49
+ */
50
+ export declare function createMcpContext(): Promise<McpContext>;
51
+ /**
52
+ * Create HTTP MCP context with tools generated from swagger specs.
53
+ * This should be called once at startup and reused.
54
+ *
55
+ * @returns HTTP MCP context with generated tools
56
+ */
57
+ export declare function createHttpMcpContext(): Promise<HttpMcpContext>;
58
+ /**
59
+ * Create an MCP server with tool handlers.
60
+ *
61
+ * @param ctx - MCP context with tool data (either STDIO or HTTP context)
62
+ * @param client - YirifiClient for making API calls
63
+ * @returns Configured McpServer instance
64
+ */
65
+ export declare function createMcpServer(ctx: McpContextBase, client: YirifiClient, executeOptions?: ExecuteToolOptions, requestToolFilter?: string): McpServer;
66
+ /**
67
+ * Log server startup information.
68
+ *
69
+ * @param ctx - MCP context (either STDIO or HTTP context)
70
+ * @param transport - Transport type label
71
+ */
72
+ export declare function logServerStartup(ctx: McpContextBase, transport: string): void;
73
+ //# sourceMappingURL=server-core.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server-core.d.ts","sourceRoot":"","sources":["../src/server-core.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAMpE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,KAAK,YAAY,EAAE,KAAK,QAAQ,EAAkC,MAAM,aAAa,CAAC;AAC/F,OAAO,EAAE,KAAK,kBAAkB,EAAe,MAAM,qBAAqB,CAAC;AAC3E,OAAO,EACL,KAAK,YAAY,EAIlB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,KAAK,aAAa,EAGnB,MAAM,sBAAsB,CAAC;AAE9B;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC7B,+BAA+B;IAC/B,aAAa,EAAE,MAAM,CAAC;IACtB,2CAA2C;IAC3C,QAAQ,EAAE,aAAa,EAAE,CAAC;IAC1B,sDAAsD;IACtD,aAAa,EAAE,YAAY,EAAE,CAAC;IAC9B,oCAAoC;IACpC,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IACpC,sCAAsC;IACtC,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CACvE;AAED;;GAEG;AACH,MAAM,WAAW,UAAW,SAAQ,cAAc;IAChD,0CAA0C;IAC1C,QAAQ,EAAE,QAAQ,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,cAAe,SAAQ,cAAc;IACpD,8BAA8B;IAC9B,QAAQ,EAAE,YAAY,CAAC;CACxB;AAED;;;;;GAKG;AACH,wBAAsB,gBAAgB,IAAI,OAAO,CAAC,UAAU,CAAC,CA8C5D;AAED;;;;;GAKG;A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