Commit Graph

156 Commits

Author SHA1 Message Date
Pietro Zullo c789c317a7 Feat: streaming steps (#159)
* Streaming steps implementation and example

* Changed astream to stream_events for clarity

* docs

* Changed file docsg

* Fixed telemetry
2025-07-05 17:22:31 -07:00
pietrozullo 367945a3eb Remove numpy dep 2025-07-03 20:28:38 -07:00
NandhuKishore24 288b943741 Fixing Disallowed tool issue #62 (#151) 2025-07-03 18:04:21 -07:00
Luigi Pederzani 5e7ab23b89 Fix: search tools tuple unpacking error (#138) (#142)
* fix: resolve tuple unpacking error in search_tools when using server manager

Fixes #138 - ValueError: not enough values to unpack (expected 3, got 1)

**Problem:**
When using MCPAgent with use_server_manager=True, users encountered a tuple
unpacking error in search_tools.py. The issue occurred because:
1. ToolSearchEngine.search_tools() sometimes returned a string (when no results)
   and sometimes returned a list of tuples (when results found)
2. SearchToolsTool._arun() expected search_tools() to return a list of tuples
   to pass to format_search_results()
3. When search_tools() returned a string, format_search_results() tried to
   iterate over the string characters, causing the unpacking error

**Solution:**
- Modified ToolSearchEngine.search_tools() to consistently return formatted
  strings by calling a new _format_search_results() method
- Added _format_search_results() method to ToolSearchEngine class
- Updated SearchToolsTool._arun() to return the already-formatted results
  directly instead of calling format_search_results() again
- Updated CLAUDE.md to include virtual environment activation instructions

**Testing:**
- Successfully reproduced the original error
- Verified the fix resolves the issue
- All unit tests pass (113/113)
- Applied code formatting and linting

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* test: add comprehensive test suite for issue #138 tuple unpacking bug

- test_tool_search_engine_consistent_return_type_with_results: ensures search_tools
  returns string when results are found (not list of tuples as in the bug)
- test_tool_search_engine_consistent_return_type_no_results: ensures search_tools
  returns string when no results found
- test_tool_search_engine_not_indexed_scenario: tests the 'still preparing' scenario
- test_search_tools_tool_arun_with_string_result: tests SearchToolsTool._arun()
  correctly handles string results from search_tools
- test_search_tools_tool_integration_scenario: integration test simulating the
  exact scenario from issue #138 that was causing the tuple unpacking error
- test_format_search_results_method_exists: validates the new _format_search_results method
- test_server_manager_active_server_marking: tests active server marking functionality
- test_search_tools_input_validation: validates ToolSearchInput model

These tests ensure the tuple unpacking bug (ValueError: not enough values to unpack
expected 3, got 1) will not regress in the future and verify the fix works correctly.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* fix: resolve logger mock issues in search_tools tests

Added @patch decorators to mock the logger in tests that call _format_search_results
to avoid TypeError with logging level comparisons during testing.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* fix: Update documentation to use session-based API instead of deprecated client methods

- Replace all references to non-existent client.connect_all() with client.create_all_sessions()
- Replace all references to non-existent client.disconnect_all() with client.close_all_sessions()
- Replace all references to client.list_tools() with session.list_tools()
- Replace all references to client.call_tool() with session.call_tool()
- Update API documentation to reflect actual MCPClient implementation
- Fix code examples to use proper session-based architecture
- Ensure all documentation matches the real codebase API

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* Improve docs

* remove unused

---------

Co-authored-by: Claude <noreply@anthropic.com>
2025-06-21 23:03:04 -07:00
Pietro Zullo 80786eb382 fix: Raise import error for fastembed, server manager does not silently fail (#141)
* Raise import error for fastembed

* add trailing space

A trailing space is missing after 'pip install mcp-use[search]', which causes the concatenated error message to run words together. Please add a space at the end of this string literal to ensure clear messaging.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Pietro Zullo <62951181+pietrozullo@users.noreply.github.com>

---------

Signed-off-by: Pietro Zullo <62951181+pietrozullo@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-06-21 22:30:07 -07:00
Ermias Baዩ a3a085f9dd fix: prevent double async cleanup and event loop errors in astream (#133)
* Fix: prevent double async cleanup and event loop errors in astream generator

* update manage_connector as flag for cleanup

Co-authored-by: Luigi Pederzani <luigipederzani@gmail.com>
Signed-off-by: Pietro Zullo <62951181+pietrozullo@users.noreply.github.com>

* fix line too long

* lint2

---------

Signed-off-by: Pietro Zullo <62951181+pietrozullo@users.noreply.github.com>
Co-authored-by: Pietro Zullo <62951181+pietrozullo@users.noreply.github.com>
Co-authored-by: Luigi Pederzani <luigipederzani@gmail.com>
Co-authored-by: pietrozullo <pietro.zullo@gmail.com>
2025-06-21 21:18:44 -07:00
Pietro Zullo 2351c072c3 feat: Set default logging level to info (#136)
* Set default debug to 1

* Update docs
2025-06-18 16:22:17 +02:00
Pietro Zullo 8a32d3c23c fix: pre commit run all files (#135)
* Set line lenght to 120

* Run pre commit all files
2025-06-18 10:12:58 +02:00
Luigi Pederzani 8aa2861202 feat: Add Scarf telemetry alongside existing PostHog analytics (#134)
* Add scarf telemetry and download tracking

* Remove unused function

---------

Co-authored-by: Pietro Zullo <62951181+pietrozullo@users.noreply.github.com>
2025-06-18 09:45:34 +02:00
Pietro Zullo f6bed01fcb feat: observability (#131)
* Add support for langfuse and laminar observaility layers

* Example env file

* fix: improve observability transparency and documentation

- Add debug logging for package import failures and missing API keys
- Fix documentation to correctly state LANGFUSE_HOST is supported  
- Centralize dotenv loading to avoid multiple calls

Co-authored-by: Pietro Zullo <pietrozullo@users.noreply.github.com>

* Ruff fix

---------

Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
Co-authored-by: Pietro Zullo <pietrozullo@users.noreply.github.com>
2025-06-17 21:15:20 +02:00
Pietro Zullo cb7c2bcbd6 Feat/telemetry (#124)
* Telemetry base

* Fix debug level

* Singleton pattern in utils for metric server

* Added public identifier to transports

* Update telemetry

* Add telemetry to mcpagent

* telemetry docs
2025-06-13 21:12:34 +02:00
Luigi Pederzani 4f05c62aa6 Fix connection state tracking after SSE disconnection (#120) (#122)
* Refactor integration test to have multiple mcp servers

* fix: check correct attribute in client_session validation

* Minor

* Add custom streaming server integration test (not related to the issue)

* Add server

* Enhanced base connector connection check to fix connection status as True even after SSE connections were closed by the server.

* Fix test since now we are using the connector and not the client_session

* Add integration tests and servers for timeout and connection testing

* Removed wrapped call_tool from session and test connection from the base connector + fix tests

* Add fallback check or default assumption for stream object
2025-06-13 18:46:44 +02:00
Luigi Pederzani ed0972a97a Fix websocket error positional arguments, headers were missing (#123) 2025-06-13 15:18:41 +02:00
pietrozullo 2d766c326d Rename client to client session 2025-06-09 19:04:24 +02:00
pietrozullo 498fffc6f5 Remove websolcker client protocl deprecation 2025-06-09 17:24:55 +02:00
leonpham-mbh 59b640ff37 feat: streamable http support (#106)
* Extend HTTP connector to support newer streamable http transport

* Fix timeout since they should be timedelta objects

* Refactor http connector to use streamable http by default

This will fallback to SSE if there are any issues with the test
ping send.

* Added transport integration tests

* Fail fast removed

* add fastmcp deps

* system install

* Fixed tests

* Remove python 3.12 from tests

---------

Co-authored-by: pietrozullo <pietro.zullo@gmail.com>
2025-06-04 22:13:03 +02:00
Pietro Zullo f13f9a8930 feat: remove client options for easier usage (#105)
* Remove clientoptions in favor of simpler, is sandbox argument and sandbox argument optional

* Tests and examples

* Remove tool from session

* Nice error message

* Update docs

* Update readme
2025-06-03 10:03:18 +02:00
pietrozullo 0ac5a4d363 Add history recording in mcpagent streaming function (#102) 2025-05-26 13:32:21 +02:00
Luigi Pederzani e8e958c565 Feature: Support for running MCP servers in a sandboxed cloud environment using E2B (#97)
* Add E2B optional dependency for sandboxed mcp servers

* Add types for sandbox options

* Add util to check if stdio server config

* Ignore B017

* Add sandbox connector to run MCP servers on e2b sandbox

* Add client options to set sandbox and sandbox options + use sandbox connector

* Add sandbox connector test + fix

* Add sandboxed stdio server example

* Add docs

* Set logger info

* Set debug in example

* Add install new optional dep
2025-05-19 14:50:38 +02:00
pietrozullo 80e86851ac fix create all session docstrings 2025-05-19 09:35:31 +02:00
pietrozullo af945d7e8a Feature: support Resources & Prompts (#80)
* Add connector hooks to resources and propts

* Adapter implementation for resources and tools, treated them as tools

* Move unpacking responsibility to adapters

* Update unittests

* Separate unit and integration

* Fix initialization logic

* Fixed tests with capability check

* Removed tool reference from session
2025-05-15 16:29:55 +02:00
pietrozullo 905f1b4eb7 Fixed base connection manager 2025-05-15 13:32:41 +02:00
pietrozullo dd2707ca93 Fixed task managers 2025-05-15 13:02:04 +02:00
pietrozullo bcd540a49a Fixed typing for session.tools - was a list of untyped dict now it is a list[mcp.types.Tool] 2025-05-12 12:06:24 +02:00
pietrozullo aff793446a Fixed test for no config client - now checks that client warns 2025-05-12 09:17:47 +02:00
pietrozullo d70acfd0e3 BR: Agent streams events not messages - this turns out to be a better way to stream responses from the agent. MCPClient works also if no server is provided, raises a warning as this might be a side effect of unintended configuration 2025-05-12 08:56:01 +02:00
Pietro a3a20907ff Dynamically import fastembed to avoid import errors if search is not isntalled 2025-05-11 17:15:31 +02:00
pietrozullo 77b2cdd2d8 feat: Streaming Response (#83)
* MCPAgent streams all events

* Remove sync streaming and fix linting

* doc update
2025-05-10 18:31:06 +02:00
Pietro 82eb062e7b Supports for prompts and test for supports of all MCP features 2025-05-02 08:43:45 +08:00
Pietro efadc4821f Remove server name unused param in agent 2025-04-26 06:46:06 +02:00
pietrozullo b4e26a46a4 Feat/search (#56)
* Move server manager to manager

* update imports

* Search tool with full indexing

* Use tool search in sevrer manager -- rebase

* Simplified server manager

* WIP: tool search with fastemebed

* Import changes and adapter repr

* Update server manager API

* Implemented search tool, single tool usage tool, and separated tools into their own implementations, decoupled manager from tools

* Separate piproject and ruff config

* Remove sentence transformers - use fastembed

* Added search extra - update isntall in test action

* Small refactor

* docs
2025-04-22 17:50:16 +02:00
pietrozullo 5d836656e7 Feat/expose tools (#45)
* Abstract tool adapter

* Adapted API users

* Documentations

* PR template
2025-04-19 15:47:29 +02:00
pietrozullo 178c80f8e5 Feat/logging (#34)
* Documentation for logging

* Update docs to double logging layer

* Readme log instruction

* Logging logic

* Pretty logging for agent

* Removed some logs
2025-04-17 11:54:13 +02:00
pietrozullo 708c116ec4 Feat/server manager (#23)
* Langchain adapter

* Removed langchain agent

* Refactored mcpagent, removed import

* Removed double initialization

* Server manager implementation

* Moved prompts to proper place and relative utils too

* Working server manager agent integration

* Update examples

* Removed debug true and added verbose option

* Replaced switch server to server disconnect

* Docs about server switching

---------

Signed-off-by: pietrozullo <62951181+pietrozullo@users.noreply.github.com>
2025-04-16 13:30:34 +02:00
pietrozullo 0026b9e2c2 Fix import 2025-04-15 18:22:34 +02:00
pietrozullo b942515fcd Removed double initialization 2025-04-15 18:22:34 +02:00
pietrozullo 179498fec4 Refactored mcpagent, removed import 2025-04-15 18:22:34 +02:00
pietrozullo c2ac33881e Removed langchain agent 2025-04-15 18:22:34 +02:00
pietrozullo 98f7dc90f7 Langchain adapter 2025-04-15 18:22:34 +02:00
pietrozullo b79dc986a4 Most logs moved to DEBUG 2025-04-11 18:34:53 +02:00
pietrozullo 98ee55fe9c Implementation of tool denylist 2025-04-09 09:31:35 +02:00
pietrozullo 6979ff353e Remove appended sse to base_url 2025-04-07 16:03:33 +02:00
pietrozullo 6fcd6237af Refactor connectors 2025-04-04 16:46:10 +02:00
pietrozullo 6a1b6ee063 Replace hand made http with mcp sse transport 2025-04-04 16:46:10 +02:00
pietrozullo 9c3578ef36 Correct arguments to http and ws connectors 2025-04-04 13:52:23 +02:00
pietrozullo 9cc7ce7196 Remove deprecated import 2025-04-04 13:52:23 +02:00
pietrozullo 9d27715e3c feat/multi server (#5)
* Multi server MVP. Still needs cancel scope fixing

* Example and updated docs

* Fix

* Reinstated nice example prompt
2025-04-03 12:27:29 +02:00
pietrozullo a753b5bd70 Remove unused util 2025-04-02 17:32:21 +02:00
pietrozullo 4733d0a6a3 Improved system prompt 2025-04-02 15:36:33 +02:00
pietrozullo be8c903571 Packge auto detects its version (TODO) check if this works reliably 2025-04-02 10:53:01 +02:00