server

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: Apache-2.0 Imports: 17 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package server is the Costfluent MCP server: tools over the Public API, each listed only when the API token the server serves carries the capability the tool's call needs, and a tool that creates or changes an object only while the token's organization lets AI agents write.

Index

Constants

View Source
const APIAttemptTimeout = 100 * time.Second

APIAttemptTimeout is how long a server waits for one attempt at a Public API call. The API answers an interactive request for up to 90 seconds, so the SDK's 30-second default abandons cost reads the API would still answer.

View Source
const AgentName = "costfluent-mcp"

AgentName names the tools to the API in every request they make, through costfluent.AgentHeader.

View Source
const AgentWritesSetting = "“Let AI agents create and change objects” under Settings, Organization"

AgentWritesSetting names the organization setting that lets AI agents write, and where an Owner finds it, for an error that says why a write was refused or is not served.

View Source
const NoCapability costfluent.Capability = ""

NoCapability gates a tool that calls no Public API: it reads Costfluent's public documentation, so a token's capabilities widen nothing it returns. Such a tool is served beside the gated ones to every token served at least one, and never on its own.

Variables

This section is empty.

Functions

func Build added in v0.2.0

func Build(client *costfluent.Client, me *costfluent.Me, opts Options) (*mcp.Server, error)

Build returns a server holding the tools me, the token client carries, may call: a read tool when the token carries its capability, a write tool only when the organization lets AI agents write too (Serves), and after them the tools that need no capability, the docs tools. A token no gated tool serves is an error naming the capabilities the read tools need, because an assistant shows no log, and a server holding only the docs would read as a broken Costfluent server. A workspace token's client defaults to its own workspace, so a tool called without a workspace reads the token's.

Every request a tool makes carries costfluent.AgentHeader, reads included, so the API can refuse a write while the organization's setting is off even when it was turned off after the server started, and its audit log names the agent.

func New

func New(ctx context.Context, client *costfluent.Client, version string) (*mcp.Server, *costfluent.Me, error)

New asks the API which token the client carries and returns a server holding the tools that token may call, as Build does. It is how the stdio mode starts: one token for the whole session.

func Serves added in v0.3.0

func Serves(me *costfluent.Me, e CatalogEntry) bool

Serves reports whether a token me describes is served the tool e: it carries the tool's capability and, for a tool that writes, its organization lets AI agents create and change objects. A tool that needs no capability is served beside any tool that does (ToolNames), never alone.

func ToolError added in v0.3.0

func ToolError(err error) error

ToolError is a failed call as the client reads it: the API's ApiError when the API refused the call, otherwise the error's text. Neither carries the token, which travels only in a request header.

func ToolNames

func ToolNames(me *costfluent.Me) []string

ToolNames lists the tools a token me describes is served, in registration order: none when no gated tool serves it, as Build then serves nothing.

Types

type AcknowledgeAnomalyInput added in v0.3.0

type AcknowledgeAnomalyInput struct {
	AnomalyID string `json:"anomaly_id" jsonschema:"the anomaly to acknowledge, as list_anomalies names it"`
}

type AddDashboardWidgetInput added in v0.3.0

type AddDashboardWidgetInput struct {
	DashboardID  string `json:"dashboard_id" jsonschema:"the dashboard to add the widget to"`
	WorkspaceID  string `json:"workspace_id,omitempty" jsonschema:"the dashboard's workspace; a workspace token's own when omitted"`
	Title        string `json:"title" jsonschema:"the widget's title"`
	Type         string `json:"type,omitempty" jsonschema:"costReport (the default) for a saved report, or text"`
	CostReportID string `json:"cost_report_id,omitempty" jsonschema:"the saved report a costReport widget draws, as list_cost_reports names it"`
	Display      string `json:"display,omitempty" jsonschema:"how a costReport widget draws its report: chart, table or kpi"`
	Content      string `json:"content,omitempty" jsonschema:"a text widget's words, at most 10,000 characters"`
	Column       *int   `json:"column,omitempty" jsonschema:"the widget's first column, from 0 of the dashboard's 12"`
	Row          *int   `json:"row,omitempty" jsonschema:"the widget's first row, from 0"`
	Width        *int   `json:"width,omitempty" jsonschema:"the widget's width in columns, 1 to 12"`
	Height       *int   `json:"height,omitempty" jsonschema:"the widget's height in rows"`
}

