-
Notifications
You must be signed in to change notification settings - Fork 3k
refactor: McpError renamed to MCPError and flatten parameters
#1956
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Kludex
wants to merge
2
commits into
main
Choose a base branch
from
refactor-mcp-error
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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.message}") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. did |
||
| ``` | ||
|
|
||
| **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. | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -13,7 +13,7 @@ | |||||
| from mcp.server.experimental.task_context import ServerTaskContext | ||||||
| from mcp.server.experimental.task_support import TaskSupport | ||||||
| from mcp.server.session import ServerSession | ||||||
| from mcp.shared.exceptions import McpError | ||||||
| from mcp.shared.exceptions import MCPError | ||||||
| from mcp.shared.experimental.tasks.helpers import MODEL_IMMEDIATE_RESPONSE_KEY, is_terminal | ||||||
| from mcp.types import ( | ||||||
| METHOD_NOT_FOUND, | ||||||
|
|
@@ -72,32 +72,26 @@ def validate_task_mode( | |||||
| Args: | ||||||
| tool_task_mode: The tool's execution.taskSupport value | ||||||
| ("forbidden", "optional", "required", or None) | ||||||
| raise_error: If True, raises McpError on validation failure. If False, returns ErrorData. | ||||||
| raise_error: If True, raises MCPError on validation failure. If False, returns ErrorData. | ||||||
|
|
||||||
| Returns: | ||||||
| None if valid, ErrorData if invalid and raise_error=False | ||||||
|
|
||||||
| Raises: | ||||||
| McpError: If invalid and raise_error=True | ||||||
| MCPError: If invalid and raise_error=True | ||||||
| """ | ||||||
|
|
||||||
| mode = tool_task_mode or TASK_FORBIDDEN | ||||||
|
|
||||||
| error: ErrorData | None = None | ||||||
|
|
||||||
| if mode == TASK_REQUIRED and not self.is_task: | ||||||
| error = ErrorData( | ||||||
| code=METHOD_NOT_FOUND, | ||||||
| message="This tool requires task-augmented invocation", | ||||||
| ) | ||||||
| error = ErrorData(code=METHOD_NOT_FOUND, message="This tool requires task-augmented invocation") | ||||||
| elif mode == TASK_FORBIDDEN and self.is_task: | ||||||
| error = ErrorData( | ||||||
| code=METHOD_NOT_FOUND, | ||||||
| message="This tool does not support task-augmented invocation", | ||||||
| ) | ||||||
| error = ErrorData(code=METHOD_NOT_FOUND, message="This tool does not support task-augmented invocation") | ||||||
|
|
||||||
| if error is not None and raise_error: | ||||||
| raise McpError(error) | ||||||
| raise MCPError(code=METHOD_NOT_FOUND, message=error.message) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
|
||||||
| return error | ||||||
|
|
||||||
|
|
@@ -113,7 +107,7 @@ def validate_for_tool( | |||||
|
|
||||||
| Args: | ||||||
| tool: The Tool definition | ||||||
| raise_error: If True, raises McpError on validation failure. | ||||||
| raise_error: If True, raises MCPError on validation failure. | ||||||
|
|
||||||
| Returns: | ||||||
| None if valid, ErrorData if invalid and raise_error=False | ||||||
|
|
||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this makes sense to be consistent. Although it does go against the google style guide: https://google.github.io/styleguide/pyguide.html#3162-naming-conventions
but since we're not strictly following that then it's not really an issue :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where are you seeing the lack of consistency? MCP is an acronymn, so that's why it would be uppercased.