-
Notifications
You must be signed in to change notification settings - Fork 21
Serve Basecamp over MCP with basecamp mcp #662
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
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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
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,78 @@ | ||
| package commands | ||
|
|
||
| import ( | ||
| "log/slog" | ||
| "os" | ||
| "os/signal" | ||
| "syscall" | ||
|
|
||
| "github.com/modelcontextprotocol/go-sdk/mcp" | ||
| "github.com/spf13/cobra" | ||
|
|
||
| "github.com/basecamp/basecamp-cli/internal/appctx" | ||
| "github.com/basecamp/basecamp-cli/internal/mcpserver" | ||
| "github.com/basecamp/basecamp-cli/internal/output" | ||
| ) | ||
|
|
||
| // mcpTransport is a seam so tests can drive the server over in-memory | ||
| // transports instead of the process's stdin/stdout. | ||
| var mcpTransport = func() mcp.Transport { return &mcp.StdioTransport{} } | ||
|
|
||
| // NewMCPCmd creates the mcp command serving Basecamp over MCP on stdio. | ||
| func NewMCPCmd() *cobra.Command { | ||
| var readOnly bool | ||
| var domains []string | ||
|
|
||
| cmd := &cobra.Command{ | ||
| Use: "mcp", | ||
| Short: "Serve Basecamp to MCP clients over stdio", | ||
| Long: "Run an MCP (Model Context Protocol) server on stdin/stdout, serving Basecamp\n" + | ||
| "projects, todos, cards, messages, and more as tools backed by your signed-in\n" + | ||
| "account.\n\n" + | ||
| "Register it with an MCP client as a stdio server, e.g.:\n\n" + | ||
| " claude mcp add basecamp -- basecamp mcp", | ||
| Example: ` basecamp mcp | ||
| basecamp mcp --read-only | ||
| basecamp mcp --domains projects,todos,cards`, | ||
| Args: cobra.NoArgs, | ||
| Annotations: map[string]string{ | ||
| "agent_notes": "Long-running server; stdout speaks the MCP wire protocol. Not for interactive use.", | ||
| }, | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| app := appctx.FromContext(cmd.Context()) | ||
|
|
||
| if !app.Auth.IsAuthenticated() { | ||
| return output.ErrAuth("Not authenticated. Run: basecamp auth login") | ||
| } | ||
| // Stdio belongs to the MCP wire, so the account cannot be | ||
| // resolved interactively: require it configured up front, like | ||
| // any other account-scoped command running non-interactively. | ||
| if err := app.RequireAccount(); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| srv, err := mcpserver.New(app.Account(), mcpserver.Config{ReadOnly: readOnly, Domains: domains}) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| ctx, stop := signal.NotifyContext(cmd.Context(), os.Interrupt, syscall.SIGTERM) | ||
| defer stop() | ||
|
|
||
| // Log to stderr: stdout belongs to the MCP wire. | ||
| logger := slog.New(slog.NewTextHandler(cmd.ErrOrStderr(), nil)) | ||
| session, err := srv.BuildMCPServer(logger).Connect(ctx, mcpTransport(), nil) | ||
| if err != nil { | ||
| return err | ||
|
jeremy marked this conversation as resolved.
|
||
| } | ||
| logger.Info("MCP server running on stdio", "tools", len(srv.Domains()), "read_only", readOnly) | ||
|
|
||
| return session.Wait() | ||
| }, | ||
| } | ||
|
|
||
| cmd.Flags().BoolVar(&readOnly, "read-only", false, "Serve only read-only actions") | ||
| cmd.Flags().StringSliceVar(&domains, "domains", nil, "Narrow to specific domains (comma-separated; default all)") | ||
|
|
||
| return cmd | ||
| } | ||
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.