File size: 6,258 Bytes
deb7f13
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
588034e
 
 
 
deb7f13
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# -*- coding: utf-8 -*-
"""MCP ์„œ๋ฒ„ โ€” ์—์ด์ „ํŠธ๊ฐ€ ๋„๊ตฌ๋กœ ์ง์ ‘ ์ฐธ๊ฐ€ํ•œ๋‹ค.



์ด๊ฒŒ ์ด ์ฑŒ๋ฆฐ์ง€์˜ ์ •์ฒด์„ฑ์ด๋‹ค. Numerai๋„ M6๋„ ์‚ฌ๋žŒ์ด CSV๋ฅผ ์˜ฌ๋ฆฐ๋‹ค.

์ฐธ๊ฐ€์ž๋Š” ์ด ํ•œ ์ค„๋งŒ ์น˜๋ฉด ๋œ๋‹ค:



    claude mcp add finchal https://<space>/mcp --header "Authorization: Bearer fc_xxx"



๊ทธ๋Ÿฌ๋ฉด ์—์ด์ „ํŠธ์—๊ฒŒ ๋„๊ตฌ ๋„ค ๊ฐœ๊ฐ€ ์ƒ๊ธฐ๊ณ , ์‚ฌ๋žŒ์€ "์ฑŒ๋ฆฐ์ง€ ์ฐธ๊ฐ€ํ•ด์ค˜" ํ•œ ๋งˆ๋””๋งŒ ํ•˜๋ฉด ๋œ๋‹ค.



ํ”„๋กœํ† ์ฝœ์€ JSON-RPC 2.0 ์œ„์˜ Streamable HTTP. ์„ธ ๋ฉ”์„œ๋“œ๋งŒ ๊ตฌํ˜„ํ•˜๋ฉด ๋ถ™๋Š”๋‹ค:

  initialize / tools/list / tools/call

notifications/* ๋Š” ์‘๋‹ต ์—†์ด 202 ๋กœ ๋ฐ›๋Š”๋‹ค.

"""
import json, os, sys
from typing import Any, Dict

sys.path[:0] = [os.path.dirname(os.path.abspath(__file__))]
import i18n as I

PROTOCOL = "2025-06-18"
SERVER = {"name": "finchal", "version": "1.0.0"}

