Skip to content
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

[#70] Handle list resources with no body #71

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -762,9 +762,13 @@ func (s *Server) handleListResources(ctx context.Context, request *transport.Bas
Cursor *string `json:"cursor"`
}
var params resourceRequestParams
err := json.Unmarshal(request.Params, &params)
if err != nil {
return nil, errors.Wrap(err, "failed to unmarshal arguments")
if request.Params == nil {
params = resourceRequestParams{}
} else {
err := json.Unmarshal(request.Params, &params)
if err != nil {
return nil, errors.Wrap(err, "failed to unmarshal arguments")
}
}

// Order by URI for pagination
Expand Down
36 changes: 36 additions & 0 deletions server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,42 @@ func TestHandleListPromptsPagination(t *testing.T) {
}
}

func TestHandleListResourcesNoParams(t *testing.T) {
mockTransport := testingutils.NewMockTransport()
server := NewServer(mockTransport)
err := server.Serve()
if err != nil {
t.Fatal(err)
}

// Register resources
resourceURIs := []string{"b://resource", "a://resource"}
for _, uri := range resourceURIs {
err = server.RegisterResource(uri, "resource-"+uri, "Test resource "+uri, "text/plain", func() (*ResourceResponse, error) {
return NewResourceResponse(NewTextEmbeddedResource(uri, "test content", "text/plain")), nil
})
if err != nil {
t.Fatal(err)
}
}

// Test with no Params defined
resp, err := server.handleListResources(context.Background(), &transport.BaseJSONRPCRequest{}, protocol.RequestHandlerExtra{})
if err != nil {
t.Fatal(err)
}

resourcesResp, ok := resp.(ListResourcesResponse)
if !ok {
t.Fatal("Expected ListResourcesResponse")
}

// Verify empty resources list
if len(resourcesResp.Resources) != len(resourceURIs) {
t.Errorf("Expected %d resources, got %d", len(resourceURIs), len(resourcesResp.Resources))
}
}

func TestHandleListResourcesPagination(t *testing.T) {
mockTransport := testingutils.NewMockTransport()
server := NewServer(mockTransport)
Expand Down