mcp-use 1.3.9__tar.gz → 1.3.11__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of mcp-use might be problematic. Click here for more details.

Files changed (191) hide show
  1. {mcp_use-1.3.9 → mcp_use-1.3.11}/.github/workflows/tests.yml +1 -1
  2. {mcp_use-1.3.9 → mcp_use-1.3.11}/PKG-INFO +22 -26
  3. {mcp_use-1.3.9 → mcp_use-1.3.11}/README.md +19 -24
  4. mcp_use-1.3.11/docs/agent/interactive-chat-patterns.mdx +272 -0
  5. {mcp_use-1.3.9 → mcp_use-1.3.11}/docs/agent/server-manager.mdx +52 -0
  6. mcp_use-1.3.11/docs/changelog/1_3_11.mdx +73 -0
  7. {mcp_use-1.3.9/docs → mcp_use-1.3.11/docs/changelog}/changelog.mdx +11 -0
  8. mcp_use-1.3.11/docs/client/authentication.mdx +417 -0
  9. {mcp_use-1.3.9 → mcp_use-1.3.11}/docs/docs.json +13 -4
  10. mcp_use-1.3.11/docs/images/Release1.3.11.png +0 -0
  11. mcp_use-1.3.11/examples/simple_oauth_example.py +37 -0
  12. mcp_use-1.3.11/examples/simple_server_manager_use.py +112 -0
  13. {mcp_use-1.3.9 → mcp_use-1.3.11}/mcp_use/__init__.py +6 -2
  14. {mcp_use-1.3.9 → mcp_use-1.3.11}/mcp_use/adapters/langchain_adapter.py +7 -5
  15. {mcp_use-1.3.9 → mcp_use-1.3.11}/mcp_use/agents/mcpagent.py +115 -19
  16. {mcp_use-1.3.9 → mcp_use-1.3.11}/mcp_use/agents/prompts/templates.py +1 -10
  17. {mcp_use-1.3.9 → mcp_use-1.3.11}/mcp_use/agents/remote.py +50 -19
  18. mcp_use-1.3.11/mcp_use/auth/__init__.py +6 -0
  19. mcp_use-1.3.11/mcp_use/auth/bearer.py +17 -0
  20. mcp_use-1.3.11/mcp_use/auth/oauth.py +625 -0
  21. mcp_use-1.3.11/mcp_use/auth/oauth_callback.py +214 -0
  22. mcp_use-1.3.11/mcp_use/cli.py +581 -0
  23. {mcp_use-1.3.9 → mcp_use-1.3.11}/mcp_use/client.py +1 -1
  24. {mcp_use-1.3.9 → mcp_use-1.3.11}/mcp_use/config.py +2 -2
  25. {mcp_use-1.3.9 → mcp_use-1.3.11}/mcp_use/connectors/base.py +17 -12
  26. {mcp_use-1.3.9 → mcp_use-1.3.11}/mcp_use/connectors/http.py +117 -21
  27. {mcp_use-1.3.9 → mcp_use-1.3.11}/mcp_use/connectors/websocket.py +14 -5
  28. mcp_use-1.3.11/mcp_use/exceptions.py +31 -0
  29. {mcp_use-1.3.9 → mcp_use-1.3.11}/mcp_use/logging.py +27 -12
  30. mcp_use-1.3.11/mcp_use/managers/base.py +36 -0
  31. {mcp_use-1.3.9 → mcp_use-1.3.11}/mcp_use/managers/server_manager.py +2 -1
  32. mcp_use-1.3.11/mcp_use/observability/__init__.py +9 -0
  33. mcp_use-1.3.11/mcp_use/observability/callbacks_manager.py +162 -0
  34. mcp_use-1.3.11/mcp_use/observability/laminar.py +42 -0
  35. mcp_use-1.3.11/mcp_use/observability/langfuse.py +59 -0
  36. {mcp_use-1.3.9 → mcp_use-1.3.11}/mcp_use/task_managers/base.py +13 -23
  37. {mcp_use-1.3.9 → mcp_use-1.3.11}/mcp_use/task_managers/sse.py +5 -0
  38. {mcp_use-1.3.9 → mcp_use-1.3.11}/mcp_use/task_managers/streamable_http.py +5 -0
  39. {mcp_use-1.3.9 → mcp_use-1.3.11}/pyproject.toml +6 -2
  40. {mcp_use-1.3.9 → mcp_use-1.3.11}/tests/integration/conftest.py +30 -0
  41. mcp_use-1.3.11/tests/integration/primitives/test_auth.py +200 -0
  42. mcp_use-1.3.11/tests/integration/servers_for_testing/auth_server.py +140 -0
  43. {mcp_use-1.3.9 → mcp_use-1.3.11}/tests/unit/test_config.py +10 -10
  44. mcp_use-1.3.11/tests/unit/test_enum_handling.py +109 -0
  45. {mcp_use-1.3.9 → mcp_use-1.3.11}/tests/unit/test_http_connector.py +9 -7
  46. mcp_use-1.3.9/mcp_use/observability/__init__.py +0 -8
  47. mcp_use-1.3.9/mcp_use/observability/laminar.py +0 -21
  48. mcp_use-1.3.9/mcp_use/observability/langfuse.py +0 -35
  49. mcp_use-1.3.9/tests/unit/test_logging.py +0 -117
  50. {mcp_use-1.3.9 → mcp_use-1.3.11}/.env.example +0 -0
  51. {mcp_use-1.3.9 → mcp_use-1.3.11}/.github/ISSUE_TEMPLATE/bug_report.md +0 -0
  52. {mcp_use-1.3.9 → mcp_use-1.3.11}/.github/pull_request_template.md +0 -0
  53. {mcp_use-1.3.9 → mcp_use-1.3.11}/.github/release-drafter.yml +0 -0
  54. {mcp_use-1.3.9 → mcp_use-1.3.11}/.github/workflows/changelog.yml +0 -0
  55. {mcp_use-1.3.9 → mcp_use-1.3.11}/.github/workflows/publish.yml +0 -0
  56. {mcp_use-1.3.9 → mcp_use-1.3.11}/.github/workflows/release-drafter.yml +0 -0
  57. {mcp_use-1.3.9 → mcp_use-1.3.11}/.github/workflows/stale.yml +0 -0
  58. {mcp_use-1.3.9 → mcp_use-1.3.11}/.github/workflows/update-readme.yml +0 -0
  59. {mcp_use-1.3.9 → mcp_use-1.3.11}/.gitignore +0 -0
  60. {mcp_use-1.3.9 → mcp_use-1.3.11}/.pre-commit-config.yaml +0 -0
  61. {mcp_use-1.3.9 → mcp_use-1.3.11}/CHANGELOG.md +0 -0
  62. {mcp_use-1.3.9 → mcp_use-1.3.11}/CLAUDE.md +0 -0
  63. {mcp_use-1.3.9 → mcp_use-1.3.11}/CODE_OF_CONDUCT.md +0 -0
  64. {mcp_use-1.3.9 → mcp_use-1.3.11}/CONTRIBUTING.md +0 -0
  65. {mcp_use-1.3.9 → mcp_use-1.3.11}/LICENSE +0 -0
  66. {mcp_use-1.3.9 → mcp_use-1.3.11}/docs/README.md +0 -0
  67. {mcp_use-1.3.9 → mcp_use-1.3.11}/docs/advanced/building-custom-agents.mdx +0 -0
  68. {mcp_use-1.3.9 → mcp_use-1.3.11}/docs/advanced/logging.mdx +0 -0
  69. {mcp_use-1.3.9 → mcp_use-1.3.11}/docs/advanced/multi-server-setup.mdx +0 -0
  70. {mcp_use-1.3.9 → mcp_use-1.3.11}/docs/advanced/security.mdx +0 -0
  71. {mcp_use-1.3.9 → mcp_use-1.3.11}/docs/agent/agent-configuration.mdx +0 -0
  72. {mcp_use-1.3.9 → mcp_use-1.3.11}/docs/agent/llm-integration.mdx +0 -0
  73. {mcp_use-1.3.9 → mcp_use-1.3.11}/docs/agent/streaming.mdx +0 -0
  74. {mcp_use-1.3.9 → mcp_use-1.3.11}/docs/agent/structured-output.mdx +0 -0
  75. {mcp_use-1.3.9 → mcp_use-1.3.11}/docs/api-reference/adapters.mdx +0 -0
  76. {mcp_use-1.3.9 → mcp_use-1.3.11}/docs/api-reference/introduction.mdx +0 -0
  77. {mcp_use-1.3.9 → mcp_use-1.3.11}/docs/api-reference/mcpagent.mdx +0 -0
  78. {mcp_use-1.3.9 → mcp_use-1.3.11}/docs/api-reference/mcpclient.mdx +0 -0
  79. {mcp_use-1.3.9 → mcp_use-1.3.11}/docs/client/client-configuration.mdx +0 -0
  80. {mcp_use-1.3.9 → mcp_use-1.3.11}/docs/client/connection-types.mdx +0 -0
  81. {mcp_use-1.3.9 → mcp_use-1.3.11}/docs/client/direct-tool-calls.mdx +0 -0
  82. {mcp_use-1.3.9 → mcp_use-1.3.11}/docs/client/elicitation.mdx +0 -0
  83. {mcp_use-1.3.9 → mcp_use-1.3.11}/docs/client/logging.mdx +0 -0
  84. {mcp_use-1.3.9 → mcp_use-1.3.11}/docs/client/notifications.mdx +0 -0
  85. {mcp_use-1.3.9 → mcp_use-1.3.11}/docs/client/prompts.mdx +0 -0
  86. {mcp_use-1.3.9 → mcp_use-1.3.11}/docs/client/resources.mdx +0 -0
  87. {mcp_use-1.3.9 → mcp_use-1.3.11}/docs/client/sampling.mdx +0 -0
  88. {mcp_use-1.3.9 → mcp_use-1.3.11}/docs/client/sandbox.mdx +0 -0
  89. {mcp_use-1.3.9 → mcp_use-1.3.11}/docs/client/tools.mdx +0 -0
  90. {mcp_use-1.3.9 → mcp_use-1.3.11}/docs/community/showcase.mdx +0 -0
  91. {mcp_use-1.3.9 → mcp_use-1.3.11}/docs/development/observability.mdx +0 -0
  92. {mcp_use-1.3.9 → mcp_use-1.3.11}/docs/development/telemetry.mdx +0 -0
  93. {mcp_use-1.3.9 → mcp_use-1.3.11}/docs/development.mdx +0 -0
  94. {mcp_use-1.3.9 → mcp_use-1.3.11}/docs/favicon.svg +0 -0
  95. {mcp_use-1.3.9 → mcp_use-1.3.11}/docs/fonts.css +0 -0
  96. {mcp_use-1.3.9 → mcp_use-1.3.11}/docs/getting-started/configuration.mdx +0 -0
  97. {mcp_use-1.3.9 → mcp_use-1.3.11}/docs/getting-started/index.mdx +0 -0
  98. {mcp_use-1.3.9 → mcp_use-1.3.11}/docs/getting-started/installation.mdx +0 -0
  99. {mcp_use-1.3.9 → mcp_use-1.3.11}/docs/getting-started/quickstart.mdx +0 -0
  100. {mcp_use-1.3.9 → mcp_use-1.3.11}/docs/images/01.png +0 -0
  101. {mcp_use-1.3.9 → mcp_use-1.3.11}/docs/images/02.png +0 -0
  102. {mcp_use-1.3.9 → mcp_use-1.3.11}/docs/images/configuration-dark.png +0 -0
  103. {mcp_use-1.3.9 → mcp_use-1.3.11}/docs/images/configuration-light.png +0 -0
  104. {mcp_use-1.3.9 → mcp_use-1.3.11}/docs/images/examples-dark.png +0 -0
  105. {mcp_use-1.3.9 → mcp_use-1.3.11}/docs/images/examples-light.png +0 -0
  106. {mcp_use-1.3.9 → mcp_use-1.3.11}/docs/images/hero-dark.png +0 -0
  107. {mcp_use-1.3.9 → mcp_use-1.3.11}/docs/images/hero-light.png +0 -0
  108. {mcp_use-1.3.9 → mcp_use-1.3.11}/docs/images/installation-dark.png +0 -0
  109. {mcp_use-1.3.9 → mcp_use-1.3.11}/docs/images/installation-light.png +0 -0
  110. {mcp_use-1.3.9 → mcp_use-1.3.11}/docs/images/quickstart-dark.png +0 -0
  111. {mcp_use-1.3.9 → mcp_use-1.3.11}/docs/images/quickstart-light.png +0 -0
  112. {mcp_use-1.3.9 → mcp_use-1.3.11}/docs/logo/dark.svg +0 -0
  113. {mcp_use-1.3.9 → mcp_use-1.3.11}/docs/logo/light.svg +0 -0
  114. {mcp_use-1.3.9 → mcp_use-1.3.11}/docs/logo/react.svg +0 -0
  115. {mcp_use-1.3.9 → mcp_use-1.3.11}/docs/snippets/snippet-intro.mdx +0 -0
  116. {mcp_use-1.3.9 → mcp_use-1.3.11}/docs/snippets/youtube-embed.mdx +0 -0
  117. {mcp_use-1.3.9 → mcp_use-1.3.11}/docs/troubleshooting/common-issues.mdx +0 -0
  118. {mcp_use-1.3.9 → mcp_use-1.3.11}/docs/troubleshooting/connection-errors.mdx +0 -0
  119. {mcp_use-1.3.9 → mcp_use-1.3.11}/docs/troubleshooting/performance.mdx +0 -0
  120. {mcp_use-1.3.9 → mcp_use-1.3.11}/examples/airbnb_mcp.json +0 -0
  121. {mcp_use-1.3.9 → mcp_use-1.3.11}/examples/airbnb_use.py +0 -0
  122. {mcp_use-1.3.9 → mcp_use-1.3.11}/examples/blender_use.py +0 -0
  123. {mcp_use-1.3.9 → mcp_use-1.3.11}/examples/browser_use.py +0 -0
  124. {mcp_use-1.3.9 → mcp_use-1.3.11}/examples/chat_example.py +0 -0
  125. {mcp_use-1.3.9 → mcp_use-1.3.11}/examples/direct_tool_call.py +0 -0
  126. {mcp_use-1.3.9 → mcp_use-1.3.11}/examples/filesystem_use.py +0 -0
  127. {mcp_use-1.3.9 → mcp_use-1.3.11}/examples/http_example.py +0 -0
  128. {mcp_use-1.3.9 → mcp_use-1.3.11}/examples/mcp_everything.py +0 -0
  129. {mcp_use-1.3.9 → mcp_use-1.3.11}/examples/multi_server_example.py +0 -0
  130. {mcp_use-1.3.9 → mcp_use-1.3.11}/examples/sandbox_everything.py +0 -0
  131. {mcp_use-1.3.9 → mcp_use-1.3.11}/examples/stream_example.py +0 -0
  132. {mcp_use-1.3.9 → mcp_use-1.3.11}/examples/structured_output.py +0 -0
  133. {mcp_use-1.3.9 → mcp_use-1.3.11}/mcp_use/adapters/__init__.py +0 -0
  134. {mcp_use-1.3.9 → mcp_use-1.3.11}/mcp_use/adapters/base.py +0 -0
  135. {mcp_use-1.3.9 → mcp_use-1.3.11}/mcp_use/agents/__init__.py +0 -0
  136. {mcp_use-1.3.9 → mcp_use-1.3.11}/mcp_use/agents/base.py +0 -0
  137. {mcp_use-1.3.9 → mcp_use-1.3.11}/mcp_use/agents/prompts/system_prompt_builder.py +0 -0
  138. {mcp_use-1.3.9 → mcp_use-1.3.11}/mcp_use/connectors/__init__.py +0 -0
  139. {mcp_use-1.3.9 → mcp_use-1.3.11}/mcp_use/connectors/sandbox.py +0 -0
  140. {mcp_use-1.3.9 → mcp_use-1.3.11}/mcp_use/connectors/stdio.py +0 -0
  141. {mcp_use-1.3.9 → mcp_use-1.3.11}/mcp_use/connectors/utils.py +0 -0
  142. {mcp_use-1.3.9 → mcp_use-1.3.11}/mcp_use/errors/__init__.py +0 -0
  143. {mcp_use-1.3.9 → mcp_use-1.3.11}/mcp_use/errors/error_formatting.py +0 -0
  144. {mcp_use-1.3.9 → mcp_use-1.3.11}/mcp_use/managers/__init__.py +0 -0
  145. {mcp_use-1.3.9 → mcp_use-1.3.11}/mcp_use/managers/tools/__init__.py +0 -0
  146. {mcp_use-1.3.9 → mcp_use-1.3.11}/mcp_use/managers/tools/base_tool.py +0 -0
  147. {mcp_use-1.3.9 → mcp_use-1.3.11}/mcp_use/managers/tools/connect_server.py +0 -0
  148. {mcp_use-1.3.9 → mcp_use-1.3.11}/mcp_use/managers/tools/disconnect_server.py +0 -0
  149. {mcp_use-1.3.9 → mcp_use-1.3.11}/mcp_use/managers/tools/get_active_server.py +0 -0
  150. {mcp_use-1.3.9 → mcp_use-1.3.11}/mcp_use/managers/tools/list_servers_tool.py +0 -0
  151. {mcp_use-1.3.9 → mcp_use-1.3.11}/mcp_use/managers/tools/search_tools.py +0 -0
  152. {mcp_use-1.3.9 → mcp_use-1.3.11}/mcp_use/session.py +0 -0
  153. {mcp_use-1.3.9 → mcp_use-1.3.11}/mcp_use/task_managers/__init__.py +0 -0
  154. {mcp_use-1.3.9 → mcp_use-1.3.11}/mcp_use/task_managers/stdio.py +0 -0
  155. {mcp_use-1.3.9 → mcp_use-1.3.11}/mcp_use/task_managers/websocket.py +0 -0
  156. {mcp_use-1.3.9 → mcp_use-1.3.11}/mcp_use/telemetry/__init__.py +0 -0
  157. {mcp_use-1.3.9 → mcp_use-1.3.11}/mcp_use/telemetry/events.py +0 -0
  158. {mcp_use-1.3.9 → mcp_use-1.3.11}/mcp_use/telemetry/telemetry.py +0 -0
  159. {mcp_use-1.3.9 → mcp_use-1.3.11}/mcp_use/telemetry/utils.py +0 -0
  160. {mcp_use-1.3.9 → mcp_use-1.3.11}/mcp_use/types/sandbox.py +0 -0
  161. {mcp_use-1.3.9 → mcp_use-1.3.11}/mcp_use/utils.py +0 -0
  162. {mcp_use-1.3.9 → mcp_use-1.3.11}/pytest.ini +0 -0
  163. {mcp_use-1.3.9 → mcp_use-1.3.11}/ruff.toml +0 -0
  164. {mcp_use-1.3.9 → mcp_use-1.3.11}/static/logo-gh.jpg +0 -0
  165. {mcp_use-1.3.9 → mcp_use-1.3.11}/static/logo_black.svg +0 -0
  166. {mcp_use-1.3.9 → mcp_use-1.3.11}/static/logo_white.svg +0 -0
  167. {mcp_use-1.3.9 → mcp_use-1.3.11}/tests/conftest.py +0 -0
  168. {mcp_use-1.3.9 → mcp_use-1.3.11}/tests/integration/__init__.py +0 -0
  169. {mcp_use-1.3.9 → mcp_use-1.3.11}/tests/integration/others/test_custom_streaming_integration.py +0 -0
  170. {mcp_use-1.3.9 → mcp_use-1.3.11}/tests/integration/primitives/test_discovery.py +0 -0
  171. {mcp_use-1.3.9 → mcp_use-1.3.11}/tests/integration/primitives/test_elicitation.py +0 -0
  172. {mcp_use-1.3.9 → mcp_use-1.3.11}/tests/integration/primitives/test_logging.py +0 -0
  173. {mcp_use-1.3.9 → mcp_use-1.3.11}/tests/integration/primitives/test_notifications.py +0 -0
  174. {mcp_use-1.3.9 → mcp_use-1.3.11}/tests/integration/primitives/test_prompts.py +0 -0
  175. {mcp_use-1.3.9 → mcp_use-1.3.11}/tests/integration/primitives/test_resources.py +0 -0
  176. {mcp_use-1.3.9 → mcp_use-1.3.11}/tests/integration/primitives/test_sampling.py +0 -0
  177. {mcp_use-1.3.9 → mcp_use-1.3.11}/tests/integration/primitives/test_tools.py +0 -0
  178. {mcp_use-1.3.9 → mcp_use-1.3.11}/tests/integration/servers_for_testing/__init__.py +0 -0
  179. {mcp_use-1.3.9 → mcp_use-1.3.11}/tests/integration/servers_for_testing/custom_streaming_server.py +0 -0
  180. {mcp_use-1.3.9 → mcp_use-1.3.11}/tests/integration/servers_for_testing/primitive_server.py +0 -0
  181. {mcp_use-1.3.9 → mcp_use-1.3.11}/tests/integration/servers_for_testing/simple_server.py +0 -0
  182. {mcp_use-1.3.9 → mcp_use-1.3.11}/tests/integration/servers_for_testing/timeout_test_server.py +0 -0
  183. {mcp_use-1.3.9 → mcp_use-1.3.11}/tests/integration/transports/test_sse.py +0 -0
  184. {mcp_use-1.3.9 → mcp_use-1.3.11}/tests/integration/transports/test_stdio.py +0 -0
  185. {mcp_use-1.3.9 → mcp_use-1.3.11}/tests/integration/transports/test_streamable_http.py +0 -0
  186. {mcp_use-1.3.9 → mcp_use-1.3.11}/tests/unit/test_client.py +0 -0
  187. {mcp_use-1.3.9 → mcp_use-1.3.11}/tests/unit/test_sandbox_connector.py +0 -0
  188. {mcp_use-1.3.9 → mcp_use-1.3.11}/tests/unit/test_search_tools_issue_138.py +0 -0
  189. {mcp_use-1.3.9 → mcp_use-1.3.11}/tests/unit/test_session.py +0 -0
  190. {mcp_use-1.3.9 → mcp_use-1.3.11}/tests/unit/test_stdio_connector.py +0 -0
  191. {mcp_use-1.3.9 → mcp_use-1.3.11}/tests/unit/test_websocket_connection_manager.py +0 -0
