Skip to main content
Glama
KIS REST API MCP Server

KIS REST API MCP Server

by migusdn

韩国投资证券 REST API MCP (Model Context Protocol)

Python 3.13+ License: MIT

这是一个将韩国投资证券 (KIS) REST API 作为 MCP 工具调用的服务器。它提供基于目录的通用工具和常用便捷工具,用于查询国内/海外股票、账户信息及订单相关 API。

主要功能

  • 基于 API 目录的调用

    • 提供 8 个组,共 166 个 REST API

    • 可确认 API 组/ID、路径、HTTP 方法、TR_ID 候选值及请求参数

    • 提供各参数的韩文标签、输入指南、示例值及主要代码值

    • 完整列表: API_CATALOG.md

  • 国内股票

    • 查询当前价格、期间/每日行情、报价、行业指数、基本信息

    • 查询余额、投资账户资产状况、可买入金额、可卖出数量

    • 查询订单/订单记录/可更正取消的订单

  • 海外股票

    • 支持美国、日本、中国、香港、越南市场代码

    • 查询当前价格、余额、按成交基准的当前余额、各币种保证金、可买入金额

    • 根据市场/买卖方向自动选择订单 TR_ID

  • 执行/运行

    • 支持 stdio, sse, streamable-http 传输方式

    • 基于 .env 或命令行参数进行配置

    • 自动补全账号、账户商品代码、认证值

    • 基于 App Key 和账户类型的令牌缓存

    • 默认拒绝未知请求参数

    • 默认拦截订单/更正/取消 API

Related MCP server: kiwoom-mcp

安全默认值

像订单/更正/取消这类会改变账户状态的 API 默认处于拦截状态。

KIS_ENABLE_TRADING=true

仅在明确设置上述值时,状态变更 API 才会执行。如果仅使用查询 API,请勿设置。

要求

  • Python >= 3.13

  • uv

安装

请参考 INSTALL.md 进行安装。LLM 或 MCP 客户端在配置时也应优先阅读此文件。

INSTALL.md 包含以下内容:

  • 基于 uv 的依赖安装

  • .env 创建及 KIS_APP_KEY, KIS_APP_SECRET, KIS_CANO, KIS_ACNT_PRDT_CD 设置

  • Codex CLI, Claude Code, Claude Desktop, 通用 MCP 客户端注册示例

  • 用于节省上下文的 KIS_MCP_TOOLSET=catalog 设置

  • 用于查询余额、可买入金额、当前价格的 call-kis-api 示例

快速本地准备:

pip install uv
uv sync
cp .env.example .env
chmod 600 .env

接着在 .env 中设置以下值。详细的值说明和各客户端注册命令请参考 INSTALL.md。

KIS_APP_KEY="발급받은 앱키"
KIS_APP_SECRET="발급받은 시크릿키"
KIS_ACCOUNT_TYPE="REAL"   # REAL 또는 VIRTUAL
KIS_CANO="계좌번호 앞 8자리"
KIS_ACNT_PRDT_CD="01"
KIS_MCP_TOOLSET="catalog"

运行

# stdio, 로컬 MCP 클라이언트 권장
uv run python server.py

也可以通过命令行参数进行设置。

uv run python server.py \
  --app-key "앱키" \
  --app-secret "시크릿키" \
  --account-type "REAL" \
  --cano "계좌번호" \
  --acnt-prdt-cd "01"

选择传输方式:

MCP_TYPE=stdio uv run python server.py
MCP_TYPE=streamable-http MCP_HOST=127.0.0.1 MCP_PORT=8000 MCP_PATH=/mcp uv run python server.py
MCP_TYPE=sse MCP_HOST=127.0.0.1 MCP_PORT=8000 MCP_PATH=/sse uv run python server.py

MCP 客户端注册示例:

以下是通用 MCP 客户端的最小示例。Codex CLI, Claude Code, Claude Desktop 命令请使用 INSTALL.md。

{
  "mcpServers": {
    "kis-mcp-server": {
      "command": "uv",
      "args": ["run", "python", "server.py"],
      "cwd": "<project-root>",
      "env": {
        "KIS_MCP_TOOLSET": "catalog",
        "KIS_MCP_LOG_LEVEL": "WARNING"
      }
    }
  }
}

MCP 工具构成

目录工具

工具

说明

list-kis-api-specs

按 API 组/搜索词查询列表

get-kis-api-spec

