charmbracelet/crush · error
session ID is required for listing MCP resources
Error message
session ID is required for listing MCP resources
What it means
The list_mcp_resources tool needs a session ID to associate the permission request with a conversation. GetSessionFromContext returns empty when the tool runs outside an agent session, so the tool aborts with this error instead of requesting permissions it cannot attribute.
Source
Thrown at internal/agent/tools/list_mcp_resources.go:43
const ListMCPResourcesToolName = "list_mcp_resources"
//go:embed list_mcp_resources.md
var listMCPResourcesDescription string
func NewListMCPResourcesTool(cfg *config.ConfigStore, permissions permission.Service) fantasy.AgentTool {
return fantasy.NewParallelAgentTool(
ListMCPResourcesToolName,
listMCPResourcesDescription,
func(ctx context.Context, params ListMCPResourcesParams, call fantasy.ToolCall) (fantasy.ToolResponse, error) {
params.MCPName = strings.TrimSpace(params.MCPName)
if params.MCPName == "" {
return fantasy.NewTextErrorResponse("mcp_name parameter is required"), nil
}
sessionID := GetSessionFromContext(ctx)
if sessionID == "" {
return fantasy.ToolResponse{}, fmt.Errorf("session ID is required for listing MCP resources")
}
relPath := filepathext.SmartJoin(cfg.WorkingDir(), params.MCPName)
p, err := permissions.Request(
ctx,
permission.CreatePermissionRequest{
SessionID: sessionID,
Path: relPath,
ToolCallID: call.ID,
ToolName: ListMCPResourcesToolName,
Action: "list",
Description: fmt.Sprintf("List MCP resources from %s", params.MCPName),
Params: ListMCPResourcesPermissionsParams(params),
},
)
if err != nil {
return fantasy.ToolResponse{}, err
}View on GitHub (pinned to 7944b8e522)
Solutions
- Ensure the tool is executed through the normal agent pipeline, which injects the session ID into the context.
- In tests, set the session ID explicitly via the context helper (GetSessionFromContext counterpart) before invoking the tool.
- If embedding the tool elsewhere, attach a valid session ID to the context first.
Example fix
// before resp, _ := tool.Execute(ctx, params) // ctx has no session // after ctx = WithSession(ctx, sessionID) resp, _ := tool.Execute(ctx, params)
Defensive patterns
Strategy: validation
Validate before calling
if GetSessionFromContext(ctx) == "" {
return errors.New("cannot list MCP resources without a session")
} Type guard
null
Try / catch
if err := run(); err != nil {
if strings.Contains(err.Error(), "session ID is required") { /* attach session and retry */ }
} Prevention
- Always invoke tools through the agent pipeline
- Seed the context with a session ID in tests
- Never reuse bare contexts for tool execution
When it happens
Trigger: Invoking the ListMcpResources tool (with mcp_name set) from a context that lacks a session, e.g. calling the tool's Execute function directly in tests or from a non-session code path.
Common situations: Unit tests calling the tool handler without seeding the context, MCP resource listing attempted during startup or from background jobs that bypass the agent session.
Related errors
- session ID is required for executing shell command
- session ID is required for downloading files
- session ID is required for creating a new file
- session ID is required for accessing directories outside wor
- session ID is required for creating a new file
AI-assisted analysis of charmbracelet/crush@7944b8e522 (2026-08-29).
Data as JSON: /api/errors/fe9b78ff5fc39dfc.
Report an issue: GitHub.