Skip to content

Commit 618bcd2

Browse files
Ajit Pratap Singhclaude
authored andcommitted
feat(mcp): add stdio transport for Glama registry compatibility
Add --stdio flag to gosqlx-mcp binary, enabling it to serve the MCP protocol over stdin/stdout when spawned as a subprocess by mcp-proxy. Glama's test infrastructure wraps any CMD with `mcp-proxy --`, which expects a stdio-based MCP subprocess. This change allows Glama to inspect tools and run server checks, unlocking the "Server inspectable" and "Tool detection" score items for AAA registry rating. The existing HTTP transport (default) is unchanged. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 2fdef5e commit 618bcd2

2 files changed

Lines changed: 32 additions & 0 deletions

File tree

cmd/gosqlx-mcp/main.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import (
4242

4343
"github.com/ajitpratap0/GoSQLX/pkg/gosqlx"
4444
gosqlxmcp "github.com/ajitpratap0/GoSQLX/pkg/mcp"
45+
mcpserver "github.com/mark3labs/mcp-go/server"
4546
)
4647

4748
func main() {
@@ -52,6 +53,31 @@ func main() {
5253
}
5354

5455
func run() error {
56+
// Check for --stdio flag (used when spawned by mcp-proxy as a subprocess).
57+
for _, arg := range os.Args[1:] {
58+
if arg == "--stdio" {
59+
return runStdio()
60+
}
61+
}
62+
return runHTTP()
63+
}
64+
65+
// runStdio serves the MCP protocol over stdin/stdout.
66+
// This mode is used when the binary is spawned by mcp-proxy.
67+
func runStdio() error {
68+
cfg := gosqlxmcp.DefaultConfig()
69+
srv := gosqlxmcp.New(cfg)
70+
71+
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
72+
defer stop()
73+
74+
stdioSrv := mcpserver.NewStdioServer(srv.MCPServer())
75+
stdioSrv.SetErrorLogger(log.New(os.Stderr, "gosqlx-mcp: ", log.LstdFlags))
76+
return stdioSrv.Listen(ctx, os.Stdin, os.Stdout)
77+
}
78+
79+
// runHTTP serves the MCP protocol over streamable HTTP transport.
80+
func runHTTP() error {
5581
cfg, err := gosqlxmcp.LoadConfig()
5682
if err != nil {
5783
return fmt.Errorf("configuration error: %w", err)

pkg/mcp/server.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ func (s *Server) Cfg() *Config {
5555
return s.cfg
5656
}
5757

58+
// MCPServer returns the underlying MCPServer for use with alternative transports
59+
// such as stdio (mcpserver.NewStdioServer).
60+
func (s *Server) MCPServer() *mcpserver.MCPServer {
61+
return s.mcpSrv
62+
}
63+
5864
// Start binds to cfg.Addr() and serves using streamable HTTP transport.
5965
// It blocks until ctx is cancelled or a fatal error occurs.
6066
func (s *Server) Start(ctx context.Context) error {

0 commit comments

Comments
 (0)