Add webhook subscription MCP tools and N8N operations
Expose webhook subscription CRUD and event listing through the MCP API (list, get, create, update, delete subscriptions + list events) and add a new webhook resource to the N8N node with matching operations. Signed-off-by: Sacha Al Himdani <sacha@getprobo.com>
This commit is contained in:
@@ -3922,3 +3922,129 @@ func (r *Resolver) PublishStatementOfApplicabilityTool(ctx context.Context, req
|
||||
DocumentVersionID: documentVersion.ID,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (r *Resolver) ListWebhookSubscriptionsTool(ctx context.Context, req *mcp.CallToolRequest, input *types.ListWebhookSubscriptionsInput) (*mcp.CallToolResult, types.ListWebhookSubscriptionsOutput, error) {
|
||||
r.MustAuthorize(ctx, input.OrganizationID, probo.ActionWebhookSubscriptionList)
|
||||
|
||||
prb := r.ProboService(ctx, input.OrganizationID)
|
||||
|
||||
pageOrderBy := page.OrderBy[coredata.WebhookSubscriptionOrderField]{
|
||||
Field: coredata.WebhookSubscriptionOrderFieldCreatedAt,
|
||||
Direction: page.OrderDirectionDesc,
|
||||
}
|
||||
if input.OrderBy != nil {
|
||||
pageOrderBy = page.OrderBy[coredata.WebhookSubscriptionOrderField]{
|
||||
Field: input.OrderBy.Field,
|
||||
Direction: input.OrderBy.Direction,
|
||||
}
|
||||
}
|
||||
|
||||
cursor := types.NewCursor(input.Size, input.Cursor, pageOrderBy)
|
||||
|
||||
page, err := prb.WebhookSubscriptions.ListForOrganizationID(ctx, input.OrganizationID, cursor)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("cannot list webhook subscriptions: %w", err))
|
||||
}
|
||||
|
||||
return nil, types.NewListWebhookSubscriptionsOutput(page), nil
|
||||
}
|
||||
|
||||
func (r *Resolver) GetWebhookSubscriptionTool(ctx context.Context, req *mcp.CallToolRequest, input *types.GetWebhookSubscriptionInput) (*mcp.CallToolResult, types.GetWebhookSubscriptionOutput, error) {
|
||||
r.MustAuthorize(ctx, input.ID, probo.ActionWebhookSubscriptionGet)
|
||||
|
||||
prb := r.ProboService(ctx, input.ID)
|
||||
|
||||
subscription, err := prb.WebhookSubscriptions.Get(ctx, input.ID)
|
||||
if err != nil {
|
||||
return nil, types.GetWebhookSubscriptionOutput{}, fmt.Errorf("failed to get webhook subscription: %w", err)
|
||||
}
|
||||
|
||||
return nil, types.GetWebhookSubscriptionOutput{
|
||||
WebhookSubscription: types.NewWebhookSubscription(subscription),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (r *Resolver) CreateWebhookSubscriptionTool(ctx context.Context, req *mcp.CallToolRequest, input *types.CreateWebhookSubscriptionInput) (*mcp.CallToolResult, types.CreateWebhookSubscriptionOutput, error) {
|
||||
r.MustAuthorize(ctx, input.OrganizationID, probo.ActionWebhookSubscriptionCreate)
|
||||
|
||||
prb := r.ProboService(ctx, input.OrganizationID)
|
||||
|
||||
subscription, err := prb.WebhookSubscriptions.Create(
|
||||
ctx,
|
||||
probo.CreateWebhookSubscriptionRequest{
|
||||
OrganizationID: input.OrganizationID,
|
||||
EndpointURL: input.EndpointURL,
|
||||
SelectedEvents: input.SelectedEvents,
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
return nil, types.CreateWebhookSubscriptionOutput{}, fmt.Errorf("failed to create webhook subscription: %w", err)
|
||||
}
|
||||
|
||||
return nil, types.CreateWebhookSubscriptionOutput{
|
||||
WebhookSubscription: types.NewWebhookSubscription(subscription),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (r *Resolver) UpdateWebhookSubscriptionTool(ctx context.Context, req *mcp.CallToolRequest, input *types.UpdateWebhookSubscriptionInput) (*mcp.CallToolResult, types.UpdateWebhookSubscriptionOutput, error) {
|
||||
r.MustAuthorize(ctx, input.ID, probo.ActionWebhookSubscriptionUpdate)
|
||||
|
||||
prb := r.ProboService(ctx, input.ID)
|
||||
|
||||
subscription, err := prb.WebhookSubscriptions.Update(
|
||||
ctx,
|
||||
probo.UpdateWebhookSubscriptionRequest{
|
||||
WebhookSubscriptionID: input.ID,
|
||||
EndpointURL: input.EndpointURL,
|
||||
SelectedEvents: input.SelectedEvents,
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
return nil, types.UpdateWebhookSubscriptionOutput{}, fmt.Errorf("failed to update webhook subscription: %w", err)
|
||||
}
|
||||
|
||||
return nil, types.UpdateWebhookSubscriptionOutput{
|
||||
WebhookSubscription: types.NewWebhookSubscription(subscription),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (r *Resolver) DeleteWebhookSubscriptionTool(ctx context.Context, req *mcp.CallToolRequest, input *types.DeleteWebhookSubscriptionInput) (*mcp.CallToolResult, types.DeleteWebhookSubscriptionOutput, error) {
|
||||
r.MustAuthorize(ctx, input.ID, probo.ActionWebhookSubscriptionDelete)
|
||||
|
||||
prb := r.ProboService(ctx, input.ID)
|
||||
|
||||
err := prb.WebhookSubscriptions.Delete(ctx, input.ID)
|
||||
if err != nil {
|
||||
return nil, types.DeleteWebhookSubscriptionOutput{}, fmt.Errorf("failed to delete webhook subscription: %w", err)
|
||||
}
|
||||
|
||||
return nil, types.DeleteWebhookSubscriptionOutput{
|
||||
DeletedWebhookSubscriptionID: input.ID,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (r *Resolver) ListWebhookEventsTool(ctx context.Context, req *mcp.CallToolRequest, input *types.ListWebhookEventsInput) (*mcp.CallToolResult, types.ListWebhookEventsOutput, error) {
|
||||
r.MustAuthorize(ctx, input.WebhookSubscriptionID, probo.ActionWebhookSubscriptionGet)
|
||||
|
||||
prb := r.ProboService(ctx, input.WebhookSubscriptionID)
|
||||
|
||||
pageOrderBy := page.OrderBy[coredata.WebhookEventOrderField]{
|
||||
Field: coredata.WebhookEventOrderFieldCreatedAt,
|
||||
Direction: page.OrderDirectionDesc,
|
||||
}
|
||||
if input.OrderBy != nil {
|
||||
pageOrderBy = page.OrderBy[coredata.WebhookEventOrderField]{
|
||||
Field: input.OrderBy.Field,
|
||||
Direction: input.OrderBy.Direction,
|
||||
}
|
||||
}
|
||||
|
||||
cursor := types.NewCursor(input.Size, input.Cursor, pageOrderBy)
|
||||
|
||||
page, err := prb.WebhookSubscriptions.ListEventsForSubscriptionID(ctx, input.WebhookSubscriptionID, cursor)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("cannot list webhook events: %w", err))
|
||||
}
|
||||
|
||||
return nil, types.NewListWebhookEventsOutput(page), nil
|
||||
}
|
||||
|
||||
@@ -5950,6 +5950,284 @@ components:
|
||||
format: date-time
|
||||
description: Update timestamp
|
||||
|
||||
WebhookEventType:
|
||||
type: string
|
||||
enum:
|
||||
- "meeting:created"
|
||||
- "meeting:updated"
|
||||
- "meeting:deleted"
|
||||
- "vendor:created"
|
||||
- "vendor:updated"
|
||||
- "vendor:deleted"
|
||||
- "user:created"
|
||||
- "user:updated"
|
||||
- "user:deleted"
|
||||
- "obligation:created"
|
||||
- "obligation:updated"
|
||||
- "obligation:deleted"
|
||||
go.probo.inc/mcpgen/type: go.probo.inc/probo/pkg/coredata.WebhookEventType
|
||||
|
||||
WebhookEventStatus:
|
||||
type: string
|
||||
enum:
|
||||
- PENDING
|
||||
- SUCCEEDED
|
||||
- FAILED
|
||||
go.probo.inc/mcpgen/type: go.probo.inc/probo/pkg/coredata.WebhookEventStatus
|
||||
|
||||
WebhookSubscriptionOrderField:
|
||||
type: string
|
||||
enum:
|
||||
- CREATED_AT
|
||||
go.probo.inc/mcpgen/type: go.probo.inc/probo/pkg/coredata.WebhookSubscriptionOrderField
|
||||
|
||||
WebhookSubscriptionOrderBy:
|
||||
type: object
|
||||
required:
|
||||
- field
|
||||
- direction
|
||||
properties:
|
||||
field:
|
||||
$ref: "#/components/schemas/WebhookSubscriptionOrderField"
|
||||
description: Webhook subscription order field
|
||||
direction:
|
||||
$ref: "#/components/schemas/OrderDirection"
|
||||
description: Order direction
|
||||
|
||||
WebhookEventOrderField:
|
||||
type: string
|
||||
enum:
|
||||
- CREATED_AT
|
||||
go.probo.inc/mcpgen/type: go.probo.inc/probo/pkg/coredata.WebhookEventOrderField
|
||||
|
||||
WebhookEventOrderBy:
|
||||
type: object
|
||||
required:
|
||||
- field
|
||||
- direction
|
||||
properties:
|
||||
field:
|
||||
$ref: "#/components/schemas/WebhookEventOrderField"
|
||||
description: Webhook event order field
|
||||
direction:
|
||||
$ref: "#/components/schemas/OrderDirection"
|
||||
description: Order direction
|
||||
|
||||
WebhookSubscription:
|
||||
type: object
|
||||
required:
|
||||
- id
|
||||
- organization_id
|
||||
- endpoint_url
|
||||
- selected_events
|
||||
- created_at
|
||||
- updated_at
|
||||
properties:
|
||||
id:
|
||||
$ref: "#/components/schemas/GID"
|
||||
description: Webhook subscription ID
|
||||
organization_id:
|
||||
$ref: "#/components/schemas/GID"
|
||||
description: Organization ID
|
||||
endpoint_url:
|
||||
type: string
|
||||
description: The HTTPS endpoint URL that receives webhook events
|
||||
selected_events:
|
||||
type: array
|
||||
items:
|
||||
$ref: "#/components/schemas/WebhookEventType"
|
||||
description: List of event types this subscription listens to
|
||||
created_at:
|
||||
type: string
|
||||
format: date-time
|
||||
description: Creation timestamp
|
||||
updated_at:
|
||||
type: string
|
||||
format: date-time
|
||||
description: Update timestamp
|
||||
|
||||
WebhookEvent:
|
||||
type: object
|
||||
required:
|
||||
- id
|
||||
- webhook_subscription_id
|
||||
- status
|
||||
- created_at
|
||||
properties:
|
||||
id:
|
||||
$ref: "#/components/schemas/GID"
|
||||
description: Webhook event ID
|
||||
webhook_subscription_id:
|
||||
$ref: "#/components/schemas/GID"
|
||||
description: Webhook subscription ID
|
||||
status:
|
||||
$ref: "#/components/schemas/WebhookEventStatus"
|
||||
description: Delivery status
|
||||
response:
|
||||
anyOf:
|
||||
- type: string
|
||||
- type: "null"
|
||||
description: HTTP response body from the endpoint
|
||||
created_at:
|
||||
type: string
|
||||
format: date-time
|
||||
description: Creation timestamp
|
||||
|
||||
ListWebhookSubscriptionsInput:
|
||||
type: object
|
||||
required:
|
||||
- organization_id
|
||||
properties:
|
||||
organization_id:
|
||||
$ref: "#/components/schemas/GID"
|
||||
description: Organization ID
|
||||
order_by:
|
||||
$ref: "#/components/schemas/WebhookSubscriptionOrderBy"
|
||||
description: Order by
|
||||
size:
|
||||
type: integer
|
||||
description: Page size
|
||||
cursor:
|
||||
$ref: "#/components/schemas/CursorKey"
|
||||
description: Page cursor
|
||||
|
||||
ListWebhookSubscriptionsOutput:
|
||||
type: object
|
||||
required:
|
||||
- webhook_subscriptions
|
||||
properties:
|
||||
webhook_subscriptions:
|
||||
type: array
|
||||
items:
|
||||
$ref: "#/components/schemas/WebhookSubscription"
|
||||
description: List of webhook subscriptions
|
||||
next_cursor:
|
||||
anyOf:
|
||||
- $ref: "#/components/schemas/CursorKey"
|
||||
- type: "null"
|
||||
description: Next page cursor
|
||||
|
||||
GetWebhookSubscriptionInput:
|
||||
type: object
|
||||
required:
|
||||
- id
|
||||
properties:
|
||||
id:
|
||||
$ref: "#/components/schemas/GID"
|
||||
description: Webhook subscription ID
|
||||
|
||||
GetWebhookSubscriptionOutput:
|
||||
type: object
|
||||
required:
|
||||
- webhook_subscription
|
||||
properties:
|
||||
webhook_subscription:
|
||||
$ref: "#/components/schemas/WebhookSubscription"
|
||||
|
||||
CreateWebhookSubscriptionInput:
|
||||
type: object
|
||||
required:
|
||||
- organization_id
|
||||
- endpoint_url
|
||||
- selected_events
|
||||
properties:
|
||||
organization_id:
|
||||
$ref: "#/components/schemas/GID"
|
||||
description: Organization ID
|
||||
endpoint_url:
|
||||
type: string
|
||||
description: The HTTPS endpoint URL that receives webhook events
|
||||
selected_events:
|
||||
type: array
|
||||
items:
|
||||
$ref: "#/components/schemas/WebhookEventType"
|
||||
description: List of event types to subscribe to
|
||||
|
||||
CreateWebhookSubscriptionOutput:
|
||||
type: object
|
||||
required:
|
||||
- webhook_subscription
|
||||
properties:
|
||||
webhook_subscription:
|
||||
$ref: "#/components/schemas/WebhookSubscription"
|
||||
|
||||
UpdateWebhookSubscriptionInput:
|
||||
type: object
|
||||
required:
|
||||
- id
|
||||
properties:
|
||||
id:
|
||||
$ref: "#/components/schemas/GID"
|
||||
description: Webhook subscription ID
|
||||
endpoint_url:
|
||||
type: string
|
||||
description: The HTTPS endpoint URL that receives webhook events
|
||||
selected_events:
|
||||
type: array
|
||||
items:
|
||||
$ref: "#/components/schemas/WebhookEventType"
|
||||
description: List of event types to subscribe to
|
||||
|
||||
UpdateWebhookSubscriptionOutput:
|
||||
type: object
|
||||
required:
|
||||
- webhook_subscription
|
||||
properties:
|
||||
webhook_subscription:
|
||||
$ref: "#/components/schemas/WebhookSubscription"
|
||||
|
||||
DeleteWebhookSubscriptionInput:
|
||||
type: object
|
||||
required:
|
||||
- id
|
||||
properties:
|
||||
id:
|
||||
$ref: "#/components/schemas/GID"
|
||||
description: Webhook subscription ID
|
||||
|
||||
DeleteWebhookSubscriptionOutput:
|
||||
type: object
|
||||
required:
|
||||
- deleted_webhook_subscription_id
|
||||
properties:
|
||||
deleted_webhook_subscription_id:
|
||||
$ref: "#/components/schemas/GID"
|
||||
description: Deleted webhook subscription ID
|
||||
|
||||
ListWebhookEventsInput:
|
||||
type: object
|
||||
required:
|
||||
- webhook_subscription_id
|
||||
properties:
|
||||
webhook_subscription_id:
|
||||
$ref: "#/components/schemas/GID"
|
||||
description: Webhook subscription ID
|
||||
order_by:
|
||||
$ref: "#/components/schemas/WebhookEventOrderBy"
|
||||
description: Order by
|
||||
size:
|
||||
type: integer
|
||||
description: Page size
|
||||
cursor:
|
||||
$ref: "#/components/schemas/CursorKey"
|
||||
description: Page cursor
|
||||
|
||||
ListWebhookEventsOutput:
|
||||
type: object
|
||||
required:
|
||||
- webhook_events
|
||||
properties:
|
||||
webhook_events:
|
||||
type: array
|
||||
items:
|
||||
$ref: "#/components/schemas/WebhookEvent"
|
||||
description: List of webhook events
|
||||
next_cursor:
|
||||
anyOf:
|
||||
- $ref: "#/components/schemas/CursorKey"
|
||||
- type: "null"
|
||||
description: Next page cursor
|
||||
|
||||
ListMeetingsInput:
|
||||
type: object
|
||||
required:
|
||||
@@ -8845,3 +9123,55 @@ tools:
|
||||
$ref: "#/components/schemas/ListAuditLogEntriesInput"
|
||||
outputSchema:
|
||||
$ref: "#/components/schemas/ListAuditLogEntriesOutput"
|
||||
- name: listWebhookSubscriptions
|
||||
description: List all webhook subscriptions for the organization
|
||||
hints:
|
||||
readonly: true
|
||||
idempotent: true
|
||||
inputSchema:
|
||||
$ref: "#/components/schemas/ListWebhookSubscriptionsInput"
|
||||
outputSchema:
|
||||
$ref: "#/components/schemas/ListWebhookSubscriptionsOutput"
|
||||
- name: getWebhookSubscription
|
||||
description: Get a webhook subscription by ID
|
||||
hints:
|
||||
readonly: true
|
||||
idempotent: true
|
||||
inputSchema:
|
||||
$ref: "#/components/schemas/GetWebhookSubscriptionInput"
|
||||
outputSchema:
|
||||
$ref: "#/components/schemas/GetWebhookSubscriptionOutput"
|
||||
- name: createWebhookSubscription
|
||||
description: Create a new webhook subscription for the organization. The endpoint URL must use HTTPS. Selected events determine which events trigger webhook deliveries.
|
||||
hints:
|
||||
readonly: false
|
||||
inputSchema:
|
||||
$ref: "#/components/schemas/CreateWebhookSubscriptionInput"
|
||||
outputSchema:
|
||||
$ref: "#/components/schemas/CreateWebhookSubscriptionOutput"
|
||||
- name: updateWebhookSubscription
|
||||
description: Update a webhook subscription's endpoint URL or selected events
|
||||
hints:
|
||||
readonly: false
|
||||
inputSchema:
|
||||
$ref: "#/components/schemas/UpdateWebhookSubscriptionInput"
|
||||
outputSchema:
|
||||
$ref: "#/components/schemas/UpdateWebhookSubscriptionOutput"
|
||||
- name: deleteWebhookSubscription
|
||||
description: Delete a webhook subscription
|
||||
hints:
|
||||
readonly: false
|
||||
destructive: true
|
||||
inputSchema:
|
||||
$ref: "#/components/schemas/DeleteWebhookSubscriptionInput"
|
||||
outputSchema:
|
||||
$ref: "#/components/schemas/DeleteWebhookSubscriptionOutput"
|
||||
- name: listWebhookEvents
|
||||
description: List webhook delivery events for a subscription. Shows delivery status (PENDING, SUCCEEDED, FAILED) and response details.
|
||||
hints:
|
||||
readonly: true
|
||||
idempotent: true
|
||||
inputSchema:
|
||||
$ref: "#/components/schemas/ListWebhookEventsInput"
|
||||
outputSchema:
|
||||
$ref: "#/components/schemas/ListWebhookEventsOutput"
|
||||
|
||||
88
pkg/server/api/mcp/v1/types/webhook_subscription.go
Normal file
88
pkg/server/api/mcp/v1/types/webhook_subscription.go
Normal file
@@ -0,0 +1,88 @@
|
||||
// Copyright (c) 2026 Probo Inc <hello@getprobo.com>.
|
||||
//
|
||||
// Permission to use, copy, modify, and/or distribute this software for any
|
||||
// purpose with or without fee is hereby granted, provided that the above
|
||||
// copyright notice and this permission notice appear in all copies.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
||||
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
||||
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
||||
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
// PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
package types
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"go.probo.inc/probo/pkg/coredata"
|
||||
"go.probo.inc/probo/pkg/page"
|
||||
)
|
||||
|
||||
func NewWebhookSubscription(w *coredata.WebhookSubscription) *WebhookSubscription {
|
||||
events := make([]coredata.WebhookEventType, len(w.SelectedEvents))
|
||||
copy(events, w.SelectedEvents)
|
||||
|
||||
return &WebhookSubscription{
|
||||
ID: w.ID,
|
||||
OrganizationID: w.OrganizationID,
|
||||
EndpointURL: w.EndpointURL,
|
||||
SelectedEvents: events,
|
||||
CreatedAt: w.CreatedAt,
|
||||
UpdatedAt: w.UpdatedAt,
|
||||
}
|
||||
}
|
||||
|
||||
func NewListWebhookSubscriptionsOutput(p *page.Page[*coredata.WebhookSubscription, coredata.WebhookSubscriptionOrderField]) ListWebhookSubscriptionsOutput {
|
||||
subscriptions := make([]*WebhookSubscription, 0, len(p.Data))
|
||||
for _, w := range p.Data {
|
||||
subscriptions = append(subscriptions, NewWebhookSubscription(w))
|
||||
}
|
||||
|
||||
var nextCursor *page.CursorKey
|
||||
if len(p.Data) > 0 {
|
||||
cursorKey := p.Data[len(p.Data)-1].CursorKey(p.Cursor.OrderBy.Field)
|
||||
nextCursor = &cursorKey
|
||||
}
|
||||
|
||||
return ListWebhookSubscriptionsOutput{
|
||||
NextCursor: nextCursor,
|
||||
WebhookSubscriptions: subscriptions,
|
||||
}
|
||||
}
|
||||
|
||||
func NewWebhookEvent(e *coredata.WebhookEvent) *WebhookEvent {
|
||||
var response *string
|
||||
if len(e.Response) > 0 && string(e.Response) != "null" {
|
||||
s := string(json.RawMessage(e.Response))
|
||||
response = &s
|
||||
}
|
||||
|
||||
return &WebhookEvent{
|
||||
ID: e.ID,
|
||||
WebhookSubscriptionID: e.WebhookSubscriptionID,
|
||||
Status: e.Status,
|
||||
Response: response,
|
||||
CreatedAt: e.CreatedAt,
|
||||
}
|
||||
}
|
||||
|
||||
func NewListWebhookEventsOutput(p *page.Page[*coredata.WebhookEvent, coredata.WebhookEventOrderField]) ListWebhookEventsOutput {
|
||||
events := make([]*WebhookEvent, 0, len(p.Data))
|
||||
for _, e := range p.Data {
|
||||
events = append(events, NewWebhookEvent(e))
|
||||
}
|
||||
|
||||
var nextCursor *page.CursorKey
|
||||
if len(p.Data) > 0 {
|
||||
cursorKey := p.Data[len(p.Data)-1].CursorKey(p.Cursor.OrderBy.Field)
|
||||
nextCursor = &cursorKey
|
||||
}
|
||||
|
||||
return ListWebhookEventsOutput{
|
||||
NextCursor: nextCursor,
|
||||
WebhookEvents: events,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user