Skip to content

Commit f1154a6

Browse files
committed
fix(mcp): recover from panics in get_profile tool
Adds a defer-recover block to catch and log panics within the `get_profile` tool function. This prevents server crashes and improves the overall stability of the application.
1 parent 2bf959b commit f1154a6

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

mcp/server.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,12 @@ func Run() {
155155
mcp.WithDescription("Get the Telkomsel profile, balance, and account status of the currently logged-in user."),
156156
),
157157
func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
158+
defer func() {
159+
if r := recover(); r != nil {
160+
log.Printf("🔥 PANIC in get_profile: %v", r)
161+
}
162+
}()
163+
158164
session := getActiveSession(sessions)
159165
if session == nil {
160166
return mcp.NewToolResultError("No active logged-in session found. Please login first."), nil

0 commit comments

Comments
 (0)