确认单个 API 的路径、TR_ID 候选值、参数

call-kis-api

使用 group, api_type, params 调用目录 API

list-kis-api-specs 会同时返回必填参数的标签、示例值及主要代码值。 get-kis-api-spec 会返回所有参数的 label, guide, examples, values, default, auto_fill 信息,以便 LLM 直接确认调用所需的输入格式。

call-kis-api 共同执行以下处理:

  • 基于环境变量自动输入账号/账户商品代码

  • 发放并缓存认证令牌

  • 构建 GET/POST 请求

  • 在多个 TR_ID 中自动选择可判定的订单 TR_ID

  • 应用状态变更 API 安全门控

  • 默认拒绝目录中不存在的参数

便捷工具

常用的国内/海外股票功能也作为单独的 MCP 工具提供。

工具

说明

inquery-stock-price

国内股票当前价查询

inquery-balance

国内股票余额查询

inquery-order-list

国内股票每日订单/成交查询

inquery-order-detail

国内股票订单详情查询

inquery-stock-info

国内股票每日行情查询

inquery-stock-history

国内股票期间行情查询

inquery-stock-ask

国内股票报价查询

inquery-stock-market

国内行业/指数当前价查询

inquery-stock-basic-info

国内股票基本信息查询

inquery-overseas-stock-price

海外股票当前价查询

order-stock

国内股票买入/卖出订单

order-overseas-stock

海外股票买入/卖出订单

如果没有 KIS_ENABLE_TRADING=true,订单工具也不会执行。

工具加载优化

MCP 客户端在连接服务器时会将工具名称、说明、输入模式加载到上下文中。暴露的便捷工具越多,对话开始时的上下文占用量就越大,因此在需要时可以使用仅暴露 3 个目录工具的轻量模式。

KIS_MCP_TOOLSET=catalog uv run python server.py

值

暴露工具数

暴露工具

用途

full

15个

目录工具 + 所有便捷工具

与现有操作兼容

catalog

3个

list-kis-api-specs, get-kis-api-spec, call-kis-api

低上下文占用量

catalog 模式是为了减少 MCP 工具模式加载量而设计的。虽然隐藏了便捷工具,但 166 个 API 仍然可以通过 call-kis-api 调用。需要的 API 可以通过 list-kis-api-specs 查找,所需的详细参数可以通过 get-kis-api-spec 随时查询。

推荐使用流程:

  1. 使用 list-kis-api-specs 搜索 API。

  2. 使用 get-kis-api-spec 确认必填参数、示例值、代码值。

  3. 使用 call-kis-api 调用实际 API。

在 MCP 客户端设置中只需添加环境变量即可。

{
  "env": {
    "KIS_MCP_TOOLSET": "catalog"
  }
}

如果想直接在工具列表中暴露常用便捷工具,请使用默认值 full。

call-kis-api 示例

国内股票当前价:

{
  "group": "domestic_stock",
  "api_type": "inquire_price",
  "params": {
    "fid_cond_mrkt_div_code": "J",
    "fid_input_iscd": "005930"
  }
}

海外股票余额:

{
  "group": "overseas_stock",
  "api_type": "inquire_balance",
  "params": {
    "ovrs_excg_cd": "NASD",
    "tr_crcy_cd": "USD"
  }
}

海外股票成交基准当前余额:

{
  "group": "overseas_stock",
  "api_type": "inquire_present_balance",
  "params": {
    "wcrc_frcr_dvsn_cd": "01",
    "natn_cd": "000",
    "tr_mket_cd": "00",
    "inqr_dvsn_cd": "00"
  }
}

海外股票可买入金额:

{
  "group": "overseas_stock",
  "api_type": "inquire_psamount",
  "params": {
    "ovrs_excg_cd": "NASD",
    "ovrs_ord_unpr": "1",
    "item_cd": "QQQ"
  }
}

主要 API 组

组

说明

API 数

auth

认证

2

domestic_stock

国内股票

74

overseas_stock

海外股票

34

domestic_bond

国内债券

14

domestic_futureoption

国内期货期权

20

overseas_futureoption

海外期货期权

19

elw

ELW

1

etfetn

ETF/ETN

2

完整的 API ID、路径、TR_ID、必填参数指南整理在 API_CATALOG.md 中。

环境变量

名称

说明

默认值

KIS_APP_KEY

KIS App Key

-

KIS_APP_SECRET

KIS Secret Key

-

KIS_ACCOUNT_TYPE