@@ -77,7 +77,7 @@ jobs:
77
77
  strategy:
78
78
  fail-fast: false
79
79
  matrix:
80
- primitive: [sampling, tools, resources, prompts, elicitation, notifications]
80
+ primitive: [sampling, tools, resources, prompts, elicitation, notifications, auth]
81
81
  steps:
82
82
  - uses: actions/checkout@v3
83
83
  - name: Set up Python 3.11
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mcp-use
3
- Version: 1.3.9
3
+ Version: 1.3.11
4
4
  Summary: MCP Library for LLMs
5
5
  Author-email: Pietro Zullo <pietro.zullo@gmail.com>
6
6
  License: MIT
@@ -15,6 +15,7 @@ Classifier: Programming Language :: Python :: 3.12
15
15
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
16
16
  Requires-Python: >=3.11
17
17
  Requires-Dist: aiohttp>=3.9.0
18
+ Requires-Dist: authlib>=1.6.3
18
19
  Requires-Dist: jsonschema-pydantic>=0.1.0
19
20
  Requires-Dist: langchain>=0.1.0
20
21
  Requires-Dist: mcp>=1.10.0
@@ -22,7 +23,7 @@ Requires-Dist: posthog>=4.8.0
22
23
  Requires-Dist: pydantic>=2.0.0
