Add tools and update authenticztion and RBAC
Signed-off-by: Bryan Frimin <bryan@getprobo.com>
This commit is contained in:
@@ -2,7 +2,6 @@ package mcp_v1
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
@@ -13,27 +12,14 @@ import (
|
||||
"go.probo.inc/probo/pkg/authz"
|
||||
"go.probo.inc/probo/pkg/gid"
|
||||
"go.probo.inc/probo/pkg/probo"
|
||||
"go.probo.inc/probo/pkg/server/api/mcp/mcputils"
|
||||
"go.probo.inc/probo/pkg/server/api/mcp/v1/server"
|
||||
serverauth "go.probo.inc/probo/pkg/server/auth"
|
||||
)
|
||||
|
||||
func (r *Resolver) ProboService(ctx context.Context, tenantID gid.TenantID) *probo.TenantService {
|
||||
validateTenantAccess(ctx, tenantID)
|
||||
return r.proboSvc.WithTenant(tenantID)
|
||||
}
|
||||
|
||||
func validateTenantAccess(ctx context.Context, tenantID gid.TenantID) {
|
||||
mcpCtx := MCPContextFromContext(ctx)
|
||||
if mcpCtx == nil {
|
||||
panic(fmt.Errorf("authentication context not found"))
|
||||
}
|
||||
|
||||
for _, tid := range mcpCtx.TenantIDs {
|
||||
if tid == tenantID {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
panic(fmt.Errorf("access denied: user does not have access to tenant %s", tenantID.String()))
|
||||
func (r *Resolver) ProboService(ctx context.Context, objectID gid.GID) *probo.TenantService {
|
||||
serverauth.RequireTenantAccess(ctx, objectID.TenantID())
|
||||
return r.proboSvc.WithTenant(objectID.TenantID())
|
||||
}
|
||||
|
||||
func NewMux(logger *log.Logger, proboSvc *probo.Service, authSvc *auth.Service, authzSvc *authz.Service, cfg Config) *chi.Mux {
|
||||
@@ -54,6 +40,10 @@ func NewMux(logger *log.Logger, proboSvc *probo.Service, authSvc *auth.Service,
|
||||
|
||||
mcpServer := server.New(resolver)
|
||||
|
||||
// Add panic recovery middleware to handle panics in goroutines spawned by MCP SDK
|
||||
mcpServer.AddReceivingMiddleware(mcputils.LoggingMiddleware(logger))
|
||||
mcpServer.AddReceivingMiddleware(mcputils.RecoveryMiddleware(logger))
|
||||
|
||||
getServer := func(r *http.Request) *mcp.Server { return mcpServer }
|
||||
eventStore := mcp.NewMemoryEventStore(nil)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user