flashduty

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 3, 2025 License: MIT Imports: 13 Imported by: 0

README

Flashduty MCP Server Package

This package provides Model Context Protocol (MCP) tools for interacting with the Flashduty API, based on the official OpenAPI specification.

Architecture

The implementation follows the same patterns as the GitHub MCP Server:

  • Client (client.go): HTTP client for Flashduty API with app_key authentication
  • Server helpers (server.go): Common parameter handling and response utilities
  • Tools (tools.go): Tool set organization and registration
  • Members (members.go): Member management tools implementation

Authentication

Uses Flashduty's app_key authentication method via query parameters:

https://api.flashcat.cloud/member/list?app_key=YOUR_APP_KEY

Members Toolset

Available Tools
1. flashduty_get_member_list
  • Method: POST /member/list
  • Description: Get paginated list of members
  • Parameters:
    • p (number): Page number, starting from 1 (default: 1)
    • limit (number): Items per page (default: 20)
    • query (string): Search keyword for member name
    • role_id (number): Filter by role ID
    • orderby (string): Sort field (created_at, updated_at)
    • asc (boolean): Sort ascending (default: false)
2. flashduty_invite_member
  • Method: POST /member/invite
  • Description: Invite a new member to the account
  • Parameters:
    • email (string): Email address (required if phone not provided)
    • phone (string): Phone number (required if email not provided)
    • country_code (string): Country code (default: CN)
    • member_name (string): Member name (required when phone provided)
    • ref_id (string): Reference ID
    • role_ids (string): Comma-separated list of role IDs
3. flashduty_update_member_info
  • Method: POST /member/info/reset
  • Description: Update member information
  • Identity Parameters (exactly one required):
    • member_id (number): Member ID
    • member_name (string): Member name
    • phone (string): Member phone
    • email (string): Member email
    • ref_id (string): Reference ID
  • Update Parameters (at least one required):
    • new_phone (string): New phone number
    • new_country_code (string): New country code
    • new_email (string): New email address
    • new_member_name (string): New member name
    • new_time_zone (string): New timezone (tzdata format)
    • new_locale (string): New locale (zh-CN, en-US)
    • new_ref_id (string): New reference ID
4. flashduty_delete_member
  • Method: POST /member/delete
  • Description: Delete a member from the account
  • Parameters (exactly one required):
    • member_id (number): Member ID
    • phone (string): Member phone
    • email (string): Member email
    • ref_id (string): Reference ID

Key Implementation Details

API Differences from REST Standards
  • All operations use POST method, not GET/PUT/DELETE
  • Uses specific Flashduty API paths (/member/list, /member/invite, etc.)
  • Request body structure follows Flashduty's schema exactly
  • Authentication via query parameter app_key instead of Bearer token
Request/Response Structure
// Member list request
{
  "p": 1,
  "limit": 20,
  "query": "search term"
}

// Member invite request  
{
  "members": [
    {
      "email": "user@example.com",
      "member_name": "User Name",
      "country_code": "CN",
      "role_ids": [1, 2]
    }
  ]
}

// Member update request
{
  "member_id": 123,
  "updates": {
    "member_name": "New Name",
    "email": "new@example.com"
  }
}
Error Handling

Flashduty API returns errors in this format:

{
  "error": {
    "code": "InvalidParameter",
    "message": "Error description"
  }
}

Testing

The package includes comprehensive unit tests using mock clients:

cd pkg/flashduty
go test -v

Tests cover:

  • Tool metadata validation
  • Request parameter handling
  • API request construction
  • Response parsing
  • Error scenarios

Future Expansion

