mcp-use 1.3.10__py3-none-any.whl → 1.3.11__py3-none-any.whl
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.
- mcp_use/adapters/langchain_adapter.py +7 -5
- mcp_use/agents/mcpagent.py +16 -4
- mcp_use/agents/prompts/templates.py +1 -10
- mcp_use/auth/__init__.py +6 -0
- mcp_use/auth/bearer.py +17 -0
- mcp_use/auth/oauth.py +625 -0
- mcp_use/auth/oauth_callback.py +214 -0
- mcp_use/client.py +1 -1
- mcp_use/config.py +2 -2
- mcp_use/connectors/base.py +17 -12
- mcp_use/connectors/http.py +117 -21
- mcp_use/connectors/websocket.py +14 -5
- mcp_use/exceptions.py +31 -0
- mcp_use/task_managers/base.py +13 -23
- mcp_use/task_managers/sse.py +5 -0
- mcp_use/task_managers/streamable_http.py +5 -0
- {mcp_use-1.3.10.dist-info → mcp_use-1.3.11.dist-info}/METADATA +19 -24
- {mcp_use-1.3.10.dist-info → mcp_use-1.3.11.dist-info}/RECORD +21 -16
- {mcp_use-1.3.10.dist-info → mcp_use-1.3.11.dist-info}/WHEEL +0 -0
- {mcp_use-1.3.10.dist-info → mcp_use-1.3.11.dist-info}/entry_points.txt +0 -0
- {mcp_use-1.3.10.dist-info → mcp_use-1.3.11.dist-info}/licenses/LICENSE +0 -0
|
@@ -39,7 +39,7 @@ class LangChainAdapter(BaseAdapter):
|
|
|
39
39
|
self._connector_tool_map: dict[BaseConnector, list[BaseTool]] = {}
|
|
40
40
|
|
|
41
41
|
def fix_schema(self, schema: dict) -> dict:
|
|
42
|
-
"""Convert JSON Schema 'type': ['string', 'null'] to 'anyOf' format.
|
|
42
|
+
"""Convert JSON Schema 'type': ['string', 'null'] to 'anyOf' format and fix enum handling.
|
|
43
43
|
|
|
44
44
|
Args:
|
|
45
45
|
schema: The JSON schema to fix.
|
|
@@ -51,6 +51,11 @@ class LangChainAdapter(BaseAdapter):
|
|
|
51
51
|
if "type" in schema and isinstance(schema["type"], list):
|
|
52
52
|
schema["anyOf"] = [{"type": t} for t in schema["type"]]
|
|
53
53
|
del schema["type"] # Remove 'type' and standardize to 'anyOf'
|
|
54
|
+
|
|
55
|
+
# Fix enum handling - ensure enum fields are properly typed as strings
|
|
56
|
+
if "enum" in schema and "type" not in schema:
|
|
57
|
+
schema["type"] = "string"
|
|
58
|
+
|
|
54
59
|
for key, value in schema.items():
|
|
55
60
|
schema[key] = self.fix_schema(value) # Apply recursively
|
|
56
61
|
return schema
|
|
@@ -71,11 +76,8 @@ class LangChainAdapter(BaseAdapter):
|
|
|
71
76
|
if tool_result.isError:
|
|
72
77
|
raise ToolException(f"Tool execution failed: {tool_result.content}")
|
|
73
78
|
|
|
74
|
-
if not tool_result.content:
|
|
75
|
-
raise ToolException("Tool execution returned no content")
|
|
76
|
-
|
|
77
79
|
decoded_result = ""
|
|
78
|
-
for item in tool_result.content:
|
|
80
|
+
for item in tool_result.content or []:
|
|
79
81
|
match item.type:
|
|
80
82
|
case "text":
|
|
81
83
|
item: TextContent
|
mcp_use/agents/mcpagent.py
CHANGED
|
@@ -492,6 +492,10 @@ class MCPAgent:
|
|
|
492
492
|
|
|
493
493
|
logger.info(f"🏁 Starting agent execution with max_steps={steps}")
|
|
494
494
|
|
|
495
|
+
# Track whether agent finished successfully vs reached max iterations
|
|
496
|
+
agent_finished_successfully = False
|
|
497
|
+
result = None
|
|
498
|
+
|
|
495
499
|
# Create a run manager with our callbacks if we have any - ONCE for the entire execution
|
|
496
500
|
run_manager = None
|
|
497
501
|
if self.callbacks:
|
|
@@ -578,6 +582,7 @@ class MCPAgent:
|
|
|
578
582
|
# Process the output
|
|
579
583
|
if isinstance(next_step_output, AgentFinish):
|
|
580
584
|
logger.info(f"✅ Agent finished at step {step_num + 1}")
|
|
585
|
+
agent_finished_successfully = True
|
|
581
586
|
result = next_step_output.return_values.get("output", "No output generated")
|
|
582
587
|
# End the chain if we have a run manager
|
|
583
588
|
if run_manager:
|
|
@@ -659,6 +664,7 @@ class MCPAgent:
|
|
|
659
664
|
tool_return = self._agent_executor._get_tool_return(last_step)
|
|
660
665
|
if tool_return is not None:
|
|
661
666
|
logger.info(f"🏆 Tool returned directly at step {step_num + 1}")
|
|
667
|
+
agent_finished_successfully = True
|
|
662
668
|
result = tool_return.return_values.get("output", "No output generated")
|
|
663
669
|
break
|
|
664
670
|
|
|
@@ -681,10 +687,16 @@ class MCPAgent:
|
|
|
681
687
|
|
|
682
688
|
# --- Loop finished ---
|
|
683
689
|
if not result:
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
690
|
+
if agent_finished_successfully:
|
|
691
|
+
# Agent finished successfully but returned empty output
|
|
692
|
+
result = "Agent completed the task successfully."
|
|
693
|
+
logger.info("✅ Agent finished successfully with empty output")
|
|
694
|
+
else:
|
|
695
|
+
# Agent actually reached max iterations
|
|
696
|
+
logger.warning(f"⚠️ Agent stopped after reaching max iterations ({steps})")
|
|
697
|
+
result = f"Agent stopped after reaching the maximum number of steps ({steps})."
|
|
698
|
+
if run_manager:
|
|
699
|
+
await run_manager.on_chain_end({"output": result})
|
|
688
700
|
|
|
689
701
|
# If structured output was requested but not achieved, attempt one final time
|
|
690
702
|
if output_schema and structured_llm and not success:
|
|
@@ -5,16 +5,7 @@ You have access to the following tools:
|
|
|
5
5
|
|
|
6
6
|
{tool_descriptions}
|
|
7
7
|
|
|
8
|
-
Use
|
|
9
|
-
|
|
10
|
-
Question: the input question you must answer
|
|
11
|
-
Thought: you should always think about what to do
|
|
12
|
-
Action: the action to take, should be one of the available tools
|
|
13
|
-
Action Input: the input to the action
|
|
14
|
-
Observation: the result of the action
|
|
15
|
-
... (this Thought/Action/Action Input/Observation can repeat N times)
|
|
16
|
-
Thought: I now know the final answer
|
|
17
|
-
Final Answer: the final answer to the original input question"""
|
|
8
|
+
Use these tools to help answer questions and complete tasks as needed."""
|
|
18
9
|
|
|
19
10
|
|
|
20
11
|
SERVER_MANAGER_SYSTEM_PROMPT_TEMPLATE = """You are a helpful assistant designed
|
mcp_use/auth/__init__.py
ADDED
mcp_use/auth/bearer.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"""Bearer token authentication support."""
|
|
2
|
+
|
|
3
|
+
from collections.abc import Generator
|
|
4
|
+
|
|
5
|
+
import httpx
|
|
6
|
+
from pydantic import BaseModel, SecretStr
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class BearerAuth(httpx.Auth, BaseModel):
|
|
10
|
+
"""Bearer token authentication for HTTP requests."""
|
|
11
|
+
|
|
12
|
+
token: SecretStr
|
|
13
|
+
|
|
14
|
+
def auth_flow(self, request: httpx.Request) -> Generator[httpx.Request, httpx.Response, None]:
|
|
15
|
+
"""Apply bearer token authentication to the request."""
|
|
16
|
+
request.headers["Authorization"] = f"Bearer {self.token.get_secret_value()}"
|
|
17
|
+
yield request
|