23
24
  Requires-Dist: python-dotenv>=1.0.0
24
25
  Requires-Dist: scarf-sdk>=0.1.0
25
- Requires-Dist: websockets>=12.0
26
+ Requires-Dist: websockets>=15.0
26
27
  Provides-Extra: anthropic
27
28
  Requires-Dist: langchain-anthropic; extra == 'anthropic'
28
29
  Provides-Extra: dev
@@ -52,13 +53,8 @@ Description-Content-Type: text/markdown
52
53
  </picture>
53
54
  </div>
54
55
 
55
- <br>
56
56
 
57
- # Create MCP Clients and Agents
58
-
59
- <p align="center">
60
- <a href="https://www.producthunt.com/products/mcp-use?embed=true&utm_source=badge-featured&utm_medium=badge&utm_source=badge-mcp&#0045;use" target="_blank"><img src="https://api.producthunt.com/widgets/embed-image/v1/featured.svg?post_id=1002629&theme=neutral&t=1754609432704" alt="mcp&#0045;use - Open&#0032;source&#0032;SDK&#0032;and&#0032;infra&#0032;for&#0032;MCP&#0032;servers&#0032;&#0038;&#0032;agents | Product Hunt" style="width: 150px; height: 32px;" width="150" height="32" /></a>
61
- </p>
57
+ <h1 align="center">🚀 Create MCP Clients and Agents</h1>
62
58
  <p align="center">
