verae-mcp-timestamping-serv.../internal/tools/types.go
George Lambert 3ec1f0516b
Some checks failed
test-and-deploy / test (push) Failing after 12m55s
test-and-deploy / deploy-138 (push) Has been cancelled
feat(mcp): optional receipt_format on stamp/verify (text/PDF/JSON/MD/CSV/TSV)
Add receipt_format to stamp and verify. Omitted → text; receipt|PDF-Receipt → PDF;
JSON-Receipt → JSON; MD|MD-Receipt; CSV|CSV-Receipt; TSV|TSV-Receipt.

Stamp always returns receipts[] and adds artifacts[] in the chosen format.
Stdio writes ~/.verae/receipts (0600); public MCP returns content_text/content_base64 only.
Verify accepts inline receipt or receipt_path (stdio), parses id, and re-emits an artifact.

Vendors pdfcert (+ slim statuslang, gofpdf) for CERT-01 PDF. Also lands welcome tool
and email-username helpers already wired into register/public paths.
2026-10-20 16:02:20 -04:00

143 lines
6.9 KiB
Go

package tools
// StampArgs is the stamp tool input.
type StampArgs struct {
SHA256 string `json:"sha256" jsonschema:"SHA-256 digest (64 hex; optional sha256: prefix)"`
Scope string `json:"scope,omitempty" jsonschema:"local, shared, or global (default local)"`
CubeID string `json:"cube_id,omitempty" jsonschema:"optional cube id"`
OrgID string `json:"org_id,omitempty" jsonschema:"optional org id"`
Metadata map[string]any `json:"metadata,omitempty" jsonschema:"optional plain object or a verae-meta-git/1 history. Blank values do not delete fields. Global scope only."`
Restamp bool `json:"restamp,omitempty" jsonschema:"when true, append metadata onto the previous global stamp for this digest"`
Message string `json:"message,omitempty" jsonschema:"optional history commit message"`
ReceiptFormat string `json:"receipt_format,omitempty" jsonschema:"optional receipt presentation: omit=text; receipt|PDF-Receipt=PDF; JSON-Receipt=JSON; MD|MD-Receipt; CSV|CSV-Receipt; TSV|TSV-Receipt"`
}
// VerifyArgs is the verify tool input.
type VerifyArgs struct {
ReceiptID string `json:"receipt_id,omitempty" jsonschema:"receipt or certificate id (optional when Receipt or ReceiptPath supplies it)"`
WantScope string `json:"want_scope,omitempty" jsonschema:"optional minimum scope (local|shared|global)"`
ReceiptFormat string `json:"receipt_format,omitempty" jsonschema:"how to interpret Receipt/ReceiptPath and/or re-emit artifact: omit=text; receipt|PDF-Receipt=PDF; JSON-Receipt=JSON; MD|CSV|TSV"`
Receipt string `json:"receipt,omitempty" jsonschema:"optional inline receipt body (text/JSON/MD/CSV/TSV or base64 PDF)"`
ReceiptPath string `json:"receipt_path,omitempty" jsonschema:"optional local path to a receipt file (stdio only; rejected on public MCP)"`
}
// HashReportArgs is the hash_report tool input.
type HashReportArgs struct {
SHA256 string `json:"sha256" jsonschema:"SHA-256 digest (64 hex; optional sha256: prefix)"`
OrgID string `json:"org_id,omitempty" jsonschema:"optional org id filter"`
WantScope string `json:"want_scope,omitempty" jsonschema:"optional minimum scope filter"`
}
// AuthUserPass are credentials for signup/login.
type AuthUserPass struct {
Username string `json:"username" jsonschema:"Email address used as VeraeTime username (required; must be an email)"`
Password string `json:"password" jsonschema:"VeraeTime password"`
}
// CreateUserArgs creates a VeraeTime user (admin bearer required).
type CreateUserArgs struct {
Username string `json:"username" jsonschema:"Email address used as the new username (required; must be an email)"`
Password string `json:"password" jsonschema:"new password"`
Role string `json:"role" jsonschema:"user or admin"`
}
// EmptyArgs is used by session.
type EmptyArgs struct{}
// ReceiptDTO is the MCP receipt shape (snake_case JSON).
type ReceiptDTO struct {
ReceiptID string `json:"receipt_id"`
Hash string `json:"hash"`
Scope string `json:"scope"`
CubeID string `json:"cube_id,omitempty"`
OrgID string `json:"org_id,omitempty"`
CreatedAt string `json:"created_at"`
Merkle string `json:"merkle"`
RestampOf string `json:"restamp_of,omitempty"`
}
// ReceiptArtifact is a rendered receipt in the requested presentation format.
type ReceiptArtifact struct {
Format string `json:"format"` // text|pdf|json|md|csv|tsv
MediaType string `json:"media_type"` // MIME type
Filename string `json:"filename,omitempty"`
Path string `json:"path,omitempty"` // written under ~/.verae/receipts when stdio
ContentText string `json:"content_text,omitempty"` // text/JSON/MD/CSV/TSV body
ContentB64 string `json:"content_base64,omitempty"` // PDF (and large bodies if needed)
}
// ReceiptsOut wraps a receipt list.
type ReceiptsOut struct {
Receipts []ReceiptDTO `json:"receipts"`
Artifacts []ReceiptArtifact `json:"artifacts,omitempty"`
}
// VerifyOut is the verify tool result.
type VerifyOut struct {
Valid bool `json:"valid"`
Error string `json:"error,omitempty"`
Receipt *ReceiptDTO `json:"receipt,omitempty"`
Artifact *ReceiptArtifact `json:"artifact,omitempty"`
}
// LoginOut is returned by login. On the public HTTP server it includes access_token
// so the client can set Authorization / bearer_token_file. Stdio login also returns
// the token and persists it on the host.
type LoginOut struct {
Username string `json:"username"`
Role string `json:"role"`
ExpiresAt string `json:"expires_at"`
AccessToken string `json:"access_token,omitempty"`
HowToUse string `json:"how_to_use,omitempty"`
}
// SessionOut is returned by session.
type SessionOut struct {
Valid bool `json:"valid"`
Username string `json:"username,omitempty"`
Role string `json:"role,omitempty"`
ExpiresAt string `json:"expires_at,omitempty"`
}
// CreateUserOut is returned by signup and create_user.
// Signup includes access_token so a new account can stamp without a separate login.
type CreateUserOut struct {
ID string `json:"id,omitempty"`
Username string `json:"username"`
Role string `json:"role"`
AccessToken string `json:"access_token,omitempty"`
ExpiresAt string `json:"expires_at,omitempty"`
HowToUse string `json:"how_to_use,omitempty"`
}
// StampBatchArgs is the stamp_batch tool input (DEC-659).
type StampBatchArgs struct {
SHA256s []string `json:"sha256s" jsonschema:"SHA-256 digests (64 hex each), 1..500"`
Scope string `json:"scope,omitempty" jsonschema:"global (default; charged per new digest to your Verae account) or local"`
Metadata []map[string]any `json:"metadata,omitempty" jsonschema:"optional history patch per digest, same length as sha256s. Global scope only."`
Restamp bool `json:"restamp,omitempty" jsonschema:"when true, append each metadata patch onto the previous global stamp"`
Message string `json:"message,omitempty" jsonschema:"optional history commit message for every item"`
}
// BatchItemDTO is one item of a stamp_batch answer.
type BatchItemDTO struct {
Index int `json:"index"`
Hash string `json:"hash"`
JobID string `json:"job_id,omitempty"`
Status string `json:"status"`
Existing bool `json:"existing"`
ReceiptID string `json:"receipt_id,omitempty"`
Credits int `json:"credits"`
Error string `json:"error,omitempty"`
}
// StampBatchOut is the stamp_batch result: one receipt entry per input digest, in order.
type StampBatchOut struct {
Count int `json:"count"`
Created int `json:"created"`
Existing int `json:"existing"`
Failed int `json:"failed"`
TotalCredits int `json:"total_credits"`
BalanceCredits *int `json:"balance_credits,omitempty"`
Items []BatchItemDTO `json:"items"`
}