kiwoom-mcp-server 0.14.0 → 0.16.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.en.md CHANGED
@@ -23,8 +23,8 @@ allowance.
23
23
 
24
24
  | Tool | Description | Kiwoom TR |
25
25
  |---|---|---|
26
- | `search_stock` | Name → code search (KOSPI/KOSDAQ, incl. ETF/ETN) | ka10099 |
27
- | `get_stock_price` | Current price / change rate / volume / basic metrics | ka10001 |
26
+ | `search_stock` | Name → code search (KOSPI/KOSDAQ, incl. ETF/ETN) + trading-caution flags | ka10099 |
27
+ | `get_stock_price` | Current price / change rate / volume / basic metrics + sector, listing date, caution flags | ka10001, ka10099 |
28
28
  | `get_stock_chart` | Daily/weekly/monthly/yearly/minute/tick candles (adjusted price) | ka10079~83, ka10094 |
29
29
  | `get_orderbook` | 10-level ask/bid quotes and sizes | ka10004 |
30
30
  | `get_market_index` | KOSPI/KOSDAQ composite and sector indices | ka20003 |
@@ -47,7 +47,7 @@ allowance.
47
47
  | Tool | Description | Kiwoom TR |
48
48
  |---|---|---|
49
49
  | `get_watchlist_groups` | List of saved watchlist groups (code + name) | ka01300 |
50
- | `get_watchlist` | Stocks in a group (enriched with name / prev close / market) | ka01301, ka10099 |
50
+ | `get_watchlist` | Stocks in a group (enriched with name / prev close / market / caution flags) | ka01301, ka10099 |
51
51
 
52
52
  > The Kiwoom REST API exposes no watchlist **edit** (add/remove) TR — read-only.
53
53
 
package/README.md CHANGED
@@ -21,8 +21,8 @@ Claude Desktop / Claude Code에서 자연어로 국내 주식 시세·차트·
21
21
 
22
22
  | Tool | 설명 | 키움 TR |
23
23
  |---|---|---|
24
- | `search_stock` | 종목명→코드 검색 (코스피/코스닥, ETF/ETN 포함) | ka10099 |
25
- | `get_stock_price` | 현재가/등락률/거래량/기본지표 | ka10001 |
24
+ | `search_stock` | 종목명→코드 검색 (코스피/코스닥, ETF/ETN 포함) + 투자유의 표시 | ka10099 |
25
+ | `get_stock_price` | 현재가/등락률/거래량/기본지표 + 업종·상장일·투자유의 | ka10001, ka10099 |
26
26
  | `get_stock_chart` | 일/주/월/년/분/틱봉 캔들 차트 (수정주가 반영) | ka10079~83, ka10094 |
27
27
  | `get_orderbook` | 10단계 매도/매수 호가·잔량 | ka10004 |
28
28
  | `get_market_index` | 코스피/코스닥 종합·업종 지수 | ka20003 |
@@ -45,7 +45,7 @@ Claude Desktop / Claude Code에서 자연어로 국내 주식 시세·차트·
45
45
  | Tool | 설명 | 키움 TR |
46
46
  |---|---|---|
47
47
  | `get_watchlist_groups` | HTS 관심종목 그룹 목록 (그룹코드+그룹명) | ka01300 |
48
- | `get_watchlist` | 그룹 내 종목 목록 (종목명·전일종가·시장 보강) | ka01301, ka10099 |
48
+ | `get_watchlist` | 그룹 내 종목 목록 (종목명·전일종가·시장·투자유의 보강) | ka01301, ka10099 |
49
49
 
50
50
  > 키움 REST API에는 관심종목 **편집(추가/삭제)** TR이 없어 조회만 가능합니다.
51
51
 