63
59
  <a href="https://github.com/pietrozullo/mcp-use/stargazers" alt="GitHub stars">
64
60
  <img src="https://img.shields.io/github/stars/pietrozullo/mcp-use?style=social" /></a>
@@ -95,7 +91,7 @@ Description-Content-Type: text/markdown
95
91
 
96
92
  | Supports | |
97
93
  | :------------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
98
- | **Primitives** | [![Tools](https://img.shields.io/github/actions/workflow/status/pietrozullo/mcp-use/tests.yml?job=primitive-tools&label=Tools&style=flat)](https://github.com/pietrozullo/mcp-use/actions/workflows/tests.yml) [![Resources](https://img.shields.io/github/actions/workflow/status/pietrozullo/mcp-use/tests.yml?job=primitive-resources&label=Resources&style=flat)](https://github.com/pietrozullo/mcp-use/actions/workflows/tests.yml) [![Prompts](https://img.shields.io/github/actions/workflow/status/pietrozullo/mcp-use/tests.yml?job=primitive-prompts&label=Prompts&style=flat)](https://github.com/pietrozullo/mcp-use/actions/workflows/tests.yml) [![Sampling](https://img.shields.io/github/actions/workflow/status/pietrozullo/mcp-use/tests.yml?job=primitive-sampling&label=Sampling&style=flat)](https://github.com/pietrozullo/mcp-use/actions/workflows/tests.yml) [![Elicitation](https://img.shields.io/github/actions/workflow/status/pietrozullo/mcp-use/tests.yml?job=primitive-elicitation&label=Elicitation&style=flat)](https://github.com/pietrozullo/mcp-use/actions/workflows/tests.yml) |
94
+ | **Primitives** | [![Tools](https://img.shields.io/github/actions/workflow/status/pietrozullo/mcp-use/tests.yml?job=primitive-tools&label=Tools&style=flat)](https://github.com/pietrozullo/mcp-use/actions/workflows/tests.yml) [![Resources](https://img.shields.io/github/actions/workflow/status/pietrozullo/mcp-use/tests.yml?job=primitive-resources&label=Resources&style=flat)](https://github.com/pietrozullo/mcp-use/actions/workflows/tests.yml) [![Prompts](https://img.shields.io/github/actions/workflow/status/pietrozullo/mcp-use/tests.yml?job=primitive-prompts&label=Prompts&style=flat)](https://github.com/pietrozullo/mcp-use/actions/workflows/tests.yml) [![Sampling](https://img.shields.io/github/actions/workflow/status/pietrozullo/mcp-use/tests.yml?job=primitive-sampling&label=Sampling&style=flat)](https://github.com/pietrozullo/mcp-use/actions/workflows/tests.yml) [![Elicitation](https://img.shields.io/github/actions/workflow/status/pietrozullo/mcp-use/tests.yml?job=primitive-elicitation&label=Elicitation&style=flat)](https://github.com/pietrozullo/mcp-use/actions/workflows/tests.yml) [![Authentication](https://img.shields.io/github/actions/workflow/status/pietrozullo/mcp-use/tests.yml?job=primitive-authentication&label=Authentication&style=flat)](https://github.com/pietrozullo/mcp-use/actions/workflows/tests.yml) |
99
95
  | **Transports** | [![Stdio](https://img.shields.io/github/actions/workflow/status/pietrozullo/mcp-use/tests.yml?job=transport-stdio&label=Stdio&style=flat)](https://github.com/pietrozullo/mcp-use/actions/workflows/tests.yml) [![SSE](https://img.shields.io/github/actions/workflow/status/pietrozullo/mcp-use/tests.yml?job=transport-sse&label=SSE&style=flat)](https://github.com/pietrozullo/mcp-use/actions/workflows/tests.yml) [![Streamable HTTP](https://img.shields.io/github/actions/workflow/status/pietrozullo/mcp-use/tests.yml?job=transport-streamableHttp&label=Streamable%20HTTP&style=flat)](https://github.com/pietrozullo/mcp-use/actions/workflows/tests.yml) |
100
96
 
101
97
  ## Features
@@ -154,7 +150,7 @@ pip install mcp-use
154
150
  Or install from source:
155
151
 
156
152
  ```bash
157
- git clone https://github.com/pietrozullo/mcp-use.git
153
+ git clone https://github.com/mcp-use/mcp-use.git
158
154
  cd mcp-use
159
155
  pip install -e .
160
156
  ```
@@ -253,14 +249,14 @@ For other settings, models, and more, check out the documentation.
253
249
 
254
250
  ## Streaming Agent Output
255
251
 
256
- MCP-Use supports asynchronous streaming of agent output using the `astream` method on `MCPAgent`. This allows you to receive incremental results, tool actions, and intermediate steps as they are generated by the agent, enabling real-time feedback and progress reporting.
252
+ MCP-Use supports asynchronous streaming of agent output using the `stream` method on `MCPAgent`. This allows you to receive incremental results, tool actions, and intermediate steps as they are generated by the agent, enabling real-time feedback and progress reporting.
257
253
 
258
254
  ### How to use
259
255
 
260
- Call `agent.astream(query)` and iterate over the results asynchronously:
256
+ Call `agent.stream(query)` and iterate over the results asynchronously:
261
257
 
262
258
  ```python
263
- async for chunk in agent.astream("Find the best restaurant in San Francisco"):
259
+ async for chunk in agent.stream("Find the best restaurant in San Francisco"):
264
260
  print(chunk["messages"], end="", flush=True)
265
261
  ```
266
262
 
@@ -280,7 +276,7 @@ async def main():
280
276
  client = MCPClient.from_config_file("browser_mcp.json")
281
277
  llm = ChatOpenAI(model="gpt-4o")
282
278
  agent = MCPAgent(llm=llm, client=client, max_steps=30)
283
- async for chunk in agent.astream("Look for job at nvidia for machine learning engineer."):
279
+ async for chunk in agent.stream("Look for job at nvidia for machine learning engineer."):
284
280
  print(chunk["messages"], end="", flush=True)
285
281
 
286
282
  if __name__ == "__main__":
@@ -837,31 +833,31 @@ Thanks to all our amazing contributors!
837
833
  </tr>
838
834
  <tr>
839
835
  <td><img src="https://avatars.githubusercontent.com/u/38653995?s=40&v=4" width="20" height="20" style="vertical-align: middle; margin-right: 8px;"> <a href="https://github.com/patchy631/ai-engineering-hub"><strong>patchy631/ai-engineering-hub</strong></a></td>
840
- <td>⭐ 15920</td>
841
- </tr>
842
- <tr>
843
- <td><img src="https://avatars.githubusercontent.com/u/170207473?s=40&v=4" width="20" height="20" style="vertical-align: middle; margin-right: 8px;"> <a href="https://github.com/tavily-ai/meeting-prep-agent"><strong>tavily-ai/meeting-prep-agent</strong></a></td>
844
- <td>⭐ 129</td>
836
+ <td>⭐ 17917</td>
845
837
  </tr>
846
838
  <tr>
847
839
  <td><img src="https://avatars.githubusercontent.com/u/164294848?s=40&v=4" width="20" height="20" style="vertical-align: middle; margin-right: 8px;"> <a href="https://github.com/buildfastwithai/gen-ai-experiments"><strong>buildfastwithai/gen-ai-experiments</strong></a></td>
848
- <td>⭐ 93</td>
840
+ <td>⭐ 178</td>
849
841
  </tr>
850
842
  <tr>
851
843
  <td><img src="https://avatars.githubusercontent.com/u/187057607?s=40&v=4" width="20" height="20" style="vertical-align: middle; margin-right: 8px;"> <a href="https://github.com/hud-evals/hud-python"><strong>hud-evals/hud-python</strong></a></td>
852
- <td>⭐ 76</td>
844
+ <td>⭐ 159</td>
845
+ </tr>
846
+ <tr>
847
+ <td><img src="https://avatars.githubusercontent.com/u/170207473?s=40&v=4" width="20" height="20" style="vertical-align: middle; margin-right: 8px;"> <a href="https://github.com/tavily-ai/meeting-prep-agent"><strong>tavily-ai/meeting-prep-agent</strong></a></td>
848
+ <td>⭐ 136</td>
853
849
  </tr>
854
850
  <tr>
855
851
  <td><img src="https://avatars.githubusercontent.com/u/20041231?s=40&v=4" width="20" height="20" style="vertical-align: middle; margin-right: 8px;"> <a href="https://github.com/krishnaik06/MCP-CRASH-Course"><strong>krishnaik06/MCP-CRASH-Course</strong></a></td>
856
- <td>⭐ 61</td>
852
+ <td>⭐ 72</td>
857
853
  </tr>
858
854
  <tr>
859
855
  <td><img src="https://avatars.githubusercontent.com/u/54944174?s=40&v=4" width="20" height="20" style="vertical-align: middle; margin-right: 8px;"> <a href="https://github.com/larksuite/lark-samples"><strong>larksuite/lark-samples</strong></a></td>
860
- <td>⭐ 35</td>
856
+ <td>⭐ 40</td>
861
857
  </tr>
862
858
  <tr>
863
859
  <td><img src="https://avatars.githubusercontent.com/u/892404?s=40&v=4" width="20" height="20" style="vertical-align: middle; margin-right: 8px;"> <a href="https://github.com/truemagic-coder/solana-agent-app"><strong>truemagic-coder/solana-agent-app</strong></a></td>
864
- <td>⭐ 30</td>
860
+ <td>⭐ 29</td>
865
861
  </tr>
866
862
  <tr>
867
863
  <td><img src="https://avatars.githubusercontent.com/u/8344498?s=40&v=4" width="20" height="20" style="vertical-align: middle; margin-right: 8px;"> <a href="https://github.com/schogini/techietalksai"><strong>schogini/techietalksai</strong></a></td>
@@ -869,11 +865,11 @@ Thanks to all our amazing contributors!
869
865
  </tr>
870
866
  <tr>
871
867
  <td><img src="https://avatars.githubusercontent.com/u/201161342?s=40&v=4" width="20" height="20" style="vertical-align: middle; margin-right: 8px;"> <a href="https://github.com/autometa-dev/whatsapp-mcp-voice-agent"><strong>autometa-dev/whatsapp-mcp-voice-agent</strong></a></td>
872
- <td>⭐ 22</td>
868
+ <td>⭐ 23</td>
873
869
  </tr>
874
870
  <tr>
875
871
  <td><img src="https://avatars.githubusercontent.com/u/100749943?s=40&v=4" width="20" height="20" style="vertical-align: middle; margin-right: 8px;"> <a href="https://github.com/Deniscartin/mcp-cli"><strong>Deniscartin/mcp-cli</strong></a></td>
876
- <td>⭐ 19</td>
872
+ <td>⭐ 20</td>
877
873
  </tr>
878
874
  </table>
879
875
 
@@ -7,13 +7,8 @@
7
7
  </picture>
8
8
  </div>
9
9
 
10
- <br>
11
10
 
12
- # Create MCP Clients and Agents
13
-
14
- <p align="center">
15
- <a href="https://www.producthunt.com/products/mcp-use?embed=true&utm_source=badge-featured&utm_medium=badge&utm_source=badge-mcp&#0045;use" target="_blank"><img src="https://api.producthunt.com/widgets/embed-image/v1/featured.svg?post_id=1002629&theme=neutral&t=1754609432704" alt="mcp&#0045;use - Open&#0032;source&#0032;SDK&#0032;and&#0032;infra&#0032;for&#0032;MCP&#0032;servers&#0032;&#0038;&#0032;agents | Product Hunt" style="width: 150px; height: 32px;" width="150" height="32" /></a>
16
- </p>
11
+ <h1 align="center">🚀 Create MCP Clients and Agents</h1>
17
12
  <p align="center">
18
13
  <a href="https://github.com/pietrozullo/mcp-use/stargazers" alt="GitHub stars">
19
14
  <img src="https://img.shields.io/github/stars/pietrozullo/mcp-use?style=social" /></a>
@@ -50,7 +45,7 @@
50
45
 
51
46
  | Supports | |
52
47
  | :------------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
53
- | **Primitives** | [![Tools](https://img.shields.io/github/actions/workflow/status/pietrozullo/mcp-use/tests.yml?job=primitive-tools&label=Tools&style=flat)](https://github.com/pietrozullo/mcp-use/actions/workflows/tests.yml) [![Resources](https://img.shields.io/github/actions/workflow/status/pietrozullo/mcp-use/tests.yml?job=primitive-resources&label=Resources&style=flat)](https://github.com/pietrozullo/mcp-use/actions/workflows/tests.yml) [![Prompts](https://img.shields.io/github/actions/workflow/status/pietrozullo/mcp-use/tests.yml?job=primitive-prompts&label=Prompts&style=flat)](https://github.com/pietrozullo/mcp-use/actions/workflows/tests.yml) [![Sampling](https://img.shields.io/github/actions/workflow/status/pietrozullo/mcp-use/tests.yml?job=primitive-sampling&label=Sampling&style=flat)](https://github.com/pietrozullo/mcp-use/actions/workflows/tests.yml) [![Elicitation](https://img.shields.io/github/actions/workflow/status/pietrozullo/mcp-use/tests.yml?job=primitive-elicitation&label=Elicitation&style=flat)](https://github.com/pietrozullo/mcp-use/actions/workflows/tests.yml) |
48
+ | **Primitives** | [![Tools](https://img.shields.io/github/actions/workflow/status/pietrozullo/mcp-use/tests.yml?job=primitive-tools&label=Tools&style=flat)](https://github.com/pietrozullo/mcp-use/actions/workflows/tests.yml) [![Resources](https://img.shields.io/github/actions/workflow/status/pietrozullo/mcp-use/tests.yml?job=primitive-resources&label=Resources&style=flat)](https://github.com/pietrozullo/mcp-use/actions/workflows/tests.yml) [![Prompts](https://img.shields.io/github/actions/workflow/status/pietrozullo/mcp-use/tests.yml?job=primitive-prompts&label=Prompts&style=flat)](https://github.com/pietrozullo/mcp-use/actions/workflows/tests.yml) [![Sampling](https://img.shields.io/github/actions/workflow/status/pietrozullo/mcp-use/tests.yml?job=primitive-sampling&label=Sampling&style=flat)](https://github.com/pietrozullo/mcp-use/actions/workflows/tests.yml) [![Elicitation](https://img.shields.io/github/actions/workflow/status/pietrozullo/mcp-use/tests.yml?job=primitive-elicitation&label=Elicitation&style=flat)](https://github.com/pietrozullo/mcp-use/actions/workflows/tests.yml) [![Authentication](https://img.shields.io/github/actions/workflow/status/pietrozullo/mcp-use/tests.yml?job=primitive-authentication&label=Authentication&style=flat)](https://github.com/pietrozullo/mcp-use/actions/workflows/tests.yml) |
54
49
  | **Transports** | [![Stdio](https://img.shields.io/github/actions/workflow/status/pietrozullo/mcp-use/tests.yml?job=transport-stdio&label=Stdio&style=flat)](https://github.com/pietrozullo/mcp-use/actions/workflows/tests.yml) [![SSE](https://img.shields.io/github/actions/workflow/status/pietrozullo/mcp-use/tests.yml?job=transport-sse&label=SSE&style=flat)](https://github.com/pietrozullo/mcp-use/actions/workflows/tests.yml) [![Streamable HTTP](https://img.shields.io/github/actions/workflow/status/pietrozullo/mcp-use/tests.yml?job=transport-streamableHttp&label=Streamable%20HTTP&style=flat)](https://github.com/pietrozullo/mcp-use/actions/workflows/tests.yml) |
55
50
 
56
51
  ## Features
@@ -109,7 +104,7 @@ pip install mcp-use
109
104
  Or install from source:
110
105
 
111
106
  ```bash
112
- git clone https://github.com/pietrozullo/mcp-use.git
107
+ git clone https://github.com/mcp-use/mcp-use.git
113
108
  cd mcp-use
114
109
  pip install -e .
115
110
  ```
@@ -208,14 +203,14 @@ For other settings, models, and more, check out the documentation.
208
203
 
209
204
  ## Streaming Agent Output
210
205
 
211
- MCP-Use supports asynchronous streaming of agent output using the `astream` method on `MCPAgent`. This allows you to receive incremental results, tool actions, and intermediate steps as they are generated by the agent, enabling real-time feedback and progress reporting.
206
+ MCP-Use supports asynchronous streaming of agent output using the `stream` method on `MCPAgent`. This allows you to receive incremental results, tool actions, and intermediate steps as they are generated by the agent, enabling real-time feedback and progress reporting.
212
207
 
213
208
  ### How to use
214
209
 
215
- Call `agent.astream(query)` and iterate over the results asynchronously:
210
+ Call `agent.stream(query)` and iterate over the results asynchronously:
216
211
 
217
212
  ```python
218
- async for chunk in agent.astream("Find the best restaurant in San Francisco"):
213
+ async for chunk in agent.stream("Find the best restaurant in San Francisco"):
219
214
  print(chunk["messages"], end="", flush=True)
220
215
  ```
221
216
 
@@ -235,7 +230,7 @@ async def main():
235
230
  client = MCPClient.from_config_file("browser_mcp.json")
236
231
  llm = ChatOpenAI(model="gpt-4o")
237
232
  agent = MCPAgent(llm=llm, client=client, max_steps=30)
238
- async for chunk in agent.astream("Look for job at nvidia for machine learning engineer."):
233
+ async for chunk in agent.stream("Look for job at nvidia for machine learning engineer."):
239
234
  print(chunk["messages"], end="", flush=True)
240
235
 
241
236
  if __name__ == "__main__":
@@ -792,31 +787,31 @@ Thanks to all our amazing contributors!
792
787
  </tr>
793
788
  <tr>
794
789
  <td><img src="https://avatars.githubusercontent.com/u/38653995?s=40&v=4" width="20" height="20" style="vertical-align: middle; margin-right: 8px;"> <a href="https://github.com/patchy631/ai-engineering-hub"><strong>patchy631/ai-engineering-hub</strong></a></td>
795
- <td>⭐ 15920</td>
796
- </tr>
797
- <tr>
798
- <td><img src="https://avatars.githubusercontent.com/u/170207473?s=40&v=4" width="20" height="20" style="vertical-align: middle; margin-right: 8px;"> <a href="https://github.com/tavily-ai/meeting-prep-agent"><strong>tavily-ai/meeting-prep-agent</strong></a></td>
799
- <td>⭐ 129</td>
790
+ <td>⭐ 17917</td>
800
791
  </tr>
801
792
  <tr>
802
793
  <td><img src="https://avatars.githubusercontent.com/u/164294848?s=40&v=4" width="20" height="20" style="vertical-align: middle; margin-right: 8px;"> <a href="https://github.com/buildfastwithai/gen-ai-experiments"><strong>buildfastwithai/gen-ai-experiments</strong></a></td>
803
- <td>⭐ 93</td>
794
+ <td>⭐ 178</td>
804
795
  </tr>
805
796
  <tr>
806
797
  <td><img src="https://avatars.githubusercontent.com/u/187057607?s=40&v=4" width="20" height="20" style="vertical-align: middle; margin-right: 8px;"> <a href="https://github.com/hud-evals/hud-python"><strong>hud-evals/hud-python</strong></a></td>
807
- <td>⭐ 76</td>
798
+ <td>⭐ 159</td>
799
+ </tr>
800
+ <tr>
801
+ <td><img src="https://avatars.githubusercontent.com/u/170207473?s=40&v=4" width="20" height="20" style="vertical-align: middle; margin-right: 8px;"> <a href="https://github.com/tavily-ai/meeting-prep-agent"><strong>tavily-ai/meeting-prep-agent</strong></a></td>
802
+ <td>⭐ 136</td>
808
803
  </tr>
809
804
  <tr>
810
805
  <td><img src="https://avatars.githubusercontent.com/u/20041231?s=40&v=4" width="20" height="20" style="vertical-align: middle; margin-right: 8px;"> <a href="https://github.com/krishnaik06/MCP-CRASH-Course"><strong>krishnaik06/MCP-CRASH-Course</strong></a></td>
811
- <td>⭐ 61</td>
806
+ <td>⭐ 72</td>
812
807
  </tr>
813
808
  <tr>
814
809
  <td><img src="https://avatars.githubusercontent.com/u/54944174?s=40&v=4" width="20" height="20" style="vertical-align: middle; margin-right: 8px;"> <a href="https://github.com/larksuite/lark-samples"><strong>larksuite/lark-samples</strong></a></td>
815
- <td>⭐ 35</td>
810
+ <td>⭐ 40</td>
816
811
  </tr>
817
812
  <tr>
818
813
  <td><img src="https://avatars.githubusercontent.com/u/892404?s=40&v=4" width="20" height="20" style="vertical-align: middle; margin-right: 8px;"> <a href="https://github.com/truemagic-coder/solana-agent-app"><strong>truemagic-coder/solana-agent-app</strong></a></td>
819
- <td>⭐ 30</td>
814
+ <td>⭐ 29</td>
820
815
  </tr>
821
816
  <tr>
822
817
  <td><img src="https://avatars.githubusercontent.com/u/8344498?s=40&v=4" width="20" height="20" style="vertical-align: middle; margin-right: 8px;"> <a href="https://github.com/schogini/techietalksai"><strong>schogini/techietalksai</strong></a></td>
@@ -824,11 +819,11 @@ Thanks to all our amazing contributors!
824
819
  </tr>
825
820
  <tr>
826
821
  <td><img src="https://avatars.githubusercontent.com/u/201161342?s=40&v=4" width="20" height="20" style="vertical-align: middle; margin-right: 8px;"> <a href="https://github.com/autometa-dev/whatsapp-mcp-voice-agent"><strong>autometa-dev/whatsapp-mcp-voice-agent</strong></a></td>
827
- <td>⭐ 22</td>
822
+ <td>⭐ 23</td>
828
823
  </tr>
829
824
  <tr>
830
825
  <td><img src="https://avatars.githubusercontent.com/u/100749943?s=40&v=4" width="20" height="20" style="vertical-align: middle; margin-right: 8px;"> <a href="https://github.com/Deniscartin/mcp-cli"><strong>Deniscartin/mcp-cli</strong></a></td>
831
- <td>⭐ 19</td>
826
+ <td>⭐ 20</td>
832
827
  </tr>
833
828
  </table>
834
829
 
@@ -0,0 +1,272 @@
1
+ ---
2
+ title: "Interactive Chat Patterns"
3
+ description: "Create interactive chat interfaces with persistent conversation memory"
4
+ icon: "message-circle"
5
+ ---
6
+
7
+ ## Building a chat loop
8
+
9
+ With mcp-use you can build interactive interface where users can have conversations with
10
+ your `MCPAgent`, maintaining context and memory across multiple queries.
11
+
12
+ ## Basic chat loop
13
+ Here's a basic chat-loop with conversation memory enabled:
14
+ ```python chat_loop.py
15
+ import asyncio
16
+ from dotenv import load_dotenv
17
+ from langchain_openai import ChatOpenAI
18
+ from mcp_use import MCPAgent, MCPClient
19
+
20
+ async def basic_chat_loop():
21
+ """Simple console chat loop with MCPAgent"""
22
+ # Load environment variables
23
+ load_dotenv()
24
+
25
+ # MCP server configuration
26
+ config = {
27
+ "mcpServers": {
28
+ "playwright": {
29
+ "command": "npx",
30
+ "args": ["@playwright/mcp@latest"],
31
+ "env": {"DISPLAY": ":1"}
32
+ },
33
+ "filesystem": {
34
+ "command": "npx",
35
+ "args": ["-y", "@modelcontextprotocol/server-filesystem", "/tmp"]
36
+ }
37
+ }
38
+ }
39
+
40
+ # Create client and agent
41
+ client = MCPClient.from_dict(config)
42
+ llm = ChatOpenAI(model="gpt-4o")
43
+
44
+ agent = MCPAgent(llm=llm,
45
+ client=client,
46
+ memory_enabled=True, # Enable memory to track conversation history
47
+ max_steps=20)
48
+
49
+ # Some initial messages
50
+ print("🤖 MCP Agent Chat")
51
+ print("Type 'quit/exit' to exit the chat.")
52
+ print("Type 'clear' to clear conversation history")
53
+
54
+ try:
55
+ while True:
56
+ user_input = input("\nYou: ")
57
+
58
+ if user_input.lower() in ['quit', 'exit']:
59
+ print("👋 Goodbye!")
60
+ break
61
+
62
+ if user_input.lower() == 'clear':
63
+ agent.clear_conversation_history()
64
+ print("🧹 Conversation history cleared.")
65
+ continue
66
+
67
+ # Skip empty messages
68
+ if not user_input:
69
+ continue
70
+
71
+ try:
72
+ print("\n🤖 Assistant: ", end="", flush=True)
73
+ response = await agent.run(user_input)
74
+ print(response)
75
+ except KeyboardInterrupt: # Handle keyboard interrupt
76
+ print("\n\n⏸️ Interrupted by user")
77
+ break
78
+ except Exception as e:
79
+ print(f"\n❌ Error: {e}")
80
+ print("Please try again or type 'exit' to quit.")
81
+ finally:
82
+ await client.close_all_sessions()
83
+
84
+ if __name__ == "__main__":
85
+ asyncio.run(basic_chat_loop())
86
+ ```
87
+
88
+ ## Streaming Chat Loop
89
+
90
+ Here's a chat loop with streaming responses enabled:
91
+
92
+ ```python chat_loop_streaming.py
93
+ import asyncio
94
+ from dotenv import load_dotenv
95
+ from langchain_openai import ChatOpenAI
96
+ from mcp_use import MCPAgent, MCPClient
97
+
98
+ async def streaming_chat_loop():
99
+ """Chat loop with streaming responses with MCPAgent"""
100
+ # Load environment variables
101
+ load_dotenv()
102
+
103
+ # MCP server configuration
104
+ config = {
105
+ "mcpServers": {
106
+ "playwright": {
107
+ "command": "npx",
108
+ "args": ["@playwright/mcp@latest"],
109
+ "env": {"DISPLAY": ":1"}
110
+ }
111
+ }
112
+ }
113
+
114
+ # Create client and agent
115
+ client = MCPClient.from_dict(config)
116
+ llm = ChatOpenAI(model="gpt-4o")
117
+
118
+ agent = MCPAgent(llm=llm,
119
+ client=client,
120
+ memory_enabled=True, # Enable memory to track conversation history
121
+ max_steps=20)
122
+
123
+ # Some initial messages
124
+ print("🤖 MCP Agent Chat (Streaming)")
125
+ print("Type 'quit/exit' to exit the chat.")
126
+ print("Type 'clear' to clear conversation history")
127
+
128
+ try:
129
+ while True:
130
+ user_input = input("\nYou: ")
131
+
132
+ if user_input.lower() in ['quit', 'exit']:
133
+ print("👋 Goodbye!")
134
+ break
135
+
136
+ if user_input.lower() == 'clear':
137
+ agent.clear_conversation_history()
138
+ print("🧹 Conversation history cleared.")
139
+ continue
140
+
141
+ if not user_input: # Skip empty messages
142
+ continue
143
+
144
+ try:
145
+ print("\n🤖 Assistant: ", end="", flush=True)
146
+
147
+ # Stream the response
148
+ async for chunk in agent.stream(user_input):
149
+ print(chunk, end="", flush=True)
150
+ print()
151
+ except KeyboardInterrupt: # Handle keyboard interrupt
152
+ print("\n\n⏸️ Interrupted by user")
153
+ break
154
+ except Exception as e:
155
+ print(f"\n❌ Error: {e}")
156
+ print("Please try again or type 'exit' to quit.")
157
+ finally:
158
+ await client.close_all_sessions()
159
+
160
+ if __name__ == "__main__":
161
+ asyncio.run(streaming_chat_loop())
162
+ ```
163
+
164
+ ## Chat Loop with Structured I/O
165
+
166
+ It's possible to create a chat loop that can handle both natural language and structured inputs, allowing users to request specific tasks or analyses in a structured format. Here's an example of how to implement this:
167
+
168
+ ```python
169
+ import asyncio
170
+ from dotenv import load_dotenv
171
+ from pydantic import BaseModel, Field
172
+ from langchain_openai import ChatOpenAI
173
+ from mcp_use import MCPAgent, MCPClient
174
+ from typing import Optional
175
+
176
+ class TaskRequest(BaseModel):
177
+ task_type: Optional[str] = Field(description="The type of task to perform")
178
+ description: Optional[str] = Field(description="Detailed description of the task")
179
+ priority: Optional[str] = Field(description="Priority level: low, medium, high")
180
+
181
+ async def structured_chat_loop():
182
+ """Chat loop that can handle both natural language and structured inputs."""
183
+ # Load environment variables
184
+ load_dotenv()
185
+
186
+ # MCP server configuration
187
+ config = {
188
+ "mcpServers": {
189
+ "playwright": {
190
+ "command": "npx",
191
+ "args": ["@playwright/mcp@latest"],
192
+ "env": {"DISPLAY": ":1"}
193
+ }
194
+ }
195
+ }
196
+
197
+ # Create client and agent
198
+ client = MCPClient.from_dict(config)
199
+ llm = ChatOpenAI(model="gpt-4o")
200
+
201
+ agent = MCPAgent(
202
+ llm=llm,
203
+ client=client,
204
+ memory_enabled=True, # Enable memory to track conversation history
205
+ max_steps=20
206
+ )
207
+
208
+ # Initial messages
209
+ print("🤖 MCP Agent Chat (Structured)")
210
+ print("You can chat naturally or request structured task analysis")
211
+ print("Type 'task' to create a structured task request")
212
+
213
+ try:
214
+ while True:
215
+ user_input = input("\nYou: ")
216
+ if user_input.lower() in ['exit', 'quit']:
217
+ print("👋 Goodbye!")
218
+ break
219
+
220
+ try:
221
+ if user_input.lower() == 'task':
222
+ print("\n📋 Creating structured task...")
223
+ task_description = input("Describe your task: ")
224
+
225
+ task: TaskRequest = await agent.run(
226
+ f"Analyze a task with the following description: {task_description}",
227
+ output_schema=TaskRequest
228
+ )
229
+
230
+ # Print task analysis
231
+ print(f"\n✅ Task Analysis:")
232
+ print(f"• Type: {task.task_type}")
233
+ print(f"• Description: {task.description}")
234
+ print(f"• Priority: {task.priority or 'low'}")
235
+
236
+ proceed = input("\nDo you want to proceed with this task? (y/n)")
237
+ if proceed.lower() == 'y':
238
+ response = await agent.run(
239
+ f"Execute the following task: {task.description}"
240
+ )
241
+ print(f"\n🤖 Assistant: {response}")
242
+ else:
243
+ # Regular conversation
244
+ response = await agent.run(user_input)
245
+ print(f"\n🤖 Assistant: {response}")
246
+ except KeyboardInterrupt:
247
+ print("\n👋 Goodbye!")
248
+ break
249
+ except Exception as e:
250
+ print(f"❌ Error: {e}")
251
+ print("Please try again or type 'exit' to quit.")
252
+
253
+ finally:
254
+ await client.close_all_sessions()
255
+
256
+ if __name__ == "__main__":
257
+ asyncio.run(structured_chat_loop())
258
+ ```
259
+
260
+ ## Next Steps
261
+
262
+ <CardGroup cols={3}>
263
+ <Card title="Agent Configuration" icon="cloud" href="/agent/agent-configuration">
264
+ Learn more about configuring agents for optimal streaming performance
265
+ </Card>
266
+ <Card title="Multi-Server Setup" icon="server" href="/advanced/multi-server-setup">
267
+ Stream output from agents using multiple MCP servers
268
+ </Card>
269
+ <Card title="Security Best Practices" icon="shield" href="/advanced/security">
270
+ Learn how to secure your MCP deployments
271
+ </Card>
272
+ </CardGroup>
@@ -71,6 +71,7 @@ agent = MCPAgent(
71
71
  )
72
72
  ```
73
73
 
74
+
74
75
  ## 🔍 Tool Discovery Flow
75
76
 
76
77
 
@@ -213,3 +214,54 @@ if __name__ == "__main__":
213
214
  ```
214
215
 
215
216
  The Server Manager transforms your MCP agent from a static tool user into an intelligent, adaptive assistant that can dynamically discover and utilize the perfect tools for any task! 🚀
217
+
218
+
219
+
220
+ ## Bring Your Own Server Manager
221
+
222
+ For ultimate control, you can create your own server manager. By implementing the `BaseServerManager` abstract class, you can define custom logic for tool discovery, dynamic tool creation, or integration with other systems. The server manager's primary role is to provide tools **to the agent**. These can be management tools for connecting to external MCP servers, or, as shown below, custom tools that operate entirely within the agent's environment without needing an external server.
223
+
224
+ Here’s a minimal example of a custom server manager that provides a single, hard-coded tool directly to the agent.
225
+
226
+ ```python
227
+ import asyncio
228
+ from mcp_use.agents import MCPAgent
229
+ from mcp_use.managers.base import BaseServerManager
230
+ from langchain_core.tools import BaseTool
231
+ from langchain_openai import ChatOpenAI
232
+ from pydantic import BaseModel
233
+
234
+ # 1. Define a custom tool
235
+ class HelloWorldTool(BaseTool):
236
+ """A simple tool that returns a greeting."""
237
+ name: str = "hello_world"
238
+ description: str = "Returns 'Hello, World!'"
239
+ args_schema: type[BaseModel] | None = None
240
+ def _run(self) -> str: return "Hello, World!"
241
+ async def _arun(self) -> str: return "Hello, World!"
242
+
243
+ # 2. Implement the BaseServerManager interface
244
+ class SimpleServerManager(BaseServerManager):
245
+ """A minimal server manager with one tool."""
246
+ def __init__(self):
247
+ self._tools = [HelloWorldTool()]
248
+ async def initialize(self) -> None: pass
249
+ @property
250
+ def tools(self) -> list[BaseTool]: return self._tools
251
+ def has_tool_changes(self, current_tool_names: set[str]) -> bool:
252
+ return {tool.name for tool in self.tools} != current_tool_names
253
+
254
+ # 3. Pass your custom manager to the agent
255
+ async def useCustomManager():
256
+ agent = MCPAgent(
257
+ llm=ChatOpenAI(model="gpt-4o"),
258
+ use_server_manager=True,
259
+ server_manager=SimpleServerManager(),
260
+ )
261
+ # The agent now has access to your custom tool
262
+ result = await agent.run("Use the hello_world tool")
263
+ print(result) #> "Hello, World!"
264
+ await agent.close()
265
+
266
+ asyncio.run(useCustomManager())
267
+ ```