refactor: McpError renamed to MCPError and flatten parameters (#1956)
Co-authored-by: Max Isbey <224885523+maxisbey@users.noreply.github.com>
This commit is contained in:
parent
65c614e48e
commit
acba5478a9
2 changed files with 253 additions and 326 deletions
|
|
@ -337,7 +337,7 @@ if __name__ == "__main__":
|
|||
Handle task errors gracefully:
|
||||
|
||||
```python
|
||||
from mcp.shared.exceptions import McpError
|
||||
from mcp.shared.exceptions import MCPError
|
||||
|
||||
try:
|
||||
result = await session.experimental.call_tool_as_task("my_tool", args)
|
||||
|
|
@ -349,8 +349,8 @@ try:
|
|||
|
||||
final = await session.experimental.get_task_result(task_id, CallToolResult)
|
||||
|
||||
except McpError as e:
|
||||
print(f"MCP error: {e.error.message}")
|
||||
except MCPError as e:
|
||||
print(f"MCP error: {e.message}")
|
||||
except Exception as e:
|
||||
print(f"Error: {e}")
|
||||
```
|
||||
|
|
|
|||
|
|
@ -121,6 +121,38 @@ result = await session.list_resources(params=PaginatedRequestParams(cursor="next
|
|||
result = await session.list_tools(params=PaginatedRequestParams(cursor="next_page_token"))
|
||||
```
|
||||
|
||||
### `McpError` renamed to `MCPError`
|
||||
|
||||
The `McpError` exception class has been renamed to `MCPError` for consistent naming with the MCP acronym style used throughout the SDK.
|
||||
|
||||
**Before (v1):**
|
||||
|
||||
```python
|
||||
from mcp.shared.exceptions import McpError
|
||||
|
||||
try:
|
||||
result = await session.call_tool("my_tool")
|
||||
except McpError as e:
|
||||
print(f"Error: {e.error.message}")
|
||||
```
|
||||
|
||||
**After (v2):**
|
||||
|
||||
```python
|
||||
from mcp.shared.exceptions import MCPError
|
||||
|
||||
try:
|
||||
result = await session.call_tool("my_tool")
|
||||
except MCPError as e:
|
||||
print(f"Error: {e.message}")
|
||||
```
|
||||
|
||||
`MCPError` is also exported from the top-level `mcp` package:
|
||||
|
||||
```python
|
||||
from mcp import MCPError
|
||||
```
|
||||
|
||||
### `FastMCP` renamed to `MCPServer`
|
||||
|
||||
The `FastMCP` class has been renamed to `MCPServer` to better reflect its role as the main server class in the SDK. This is a simple rename with no functional changes to the class itself.
|
||||
|
|
|
|||
Loading…
Reference in a new issue