20
20
from fastapi import FastAPI , Request
21
21
from mcp .server import FastMCP
22
22
from mcp .server .fastmcp import Context
23
- from mcp .server .session import ServerSessionT
24
23
from pydantic import Field
25
24
from starlette .datastructures import QueryParams
26
25
from uvicorn import Config , Server
@@ -120,12 +119,12 @@ async def app_lifespan(_server: FastMCP) -> AsyncIterator[AppContext]:
120
119
121
120
@mcp .tool ()
122
121
async def open_note (
123
- ctx : Context [ ServerSessionT , AppContext ] ,
122
+ ctx : Context ,
124
123
id : str | None = Field (description = "note unique identifier" , default = None ),
125
124
title : str | None = Field (description = "note title" , default = None ),
126
125
) -> str :
127
126
"""Open a note identified by its title or id and return its content."""
128
- app_ctx = ctx .request_context .lifespan_context
127
+ app_ctx : AppContext = ctx .request_context .lifespan_context # type: ignore
129
128
future = Future [QueryParams ]()
130
129
await app_ctx .open_note_results .put (future )
131
130
@@ -152,14 +151,14 @@ async def open_note(
152
151
153
152
@mcp .tool ()
154
153
async def create (
155
- ctx : Context [ ServerSessionT , AppContext ] ,
154
+ ctx : Context ,
156
155
title : str | None = Field (description = "note title" , default = None ),
157
156
text : str | None = Field (description = "note body" , default = None ),
158
157
tags : list [str ] | None = Field (description = "list of tags" , default = None ),
159
158
timestamp : bool = Field (description = "prepend the current date and time to the text" , default = False ),
160
159
) -> str :
161
160
"""Create a new note and return its unique identifier. Empty notes are not allowed."""
162
- app_ctx = ctx .request_context .lifespan_context
161
+ app_ctx : AppContext = ctx .request_context .lifespan_context # type: ignore
163
162
future = Future [QueryParams ]()
164
163
await app_ctx .create_results .put (future )
165
164
@@ -187,10 +186,10 @@ async def create(
187
186
188
187
@mcp .tool ()
189
188
async def tags (
190
- ctx : Context [ ServerSessionT , AppContext ] ,
189
+ ctx : Context ,
191
190
) -> list [str ]:
192
191
"""Return all the tags currently displayed in Bear’s sidebar."""
193
- app_ctx = ctx .request_context .lifespan_context
192
+ app_ctx : AppContext = ctx .request_context .lifespan_context # type: ignore
194
193
future = Future [QueryParams ]()
195
194
await app_ctx .tags_results .put (future )
196
195
@@ -208,11 +207,11 @@ async def tags(
208
207
209
208
@mcp .tool ()
210
209
async def open_tag (
211
- ctx : Context [ ServerSessionT , AppContext ] ,
210
+ ctx : Context ,
212
211
name : str = Field (description = "tag name or a list of tags divided by comma" ),
213
212
) -> list [str ]:
214
213
"""Show all the notes which have a selected tag in bear."""
215
- app_ctx = ctx .request_context .lifespan_context
214
+ app_ctx : AppContext = ctx .request_context .lifespan_context # type: ignore
216
215
future = Future [QueryParams ]()
217
216
await app_ctx .open_tag_results .put (future )
218
217
@@ -231,11 +230,11 @@ async def open_tag(
231
230
232
231
@mcp .tool ()
233
232
async def todo (
234
- ctx : Context [ ServerSessionT , AppContext ] ,
233
+ ctx : Context ,
235
234
search : str | None = Field (description = "string to search" , default = None ),
236
235
) -> list [str ]:
237
236
"""Select the Todo sidebar item."""
238
- app_ctx = ctx .request_context .lifespan_context
237
+ app_ctx : AppContext = ctx .request_context .lifespan_context # type: ignore
239
238
future = Future [QueryParams ]()
240
239
await app_ctx .todo_results .put (future )
241
240
@@ -256,11 +255,11 @@ async def todo(
256
255
257
256
@mcp .tool ()
258
257
async def today (
259
- ctx : Context [ ServerSessionT , AppContext ] ,
258
+ ctx : Context ,
260
259
search : str | None = Field (description = "string to search" , default = None ),
261
260
) -> list [str ]:
262
261
"""Select the Today sidebar item."""
263
- app_ctx = ctx .request_context .lifespan_context
262
+ app_ctx : AppContext = ctx .request_context .lifespan_context # type: ignore
264
263
future = Future [QueryParams ]()
265
264
await app_ctx .today_results .put (future )
266
265
@@ -281,12 +280,12 @@ async def today(
281
280
282
281
@mcp .tool ()
283
282
async def search (
284
- ctx : Context [ ServerSessionT , AppContext ] ,
283
+ ctx : Context ,
285
284
term : str | None = Field (description = "string to search" , default = None ),
286
285
tag : str | None = Field (description = "tag to search into" , default = None ),
287
286
) -> list [str ]:
288
287
"""Show search results in Bear for all notes or for a specific tag."""
289
- app_ctx = ctx .request_context .lifespan_context
288
+ app_ctx : AppContext = ctx .request_context .lifespan_context # type: ignore
290
289
future = Future [QueryParams ]()
291
290
await app_ctx .search_results .put (future )
292
291
@@ -309,15 +308,15 @@ async def search(
309
308
310
309
@mcp .tool ()
311
310
async def grab_url (
312
- ctx : Context [ ServerSessionT , AppContext ] ,
311
+ ctx : Context ,
313
312
url : str = Field (description = "url to grab" ),
314
313
tags : list [str ] | None = Field (
315
314
description = "list of tags. If tags are specified in the Bear’s web content preferences, this parameter is ignored." ,
316
315
default = None ,
317
316
),
318
317
) -> str :
319
318
"""Create a new note with the content of a web page and return its unique identifier."""
320
- app_ctx = ctx .request_context .lifespan_context
319
+ app_ctx : AppContext = ctx .request_context .lifespan_context # type: ignore
321
320
future = Future [QueryParams ]()
322
321
await app_ctx .grab_url_results .put (future )
323
322
0 commit comments