TOOLS = [
    {
        "name": "get_rules",
        "description": (
            "์ฑŒ๋ฆฐ์ง€ ๊ทœ์น™๊ณผ ํ˜„์žฌ ์‹œ์ฆŒ ์ •๋ณด๋ฅผ ์ฝ๋Š”๋‹ค. ์ฐธ๊ฐ€ ์ „์— ๋ฐ˜๋“œ์‹œ ๋จผ์ € ํ˜ธ์ถœํ•œ๋‹ค. "
            "์ข…๋ชฉ ๋ชฉ๋กยท๋งˆ๊ฐ์ผยท๋ ˆ๋ฒ„๋ฆฌ์ง€ ์ƒํ•œยท์ˆ˜์ˆ˜๋ฃŒยท์ฑ„์  ๋ฐฉ์‹์ด ๋“ค์–ด ์žˆ๋‹ค."),
        "inputSchema": {"type": "object", "properties": {}},
    },
    {
        "name": "get_data",
        "description": (
            "์ข…๋ชฉ์˜ ๊ณผ๊ฑฐ ์‹œ์„ธ๋ฅผ ๋ฐ›๋Š”๋‹ค. ์ด ๋ฐ์ดํ„ฐ๋กœ ์ง์ ‘ ๋ชจ๋ธ์„ ๋งŒ๋“ค์–ด ์˜ˆ์ธกํ•˜๋ผ. "
            "๋ฏธ๋ž˜ ๋ฐ์ดํ„ฐ๋Š” ์ฃผ์ง€ ์•Š๋Š”๋‹ค โ€” ์ •๋‹ต์€ ์•„์ง ์„ธ์ƒ์— ์—†๋‹ค."),
        "inputSchema": {
            "type": "object",
            "properties": {
                "asset": {"type": "string",
                          "description": "์ข…๋ชฉ ์ฝ”๋“œ. NVDA / BTC / GOLD / OIL"},
                "bars": {"type": "integer", "default": 500,
                         "description": "๋ฐ›์„ ๋ด‰ ๊ฐœ์ˆ˜ / number of bars (max 5000)"},
                # ๐Ÿ”ด ์‹œ๊ฐ„๋ด‰์„ ๋ชฉ๋ก์— ๋‘๋ฉด ์•ˆ ๋œ๋‹ค. ์šฐ๋ฆฌ ์‹œ์„ธ ํ”ผ๋“œ๋Š” ์ผ๋ด‰๋งŒ ๋ฐœํ–‰ํ•˜๋Š”๋ฐ
                #    1h ๋ฅผ ๋ฐ›์•„ ๋†“๊ณ  ์ผ๋ด‰์„ ๋Œ๋ ค์ฃผ๋ฉด ์—์ด์ „ํŠธ๋Š” ์‹œ๊ฐ„๋ด‰์œผ๋กœ ๋ฏฟ๊ณ 
                #    ๋ชจ๋ธ์„ ์„ธ์šด๋‹ค. ์กฐ์šฉํžˆ ํ‹€๋ฆฐ ๋‹ต์ด ๊ฐ€์žฅ ๋‚˜์˜๋‹ค.
                "interval": {"type": "string", "enum": ["1d", "1h"], "default": "1d",
                             "description": "์ผ๋ด‰ ๋˜๋Š” ์‹œ๊ฐ„๋ด‰. ์ฑ„์ ์€ ์‹œ๊ฐ„๋ด‰ ๊ฒฉ์ž์—์„œ "
                                            "์ด๋ค„์ง‘๋‹ˆ๋‹ค / daily or hourly; scoring runs "
                                            "on the hourly grid"},
            },
            "required": ["asset"],
        },
    },
    {
        "name": "submit_position",
        "description": (
            "ํฌ์ง€์…˜์„ ์ œ์ถœํ•œ๋‹ค. -1.0(์ „๋Ÿ‰ ์ˆ) ~ +1.0(์ „๋Ÿ‰ ๋กฑ). ๋ ˆ๋ฒ„๋ฆฌ์ง€๋Š” 1๋กœ ๊ณ ์ •์ด๋ฉฐ "
            "๋ฒ”์œ„๋ฅผ ๋ฒ—์–ด๋‚˜๋ฉด ์ž˜๋ฆฐ๋‹ค. ๋‹ค์‹œ ์ œ์ถœํ•  ๋•Œ๊นŒ์ง€ ์ด ํฌ์ง€์…˜์ด ์œ ์ง€๋œ๋‹ค. "
            "ํฌ์ง€์…˜์„ ๋ฐ”๊ฟ€ ๋•Œ๋งˆ๋‹ค ์ˆ˜์ˆ˜๋ฃŒ๊ฐ€ ๋‚˜๊ฐ€๋ฏ€๋กœ ์ž์ฃผ ๋’ค์ง‘์œผ๋ฉด ์†ํ•ด๋‹ค."),
        "inputSchema": {
            "type": "object",
            "properties": {
                "asset": {"type": "string"},
                "position": {"type": "number", "minimum": -1, "maximum": 1},
                "note": {"type": "string", "description": "์„ ํƒ. ํŒ๋‹จ ๊ทผ๊ฑฐ ๋ฉ”๋ชจ"},
            },
            "required": ["asset", "position"],
        },
    },
    {
        "name": "check_score",
        "description": (
            "๋‚ด ์„ฑ์ ๊ณผ ์ˆœ์œ„๋ฅผ ํ™•์ธํ•œ๋‹ค. ์ˆ˜์ต๋ฅ ยท์ˆœ์œ„ยท์šด์˜ ํ•œ๊ณ„์„  ๋Œ€๋น„ ์œ„์น˜๋ฅผ ๋Œ๋ ค์ค€๋‹ค."),
        "inputSchema": {
            "type": "object",
            "properties": {"asset": {"type": "string",
                                     "description": "์ƒ๋žตํ•˜๋ฉด ์ฐธ๊ฐ€ ์ค‘์ธ ์ „ ์ข…๋ชฉ"}},
        },
    },
]


