Expose createDevice on MCP, CLI, and n8n

Device create was left off the ITAM surfaces because enrollment
returns a one-shot token. Add createDevice so automations can issue
PENDING devices with the enrollment payload.

Signed-off-by: Ludovic Vielle <ludovic@probo.com>
This commit is contained in:
Ludovic Vielle
2026-07-30 20:52:29 +02:00
parent 62e65eccda
commit b328133b4c
10 changed files with 417 additions and 38 deletions

View File

@@ -7602,3 +7602,46 @@ func (r *Resolver) SetDeviceOwnerTool(ctx context.Context, req *mcp.CallToolRequ
Device: types.NewDevice(device, nil),
}, nil
}
func (r *Resolver) CreateDeviceTool(ctx context.Context, req *mcp.CallToolRequest, input *types.CreateDeviceInput) (*mcp.CallToolResult, types.CreateDeviceOutput, error) {
scope, err := r.Authorize(ctx, input.OrganizationID, itam.ActionDeviceCreate)
if err != nil {
return nil, types.CreateDeviceOutput{}, err
}
result, err := r.itamSvc.CreateDevice(
ctx,
scope,
itam.CreateDeviceRequest{
OrganizationID: input.OrganizationID,
OwnerID: input.OwnerID,
},
)
if err != nil {
if errors.Is(err, coredata.ErrResourceNotFound) {
return nil, types.CreateDeviceOutput{}, fmt.Errorf("resource not found")
}
if errors.Is(err, itam.ErrInvalidOwnerProfile) {
return nil, types.CreateDeviceOutput{}, fmt.Errorf("owner_id must reference a membership profile of the device organization")
}
r.logger.ErrorCtx(ctx, "cannot create device", log.Error(err))
return nil, types.CreateDeviceOutput{}, fmt.Errorf("internal server error")
}
urls, err := itam.BuildEnrollmentURLs(r.baseURL, result.EnrollmentToken)
if err != nil {
r.logger.ErrorCtx(ctx, "cannot build enrollment URLs", log.Error(err))
return nil, types.CreateDeviceOutput{}, fmt.Errorf("internal server error")
}
return nil, types.CreateDeviceOutput{
Device: types.NewDevice(result.Device, nil),
EnrollmentToken: result.EnrollmentToken,
ServerURL: urls.ServerURL,
EnrollmentURL: urls.EnrollmentURL,
}, nil
}