You've already forked agentic-coding-workflow
feat(mcp): scope check helpers (CheckToolFromCtx + CheckProjectFromCtx)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
package mcp
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/google/uuid"
|
||||
|
||||
"github.com/yan1h/agent-coding-workflow/internal/infra/errs"
|
||||
)
|
||||
|
||||
func CheckToolFromCtx(ctx context.Context, toolName string) error {
|
||||
sess, ok := FromContext(ctx)
|
||||
if !ok {
|
||||
return errs.New(errs.CodeInternal, "mcp: AuthSession missing")
|
||||
}
|
||||
if !sess.Scope.AllowsTool(toolName) {
|
||||
return errs.New(errs.CodeMcpTokenScopeViolation,
|
||||
"tool '"+toolName+"' is not in token scope")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func CheckProjectFromCtx(ctx context.Context, projectID uuid.UUID) error {
|
||||
sess, ok := FromContext(ctx)
|
||||
if !ok {
|
||||
return errs.New(errs.CodeInternal, "mcp: AuthSession missing")
|
||||
}
|
||||
if !sess.Scope.AllowsProject(projectID) {
|
||||
return errs.New(errs.CodeMcpTokenScopeViolation,
|
||||
"project is not in token scope")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user