Skip to content

Commit 53c5075

Browse files
authored
Merge pull request #9 from magicdrive/revival_mcp_server
Revival mcp server
2 parents f5bbb2b + 28fdd93 commit 53c5075

37 files changed

Lines changed: 3406 additions & 1083 deletions

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,14 @@ ark mcp-server [OPTIONS]
8686
| `--delete-comments` | `-D` | Strip comments (language‑aware) ||
8787

8888
---
89-
<!--
89+
9090
## 🛰 mcp‑server Options
9191

9292
| Option | Alias | Description | Default |
9393
|--------|-------|-------------|---------|
9494
| `--root <dir>` | `-r` | Serve directory root | `$PWD` |
95-
| `--port <port>` | `-p` | HTTP listen port | `8522` |
95+
| `--type <stdio|http>` | `-t` | HTTP listen port | `stdio` |
96+
| `--http-port <port>` | `-p` | HTTP listen port | `8522` |
9697
| `--scan-buffer <size>` | `-b` | Read buffer size (`10M`, `500K`, …) | `10M` |
9798
| `--mask-secrets <on/off>` | `-m` | Detect & mask secrets | `on` |
9899
| `--allow-gitignore <on/off>` | `-a` | Obey `.gitignore` rules | `on` |
@@ -108,7 +109,7 @@ ark mcp-server [OPTIONS]
108109
| `--delete-comments` | `-D` | Strip comments (language‑aware) ||
109110

110111
---
111-
-->
112+
112113
## 📝 Arguments
113114

114115
| Argument | Description |

cmd/ark/mod.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,15 @@ import (
1111
)
1212