type AssignSavingsItemOwnerInput added in v0.3.0

type AssignSavingsItemOwnerInput struct {
	SavingsItemID string `json:"savings_item_id" jsonschema:"the finding, as list_savings_items names it"`
	WorkspaceID   string `json:"workspace_id,omitempty" jsonschema:"the finding's workspace; a workspace token's own when omitted"`
	Owner         string `json:"owner" jsonschema:"who acts on the finding, free text such as a team or a person, at most 200 characters"`
}

type CatalogEntry added in v0.3.0

type CatalogEntry struct {
	Name       string
	Capability costfluent.Capability
	Writes     bool
}

CatalogEntry names a tool, the capability its call needs and whether it creates or changes Costfluent objects, which only an organization that lets AI agents write is served.

func Catalog added in v0.3.0

func Catalog() []CatalogEntry

Catalog lists every tool the registry holds with the capability its call needs, in registration order, whatever a token carries: what a front-end that builds its own surface from the tools, such as the CLI's help, reads without asking the API.

type Changed added in v0.3.0

type Changed struct {
	ID     string `json:"id"`
	Status string `json:"status"`
}

Changed is what a write that answers with no object did.

type CommitmentCoverageInput added in v0.2.0

type CommitmentCoverageInput struct {
	StartDate   string `json:"start_date" jsonschema:"the first day, YYYY-MM-DD"`
	EndDate     string `json:"end_date" jsonschema:"the last day, inclusive, YYYY-MM-DD"`
	WorkspaceID string `json:"workspace_id,omitempty" jsonschema:"the workspace to read; a workspace token's own when omitted"`
	Granularity string `json:"granularity,omitempty" jsonschema:"the period of each bin: day, week, month or quarter; month when omitted"`
	Filter      string `json:"filter,omitempty" jsonschema:"a Costfluent cost filter (CQL), such as costs.provider = 'aws'"`
}

type CostAlertInput added in v0.3.0

type CostAlertInput struct {
	CostAlertID string `json:"cost_alert_id" jsonschema:"the cost alert"`
	WorkspaceID string `json:"workspace_id,omitempty" jsonschema:"the alert's workspace; a workspace token's own when omitted"`
}

type CostReportDataInput

type CostReportDataInput struct {
	CostReportID string `json:"cost_report_id" jsonschema:"the saved report's ID, as list_cost_reports names it"`
	WorkspaceID  string `json:"workspace_id,omitempty" jsonschema:"the report's workspace; a workspace token's own when omitted"`
}

type CostReportResult added in v0.3.0

type CostReportResult struct {
	costfluent.CostReportData
	SeriesOmittedPeriods int    `json:"series_omitted_periods,omitempty"`
	SeriesFrom           string `json:"series_from,omitempty"`
}

CostReportResult is what a saved report shows. When it would encode past maxReportBytes, the series, comparison, unit cost and forecast keep only their points dated from SeriesFrom on, and SeriesOmittedPeriods counts the dates left out. The summary, breakdown and names stay whole, so when they alone pass maxReportBytes the answer keeps the latest date only and is larger still.

type CostReports

type CostReports struct {
	Reports  []costfluent.CostReport `json:"reports"`
	NextPage int                     `json:"next_page,omitempty"`
}

CostReports is one page of a workspace's saved cost reports. NextPage is the page to ask for next, absent on the last. It keeps the reports key it had before it paged, so a reader of one answer per workspace still reads it.

type CostsResult

type CostsResult struct {
	Rows     []costfluent.CostDataPoint `json:"rows"`
	Meta     costfluent.CostDataMeta    `json:"meta"`
	NextPage int                        `json:"next_page,omitempty"`
}

CostsResult is one page of cost rows and what the query covered.

type CreateAnnotationInput added in v0.3.0

