@@ -535,19 +535,25 @@ def tool(
535535 - If False, unconditionally creates an unstructured tool
536536
537537 Example:
538+ ```python
538539 @server.tool()
539540 def my_tool(x: int) -> str:
540541 return str(x)
542+ ```
541543
544+ ```python
542545 @server.tool()
543546 async def tool_with_context(x: int, ctx: Context) -> str:
544547 await ctx.info(f"Processing {x}")
545548 return str(x)
549+ ```
546550
551+ ```python
547552 @server.tool()
548553 async def async_tool(x: int, context: Context) -> str:
549554 await context.report_progress(50, 100)
550555 return str(x)
556+ ```
551557 """
552558 # Check if user passed function directly instead of calling decorator
553559 if callable (name ):
@@ -579,12 +585,14 @@ def completion(self):
579585 - context: Optional CompletionContext with previously resolved arguments
580586
581587 Example:
588+ ```python
582589 @mcp.completion()
583590 async def handle_completion(ref, argument, context):
584591 if isinstance(ref, ResourceTemplateReference):
585592 # Return completions based on ref, argument, and context
586593 return Completion(values=["option1", "option2"])
587594 return None
595+ ```
588596 """
589597
590598 def decorator (func : _CallableT ) -> _CallableT :
@@ -647,6 +655,7 @@ def resource(
647655 meta: Optional metadata dictionary for the resource
648656
649657 Example:
658+ ```python
650659 @server.resource("resource://my-resource")
651660 def get_data() -> str:
652661 return "Hello, world!"
@@ -664,6 +673,7 @@ def get_weather(city: str) -> str:
664673 async def get_weather(city: str) -> str:
665674 data = await fetch_weather(city)
666675 return f"Weather for {city}: {data}"
676+ ```
667677 """
668678 # Check if user passed function directly instead of calling decorator
669679 if callable (uri ):
@@ -747,6 +757,7 @@ def prompt(
747757 icons: Optional list of icons for the prompt
748758
749759 Example:
760+ ```python
750761 @server.prompt()
751762 def analyze_table(table_name: str) -> list[Message]:
752763 schema = read_table_schema(table_name)
@@ -772,6 +783,7 @@ async def analyze_file(path: str) -> list[Message]:
772783 }
773784 }
774785 ]
786+ ```
775787 """
776788 # Check if user passed function directly instead of calling decorator
777789 if callable (name ):
@@ -813,9 +825,11 @@ def custom_route(
813825 include_in_schema: Whether to include in OpenAPI schema, defaults to True
814826
815827 Example:
828+ ```python
816829 @server.custom_route("/health", methods=["GET"])
817830 async def health_check(request: Request) -> Response:
818831 return JSONResponse({"status": "ok"})
832+ ```
819833 """
820834
821835 def decorator ( # pragma: no cover
0 commit comments