Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

streamable_http_client.py 1.4KB

123456789101112131415161718192021222324252627282930313233343536
  1. #
  2. # Copyright 2025 The InfiniFlow Authors. All Rights Reserved.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. #
  16. from mcp import ClientSession
  17. from mcp.client.streamable_http import streamablehttp_client
  18. async def main():
  19. try:
  20. async with streamablehttp_client("http://localhost:9382/mcp/") as (read_stream, write_stream, _):
  21. async with ClientSession(read_stream, write_stream) as session:
  22. await session.initialize()
  23. tools = await session.list_tools()
  24. print(f"{tools.tools=}")
  25. response = await session.call_tool(name="ragflow_retrieval", arguments={"dataset_ids": ["bc4177924a7a11f09eff238aa5c10c94"], "document_ids": [], "question": "How to install neovim?"})
  26. print(f"Tool response: {response.model_dump()}")
  27. except Exception as e:
  28. print(e)
  29. if __name__ == "__main__":
  30. from anyio import run
  31. run(main)