Skip to content

Commit d739114

Browse files
committed
Implement basic MCP server
1 parent 5641ac3 commit d739114

File tree

15 files changed

+1016
-0
lines changed

15 files changed

+1016
-0
lines changed

.github/dependabot.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "gomod"
4+
directory: "/"
5+
schedule:
6+
interval: "daily"
7+
groups:
8+
minor-dependencies:
9+
update-types:
10+
- "minor"
11+
- "patch"
12+
- package-ecosystem: "github-actions"
13+
directory: "/"
14+
schedule:
15+
interval: "daily"

.github/workflows/release.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
8+
permissions:
9+
contents: write
10+
packages: write
11+
12+
jobs:
13+
goreleaser:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v4
18+
with:
19+
fetch-depth: 0
20+
21+
- name: Set up Go
22+
uses: actions/setup-go@v5
23+
with:
24+
go-version: '>=1.21.0'
25+
check-latest: true
26+
27+
- name: Run GoReleaser
28+
uses: goreleaser/goreleaser-action@v6
29+
with:
30+
distribution: goreleaser
31+
version: '~> v2'
32+
args: release --clean
33+
env:
34+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
35+
36+
- name: Extract version
37+
id: get-version
38+
run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
39+
40+
- name: Login to GitHub Container Registry
41+
uses: docker/login-action@v3
42+
with:
43+
registry: ghcr.io
44+
username: ${{ github.repository_owner }}
45+
password: ${{ secrets.GITHUB_TOKEN }}
46+
47+
- name: Set up Docker Buildx
48+
uses: docker/setup-buildx-action@v3
49+
50+
- name: Build and push Docker image
51+
uses: docker/build-push-action@v6
52+
with:
53+
context: .
54+
push: true
55+
platforms: linux/amd64,linux/arm64
56+
tags: |
57+
ghcr.io/${{ github.repository }}:latest
58+
ghcr.io/${{ github.repository }}:${{ steps.get-version.outputs.VERSION }}

.github/workflows/test.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Test
2+
3+
on: [push]
4+
5+
jobs:
6+
tests:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- name: Checkout
10+
uses: actions/checkout@v4
11+
with:
12+
fetch-depth: 0
13+
14+
- name: Set up Go
15+
uses: actions/setup-go@v5
16+
with:
17+
go-version: '>=1.21.0'
18+
check-latest: true
19+
20+
- name: Run tests
21+
run: go test ./...

.goreleaser.yml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
version: 2
2+
3+
before:
4+
hooks:
5+
- go mod tidy
6+
7+
builds:
8+
- id: codebench-mcp
9+
env:
10+
- CGO_ENABLED=0
11+
goos:
12+
- linux
13+
- windows
14+
- darwin
15+
goarch:
16+
- amd64
17+
- arm64
18+
ldflags:
19+
- -s -w -X github.com/mark3labs/codebench-mcp/jsserver.Version={{.Version}}
20+
binary: codebench-mcp
21+
main: .
22+
23+
archives:
24+
- id: default
25+
format_overrides:
26+
- goos: windows
27+
formats:
28+
- zip
29+
name_template: >-
30+
{{ .ProjectName }}_
31+
{{- .Os }}_
32+
{{- .Arch }}
33+
files:
34+
- README.md
35+
- LICENSE*
36+
37+
checksum:
38+
name_template: 'checksums.txt'
39+
algorithm: sha256
40+
41+
# Using new snapshot configuration
42+
snapshot:
43+
version_template: "{{ .Version }}-SNAPSHOT-{{ .ShortCommit }}"
44+
45+
changelog:
46+
sort: asc
47+
filters:
48+
exclude:
49+
- '^docs:'
50+
- '^test:'
51+
- Merge pull request
52+
- Merge branch
53+
54+
release:
55+
github:
56+
owner: mark3labs
57+
name: codebench-mcp
58+
draft: false
59+
prerelease: auto
60+
name_template: "{{ .Tag }}"
61+
mode: replace

CONTEXT.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# CodeBench MCP - JavaScript Executor
2+
3+
An MCP server that provides JavaScript execution capabilities with Node.js-like APIs.
4+
5+
## Tool
6+
7+
### executeJS
8+
- Execute JavaScript code with full Node.js-like environment
9+
- Includes: console, fs, http, timers (setTimeout/setInterval), process, and require
10+
- Parameters: `code` (required): JavaScript code to execute
11+
12+
## Build/Test Commands
13+
- `go build ./...` - Build all packages
14+
- `go test ./...` - Run all tests
15+
- `go test -v ./...` - Run tests with verbose output
16+
- `go test -run TestName` - Run specific test
17+
- `go mod tidy` - Clean up dependencies
18+
- `go fmt ./...` - Format code
19+
- `go vet ./...` - Static analysis
20+
- `golangci-lint run` - Comprehensive linting (if configured)
21+
22+
## Code Style Guidelines
23+
- Use `gofmt` for consistent formatting
24+
- Follow standard Go naming conventions: PascalCase for exported, camelCase for unexported
25+
- Package names should be lowercase, single words when possible
26+
- Use meaningful variable names, avoid abbreviations
27+
- Error handling: always check errors, wrap with context using `fmt.Errorf("context: %w", err)`
28+
- Imports: group standard library, third-party, then local packages with blank lines
29+
- Use interfaces for testability and loose coupling
30+
- Prefer composition over inheritance
31+
- Keep functions small and focused on single responsibility
32+
33+
## Project Info
34+
- Go version: 1.23.10
35+
- Module: github.com/mark3labs/codebench-mcp