type CreateAnnotationInput struct {
	WorkspaceID   string   `json:"workspace_id,omitempty" jsonschema:"the workspace; a workspace token's own when omitted"`
	Date          string   `json:"date" jsonschema:"the day the note stands on, YYYY-MM-DD"`
	Text          string   `json:"text" jsonschema:"the note, at most 1,000 characters"`
	CostReportIDs []string `json:"cost_report_ids" jsonschema:"the saved reports the note stands on, one to ten, as list_cost_reports names them"`
}

type CreateBudgetInput added in v0.3.0

type CreateBudgetInput struct {
	WorkspaceID     string   `json:"workspace_id,omitempty" jsonschema:"the workspace; a workspace token's own when omitted"`
	Name            string   `json:"name" jsonschema:"the budget's name"`
	Currency        string   `json:"currency" jsonschema:"the budget's ISO 4217 currency, such as USD"`
	Amount          string   `json:"amount" jsonschema:"every period's amount, a decimal, such as 5000 or 1250.50"`
	StartDate       string   `json:"start_date,omitempty" jsonschema:"the first period's first day, YYYY-MM-DD; today when omitted"`
	IntervalCount   int      `json:"interval_count,omitempty" jsonschema:"how many interval units a period lasts; 1 when omitted"`
	IntervalUnit    string   `json:"interval_unit,omitempty" jsonschema:"day, week, month or year; month when omitted, so a quarter is 3 months"`
	Measure         string   `json:"measure,omitempty" jsonschema:"cost (the default) or usage, which counts usage_unit on cost_report_id's rows"`
	UsageUnit       string   `json:"usage_unit,omitempty" jsonschema:"the one usage unit a usage budget counts, such as Tokens"`
	CostReportID    string   `` /* 185-byte string literal not displayed */
	SegmentID       string   `json:"segment_id,omitempty" jsonschema:"the allocation segment whose costs the budget measures"`
	AlertThresholds []string `` /* 300-byte string literal not displayed */
	AppIDs          []string `json:"app_ids,omitempty" jsonschema:"the notification channels every threshold notifies"`
}

type CreateCostAlertInput added in v0.3.0

type CreateCostAlertInput struct {
	WorkspaceID                string   `json:"workspace_id,omitempty" jsonschema:"the workspace; a workspace token's own when omitted"`
	Name                       string   `json:"name" jsonschema:"the alert's name"`
	ThresholdType              string   `` /* 263-byte string literal not displayed */
	ThresholdValue             string   `json:"threshold_value" jsonschema:"the threshold, a decimal: an amount or a percent as threshold_type says"`
	ComparisonPeriod           string   `` /* 172-byte string literal not displayed */
	MinimumAmount              string   `` /* 129-byte string literal not displayed */
	ProviderIDs                []string `json:"provider_ids,omitempty" jsonschema:"the Costfluent connections (prv_...) to watch; every connection when omitted"`
	Filter                     string   `` /* 137-byte string literal not displayed */
	AppIDs                     []string `json:"app_ids,omitempty" jsonschema:"the notification channels it notifies"`
	EvaluationFrequencyMinutes *int     `` /* 128-byte string literal not displayed */
}

type CreateCostReportInput added in v0.3.0

type CreateCostReportInput struct {
	WorkspaceID string `json:"workspace_id,omitempty" jsonschema:"the workspace; a workspace token's own when omitted"`
	Title       string `json:"title" jsonschema:"the report's title"`
	ReportFields
}

type CreateDashboardInput added in v0.3.0

type CreateDashboardInput struct {
	WorkspaceID  string `json:"workspace_id,omitempty" jsonschema:"the workspace; a workspace token's own when omitted"`
	Title        string `json:"title" jsonschema:"the dashboard's title"`
	DateInterval string `` /* 166-byte string literal not displayed */
	DateBin      string `json:"date_bin,omitempty" jsonschema:"day, week, month, quarter or cumulative"`
	StartDate    string `json:"start_date,omitempty" jsonschema:"a custom range's first day, YYYY-MM-DD"`
	EndDate      string `json:"end_date,omitempty" jsonschema:"a custom range's last day, inclusive, YYYY-MM-DD"`
}

