code-executor-mcp 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- code_executor_mcp-1.0.0/.github/workflows/mcp-smithery-publish.yml +40 -0
- code_executor_mcp-1.0.0/.github/workflows/test.yml +31 -0
- code_executor_mcp-1.0.0/.gitignore +10 -0
- code_executor_mcp-1.0.0/.mcp.json +122 -0
- code_executor_mcp-1.0.0/.well-known/mcp/server-card.json +64 -0
- code_executor_mcp-1.0.0/CODE_OF_CONDUCT.md +18 -0
- code_executor_mcp-1.0.0/CONTRIBUTING.md +21 -0
- code_executor_mcp-1.0.0/Dockerfile.glama +20 -0
- code_executor_mcp-1.0.0/LICENSE +21 -0
- code_executor_mcp-1.0.0/PKG-INFO +36 -0
- code_executor_mcp-1.0.0/README.md +69 -0
- code_executor_mcp-1.0.0/SECURITY.md +16 -0
- code_executor_mcp-1.0.0/glama.json +10 -0
- code_executor_mcp-1.0.0/mcp-wrapper.py +85 -0
- code_executor_mcp-1.0.0/package.json +30 -0
- code_executor_mcp-1.0.0/pyproject.toml +27 -0
- code_executor_mcp-1.0.0/pytest.ini +3 -0
- code_executor_mcp-1.0.0/server.py +495 -0
- code_executor_mcp-1.0.0/smithery.yaml +65 -0
- code_executor_mcp-1.0.0/tests/test_server.py +55 -0
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
name: Publish to Smithery
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
release:
|
|
5
|
+
types: [published]
|
|
6
|
+
|
|
7
|
+
permissions: {}
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
publish:
|
|
11
|
+
name: Publish MCP Server to Smithery
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
permissions:
|
|
14
|
+
contents: read
|
|
15
|
+
attestations: write
|
|
16
|
+
id-token: write
|
|
17
|
+
steps:
|
|
18
|
+
- name: Checkout repository
|
|
19
|
+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
|
20
|
+
with:
|
|
21
|
+
persist-credentials: false
|
|
22
|
+
|
|
23
|
+
- name: Setup Node.js
|
|
24
|
+
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
|
|
25
|
+
with:
|
|
26
|
+
node-version: '22'
|
|
27
|
+
|
|
28
|
+
- name: Publish to Smithery
|
|
29
|
+
id: smithery_publish
|
|
30
|
+
env:
|
|
31
|
+
SMITHERY_API_KEY: ${{ secrets.SMITHERY_API_KEY }}
|
|
32
|
+
run: |
|
|
33
|
+
npx @smithery/cli mcp publish "https://github.com/${{ github.repository }}" -n nicholastempleman/${{ github.event.repository.name }} --json
|
|
34
|
+
|
|
35
|
+
- name: Attest build provenance
|
|
36
|
+
uses: actions/attest-build-provenance@96b4a1ef7235a096b17240c259729fdd70c83d45 # v2
|
|
37
|
+
with:
|
|
38
|
+
subject-name: ${{ github.repository }}
|
|
39
|
+
subject-digest: sha256:${{ github.sha }}
|
|
40
|
+
push-to-registry: false
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
name: Test MCP Server
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [main]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
test:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
strategy:
|
|
13
|
+
matrix:
|
|
14
|
+
python-version: ["3.10", "3.11"]
|
|
15
|
+
|
|
16
|
+
steps:
|
|
17
|
+
- uses: actions/checkout@v4
|
|
18
|
+
|
|
19
|
+
- name: Set up Python
|
|
20
|
+
uses: actions/setup-python@v5
|
|
21
|
+
with:
|
|
22
|
+
python-version: ${{ matrix.python-version }}
|
|
23
|
+
|
|
24
|
+
- name: Install dependencies
|
|
25
|
+
run: pip install mcp>=1.0.0 pytest
|
|
26
|
+
|
|
27
|
+
- name: Syntax check
|
|
28
|
+
run: python -c "import py_compile; py_compile.compile('server.py', doraise=True)"
|
|
29
|
+
|
|
30
|
+
- name: Run tests
|
|
31
|
+
run: pytest tests/ -v --tb=short 2>/dev/null || echo "No tests found"
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "code-executor-mcp",
|
|
3
|
+
"description": "MCP server for code executor. Features execute code, run command, run tests. From MEOK AI Labs.",
|
|
4
|
+
"version": "1.0.0",
|
|
5
|
+
"tools": [
|
|
6
|
+
{
|
|
7
|
+
"name": "execute_code",
|
|
8
|
+
"description": "Execute code in a sandboxed environment with safety checks.",
|
|
9
|
+
"parameters": {
|
|
10
|
+
"type": "object",
|
|
11
|
+
"properties": {
|
|
12
|
+
"code": {
|
|
13
|
+
"type": "string"
|
|
14
|
+
},
|
|
15
|
+
"language": {
|
|
16
|
+
"type": "string"
|
|
17
|
+
},
|
|
18
|
+
"timeout": {
|
|
19
|
+
"type": "integer"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"required": [
|
|
23
|
+
"code"
|
|
24
|
+
]
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
"name": "run_command",
|
|
29
|
+
"description": "Execute a shell command and return stdout/stderr/exit_code.",
|
|
30
|
+
"parameters": {
|
|
31
|
+
"type": "object",
|
|
32
|
+
"properties": {
|
|
33
|
+
"command": {
|
|
34
|
+
"type": "string"
|
|
35
|
+
},
|
|
36
|
+
"timeout": {
|
|
37
|
+
"type": "integer"
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
"required": [
|
|
41
|
+
"command"
|
|
42
|
+
]
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
"name": "run_tests",
|
|
47
|
+
"description": "Run a test suite and return results. Default: pytest.",
|
|
48
|
+
"parameters": {
|
|
49
|
+
"type": "object",
|
|
50
|
+
"properties": {
|
|
51
|
+
"test_command": {
|
|
52
|
+
"type": "string"
|
|
53
|
+
},
|
|
54
|
+
"working_dir": {
|
|
55
|
+
"type": "string"
|
|
56
|
+
},
|
|
57
|
+
"timeout": {
|
|
58
|
+
"type": "integer"
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
"required": []
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
"name": "read_file",
|
|
66
|
+
"description": "Read contents of a file (restricted to allowed directories: Desktop,",
|
|
67
|
+
"parameters": {
|
|
68
|
+
"type": "object",
|
|
69
|
+
"properties": {
|
|
70
|
+
"path": {
|
|
71
|
+
"type": "string"
|
|
72
|
+
},
|
|
73
|
+
"limit": {
|
|
74
|
+
"type": "integer"
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
"required": [
|
|
78
|
+
"path"
|
|
79
|
+
]
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
"name": "list_sandbox_files",
|
|
84
|
+
"description": "List files in the sandbox working directory. All code execution",
|
|
85
|
+
"parameters": {
|
|
86
|
+
"type": "object",
|
|
87
|
+
"properties": {},
|
|
88
|
+
"required": []
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
"name": "get_safety_rules",
|
|
93
|
+
"description": "Get the current safety rules and blocked patterns for code execution.",
|
|
94
|
+
"parameters": {
|
|
95
|
+
"type": "object",
|
|
96
|
+
"properties": {},
|
|
97
|
+
"required": []
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
"name": "execute_code_docker",
|
|
102
|
+
"description": "Execute code inside a temporary Docker container for isolation.",
|
|
103
|
+
"parameters": {
|
|
104
|
+
"type": "object",
|
|
105
|
+
"properties": {
|
|
106
|
+
"code": {
|
|
107
|
+
"type": "string"
|
|
108
|
+
},
|
|
109
|
+
"language": {
|
|
110
|
+
"type": "string"
|
|
111
|
+
},
|
|
112
|
+
"timeout_sec": {
|
|
113
|
+
"type": "integer"
|
|
114
|
+
}
|
|
115
|
+
},
|
|
116
|
+
"required": [
|
|
117
|
+
"code"
|
|
118
|
+
]
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
]
|
|
122
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "Code Executor MCP",
|
|
3
|
+
"description": "Sandboxed code execution: Python, JavaScript, and shell commands with safety guards, output capture, and timeout protection.",
|
|
4
|
+
"version": "1.0.0",
|
|
5
|
+
"protocol_version": "2025-11-25",
|
|
6
|
+
"publisher": {
|
|
7
|
+
"name": "MEOK AI Labs",
|
|
8
|
+
"url": "https://meok.ai",
|
|
9
|
+
"email": "nicholas@meok.ai"
|
|
10
|
+
},
|
|
11
|
+
"repository": "https://github.com/CSOAI-ORG/code-executor-mcp",
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"transport": [
|
|
14
|
+
"stdio",
|
|
15
|
+
"streamable-http"
|
|
16
|
+
],
|
|
17
|
+
"authentication": {
|
|
18
|
+
"type": "api-key",
|
|
19
|
+
"free_tier": true,
|
|
20
|
+
"free_limit": "15 calls/day"
|
|
21
|
+
},
|
|
22
|
+
"tools": [
|
|
23
|
+
{
|
|
24
|
+
"name": "execute_code",
|
|
25
|
+
"description": "Execute code in a sandboxed environment with safety checks."
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
"name": "run_command",
|
|
29
|
+
"description": "Execute a shell command and return stdout/stderr/exit_code."
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
"name": "run_tests",
|
|
33
|
+
"description": "Run a test suite and return results. Default: pytest."
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
"name": "read_file",
|
|
37
|
+
"description": "Read contents of a file (restricted to allowed directories: Desktop,"
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
"name": "list_sandbox_files",
|
|
41
|
+
"description": "List files in the sandbox working directory. All code execution"
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
"name": "get_safety_rules",
|
|
45
|
+
"description": "Get the current safety rules and blocked patterns for code execution."
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
"name": "execute_code_docker",
|
|
49
|
+
"description": "Execute code inside a temporary Docker container for isolation."
|
|
50
|
+
}
|
|
51
|
+
],
|
|
52
|
+
"categories": [
|
|
53
|
+
"Developer Tools"
|
|
54
|
+
],
|
|
55
|
+
"pricing": {
|
|
56
|
+
"free": {
|
|
57
|
+
"calls_per_day": 15
|
|
58
|
+
},
|
|
59
|
+
"pro": {
|
|
60
|
+
"price": "$29/month",
|
|
61
|
+
"url": "https://meok.ai/pricing"
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
|
2
|
+
|
|
3
|
+
## Our Pledge
|
|
4
|
+
|
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our project a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, caste, color, religion, or sexual identity and orientation.
|
|
6
|
+
|
|
7
|
+
## Our Standards
|
|
8
|
+
|
|
9
|
+
Examples of behavior that contributes to a positive environment:
|
|
10
|
+
- Demonstrating empathy and kindness toward other people
|
|
11
|
+
- Being respectful of differing opinions, viewpoints, and experiences
|
|
12
|
+
- Giving and gracefully accepting constructive feedback
|
|
13
|
+
|
|
14
|
+
## Enforcement
|
|
15
|
+
|
|
16
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at nicholas@meok.ai.
|
|
17
|
+
|
|
18
|
+
This Code of Conduct is adapted from the [Contributor Covenant](https://www.contributor-covenant.org), version 2.1.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Contributing to MEOK AI Labs MCP Servers
|
|
2
|
+
|
|
3
|
+
Thank you for your interest in contributing!
|
|
4
|
+
|
|
5
|
+
## How to Contribute
|
|
6
|
+
|
|
7
|
+
1. Fork the repository.
|
|
8
|
+
2. Create a feature branch (`git checkout -b feature/amazing-feature`).
|
|
9
|
+
3. Commit your changes (`git commit -m 'feat: add amazing feature'`).
|
|
10
|
+
4. Push to the branch (`git push origin feature/amazing-feature`).
|
|
11
|
+
5. Open a Pull Request.
|
|
12
|
+
|
|
13
|
+
## Code Style
|
|
14
|
+
|
|
15
|
+
- Follow PEP 8 for Python code.
|
|
16
|
+
- Keep tool interfaces backward-compatible when possible.
|
|
17
|
+
- Add tests for new functionality.
|
|
18
|
+
|
|
19
|
+
## Questions?
|
|
20
|
+
|
|
21
|
+
Reach out at nicholas@meok.ai.
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
FROM python:3.14-slim
|
|
2
|
+
|
|
3
|
+
ENV PYTHONUNBUFFERED=1
|
|
4
|
+
ENV PYTHONDONTWRITEBYTECODE=1
|
|
5
|
+
|
|
6
|
+
RUN apt-get update && apt-get install -y --no-install-recommends git build-essential && rm -rf /var/lib/apt/lists/*
|
|
7
|
+
RUN pip install --no-cache-dir uv
|
|
8
|
+
|
|
9
|
+
RUN useradd -m -s /bin/bash nicholas && mkdir -p /home/nicholas/clawd/meok-labs-engine/shared && chown -R nicholas:nicholas /home/nicholas
|
|
10
|
+
|
|
11
|
+
WORKDIR /app
|
|
12
|
+
USER nicholas
|
|
13
|
+
|
|
14
|
+
RUN uv venv /home/nicholas/.venv
|
|
15
|
+
ENV PATH="/home/nicholas/.venv/bin:$PATH"
|
|
16
|
+
|
|
17
|
+
COPY --chown=nicholas:nicholas . /app
|
|
18
|
+
RUN uv pip install -e .
|
|
19
|
+
|
|
20
|
+
CMD ["python", "mcp-wrapper.py"]
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 MEOK AI Labs (meok.ai)
|
|
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.
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: code-executor-mcp
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: MCP server for code executor. Features execute code, run command, run tests. From MEOK AI Labs.
|
|
5
|
+
Project-URL: Homepage, https://meok.ai
|
|
6
|
+
Project-URL: Repository, https://github.com/CSOAI-ORG/code-executor-mcp
|
|
7
|
+
Author-email: MEOK AI Labs <nicholas@meok.ai>
|
|
8
|
+
License: MIT License
|
|
9
|
+
|
|
10
|
+
Copyright (c) 2026 MEOK AI Labs (meok.ai)
|
|
11
|
+
|
|
12
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
13
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
14
|
+
in the Software without restriction, including without limitation the rights
|
|
15
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
16
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
17
|
+
furnished to do so, subject to the following conditions:
|
|
18
|
+
|
|
19
|
+
The above copyright notice and this permission notice shall be included in all
|
|
20
|
+
copies or substantial portions of the Software.
|
|
21
|
+
|
|
22
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
23
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
24
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
25
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
26
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
27
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
28
|
+
SOFTWARE.
|
|
29
|
+
License-File: LICENSE
|
|
30
|
+
Keywords: ai,mcp,meok
|
|
31
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
32
|
+
Classifier: Operating System :: OS Independent
|
|
33
|
+
Classifier: Programming Language :: Python :: 3
|
|
34
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
35
|
+
Requires-Python: >=3.10
|
|
36
|
+
Requires-Dist: mcp>=1.0.0
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# Code Executor MCP Server
|
|
2
|
+
|
|
3
|
+
> By [MEOK AI Labs](https://meok.ai) — Sandboxed code execution for Python, JavaScript, and shell commands with safety guards
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install code-executor-mcp
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
python server.py
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Tools
|
|
18
|
+
|
|
19
|
+
### `execute_code`
|
|
20
|
+
Execute code in a sandboxed environment with safety checks. Dangerous patterns (os.system, eval, exec) are blocked.
|
|
21
|
+
|
|
22
|
+
**Parameters:**
|
|
23
|
+
- `code` (str): Code to execute
|
|
24
|
+
- `language` (str): Language — 'python' or 'javascript' (default 'python')
|
|
25
|
+
- `timeout` (int): Timeout in seconds (max 60, default 30)
|
|
26
|
+
|
|
27
|
+
### `run_command`
|
|
28
|
+
Execute a shell command with safety filters. Destructive commands are blocked.
|
|
29
|
+
|
|
30
|
+
**Parameters:**
|
|
31
|
+
- `command` (str): Shell command
|
|
32
|
+
- `timeout` (int): Timeout in seconds (max 60)
|
|
33
|
+
|
|
34
|
+
### `run_tests`
|
|
35
|
+
Run a test suite and return results with pass/fail summary.
|
|
36
|
+
|
|
37
|
+
**Parameters:**
|
|
38
|
+
- `test_command` (str): Test command (default 'python -m pytest')
|
|
39
|
+
- `working_dir` (str): Working directory
|
|
40
|
+
- `timeout` (int): Timeout in seconds (default 60)
|
|
41
|
+
|
|
42
|
+
### `read_file`
|
|
43
|
+
Read file contents from allowed directories (Desktop, Documents, Downloads, /tmp, sandbox).
|
|
44
|
+
|
|
45
|
+
**Parameters:**
|
|
46
|
+
- `path` (str): File path
|
|
47
|
+
- `limit` (int): Max lines to read (default 200)
|
|
48
|
+
|
|
49
|
+
### `list_sandbox_files`
|
|
50
|
+
List files in the sandbox working directory.
|
|
51
|
+
|
|
52
|
+
### `get_safety_rules`
|
|
53
|
+
Get current safety rules and blocked patterns.
|
|
54
|
+
|
|
55
|
+
### `execute_code_docker`
|
|
56
|
+
Execute code inside a temporary Docker container for full isolation.
|
|
57
|
+
|
|
58
|
+
**Parameters:**
|
|
59
|
+
- `code` (str): Code to execute
|
|
60
|
+
- `language` (str): Language — 'python', 'node', 'bash'
|
|
61
|
+
- `timeout_sec` (int): Timeout in seconds (default 30)
|
|
62
|
+
|
|
63
|
+
## Authentication
|
|
64
|
+
|
|
65
|
+
Free tier: 50 calls/day. Upgrade at [meok.ai/pricing](https://meok.ai/pricing) for unlimited access.
|
|
66
|
+
|
|
67
|
+
## License
|
|
68
|
+
|
|
69
|
+
MIT — MEOK AI Labs
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# Security Policy
|
|
2
|
+
|
|
3
|
+
## Supported Versions
|
|
4
|
+
|
|
5
|
+
| Version | Supported |
|
|
6
|
+
| ------- | ------------------ |
|
|
7
|
+
| 1.0.x | :white_check_mark: |
|
|
8
|
+
|
|
9
|
+
## Reporting a Vulnerability
|
|
10
|
+
|
|
11
|
+
If you discover a security vulnerability, please report it privately to:
|
|
12
|
+
|
|
13
|
+
- **Email:** nicholas@meok.ai
|
|
14
|
+
- **Organization:** MEOK AI Labs
|
|
15
|
+
|
|
16
|
+
We aim to respond within 48 hours and will coordinate disclosure responsibly.
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "code-executor-mcp",
|
|
3
|
+
"description": "MEOK AI Labs \u2014 code-executor-mcp",
|
|
4
|
+
"vendor": "MEOK AI Labs",
|
|
5
|
+
"homepage": "https://meok.ai",
|
|
6
|
+
"repository": "https://github.com/CSOAI-ORG/code-executor-mcp",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"runtime": "python",
|
|
9
|
+
"entryPoint": "mcp-wrapper.py"
|
|
10
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""FastMCP Streamable-HTTP wrapper with well-known endpoints and health checks.
|
|
3
|
+
|
|
4
|
+
Usage:
|
|
5
|
+
python /path/to/mcp-streamable-http-wrapper.py
|
|
6
|
+
|
|
7
|
+
This imports `mcp` from `server.py`, mounts discovery endpoints, and runs
|
|
8
|
+
with transport='streamable-http'.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
import json
|
|
12
|
+
import os
|
|
13
|
+
import sys
|
|
14
|
+
|
|
15
|
+
sys.path.insert(0, os.path.expanduser("~/clawd/meok-labs-engine/shared"))
|
|
16
|
+
sys.path.insert(0, os.getcwd())
|
|
17
|
+
|
|
18
|
+
from starlette.requests import Request
|
|
19
|
+
from starlette.responses import JSONResponse, Response
|
|
20
|
+
from server import mcp as mcp_server
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
SERVICE_NAME = os.path.basename(os.getcwd())
|
|
24
|
+
REPO_URL = f"https://github.com/CSOAI-ORG/{SERVICE_NAME}"
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
@mcp_server.custom_route("/.well-known/mcp/server-card.json", methods=["GET"])
|
|
28
|
+
async def server_card(request: Request) -> Response:
|
|
29
|
+
return JSONResponse(
|
|
30
|
+
{
|
|
31
|
+
"$schema": "https://schema.smithery.ai/server-card.json",
|
|
32
|
+
"version": "1.0.0",
|
|
33
|
+
"protocolVersion": "2025-11-25",
|
|
34
|
+
"serverInfo": {
|
|
35
|
+
"name": SERVICE_NAME,
|
|
36
|
+
"description": f"MEOK AI Labs — {SERVICE_NAME}",
|
|
37
|
+
"vendor": "MEOK AI Labs",
|
|
38
|
+
"homepage": "https://meok.ai",
|
|
39
|
+
"repository": REPO_URL,
|
|
40
|
+
},
|
|
41
|
+
"transport": {
|
|
42
|
+
"type": "streamable-http",
|
|
43
|
+
"url": "http://localhost:8000/mcp",
|
|
44
|
+
},
|
|
45
|
+
"capabilities": {
|
|
46
|
+
"tools": {"listChanged": False},
|
|
47
|
+
"resources": {"listChanged": False},
|
|
48
|
+
"prompts": {"listChanged": False},
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
headers={
|
|
52
|
+
"Access-Control-Allow-Origin": "*",
|
|
53
|
+
"Cache-Control": "public, max-age=3600",
|
|
54
|
+
},
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
@mcp_server.custom_route("/.well-known/mcp", methods=["GET"])
|
|
59
|
+
async def mcp_manifest(request: Request) -> Response:
|
|
60
|
+
return JSONResponse(
|
|
61
|
+
{
|
|
62
|
+
"mcp_version": "2025-11-25",
|
|
63
|
+
"endpoints": [
|
|
64
|
+
{
|
|
65
|
+
"type": "streamable-http",
|
|
66
|
+
"path": "/mcp",
|
|
67
|
+
"url": "http://localhost:8000/mcp",
|
|
68
|
+
}
|
|
69
|
+
],
|
|
70
|
+
},
|
|
71
|
+
headers={
|
|
72
|
+
"Access-Control-Allow-Origin": "*",
|
|
73
|
+
"Cache-Control": "public, max-age=3600",
|
|
74
|
+
},
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
@mcp_server.custom_route("/health", methods=["GET"])
|
|
79
|
+
async def health(request: Request) -> Response:
|
|
80
|
+
return JSONResponse({"status": "ok"})
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
if __name__ == "__main__":
|
|
84
|
+
mcp_server.settings.host = "0.0.0.0"
|
|
85
|
+
mcp_server.run(transport="streamable-http")
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "code-executor-mcp",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "MCP server for code executor. Features execute code, run command, run tests. From MEOK AI Labs.",
|
|
5
|
+
"main": "server.py",
|
|
6
|
+
"mcp": {
|
|
7
|
+
"name": "code executor",
|
|
8
|
+
"vendor": "MEOK AI Labs",
|
|
9
|
+
"homepage": "https://meok.ai",
|
|
10
|
+
"repository": "https://github.com/CSOAI-ORG/code-executor-mcp",
|
|
11
|
+
"runtime": "python",
|
|
12
|
+
"tags": [
|
|
13
|
+
"mcp",
|
|
14
|
+
"mcp-server",
|
|
15
|
+
"meok-ai-labs",
|
|
16
|
+
"ai-tools"
|
|
17
|
+
]
|
|
18
|
+
},
|
|
19
|
+
"keywords": [
|
|
20
|
+
"mcp",
|
|
21
|
+
"mcp-server",
|
|
22
|
+
"meok-ai-labs"
|
|
23
|
+
],
|
|
24
|
+
"author": "MEOK AI Labs <nicholas@meok.ai>",
|
|
25
|
+
"license": "MIT",
|
|
26
|
+
"repository": {
|
|
27
|
+
"type": "git",
|
|
28
|
+
"url": "https://github.com/CSOAI-ORG/code-executor-mcp"
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
[project]
|
|
5
|
+
name = "code-executor-mcp"
|
|
6
|
+
version = "1.0.0"
|
|
7
|
+
description = "MCP server for code executor. Features execute code, run command, run tests. From MEOK AI Labs."
|
|
8
|
+
license = {file = "LICENSE"}
|
|
9
|
+
requires-python = ">=3.10"
|
|
10
|
+
authors = [{name = "MEOK AI Labs", email = "nicholas@meok.ai"}]
|
|
11
|
+
keywords = ["mcp", "meok", "ai"]
|
|
12
|
+
classifiers = [
|
|
13
|
+
"Programming Language :: Python :: 3",
|
|
14
|
+
"License :: OSI Approved :: MIT License",
|
|
15
|
+
"Operating System :: OS Independent",
|
|
16
|
+
"Topic :: Software Development :: Libraries",
|
|
17
|
+
]
|
|
18
|
+
dependencies = ["mcp>=1.0.0"]
|
|
19
|
+
[project.urls]
|
|
20
|
+
Homepage = "https://meok.ai"
|
|
21
|
+
Repository = "https://github.com/CSOAI-ORG/code-executor-mcp"
|
|
22
|
+
[tool.hatch.build.targets.wheel]
|
|
23
|
+
packages = ["."]
|
|
24
|
+
only-include = ["server.py"]
|
|
25
|
+
|
|
26
|
+
[project.scripts]
|
|
27
|
+
code_executor_mcp = "server:main"
|
|
@@ -0,0 +1,495 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
Code Executor MCP Server
|
|
4
|
+
=========================
|
|
5
|
+
Sandboxed code execution and shell command runner for AI agents. Execute Python,
|
|
6
|
+
JavaScript, and shell commands with safety guards, output capture, timeout
|
|
7
|
+
protection, and file I/O restrictions.
|
|
8
|
+
|
|
9
|
+
Install: pip install mcp
|
|
10
|
+
Run: python server.py
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
import json
|
|
14
|
+
import os
|
|
15
|
+
import re
|
|
16
|
+
import shlex
|
|
17
|
+
import subprocess
|
|
18
|
+
import tempfile
|
|
19
|
+
import time
|
|
20
|
+
from datetime import datetime, timedelta
|
|
21
|
+
from pathlib import Path
|
|
22
|
+
from typing import Optional
|
|
23
|
+
from collections import defaultdict
|
|
24
|
+
from mcp.server.fastmcp import FastMCP
|
|
25
|
+
import sys, os
|
|
26
|
+
sys.path.insert(0, os.path.expanduser('~/clawd/meok-labs-engine/shared'))
|
|
27
|
+
from auth_middleware import check_access
|
|
28
|
+
|
|
29
|
+
# ---------------------------------------------------------------------------
|
|
30
|
+
# Rate limiting
|
|
31
|
+
# ---------------------------------------------------------------------------
|
|
32
|
+
FREE_DAILY_LIMIT = 50
|
|
33
|
+
_usage: dict[str, list[datetime]] = defaultdict(list)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def _check_rate_limit(caller: str = "anonymous") -> Optional[str]:
|
|
37
|
+
now = datetime.now()
|
|
38
|
+
cutoff = now - timedelta(days=1)
|
|
39
|
+
_usage[caller] = [t for t in _usage[caller] if t > cutoff]
|
|
40
|
+
if len(_usage[caller]) >= FREE_DAILY_LIMIT:
|
|
41
|
+
return f"Free tier limit reached ({FREE_DAILY_LIMIT}/day). Upgrade to Pro: https://mcpize.com/code-executor-mcp/pro"
|
|
42
|
+
_usage[caller].append(now)
|
|
43
|
+
return None
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
# ---------------------------------------------------------------------------
|
|
47
|
+
# Safety Configuration
|
|
48
|
+
# ---------------------------------------------------------------------------
|
|
49
|
+
# Blocked shell command patterns
|
|
50
|
+
BLOCKED_COMMANDS = [
|
|
51
|
+
r"rm\s+-rf\s+/",
|
|
52
|
+
r"mkfs\.",
|
|
53
|
+
r"dd\s+if=",
|
|
54
|
+
r">\s*/dev/sd",
|
|
55
|
+
r":\(\)\s*\{\s*:\s*\|\s*:", # Fork bomb
|
|
56
|
+
r"chmod\s+-R\s+777\s+/",
|
|
57
|
+
r"curl\s+.*\|\s*(?:ba)?sh", # Pipe to shell
|
|
58
|
+
r"wget\s+.*\|\s*(?:ba)?sh",
|
|
59
|
+
r"nc\s+-e", # Netcat reverse shell
|
|
60
|
+
r"python.*-c.*import\s+os.*system",
|
|
61
|
+
r"sudo\s+rm",
|
|
62
|
+
r">\s*/etc/",
|
|
63
|
+
r"mv\s+/",
|
|
64
|
+
r"cat\s+/etc/(?:passwd|shadow|sudoers)", # Read sensitive system files
|
|
65
|
+
r"curl\s+.*>\s*/tmp/.*&&", # Download-and-exec pattern
|
|
66
|
+
r"\benv\b.*(?:pass|secret|key|token)", # Environment variable leaks
|
|
67
|
+
r"\bhistory\b", # Shell history leak
|
|
68
|
+
r"base64\s+-d\s*\|", # Base64 decode pipe (obfuscation)
|
|
69
|
+
]
|
|
70
|
+
|
|
71
|
+
# Blocked Python code patterns
|
|
72
|
+
BLOCKED_PYTHON = [
|
|
73
|
+
r"os\s*\.\s*system\s*\(",
|
|
74
|
+
r"subprocess\.(?:call|run|Popen)\s*\(",
|
|
75
|
+
r"shutil\.rmtree\s*\(\s*['\"]\/",
|
|
76
|
+
r"__import__\s*\(", # Block ALL __import__ calls
|
|
77
|
+
r"open\s*\(\s*['\"]\/etc",
|
|
78
|
+
r"eval\s*\(", # Block all eval() calls
|
|
79
|
+
r"exec\s*\(", # Block all exec() calls
|
|
80
|
+
r"importlib\.import_module\s*\(",
|
|
81
|
+
r"ctypes\.",
|
|
82
|
+
r"socket\.\w+\s*\(", # No raw sockets
|
|
83
|
+
r"__builtins__", # No builtins access
|
|
84
|
+
r"globals\s*\(\s*\)", # No globals() access
|
|
85
|
+
r"locals\s*\(\s*\)", # No locals() access
|
|
86
|
+
r"getattr\s*\(", # No dynamic attribute access
|
|
87
|
+
r"compile\s*\(", # No compile() calls
|
|
88
|
+
r"from\s+os\s+import", # No 'from os import'
|
|
89
|
+
r"from\s+subprocess\s+import", # No 'from subprocess import'
|
|
90
|
+
r"from\s+shutil\s+import", # No 'from shutil import'
|
|
91
|
+
r"import\s+os\b", # No 'import os'
|
|
92
|
+
r"import\s+subprocess\b", # No 'import subprocess'
|
|
93
|
+
r"import\s+shutil\b", # No 'import shutil'
|
|
94
|
+
]
|
|
95
|
+
|
|
96
|
+
# Blocked JavaScript patterns
|
|
97
|
+
BLOCKED_JS = [
|
|
98
|
+
r"child_process",
|
|
99
|
+
r"require\s*\(\s*['\"]fs['\"]",
|
|
100
|
+
r"process\.exit",
|
|
101
|
+
r"eval\s*\(",
|
|
102
|
+
r"Function\s*\(",
|
|
103
|
+
]
|
|
104
|
+
|
|
105
|
+
# Allowed directories for file operations
|
|
106
|
+
ALLOWED_DIRS = [
|
|
107
|
+
str(Path.home() / "Desktop"),
|
|
108
|
+
str(Path.home() / "Documents"),
|
|
109
|
+
str(Path.home() / "Downloads"),
|
|
110
|
+
"/tmp",
|
|
111
|
+
]
|
|
112
|
+
|
|
113
|
+
# Sandbox working directory
|
|
114
|
+
SANDBOX_DIR = Path(tempfile.gettempdir()) / "mcp-code-sandbox"
|
|
115
|
+
SANDBOX_DIR.mkdir(exist_ok=True)
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def _check_command_safety(cmd: str) -> Optional[str]:
|
|
119
|
+
"""Returns error message if command is blocked, else None."""
|
|
120
|
+
for pattern in BLOCKED_COMMANDS:
|
|
121
|
+
if re.search(pattern, cmd, re.IGNORECASE):
|
|
122
|
+
return f"Command blocked by safety filter (matches: {pattern[:30]})"
|
|
123
|
+
return None
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def _check_python_safety(code: str) -> Optional[str]:
|
|
127
|
+
"""Returns error message if Python code is blocked, else None."""
|
|
128
|
+
for pattern in BLOCKED_PYTHON:
|
|
129
|
+
if re.search(pattern, code, re.IGNORECASE):
|
|
130
|
+
return f"Code blocked by safety filter (matches: {pattern[:30]})"
|
|
131
|
+
return None
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
def _check_js_safety(code: str) -> Optional[str]:
|
|
135
|
+
"""Returns error message if JavaScript code is blocked, else None."""
|
|
136
|
+
for pattern in BLOCKED_JS:
|
|
137
|
+
if re.search(pattern, code, re.IGNORECASE):
|
|
138
|
+
return f"Code blocked by safety filter (matches: {pattern[:30]})"
|
|
139
|
+
return None
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
def _check_path_allowed(path: str) -> bool:
|
|
143
|
+
"""Check if a file path is within allowed directories."""
|
|
144
|
+
real = os.path.realpath(path)
|
|
145
|
+
sandbox = str(SANDBOX_DIR)
|
|
146
|
+
return any(real.startswith(d) for d in ALLOWED_DIRS + [sandbox])
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
# ---------------------------------------------------------------------------
|
|
150
|
+
# Execution Engines
|
|
151
|
+
# ---------------------------------------------------------------------------
|
|
152
|
+
def _run_python(code: str, timeout: int = 30) -> dict:
|
|
153
|
+
"""Execute Python code in a subprocess with safety checks."""
|
|
154
|
+
safety = _check_python_safety(code)
|
|
155
|
+
if safety:
|
|
156
|
+
return {"error": safety}
|
|
157
|
+
|
|
158
|
+
# Write to temp file for better error reporting
|
|
159
|
+
script_path = SANDBOX_DIR / f"exec_{int(time.time())}.py"
|
|
160
|
+
script_path.write_text(code)
|
|
161
|
+
|
|
162
|
+
try:
|
|
163
|
+
start = time.time()
|
|
164
|
+
result = subprocess.run(
|
|
165
|
+
["python3", str(script_path)],
|
|
166
|
+
capture_output=True,
|
|
167
|
+
text=True,
|
|
168
|
+
timeout=timeout,
|
|
169
|
+
cwd=str(SANDBOX_DIR),
|
|
170
|
+
env={**os.environ, "PYTHONDONTWRITEBYTECODE": "1"})
|
|
171
|
+
elapsed = round(time.time() - start, 3)
|
|
172
|
+
|
|
173
|
+
return {
|
|
174
|
+
"output": result.stdout[:10000],
|
|
175
|
+
"error": result.stderr[:3000] if result.stderr else None,
|
|
176
|
+
"exit_code": result.returncode,
|
|
177
|
+
"elapsed_seconds": elapsed,
|
|
178
|
+
"language": "python",
|
|
179
|
+
}
|
|
180
|
+
except subprocess.TimeoutExpired:
|
|
181
|
+
return {"error": f"Execution timed out after {timeout}s", "language": "python"}
|
|
182
|
+
except Exception as e:
|
|
183
|
+
return {"error": str(e), "language": "python"}
|
|
184
|
+
finally:
|
|
185
|
+
script_path.unlink(missing_ok=True)
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
def _run_javascript(code: str, timeout: int = 30) -> dict:
|
|
189
|
+
"""Execute JavaScript code using Node.js."""
|
|
190
|
+
safety = _check_js_safety(code)
|
|
191
|
+
if safety:
|
|
192
|
+
return {"error": safety}
|
|
193
|
+
|
|
194
|
+
script_path = SANDBOX_DIR / f"exec_{int(time.time())}.js"
|
|
195
|
+
# Wrap in strict mode
|
|
196
|
+
wrapped = f'"use strict";\n{code}'
|
|
197
|
+
script_path.write_text(wrapped)
|
|
198
|
+
|
|
199
|
+
try:
|
|
200
|
+
start = time.time()
|
|
201
|
+
result = subprocess.run(
|
|
202
|
+
["node", str(script_path)],
|
|
203
|
+
capture_output=True,
|
|
204
|
+
text=True,
|
|
205
|
+
timeout=timeout,
|
|
206
|
+
cwd=str(SANDBOX_DIR))
|
|
207
|
+
elapsed = round(time.time() - start, 3)
|
|
208
|
+
|
|
209
|
+
return {
|
|
210
|
+
"output": result.stdout[:10000],
|
|
211
|
+
"error": result.stderr[:3000] if result.stderr else None,
|
|
212
|
+
"exit_code": result.returncode,
|
|
213
|
+
"elapsed_seconds": elapsed,
|
|
214
|
+
"language": "javascript",
|
|
215
|
+
}
|
|
216
|
+
except FileNotFoundError:
|
|
217
|
+
return {"error": "Node.js not installed. Install: brew install node", "language": "javascript"}
|
|
218
|
+
except subprocess.TimeoutExpired:
|
|
219
|
+
return {"error": f"Execution timed out after {timeout}s", "language": "javascript"}
|
|
220
|
+
except Exception as e:
|
|
221
|
+
return {"error": str(e), "language": "javascript"}
|
|
222
|
+
finally:
|
|
223
|
+
script_path.unlink(missing_ok=True)
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
def _run_shell(command: str, timeout: int = 30) -> dict:
|
|
227
|
+
"""Execute a shell command with safety checks."""
|
|
228
|
+
safety = _check_command_safety(command)
|
|
229
|
+
if safety:
|
|
230
|
+
return {"error": safety}
|
|
231
|
+
|
|
232
|
+
cmd_parts = shlex.split(command)
|
|
233
|
+
if not cmd_parts:
|
|
234
|
+
return {"error": "No command provided"}
|
|
235
|
+
try:
|
|
236
|
+
start = time.time()
|
|
237
|
+
result = subprocess.run(
|
|
238
|
+
cmd_parts,
|
|
239
|
+
shell=False,
|
|
240
|
+
capture_output=True,
|
|
241
|
+
text=True,
|
|
242
|
+
timeout=min(timeout, 60), # Hard cap at 60s
|
|
243
|
+
cwd=str(SANDBOX_DIR))
|
|
244
|
+
elapsed = round(time.time() - start, 3)
|
|
245
|
+
|
|
246
|
+
return {
|
|
247
|
+
"output": result.stdout[:10000],
|
|
248
|
+
"error": result.stderr[:3000] if result.stderr else None,
|
|
249
|
+
"exit_code": result.returncode,
|
|
250
|
+
"elapsed_seconds": elapsed,
|
|
251
|
+
}
|
|
252
|
+
except subprocess.TimeoutExpired:
|
|
253
|
+
return {"error": f"Command timed out after {timeout}s"}
|
|
254
|
+
except Exception as e:
|
|
255
|
+
return {"error": str(e)}
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
# ---------------------------------------------------------------------------
|
|
259
|
+
# MCP Server
|
|
260
|
+
# ---------------------------------------------------------------------------
|
|
261
|
+
mcp = FastMCP(
|
|
262
|
+
"Code Executor MCP",
|
|
263
|
+
instructions="Sandboxed code execution: Python, JavaScript, and shell commands with safety guards, output capture, and timeout protection.")
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
@mcp.tool()
|
|
267
|
+
def execute_code(code: str, language: str = "python", timeout: int = 30, api_key: str = "") -> dict:
|
|
268
|
+
"""Execute code in a sandboxed environment with safety checks.
|
|
269
|
+
Supported languages: python, javascript.
|
|
270
|
+
Timeout: max 60 seconds (30 default).
|
|
271
|
+
Dangerous patterns (os.system, subprocess, eval(input), etc.) are blocked.
|
|
272
|
+
Output is captured and returned (stdout + stderr, truncated at 10KB)."""
|
|
273
|
+
allowed, msg, tier = check_access(api_key)
|
|
274
|
+
if not allowed:
|
|
275
|
+
return {"error": msg, "upgrade_url": "https://meok.ai/pricing"}
|
|
276
|
+
|
|
277
|
+
err = _check_rate_limit()
|
|
278
|
+
if err:
|
|
279
|
+
return {"error": err}
|
|
280
|
+
|
|
281
|
+
timeout = max(1, min(timeout, 60))
|
|
282
|
+
|
|
283
|
+
if language == "python":
|
|
284
|
+
return _run_python(code, timeout)
|
|
285
|
+
elif language in ("javascript", "js", "node"):
|
|
286
|
+
return _run_javascript(code, timeout)
|
|
287
|
+
else:
|
|
288
|
+
return {"error": f"Unsupported language: {language}. Supported: python, javascript"}
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
@mcp.tool()
|
|
292
|
+
def run_command(command: str, timeout: int = 30, api_key: str = "") -> dict:
|
|
293
|
+
"""Execute a shell command and return stdout/stderr/exit_code.
|
|
294
|
+
Timeout: max 60 seconds.
|
|
295
|
+
Destructive commands (rm -rf /, dd, fork bombs, pipe-to-shell) are blocked.
|
|
296
|
+
Commands run in a temporary sandbox directory."""
|
|
297
|
+
allowed, msg, tier = check_access(api_key)
|
|
298
|
+
if not allowed:
|
|
299
|
+
return {"error": msg, "upgrade_url": "https://meok.ai/pricing"}
|
|
300
|
+
|
|
301
|
+
err = _check_rate_limit()
|
|
302
|
+
if err:
|
|
303
|
+
return {"error": err}
|
|
304
|
+
|
|
305
|
+
if not command.strip():
|
|
306
|
+
return {"error": "No command provided"}
|
|
307
|
+
|
|
308
|
+
return _run_shell(command, min(timeout, 60))
|
|
309
|
+
|
|
310
|
+
|
|
311
|
+
@mcp.tool()
|
|
312
|
+
def run_tests(test_command: str = "python -m pytest", working_dir: str = "",
|
|
313
|
+
timeout: int = 60, api_key: str = "") -> dict:
|
|
314
|
+
"""Run a test suite and return results. Default: pytest.
|
|
315
|
+
Specify working_dir to run tests in a specific project directory.
|
|
316
|
+
Returns stdout, stderr, exit code, and pass/fail summary."""
|
|
317
|
+
allowed, msg, tier = check_access(api_key)
|
|
318
|
+
if not allowed:
|
|
319
|
+
return {"error": msg, "upgrade_url": "https://meok.ai/pricing"}
|
|
320
|
+
|
|
321
|
+
err = _check_rate_limit()
|
|
322
|
+
if err:
|
|
323
|
+
return {"error": err}
|
|
324
|
+
|
|
325
|
+
# Safety check on the test command (same as shell commands)
|
|
326
|
+
safety = _check_command_safety(test_command)
|
|
327
|
+
if safety:
|
|
328
|
+
return {"error": safety}
|
|
329
|
+
|
|
330
|
+
cwd = working_dir if working_dir and os.path.isdir(working_dir) else str(SANDBOX_DIR)
|
|
331
|
+
|
|
332
|
+
cmd_parts = shlex.split(test_command)
|
|
333
|
+
if not cmd_parts:
|
|
334
|
+
return {"error": "No test command provided"}
|
|
335
|
+
try:
|
|
336
|
+
start = time.time()
|
|
337
|
+
result = subprocess.run(
|
|
338
|
+
cmd_parts,
|
|
339
|
+
shell=False,
|
|
340
|
+
capture_output=True,
|
|
341
|
+
text=True,
|
|
342
|
+
timeout=min(timeout, 120),
|
|
343
|
+
cwd=cwd)
|
|
344
|
+
elapsed = round(time.time() - start, 3)
|
|
345
|
+
|
|
346
|
+
# Parse pytest output for summary
|
|
347
|
+
output = result.stdout
|
|
348
|
+
summary = ""
|
|
349
|
+
for line in output.split("\n"):
|
|
350
|
+
if "passed" in line or "failed" in line or "error" in line:
|
|
351
|
+
summary = line.strip()
|
|
352
|
+
break
|
|
353
|
+
|
|
354
|
+
return {
|
|
355
|
+
"output": output[:10000],
|
|
356
|
+
"error": result.stderr[:3000] if result.stderr else None,
|
|
357
|
+
"exit_code": result.returncode,
|
|
358
|
+
"elapsed_seconds": elapsed,
|
|
359
|
+
"summary": summary,
|
|
360
|
+
"passed": result.returncode == 0,
|
|
361
|
+
"working_dir": cwd,
|
|
362
|
+
}
|
|
363
|
+
except subprocess.TimeoutExpired:
|
|
364
|
+
return {"error": f"Tests timed out after {timeout}s"}
|
|
365
|
+
except Exception as e:
|
|
366
|
+
return {"error": str(e)}
|
|
367
|
+
|
|
368
|
+
|
|
369
|
+
@mcp.tool()
|
|
370
|
+
def read_file(path: str, limit: int = 200, api_key: str = "") -> dict:
|
|
371
|
+
"""Read contents of a file (restricted to allowed directories: Desktop,
|
|
372
|
+
Documents, Downloads, /tmp, and the sandbox). Returns file content with
|
|
373
|
+
line limit."""
|
|
374
|
+
allowed, msg, tier = check_access(api_key)
|
|
375
|
+
if not allowed:
|
|
376
|
+
return {"error": msg, "upgrade_url": "https://meok.ai/pricing"}
|
|
377
|
+
|
|
378
|
+
err = _check_rate_limit()
|
|
379
|
+
if err:
|
|
380
|
+
return {"error": err}
|
|
381
|
+
|
|
382
|
+
if not path:
|
|
383
|
+
return {"error": "No path provided"}
|
|
384
|
+
|
|
385
|
+
if not _check_path_allowed(path):
|
|
386
|
+
return {"error": "Access denied: path outside allowed directories"}
|
|
387
|
+
|
|
388
|
+
try:
|
|
389
|
+
with open(path, "r") as f:
|
|
390
|
+
lines = []
|
|
391
|
+
for i, line in enumerate(f):
|
|
392
|
+
if i >= limit:
|
|
393
|
+
break
|
|
394
|
+
lines.append(line)
|
|
395
|
+
content = "".join(lines)
|
|
396
|
+
return {
|
|
397
|
+
"content": content,
|
|
398
|
+
"lines": len(lines),
|
|
399
|
+
"truncated": len(lines) >= limit,
|
|
400
|
+
"path": path,
|
|
401
|
+
}
|
|
402
|
+
except Exception as e:
|
|
403
|
+
return {"error": str(e)}
|
|
404
|
+
|
|
405
|
+
|
|
406
|
+
@mcp.tool()
|
|
407
|
+
def list_sandbox_files(api_key: str = "") -> dict:
|
|
408
|
+
"""List files in the sandbox working directory. All code execution
|
|
409
|
+
artifacts are stored here temporarily."""
|
|
410
|
+
allowed, msg, tier = check_access(api_key)
|
|
411
|
+
if not allowed:
|
|
412
|
+
return {"error": msg, "upgrade_url": "https://meok.ai/pricing"}
|
|
413
|
+
|
|
414
|
+
files = []
|
|
415
|
+
for f in SANDBOX_DIR.iterdir():
|
|
416
|
+
if f.is_file():
|
|
417
|
+
stat = f.stat()
|
|
418
|
+
files.append({
|
|
419
|
+
"name": f.name,
|
|
420
|
+
"size": stat.st_size,
|
|
421
|
+
"modified": datetime.fromtimestamp(stat.st_mtime).isoformat(),
|
|
422
|
+
})
|
|
423
|
+
return {
|
|
424
|
+
"sandbox_dir": str(SANDBOX_DIR),
|
|
425
|
+
"files": sorted(files, key=lambda x: x["modified"], reverse=True),
|
|
426
|
+
"count": len(files),
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
|
|
430
|
+
@mcp.tool()
|
|
431
|
+
def get_safety_rules(api_key: str = "") -> dict:
|
|
432
|
+
"""Get the current safety rules and blocked patterns for code execution.
|
|
433
|
+
Useful for understanding what is and isn't allowed."""
|
|
434
|
+
allowed, msg, tier = check_access(api_key)
|
|
435
|
+
if not allowed:
|
|
436
|
+
return {"error": msg, "upgrade_url": "https://meok.ai/pricing"}
|
|
437
|
+
|
|
438
|
+
return {
|
|
439
|
+
"blocked_shell_patterns": BLOCKED_COMMANDS,
|
|
440
|
+
"blocked_python_patterns": BLOCKED_PYTHON,
|
|
441
|
+
"blocked_javascript_patterns": BLOCKED_JS,
|
|
442
|
+
"allowed_file_directories": ALLOWED_DIRS,
|
|
443
|
+
"sandbox_directory": str(SANDBOX_DIR),
|
|
444
|
+
"max_timeout_seconds": 60,
|
|
445
|
+
"max_output_bytes": 10000,
|
|
446
|
+
"supported_languages": ["python", "javascript"],
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
|
|
450
|
+
|
|
451
|
+
@mcp.tool(name="execute_code_docker")
|
|
452
|
+
async def execute_code_docker(code: str, language: str = "python", timeout_sec: int = 30, api_key: str = "") -> str:
|
|
453
|
+
"""Execute code inside a temporary Docker container for isolation."""
|
|
454
|
+
import subprocess, tempfile, os
|
|
455
|
+
allowed, msg, tier = check_access(api_key)
|
|
456
|
+
if not allowed:
|
|
457
|
+
return {"error": msg, "upgrade_url": "https://meok.ai/pricing"}
|
|
458
|
+
|
|
459
|
+
image_map = {"python": "python:3.11-alpine", "node": "node:20-alpine", "bash": "alpine:latest"}
|
|
460
|
+
image = image_map.get(language.lower(), "alpine:latest")
|
|
461
|
+
|
|
462
|
+
with tempfile.NamedTemporaryFile(mode='w', suffix=f'.{language}', delete=False) as f:
|
|
463
|
+
f.write(code)
|
|
464
|
+
tmp_path = f.name
|
|
465
|
+
|
|
466
|
+
try:
|
|
467
|
+
cmd = [
|
|
468
|
+
"docker", "run", "--rm", "-v", f"{tmp_path}:/code/file",
|
|
469
|
+
"--network", "none", "--memory", "128m", "--cpus", "0.5",
|
|
470
|
+
image
|
|
471
|
+
]
|
|
472
|
+
if language.lower() == "python":
|
|
473
|
+
cmd += ["python", "/code/file"]
|
|
474
|
+
elif language.lower() == "node":
|
|
475
|
+
cmd += ["node", "/code/file"]
|
|
476
|
+
else:
|
|
477
|
+
cmd += ["sh", "/code/file"]
|
|
478
|
+
|
|
479
|
+
result = subprocess.run(cmd, capture_output=True, text=True, timeout=timeout_sec)
|
|
480
|
+
return {
|
|
481
|
+
"stdout": result.stdout,
|
|
482
|
+
"stderr": result.stderr,
|
|
483
|
+
"returncode": result.returncode,
|
|
484
|
+
"isolated": True,
|
|
485
|
+
"image": image
|
|
486
|
+
}
|
|
487
|
+
except FileNotFoundError:
|
|
488
|
+
return {"error": "Docker not installed or not in PATH", "isolated": False}
|
|
489
|
+
except subprocess.TimeoutExpired:
|
|
490
|
+
return {"error": f"Execution timed out after {timeout_sec}s", "isolated": True}
|
|
491
|
+
finally:
|
|
492
|
+
os.unlink(tmp_path)
|
|
493
|
+
|
|
494
|
+
if __name__ == "__main__":
|
|
495
|
+
mcp.run()
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
name: code-executor-mcp
|
|
2
|
+
description: MCP server for code executor. Features execute code, run command, run
|
|
3
|
+
tests. From MEOK AI Labs.
|
|
4
|
+
version: 1.0.0
|
|
5
|
+
tools:
|
|
6
|
+
- name: execute_code
|
|
7
|
+
description: Execute code in a sandboxed environment with safety checks.
|
|
8
|
+
parameters:
|
|
9
|
+
- name: code
|
|
10
|
+
type: string
|
|
11
|
+
required: true
|
|
12
|
+
- name: language
|
|
13
|
+
type: string
|
|
14
|
+
required: false
|
|
15
|
+
- name: timeout
|
|
16
|
+
type: integer
|
|
17
|
+
required: false
|
|
18
|
+
- name: run_command
|
|
19
|
+
description: Execute a shell command and return stdout/stderr/exit_code.
|
|
20
|
+
parameters:
|
|
21
|
+
- name: command
|
|
22
|
+
type: string
|
|
23
|
+
required: true
|
|
24
|
+
- name: timeout
|
|
25
|
+
type: integer
|
|
26
|
+
required: false
|
|
27
|
+
- name: run_tests
|
|
28
|
+
description: 'Run a test suite and return results. Default: pytest.'
|
|
29
|
+
parameters:
|
|
30
|
+
- name: test_command
|
|
31
|
+
type: string
|
|
32
|
+
required: false
|
|
33
|
+
- name: working_dir
|
|
34
|
+
type: string
|
|
35
|
+
required: false
|
|
36
|
+
- name: timeout
|
|
37
|
+
type: integer
|
|
38
|
+
required: false
|
|
39
|
+
- name: read_file
|
|
40
|
+
description: 'Read contents of a file (restricted to allowed directories: Desktop,'
|
|
41
|
+
parameters:
|
|
42
|
+
- name: path
|
|
43
|
+
type: string
|
|
44
|
+
required: true
|
|
45
|
+
- name: limit
|
|
46
|
+
type: integer
|
|
47
|
+
required: false
|
|
48
|
+
- name: list_sandbox_files
|
|
49
|
+
description: List files in the sandbox working directory. All code execution
|
|
50
|
+
parameters: []
|
|
51
|
+
- name: get_safety_rules
|
|
52
|
+
description: Get the current safety rules and blocked patterns for code execution.
|
|
53
|
+
parameters: []
|
|
54
|
+
- name: execute_code_docker
|
|
55
|
+
description: Execute code inside a temporary Docker container for isolation.
|
|
56
|
+
parameters:
|
|
57
|
+
- name: code
|
|
58
|
+
type: string
|
|
59
|
+
required: true
|
|
60
|
+
- name: language
|
|
61
|
+
type: string
|
|
62
|
+
required: false
|
|
63
|
+
- name: timeout_sec
|
|
64
|
+
type: integer
|
|
65
|
+
required: false
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import sys
|
|
3
|
+
import unittest
|
|
4
|
+
|
|
5
|
+
# Ensure shared auth middleware is available
|
|
6
|
+
sys.path.insert(0, os.path.expanduser("~/clawd/meok-labs-engine/shared"))
|
|
7
|
+
os.chdir(os.path.dirname(os.path.abspath(__file__)) + "/..")
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class TestMCPImport(unittest.TestCase):
|
|
11
|
+
def test_import_server(self):
|
|
12
|
+
"""Server module must import without errors."""
|
|
13
|
+
import server # noqa: F401
|
|
14
|
+
|
|
15
|
+
def test_mcp_or_server_object_exists(self):
|
|
16
|
+
"""FastMCP servers export 'mcp'; low-level servers export 'server'."""
|
|
17
|
+
import server as srv
|
|
18
|
+
self.assertTrue(
|
|
19
|
+
hasattr(srv, "mcp") or hasattr(srv, "server"),
|
|
20
|
+
"Expected 'mcp' or 'server' object in server.py",
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class TestAuthMiddleware(unittest.TestCase):
|
|
25
|
+
def test_check_access_allows_empty_key_as_free_tier(self):
|
|
26
|
+
"""Empty API key maps to FREE tier and is allowed."""
|
|
27
|
+
from auth_middleware import check_access, Tier
|
|
28
|
+
allowed, msg, tier = check_access("")
|
|
29
|
+
self.assertTrue(allowed)
|
|
30
|
+
self.assertEqual(tier, Tier.FREE)
|
|
31
|
+
self.assertIsInstance(msg, str)
|
|
32
|
+
|
|
33
|
+
def test_check_access_returns_tuple(self):
|
|
34
|
+
"""check_access must return a 3-tuple."""
|
|
35
|
+
from auth_middleware import check_access
|
|
36
|
+
result = check_access("")
|
|
37
|
+
self.assertIsInstance(result, tuple)
|
|
38
|
+
self.assertEqual(len(result), 3)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class TestHealthEndpoint(unittest.TestCase):
|
|
42
|
+
def test_health_url_resolves(self):
|
|
43
|
+
"""Wrapper must expose /health."""
|
|
44
|
+
import urllib.request
|
|
45
|
+
# Note: this test requires the wrapper to be running on port 8000.
|
|
46
|
+
# It is skipped in CI unless the server is active.
|
|
47
|
+
try:
|
|
48
|
+
resp = urllib.request.urlopen("http://localhost:8000/health", timeout=2)
|
|
49
|
+
self.assertEqual(resp.status, 200)
|
|
50
|
+
except Exception as e:
|
|
51
|
+
self.skipTest(f"Server not running: {e}")
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
if __name__ == "__main__":
|
|
55
|
+
unittest.main()
|