FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
python-sdk/tests/issues/test_355_type_error.py at main · amoycode/python-sdk · GitHub
amoycode
/
python-sdk
Public
forked from
modelcontextprotocol/python-sdk
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
python-sdk
/
tests
/
issues
/
test_355_type_error.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
50 lines (35 loc) · 1.08 KB
Breadcrumbs
python-sdk
/
tests
/
issues
/
test_355_type_error.py
Copy path
File metadata and controls
50 lines (35 loc) · 1.08 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
from
collections
.
abc
import
AsyncIterator
from
contextlib
import
asynccontextmanager
from
dataclasses
import
dataclass
from
mcp
.
server
.
fastmcp
import
Context
,
FastMCP
class
Database
:
# Replace with your actual DB type
@
classmethod
async
def
connect
(
cls
):
return
cls
()
async
def
disconnect
(
self
):
pass
def
query
(
self
):
return
"Hello, World!"
# Create a named server
mcp
=
FastMCP
(
"My App"
)
@
dataclass
class
AppContext
:
db
:
Database
@
asynccontextmanager
async
def
app_lifespan
(
server
:
FastMCP
)
->
AsyncIterator
[
AppContext
]:
"""Manage application lifecycle with type-safe context"""
# Initialize on startup
db
=
await
Database
.
connect
()
try
:
yield
AppContext
(
db
=
db
)
finally
:
# Cleanup on shutdown
await
db
.
disconnect
()
# Pass lifespan to server
mcp
=
FastMCP
(
"My App"
,
lifespan
=
app_lifespan
)
# Access type-safe lifespan context in tools
@
mcp
.
tool
()
def
query_db
(
ctx
:
Context
)
->
str
:
"""Tool that uses initialized resources"""
db
=
ctx
.
request_context
.
lifespan_context
.
db
return
db
.
query
()
Back
|
FazBrowse Home
|
New Git URL