Skip to content

Conversation

@peteski22
Copy link
Contributor

@peteski22 peteski22 commented Sep 18, 2025

Summary:

This PR implements comprehensive support for MCP (Model Context Protocol) resources in the mcpd REST API, enabling clients to discover and access server resources through standard HTTP endpoints.

  • Add new REST endpoints for MCP resource operations:
    • GET /api/v1/servers/{name}/resources - List server resources with pagination
    • GET /api/v1/servers/{name}/resources/templates - List resource templates for URI discovery
    • GET /api/v1/servers/{name}/resources/content?uri={uri} - Get resource content by URI
  • Add proper HTTP status code mapping (404, 403, 501, 502) for resource-specific errors
  • Add comprehensive error handling with method-not-found detection for servers without resource capability
  • Add tests for all resource API endpoints and error scenarios

Closes: #181

NOTE:

If mark3labs/mcp-go#595 is merged and released, then we can also refactor the checks for 'Method not found' in the code.

@peteski22
Copy link
Contributor Author

peteski22 commented Sep 19, 2025

RE: Failing tests see: #184

@peteski22 peteski22 force-pushed the peteski22/181/api/resource-support branch from 14fde23 to 07ca63e Compare September 19, 2025 16:05
@peteski22 peteski22 force-pushed the peteski22/181/api/resource-support branch from 8ffd371 to 614a75b Compare September 24, 2025 15:24
@peteski22 peteski22 force-pushed the peteski22/181/api/resource-support branch from d7984a2 to 6f2053d Compare September 25, 2025 10:35
* Add ErrResourceListFailed, ErrResourceReadFailed for server communication errors (502)
* Add ErrResourceNotFound for missing resources (404)
* Add ErrResourceForbidden for access control violations (403)
* Add ErrResourcesNotImplemented for servers without resource capability (501)

These errors enable proper HTTP status code mapping in the API layer.
* Add mapping for ErrResourceNotFound → 404 Not Found
* Add mapping for ErrResourceForbidden → 403 Forbidden
* Add mapping for ErrResourceListFailed → 502 Bad Gateway
* Add mapping for ErrResourceReadFailed → 502 Bad Gateway
* Add mapping for ErrResourcesNotImplemented → 501 Not Implemented
* Add comprehensive test cases for all new error mappings

This enables proper REST API status codes for resource-related errors.
* Add Resource, ResourceTemplate, ResourceContent API types with proper JSON tags
* Add Meta type alias for consistent metadata handling
* Add DomainResource, DomainResourceTemplate, DomainMeta wrapper types
* Implement ToAPIType methods with proper MCP spec compliance
* Add handleServerResources with cursor-based pagination support
* Add handleServerResourceTemplates for URI template discovery
* Add handleServerResourceRead for content retrieval
* Add method not found detection with temporary string matching
* Add comprehensive error handling with proper error wrapping

Implements full MCP resource specification for REST API access.
* Add unit tests for handleServerResources with pagination scenarios
* Add unit tests for handleServerResourceTemplates
* Add unit tests for handleServerResourceRead with multiple content types
* Add comprehensive error case testing for all handlers
* Extend mockMCPClient to support resource operations
* Test proper error propagation and HTTP status mapping
* Validate JSON response structure and schema compliance

Ensures robust test coverage for all resource API functionality.
* Add resource-related fields to mockMCPClient for testing
* Add ListResources, ListResourceTemplates, ReadResource mock methods
* Enable comprehensive resource API testing infrastructure

This provides the foundation for resource API test coverage.
Add RegisterResourceRoutes call to RegisterServerRoutes to expose:
* GET /api/v1/servers/{name}/resources - List server resources
* GET /api/v1/servers/{name}/resources/templates - List resource templates
* POST /api/v1/servers/{name}/resources/read - Read resource content

This completes the resource API integration into the REST API.
Add node_modules/ to gitignore for test MCP servers and development tools.
@peteski22 peteski22 force-pushed the peteski22/181/api/resource-support branch from 6f2053d to af40a8f Compare September 25, 2025 10:50
@peteski22 peteski22 merged commit e411800 into main Sep 25, 2025
2 checks passed
@peteski22 peteski22 deleted the peteski22/181/api/resource-support branch September 25, 2025 13:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Extend mcpd HTTP REST API to support resources

3 participants