MCPcopy Index your code
hub / github.com/modelcontextprotocol/python-sdk / echo

Function echo

examples/mcpserver/logging_and_progress.py:12–31  ·  view source on GitHub ↗

Echo the input text sending log messages and progress updates during processing.

(text: str, ctx: Context)

Source from the content-addressed store, hash-verified

10
11@mcp.tool()
12async def echo(text: str, ctx: Context) -> str:
13 """Echo the input text sending log messages and progress updates during processing."""
14 await ctx.report_progress(progress=0, total=100)
15 await ctx.info("Starting to process echo for input: " + text)
16
17 await asyncio.sleep(2)
18
19 await ctx.info("Halfway through processing echo for input: " + text)
20 await ctx.report_progress(progress=50, total=100)
21
22 await asyncio.sleep(2)
23
24 await ctx.info("Finished processing echo for input: " + text)
25 await ctx.report_progress(progress=100, total=100)
26
27 # Progress notifications are process asynchronously by the client.
28 # A small delay here helps ensure the last notification is processed by the client.
29 await asyncio.sleep(0.1)
30
31 return text

Callers

nothing calls this directly

Calls 2

infoMethod · 0.80
report_progressMethod · 0.45

Tested by

no test coverage detected