REAL 或 VIRTUAL

-

KIS_CANO

账号前 8 位

-

KIS_ACNT_PRDT_CD

账户商品代码

01

KIS_TOKEN_FILE

令牌缓存文件

token.json

KIS_ENABLE_TRADING

激活订单/更正/取消 API

未激活

KIS_MCP_TOOLSET

MCP 工具暴露范围 (full, catalog)

full

KIS_MCP_LOG_LEVEL

日志级别

INFO

MCP_TYPE

stdio, sse, streamable-http

stdio

MCP_HOST

HTTP/SSE host

127.0.0.1

MCP_PORT

HTTP/SSE port

8000

MCP_PATH

HTTP/SSE path

/mcp

开发/验证

uv run python -m compileall main.py server.py example.py tests
uv run python -m unittest discover -v
git diff --check

许可证

MIT

Available Tools

10 tools
inquery-balanceB

Get current stock balance information from Korea Investment & Securities

Inputs: no named parameters.

inquery-order-detailC

Get order detail from Korea Investment & Securities

Inputs: order_no (required), order_date (required).

inquery-order-listC

Get daily order list from Korea Investment & Securities

Inputs: start_date (required), end_date (required).

inquery-overseas-stock-priceC

Get overseas stock price from Korea Investment & Securities

Inputs: symbol (required), market (required).

inquery-stock-askC

Get stock ask price from Korea Investment & Securities

Inputs: symbol (required).

inquery-stock-historyC

Get daily stock price history from Korea Investment & Securities

Inputs: symbol (required), start_date (required), end_date (required).

inquery-stock-infoC

Get daily stock price information from Korea Investment & Securities

Inputs: symbol (required), start_date (required), end_date (required).

inquery-stock-priceC

Get current stock price information from Korea Investment & Securities

Inputs: symbol (required).

order-overseas-stockC

Order overseas stock (buy/sell) from Korea Investment & Securities

Inputs: symbol (required), quantity (required), price (required), order_type (required), +1 more.

order-stockC

Order stock (buy/sell) from Korea Investment & Securities

Inputs: symbol (required), quantity (required), price (required), order_type (required).

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    B3.2/5.0

    Scored across 10 tools

    Disambiguation3/5

    The tools have clear distinctions between querying (inquery-*) and ordering (order-*), but within the querying tools there is significant overlap that could cause confusion. For example, inquery-stock-price, inquery-stock-info, and inquery-stock-ask all seem to retrieve stock price-related data with subtle differences that may not be immediately clear to an agent.

    Naming Consistency5/5

    All tool names follow a consistent hyphen-separated pattern with a clear verb-noun structure (e.g., inquery-balance, order-stock). The naming is predictable and uniform across all 10 tools, making it easy for an agent to parse and understand the purpose of each tool.

    Tool Count5/5

    With 10 tools, the count is well-scoped for a securities trading API, covering key operations like querying balances, orders, stock prices, and placing orders. Each tool appears to serve a distinct function within the domain, and the number is neither too sparse nor overwhelming.

    Completeness4/5

    The tool set provides comprehensive coverage for core trading operations, including querying various data (balances, orders, prices) and executing orders (domestic and overseas). A minor gap is the lack of tools for modifying or canceling orders, which might be necessary for full lifecycle management, but agents can likely work around this with the existing query and order tools.

    Maintenance

    ActivityInactive
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      A
      quality
      D
      maintenance
      An MCP server that enables natural language control of Kiwoom Securities accounts through Claude Desktop. It provides tools for stock price lookup, buying and selling stocks, and analyzing portfolios or trade history via the Kiwoom REST API.
      11
      2
      MIT
    • A
      license
      Not graded
      quality
      D
      maintenance
      A Model Context Protocol server that wraps the Kiwoom Securities REST API to provide read-only access to Korean stock market information. It enables LLMs to query real-time prices, charts, investor trends, and account balances directly.
      4
      MIT
    • A
      license
      Not graded
      quality
      D
      maintenance
      A Model Context Protocol server that integrates Futu OpenAPI, enabling AI models to query real-time market data and execute trades across Hong Kong, US, and A-share markets.
      30 PyPI
      81
      MIT
    • A
      license
      A
      quality
      B
      maintenance
      Read-only MCP server for Kiwoom Securities, enabling natural language queries of Korean stock market data and account information, including ISA tax status.
      49
      129 npm
      1
      MIT