type GetDocPageInput added in v0.3.0

type GetDocPageInput struct {
	URL string `` /* 218-byte string literal not displayed */
}

type KubernetesEfficiencyInput added in v0.2.0

type KubernetesEfficiencyInput struct {
	StartDate   string `json:"start_date" jsonschema:"the first day, YYYY-MM-DD"`
	EndDate     string `json:"end_date" jsonschema:"the last day, inclusive, YYYY-MM-DD"`
	Level       string `json:"level" jsonschema:"what each row is: cluster, namespace or workload"`
	WorkspaceID string `json:"workspace_id,omitempty" jsonschema:"the workspace to read; a workspace token's own when omitted"`
	Filter      string `json:"filter,omitempty" jsonschema:"a Costfluent cost filter (CQL), such as costs.cluster = 'prod'"`
}

type ListAnnotationsInput added in v0.2.0

type ListAnnotationsInput struct {
	WorkspaceID     string `json:"workspace_id,omitempty" jsonschema:"the workspace to read; a workspace token's own when omitted"`
	CostReportID    string `` /* 126-byte string literal not displayed */
	StartDate       string `json:"start_date,omitempty" jsonschema:"the first annotated day, YYYY-MM-DD"`
	EndDate         string `json:"end_date,omitempty" jsonschema:"the last annotated day, inclusive, YYYY-MM-DD"`
	IncludeResolved bool   `json:"include_resolved,omitempty" jsonschema:"true to list resolved annotations too; open ones only when omitted"`
	Page            int    `json:"page,omitempty" jsonschema:"the page to read, from 1"`
}

type ListAnomaliesInput

type ListAnomaliesInput struct {
	StartDate          string `json:"start_date,omitempty" jsonschema:"the first anomaly day, YYYY-MM-DD"`
	EndDate            string `json:"end_date,omitempty" jsonschema:"the last anomaly day, YYYY-MM-DD"`
	Severity           string `json:"severity,omitempty" jsonschema:"only anomalies of this severity: low, medium, high, critical, in any case"`
	CloudAccountID     string `` /* 209-byte string literal not displayed */
	UnacknowledgedOnly bool   `json:"unacknowledged_only,omitempty" jsonschema:"true for open anomalies only"`
	Page               int    `json:"page,omitempty" jsonschema:"the page to read, from 1"`
}

type ListBudgetsInput

type ListBudgetsInput struct {
	WorkspaceID string `json:"workspace_id,omitempty" jsonschema:"the workspace to read; a workspace token's own when omitted"`
	Page        int    `json:"page,omitempty" jsonschema:"the page to read, from 1"`
}

type ListCommitmentsInput added in v0.2.0

type ListCommitmentsInput struct {
	WorkspaceID   string `json:"workspace_id,omitempty" jsonschema:"the workspace to read; a workspace token's own when omitted"`
	Provider      string `json:"provider,omitempty" jsonschema:"only commitments held through this provider, such as aws, azure or gcp"`
	Status        string `json:"status,omitempty" jsonschema:"only commitments in this state: active, expiring, expired or unknown (no end stated)"`
	Type          string `` /* 128-byte string literal not displayed */
	Service       string `json:"service,omitempty" jsonschema:"only commitments for this service, as the provider names it"`
	Account       string `json:"account,omitempty" jsonschema:"only commitments held in this provider account"`
	Region        string `json:"region,omitempty" jsonschema:"only commitments in this region"`
	TermYears     int    `json:"term_years,omitempty" jsonschema:"only commitments of this term in years: 1, 3 or 5"`
	PaymentOption string `json:"payment_option,omitempty" jsonschema:"only commitments paid this way: All Upfront, Partial Upfront or No Upfront"`
	Page          int    `json:"page,omitempty" jsonschema:"the page to read, from 1"`
}

type ListCostReportsInput added in v0.3.0

type ListCostReportsInput struct {
	WorkspaceID string `json:"workspace_id,omitempty" jsonschema:"the workspace to read; a workspace token's own when omitted"`
	Page        int    `json:"page,omitempty" jsonschema:"the page to read, from 1"`
}

