Skip to content

Commit 08331bf

Browse files
authored
[GMLP-6388] Add support for Gumloop AuthError exception (#9)
1 parent eae5fcf commit 08331bf

4 files changed

Lines changed: 46 additions & 3 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "gumloop-mcp"
3-
version = "0.1.10"
3+
version = "0.1.11"
44
description = "guMCP (Gumloop Model Context Protocol) SDK"
55
readme = "README.md"
66
requires-python = ">=3.10"

src/mcp/server/lowlevel/server.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ async def main():
8888
from mcp.server.models import InitializationOptions
8989
from mcp.server.session import ServerSession
9090
from mcp.shared.context import RequestContext
91-
from mcp.shared.exceptions import McpError
91+
from mcp.shared.exceptions import McpError, AuthError
9292
from mcp.shared.message import ServerMessageMetadata, SessionMessage
9393
from mcp.shared.session import RequestResponder
9494

@@ -651,6 +651,18 @@ async def handler(req: types.CallToolRequest):
651651
isError=False,
652652
)
653653
)
654+
except AuthError as e:
655+
return types.ServerResult(
656+
types.CallToolResult(
657+
content=[
658+
types.TextContent(
659+
type="text",
660+
text=json.dumps(e.details.model_dump()),
661+
)
662+
],
663+
isError=True,
664+
)
665+
)
654666
except Exception as e:
655667
return self._make_error_result(str(e))
656668

src/mcp/shared/exceptions.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from mcp.types import ErrorData
1+
from mcp.types import ErrorData, AuthErrorData
22

33

44
class McpError(Exception):
@@ -12,3 +12,16 @@ def __init__(self, error: ErrorData):
1212
"""Initialize McpError."""
1313
super().__init__(error.message)
1414
self.error = error
15+
16+
17+
class AuthError(Exception):
18+
"""
19+
Exception type raised for authentication and authorization failures.
20+
"""
21+
22+
details: AuthErrorData
23+
24+
def __init__(self, details: AuthErrorData):
25+
"""Initialize AuthError."""
26+
super().__init__(details.message)
27+
self.details = details

src/mcp/types.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,24 @@ class ErrorData(BaseModel):
179179
model_config = ConfigDict(extra="allow")
180180

181181

182+
class AuthErrorData(BaseModel):
183+
"""Error information for authentication and authorization failures."""
184+
185+
error: str
186+
"""The error type identifier (e.g., 'credentials_not_found', 'invalid_token', 'insufficient_permissions')."""
187+
188+
message: str
189+
"""A human-readable error message."""
190+
191+
service: str
192+
"""The service name requiring authentication."""
193+
194+
error_status: int
195+
"""The HTTP status code (401, 403, 400, etc.)."""
196+
197+
model_config = ConfigDict(extra="allow")
198+
199+
182200
class JSONRPCError(BaseModel):
183201
"""A response to a request that indicates an error occurred."""
184202

0 commit comments

Comments
 (0)