krx-cli 1.6.0 → 1.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/SKILL.md +35 -1
- package/dist/cli.js +59 -20
- package/dist/cli.js.map +4 -4
- package/dist/mcp.js +49 -19
- package/dist/mcp.js.map +4 -4
- package/package.json +1 -1
package/dist/mcp.js
CHANGED
|
@@ -31157,12 +31157,51 @@ function applyPipeline(data, options) {
|
|
|
31157
31157
|
if (options.sort) {
|
|
31158
31158
|
result = sortData(result, options.sort, options.direction ?? "desc");
|
|
31159
31159
|
}
|
|
31160
|
+
if (options.offset !== void 0 && options.offset > 0) {
|
|
31161
|
+
result = result.slice(options.offset);
|
|
31162
|
+
}
|
|
31160
31163
|
if (options.limit && options.limit > 0) {
|
|
31161
31164
|
result = limitData(result, options.limit);
|
|
31162
31165
|
}
|
|
31163
31166
|
return result;
|
|
31164
31167
|
}
|
|
31165
31168
|
|
|
31169
|
+
// src/mcp/tools/result.ts
|
|
31170
|
+
var MAX_RESULT_BYTES = 5e5;
|
|
31171
|
+
function successResult(data) {
|
|
31172
|
+
const text = JSON.stringify(data, null, 2);
|
|
31173
|
+
if (Buffer.byteLength(text, "utf-8") <= MAX_RESULT_BYTES) {
|
|
31174
|
+
return { content: [{ type: "text", text }] };
|
|
31175
|
+
}
|
|
31176
|
+
let lo = 0;
|
|
31177
|
+
let hi = data.length;
|
|
31178
|
+
while (lo < hi) {
|
|
31179
|
+
const mid = Math.ceil((lo + hi) / 2);
|
|
31180
|
+
const candidate = JSON.stringify(data.slice(0, mid), null, 2);
|
|
31181
|
+
if (Buffer.byteLength(candidate, "utf-8") <= MAX_RESULT_BYTES - 2e3) {
|
|
31182
|
+
lo = mid;
|
|
31183
|
+
} else {
|
|
31184
|
+
hi = mid - 1;
|
|
31185
|
+
}
|
|
31186
|
+
}
|
|
31187
|
+
const truncated = data.slice(0, lo);
|
|
31188
|
+
const result = {
|
|
31189
|
+
data: truncated,
|
|
31190
|
+
_truncated: {
|
|
31191
|
+
total: data.length,
|
|
31192
|
+
returned: lo,
|
|
31193
|
+
message: `Result truncated: ${lo} of ${data.length} rows returned. To get remaining rows, use offset=${lo} with limit=${lo}. Or use 'fields' to reduce row size.`
|
|
31194
|
+
}
|
|
31195
|
+
};
|
|
31196
|
+
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
31197
|
+
}
|
|
31198
|
+
function errorResult(message) {
|
|
31199
|
+
return {
|
|
31200
|
+
content: [{ type: "text", text: JSON.stringify({ error: message }) }],
|
|
31201
|
+
isError: true
|
|
31202
|
+
};
|
|
31203
|
+
}
|
|
31204
|
+
|
|
31166
31205
|
// src/mcp/tools/index.ts
|
|
31167
31206
|
function getEndpointShortName(path5) {
|
|
31168
31207
|
return path5.split("/").pop() ?? path5;
|
|
@@ -31182,7 +31221,9 @@ Notes:
|
|
|
31182
31221
|
- Date format: YYYYMMDD (e.g., 20260310)
|
|
31183
31222
|
- Data is T-1 (previous trading day)
|
|
31184
31223
|
- All response values are strings
|
|
31185
|
-
- Rate limit: 10,000 calls/day
|
|
31224
|
+
- Rate limit: 10,000 calls/day
|
|
31225
|
+
- IMPORTANT: When querying a specific stock, ALWAYS pass 'isuCd' to filter. Without it, all stocks in the market are returned.
|
|
31226
|
+
- Full market listings can exceed the result size limit. Use 'fields' to select only needed columns, or 'limit'+'offset' for pagination. If the response contains '_truncated', follow its instructions to retrieve remaining data.`;
|
|
31186
31227
|
}
|
|
31187
31228
|
function buildInputSchema(endpoints) {
|
|
31188
31229
|
const shortNames = endpoints.map((e) => getEndpointShortName(e.path));
|
|
@@ -31200,6 +31241,7 @@ function buildInputSchema(endpoints) {
|
|
|
31200
31241
|
isuCd: external_exports.string().optional().describe("Stock/item code (ISU_CD) to filter a specific item"),
|
|
31201
31242
|
sort: external_exports.string().optional().describe("Sort results by this field name"),
|
|
31202
31243
|
sort_direction: external_exports.enum(["asc", "desc"]).optional().describe("Sort direction (default: desc)"),
|
|
31244
|
+
offset: external_exports.number().optional().describe("Skip first N results (use with limit for pagination)"),
|
|
31203
31245
|
limit: external_exports.number().optional().describe("Limit number of results returned"),
|
|
31204
31246
|
filter: external_exports.string().optional().describe(
|
|
31205
31247
|
'Filter expression (e.g. "FLUC_RT > 5", "MKT_NM == KOSPI"). Operators: >, <, >=, <=, ==, !='
|
|
@@ -31222,14 +31264,6 @@ function filterFields(data, fields) {
|
|
|
31222
31264
|
return filtered;
|
|
31223
31265
|
});
|
|
31224
31266
|
}
|
|
31225
|
-
function errorResult(message) {
|
|
31226
|
-
return {
|
|
31227
|
-
content: [
|
|
31228
|
-
{ type: "text", text: JSON.stringify({ error: message }) }
|
|
31229
|
-
],
|
|
31230
|
-
isError: true
|
|
31231
|
-
};
|
|
31232
|
-
}
|
|
31233
31267
|
function createCategoryTool(categoryId) {
|
|
31234
31268
|
const endpoints = ENDPOINTS.filter((e) => e.category === categoryId);
|
|
31235
31269
|
return {
|
|
@@ -31286,22 +31320,20 @@ function createCategoryTool(categoryId) {
|
|
|
31286
31320
|
const filterExpr = args.filter;
|
|
31287
31321
|
const sortField2 = args.sort;
|
|
31288
31322
|
const sortDirection2 = args.sort_direction ?? "desc";
|
|
31323
|
+
const offsetN2 = args.offset;
|
|
31289
31324
|
const limitN2 = args.limit;
|
|
31290
31325
|
data2 = applyPipeline(data2, {
|
|
31291
31326
|
filter: filterExpr,
|
|
31292
31327
|
sort: sortField2,
|
|
31293
31328
|
direction: sortDirection2,
|
|
31329
|
+
offset: offsetN2,
|
|
31294
31330
|
limit: limitN2
|
|
31295
31331
|
});
|
|
31296
31332
|
const fields2 = args.fields;
|
|
31297
31333
|
if (fields2) {
|
|
31298
31334
|
data2 = filterFields(data2, fields2);
|
|
31299
31335
|
}
|
|
31300
|
-
return
|
|
31301
|
-
content: [
|
|
31302
|
-
{ type: "text", text: JSON.stringify(data2, null, 2) }
|
|
31303
|
-
]
|
|
31304
|
-
};
|
|
31336
|
+
return successResult(data2);
|
|
31305
31337
|
}
|
|
31306
31338
|
const dateStr = args.date ?? getRecentTradingDate();
|
|
31307
31339
|
try {
|
|
@@ -31326,23 +31358,21 @@ function createCategoryTool(categoryId) {
|
|
|
31326
31358
|
const filterExpr2 = args.filter;
|
|
31327
31359
|
const sortField = args.sort;
|
|
31328
31360
|
const sortDirection = args.sort_direction ?? "desc";
|
|
31361
|
+
const offsetN = args.offset;
|
|
31329
31362
|
const limitN = args.limit;
|
|
31330
31363
|
let data = result.data;
|
|
31331
31364
|
data = applyPipeline(data, {
|
|
31332
31365
|
filter: filterExpr2,
|
|
31333
31366
|
sort: sortField,
|
|
31334
31367
|
direction: sortDirection,
|
|
31368
|
+
offset: offsetN,
|
|
31335
31369
|
limit: limitN
|
|
31336
31370
|
});
|
|
31337
31371
|
const fields = args.fields;
|
|
31338
31372
|
if (fields) {
|
|
31339
31373
|
data = filterFields(data, fields);
|
|
31340
31374
|
}
|
|
31341
|
-
return
|
|
31342
|
-
content: [
|
|
31343
|
-
{ type: "text", text: JSON.stringify(data, null, 2) }
|
|
31344
|
-
]
|
|
31345
|
-
};
|
|
31375
|
+
return successResult(data);
|
|
31346
31376
|
}
|
|
31347
31377
|
};
|
|
31348
31378
|
}
|