@@ -2,11 +2,13 @@ package mcp
22
33import (
44 "context"
5+ "errors"
56 "iter"
67 "log/slog"
78
89 "github.com/charmbracelet/crush/internal/config"
910 "github.com/charmbracelet/crush/internal/csync"
11+ "github.com/modelcontextprotocol/go-sdk/jsonrpc"
1012 "github.com/modelcontextprotocol/go-sdk/mcp"
1113)
1214
@@ -81,11 +83,22 @@ func getResources(ctx context.Context, c *ClientSession) ([]*Resource, error) {
8183 }
8284 result, err := c.ListResources(ctx, &mcp.ListResourcesParams{})
8385 if err != nil {
86+ // Handle "Method not found" errors from MCP servers that don't support resources/list
87+ if isMethodNotFoundError(err) {
88+ slog.Warn("MCP server does not support resources/list", "error", err)
89+ return nil, nil
90+ }
8491 return nil, err
8592 }
8693 return result.Resources, nil
8794}
8895
96+// isMethodNotFoundError checks if the error is a JSON-RPC "Method not found" error.
97+func isMethodNotFoundError(err error) bool {
98+ var rpcErr *jsonrpc.Error
99+ return errors.As(err, &rpcErr) && rpcErr != nil && rpcErr.Code == jsonrpc.CodeMethodNotFound
100+}
101+
89102func updateResources(name string, resources []*Resource) int {
90103 if len(resources) == 0 {
91104 allResources.Del(name)