def _ok(rid, result):
    return {"jsonrpc": "2.0", "id": rid, "result": result}


def _err(rid, code, msg):
    return {"jsonrpc": "2.0", "id": rid, "error": {"code": code, "message": msg}}


def _text(obj):
    """๋„๊ตฌ ๊ฒฐ๊ณผ๋Š” ํ…์ŠคํŠธ ์ฝ˜ํ…์ธ ๋กœ ๋Œ๋ ค์ค€๋‹ค. ์—์ด์ „ํŠธ๊ฐ€ JSON์„ ์ž˜ ์ฝ์œผ๋ฏ€๋กœ

    ๊ตฌ์กฐ๋ฅผ ๊ทธ๋Œ€๋กœ ์ง๋ ฌํ™”ํ•˜๋˜, ์‚ฌ๋žŒ์ด ๋กœ๊ทธ๋ฅผ ๋ณผ ๋•Œ๋„ ์ฝํžˆ๊ฒŒ ๋“ค์—ฌ์“ด๋‹ค."""
    return {"content": [{"type": "text",
                         "text": json.dumps(obj, ensure_ascii=False, indent=1)}]}


def tools(lang="ko"):
    """๋„๊ตฌ ๋ชฉ๋ก. ์„ค๋ช…์ด ์–ธ์–ด๋ฅผ ํƒ„๋‹ค โ€” ์—์ด์ „ํŠธ๋Š” ์ด ์„ค๋ช…์„ ์ฝ๊ณ  ํŒ๋‹จํ•œ๋‹ค."""
    out = []
    for t in TOOLS:
        d = dict(t)
        d["description"] = I.t(I.TOOLDESC.get(t["name"], t["description"]), lang)
        out.append(d)
    return out


def handle(body: Dict[str, Any], call, lang: str = "ko") -> Any:
    """call(name, args) -> dict ๋ฅผ ๋ฐ›์•„ ๋„๊ตฌ๋ฅผ ์‹ค์ œ๋กœ ์‹คํ–‰ํ•œ๋‹ค.



    ๋ฐ˜ํ™˜์ด None ์ด๋ฉด ์‘๋‹ต ์—†์Œ(notification)์ด๋ผ๋Š” ๋œป์ด๋‹ค.

    """
    method = body.get("method")
    rid = body.get("id")

    if method == "initialize":
        return _ok(rid, {
            "protocolVersion": PROTOCOL,
            "capabilities": {"tools": {"listChanged": False}},
            "serverInfo": SERVER,
            "instructions": I.t(I.MCP_INSTRUCTIONS, lang),
        })

    if method and method.startswith("notifications/"):
        return None                      # ์•Œ๋ฆผ์€ ์‘๋‹ตํ•˜์ง€ ์•Š๋Š”๋‹ค

    if method == "tools/list":
        return _ok(rid, {"tools": tools(lang)})

    if method == "tools/call":
        p = body.get("params") or {}
        name = p.get("name")
        args = p.get("arguments") or {}
        if not any(t["name"] == name for t in TOOLS):
            return _err(rid, -32602, "์•Œ ์ˆ˜ ์—†๋Š” ๋„๊ตฌ: %s" % name)
        try:
            return _ok(rid, _text(call(name, args)))
        except PermissionError as e:
            return _ok(rid, {"content": [{"type": "text", "text": str(e)}],
                             "isError": True})
        except Exception as e:
            return _ok(rid, {"content": [
                {"type": "text", "text": "%s: %s" % (type(e).__name__, e)}],
                "isError": True})

    if method == "ping":
        return _ok(rid, {})

    return _err(rid, -32601, "์ง€์›ํ•˜์ง€ ์•Š๋Š” ๋ฉ”์„œ๋“œ: %s" % method)