@@ -23,3 +23,30 @@ export async function loadMasterList(client) {
23
23
  export function clearMasterListCache() {
24
24
  cache = null;
25
25
  }
26
+ /**
27
+ * ka10099 orderWarning(투자유의종목여부) codes. "5" arrives on rows whose
28
+ * auditInfo is 투자경고 (mock-probed 2026-07-11), so the openapi description's
29
+ * "투자경과" is read as a typo for 투자경고. "1" is ETF-only.
30
+ */
31
+ const ORDER_WARNING_LABELS = {
32
+ "1": "ETF투자주의요망",
33
+ "2": "정리매매",
34
+ "3": "단기과열",
35
+ "4": "투자위험",
36
+ "5": "투자경고",
37
+ };
38
+ /**
39
+ * Abnormal-status labels for a master-list row — 감리구분(auditInfo)이 "정상"이
40
+ * 아니면 그 값을, orderWarning이 "0"이 아니면 라벨을 모은다. 둘이 같은 상태를
41
+ * 가리키는 경우(예: auditInfo "단기과열" + orderWarning "3")는 한 번만 담는다.
42
+ * 정상 종목은 빈 배열.
43
+ */
44
+ export function masterItemWarnings(item) {
45
+ const warnings = [];
46
+ if (item.auditInfo && item.auditInfo !== "정상")
47
+ warnings.push(item.auditInfo);
48
+ const orderLabel = ORDER_WARNING_LABELS[item.orderWarning];
49
+ if (orderLabel && !warnings.includes(orderLabel))
50
+ warnings.push(orderLabel);
51
+ return warnings;
52
+ }
@@ -134,10 +134,12 @@ export const stockListItemSchema = z.looseObject({
134
134
  lastPrice: str(), // 전일종가, zero-padded
135
135
  marketName: str(), // "거래소" | "코스닥" | "ETF" | ...
136
136
  upName: str(), // 업종명 (ETF/ETN은 빈 값)
137
- upSizeName: str(), // 대형주/중형주/소형주
137
+ upSizeName: str(), // 대형주/중형주/소형주 (우선주/ETF 등은 빈 값)
138
138
  state: str(), // "증거금20%|담보대출|신용가능"
139
- auditInfo: str(), // "정상" 등
140
- orderWarning: str(), // "0"=정상
139
+ auditInfo: str(), // "정상"/"거래정지"/"관리종목"/"투자주의환기종목"/"단기과열"/"투자경고"
140
+ orderWarning: str(), // 투자유의: "0"=해당없음, 나머지는 master-list.ts ORDER_WARNING_LABELS
141
+ regDay: str(), // 상장일 yyyyMMdd
142
+ companyClassName: str(), // 코스닥 전용 기업분류: 벤처기업/우량기업/스팩 등 (그 외 빈 값)
141
143
  });
142
144
  export const stockListResponseSchema = z.looseObject({
143
145
  ...envelope,
package/dist/server.js CHANGED
@@ -27,7 +27,7 @@ import { registerTransactionsTool } from "./tools/transactions.js";
27
27
  import { registerViStocksTool } from "./tools/vi-stocks.js";
28
28
  import { registerWatchlistGroupsTool, registerWatchlistTool } from "./tools/watchlist.js";
29
29
  export const SERVER_NAME = "kiwoom-mcp-server";
30
- export const SERVER_VERSION = "0.14.0";
30
+ export const SERVER_VERSION = "0.16.0";
31
31
  export function createServer() {
32
32
  const server = new McpServer({
33
33
  name: SERVER_NAME,
@@ -2,10 +2,14 @@ import { z } from "zod";
2
2
  import { getKiwoomContext } from "../context.js";
3
3
  import { fetchEtfInfo, fetchEtfNav, fetchStockInfo } from "../kiwoom/api.js";
4
4
  import { formatKRW, formatPercent, formatQuantity, formatRatioPercent, formatSigned, parseKiwoomNumber, parseKiwoomPrice, } from "../utils/num.js";
5
+ import { formatNonEtfNotice } from "./etf-returns.js";
5
6
  import { runTool, textResult } from "./helpers.js";
6
7
  export function formatEtfInfo(etf, quote, nav, stockCode, modeLabel) {
7
- if (!etf.stk_nm) {
8
- return `[${modeLabel}] ${stockCode}의 ETF 정보가 없습니다. ETF 종목코드인지 확인해 주세요.`;
8
+ // 비ETF/미존재 코드 가드 — get_etf_returns와 동일한 ka40002 판별자
9
+ // (비ETF는 stk_nm만 채워지고 추적지수명이 빈값, 없는 코드는 다 빈값).
10
+ // 이전에는 비ETF에 "-"투성이 카드가 나갔다 (2026-07-10 GUI 테스트 watch item).
11
+ if (!etf.stk_nm || !etf.etfobjt_idex_nm) {
12
+ return formatNonEtfNotice(etf.stk_nm, stockCode, modeLabel, "ETF 정보를");
9
13
  }
10
14
  const lines = [
11
15
  `[${modeLabel}] ${etf.stk_nm} (${stockCode}) ETF 정보`,
@@ -10,10 +10,11 @@ const DEFAULT_BENCHMARK = "201";
10
10
  * 비ETF 가드 안내 (2026-07-10 GUI 테스트 발견 대응): ka40001은 일반 종목 코드에도
11
11
  * 수익률을 돌려주므로 ka40002로 선별한다 — 비ETF는 stk_nm은 있지만 추적지수명이
12
12
  * 빈값, 존재하지 않는 코드는 둘 다 빈값 (mock-probed 2026-07-10).
13
+ * get_etf_info도 같은 판별자를 쓴다 — featurePhrase는 조사까지 포함한 목적어구.
13
14
  */
14
- export function formatNonEtfNotice(stockName, stockCode, modeLabel) {
15
+ export function formatNonEtfNotice(stockName, stockCode, modeLabel, featurePhrase = "ETF 기간 수익률을") {
15
16
  if (stockName) {
16
- return (`[${modeLabel}] ${stockName} (${stockCode})은(는) ETF가 아니어서 ETF 기간 수익률을 제공하지 않습니다. ` +
17
+ return (`[${modeLabel}] ${stockName} (${stockCode})은(는) ETF가 아니어서 ${featurePhrase} 제공하지 않습니다. ` +
17
18
  `일반 종목 시세는 get_stock_price / get_stock_chart를 이용하세요.`);
18
19
  }
19
20
  return (`[${modeLabel}] ${stockCode}의 ETF 정보를 찾을 수 없습니다. ` +
@@ -1,6 +1,8 @@
1
1
  import { z } from "zod";
2
2
  import { getKiwoomContext } from "../context.js";
3
3
  import { fetchStockInfo } from "../kiwoom/api.js";
4
+ import { loadMasterList, masterItemWarnings } from "../kiwoom/master-list.js";
5
+ import { formatDateDashed } from "../utils/date.js";
4
6
  import { formatKRW, formatPercent, parseKiwoomNumber, parseKiwoomPrice, } from "../utils/num.js";
5
7
  import { runTool, textResult } from "./helpers.js";
6
8
  const PRE_SIG_LABELS = {
@@ -10,7 +12,7 @@ const PRE_SIG_LABELS = {
10
12
  "4": "하한",
11
13
  "5": "하락",
12
14
  };
13
- export function formatStockInfo(info, modeLabel) {
15
+ export function formatStockInfo(info, modeLabel, master) {
14
16
  const cur = parseKiwoomPrice(info.cur_prc);
15
17
  const change = parseKiwoomNumber(info.pred_pre);
16
18
  const fluRt = parseKiwoomNumber(info.flu_rt);
@@ -45,12 +47,28 @@ export function formatStockInfo(info, modeLabel) {
45
47
  if (fundamentals.length > 0) {
46
48
  lines.push(`- ${fundamentals.join(" / ")}`);
47
49
  }
50
+ // ka10099 마스터 캐시에서 얻는 부가 정보 — 조회 실패 시 이 블록만 조용히 빠진다.
51
+ if (master) {
52
+ const marketParts = [master.marketName, master.upName].filter(Boolean).join(" · ");
53
+ const sizeClass = [master.upSizeName, master.companyClassName].filter(Boolean).join(", ");
54
+ if (marketParts) {
55
+ lines.push(`- 시장/업종: ${marketParts}${sizeClass ? ` (${sizeClass})` : ""}`);
56
+ }
57
+ if (/^\d{8}$/.test(master.regDay)) {
58
+ lines.push(`- 상장일: ${formatDateDashed(master.regDay)}`);
59
+ }
60
+ const warnings = masterItemWarnings(master);
61
+ if (warnings.length > 0) {
62
+ lines.push(`- ⚠️ 투자유의: ${warnings.join(" · ")}`);
63
+ }
64
+ }
48
65
  return lines.join("\n");
49
66
  }
50
67
  export function registerStockPriceTool(server) {
51
68
  server.registerTool("get_stock_price", {
52
69
  title: "종목 현재가 조회",
53
70
  description: "6자리 종목코드로 국내 주식/ETF의 현재가, 등락률, 거래량, 기본 지표를 조회합니다 (키움 ka10001). " +
71
+ "업종·상장일과 거래정지/관리종목/투자경고 같은 투자유의 상태도 함께 표시됩니다. " +
54
72
  "종목명만 알고 있다면 search_stock으로 먼저 코드를 찾으세요.",
55
73
  inputSchema: {
56
74
  stock_code: z
@@ -60,7 +78,14 @@ export function registerStockPriceTool(server) {
60
78
  },
61
79
  }, async ({ stock_code }) => runTool(async () => {
62
80
  const { client, config } = getKiwoomContext();
63
- const info = await fetchStockInfo(client, stock_code);
64
- return textResult(formatStockInfo(info, config.modeLabel));
81
+ // 마스터 조회는 best-effort 부가정보 — 실패해도 시세 응답은 그대로 나간다.
82
+ // 캐시가 따뜻하면 추가 API 콜 없음(12h TTL), 콜드면 ka10099 2콜이 병렬로 얹힌다.
83
+ const [info, master] = await Promise.all([
84
+ fetchStockInfo(client, stock_code),
85
+ loadMasterList(client)
86
+ .then((items) => items.find((i) => i.code === stock_code))
87
+ .catch(() => undefined),
88
+ ]);
89
+ return textResult(formatStockInfo(info, config.modeLabel, master));
65
90
  }));
66
91
  }
@@ -1,6 +1,6 @@
1
1
  import { z } from "zod";
2
2
  import { getKiwoomContext } from "../context.js";
3
- import { loadMasterList } from "../kiwoom/master-list.js";
3
+ import { loadMasterList, masterItemWarnings } from "../kiwoom/master-list.js";
4
4
  import { formatKRW, parseKiwoomPrice } from "../utils/num.js";
5
5
  import { runTool, textResult } from "./helpers.js";
6
6
  const MAX_RESULTS = 10;
@@ -38,11 +38,12 @@ export function formatSearchResults(results, query, modeLabel) {
38
38
  const lines = [
39
39
  `[${modeLabel}] 종목 검색: "${query}" (${results.length}건${results.length >= MAX_RESULTS ? ", 상위만 표시" : ""})`,
40
40
  "",
41
- "| 코드 | 종목명 | 시장 | 전일종가 | 업종 |",
42
- "|---|---|---|---:|---|",
41
+ "| 코드 | 종목명 | 시장 | 전일종가 | 업종 | 비고 |",
42
+ "|---|---|---|---:|---|---|",
43
43
  ];
44
44
  for (const r of results) {
45
- lines.push(`| ${r.code} | ${r.name} | ${r.marketName || "-"} | ${formatKRW(parseKiwoomPrice(r.lastPrice))} | ${r.upName || "-"} |`);
45
+ const warnings = masterItemWarnings(r);
46
+ lines.push(`| ${r.code} | ${r.name} | ${r.marketName || "-"} | ${formatKRW(parseKiwoomPrice(r.lastPrice))} | ${r.upName || "-"} | ${warnings.join("·") || "-"} |`);
46
47
  }
47
48
  return lines.join("\n");
48
49
  }
@@ -51,6 +52,7 @@ export function registerStockSearchTool(server) {
51
52
  title: "종목 검색 (이름→코드)",
52
53
  description: "종목명(부분 일치)이나 6자리 코드로 코스피/코스닥 상장 종목(ETF/ETN 포함)을 검색해 " +
53
54
  "종목코드를 찾습니다 (키움 ka10099). 다른 tool에 넘길 종목코드를 모를 때 먼저 사용하세요. " +
55
+ "거래정지·관리종목·투자경고 같은 투자유의 상태는 비고 컬럼에 표시됩니다. " +
54
56
  "첫 호출은 종목 마스터를 내려받아 몇 초 걸리고, 이후 12시간 동안 캐시됩니다.",
55
57
  inputSchema: {
56
58
  query: z.string().min(1).describe("종목명 일부(예: '삼성전자', 'KODEX 미국') 또는 6자리 종목코드"),
@@ -2,7 +2,7 @@ import { z } from "zod";
2
2
  import { getKiwoomContext } from "../context.js";
3
3
  import { fetchWatchlistGroupDetail, fetchWatchlistGroups } from "../kiwoom/api.js";
4
4
  import { KiwoomApiError } from "../kiwoom/errors.js";
5
- import { loadMasterList } from "../kiwoom/master-list.js";
5
+ import { loadMasterList, masterItemWarnings } from "../kiwoom/master-list.js";
6
6
  import { normalizeStockCode, } from "../kiwoom/types.js";
7
7
  import { formatKRW, parseKiwoomPrice } from "../utils/num.js";
8
8
  import { runTool, textResult } from "./helpers.js";
@@ -39,7 +39,7 @@ export function formatWatchlist(group, stocks, nameIndex, modeLabel) {
39
39
  if (stocks.length === 0) {
40
40
  return `${title}\n\n(이 그룹에 등록된 종목이 없습니다.)`;
41
41
  }
42
- const lines = [title, "", "| 코드 | 종목명 | 시장 | 전일종가 |", "|---|---|---|---:|"];
42
+ const lines = [title, "", "| 코드 | 종목명 | 시장 | 전일종가 | 비고 |", "|---|---|---|---:|---|"];
43
43
  let missing = 0;
44
44
  for (const s of stocks) {
45
45
  const code = normalizeStockCode(s.cod2);
@@ -50,7 +50,8 @@ export function formatWatchlist(group, stocks, nameIndex, modeLabel) {
50
50
  const name = `${bookmark}${info?.name || "-"}`;
51
51
  const market = info?.marketName || "-";
52
52
  const price = info ? formatKRW(parseKiwoomPrice(info.lastPrice)) : "-";
53
- lines.push(`| ${code} | ${name} | ${market} | ${price} |`);
53
+ const flags = info ? masterItemWarnings(info).join("·") : "";
54
+ lines.push(`| ${code} | ${name} | ${market} | ${price} | ${flags || "-"} |`);
54
55
  }
55
56
  if (nameIndex.size === 0) {
56
57
  lines.push("", "※ 종목 마스터를 불러오지 못해 코드만 표시했습니다.");
@@ -91,7 +92,7 @@ export function registerWatchlistTool(server) {
91
92
  title: "관심종목 그룹 상세",
92
93
  description: "관심종목 그룹에 담긴 종목 목록을 조회합니다 (키움 ka01301, 읽기 전용). " +
93
94
  "그룹코드(예: '000') 또는 그룹명(예: 'etf')을 넘기세요. 그룹을 모르면 get_watchlist_groups로 먼저 확인하세요. " +
94
- "종목명·전일종가·시장은 종목 마스터에서 보강해 함께 표시합니다.",
95
+ "종목명·전일종가·시장과 거래정지/관리종목 같은 투자유의 상태를 종목 마스터에서 보강해 함께 표시합니다.",
95
96
  inputSchema: {
96
97
  group: z
97
98
  .string()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kiwoom-mcp-server",
3
- "version": "0.14.0",
3
+ "version": "0.16.0",
4
4
  "description": "Read-only MCP server exposing the Kiwoom Securities REST API (market data, account inquiry, ISA tax-allowance calculator) to Claude Desktop / Claude Code.",
5
5
  "private": false,
6
6
  "type": "module",