Client auto-resolves InputRequiredResult via existing callbacks (SEP-2322) (#2998)
This commit is contained in:
parent
3945bdde11
commit
08b62308d4
2 changed files with 1258 additions and 202 deletions
|
|
@ -10,10 +10,10 @@ def fulfil(request: InputRequest) -> InputResponse:
|
|||
|
||||
|
||||
async def provision(client: Client, name: str) -> CallToolResult:
|
||||
result = await client.call_tool("provision", {"name": name}, allow_input_required=True)
|
||||
result = await client.session.call_tool("provision", {"name": name}, allow_input_required=True)
|
||||
while isinstance(result, InputRequiredResult):
|
||||
responses = {key: fulfil(request) for key, request in (result.input_requests or {}).items()}
|
||||
result = await client.call_tool(
|
||||
result = await client.session.call_tool(
|
||||
"provision",
|
||||
{"name": name},
|
||||
input_responses=responses,
|
||||
|
|
|
|||
14
docs_src/mrtr/tutorial003.py
Normal file
14
docs_src/mrtr/tutorial003.py
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
from mcp_types import ElicitRequestParams, ElicitResult
|
||||
|
||||
from mcp import Client
|
||||
from mcp.client import ClientRequestContext
|
||||
|
||||
|
||||
async def handle_elicitation(context: ClientRequestContext, params: ElicitRequestParams) -> ElicitResult:
|
||||
return ElicitResult(action="accept", content={"region": "eu-west-1"})
|
||||
|
||||
|
||||
async def main() -> None:
|
||||
async with Client("http://127.0.0.1:8000/mcp", elicitation_callback=handle_elicitation) as client:
|
||||
result = await client.call_tool("provision", {"name": "orders"})
|
||||
print(result.content)
|
||||
Loading…
Reference in a new issue