Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions cmd/codemap-mcp/main.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
package main

import (
"context"
"fmt"
"os"

codemapmcp "codemap/mcp"
"codemap/cmd"
)

func main() {
if err := codemapmcp.Run(context.Background()); err != nil {
fmt.Fprintf(os.Stderr, "MCP server error: %v\n", err)
os.Exit(1)
if code := cmd.RunMCP(); code != 0 {
os.Exit(code)
}
}
22 changes: 22 additions & 0 deletions cmd/mcp.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package cmd

import (
"context"
"fmt"
"os"

codemapmcp "codemap/mcp"
)

// RunMCP runs the shared stdio server and returns its process exit status.
func RunMCP() int {
return runMCP(codemapmcp.Run)
}

func runMCP(runner func(context.Context) error) int {
if err := runner(context.Background()); err != nil {
fmt.Fprintf(os.Stderr, "MCP server error: %v\n", err)
return 1
}
return 0
}
17 changes: 17 additions & 0 deletions cmd/mcp_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package cmd

import (
"context"
"errors"
"testing"
)

func TestRunMCPReturnsServerStatus(t *testing.T) {
if code := runMCP(func(context.Context) error { return nil }); code != 0 {
t.Fatalf("RunMCP success exit code = %d, want 0", code)
}

if code := runMCP(func(context.Context) error { return errors.New("boom") }); code != 1 {
t.Fatalf("RunMCP failure exit code = %d, want 1", code)
}
}
7 changes: 2 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"context"
"encoding/json"
"errors"
"flag"
Expand All @@ -18,7 +17,6 @@ import (
"codemap/config"
"codemap/handoff"
"codemap/limits"
codemapmcp "codemap/mcp"
"codemap/render"
"codemap/scanner"
"codemap/watch"
Expand Down Expand Up @@ -108,9 +106,8 @@ func main() {

// Handle "mcp" subcommand before global flag parsing
if len(os.Args) >= 2 && os.Args[1] == "mcp" {
if err := codemapmcp.Run(context.Background()); err != nil {
fmt.Fprintf(os.Stderr, "MCP server error: %v\n", err)
os.Exit(1)
if code := cmd.RunMCP(); code != 0 {
os.Exit(code)
}
return
}
Expand Down
6 changes: 6 additions & 0 deletions mcp_fallback_entrypoints_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ func TestMCPEntrypointsMatchConfigFallback(t *testing.T) {
if !strings.Contains(cliResult, "Matches excluded by `only` config:") {
t.Fatalf("fallback guidance missing: %s", cliResult)
}

cliResult = probeFallbackTestBinary(t, cli, []string{"mcp", "ignored"}, root)
standaloneResult = probeFallbackTestBinary(t, standalone, []string{"ignored"}, root)
if cliResult != standaloneResult {
t.Fatalf("legacy argument handling differs:\ncodemap mcp: %s\ncodemap-mcp: %s", cliResult, standaloneResult)
}
}

func buildFallbackTestBinary(t *testing.T, output, pkg string) string {
Expand Down
Loading