FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
python-sdk/docs_src/asgi/tutorial005.py at main · modelcontextprotocol/python-sdk · GitHub
modelcontextprotocol
python-sdk
Repository navigation
Code
Issues
246
(246)
Pull requests
106
(106)
Actions
Projects
Security and quality
12
(12)
Insights
Expand file tree
Breadcrumbs
python-sdk
/
docs_src
/
asgi
/
tutorial005.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
52 lines (42 loc) · 1.38 KB
Breadcrumbs
python-sdk
/
docs_src
/
asgi
/
tutorial005.py
Copy path
File metadata and controls
52 lines (42 loc) · 1.38 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
51
52
from
collections
.
abc
import
AsyncIterator
from
contextlib
import
asynccontextmanager
from
starlette
.
applications
import
Starlette
from
starlette
.
middleware
import
Middleware
from
starlette
.
middleware
.
cors
import
CORSMiddleware
from
starlette
.
routing
import
Mount
from
mcp
.
server
import
MCPServer
from
mcp
.
server
.
transport_security
import
TransportSecuritySettings
mcp
=
MCPServer
(
"Notes"
)
@
mcp
.
tool
()
def
add_note
(
text
:
str
)
->
str
:
"""Save a note."""
return
f"Saved:
{
text
}
"
@
asynccontextmanager
async
def
lifespan
(
app
:
Starlette
)
->
AsyncIterator
[
None
]:
async
with
mcp
.
session_manager
.
run
():
yield
security
=
TransportSecuritySettings
(
allowed_hosts
=
[
"mcp.example.com"
,
"mcp.example.com:*"
],
allowed_origins
=
[
"https://app.example.com"
],
)
app
=
Starlette
(
routes
=
[
Mount
(
"/"
,
app
=
mcp
.
streamable_http_app
(
transport_security
=
security
))],
middleware
=
[
Middleware
(
CORSMiddleware
,
allow_origins
=
[
"https://app.example.com"
],
allow_methods
=
[
"GET"
,
"POST"
,
"DELETE"
],
allow_headers
=
[
"Authorization"
,
"Content-Type"
,
"Last-Event-ID"
,
"Mcp-Method"
,
"Mcp-Name"
,
"Mcp-Protocol-Version"
,
"Mcp-Session-Id"
,
],
expose_headers
=
[
"Mcp-Session-Id"
],
)
],
lifespan
=
lifespan
,
)
Back
|
FazBrowse Home
|
New Git URL