The current implementation focuses on member management. The architecture supports easy addition of other Flashduty toolsets:

  • Teams management (/team/*)
  • Schedules management (/schedule/*)
  • Channels management (/channel/*)
  • Incidents management (/incident/*)
  • Alerts management (/alert/*)
  • Analytics (/analytics/*)

Each toolset would follow the same pattern established in the members implementation.

Documentation

Overview

This is a new file

Index

Constants

This section is empty.

Variables

View Source
var DefaultTools = []string{"flashduty_members", "flashduty_teams", "flashduty_channels", "flashduty_incidents"}

DefaultTools is the default list of enabled Flashduty toolsets

Functions

func AckIncident

func AckIncident(getClient GetFlashdutyClientFn, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc)

AckIncident creates a tool to acknowledge incidents

func AddResponder

func AddResponder(getClient GetFlashdutyClientFn, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc)

AddResponder creates a tool to add responders to incidents

func AssignIncident

func AssignIncident(getClient GetFlashdutyClientFn, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc)

AssignIncident creates a tool to assign incidents to people or escalation rules

func ChannelInfos

func ChannelInfos(getClient GetFlashdutyClientFn, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc)

ChannelInfos creates a tool to get collaboration space information by channel IDs

func CommentIncident

func CommentIncident(getClient GetFlashdutyClientFn, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc)

CommentIncident creates a tool to add comments to incidents

func CreateIncident

func CreateIncident(getClient GetFlashdutyClientFn, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc)

CreateIncident creates a tool to create a new incident

func DefaultToolsetGroup

func DefaultToolsetGroup(getClient GetFlashdutyClientFn, readOnly bool, t translations.TranslationHelperFunc) *toolsets.ToolsetGroup

DefaultToolsetGroup returns the default toolset group for Flashduty

func GetIncidentAlerts

func GetIncidentAlerts(getClient GetFlashdutyClientFn, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc)

GetIncidentAlerts creates a tool to get alerts associated with incidents

func GetIncidentTimeline

func GetIncidentTimeline(getClient GetFlashdutyClientFn, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc)

GetIncidentTimeline creates a tool to get incident timeline and feed

func IncidentInfos

func IncidentInfos(getClient GetFlashdutyClientFn, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc)

IncidentInfos creates a tool to get incident information by incident IDs

func ListIncidents

func ListIncidents(getClient GetFlashdutyClientFn, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc)

ListIncidents creates a tool to list incidents with comprehensive filters

func ListPastIncidents

func ListPastIncidents(getClient GetFlashdutyClientFn, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc)

ListPastIncidents creates a tool to list similar historical incidents

func MarshalledTextResult

func MarshalledTextResult(v any) *mcp.CallToolResult

MarshalledTextResult marshals the given value to JSON and returns it as a text result

func MemberInfos

func MemberInfos(getClient GetFlashdutyClientFn, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc)

MemberInfos creates a tool to get member information by person IDs

func MergeIncident

func MergeIncident(getClient GetFlashdutyClientFn, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc)

MergeIncident creates a tool to merge multiple incidents into one

func OptionalInt

func OptionalInt(r mcp.CallToolRequest, p string) (int, error)

OptionalInt is a helper function that can be used to fetch a requested parameter from the request. It does the following checks: 1. Checks if the parameter is present in the request, if not, it returns its zero-value 2. If it is present, it checks if the parameter is of the expected type and returns it

func OptionalParam

func OptionalParam[T any](r mcp.CallToolRequest, p string) (T, error)

OptionalParam is a helper function that can be used to fetch a requested parameter from the request. It does the following checks: 1. Checks if the parameter is present in the request, if not, it returns its zero-value 2. If it is present, it checks if the parameter is of the expected type and returns it

func RequiredInt

func RequiredInt(r mcp.CallToolRequest, p string) (int, error)

RequiredInt is a helper function that can be used to fetch a requested parameter from the request. It does the following checks: 1. Checks if the parameter is present in the request. 2. Checks if the parameter is of the expected type. 3. Checks if the parameter is not empty, i.e: non-zero value

func RequiredParam

func RequiredParam[T comparable](r mcp.CallToolRequest, p string) (T, error)

RequiredParam is a helper function that can be used to fetch a requested parameter from the request. It does the following checks: 1. Checks if the parameter is present in the request. 2. Checks if the parameter is of the expected type. 3. Checks if the parameter is not empty, i.e: non-zero value

func ResolveIncident

func ResolveIncident(getClient GetFlashdutyClientFn, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc)

ResolveIncident creates a tool to resolve incidents

func SnoozeIncident

func SnoozeIncident(getClient GetFlashdutyClientFn, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc)

SnoozeIncident creates a tool to snooze incidents for a period

func TeamInfos

TeamInfos creates a tool to get team information by team IDs

func ToBoolPtr

func ToBoolPtr(b bool) *bool

ToBoolPtr converts a bool to a *bool pointer.

func UpdateIncidentDescription

func UpdateIncidentDescription(getClient GetFlashdutyClientFn, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc)

UpdateIncidentDescription creates a tool to update incident description

func UpdateIncidentFields

func UpdateIncidentFields(getClient GetFlashdutyClientFn, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc)

UpdateIncidentFields creates a tool to update custom fields

func UpdateIncidentImpact

func UpdateIncidentImpact(getClient GetFlashdutyClientFn, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc)

UpdateIncidentImpact creates a tool to update incident impact

func UpdateIncidentResolution

func UpdateIncidentResolution(getClient GetFlashdutyClientFn, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc)

UpdateIncidentResolution creates a tool to update incident resolution

func UpdateIncidentRootCause

func UpdateIncidentRootCause(getClient GetFlashdutyClientFn, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc)

UpdateIncidentRootCause creates a tool to update incident root cause

func UpdateIncidentSeverity

func UpdateIncidentSeverity(getClient GetFlashdutyClientFn, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc)

UpdateIncidentSeverity creates a tool to update incident severity

func UpdateIncidentTitle

func UpdateIncidentTitle(getClient GetFlashdutyClientFn, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc)

UpdateIncidentTitle creates a tool to update incident title

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client represents a Flashduty API client

func NewClient

func NewClient(appKey, baseURL, userAgent string) (*Client, error)

NewClient creates a new Flashduty API client

func (*Client) SetUserAgent

func (c *Client) SetUserAgent(userAgent string)

SetUserAgent sets the user agent for the client

type DutyError

type DutyError struct {
	Code    string `json:"code"`
	Message string `json:"message"`
}

DutyError represents Flashduty API error

type FlashdutyResponse

type FlashdutyResponse struct {
	Error *DutyError  `json:"error,omitempty"`
	Data  interface{} `json:"data,omitempty"`
}

FlashdutyResponse represents the standard Flashduty API response structure

type GetFlashdutyClientFn

type GetFlashdutyClientFn func(context.Context) (context.Context, *Client, error)

GetFlashdutyClientFn is a function that returns a flashduty client

type MemberItem

type MemberItem struct {
	MemberID       int    `json:"member_id"`
	MemberName     string `json:"member_name"`
	Phone          string `json:"phone,omitempty"`
	PhoneVerified  bool   `json:"phone_verified,omitempty"`
	Email          string `json:"email,omitempty"`
	EmailVerified  bool   `json:"email_verified,omitempty"`
	AccountRoleIDs []int  `json:"account_role_ids,omitempty"`
	TimeZone       string `json:"time_zone,omitempty"`
	Locale         string `json:"locale,omitempty"`
	Status         string `json:"status"`
	CreatedAt      int64  `json:"created_at"`
	UpdatedAt      int64  `json:"updated_at"`
	RefID          string `json:"ref_id,omitempty"`
}

MemberItem represents a member item as defined in the OpenAPI spec

type MemberItemShort

type MemberItemShort struct {
	MemberID   int    `json:"MemberID"`
	MemberName string `json:"MemberName"`
}

MemberItemShort represents a short member item for invite response

type MemberListResponse

type MemberListResponse struct {
	Error *DutyError `json:"error,omitempty"`
	Data  *struct {
		P     int          `json:"p"`
		Limit int          `json:"limit"`
		Total int          `json:"total"`
		Items []MemberItem `json:"items"`
	} `json:"data,omitempty"`
}

MemberListResponse represents the response for member list API

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL