|
3 | 3 | from typing import Annotated |
4 | 4 |
|
5 | 5 | import datetime |
| 6 | +from mcp.server.fastmcp import FastMCP |
6 | 7 |
|
7 | 8 | from schwab_mcp.context import SchwabContext, SchwabServerContext |
8 | | -from schwab_mcp.tools.registry import register |
| 9 | +from schwab_mcp.tools._registration import register_tool |
9 | 10 | from schwab_mcp.tools.utils import JSONType, call |
10 | 11 |
|
11 | 12 |
|
12 | 13 | def _parse_iso_datetime(value: str | None) -> datetime.datetime | None: |
13 | 14 | return datetime.datetime.fromisoformat(value) if value is not None else None |
14 | 15 |
|
15 | 16 |
|
16 | | -@register |
17 | 17 | async def get_advanced_price_history( |
18 | 18 | ctx: SchwabContext, |
19 | 19 | symbol: Annotated[str, "Symbol of the security"], |
@@ -95,7 +95,6 @@ async def get_advanced_price_history( |
95 | 95 | ) |
96 | 96 |
|
97 | 97 |
|
98 | | -@register |
99 | 98 | async def get_price_history_every_minute( |
100 | 99 | ctx: SchwabContext, |
101 | 100 | symbol: Annotated[str, "Symbol of the security"], |
@@ -127,7 +126,6 @@ async def get_price_history_every_minute( |
127 | 126 | ) |
128 | 127 |
|
129 | 128 |
|
130 | | -@register |
131 | 129 | async def get_price_history_every_five_minutes( |
132 | 130 | ctx: SchwabContext, |
133 | 131 | symbol: Annotated[str, "Symbol of the security"], |
@@ -159,7 +157,6 @@ async def get_price_history_every_five_minutes( |
159 | 157 | ) |
160 | 158 |
|
161 | 159 |
|
162 | | -@register |
163 | 160 | async def get_price_history_every_ten_minutes( |
164 | 161 | ctx: SchwabContext, |
165 | 162 | symbol: Annotated[str, "Symbol of the security"], |
@@ -191,7 +188,6 @@ async def get_price_history_every_ten_minutes( |
191 | 188 | ) |
192 | 189 |
|
193 | 190 |
|
194 | | -@register |
195 | 191 | async def get_price_history_every_fifteen_minutes( |
196 | 192 | ctx: SchwabContext, |
197 | 193 | symbol: Annotated[str, "Symbol of the security"], |
@@ -223,7 +219,6 @@ async def get_price_history_every_fifteen_minutes( |
223 | 219 | ) |
224 | 220 |
|
225 | 221 |
|
226 | | -@register |
227 | 222 | async def get_price_history_every_thirty_minutes( |
228 | 223 | ctx: SchwabContext, |
229 | 224 | symbol: Annotated[str, "Symbol of the security"], |
@@ -255,7 +250,6 @@ async def get_price_history_every_thirty_minutes( |
255 | 250 | ) |
256 | 251 |
|
257 | 252 |
|
258 | | -@register |
259 | 253 | async def get_price_history_every_day( |
260 | 254 | ctx: SchwabContext, |
261 | 255 | symbol: Annotated[str, "Symbol of the security to fetch price history for"], |
@@ -293,7 +287,6 @@ async def get_price_history_every_day( |
293 | 287 | ) |
294 | 288 |
|
295 | 289 |
|
296 | | -@register |
297 | 290 | async def get_price_history_every_week( |
298 | 291 | ctx: SchwabContext, |
299 | 292 | symbol: Annotated[str, "Symbol of the security"], |
@@ -323,3 +316,21 @@ async def get_price_history_every_week( |
323 | 316 | need_extended_hours_data=extended_hours, |
324 | 317 | need_previous_close=previous_close, |
325 | 318 | ) |
| 319 | + |
| 320 | + |
| 321 | +_READ_ONLY_TOOLS = ( |
| 322 | + get_advanced_price_history, |
| 323 | + get_price_history_every_minute, |
| 324 | + get_price_history_every_five_minutes, |
| 325 | + get_price_history_every_ten_minutes, |
| 326 | + get_price_history_every_fifteen_minutes, |
| 327 | + get_price_history_every_thirty_minutes, |
| 328 | + get_price_history_every_day, |
| 329 | + get_price_history_every_week, |
| 330 | +) |
| 331 | + |
| 332 | + |
| 333 | +def register(server: FastMCP, *, allow_write: bool) -> None: |
| 334 | + _ = allow_write |
| 335 | + for func in _READ_ONLY_TOOLS: |
| 336 | + register_tool(server, func) |
0 commit comments