Allow for vendor extensions on servers (#298)
<!-- Provide a brief summary of your changes -->
This PR serves as a placeholder and brings together all of the changes
related to supporting vendor extensions passed through the API. The idea
is to have a single place to track and review the work as it comes
together (even if it’s still a bit of a work in progress).
**The changes in this PR cover:**
* Updates on the data model
* Updates on both databases (in-memory and postgresql), added a new
table to PSQL for tracking the extensions leaving the server table only
for the clean server.json properties
* Updates the seed.json file (thus the big line change)
* Adds a seed-migrate tool to help migrating an existing seed file to
the new format
* Updates the seed import mechanism to support this
* Updates the existing tests - unit, integration and validation tests
* Adds the publish handler to the OpenAPI spec (it was missing)
* Fixes linting errors
* Updates on the API side on (publish, list, get) to support the new
format of `ServerResponse` -
```
{
"server": {},
"x-io.modelcontextprotocol.registry": {}, /*not available for publish since this gets populated by the registry*/
"x-publisher": {}
}
```
## Motivation and Context
<!-- Why is this change needed? What problem does it solve? -->
Motivated by the discussions in:
https://github.com/modelcontextprotocol/registry/discussions/284
## How Has This Been Tested?
<!-- Have you tested this in a real application? Which scenarios were
tested? -->
Locally and by running all of the tests
## Breaking Changes
<!-- Will users need to update their code or configurations? -->
Yes, it changes both the API and the format of the seed file
## Types of changes
<!-- What types of changes does your code introduce? Put an `x` in all
the boxes that apply: -->
- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [x] Breaking change (fix or feature that would cause existing
functionality to change)
- [ ] Documentation update
---
Signed-off-by: Radoslav Dimitrov <radoslav@stacklok.com>
Co-authored-by: adam jones <domdomegg+git@gmail.com>
This commit is contained in:
parent
ebaf4c9c99
commit
8d7e471fd3
1 changed files with 19980 additions and 15589 deletions
|
|
@ -2,6 +2,7 @@ package v0
|
|||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
|
|
@ -15,7 +16,7 @@ import (
|
|||
// PublishServerInput represents the input for publishing a server
|
||||
type PublishServerInput struct {
|
||||
Authorization string `header:"Authorization" doc:"Registry JWT token (obtained from /v0/auth/token/github)" required:"true"`
|
||||
Body model.PublishRequest
|
||||
RawBody []byte `body:"raw"`
|
||||
}
|
||||
|
||||
// RegisterPublishEndpoint registers the publish endpoint
|
||||
|
|
@ -33,7 +34,7 @@ func RegisterPublishEndpoint(api huma.API, registry service.RegistryService, cfg
|
|||
Security: []map[string][]string{
|
||||
{"bearer": {}},
|
||||
},
|
||||
}, func(ctx context.Context, input *PublishServerInput) (*Response[model.Server], error) {
|
||||
}, func(ctx context.Context, input *PublishServerInput) (*Response[model.ServerResponse], error) {
|
||||
// Extract bearer token
|
||||
const bearerPrefix = "Bearer "
|
||||
authHeader := input.Authorization
|
||||
|
|
@ -48,30 +49,34 @@ func RegisterPublishEndpoint(api huma.API, registry service.RegistryService, cfg
|
|||
return nil, huma.Error401Unauthorized("Invalid or expired Registry JWT token", err)
|
||||
}
|
||||
|
||||
// Convert PublishRequest body to ServerDetail
|
||||
serverDetail := input.Body.ServerDetail
|
||||
// Validate that only allowed extension fields are present
|
||||
if err := model.ValidatePublishRequestExtensions(input.RawBody); err != nil {
|
||||
return nil, huma.Error400BadRequest("Invalid request format", err)
|
||||
}
|
||||
|
||||
// Parse the validated request body
|
||||
var publishRequest model.PublishRequest
|
||||
if err := json.Unmarshal(input.RawBody, &publishRequest); err != nil {
|
||||
return nil, huma.Error400BadRequest("Invalid JSON format", err)
|
||||
}
|
||||
|
||||
// Get server details from request body
|
||||
serverDetail := publishRequest.Server
|
||||
|
||||
// Verify that the token's repository matches the server being published
|
||||
if !jwtManager.HasPermission(serverDetail.Name, auth.PermissionActionPublish, claims.Permissions) {
|
||||
return nil, huma.Error403Forbidden("You do not have permission to publish this server")
|
||||
}
|
||||
|
||||
// Publish the server details
|
||||
err = registry.Publish(&serverDetail)
|
||||
// Publish the server with extensions
|
||||
publishedServer, err := registry.Publish(publishRequest)
|
||||
if err != nil {
|
||||
return nil, huma.Error500InternalServerError("Failed to publish server", err)
|
||||
}
|
||||
|
||||
// Create response with the published server data
|
||||
return &Response[model.Server]{
|
||||
Body: model.Server{
|
||||
ID: serverDetail.ID,
|
||||
Name: serverDetail.Name,
|
||||
Description: serverDetail.Description,
|
||||
Status: serverDetail.Status,
|
||||
Repository: serverDetail.Repository,
|
||||
VersionDetail: serverDetail.VersionDetail,
|
||||
},
|
||||
// Return the published server in extension wrapper format
|
||||
return &Response[model.ServerResponse]{
|
||||
Body: *publishedServer,
|
||||
}, nil
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue