33from typing import Annotated
44
55import datetime
6- from mcp .server .fastmcp import Context
76
7+ from schwab_mcp .context import SchwabContext , SchwabServerContext
88from schwab_mcp .tools .registry import register
9- from schwab_mcp .tools .utils import call , get_context
9+ from schwab_mcp .tools .utils import call
1010
1111
1212def _parse_iso_datetime (value : str | None ) -> datetime .datetime | None :
@@ -15,7 +15,7 @@ def _parse_iso_datetime(value: str | None) -> datetime.datetime | None:
1515
1616@register
1717async def get_advanced_price_history (
18- ctx : Context ,
18+ ctx : SchwabContext ,
1919 symbol : Annotated [str , "Symbol of the security" ],
2020 period_type : Annotated [
2121 str | None , "Period type: DAY, MONTH, YEAR, YEAR_TO_DATE"
@@ -60,7 +60,7 @@ async def get_advanced_price_history(
6060 YEAR_TO_DATE: DAILY, WEEKLY (default)
6161 Dates must be in ISO format.
6262 """
63- context = get_context ( ctx )
63+ context : SchwabServerContext = ctx . request_context . lifespan_context
6464 client = context .price_history
6565
6666 start_dt = _parse_iso_datetime (start_datetime )
@@ -97,7 +97,7 @@ async def get_advanced_price_history(
9797
9898@register
9999async def get_price_history_every_minute (
100- ctx : Context ,
100+ ctx : SchwabContext ,
101101 symbol : Annotated [str , "Symbol of the security" ],
102102 start_datetime : Annotated [
103103 str | None , "Start date for history (ISO format, e.g., '2023-01-01T09:30:00')"
@@ -111,7 +111,7 @@ async def get_price_history_every_minute(
111111 """
112112 Get OHLCV price history per minute. For detailed intraday analysis. Max 48 days history. Dates ISO format.
113113 """
114- context = get_context ( ctx )
114+ context : SchwabServerContext = ctx . request_context . lifespan_context
115115 client = context .price_history
116116
117117 start_dt = _parse_iso_datetime (start_datetime )
@@ -129,7 +129,7 @@ async def get_price_history_every_minute(
129129
130130@register
131131async def get_price_history_every_five_minutes (
132- ctx : Context ,
132+ ctx : SchwabContext ,
133133 symbol : Annotated [str , "Symbol of the security" ],
134134 start_datetime : Annotated [
135135 str | None , "Start date for history (ISO format, e.g., '2023-01-01T09:30:00')"
@@ -143,7 +143,7 @@ async def get_price_history_every_five_minutes(
143143 """
144144 Get OHLCV price history per 5 minutes. Balance between detail and noise. Approx. 9 months history. Dates ISO format.
145145 """
146- context = get_context ( ctx )
146+ context : SchwabServerContext = ctx . request_context . lifespan_context
147147 client = context .price_history
148148
149149 start_dt = _parse_iso_datetime (start_datetime )
@@ -161,7 +161,7 @@ async def get_price_history_every_five_minutes(
161161
162162@register
163163async def get_price_history_every_ten_minutes (
164- ctx : Context ,
164+ ctx : SchwabContext ,
165165 symbol : Annotated [str , "Symbol of the security" ],
166166 start_datetime : Annotated [
167167 str | None , "Start date for history (ISO format, e.g., '2023-01-01T09:30:00')"
@@ -175,7 +175,7 @@ async def get_price_history_every_ten_minutes(
175175 """
176176 Get OHLCV price history per 10 minutes. Good for intraday trends/levels. Approx. 9 months history. Dates ISO format.
177177 """
178- context = get_context ( ctx )
178+ context : SchwabServerContext = ctx . request_context . lifespan_context
179179 client = context .price_history
180180
181181 start_dt = _parse_iso_datetime (start_datetime )
@@ -193,7 +193,7 @@ async def get_price_history_every_ten_minutes(
193193
194194@register
195195async def get_price_history_every_fifteen_minutes (
196- ctx : Context ,
196+ ctx : SchwabContext ,
197197 symbol : Annotated [str , "Symbol of the security" ],
198198 start_datetime : Annotated [
199199 str | None , "Start date for history (ISO format, e.g., '2023-01-01T09:30:00')"
@@ -207,7 +207,7 @@ async def get_price_history_every_fifteen_minutes(
207207 """
208208 Get OHLCV price history per 15 minutes. Shows significant intraday moves, filters noise. Approx. 9 months history. Dates ISO format.
209209 """
210- context = get_context ( ctx )
210+ context : SchwabServerContext = ctx . request_context . lifespan_context
211211 client = context .price_history
212212
213213 start_dt = _parse_iso_datetime (start_datetime )
@@ -225,7 +225,7 @@ async def get_price_history_every_fifteen_minutes(
225225
226226@register
227227async def get_price_history_every_thirty_minutes (
228- ctx : Context ,
228+ ctx : SchwabContext ,
229229 symbol : Annotated [str , "Symbol of the security" ],
230230 start_datetime : Annotated [
231231 str | None , "Start date for history (ISO format, e.g., '2023-01-01T09:30:00')"
@@ -239,7 +239,7 @@ async def get_price_history_every_thirty_minutes(
239239 """
240240 Get OHLCV price history per 30 minutes. For broader intraday trends, filters noise. Approx. 9 months history. Dates ISO format.
241241 """
242- context = get_context ( ctx )
242+ context : SchwabServerContext = ctx . request_context . lifespan_context
243243 client = context .price_history
244244
245245 start_dt = _parse_iso_datetime (start_datetime )
@@ -257,7 +257,7 @@ async def get_price_history_every_thirty_minutes(
257257
258258@register
259259async def get_price_history_every_day (
260- ctx : Context ,
260+ ctx : SchwabContext ,
261261 symbol : Annotated [str , "Symbol of the security to fetch price history for" ],
262262 start_datetime : Annotated [
263263 str | None ,
@@ -277,7 +277,7 @@ async def get_price_history_every_day(
277277 """
278278 Get daily OHLCV price history. For medium/long-term analysis. Extensive history (back to 1985 possible). Dates ISO format.
279279 """
280- context = get_context ( ctx )
280+ context : SchwabServerContext = ctx . request_context . lifespan_context
281281 client = context .price_history
282282
283283 start_dt = _parse_iso_datetime (start_datetime )
@@ -295,7 +295,7 @@ async def get_price_history_every_day(
295295
296296@register
297297async def get_price_history_every_week (
298- ctx : Context ,
298+ ctx : SchwabContext ,
299299 symbol : Annotated [str , "Symbol of the security" ],
300300 start_datetime : Annotated [
301301 str | None , "Start date for history (ISO format, e.g., '2023-01-01T00:00:00')"
@@ -309,7 +309,7 @@ async def get_price_history_every_week(
309309 """
310310 Get weekly OHLCV price history. For long-term analysis, major cycles. Extensive history (back to 1985 possible). Dates ISO format.
311311 """
312- context = get_context ( ctx )
312+ context : SchwabServerContext = ctx . request_context . lifespan_context
313313 client = context .price_history
314314
315315 start_dt = _parse_iso_datetime (start_datetime )
0 commit comments