Dockerfile

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Generated by https://smithery.ai. See: https://smithery.ai/docs/config#dockerfile
2+
FROM golang:1.23-alpine AS builder
3+
4+
WORKDIR /app
5+
6+
# Copy go.mod and go.sum first for caching dependencies
7+
COPY go.mod go.sum ./
8+
9+
# Download dependencies
10+
RUN go mod download
11+
12+
# Copy the source code
13+
COPY . .
14+
15+
# Build the application
16+
RUN go build -ldflags="-s -w" -o server .
17+
18+
FROM alpine:latest
19+
20+
WORKDIR /app
21+
22+
# Copy the built binary from the builder stage
23+
COPY --from=builder /app/server ./
24+
25+
# The container will run the JavaScript executor MCP server
26+
ENTRYPOINT ["./server"]

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 Anthropic, PBC
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
# JavaScript Executor MCP Server
2+
3+
This MCP server provides JavaScript execution capabilities with a Node.js-like environment.
4+
5+
## Features
6+
7+
The `executeJS` tool provides:
8+
9+
- **Console API**: `console.log()`, `console.error()`, `console.warn()`
10+
- **File System**: `fs.readFileSync()`, `fs.writeFileSync()`, `fs.existsSync()`
11+
- **HTTP Server**: `http.createServer()` with request/response handling
12+
- **Timers**: `setTimeout()`, `clearTimeout()`, `setInterval()`, `clearInterval()`
13+
- **Process**: `process.argv`, `process.cwd()`, `process.exit()`, `process.env`
14+
- **Module System**: `require()` for loading JavaScript modules
15+
16+
## Getting Started
17+
18+
### Installation
19+
20+
#### Using Go Install
21+
22+
```bash
23+
go install github.com/mark3labs/codebench-mcp@latest
24+
```
25+
26+
### Usage
27+
28+
#### As a standalone server
29+
30+
```bash
31+
codebench-mcp
32+
```
33+
34+
#### As a library in your Go project
35+
36+
```go
37+
package main
38+
39+
import (
40+
"log"
41+
42+
"github.com/mark3labs/codebench-mcp/jsserver"
43+
"github.com/mark3labs/mcp-go/server"
44+
)
45+
46+
func main() {
47+
// Create a new JavaScript executor server
48+
jss, err := jsserver.NewJSServer()
49+
if err != nil {
50+
log.Fatalf("Failed to create server: %v", err)
51+
}
52+
53+
// Serve requests
54+
if err := server.ServeStdio(jss); err != nil {
55+
log.Fatalf("Server error: %v", err)
56+
}
57+
}
58+
```
59+
60+
### Usage with Model Context Protocol
61+
62+
To integrate this server with apps that support MCP:
63+
64+
```json
65+
{
66+
"mcpServers": {
67+
"javascript": {
68+
"command": "codebench-mcp"
69+
}
70+
}
71+
}
72+
```
73+
74+
### Docker
75+
76+
#### Running with Docker
77+
78+
You can run the JavaScript Executor MCP server using Docker:
79+
80+
```bash
81+
docker run -i --rm ghcr.io/mark3labs/codebench-mcp:latest
82+
```
83+
84+
#### Docker Configuration with MCP
85+
86+
To integrate the Docker image with apps that support MCP:
87+
88+
```json
89+
{
90+
"mcpServers": {
91+
"javascript": {
92+
"command": "docker",
93+
"args": [
94+
"run",
95+
"-i",
96+
"--rm",
97+
"ghcr.io/mark3labs/codebench-mcp:latest"
98+
]
99+
}
100+
}
101+
}
102+
```
103+
104+
## Tool Reference
105+
106+
### executeJS
107+
108+
Execute JavaScript code with full Node.js-like environment.
109+
110+
**Parameters:**
111+
- `code` (required): JavaScript code to execute
112+
113+
**Example:**
114+
```javascript
115+
console.log("Hello, World!");
116+
117+
// File operations
118+
fs.writeFileSync("test.txt", "Hello from JS!");
119+
const content = fs.readFileSync("test.txt");
120+
console.log("File content:", content);
121+
122+
// HTTP server
123+
const server = http.createServer((req, res) => {
124+
res.end("Hello from HTTP server!");
125+
});
126+
server.listen(8080);
127+
128+
// Timers
129+
setTimeout(() => {
130+
console.log("Timer executed!");
131+
}, 1000);
132+
133+
// Process info
134+
console.log("Current directory:", process.cwd());
135+
console.log("Arguments:", process.argv);
136+
```
137+
138+
## Building
139+
140+
```bash
141+
go build -o codebench-mcp .
142+
```
143+
144+
## License
145+
146+
See the [LICENSE](LICENSE) file for details.

codebench-mcp

18.4 MB
Binary file not shown.

0 commit comments

Comments
 (0)