type ListSavingsItemsInput added in v0.2.0

type ListSavingsItemsInput struct {
	WorkspaceID          string `json:"workspace_id,omitempty" jsonschema:"the workspace to read; a workspace token's own when omitted"`
	Tab                  string `` /* 128-byte string literal not displayed */
	Source               string `` /* 187-byte string literal not displayed */
	Kind                 string `` /* 170-byte string literal not displayed */
	CloudAccountID       string `` /* 213-byte string literal not displayed */
	CostEstimateID       string `` /* 264-byte string literal not displayed */
	MinimumMonthlySaving string `` /* 153-byte string literal not displayed */
	Sort                 string `json:"sort,omitempty" jsonschema:"newest (the default) or largestSaving"`
	Page                 int    `json:"page,omitempty" jsonschema:"the page to read, from 1"`
}

type ListWorkspacesInput

type ListWorkspacesInput struct {
	Page int `json:"page,omitempty" jsonschema:"the page to read, from 1"`
}

type Options added in v0.2.0

type Options struct {
	Version string
	// CallTimeout, when positive, ends a tool call still running after it as a tool error.
	CallTimeout time.Duration
	// Hosted answers a call that never reached the API with a generic tool error, because the
	// transport's own text names the upstream's internal address, which a hosted caller has no use for.
	Hosted bool
	// Docs is where the docs tools read the documentation; the process's shared Source when nil.
	Docs *docs.Source
}

Options shape the server Build returns.

type Page

type Page[T any] struct {
	Items    []T `json:"items"`
	NextPage int `json:"next_page,omitempty"`
}

Page is one page of a listing. NextPage is the page to ask for next, absent on the last.

type QueryCostsInput

type QueryCostsInput struct {
	StartDate   string   `json:"start_date" jsonschema:"the first day, YYYY-MM-DD"`
	EndDate     string   `json:"end_date" jsonschema:"the last day, inclusive, YYYY-MM-DD"`
	WorkspaceID string   `` /* 148-byte string literal not displayed */
	Granularity string   `` /* 184-byte string literal not displayed */
	GroupBy     []string `` /* 156-byte string literal not displayed */
	Filter      string   `` /* 131-byte string literal not displayed */
	Measure     string   `json:"measure,omitempty" jsonschema:"cost, usage (consumed quantity) or count (distinct resources); cost when omitted"`
	Amortize    *bool    `` /* 132-byte string literal not displayed */
	Page        int      `json:"page,omitempty" jsonschema:"the page to read, from 1"`
	Limit       int      `json:"limit,omitempty" jsonschema:"rows per page, at most 5000; 500 when omitted"`
}

type ReportFields added in v0.3.0

type ReportFields struct {
	ChartType           string   `json:"chart_type,omitempty" jsonschema:"line, bar, stackedBar, area, pie or table; a new report draws stackedBar"`
	DateBin             string   `` /* 165-byte string literal not displayed */
	DateInterval        string   `` /* 483-byte string literal not displayed */
	StartDate           string   `json:"start_date,omitempty" jsonschema:"a custom window's first day, YYYY-MM-DD"`
	EndDate             string   `json:"end_date,omitempty" jsonschema:"a custom window's last day, inclusive, YYYY-MM-DD"`
	Filter              string   `` /* 183-byte string literal not displayed */
	GroupBy             []string `` /* 156-byte string literal not displayed */
	FolderID            string   `json:"folder_id,omitempty" jsonschema:"the folder to file the report in"`
	Measure             string   `json:"measure,omitempty" jsonschema:"what the report counts: cost, usage (consumed quantity) or count (distinct resources)"`
	Amortize            *bool    `json:"amortize,omitempty" jsonschema:"true for effective cost with commitments spread over their term"`
	IncludeCredits      *bool    `json:"include_credits,omitempty" jsonschema:"whether credits count"`
	IncludeRefunds      *bool    `json:"include_refunds,omitempty" jsonschema:"whether refunds count"`
	IncludeTax          *bool    `json:"include_tax,omitempty" jsonschema:"whether tax counts"`
	ShowForecast        *bool    `json:"show_forecast,omitempty" jsonschema:"whether the chart shows a forecast"`
	CompareToLastPeriod *bool    `json:"compare_to_last_period,omitempty" jsonschema:"whether the report compares with the period before"`
}

