Skip to content

Commit 82f9ac7

Browse files
committed
feat: add mcp command
1 parent 8809e1c commit 82f9ac7

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

pkg/cmd/cmd.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ var Command = cli.Command{
9595
&orgsList,
9696
},
9797
},
98+
99+
&mcpCommand,
98100
},
99101
EnableShellCompletion: true,
100102
HideHelpCommand: true,

pkg/cmd/mcp.go

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
package cmd
4+
5+
import (
6+
"context"
7+
"fmt"
8+
"os"
9+
"os/exec"
10+
11+
"github.com/urfave/cli/v3"
12+
)
13+
14+
var mcpCommand = cli.Command{
15+
Name: "mcp",
16+
Usage: "Run Stainless MCP server",
17+
Description: "Wrapper around @stainless-api/mcp@latest with environment variables set",
18+
Action: handleMCP,
19+
ArgsUsage: "[MCP_ARGS...]",
20+
HideHelpCommand: true,
21+
SkipFlagParsing: true,
22+
}
23+
24+
func handleMCP(ctx context.Context, cmd *cli.Command) error {
25+
args := []string{"-y", "@stainless-api/mcp@latest"}
26+
27+
if cmd.Args().Len() > 0 {
28+
args = append(args, cmd.Args().Slice()...)
29+
}
30+
31+
env := os.Environ()
32+
33+
// Set STAINLESS_API_KEY if not already in environment
34+
if apiKey := os.Getenv("STAINLESS_API_KEY"); apiKey == "" {
35+
authConfig, err := LoadAuthConfig()
36+
if err == nil && authConfig != nil && authConfig.AccessToken != "" {
37+
env = append(env, fmt.Sprintf("STAINLESS_API_KEY=%s", authConfig.AccessToken))
38+
}
39+
}
40+
41+
// Set STAINLESS_PROJECT from workspace config if available
42+
var config WorkspaceConfig
43+
found, err := config.Find()
44+
if err == nil && found && config.Project != "" {
45+
env = append(env, fmt.Sprintf("STAINLESS_PROJECT=%s", config.Project))
46+
}
47+
48+
npmCmd := exec.CommandContext(ctx, "npx", args...)
49+
npmCmd.Env = env
50+
npmCmd.Stdout = os.Stdout
51+
npmCmd.Stderr = os.Stderr
52+
npmCmd.Stdin = os.Stdin
53+
54+
return npmCmd.Run()
55+
}

0 commit comments

Comments
 (0)