1313
func Execute(version string) {
14-
if len(os.Args) > 2 && os.Args[1] == "mcp-server" && false {
15-
_, opt, err := commandline.ServerOptParse(os.Args[2:])
14+
if len(os.Args) >= 2 && os.Args[1] == "mcp-server" {
15+
_, opt, err := commandline.ServerOptParse(version, os.Args[2:])
1616
if err != nil {
1717
log.Fatalf("Faital Error: %v\n", err)
1818
}
19+
if opt.GeneralOption.HelpFlag {
20+
opt.GeneralOption.FlagSet.Usage()
21+
os.Exit(0)
22+
}
1923
mcp.RunMCPServe(opt.RootDir, opt)
2024

2125
} else {

internal/commandline/help.txt

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ Usage: ark [OPTIONS] <dirname>
33
Description:
44
Yet another alternate [directory|repository] represent text generator tool.
55

6-
Options:
6+
Sub commands:
7+
mcp-server Start MCP server.
8+
9+
10+
general (text generator mode) options:
711
-h, --help Show this help message and exit.
812
-v, --version Show version.
913
-o, --output-filename <filename> Specify ark output txt filename. (optional. default: 'ark_output.txt')
@@ -25,6 +29,25 @@ Options:
2529
-S, --silent Specify flag process without displaying messages during processing. (optional.)
2630
-D, --delete-comments Specify flag strip comments based on language detection. (optional.)
2731

32+
mcp-server options:
33+
-r, --root <dirname> Specify the mcp-server serve root dirname(optional. default: $pwd)
34+
-t, --type <http|stdio> Specify the mcp-server serve type. (optional. default: 'stdio')
35+
-p, --port <number> Specify the mcp-server port. (optional. default: 8522)
36+
-b, --scan-buffer <number|byte-string> Specify the line scan buffer size. (optional. default: '10M')
37+
-m, --mask-secrets <'on'|'off'> Specify Detect the secrets and convert it to masked output. (optional. default: 'on').
38+
-a, --allow-gitignore <'on'|'off'> Specify enable .gitignore filter rule. (optional. default: 'on')
39+
-A, --additionally-ignorerule <filepath> Specify a file containing additional ignore rules. (optional.)
40+
-d, --ignore-dotfile <'on'|'off'> Specify ignore dot files. (optional. default 'off')
41+
-x, --pattern-regex <regxp> Specify watch file pattern regexp. (optional.)
42+
-i, --include-ext <extention> Specify include file extention. Allows comma separated list.(optional.)
43+
-g, --exclude-dir-regex <regexp> Specify include directory ignore pattern regexp. (optional.)
44+
-G, --exclude-file-regex <regexp> Specify watch file ignore pattern regexp. (optional.)
45+
-e, --exclude-ext <extention> Specify watch exclude file extention. Allows comma separated list. (optional.)
46+
-E, --exclude-dir <dirname> Specify watch exclude dirname. Allows comma separated list. (optional.)
47+
-s, --skip-non-utf8 Specify flag to ignore files that do not have utf8 charset. (optional.)
48+
-D, --delete-comments Specify flag strip comments based on language detection. (optional.)
49+
50+
2851
Arguments:
2952
<byte-string> byte size string. (ex) 10M, 100k
3053
<dirname> The directory name.

internal/commandline/help_mcp.txt

Lines changed: 0 additions & 58 deletions
This file was deleted.

internal/commandline/mod.go

Lines changed: 0 additions & 2 deletions
This file was deleted.

internal/commandline/server_option.go

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,28 @@
11
package commandline
22

33
import (
4+
"errors"
45
"flag"
56
"fmt"
67
"os"
78
"strconv"
9+
"strings"
810

911
"github.com/magicdrive/ark/internal/common"
12+
"github.com/magicdrive/ark/internal/model"
1013
)
1114

1215
// ServeOption defines options for launching the MCP server
1316
type ServeOption struct {
14-
RootDir string
15-
Port string
16-
GeneralOption *Option
17+
ThisVersion string
18+
RootDir string
19+
McpServerType model.McpSreverType
20+
McpServerTypeValue string
21+
HttpPort string
22+
GeneralOption *Option
1723
}
1824

19-
func ServerOptParse(args []string) (int, *ServeOption, error) {
25+
func ServerOptParse(version string, args []string) (int, *ServeOption, error) {
2026

2127
optLength := len(args)
2228

@@ -28,9 +34,13 @@ func ServerOptParse(args []string) (int, *ServeOption, error) {
2834
rootDirOpt := fs.String("root", currentDir, "Specify ark mcp server serv directory.")
2935
fs.StringVar(rootDirOpt, "r", currentDir, "Specify ark mcp server serv directory.")
3036

31-
// --port
32-
portOpt := fs.Int("port", 8522, "Specify ark mcp server port.")
33-
fs.IntVar(portOpt, "p", 8522, "Specify ark mcp server port.")
37+
// --type
38+
mcpServerTypeOpt := fs.String("type", "stdio", "Specify ark mcp server serv type.")
39+
fs.StringVar(mcpServerTypeOpt, "t", "stdio", "Specify ark mcp server serv type.")
40+
41+
// --http-port
42+
httpPortOpt := fs.Int("http-port", 8522, "Specify ark mcp server port.")
43+
fs.IntVar(httpPortOpt, "p", 8522, "Specify ark mcp server port.")
3444

3545
// --scan-buffer
3646
scanBufferValueOpt := fs.String("scan-buffer", "10M", "Specify the line scan buffer size.")
@@ -120,17 +130,35 @@ func ServerOptParse(args []string) (int, *ServeOption, error) {
120130
FlagSet: fs,
121131
}
122132

123-
if err := generalOpt.Normalize(); err != nil {
124-
return optLength, nil, err
133+
result := &ServeOption{
134+
ThisVersion: version,
135+
RootDir: *rootDirOpt,
136+
McpServerTypeValue: *mcpServerTypeOpt,
137+
HttpPort: strconv.Itoa(*httpPortOpt),
138+
GeneralOption: generalOpt,
125139
}
126140

127-
result := &ServeOption{
128-
RootDir: *rootDirOpt,
129-
Port: strconv.Itoa(*portOpt),
130-
GeneralOption: generalOpt,
141+
if err := common.JoinErrors(result.Normalize(), generalOpt.Normalize()); err != nil {
142+
return optLength, nil, err
131143
}
132144

133145
OverRideHelp(fs)
134146

135147
return optLength, result, nil
136148
}
149+
150+
func (cr *ServeOption) Normalize() error {
151+
152+
var errorMessages = []string{}
153+
154+
// --type
155+
if err := cr.McpServerType.Set(cr.McpServerTypeValue); err != nil {
156+
errorMessages = append(errorMessages, fmt.Sprintf("--type %s", err.Error()))
157+
}
158+
159+
if len(errorMessages) == 0 {
160+
return nil
161+
} else {
162+
return errors.New(strings.Join(errorMessages, "\n"))
163+
}
164+
}

internal/commandline/server_option_test.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import (
99
func TestServerOptParse_Basic(t *testing.T) {
1010
args := []string{
1111
"--root", "/my/project",
12-
"--port", "12345",
12+
"--type", "http",
13+
"--http-port", "12345",
1314
"--scan-buffer", "20M",
1415
"--mask-secrets", "off",
1516
"--allow-gitignore", "off",
@@ -25,16 +26,19 @@ func TestServerOptParse_Basic(t *testing.T) {
2526
"--delete-comment",
2627
}
2728

28-
_, opt, err := commandline.ServerOptParse(args)
29+
_, opt, err := commandline.ServerOptParse("v1.0.0", args)
2930
if err != nil {
3031
t.Fatalf("Expected no error, got: %v", err)
3132
}
3233

3334
if opt.RootDir != "/my/project" {
3435
t.Errorf("RootDir mismatch. got=%s", opt.RootDir)
3536
}
36-
if opt.Port != "12345" {
37-
t.Errorf("Port mismatch. got=%s", opt.Port)
37+
if opt.McpServerTypeValue != "http" {
38+
t.Errorf("McpServerTypeValue mismatch. got=%s", opt.McpServerTypeValue)
39+
}
40+
if opt.HttpPort != "12345" {
41+
t.Errorf("HttpPort mismatch. got=%s", opt.HttpPort)
3842
}
3943
if opt.GeneralOption.MaskSecretsFlagValue != "off" {
4044
t.Errorf("MaskSecretsFlagValue mismatch. got=%s", opt.GeneralOption.MaskSecretsFlagValue)

internal/common/common.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,24 @@
11
package common
22

33
import (
4+
"errors"
45
"os"
56
"strings"
67
)
78

9+
func JoinErrors(errs ...error) error {
10+
var messages []string
11+
for _, err := range errs {
12+
if err != nil {
13+
messages = append(messages, err.Error())
14+
}
15+
}
16+
if len(messages) == 0 {
17+
return nil
18+
}
19+
return errors.New(strings.Join(messages, "\n"))
20+
}
21+
822
func MergeAllowFileList(a, b map[string]bool) map[string]bool {
923
merged := make(map[string]bool)
1024
for k, v := range a {
@@ -52,4 +66,3 @@ func GetCurrentDir() string {
5266
func TrimDotSlash(path string) string {
5367
return strings.TrimPrefix(path, "./")
5468
}
55-

0 commit comments

Comments
 (0)