cat / 012
clone

a spreadsheet for the terminal: lotus 1-2-3 looks, google sheets keys and formulas, one go binary

cat/module-path
012 / internal / mcp / prompts.go
prompts.go 3.7K
1package mcp23import (4 "context"5 "strings"67 sdk "github.com/modelcontextprotocol/go-sdk/mcp"8)910// Prompts are starting points a host offers people (as slash commands11// in Claude Code): each a message asking the model to do a common job12// with the tools, the way the tools are best used.13var prompts = []struct {14 prompt *sdk.Prompt15 text string // with {arg} for each argument16}{{17 prompt: &sdk.Prompt{Name: "summarize_workbook", Title: "Summarize the workbook",18 Description: "What each sheet holds and what its numbers say", Arguments: []*sdk.PromptArgument{pathArg}},19 text: "Call describe on {path}, then read the main ranges it points at with read_range (a few hundred rows at most). " +20 "Summarize what each sheet holds, how the sheets relate (formulas between them, tables, pivots, charts), and what the numbers say. Don't change anything.",21}, {22 prompt: &sdk.Prompt{Name: "fix_errors", Title: "Fix formula errors",23 Description: "Find the formulas showing errors, explain them and fix them", Arguments: []*sdk.PromptArgument{pathArg}},24 text: "Call list_errors on {path}. For each formula showing an error, read the cells it reads, and explain the cause. " +25 "Propose a fix, check it with evaluate at the same cell, and show it with write_cells and dry_run. Make the fixes once they're agreed.",26}, {27 prompt: &sdk.Prompt{Name: "add_column", Title: "Add a computed column",28 Description: "A new column of formulas beside a table of data",29 Arguments: []*sdk.PromptArgument{pathArg,30 {Name: "range", Description: "the data, e.g. Sales!A1:F99, or a table's name", Required: true},31 {Name: "column", Description: "what the new column computes, e.g. profit as revenue minus cost", Required: true},32 }},33 text: "Add a column to {range} in {path} that computes {column}. Call describe and read_range to find the header row and the columns involved. " +34 "Write the header, then the formula for the first data row: check it with evaluate at that cell, then write every row's formula with write_cells (dry_run first), relative references moving with the row. " +35 "Follow the columns' number formats. Finish with list_errors.",36}, {37 prompt: &sdk.Prompt{Name: "chart", Title: "Chart some data",38 Description: "A chart that answers a question about a range",39 Arguments: []*sdk.PromptArgument{pathArg,40 {Name: "range", Description: "the data, e.g. Sales!A1:C13", Required: true},41 {Name: "question", Description: "what the chart should show, e.g. how sales grew by month"},42 }},43 text: "Read {range} in {path} with read_range and pick the chart that best shows {question}: line or area for change over time, column or bar to compare, pie for shares of a whole, scatter for two measures. " +44 "If the data needs summarizing first, use create_pivot and chart its result. Create it with create_chart, with a title that says what it shows.",45}}4647// pathArg is every prompt's workbook; without it the model finds one.48var pathArg = &sdk.PromptArgument{Name: "path", Description: "the workbook, e.g. budget.012; describe without a path lists them"}4950// unset are what a prompt says for the arguments not given.51var unset = map[string]string{52 "{question}": "the data's main point",53 "{path}": "the workbook (describe without a path lists them)",54}5556func (s *Server) addPrompts() {57 for _, p := range prompts {58 text := p.text59 s.AddPrompt(p.prompt, func(_ context.Context, req *sdk.GetPromptRequest) (*sdk.GetPromptResult, error) {60 msg := text61 for k, v := range req.Params.Arguments {62 if v != "" {63 msg = strings.ReplaceAll(msg, "{"+k+"}", v)64 }65 }66 for k, v := range unset {67 msg = strings.ReplaceAll(msg, k, v)68 }69 return &sdk.GetPromptResult{Description: req.Params.Name,70 Messages: []*sdk.PromptMessage{{Role: "user", Content: &sdk.TextContent{Text: msg}}}}, nil71 })72 }73}