ReportFields are a cost report's definition as a create or an update takes it. A field left out is the API's default on a create and the report's own on an update.

type SearchDocsInput added in v0.3.0

type SearchDocsInput struct {
	Query    string `` /* 132-byte string literal not displayed */
	Language string `json:"language,omitempty" jsonschema:"the docs' language: en or de; en when omitted"`
	Limit    int    `json:"limit,omitempty" jsonschema:"sections to return: 5 when omitted, at most 10"`
}

type SearchDocsResult added in v0.3.0

type SearchDocsResult struct {
	Results []docs.Hit `json:"results"`
}

SearchDocsResult is the sections that match a query best, best first.

type SetSavingsItemStatusInput added in v0.3.0

type SetSavingsItemStatusInput struct {
	SavingsItemID string `json:"savings_item_id" jsonschema:"the finding, as list_savings_items names it"`
	WorkspaceID   string `json:"workspace_id,omitempty" jsonschema:"the finding's workspace; a workspace token's own when omitted"`
	Status        string `` /* 170-byte string literal not displayed */
	Reason        string `` /* 135-byte string literal not displayed */
}

type UpdateBudgetInput added in v0.3.0

type UpdateBudgetInput struct {
	BudgetID           string   `json:"budget_id" jsonschema:"the budget to change, as list_budgets names it"`
	Name               string   `json:"name,omitempty" jsonschema:"the budget's new name"`
	Amount             string   `json:"amount,omitempty" jsonschema:"every period's new amount, a decimal"`
	CostReportID       string   `json:"cost_report_id,omitempty" jsonschema:"move the budget onto this saved report's costs"`
	SegmentID          string   `json:"segment_id,omitempty" jsonschema:"move the budget onto this allocation segment's costs"`
	AddAlertThresholds []string `` /* 335-byte string literal not displayed */
}

type UpdateCostAlertInput added in v0.3.0

type UpdateCostAlertInput struct {
	CostAlertID                string   `json:"cost_alert_id" jsonschema:"the cost alert to change"`
	WorkspaceID                string   `json:"workspace_id,omitempty" jsonschema:"the alert's workspace; a workspace token's own when omitted"`
	Name                       string   `json:"name,omitempty" jsonschema:"the alert's new name"`
	ThresholdType              string   `` /* 273-byte string literal not displayed */
	ThresholdValue             string   `json:"threshold_value,omitempty" jsonschema:"the new threshold, a decimal: an amount or a percent as threshold_type says"`
	ComparisonPeriod           string   `` /* 172-byte string literal not displayed */
	MinimumAmount              string   `` /* 150-byte string literal not displayed */
	ProviderIDs                []string `json:"provider_ids,omitempty" jsonschema:"the Costfluent connections (prv_...) to watch instead of the alert's, at least one"`
	Filter                     string   `json:"filter,omitempty" jsonschema:"a new Costfluent cost filter (CQL) narrowing what the alert watches"`
	AddAppIDs                  []string `json:"add_app_ids,omitempty" jsonschema:"notification channels to add beside the alert's own, which all stay"`
	EvaluationFrequencyMinutes *int     `json:"evaluation_frequency_minutes,omitempty" jsonschema:"how often it is evaluated, in minutes"`
}

type UpdateCostReportInput added in v0.3.0

type UpdateCostReportInput struct {
	CostReportID string `json:"cost_report_id" jsonschema:"the saved report to change, as list_cost_reports names it"`
	WorkspaceID  string `json:"workspace_id,omitempty" jsonschema:"the report's workspace; a workspace token's own when omitted"`
	Title        string `json:"title,omitempty" jsonschema:"the report's new title"`
	ReportFields
}

Jump to

Keyboard shortcuts

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