krx-cli 1.5.0 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +22 -17
- package/SKILL.md +43 -1
- package/dist/cli.js +55382 -13176
- package/dist/cli.js.map +4 -4
- package/dist/mcp.js +48 -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 && 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 = 9e5;
|
|
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 - 200) {
|
|
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,8 @@ 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: Full market listings can exceed the 1MB result 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
31226
|
}
|
|
31187
31227
|
function buildInputSchema(endpoints) {
|
|
31188
31228
|
const shortNames = endpoints.map((e) => getEndpointShortName(e.path));
|
|
@@ -31200,6 +31240,7 @@ function buildInputSchema(endpoints) {
|
|
|
31200
31240
|
isuCd: external_exports.string().optional().describe("Stock/item code (ISU_CD) to filter a specific item"),
|
|
31201
31241
|
sort: external_exports.string().optional().describe("Sort results by this field name"),
|
|
31202
31242
|
sort_direction: external_exports.enum(["asc", "desc"]).optional().describe("Sort direction (default: desc)"),
|
|
31243
|
+
offset: external_exports.number().optional().describe("Skip first N results (use with limit for pagination)"),
|
|
31203
31244
|
limit: external_exports.number().optional().describe("Limit number of results returned"),
|
|
31204
31245
|
filter: external_exports.string().optional().describe(
|
|
31205
31246
|
'Filter expression (e.g. "FLUC_RT > 5", "MKT_NM == KOSPI"). Operators: >, <, >=, <=, ==, !='
|
|
@@ -31222,14 +31263,6 @@ function filterFields(data, fields) {
|
|
|
31222
31263
|
return filtered;
|
|
31223
31264
|
});
|
|
31224
31265
|
}
|
|
31225
|
-
function errorResult(message) {
|
|
31226
|
-
return {
|
|
31227
|
-
content: [
|
|
31228
|
-
{ type: "text", text: JSON.stringify({ error: message }) }
|
|
31229
|
-
],
|
|
31230
|
-
isError: true
|
|
31231
|
-
};
|
|
31232
|
-
}
|
|
31233
31266
|
function createCategoryTool(categoryId) {
|
|
31234
31267
|
const endpoints = ENDPOINTS.filter((e) => e.category === categoryId);
|
|
31235
31268
|
return {
|
|
@@ -31286,22 +31319,20 @@ function createCategoryTool(categoryId) {
|
|
|
31286
31319
|
const filterExpr = args.filter;
|
|
31287
31320
|
const sortField2 = args.sort;
|
|
31288
31321
|
const sortDirection2 = args.sort_direction ?? "desc";
|
|
31322
|
+
const offsetN2 = args.offset;
|
|
31289
31323
|
const limitN2 = args.limit;
|
|
31290
31324
|
data2 = applyPipeline(data2, {
|
|
31291
31325
|
filter: filterExpr,
|
|
31292
31326
|
sort: sortField2,
|
|
31293
31327
|
direction: sortDirection2,
|
|
31328
|
+
offset: offsetN2,
|
|
31294
31329
|
limit: limitN2
|
|
31295
31330
|
});
|
|
31296
31331
|
const fields2 = args.fields;
|
|
31297
31332
|
if (fields2) {
|
|
31298
31333
|
data2 = filterFields(data2, fields2);
|
|
31299
31334
|
}
|
|
31300
|
-
return
|
|
31301
|
-
content: [
|
|
31302
|
-
{ type: "text", text: JSON.stringify(data2, null, 2) }
|
|
31303
|
-
]
|
|
31304
|
-
};
|
|
31335
|
+
return successResult(data2);
|
|
31305
31336
|
}
|
|
31306
31337
|
const dateStr = args.date ?? getRecentTradingDate();
|
|
31307
31338
|
try {
|
|
@@ -31326,23 +31357,21 @@ function createCategoryTool(categoryId) {
|
|
|
31326
31357
|
const filterExpr2 = args.filter;
|
|
31327
31358
|
const sortField = args.sort;
|
|
31328
31359
|
const sortDirection = args.sort_direction ?? "desc";
|
|
31360
|
+
const offsetN = args.offset;
|
|
31329
31361
|
const limitN = args.limit;
|
|
31330
31362
|
let data = result.data;
|
|
31331
31363
|
data = applyPipeline(data, {
|
|
31332
31364
|
filter: filterExpr2,
|
|
31333
31365
|
sort: sortField,
|
|
31334
31366
|
direction: sortDirection,
|
|
31367
|
+
offset: offsetN,
|
|
31335
31368
|
limit: limitN
|
|
31336
31369
|
});
|
|
31337
31370
|
const fields = args.fields;
|
|
31338
31371
|
if (fields) {
|
|
31339
31372
|
data = filterFields(data, fields);
|
|
31340
31373
|
}
|
|
31341
|
-
return
|
|
31342
|
-
content: [
|
|
31343
|
-
{ type: "text", text: JSON.stringify(data, null, 2) }
|
|
31344
|
-
]
|
|
31345
|
-
};
|
|
31374
|
+
return successResult(data);
|
|
31346
31375
|
}
|
|
31347
31376
|
};
|
|
31348
31377
|
}
|