From edd8ea1280e45a9fdf94beaa1295c885259c0589 Mon Sep 17 00:00:00 2001 From: Really Him Date: Sat, 24 May 2025 10:27:51 -0400 Subject: [PATCH 1/3] docs: fix incorrect usage example re get_context() --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 26f43cfd9..21821e615 100644 --- a/README.md +++ b/README.md @@ -631,7 +631,7 @@ server = Server("example-server", lifespan=server_lifespan) # Access lifespan context in handlers @server.call_tool() async def query_db(name: str, arguments: dict) -> list: - ctx = server.get_context() + ctx = server.request_context db = ctx.lifespan_context["db"] return await db.query(arguments["query"]) ``` From 759f2768466dded57340f27563dbcc834d411e84 Mon Sep 17 00:00:00 2001 From: Really Him Date: Sat, 24 May 2025 11:40:38 -0400 Subject: [PATCH 2/3] fix: fix problem with get_context example --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 21821e615..f81771c69 100644 --- a/README.md +++ b/README.md @@ -192,9 +192,10 @@ mcp = FastMCP("My App", lifespan=app_lifespan) # Access type-safe lifespan context in tools @mcp.tool() -def query_db(ctx: Context) -> str: +def query_db() -> str: """Tool that uses initialized resources""" - db = ctx.request_context.lifespan_context.db + ctx = mcp.get_context() + db = ctx.request_context.lifespan_context["db"] return db.query() ``` From f9a08e8dbb98a214b288c275ef1867ad6ba96c75 Mon Sep 17 00:00:00 2001 From: Really Him Date: Sat, 24 May 2025 11:50:07 -0400 Subject: [PATCH 3/3] lint: removed unused import --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f81771c69..4c8bb90dc 100644 --- a/README.md +++ b/README.md @@ -160,7 +160,7 @@ from dataclasses import dataclass from fake_database import Database # Replace with your actual DB type -from mcp.server.fastmcp import Context, FastMCP +from mcp.server.fastmcp import FastMCP # Create a named server mcp = FastMCP("My App")