Repository navigation
feat(mcp): serve the Procedure as prompts and resources #184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+1,040
−15
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
057c1a2
feat(skillfs): serve task-scoped Procedures
SutuSebastian b4de549
feat(mcp): advertise prompts and resources capabilities
SutuSebastian 0614f8c
feat(mcp): serve one Procedure prompt per task
SutuSebastian 3ad3c41
feat(mcp): serve the embedded payload as resources
SutuSebastian baeb96b
test(mcp): pin procedure surfaces across server modes
SutuSebastian 3105e24
feat(mcp): point hosts at the embedded Procedure
SutuSebastian 85b2e97
docs: describe MCP prompts and resources
SutuSebastian 0d87cef
refactor: satisfy lint without suppressions
SutuSebastian 25baf18
build: raise size ceilings for MCP payload surfaces
SutuSebastian e1056fb
refactor: keep the existing lint boundary unchanged
SutuSebastian 05c8f77
docs: name the five MCP task prompts exactly
SutuSebastian File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@stainless-code/verdict": minor | ||
| --- | ||
|
|
||
| MCP hosts can now load the Procedure straight from the binary. `prompts/list` and `prompts/get` serve five task prompts (`address-reviews`, `fix-ci`, `incremental-review`, `review`, `validate`), and `resources/list` and `resources/read` serve every payload file at `verdict://skill/<path>`, byte-identical to `verdict skill show`. Prompts and resources are read-only and available in every server mode, including `--read-only` and `--operator`. `initialize` advertises both capabilities and points hosts at the `review` prompt or `verdict://skill/PROCEDURE.md`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,175 @@ | ||
| package mcp | ||
|
|
||
| import ( | ||
| "bytes" | ||
| "context" | ||
| "encoding/json" | ||
| "fmt" | ||
| "strconv" | ||
| "testing" | ||
|
|
||
| skillfs "github.com/stainless-code/verdict" | ||
| "github.com/stainless-code/verdict/internal/core/skill" | ||
| ) | ||
|
|
||
| type procedureModeCase struct { | ||
| name string | ||
| tools int | ||
| readOnly bool | ||
| operator bool | ||
| } | ||
|
|
||
| // TestProcedureSurfacesIgnoreModes proves prompts and resources are | ||
| // byte-for-byte the same on every tool surface. The tool counts pin that the | ||
| // three configs really are different surfaces. | ||
| func TestProcedureSurfacesIgnoreModes(t *testing.T) { | ||
| t.Parallel() | ||
| cases := []procedureModeCase{ | ||
| {name: "default", tools: 25}, | ||
| {name: "read-only", tools: 14, readOnly: true}, | ||
| {name: "operator", tools: 26, operator: true}, | ||
| } | ||
| paths, wantPrompt, wantResource := procedureFixtures(t) | ||
|
|
||
| var baseline procedureWire | ||
| for i, tc := range cases { | ||
| t.Run(tc.name, func(t *testing.T) { | ||
| cfg := testConfig() | ||
| cfg.ReadOnly = tc.readOnly | ||
| cfg.Operator = tc.operator | ||
| frames := procedureFrames(t, &cfg) | ||
| checkProcedureSurface(t, tc, frames, len(paths), len(skillfs.Tasks()), wantPrompt, wantResource) | ||
| wire := procedureWireFrom(frames) | ||
| if i == 0 { | ||
| baseline = wire | ||
| return | ||
| } | ||
| checkProcedureWire(t, tc.name, &wire, &baseline) | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func procedureFixtures(t *testing.T) ([]string, []byte, []byte) { | ||
| t.Helper() | ||
| paths, err := skillfs.Paths() | ||
| if err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| wantResource, ref := skill.ShowFile(context.Background(), &skill.Request{}, "PROCEDURE.md") | ||
| if ref != nil { | ||
| t.Fatal(ref) | ||
| } | ||
| wantPrompt, err := skillfs.ReviewProcedure() | ||
| if err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| return paths, wantPrompt, wantResource | ||
| } | ||
|
|
||
| func procedureFrames(t *testing.T, cfg *Config) map[string]frame { | ||
| t.Helper() | ||
| lines := []string{ | ||
| `{"jsonrpc":"2.0","id":1,"method":"tools/list"}`, | ||
| `{"jsonrpc":"2.0","id":2,"method":"prompts/list"}`, | ||
| `{"jsonrpc":"2.0","id":3,"method":"prompts/get","params":{"name":"review"}}`, | ||
| `{"jsonrpc":"2.0","id":4,"method":"resources/list"}`, | ||
| fmt.Sprintf(`{"jsonrpc":"2.0","id":5,"method":"resources/read","params":{"uri":%q}}`, | ||
| resourceURIPrefix+"PROCEDURE.md"), | ||
| } | ||
| frames := serve(t, cfg, lines...) | ||
| for i := range lines { | ||
| id := strconv.Itoa(i + 1) | ||
| if frame := frames[id]; frame.Error != nil { | ||
| t.Fatalf("request %s error = %+v", id, frame.Error) | ||
| } | ||
| } | ||
| return frames | ||
| } | ||
|
|
||
| func checkProcedureSurface(t *testing.T, tc procedureModeCase, frames map[string]frame, | ||
| pathCount, taskCount int, wantPrompt, wantResource []byte, | ||
| ) { | ||
| t.Helper() | ||
| checkToolCount(t, tc, frames) | ||
| checkPromptSurface(t, tc.name, frames, taskCount, wantPrompt) | ||
| checkResourceSurface(t, tc.name, frames, pathCount, wantResource) | ||
| } | ||
|
|
||
| func checkToolCount(t *testing.T, tc procedureModeCase, frames map[string]frame) { | ||
| t.Helper() | ||
| var tools toolsListResult | ||
| if err := json.Unmarshal(frames["1"].Result, &tools); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| if len(tools.Tools) != tc.tools { | ||
| t.Fatalf("%s tools = %d, want %d", tc.name, len(tools.Tools), tc.tools) | ||
| } | ||
| } | ||
|
|
||
| func checkPromptSurface(t *testing.T, name string, frames map[string]frame, taskCount int, want []byte) { | ||
| t.Helper() | ||
| var prompts promptsListResult | ||
| if err := json.Unmarshal(frames["2"].Result, &prompts); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| if len(prompts.Prompts) != taskCount { | ||
| t.Fatalf("%s prompts = %d, want %d", name, len(prompts.Prompts), taskCount) | ||
| } | ||
| var prompt promptResult | ||
| if err := json.Unmarshal(frames["3"].Result, &prompt); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| if len(prompt.Messages) != 1 || !bytes.Equal([]byte(prompt.Messages[0].Content.Text), want) { | ||
| t.Fatalf("%s review prompt does not carry the binary's Procedure", name) | ||
| } | ||
| } | ||
|
|
||
| func checkResourceSurface(t *testing.T, name string, frames map[string]frame, pathCount int, want []byte) { | ||
| t.Helper() | ||
| var resources resourceListResult | ||
| if err := json.Unmarshal(frames["4"].Result, &resources); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| if len(resources.Resources) != pathCount { | ||
| t.Fatalf("%s resources = %d, want %d", name, len(resources.Resources), pathCount) | ||
| } | ||
| var content resourceReadResult | ||
| if err := json.Unmarshal(frames["5"].Result, &content); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| if len(content.Contents) != 1 || !bytes.Equal([]byte(content.Contents[0].Text), want) { | ||
| t.Fatalf("%s PROCEDURE.md resource is not byte-identical to skill show", name) | ||
| } | ||
| } | ||
|
|
||
| type procedureWire struct { | ||
| promptsList json.RawMessage | ||
| promptGet json.RawMessage | ||
| resourcesList json.RawMessage | ||
| resourceRead json.RawMessage | ||
| } | ||
|
|
||
| func procedureWireFrom(frames map[string]frame) procedureWire { | ||
| return procedureWire{ | ||
| promptsList: frames["2"].Result, | ||
| promptGet: frames["3"].Result, | ||
| resourcesList: frames["4"].Result, | ||
| resourceRead: frames["5"].Result, | ||
| } | ||
| } | ||
|
|
||
| func checkProcedureWire(t *testing.T, name string, got, want *procedureWire) { | ||
| t.Helper() | ||
| if !bytes.Equal(got.promptsList, want.promptsList) { | ||
| t.Errorf("%s prompts/list differs from the default surface", name) | ||
| } | ||
| if !bytes.Equal(got.promptGet, want.promptGet) { | ||
| t.Errorf("%s prompts/get differs from the default surface", name) | ||
| } | ||
| if !bytes.Equal(got.resourcesList, want.resourcesList) { | ||
| t.Errorf("%s resources/list differs from the default surface", name) | ||
| } | ||
| if !bytes.Equal(got.resourceRead, want.resourceRead) { | ||
| t.Errorf("%s resources/read differs from the default surface", name) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| package mcp | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "errors" | ||
| "strconv" | ||
| "strings" | ||
|
|
||
| skillfs "github.com/stainless-code/verdict" | ||
| ) | ||
|
|
||
| const ( | ||
| methodPromptsList = "prompts/list" | ||
| methodPromptsGet = "prompts/get" | ||
| ) | ||
|
|
||
| // promptDescriptions is the host-facing copy for the tasks in skillfs.Tasks. | ||
| var promptDescriptions = map[string]string{ | ||
| "address-reviews": "Address review threads with verified fixes and one reply per thread.", | ||
| "fix-ci": "Diagnose a PR-introduced CI failure, fix it, and push the fix with a summary.", | ||
| "incremental-review": "Review only the commits added since a prior review, with a no-review note for trivial deltas.", | ||
| "review": "Review a fetched PR or local diff and write one review.json.", | ||
| "validate": "Validate candidate findings against the bundle without changing it.", | ||
| } | ||
|
|
||
| func (s *Server) handlePromptsList(req *rpcRequest) { | ||
| if len(req.ID) == 0 { | ||
| return | ||
| } | ||
| prompts := make([]promptDescriptor, 0, len(promptDescriptions)) | ||
| for _, task := range skillfs.Tasks() { | ||
| prompts = append(prompts, promptDescriptor{ | ||
| Name: task, | ||
| Description: promptDescriptions[task], | ||
| }) | ||
| } | ||
| s.writeResult(req.ID, promptsListResult{Prompts: prompts}) | ||
| } | ||
|
|
||
| func (s *Server) handlePromptsGet(req *rpcRequest) { | ||
| if len(req.ID) == 0 { | ||
| return | ||
| } | ||
| params, ok := decodeParams[promptNameParams](req.Params) | ||
| if !ok || params.Name == "" { | ||
| s.writeInvalidPrompt(req.ID, "") | ||
| return | ||
| } | ||
| body, err := skillfs.TaskProcedure(params.Name) | ||
| if err != nil { | ||
| if _, ok := errors.AsType[*skillfs.UnknownTaskError](err); ok { | ||
| s.writeInvalidPrompt(req.ID, params.Name) | ||
| return | ||
| } | ||
| s.writeError(req.ID, codeInternalError, "prompt unavailable: "+err.Error()) | ||
| return | ||
| } | ||
| s.writeResult(req.ID, getPromptResult{ | ||
| Description: promptDescriptions[params.Name], | ||
| Messages: []promptMessage{{ | ||
| Role: "user", | ||
| Content: contentBlock{Type: contentTypeText, Text: string(body)}, | ||
| }}, | ||
| }) | ||
| } | ||
|
|
||
| // MCP 2025-06-18 § server/prompts error handling: an invalid prompt name is | ||
| // -32602. The message names the served tasks because this server has no | ||
| // prompt arguments. | ||
| func (s *Server) writeInvalidPrompt(id json.RawMessage, name string) { | ||
| message := "missing prompt name; valid tasks: " + strings.Join(skillfs.Tasks(), ", ") | ||
| if name != "" { | ||
| message = "unknown prompt " + strconv.Quote(name) + "; valid tasks: " + strings.Join(skillfs.Tasks(), ", ") | ||
| } | ||
| s.writeError(id, codeInvalidParams, message) | ||
| } | ||
|
|
||
| type promptNameParams struct { | ||
| Name string `json:"name"` | ||
| } | ||
|
|
||
| type promptDescriptor struct { | ||
| Name string `json:"name"` | ||
| Description string `json:"description"` | ||
| } | ||
|
|
||
| type promptsListResult struct { | ||
| Prompts []promptDescriptor `json:"prompts"` | ||
| } | ||
|
|
||
| type promptMessage struct { | ||
| Role string `json:"role"` | ||
| Content contentBlock `json:"content"` | ||
| } | ||
|
|
||
| type getPromptResult struct { | ||
| Description string `json:"description"` | ||
| Messages []promptMessage `json:"messages"` | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.