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
Copy file name to clipboardExpand all lines: asciidoc/courses/genai-mcp-build-custom-tools-python/modules/2-database-features/lessons/1-connecting-neo4j/lesson.adoc
+14-2Lines changed: 14 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -46,9 +46,14 @@ FastMCP provides a **lifespan** feature that allows you to:
46
46
47
47
=== The Lifespan Context Manager
48
48
49
-
A lifespan function is an async context manager that yields a context object containing your initialized resources:
49
+
To share objects across the server, we can create a function that initializes resources when the server starts and cleans them up when it shuts down.
50
+
51
+
The function yields an object that contains the FastMCP server will make available to any tools and resources that request it.
52
+
53
+
Let's take a look at a full example:
50
54
51
55
[source,python]
56
+
.Full lifespan example
52
57
----
53
58
import os
54
59
from collections.abc import AsyncIterator
@@ -138,6 +143,7 @@ For your MCP server, you will need to define a context class that holds the Neo4
0 commit comments