gstaccelerator 0.1.0 → 0.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,243 @@
1
+ // src/client.ts
2
+ import crossFetch from "cross-fetch";
3
+
4
+ // src/errors.ts
5
+ var GSTAcceleratorError = class extends Error {
6
+ constructor(message, statusCode, responseBody) {
7
+ super(message);
8
+ this.statusCode = statusCode;
9
+ this.responseBody = responseBody;
10
+ this.name = "GSTAcceleratorError";
11
+ }
12
+ };
13
+ var AuthenticationError = class extends GSTAcceleratorError {
14
+ constructor(message, statusCode, responseBody) {
15
+ super(message, statusCode, responseBody);
16
+ this.name = "AuthenticationError";
17
+ }
18
+ };
19
+ var RateLimitError = class extends GSTAcceleratorError {
20
+ constructor(message, statusCode, responseBody, retryAfter) {
21
+ super(message, statusCode, responseBody);
22
+ this.name = "RateLimitError";
23
+ this.retryAfter = retryAfter;
24
+ }
25
+ };
26
+ var NotFoundError = class extends GSTAcceleratorError {
27
+ constructor(message, statusCode, responseBody) {
28
+ super(message, statusCode, responseBody);
29
+ this.name = "NotFoundError";
30
+ }
31
+ };
32
+ var ValidationError = class extends GSTAcceleratorError {
33
+ constructor(message, statusCode, responseBody) {
34
+ super(message, statusCode, responseBody);
35
+ this.name = "ValidationError";
36
+ }
37
+ };
38
+ var ServerError = class extends GSTAcceleratorError {
39
+ constructor(message, statusCode, responseBody) {
40
+ super(message, statusCode, responseBody);
41
+ this.name = "ServerError";
42
+ }
43
+ };
44
+
45
+ // src/resources/hsn.ts
46
+ var HSNClient = class {
47
+ constructor(client) {
48
+ this.client = client;
49
+ }
50
+ async get(code) {
51
+ return this.client.request("GET", `/api/v1/hsn/${code}`);
52
+ }
53
+ };
54
+
55
+ // src/resources/sac.ts
56
+ var SACClient = class {
57
+ constructor(client) {
58
+ this.client = client;
59
+ }
60
+ async get(code) {
61
+ return this.client.request("GET", `/api/v1/sac/${code}`);
62
+ }
63
+ };
64
+
65
+ // src/resources/gstin.ts
66
+ var GSTINClient = class {
67
+ constructor(client) {
68
+ this.client = client;
69
+ }
70
+ async validate(gstin) {
71
+ return this.client.request("GET", `/api/v1/gstin/${gstin}/validate`);
72
+ }
73
+ async state(gstin) {
74
+ return this.client.request("GET", `/api/v1/gstin/${gstin}/state`);
75
+ }
76
+ async pan(gstin) {
77
+ return this.client.request("GET", `/api/v1/gstin/${gstin}/pan`);
78
+ }
79
+ };
80
+
81
+ // src/client.ts
82
+ var isBrowser = typeof window !== "undefined" && typeof window.document !== "undefined";
83
+ var fetchImpl = typeof fetch !== "undefined" ? fetch : crossFetch;
84
+ var GSTAccelerator = class {
85
+ constructor(config) {
86
+ this.apiKey = config.apiKey || "";
87
+ this.baseUrl = config.baseUrl || "https://gstaccelerator.in";
88
+ this.timeout = config.timeout || 3e4;
89
+ this.maxRetries = config.maxRetries ?? 3;
90
+ this.hsn = new HSNClient(this);
91
+ this.sac = new SACClient(this);
92
+ this.gstin = new GSTINClient(this);
93
+ }
94
+ async request(method, path, body) {
95
+ const url = `${this.baseUrl}${path}`;
96
+ const headers = {
97
+ "Content-Type": "application/json",
98
+ "Authorization": `Bearer ${this.apiKey}`
99
+ };
100
+ if (!isBrowser) {
101
+ headers["User-Agent"] = `gstaccelerator-js/0.1.0`;
102
+ }
103
+ let attempt = 0;
104
+ while (attempt <= this.maxRetries) {
105
+ try {
106
+ const controller = new AbortController();
107
+ const timeoutId = setTimeout(() => controller.abort(), this.timeout);
108
+ const response = await fetchImpl(url, {
109
+ method,
110
+ headers,
111
+ body: body ? JSON.stringify(body) : void 0,
112
+ signal: controller.signal
113
+ });
114
+ clearTimeout(timeoutId);
115
+ if (response.ok) {
116
+ const text = await response.text();
117
+ return text ? JSON.parse(text) : {};
118
+ }
119
+ const errText = await response.text();
120
+ const errJson = errText ? JSON.parse(errText) : {};
121
+ if (response.status === 401) {
122
+ throw new AuthenticationError("Authentication failed", 401, errJson);
123
+ } else if (response.status === 404) {
124
+ throw new NotFoundError("Resource not found", 404, errJson);
125
+ } else if (response.status === 400 || response.status === 422) {
126
+ throw new ValidationError("Validation error", response.status, errJson);
127
+ } else if (response.status === 429) {
128
+ if (attempt < this.maxRetries) {
129
+ const retryAfter2 = response.headers.get("Retry-After");
130
+ const delay = retryAfter2 ? parseInt(retryAfter2, 10) * 1e3 : 1e3 * Math.pow(2, attempt);
131
+ await new Promise((resolve) => setTimeout(resolve, delay));
132
+ attempt++;
133
+ continue;
134
+ }
135
+ const retryAfter = response.headers.get("Retry-After");
136
+ throw new RateLimitError("Rate limit exceeded", 429, errJson, retryAfter ? parseInt(retryAfter, 10) : void 0);
137
+ } else if (response.status >= 500) {
138
+ if (attempt < this.maxRetries) {
139
+ await new Promise((resolve) => setTimeout(resolve, 1e3 * Math.pow(2, attempt)));
140
+ attempt++;
141
+ continue;
142
+ }
143
+ throw new ServerError(`Server error: ${response.status}`, response.status, errJson);
144
+ }
145
+ throw new GSTAcceleratorError(`HTTP Error ${response.status}`, response.status, errJson);
146
+ } catch (err) {
147
+ if (err.name === "AbortError") {
148
+ if (attempt < this.maxRetries) {
149
+ await new Promise((resolve) => setTimeout(resolve, 1e3 * Math.pow(2, attempt)));
150
+ attempt++;
151
+ continue;
152
+ }
153
+ throw new GSTAcceleratorError("Request timeout", 0, {});
154
+ }
155
+ if (err instanceof GSTAcceleratorError) {
156
+ throw err;
157
+ }
158
+ if (attempt < this.maxRetries) {
159
+ await new Promise((resolve) => setTimeout(resolve, 1e3 * Math.pow(2, attempt)));
160
+ attempt++;
161
+ continue;
162
+ }
163
+ throw new GSTAcceleratorError(err.message || "Unknown error", 0, {});
164
+ }
165
+ }
166
+ throw new GSTAcceleratorError("Max retries exceeded", 0, {});
167
+ }
168
+ async lookup(description, options) {
169
+ const payload = { description };
170
+ if (options?.supplyType) payload.supply_type = options.supplyType;
171
+ if (options?.branded !== void 0) payload.branded = options.branded;
172
+ if (options?.saleValueInr !== void 0) payload.sale_value_inr = options.saleValueInr;
173
+ if (options?.stateOfSupply) payload.state_of_supply = options.stateOfSupply;
174
+ return this.request("POST", "/api/v1/lookup", payload);
175
+ }
176
+ async autocomplete(query) {
177
+ const params = new URLSearchParams({ q: query });
178
+ return this.request("GET", `/api/v1/autocomplete?${params.toString()}`);
179
+ }
180
+ async bulk(descriptions) {
181
+ return this.request("POST", "/api/v1/bulk", { descriptions });
182
+ }
183
+ async health() {
184
+ return this.request("GET", "/api/v1/health");
185
+ }
186
+ async meta() {
187
+ return this.request("GET", "/api/v1/meta");
188
+ }
189
+ };
190
+
191
+ // src/index.ts
192
+ var index_default = GSTAccelerator;
193
+ var GSTAcceleratorMCPTools = [
194
+ {
195
+ name: "hsn_lookup",
196
+ description: "Look up Indian GST rate for a specific HSN code",
197
+ input_schema: {
198
+ type: "object",
199
+ properties: {
200
+ code: { type: "string", description: "8-digit HSN code" }
201
+ },
202
+ required: ["code"]
203
+ }
204
+ },
205
+ {
206
+ name: "gst_search",
207
+ description: "Search GST HSN codes by product description",
208
+ input_schema: {
209
+ type: "object",
210
+ properties: {
211
+ description: { type: "string" },
212
+ supply_type: { type: "string", enum: ["B2B", "B2C"] },
213
+ branded: { type: "boolean" },
214
+ sale_value_inr: { type: "number" }
215
+ },
216
+ required: ["description"]
217
+ }
218
+ },
219
+ {
220
+ name: "gstin_validate",
221
+ description: "Validate an Indian GSTIN number and extract components",
222
+ input_schema: {
223
+ type: "object",
224
+ properties: {
225
+ gstin: { type: "string", description: "15-character GSTIN" }
226
+ },
227
+ required: ["gstin"]
228
+ }
229
+ }
230
+ ];
231
+
232
+ export {
233
+ GSTAcceleratorError,
234
+ AuthenticationError,
235
+ RateLimitError,
236
+ NotFoundError,
237
+ ValidationError,
238
+ ServerError,
239
+ GSTAccelerator,
240
+ index_default,
241
+ GSTAcceleratorMCPTools
242
+ };
243
+ //# sourceMappingURL=chunk-JFLL4PYR.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/client.ts","../src/errors.ts","../src/resources/hsn.ts","../src/resources/sac.ts","../src/resources/gstin.ts","../src/index.ts"],"sourcesContent":["import crossFetch from 'cross-fetch';\nimport { GSTAcceleratorConfig, LookupOptions, MetaResponse } from './types';\nimport { AuthenticationError, NotFoundError, ValidationError, RateLimitError, ServerError, GSTAcceleratorError } from './errors';\nimport { HSNClient } from './resources/hsn';\nimport { SACClient } from './resources/sac';\nimport { GSTINClient } from './resources/gstin';\n\nconst isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined';\nconst fetchImpl = typeof fetch !== 'undefined' ? fetch : crossFetch;\n\nexport class GSTAccelerator {\n private apiKey: string;\n private baseUrl: string;\n private timeout: number;\n public maxRetries: number;\n \n public hsn: HSNClient;\n public sac: SACClient;\n public gstin: GSTINClient;\n\n constructor(config: GSTAcceleratorConfig) {\n this.apiKey = config.apiKey || '';\n this.baseUrl = config.baseUrl || 'https://gstaccelerator.in';\n this.timeout = config.timeout || 30000;\n this.maxRetries = config.maxRetries ?? 3;\n \n this.hsn = new HSNClient(this);\n this.sac = new SACClient(this);\n this.gstin = new GSTINClient(this);\n }\n\n async request<T>(method: string, path: string, body?: any): Promise<T> {\n const url = `${this.baseUrl}${path}`;\n const headers: Record<string, string> = {\n 'Content-Type': 'application/json',\n 'Authorization': `Bearer ${this.apiKey}`\n };\n\n if (!isBrowser) {\n headers['User-Agent'] = `gstaccelerator-js/0.1.0`;\n }\n\n let attempt = 0;\n \n while (attempt <= this.maxRetries) {\n try {\n const controller = new AbortController();\n const timeoutId = setTimeout(() => controller.abort(), this.timeout);\n \n const response = await fetchImpl(url, {\n method,\n headers,\n body: body ? JSON.stringify(body) : undefined,\n signal: controller.signal\n });\n \n clearTimeout(timeoutId);\n\n if (response.ok) {\n const text = await response.text();\n return text ? JSON.parse(text) : {} as T;\n }\n\n const errText = await response.text();\n const errJson = errText ? JSON.parse(errText) : {};\n\n if (response.status === 401) {\n throw new AuthenticationError('Authentication failed', 401, errJson);\n } else if (response.status === 404) {\n throw new NotFoundError('Resource not found', 404, errJson);\n } else if (response.status === 400 || response.status === 422) {\n throw new ValidationError('Validation error', response.status, errJson);\n } else if (response.status === 429) {\n if (attempt < this.maxRetries) {\n const retryAfter = response.headers.get('Retry-After');\n const delay = retryAfter ? parseInt(retryAfter, 10) * 1000 : 1000 * Math.pow(2, attempt);\n await new Promise(resolve => setTimeout(resolve, delay));\n attempt++;\n continue;\n }\n const retryAfter = response.headers.get('Retry-After');\n throw new RateLimitError('Rate limit exceeded', 429, errJson, retryAfter ? parseInt(retryAfter, 10) : undefined);\n } else if (response.status >= 500) {\n if (attempt < this.maxRetries) {\n await new Promise(resolve => setTimeout(resolve, 1000 * Math.pow(2, attempt)));\n attempt++;\n continue;\n }\n throw new ServerError(`Server error: ${response.status}`, response.status, errJson);\n }\n\n throw new GSTAcceleratorError(`HTTP Error ${response.status}`, response.status, errJson);\n } catch (err: any) {\n if (err.name === 'AbortError') {\n if (attempt < this.maxRetries) {\n await new Promise(resolve => setTimeout(resolve, 1000 * Math.pow(2, attempt)));\n attempt++;\n continue;\n }\n throw new GSTAcceleratorError('Request timeout', 0, {});\n }\n \n if (err instanceof GSTAcceleratorError) {\n throw err;\n }\n\n if (attempt < this.maxRetries) {\n await new Promise(resolve => setTimeout(resolve, 1000 * Math.pow(2, attempt)));\n attempt++;\n continue;\n }\n throw new GSTAcceleratorError(err.message || 'Unknown error', 0, {});\n }\n }\n \n throw new GSTAcceleratorError('Max retries exceeded', 0, {});\n }\n\n async lookup(description: string, options?: LookupOptions): Promise<any[]> {\n const payload: any = { description };\n if (options?.supplyType) payload.supply_type = options.supplyType;\n if (options?.branded !== undefined) payload.branded = options.branded;\n if (options?.saleValueInr !== undefined) payload.sale_value_inr = options.saleValueInr;\n if (options?.stateOfSupply) payload.state_of_supply = options.stateOfSupply;\n \n return this.request<any[]>('POST', '/api/v1/lookup', payload);\n }\n\n async autocomplete(query: string): Promise<string[]> {\n const params = new URLSearchParams({ q: query });\n return this.request<string[]>('GET', `/api/v1/autocomplete?${params.toString()}`);\n }\n\n async bulk(descriptions: string[]): Promise<any[][]> {\n return this.request<any[][]>('POST', '/api/v1/bulk', { descriptions });\n }\n\n async health(): Promise<Record<string, unknown>> {\n return this.request<Record<string, unknown>>('GET', '/api/v1/health');\n }\n\n async meta(): Promise<MetaResponse> {\n return this.request<MetaResponse>('GET', '/api/v1/meta');\n }\n}\n","export class GSTAcceleratorError extends Error {\n constructor(\n message: string,\n public statusCode: number,\n public responseBody: Record<string, unknown>\n ) {\n super(message);\n this.name = 'GSTAcceleratorError';\n }\n}\n\nexport class AuthenticationError extends GSTAcceleratorError {\n constructor(message: string, statusCode: number, responseBody: Record<string, unknown>) {\n super(message, statusCode, responseBody);\n this.name = 'AuthenticationError';\n }\n}\n\nexport class RateLimitError extends GSTAcceleratorError {\n public retryAfter?: number;\n \n constructor(message: string, statusCode: number, responseBody: Record<string, unknown>, retryAfter?: number) {\n super(message, statusCode, responseBody);\n this.name = 'RateLimitError';\n this.retryAfter = retryAfter;\n }\n}\n\nexport class NotFoundError extends GSTAcceleratorError {\n constructor(message: string, statusCode: number, responseBody: Record<string, unknown>) {\n super(message, statusCode, responseBody);\n this.name = 'NotFoundError';\n }\n}\n\nexport class ValidationError extends GSTAcceleratorError {\n constructor(message: string, statusCode: number, responseBody: Record<string, unknown>) {\n super(message, statusCode, responseBody);\n this.name = 'ValidationError';\n }\n}\n\nexport class ServerError extends GSTAcceleratorError {\n constructor(message: string, statusCode: number, responseBody: Record<string, unknown>) {\n super(message, statusCode, responseBody);\n this.name = 'ServerError';\n }\n}\n","import type { GSTAccelerator } from '../client';\nimport type { HSNResult } from '../types';\n\nexport class HSNClient {\n constructor(private client: GSTAccelerator) {}\n\n async get(code: string): Promise<HSNResult> {\n return this.client.request<HSNResult>('GET', `/api/v1/hsn/${code}`);\n }\n}\n","import type { GSTAccelerator } from '../client';\n\nexport class SACClient {\n constructor(private client: GSTAccelerator) {}\n\n async get(code: string): Promise<any> {\n return this.client.request<any>('GET', `/api/v1/sac/${code}`);\n }\n}\n","import type { GSTAccelerator } from '../client';\nimport type { GSTINValidationResult } from '../types';\n\nexport class GSTINClient {\n constructor(private client: GSTAccelerator) {}\n\n async validate(gstin: string): Promise<GSTINValidationResult> {\n return this.client.request<GSTINValidationResult>('GET', `/api/v1/gstin/${gstin}/validate`);\n }\n\n async state(gstin: string): Promise<any> {\n return this.client.request<any>('GET', `/api/v1/gstin/${gstin}/state`);\n }\n\n async pan(gstin: string): Promise<any> {\n return this.client.request<any>('GET', `/api/v1/gstin/${gstin}/pan`);\n }\n}\n","import { GSTAccelerator } from './client';\n\nexport { GSTAccelerator };\nexport default GSTAccelerator;\n\nexport * from './types';\nexport * from './errors';\n\nexport const GSTAcceleratorMCPTools = [\n {\n name: \"hsn_lookup\",\n description: \"Look up Indian GST rate for a specific HSN code\",\n input_schema: {\n type: \"object\",\n properties: {\n code: { type: \"string\", description: \"8-digit HSN code\" }\n },\n required: [\"code\"]\n }\n },\n {\n name: \"gst_search\",\n description: \"Search GST HSN codes by product description\",\n input_schema: {\n type: \"object\",\n properties: {\n description: { type: \"string\" },\n supply_type: { type: \"string\", enum: [\"B2B\", \"B2C\"] },\n branded: { type: \"boolean\" },\n sale_value_inr: { type: \"number\" }\n },\n required: [\"description\"]\n }\n },\n {\n name: \"gstin_validate\",\n description: \"Validate an Indian GSTIN number and extract components\",\n input_schema: {\n type: \"object\",\n properties: {\n gstin: { type: \"string\", description: \"15-character GSTIN\" }\n },\n required: [\"gstin\"]\n }\n }\n];\n"],"mappings":";AAAA,OAAO,gBAAgB;;;ACAhB,IAAM,sBAAN,cAAkC,MAAM;AAAA,EAC7C,YACE,SACO,YACA,cACP;AACA,UAAM,OAAO;AAHN;AACA;AAGP,SAAK,OAAO;AAAA,EACd;AACF;AAEO,IAAM,sBAAN,cAAkC,oBAAoB;AAAA,EAC3D,YAAY,SAAiB,YAAoB,cAAuC;AACtF,UAAM,SAAS,YAAY,YAAY;AACvC,SAAK,OAAO;AAAA,EACd;AACF;AAEO,IAAM,iBAAN,cAA6B,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AAa;AAAA,IACb,cAAc;AAAA,MACZ,MAAM;AAAA,MACN,YAAY;AAAA,QACV,MAAM,EAAE,MAAM,UAAU,aAAa,mBAAmB;AAAA,MAC1D;AAAA,MACA,UAAU,CAAC,MAAM;AAAA,IACnB;AAAA,EACF;AAAA,EACA;AAAA,IACE,MAAM;AAAA,IACN,aAAa;AAAA,IACb,cAAc;AAAA,MACZ,MAAM;AAAA,MACN,YAAY;AAAA,QACV,aAAa,EAAE,MAAM,SAAS;AAAA,QAC9B,aAAa,EAAE,MAAM,UAAU,MAAM,CAAC,OAAO,KAAK,EAAE;AAAA,QACpD,SAAS,EAAE,MAAM,UAAU;AAAA,QAC3B,gBAAgB,EAAE,MAAM,SAAS;AAAA,MACnC;AAAA,MACA,UAAU,CAAC,aAAa;AAAA,IAC1B;AAAA,EACF;AAAA,EACA;AAAA,IACE,MAAM;AAAA,IACN,aAAa;AAAA,IACb,cAAc;AAAA,MACZ,MAAM;AAAA,MACN,YAAY;AAAA,QACV,OAAO,EAAE,MAAM,UAAU,aAAa,qBAAqB;AAAA,MAC7D;AAAA,MACA,UAAU,CAAC,OAAO;AAAA,IACpB;AAAA,EACF;AACF;","names":["retryAfter"]}
package/dist/index.mjs CHANGED
@@ -1,233 +1,14 @@
1
- // src/client.ts
2
- import crossFetch from "cross-fetch";
3
-
4
- // src/errors.ts
5
- var GSTAcceleratorError = class extends Error {
6
- constructor(message, statusCode, responseBody) {
7
- super(message);
8
- this.statusCode = statusCode;
9
- this.responseBody = responseBody;
10
- this.name = "GSTAcceleratorError";
11
- }
12
- };
13
- var AuthenticationError = class extends GSTAcceleratorError {
14
- constructor(message, statusCode, responseBody) {
15
- super(message, statusCode, responseBody);
16
- this.name = "AuthenticationError";
17
- }
18
- };
19
- var RateLimitError = class extends GSTAcceleratorError {
20
- constructor(message, statusCode, responseBody, retryAfter) {
21
- super(message, statusCode, responseBody);
22
- this.name = "RateLimitError";
23
- this.retryAfter = retryAfter;
24
- }
25
- };
26
- var NotFoundError = class extends GSTAcceleratorError {
27
- constructor(message, statusCode, responseBody) {
28
- super(message, statusCode, responseBody);
29
- this.name = "NotFoundError";
30
- }
31
- };
32
- var ValidationError = class extends GSTAcceleratorError {
33
- constructor(message, statusCode, responseBody) {
34
- super(message, statusCode, responseBody);
35
- this.name = "ValidationError";
36
- }
37
- };
38
- var ServerError = class extends GSTAcceleratorError {
39
- constructor(message, statusCode, responseBody) {
40
- super(message, statusCode, responseBody);
41
- this.name = "ServerError";
42
- }
43
- };
44
-
45
- // src/resources/hsn.ts
46
- var HSNClient = class {
47
- constructor(client) {
48
- this.client = client;
49
- }
50
- async get(code) {
51
- return this.client.request("GET", `/api/v1/hsn/${code}`);
52
- }
53
- };
54
-
55
- // src/resources/sac.ts
56
- var SACClient = class {
57
- constructor(client) {
58
- this.client = client;
59
- }
60
- async get(code) {
61
- return this.client.request("GET", `/api/v1/sac/${code}`);
62
- }
63
- };
64
-
65
- // src/resources/gstin.ts
66
- var GSTINClient = class {
67
- constructor(client) {
68
- this.client = client;
69
- }
70
- async validate(gstin) {
71
- return this.client.request("GET", `/api/v1/gstin/${gstin}/validate`);
72
- }
73
- async state(gstin) {
74
- return this.client.request("GET", `/api/v1/gstin/${gstin}/state`);
75
- }
76
- async pan(gstin) {
77
- return this.client.request("GET", `/api/v1/gstin/${gstin}/pan`);
78
- }
79
- };
80
-
81
- // src/client.ts
82
- var isBrowser = typeof window !== "undefined" && typeof window.document !== "undefined";
83
- var fetchImpl = typeof fetch !== "undefined" ? fetch : crossFetch;
84
- var GSTAccelerator = class {
85
- constructor(config) {
86
- this.apiKey = config.apiKey || "";
87
- this.baseUrl = config.baseUrl || "https://gstaccelerator.in";
88
- this.timeout = config.timeout || 3e4;
89
- this.maxRetries = config.maxRetries ?? 3;
90
- this.hsn = new HSNClient(this);
91
- this.sac = new SACClient(this);
92
- this.gstin = new GSTINClient(this);
93
- }
94
- async request(method, path, body) {
95
- const url = `${this.baseUrl}${path}`;
96
- const headers = {
97
- "Content-Type": "application/json",
98
- "Authorization": `Bearer ${this.apiKey}`
99
- };
100
- if (!isBrowser) {
101
- headers["User-Agent"] = `gstaccelerator-js/0.1.0`;
102
- }
103
- let attempt = 0;
104
- while (attempt <= this.maxRetries) {
105
- try {
106
- const controller = new AbortController();
107
- const timeoutId = setTimeout(() => controller.abort(), this.timeout);
108
- const response = await fetchImpl(url, {
109
- method,
110
- headers,
111
- body: body ? JSON.stringify(body) : void 0,
112
- signal: controller.signal
113
- });
114
- clearTimeout(timeoutId);
115
- if (response.ok) {
116
- const text = await response.text();
117
- return text ? JSON.parse(text) : {};
118
- }
119
- const errText = await response.text();
120
- const errJson = errText ? JSON.parse(errText) : {};
121
- if (response.status === 401) {
122
- throw new AuthenticationError("Authentication failed", 401, errJson);
123
- } else if (response.status === 404) {
124
- throw new NotFoundError("Resource not found", 404, errJson);
125
- } else if (response.status === 400 || response.status === 422) {
126
- throw new ValidationError("Validation error", response.status, errJson);
127
- } else if (response.status === 429) {
128
- if (attempt < this.maxRetries) {
129
- const retryAfter2 = response.headers.get("Retry-After");
130
- const delay = retryAfter2 ? parseInt(retryAfter2, 10) * 1e3 : 1e3 * Math.pow(2, attempt);
131
- await new Promise((resolve) => setTimeout(resolve, delay));
132
- attempt++;
133
- continue;
134
- }
135
- const retryAfter = response.headers.get("Retry-After");
136
- throw new RateLimitError("Rate limit exceeded", 429, errJson, retryAfter ? parseInt(retryAfter, 10) : void 0);
137
- } else if (response.status >= 500) {
138
- if (attempt < this.maxRetries) {
139
- await new Promise((resolve) => setTimeout(resolve, 1e3 * Math.pow(2, attempt)));
140
- attempt++;
141
- continue;
142
- }
143
- throw new ServerError(`Server error: ${response.status}`, response.status, errJson);
144
- }
145
- throw new GSTAcceleratorError(`HTTP Error ${response.status}`, response.status, errJson);
146
- } catch (err) {
147
- if (err.name === "AbortError") {
148
- if (attempt < this.maxRetries) {
149
- await new Promise((resolve) => setTimeout(resolve, 1e3 * Math.pow(2, attempt)));
150
- attempt++;
151
- continue;
152
- }
153
- throw new GSTAcceleratorError("Request timeout", 0, {});
154
- }
155
- if (err instanceof GSTAcceleratorError) {
156
- throw err;
157
- }
158
- if (attempt < this.maxRetries) {
159
- await new Promise((resolve) => setTimeout(resolve, 1e3 * Math.pow(2, attempt)));
160
- attempt++;
161
- continue;
162
- }
163
- throw new GSTAcceleratorError(err.message || "Unknown error", 0, {});
164
- }
165
- }
166
- throw new GSTAcceleratorError("Max retries exceeded", 0, {});
167
- }
168
- async lookup(description, options) {
169
- const payload = { description };
170
- if (options?.supplyType) payload.supply_type = options.supplyType;
171
- if (options?.branded !== void 0) payload.branded = options.branded;
172
- if (options?.saleValueInr !== void 0) payload.sale_value_inr = options.saleValueInr;
173
- if (options?.stateOfSupply) payload.state_of_supply = options.stateOfSupply;
174
- return this.request("POST", "/api/v1/lookup", payload);
175
- }
176
- async autocomplete(query) {
177
- const params = new URLSearchParams({ q: query });
178
- return this.request("GET", `/api/v1/autocomplete?${params.toString()}`);
179
- }
180
- async bulk(descriptions) {
181
- return this.request("POST", "/api/v1/bulk", { descriptions });
182
- }
183
- async health() {
184
- return this.request("GET", "/api/v1/health");
185
- }
186
- async meta() {
187
- return this.request("GET", "/api/v1/meta");
188
- }
189
- };
190
-
191
- // src/index.ts
192
- var index_default = GSTAccelerator;
193
- var GSTAcceleratorMCPTools = [
194
- {
195
- name: "hsn_lookup",
196
- description: "Look up Indian GST rate for a specific HSN code",
197
- input_schema: {
198
- type: "object",
199
- properties: {
200
- code: { type: "string", description: "8-digit HSN code" }
201
- },
202
- required: ["code"]
203
- }
204
- },
205
- {
206
- name: "gst_search",
207
- description: "Search GST HSN codes by product description",
208
- input_schema: {
209
- type: "object",
210
- properties: {
211
- description: { type: "string" },
212
- supply_type: { type: "string", enum: ["B2B", "B2C"] },
213
- branded: { type: "boolean" },
214
- sale_value_inr: { type: "number" }
215
- },
216
- required: ["description"]
217
- }
218
- },
219
- {
220
- name: "gstin_validate",
221
- description: "Validate an Indian GSTIN number and extract components",
222
- input_schema: {
223
- type: "object",
224
- properties: {
225
- gstin: { type: "string", description: "15-character GSTIN" }
226
- },
227
- required: ["gstin"]
228
- }
229
- }
230
- ];
1
+ import {
2
+ AuthenticationError,
3
+ GSTAccelerator,
4
+ GSTAcceleratorError,
5
+ GSTAcceleratorMCPTools,
6
+ NotFoundError,
7
+ RateLimitError,
8
+ ServerError,
9
+ ValidationError,
10
+ index_default
11
+ } from "./chunk-JFLL4PYR.mjs";
231
12
  export {
232
13
  AuthenticationError,
233
14
  GSTAccelerator,
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/client.ts","../src/errors.ts","../src/resources/hsn.ts","../src/resources/sac.ts","../src/resources/gstin.ts","../src/index.ts"],"sourcesContent":["import crossFetch from 'cross-fetch';\nimport { GSTAcceleratorConfig, LookupOptions, MetaResponse } from './types';\nimport { AuthenticationError, NotFoundError, ValidationError, RateLimitError, ServerError, GSTAcceleratorError } from './errors';\nimport { HSNClient } from './resources/hsn';\nimport { SACClient } from './resources/sac';\nimport { GSTINClient } from './resources/gstin';\n\nconst isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined';\nconst fetchImpl = typeof fetch !== 'undefined' ? fetch : crossFetch;\n\nexport class GSTAccelerator {\n private apiKey: string;\n private baseUrl: string;\n private timeout: number;\n public maxRetries: number;\n \n public hsn: HSNClient;\n public sac: SACClient;\n public gstin: GSTINClient;\n\n constructor(config: GSTAcceleratorConfig) {\n this.apiKey = config.apiKey || '';\n this.baseUrl = config.baseUrl || 'https://gstaccelerator.in';\n this.timeout = config.timeout || 30000;\n this.maxRetries = config.maxRetries ?? 3;\n \n this.hsn = new HSNClient(this);\n this.sac = new SACClient(this);\n this.gstin = new GSTINClient(this);\n }\n\n async request<T>(method: string, path: string, body?: any): Promise<T> {\n const url = `${this.baseUrl}${path}`;\n const headers: Record<string, string> = {\n 'Content-Type': 'application/json',\n 'Authorization': `Bearer ${this.apiKey}`\n };\n\n if (!isBrowser) {\n headers['User-Agent'] = `gstaccelerator-js/0.1.0`;\n }\n\n let attempt = 0;\n \n while (attempt <= this.maxRetries) {\n try {\n const controller = new AbortController();\n const timeoutId = setTimeout(() => controller.abort(), this.timeout);\n \n const response = await fetchImpl(url, {\n method,\n headers,\n body: body ? JSON.stringify(body) : undefined,\n signal: controller.signal\n });\n \n clearTimeout(timeoutId);\n\n if (response.ok) {\n const text = await response.text();\n return text ? JSON.parse(text) : {} as T;\n }\n\n const errText = await response.text();\n const errJson = errText ? JSON.parse(errText) : {};\n\n if (response.status === 401) {\n throw new AuthenticationError('Authentication failed', 401, errJson);\n } else if (response.status === 404) {\n throw new NotFoundError('Resource not found', 404, errJson);\n } else if (response.status === 400 || response.status === 422) {\n throw new ValidationError('Validation error', response.status, errJson);\n } else if (response.status === 429) {\n if (attempt < this.maxRetries) {\n const retryAfter = response.headers.get('Retry-After');\n const delay = retryAfter ? parseInt(retryAfter, 10) * 1000 : 1000 * Math.pow(2, attempt);\n await new Promise(resolve => setTimeout(resolve, delay));\n attempt++;\n continue;\n }\n const retryAfter = response.headers.get('Retry-After');\n throw new RateLimitError('Rate limit exceeded', 429, errJson, retryAfter ? parseInt(retryAfter, 10) : undefined);\n } else if (response.status >= 500) {\n if (attempt < this.maxRetries) {\n await new Promise(resolve => setTimeout(resolve, 1000 * Math.pow(2, attempt)));\n attempt++;\n continue;\n }\n throw new ServerError(`Server error: ${response.status}`, response.status, errJson);\n }\n\n throw new GSTAcceleratorError(`HTTP Error ${response.status}`, response.status, errJson);\n } catch (err: any) {\n if (err.name === 'AbortError') {\n if (attempt < this.maxRetries) {\n await new Promise(resolve => setTimeout(resolve, 1000 * Math.pow(2, attempt)));\n attempt++;\n continue;\n }\n throw new GSTAcceleratorError('Request timeout', 0, {});\n }\n \n if (err instanceof GSTAcceleratorError) {\n throw err;\n }\n\n if (attempt < this.maxRetries) {\n await new Promise(resolve => setTimeout(resolve, 1000 * Math.pow(2, attempt)));\n attempt++;\n continue;\n }\n throw new GSTAcceleratorError(err.message || 'Unknown error', 0, {});\n }\n }\n \n throw new GSTAcceleratorError('Max retries exceeded', 0, {});\n }\n\n async lookup(description: string, options?: LookupOptions): Promise<any[]> {\n const payload: any = { description };\n if (options?.supplyType) payload.supply_type = options.supplyType;\n if (options?.branded !== undefined) payload.branded = options.branded;\n if (options?.saleValueInr !== undefined) payload.sale_value_inr = options.saleValueInr;\n if (options?.stateOfSupply) payload.state_of_supply = options.stateOfSupply;\n \n return this.request<any[]>('POST', '/api/v1/lookup', payload);\n }\n\n async autocomplete(query: string): Promise<string[]> {\n const params = new URLSearchParams({ q: query });\n return this.request<string[]>('GET', `/api/v1/autocomplete?${params.toString()}`);\n }\n\n async bulk(descriptions: string[]): Promise<any[][]> {\n return this.request<any[][]>('POST', '/api/v1/bulk', { descriptions });\n }\n\n async health(): Promise<Record<string, unknown>> {\n return this.request<Record<string, unknown>>('GET', '/api/v1/health');\n }\n\n async meta(): Promise<MetaResponse> {\n return this.request<MetaResponse>('GET', '/api/v1/meta');\n }\n}\n","export class GSTAcceleratorError extends Error {\n constructor(\n message: string,\n public statusCode: number,\n public responseBody: Record<string, unknown>\n ) {\n super(message);\n this.name = 'GSTAcceleratorError';\n }\n}\n\nexport class AuthenticationError extends GSTAcceleratorError {\n constructor(message: string, statusCode: number, responseBody: Record<string, unknown>) {\n super(message, statusCode, responseBody);\n this.name = 'AuthenticationError';\n }\n}\n\nexport class RateLimitError extends GSTAcceleratorError {\n public retryAfter?: number;\n \n constructor(message: string, statusCode: number, responseBody: Record<string, unknown>, retryAfter?: number) {\n super(message, statusCode, responseBody);\n this.name = 'RateLimitError';\n this.retryAfter = retryAfter;\n }\n}\n\nexport class NotFoundError extends GSTAcceleratorError {\n constructor(message: string, statusCode: number, responseBody: Record<string, unknown>) {\n super(message, statusCode, responseBody);\n this.name = 'NotFoundError';\n }\n}\n\nexport class ValidationError extends GSTAcceleratorError {\n constructor(message: string, statusCode: number, responseBody: Record<string, unknown>) {\n super(message, statusCode, responseBody);\n this.name = 'ValidationError';\n }\n}\n\nexport class ServerError extends GSTAcceleratorError {\n constructor(message: string, statusCode: number, responseBody: Record<string, unknown>) {\n super(message, statusCode, responseBody);\n this.name = 'ServerError';\n }\n}\n","import type { GSTAccelerator } from '../client';\nimport type { HSNResult } from '../types';\n\nexport class HSNClient {\n constructor(private client: GSTAccelerator) {}\n\n async get(code: string): Promise<HSNResult> {\n return this.client.request<HSNResult>('GET', `/api/v1/hsn/${code}`);\n }\n}\n","import type { GSTAccelerator } from '../client';\n\nexport class SACClient {\n constructor(private client: GSTAccelerator) {}\n\n async get(code: string): Promise<any> {\n return this.client.request<any>('GET', `/api/v1/sac/${code}`);\n }\n}\n","import type { GSTAccelerator } from '../client';\nimport type { GSTINValidationResult } from '../types';\n\nexport class GSTINClient {\n constructor(private client: GSTAccelerator) {}\n\n async validate(gstin: string): Promise<GSTINValidationResult> {\n return this.client.request<GSTINValidationResult>('GET', `/api/v1/gstin/${gstin}/validate`);\n }\n\n async state(gstin: string): Promise<any> {\n return this.client.request<any>('GET', `/api/v1/gstin/${gstin}/state`);\n }\n\n async pan(gstin: string): Promise<any> {\n return this.client.request<any>('GET', `/api/v1/gstin/${gstin}/pan`);\n }\n}\n","import { GSTAccelerator } from './client';\n\nexport { GSTAccelerator };\nexport default GSTAccelerator;\n\nexport * from './types';\nexport * from './errors';\n\nexport const GSTAcceleratorMCPTools = [\n {\n name: \"hsn_lookup\",\n description: \"Look up Indian GST rate for a specific HSN code\",\n input_schema: {\n type: \"object\",\n properties: {\n code: { type: \"string\", description: \"8-digit HSN code\" }\n },\n required: [\"code\"]\n }\n },\n {\n name: \"gst_search\",\n description: \"Search GST HSN codes by product description\",\n input_schema: {\n type: \"object\",\n properties: {\n description: { type: \"string\" },\n supply_type: { type: \"string\", enum: [\"B2B\", \"B2C\"] },\n branded: { type: \"boolean\" },\n sale_value_inr: { type: \"number\" }\n },\n required: [\"description\"]\n }\n },\n {\n name: \"gstin_validate\",\n description: \"Validate an Indian GSTIN number and extract components\",\n input_schema: {\n type: \"object\",\n properties: {\n gstin: { type: \"string\", description: \"15-character GSTIN\" }\n },\n required: [\"gstin\"]\n }\n }\n];\n"],"mappings":";AAAA,OAAO,gBAAgB;;;ACAhB,IAAM,sBAAN,cAAkC,MAAM;AAAA,EAC7C,YACE,SACO,YACA,cACP;AACA,UAAM,OAAO;AAHN;AACA;AAGP,SAAK,OAAO;AAAA,EACd;AACF;AAEO,IAAM,sBAAN,cAAkC,oBAAoB;AAAA,EAC3D,YAAY,SAAiB,YAAoB,cAAuC;AACtF,UAAM,SAAS,YAAY,YAAY;AACvC,SAAK,OAAO;AAAA,EACd;AACF;AAEO,IAAM,iBAAN,cAA6B,oBAAoB;AAAA,EAGtD,YAAY,SAAiB,YAAoB,cAAuC,YAAqB;AAC3G,UAAM,SAAS,YAAY,YAAY;AACvC,SAAK,OAAO;AACZ,SAAK,aAAa;AAAA,EACpB;AACF;AAEO,IAAM,gBAAN,cAA4B,oBAAoB;AAAA,EACrD,YAAY,SAAiB,YAAoB,cAAuC;AACtF,UAAM,SAAS,YAAY,YAAY;AACvC,SAAK,OAAO;AAAA,EACd;AACF;AAEO,IAAM,kBAAN,cAA8B,oBAAoB;AAAA,EACvD,YAAY,SAAiB,YAAoB,cAAuC;AACtF,UAAM,SAAS,YAAY,YAAY;AACvC,SAAK,OAAO;AAAA,EACd;AACF;AAEO,IAAM,cAAN,cAA0B,oBAAoB;AAAA,EACnD,YAAY,SAAiB,YAAoB,cAAuC;AACtF,UAAM,SAAS,YAAY,YAAY;AACvC,SAAK,OAAO;AAAA,EACd;AACF;;;AC5CO,IAAM,YAAN,MAAgB;AAAA,EACrB,YAAoB,QAAwB;AAAxB;AAAA,EAAyB;AAAA,EAE7C,MAAM,IAAI,MAAkC;AAC1C,WAAO,KAAK,OAAO,QAAmB,OAAO,eAAe,IAAI,EAAE;AAAA,EACpE;AACF;;;ACPO,IAAM,YAAN,MAAgB;AAAA,EACrB,YAAoB,QAAwB;AAAxB;AAAA,EAAyB;AAAA,EAE7C,MAAM,I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0 +1 @@
1
+ #!/usr/bin/env node
@@ -0,0 +1,329 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
18
+ // If the importer is in node compatibility mode or this is not an ESM
19
+ // file that has been converted to a CommonJS file using a Babel-
20
+ // compatible transform (i.e. "__esModule" has not been set), then set
21
+ // "default" to the CommonJS "module.exports" for node compatibility.
22
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
23
+ mod
24
+ ));
25
+
26
+ // src/mcp-server.ts
27
+ var import_server = require("@modelcontextprotocol/sdk/server/index.js");
28
+ var import_stdio = require("@modelcontextprotocol/sdk/server/stdio.js");
29
+ var import_types = require("@modelcontextprotocol/sdk/types.js");
30
+
31
+ // src/client.ts
32
+ var import_cross_fetch = __toESM(require("cross-fetch"));
33
+
34
+ // src/errors.ts
35
+ var GSTAcceleratorError = class extends Error {
36
+ constructor(message, statusCode, responseBody) {
37
+ super(message);
38
+ this.statusCode = statusCode;
39
+ this.responseBody = responseBody;
40
+ this.name = "GSTAcceleratorError";
41
+ }
42
+ };
43
+ var AuthenticationError = class extends GSTAcceleratorError {
44
+ constructor(message, statusCode, responseBody) {
45
+ super(message, statusCode, responseBody);
46
+ this.name = "AuthenticationError";
47
+ }
48
+ };
49
+ var RateLimitError = class extends GSTAcceleratorError {
50
+ constructor(message, statusCode, responseBody, retryAfter) {
51
+ super(message, statusCode, responseBody);
52
+ this.name = "RateLimitError";
53
+ this.retryAfter = retryAfter;
54
+ }
55
+ };
56
+ var NotFoundError = class extends GSTAcceleratorError {
57
+ constructor(message, statusCode, responseBody) {
58
+ super(message, statusCode, responseBody);
59
+ this.name = "NotFoundError";
60
+ }
61
+ };
62
+ var ValidationError = class extends GSTAcceleratorError {
63
+ constructor(message, statusCode, responseBody) {
64
+ super(message, statusCode, responseBody);
65
+ this.name = "ValidationError";
66
+ }
67
+ };
68
+ var ServerError = class extends GSTAcceleratorError {
69
+ constructor(message, statusCode, responseBody) {
70
+ super(message, statusCode, responseBody);
71
+ this.name = "ServerError";
72
+ }
73
+ };
74
+
75
+ // src/resources/hsn.ts
76
+ var HSNClient = class {
77
+ constructor(client) {
78
+ this.client = client;
79
+ }
80
+ async get(code) {
81
+ return this.client.request("GET", `/api/v1/hsn/${code}`);
82
+ }
83
+ };
84
+
85
+ // src/resources/sac.ts
86
+ var SACClient = class {
87
+ constructor(client) {
88
+ this.client = client;
89
+ }
90
+ async get(code) {
91
+ return this.client.request("GET", `/api/v1/sac/${code}`);
92
+ }
93
+ };
94
+
95
+ // src/resources/gstin.ts
96
+ var GSTINClient = class {
97
+ constructor(client) {
98
+ this.client = client;
99
+ }
100
+ async validate(gstin) {
101
+ return this.client.request("GET", `/api/v1/gstin/${gstin}/validate`);
102
+ }
103
+ async state(gstin) {
104
+ return this.client.request("GET", `/api/v1/gstin/${gstin}/state`);
105
+ }
106
+ async pan(gstin) {
107
+ return this.client.request("GET", `/api/v1/gstin/${gstin}/pan`);
108
+ }
109
+ };
110
+
111
+ // src/client.ts
112
+ var isBrowser = typeof window !== "undefined" && typeof window.document !== "undefined";
113
+ var fetchImpl = typeof fetch !== "undefined" ? fetch : import_cross_fetch.default;
114
+ var GSTAccelerator = class {
115
+ constructor(config) {
116
+ this.apiKey = config.apiKey || "";
117
+ this.baseUrl = config.baseUrl || "https://gstaccelerator.in";
118
+ this.timeout = config.timeout || 3e4;
119
+ this.maxRetries = config.maxRetries ?? 3;
120
+ this.hsn = new HSNClient(this);
121
+ this.sac = new SACClient(this);
122
+ this.gstin = new GSTINClient(this);
123
+ }
124
+ async request(method, path, body) {
125
+ const url = `${this.baseUrl}${path}`;
126
+ const headers = {
127
+ "Content-Type": "application/json",
128
+ "Authorization": `Bearer ${this.apiKey}`
129
+ };
130
+ if (!isBrowser) {
131
+ headers["User-Agent"] = `gstaccelerator-js/0.1.0`;
132
+ }
133
+ let attempt = 0;
134
+ while (attempt <= this.maxRetries) {
135
+ try {
136
+ const controller = new AbortController();
137
+ const timeoutId = setTimeout(() => controller.abort(), this.timeout);
138
+ const response = await fetchImpl(url, {
139
+ method,
140
+ headers,
141
+ body: body ? JSON.stringify(body) : void 0,
142
+ signal: controller.signal
143
+ });
144
+ clearTimeout(timeoutId);
145
+ if (response.ok) {
146
+ const text = await response.text();
147
+ return text ? JSON.parse(text) : {};
148
+ }
149
+ const errText = await response.text();
150
+ const errJson = errText ? JSON.parse(errText) : {};
151
+ if (response.status === 401) {
152
+ throw new AuthenticationError("Authentication failed", 401, errJson);
153
+ } else if (response.status === 404) {
154
+ throw new NotFoundError("Resource not found", 404, errJson);
155
+ } else if (response.status === 400 || response.status === 422) {
156
+ throw new ValidationError("Validation error", response.status, errJson);
157
+ } else if (response.status === 429) {
158
+ if (attempt < this.maxRetries) {
159
+ const retryAfter2 = response.headers.get("Retry-After");
160
+ const delay = retryAfter2 ? parseInt(retryAfter2, 10) * 1e3 : 1e3 * Math.pow(2, attempt);
161
+ await new Promise((resolve) => setTimeout(resolve, delay));
162
+ attempt++;
163
+ continue;
164
+ }
165
+ const retryAfter = response.headers.get("Retry-After");
166
+ throw new RateLimitError("Rate limit exceeded", 429, errJson, retryAfter ? parseInt(retryAfter, 10) : void 0);
167
+ } else if (response.status >= 500) {
168
+ if (attempt < this.maxRetries) {
169
+ await new Promise((resolve) => setTimeout(resolve, 1e3 * Math.pow(2, attempt)));
170
+ attempt++;
171
+ continue;
172
+ }
173
+ throw new ServerError(`Server error: ${response.status}`, response.status, errJson);
174
+ }
175
+ throw new GSTAcceleratorError(`HTTP Error ${response.status}`, response.status, errJson);
176
+ } catch (err) {
177
+ if (err.name === "AbortError") {
178
+ if (attempt < this.maxRetries) {
179
+ await new Promise((resolve) => setTimeout(resolve, 1e3 * Math.pow(2, attempt)));
180
+ attempt++;
181
+ continue;
182
+ }
183
+ throw new GSTAcceleratorError("Request timeout", 0, {});
184
+ }
185
+ if (err instanceof GSTAcceleratorError) {
186
+ throw err;
187
+ }
188
+ if (attempt < this.maxRetries) {
189
+ await new Promise((resolve) => setTimeout(resolve, 1e3 * Math.pow(2, attempt)));
190
+ attempt++;
191
+ continue;
192
+ }
193
+ throw new GSTAcceleratorError(err.message || "Unknown error", 0, {});
194
+ }
195
+ }
196
+ throw new GSTAcceleratorError("Max retries exceeded", 0, {});
197
+ }
198
+ async lookup(description, options) {
199
+ const payload = { description };
200
+ if (options?.supplyType) payload.supply_type = options.supplyType;
201
+ if (options?.branded !== void 0) payload.branded = options.branded;
202
+ if (options?.saleValueInr !== void 0) payload.sale_value_inr = options.saleValueInr;
203
+ if (options?.stateOfSupply) payload.state_of_supply = options.stateOfSupply;
204
+ return this.request("POST", "/api/v1/lookup", payload);
205
+ }
206
+ async autocomplete(query) {
207
+ const params = new URLSearchParams({ q: query });
208
+ return this.request("GET", `/api/v1/autocomplete?${params.toString()}`);
209
+ }
210
+ async bulk(descriptions) {
211
+ return this.request("POST", "/api/v1/bulk", { descriptions });
212
+ }
213
+ async health() {
214
+ return this.request("GET", "/api/v1/health");
215
+ }
216
+ async meta() {
217
+ return this.request("GET", "/api/v1/meta");
218
+ }
219
+ };
220
+
221
+ // src/index.ts
222
+ var GSTAcceleratorMCPTools = [
223
+ {
224
+ name: "hsn_lookup",
225
+ description: "Look up Indian GST rate for a specific HSN code",
226
+ input_schema: {
227
+ type: "object",
228
+ properties: {
229
+ code: { type: "string", description: "8-digit HSN code" }
230
+ },
231
+ required: ["code"]
232
+ }
233
+ },
234
+ {
235
+ name: "gst_search",
236
+ description: "Search GST HSN codes by product description",
237
+ input_schema: {
238
+ type: "object",
239
+ properties: {
240
+ description: { type: "string" },
241
+ supply_type: { type: "string", enum: ["B2B", "B2C"] },
242
+ branded: { type: "boolean" },
243
+ sale_value_inr: { type: "number" }
244
+ },
245
+ required: ["description"]
246
+ }
247
+ },
248
+ {
249
+ name: "gstin_validate",
250
+ description: "Validate an Indian GSTIN number and extract components",
251
+ input_schema: {
252
+ type: "object",
253
+ properties: {
254
+ gstin: { type: "string", description: "15-character GSTIN" }
255
+ },
256
+ required: ["gstin"]
257
+ }
258
+ }
259
+ ];
260
+
261
+ // src/mcp-server.ts
262
+ var apiKey = process.env.GST_API_KEY;
263
+ if (!apiKey) {
264
+ console.error("GST_API_KEY environment variable is required to run the MCP server.");
265
+ console.error("Usage: GST_API_KEY=your_key npx gstaccelerator-mcp");
266
+ process.exit(1);
267
+ }
268
+ var gst = new GSTAccelerator({ apiKey });
269
+ var server = new import_server.Server(
270
+ {
271
+ name: "gstaccelerator-mcp",
272
+ version: "0.2.0"
273
+ },
274
+ {
275
+ capabilities: {
276
+ tools: {}
277
+ }
278
+ }
279
+ );
280
+ server.setRequestHandler(import_types.ListToolsRequestSchema, async () => {
281
+ return {
282
+ tools: GSTAcceleratorMCPTools
283
+ };
284
+ });
285
+ server.setRequestHandler(import_types.CallToolRequestSchema, async (request) => {
286
+ try {
287
+ const { name, arguments: args } = request.params;
288
+ if (name === "hsn_lookup") {
289
+ const code = String(args?.code);
290
+ const result = await gst.hsn.get(code);
291
+ return {
292
+ content: [{ type: "text", text: JSON.stringify(result, null, 2) }]
293
+ };
294
+ }
295
+ if (name === "gst_search") {
296
+ const result = await gst.lookup(String(args?.description), {
297
+ supplyType: args?.supply_type,
298
+ branded: args?.branded,
299
+ saleValueInr: args?.sale_value_inr
300
+ });
301
+ return {
302
+ content: [{ type: "text", text: JSON.stringify(result, null, 2) }]
303
+ };
304
+ }
305
+ if (name === "gstin_validate") {
306
+ const gstin = String(args?.gstin);
307
+ const result = await gst.gstin.validate(gstin);
308
+ return {
309
+ content: [{ type: "text", text: JSON.stringify(result, null, 2) }]
310
+ };
311
+ }
312
+ throw new Error(`Unknown tool: ${name}`);
313
+ } catch (error) {
314
+ return {
315
+ content: [{ type: "text", text: `Error: ${error.message}` }],
316
+ isError: true
317
+ };
318
+ }
319
+ });
320
+ async function run() {
321
+ const transport = new import_stdio.StdioServerTransport();
322
+ await server.connect(transport);
323
+ console.error("GST Accelerator MCP Server running on stdio");
324
+ }
325
+ run().catch((error) => {
326
+ console.error("Fatal error running MCP server:", error);
327
+ process.exit(1);
328
+ });
329
+ //# sourceMappingURL=mcp-server.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/mcp-server.ts","../src/client.ts","../src/errors.ts","../src/resources/hsn.ts","../src/resources/sac.ts","../src/resources/gstin.ts","../src/index.ts"],"sourcesContent":["#!/usr/bin/env node\nimport { Server } from \"@modelcontextprotocol/sdk/server/index.js\";\nimport { StdioServerTransport } from \"@modelcontextprotocol/sdk/server/stdio.js\";\nimport { CallToolRequestSchema, ListToolsRequestSchema } from \"@modelcontextprotocol/sdk/types.js\";\nimport { GSTAccelerator } from \"./client\";\nimport { GSTAcceleratorMCPTools } from \"./index\";\n\nconst apiKey = process.env.GST_API_KEY;\n\nif (!apiKey) {\n console.error(\"GST_API_KEY environment variable is required to run the MCP server.\");\n console.error(\"Usage: GST_API_KEY=your_key npx gstaccelerator-mcp\");\n process.exit(1);\n}\n\nconst gst = new GSTAccelerator({ apiKey });\n\nconst server = new Server(\n {\n name: \"gstaccelerator-mcp\",\n version: \"0.2.0\",\n },\n {\n capabilities: {\n tools: {},\n },\n }\n);\n\nserver.setRequestHandler(ListToolsRequestSchema, async () => {\n return {\n tools: GSTAcceleratorMCPTools,\n };\n});\n\nserver.setRequestHandler(CallToolRequestSchema, async (request) => {\n try {\n const { name, arguments: args } = request.params;\n \n if (name === \"hsn_lookup\") {\n const code = String(args?.code);\n const result = await gst.hsn.get(code);\n return {\n content: [{ type: \"text\", text: JSON.stringify(result, null, 2) }],\n };\n }\n \n if (name === \"gst_search\") {\n const result = await gst.lookup(String(args?.description), {\n supplyType: args?.supply_type as any,\n branded: args?.branded as any,\n saleValueInr: args?.sale_value_inr as any,\n });\n return {\n content: [{ type: \"text\", text: JSON.stringify(result, null, 2) }],\n };\n }\n \n if (name === \"gstin_validate\") {\n const gstin = String(args?.gstin);\n const result = await gst.gstin.validate(gstin);\n return {\n content: [{ type: \"text\", text: JSON.stringify(result, null, 2) }],\n };\n }\n \n throw new Error(`Unknown tool: ${name}`);\n } catch (error: any) {\n return {\n content: [{ type: \"text\", text: `Error: ${error.message}` }],\n isError: true,\n };\n }\n});\n\nasync function run() {\n const transport = new StdioServerTransport();\n await server.connect(transport);\n console.error(\"GST Accelerator MCP Server running on stdio\");\n}\n\nrun().catch((error) => {\n console.error(\"Fatal error running MCP server:\", error);\n process.exit(1);\n});\n","import crossFetch from 'cross-fetch';\nimport { GSTAcceleratorConfig, LookupOptions, MetaResponse } from './types';\nimport { AuthenticationError, NotFoundError, ValidationError, RateLimitError, ServerError, GSTAcceleratorError } from './errors';\nimport { HSNClient } from './resources/hsn';\nimport { SACClient } from './resources/sac';\nimport { GSTINClient } from './resources/gstin';\n\nconst isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined';\nconst fetchImpl = typeof fetch !== 'undefined' ? fetch : crossFetch;\n\nexport class GSTAccelerator {\n private apiKey: string;\n private baseUrl: string;\n private timeout: number;\n public maxRetries: number;\n \n public hsn: HSNClient;\n public sac: SACClient;\n public gstin: GSTINClient;\n\n constructor(config: GSTAcceleratorConfig) {\n this.apiKey = config.apiKey || '';\n this.baseUrl = config.baseUrl || 'https://gstaccelerator.in';\n this.timeout = config.timeout || 30000;\n this.maxRetries = config.maxRetries ?? 3;\n \n this.hsn = new HSNClient(this);\n this.sac = new SACClient(this);\n this.gstin = new GSTINClient(this);\n }\n\n async request<T>(method: string, path: string, body?: any): Promise<T> {\n const url = `${this.baseUrl}${path}`;\n const headers: Record<string, string> = {\n 'Content-Type': 'application/json',\n 'Authorization': `Bearer ${this.apiKey}`\n };\n\n if (!isBrowser) {\n headers['User-Agent'] = `gstaccelerator-js/0.1.0`;\n }\n\n let attempt = 0;\n \n while (attempt <= this.maxRetries) {\n try {\n const controller = new AbortController();\n const timeoutId = setTimeout(() => controller.abort(), this.timeout);\n \n const response = await fetchImpl(url, {\n method,\n headers,\n body: body ? JSON.stringify(body) : undefined,\n signal: controller.signal\n });\n \n clearTimeout(timeoutId);\n\n if (response.ok) {\n const text = await response.text();\n return text ? JSON.parse(text) : {} as T;\n }\n\n const errText = await response.text();\n const errJson = errText ? JSON.parse(errText) : {};\n\n if (response.status === 401) {\n throw new AuthenticationError('Authentication failed', 401, errJson);\n } else if (response.status === 404) {\n throw new NotFoundError('Resource not found', 404, errJson);\n } else if (response.status === 400 || response.status === 422) {\n throw new ValidationError('Validation error', response.status, errJson);\n } else if (response.status === 429) {\n if (attempt < this.maxRetries) {\n const retryAfter = response.headers.get('Retry-After');\n const delay = retryAfter ? parseInt(retryAfter, 10) * 1000 : 1000 * Math.pow(2, attempt);\n await new Promise(resolve => setTimeout(resolve, delay));\n attempt++;\n continue;\n }\n const retryAfter = response.headers.get('Retry-After');\n throw new RateLimitError('Rate limit exceeded', 429, errJson, retryAfter ? parseInt(retryAfter, 10) : undefined);\n } else if (response.status >= 500) {\n if (attempt < this.maxRetries) {\n await new Promise(resolve => setTimeout(resolve, 1000 * Math.pow(2, attempt)));\n attempt++;\n continue;\n }\n throw new ServerError(`Server error: ${response.status}`, response.status, errJson);\n }\n\n throw new GSTAcceleratorError(`HTTP Error ${response.status}`, response.status, errJson);\n } catch (err: any) {\n if (err.name === 'AbortError') {\n if (attempt < this.maxRetries) {\n await new Promise(resolve => setTimeout(resolve, 1000 * Math.pow(2, attempt)));\n attempt++;\n continue;\n }\n throw new GSTAcceleratorError('Request timeout', 0, {});\n }\n \n if (err instanceof GSTAcceleratorError) {\n throw err;\n }\n\n if (attempt < this.maxRetries) {\n await new Promise(resolve => setTimeout(resolve, 1000 * Math.pow(2, attempt)));\n attempt++;\n continue;\n }\n throw new GSTAcceleratorError(err.message || 'Unknown error', 0, {});\n }\n }\n \n throw new GSTAcceleratorError('Max retries exceeded', 0, {});\n }\n\n async lookup(description: string, options?: LookupOptions): Promise<any[]> {\n const payload: any = { description };\n if (options?.supplyType) payload.supply_type = options.supplyType;\n if (options?.branded !== undefined) payload.branded = options.branded;\n if (options?.saleValueInr !== undefined) payload.sale_value_inr = options.saleValueInr;\n if (options?.stateOfSupply) payload.state_of_supply = options.stateOfSupply;\n \n return this.request<any[]>('POST', '/api/v1/lookup', payload);\n }\n\n async autocomplete(query: string): Promise<string[]> {\n const params = new URLSearchParams({ q: query });\n return this.request<string[]>('GET', `/api/v1/autocomplete?${params.toString()}`);\n }\n\n async bulk(descriptions: string[]): Promise<any[][]> {\n return this.request<any[][]>('POST', '/api/v1/bulk', { descriptions });\n }\n\n async health(): Promise<Record<string, unknown>> {\n return this.request<Record<string, unknown>>('GET', '/api/v1/health');\n }\n\n async meta(): Promise<MetaResponse> {\n return this.request<MetaResponse>('GET', '/api/v1/meta');\n }\n}\n","export class GSTAcceleratorError extends Error {\n constructor(\n message: string,\n public statusCode: number,\n public responseBody: Record<string, unknown>\n ) {\n super(message);\n this.name = 'GSTAcceleratorError';\n }\n}\n\nexport class AuthenticationError extends GSTAcceleratorError {\n constructor(message: string, statusCode: number, responseBody: Record<string, unknown>) {\n super(message, statusCode, responseBody);\n this.name = 'AuthenticationError';\n }\n}\n\nexport class RateLimitError extends GSTAcceleratorError {\n public retryAfter?: number;\n \n constructor(message: string, statusCode: number, responseBody: Record<string, unknown>, retryAfter?: number) {\n super(message, statusCode, responseBody);\n this.name = 'RateLimitError';\n this.retryAfter = retryAfter;\n }\n}\n\nexport class NotFoundError extends GSTAcceleratorError {\n constructor(message: string, statusCode: number, responseBody: Record<string, unknown>) {\n super(message, statusCode, responseBody);\n this.name = 'NotFoundError';\n }\n}\n\nexport class ValidationError extends GSTAcceleratorError {\n constructor(message: string, statusCode: number, responseBody: Record<string, unknown>) {\n super(message, statusCode, responseBody);\n this.name = 'ValidationError';\n }\n}\n\nexport class ServerError extends GSTAcceleratorError {\n constructor(message: string, statusCode: number, responseBody: Record<string, unknown>) {\n super(message, statusCode, responseBody);\n this.name = 'ServerError';\n }\n}\n","import type { GSTAccelerator } from '../client';\nimport type { HSNResult } from '../types';\n\nexport class HSNClient {\n constructor(private client: GSTAccelerator) {}\n\n async get(code: string): Promise<HSNResult> {\n return this.client.request<HSNResult>('GET', `/api/v1/hsn/${code}`);\n }\n}\n","import type { GSTAccelerator } from '../client';\n\nexport class SACClient {\n constructor(private client: GSTAccelerator) {}\n\n async get(code: string): Promise<any> {\n return this.client.request<any>('GET', `/api/v1/sac/${code}`);\n }\n}\n","import type { GSTAccelerator } from '../client';\nimport type { GSTINValidationResult } from '../types';\n\nexport class GSTINClient {\n constructor(private client: GSTAccelerator) {}\n\n async validate(gstin: string): Promise<GSTINValidationResult> {\n return this.client.request<GSTINValidationResult>('GET', `/api/v1/gstin/${gstin}/validate`);\n }\n\n async state(gstin: string): Promise<any> {\n return this.client.request<any>('GET', `/api/v1/gstin/${gstin}/state`);\n }\n\n async pan(gstin: string): Promise<any> {\n return this.client.request<any>('GET', `/api/v1/gstin/${gstin}/pan`);\n }\n}\n","import { GSTAccelerator } from './client';\n\nexport { GSTAccelerator };\nexport default GSTAccelerator;\n\nexport * from './types';\nexport * from './errors';\n\nexport const GSTAcceleratorMCPTools = [\n {\n name: \"hsn_lookup\",\n description: \"Look up Indian GST rate for a specific HSN code\",\n input_schema: {\n type: \"object\",\n properties: {\n code: { type: \"string\", description: \"8-digit HSN code\" }\n },\n required: [\"code\"]\n }\n },\n {\n name: \"gst_search\",\n description: \"Search GST HSN codes by product description\",\n input_schema: {\n type: \"object\",\n properties: {\n description: { type: \"string\" },\n supply_type: { type: \"string\", enum: [\"B2B\", \"B2C\"] },\n branded: { type: \"boolean\" },\n sale_value_inr: { type: \"number\" }\n },\n required: [\"description\"]\n }\n },\n {\n name: \"gstin_validate\",\n description: \"Validate an Indian GSTIN number and extract components\",\n input_schema: {\n type: \"object\",\n properties: {\n gstin: { type: \"string\", description: \"15-character GSTIN\" }\n },\n required: [\"gstin\"]\n }\n }\n];\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AACA,oBAAuB;AACvB,mBAAqC;AACrC,mBAA8D;;;ACH9D,yBAAuB;;;ACAhB,IAAM,sBAAN,cAAkC,MAAM;AAAA,EAC7C,YACE,SACO,YACA,cACP;AACA,UAAM,OAAO;AAHN;AACA;AAGP,SAAK,OAAO;AAAA,EACd;AACF;AAEO,IAAM,sBAAN,cAAkC,oBAAoB;AAAA,EAC3D,YAAY,SAAiB,YAAoB,cAAuC;AACtF,UAAM,SAAS,YAAY,YAAY;AACvC,SAAK,OAAO;AAAA,EACd;AACF;AAEO,IAAM,iBAAN,cAA6B,oBAAoB;AAAA,EAGtD,YAAY,SAAiB,YAAoB,cAAuC,YAAqB;AAC3G,UAAM,SAAS,YAAY,YAAY;AACvC,SAAK,OAAO;AACZ,SAAK,aAAa;AAAA,EACpB;AACF;AAEO,IAAM,gBAAN,cAA4B,oBAAoB;AAAA,EACrD,YAAY,SAAiB,YAAoB,cAAuC;AACtF,UAAM,SAAS,YAAY,YAAY;AACvC,SAAK,OAAO;AAAA,EACd;AACF;AAEO,IAAM,kBAAN,cAA8B,oBAAoB;AAAA,EACvD,YAAY,SAAiB,YAAoB,cAAuC;AACtF,UAAM,SAAS,YAAY,YAAY;AACvC,SAAK,OAAO;AAAA,EACd;AACF;AAEO,IAAM,cAAN,cAA0B,oBAAoB;AAAA,EACnD,YAAY,SAAiB,YAAoB,cAAuC;AACtF,U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UAAU,QAAQ,MAAM,CAAC,EAAE,CAAC;AAAA,MACnE;AAAA,IACF;AAEA,QAAI,SAAS,kBAAkB;AAC7B,YAAM,QAAQ,OAAO,MAAM,KAAK;AAChC,YAAM,SAAS,MAAM,IAAI,MAAM,SAAS,KAAK;AAC7C,aAAO;AAAA,QACL,SAAS,CAAC,EAAE,MAAM,QAAQ,MAAM,KAAK,UAAU,QAAQ,MAAM,CAAC,EAAE,CAAC;AAAA,MACnE;AAAA,IACF;AAEA,UAAM,IAAI,MAAM,iBAAiB,IAAI,EAAE;AAAA,EACzC,SAAS,OAAY;AACnB,WAAO;AAAA,MACL,SAAS,CAAC,EAAE,MAAM,QAAQ,MAAM,UAAU,MAAM,OAAO,GAAG,CAAC;AAAA,MAC3D,SAAS;AAAA,IACX;AAAA,EACF;AACF,CAAC;AAED,eAAe,MAAM;AACnB,QAAM,YAAY,IAAI,kCAAqB;AAC3C,QAAM,OAAO,QAAQ,SAAS;AAC9B,UAAQ,MAAM,6CAA6C;AAC7D;AAEA,IAAI,EAAE,MAAM,CAAC,UAAU;AACrB,UAAQ,MAAM,mCAAmC,KAAK;AACtD,UAAQ,KAAK,CAAC;AAChB,CAAC;","names":["crossFetch","retryAfter"]}
@@ -0,0 +1,78 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ GSTAccelerator,
4
+ GSTAcceleratorMCPTools
5
+ } from "./chunk-JFLL4PYR.mjs";
6
+
7
+ // src/mcp-server.ts
8
+ import { Server } from "@modelcontextprotocol/sdk/server/index.js";
9
+ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
10
+ import { CallToolRequestSchema, ListToolsRequestSchema } from "@modelcontextprotocol/sdk/types.js";
11
+ var apiKey = process.env.GST_API_KEY;
12
+ if (!apiKey) {
13
+ console.error("GST_API_KEY environment variable is required to run the MCP server.");
14
+ console.error("Usage: GST_API_KEY=your_key npx gstaccelerator-mcp");
15
+ process.exit(1);
16
+ }
17
+ var gst = new GSTAccelerator({ apiKey });
18
+ var server = new Server(
19
+ {
20
+ name: "gstaccelerator-mcp",
21
+ version: "0.2.0"
22
+ },
23
+ {
24
+ capabilities: {
25
+ tools: {}
26
+ }
27
+ }
28
+ );
29
+ server.setRequestHandler(ListToolsRequestSchema, async () => {
30
+ return {
31
+ tools: GSTAcceleratorMCPTools
32
+ };
33
+ });
34
+ server.setRequestHandler(CallToolRequestSchema, async (request) => {
35
+ try {
36
+ const { name, arguments: args } = request.params;
37
+ if (name === "hsn_lookup") {
38
+ const code = String(args?.code);
39
+ const result = await gst.hsn.get(code);
40
+ return {
41
+ content: [{ type: "text", text: JSON.stringify(result, null, 2) }]
42
+ };
43
+ }
44
+ if (name === "gst_search") {
45
+ const result = await gst.lookup(String(args?.description), {
46
+ supplyType: args?.supply_type,
47
+ branded: args?.branded,
48
+ saleValueInr: args?.sale_value_inr
49
+ });
50
+ return {
51
+ content: [{ type: "text", text: JSON.stringify(result, null, 2) }]
52
+ };
53
+ }
54
+ if (name === "gstin_validate") {
55
+ const gstin = String(args?.gstin);
56
+ const result = await gst.gstin.validate(gstin);
57
+ return {
58
+ content: [{ type: "text", text: JSON.stringify(result, null, 2) }]
59
+ };
60
+ }
61
+ throw new Error(`Unknown tool: ${name}`);
62
+ } catch (error) {
63
+ return {
64
+ content: [{ type: "text", text: `Error: ${error.message}` }],
65
+ isError: true
66
+ };
67
+ }
68
+ });
69
+ async function run() {
70
+ const transport = new StdioServerTransport();
71
+ await server.connect(transport);
72
+ console.error("GST Accelerator MCP Server running on stdio");
73
+ }
74
+ run().catch((error) => {
75
+ console.error("Fatal error running MCP server:", error);
76
+ process.exit(1);
77
+ });
78
+ //# sourceMappingURL=mcp-server.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/mcp-server.ts"],"sourcesContent":["#!/usr/bin/env node\nimport { Server } from \"@modelcontextprotocol/sdk/server/index.js\";\nimport { StdioServerTransport } from \"@modelcontextprotocol/sdk/server/stdio.js\";\nimport { CallToolRequestSchema, ListToolsRequestSchema } from \"@modelcontextprotocol/sdk/types.js\";\nimport { GSTAccelerator } from \"./client\";\nimport { GSTAcceleratorMCPTools } from \"./index\";\n\nconst apiKey = process.env.GST_API_KEY;\n\nif (!apiKey) {\n console.error(\"GST_API_KEY environment variable is required to run the MCP server.\");\n console.error(\"Usage: GST_API_KEY=your_key npx gstaccelerator-mcp\");\n process.exit(1);\n}\n\nconst gst = new GSTAccelerator({ apiKey });\n\nconst server = new Server(\n {\n name: \"gstaccelerator-mcp\",\n version: \"0.2.0\",\n },\n {\n capabilities: {\n tools: {},\n },\n }\n);\n\nserver.setRequestHandler(ListToolsRequestSchema, async () => {\n return {\n tools: GSTAcceleratorMCPTools,\n };\n});\n\nserver.setRequestHandler(CallToolRequestSchema, async (request) => {\n try {\n const { name, arguments: args } = request.params;\n \n if (name === \"hsn_lookup\") {\n const code = String(args?.code);\n const result = await gst.hsn.get(code);\n return {\n content: [{ type: \"text\", text: JSON.stringify(result, null, 2) }],\n };\n }\n \n if (name === \"gst_search\") {\n const result = await gst.lookup(String(args?.description), {\n supplyType: args?.supply_type as any,\n branded: args?.branded as any,\n saleValueInr: args?.sale_value_inr as any,\n });\n return {\n content: [{ type: \"text\", text: JSON.stringify(result, null, 2) }],\n };\n }\n \n if (name === \"gstin_validate\") {\n const gstin = String(args?.gstin);\n const result = await gst.gstin.validate(gstin);\n return {\n content: [{ type: \"text\", text: JSON.stringify(result, null, 2) }],\n };\n }\n \n throw new Error(`Unknown tool: ${name}`);\n } catch (error: any) {\n return {\n content: [{ type: \"text\", text: `Error: ${error.message}` }],\n isError: true,\n };\n }\n});\n\nasync function run() {\n const transport = new StdioServerTransport();\n await server.connect(transport);\n console.error(\"GST Accelerator MCP Server running on stdio\");\n}\n\nrun().catch((error) => {\n console.error(\"Fatal error running MCP server:\", error);\n process.exit(1);\n});\n"],"mappings":";;;;;;;AACA,SAAS,cAAc;AACvB,SAAS,4BAA4B;AACrC,SAAS,uBAAuB,8BAA8B;AAI9D,IAAM,S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M,KAAK,UAAU,QAAQ,MAAM,CAAC,EAAE,CAAC;AAAA,MACnE;AAAA,IACF;AAEA,UAAM,IAAI,MAAM,iBAAiB,IAAI,EAAE;AAAA,EACzC,SAAS,OAAY;AACnB,WAAO;AAAA,MACL,SAAS,CAAC,EAAE,MAAM,QAAQ,MAAM,UAAU,MAAM,OAAO,GAAG,CAAC;AAAA,MAC3D,SAAS;AAAA,IACX;AAAA,EACF;AACF,CAAC;AAED,eAAe,MAAM;AACnB,QAAM,YAAY,IAAI,qBAAqB;AAC3C,QAAM,OAAO,QAAQ,SAAS;AAC9B,UAAQ,MAAM,6CAA6C;AAC7D;AAEA,IAAI,EAAE,MAAM,CAAC,UAAU;AACrB,UAAQ,MAAM,mCAAmC,KAAK;AACtD,UAAQ,KAAK,CAAC;AAChB,CAAC;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gstaccelerator",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "JavaScript client for the GST Accelerator API — India GST HSN/SAC lookup, GSTIN validation",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -38,10 +38,15 @@
38
38
  "build": "tsup"
39
39
  },
40
40
  "devDependencies": {
41
+ "@types/node": "^26.1.1",
41
42
  "tsup": "^8.0.0",
42
43
  "typescript": "^5.0.0"
43
44
  },
44
45
  "dependencies": {
46
+ "@modelcontextprotocol/sdk": "^1.29.0",
45
47
  "cross-fetch": "^4.0.0"
48
+ },
49
+ "bin": {
50
+ "gstaccelerator-mcp": "./dist/mcp-server.js"
46
51
  }
47
52
  }