You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 543c733
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: docs/handlers/lifespan.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -41,7 +41,7 @@ Nothing new. `ctx` is a **Context** parameter, so the SDK injects it and it neve
41
41
42
42
`genre` is the only argument the model can pass. The lifespan is your server's business.
43
43
44
-
`@mcp.resource()` and `@mcp.prompt()`functions can take the same typed `ctx` parameter. Everything `ctx` carries is in **[The Context](context.md)**.
44
+
URI-template `@mcp.resource("scheme://{param}")`handlers and `@mcp.prompt()`handlers can take the same typed `ctx` parameter. Static resources cannot accept `Context` because context injection is available only for resource templates. Everything `ctx` carries is in **[The Context](context.md)**.
45
45
46
46
### It really is typed
47
47
@@ -82,8 +82,8 @@ Strip the server down to the lifecycle: give `Database` a `connected` flag, flip
82
82
*`lifespan=` takes an `@asynccontextmanager` that receives the server and `yield`s one object.
83
83
* Code before the `yield` is startup. The `finally` after it is shutdown.
84
84
* It runs once, around the whole life of the server, not per request.
85
-
* Whatever you `yield` is `ctx.request_context.lifespan_context` in every tool, resource, and prompt.
86
-
*`ctx: Context[AppContext]` makes that access fully typed in tools, resources, and prompts.
85
+
* Whatever you `yield` is `ctx.request_context.lifespan_context` in every tool, resource-template, and prompt handler that accepts `ctx`.
86
+
*`ctx: Context[AppContext]` makes that access fully typed in tools, resource templates, and prompts. Static resources cannot accept `ctx`.
87
87
* No `lifespan=` means an empty `dict`, never `None`.
88
88
89
89
A handler that stops mid-call to ask the user for something only they know is **[Elicitation](elicitation.md)**.
0 commit comments