Skip to content

Commit 8255000

Browse files
committed
add mcp server
1 parent ff6c589 commit 8255000

File tree

9 files changed

+1551
-0
lines changed

9 files changed

+1551
-0
lines changed

.gitignore

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Python bytecode
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# Distribution / packaging
7+
dist/
8+
build/
9+
*.egg-info/
10+
*.egg
11+
12+
# Virtual environments
13+
venv/
14+
env/
15+
ENV/
16+
17+
# Testing
18+
.pytest_cache/
19+
.coverage
20+
htmlcov/
21+
22+
# Logs
23+
*.log
24+
25+
# IDE specific files
26+
.idea/
27+
.vscode/
28+
*.swp
29+
*.swo
30+
31+
# OS specific files
32+
.DS_Store
33+
Thumbs.db
34+
35+
# Configuration files with sensitive information
36+
asterisk-config.json

README.md

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
# Asterisk MCP Server
2+
3+
A Model Context Protocol (MCP) server that provides security scanning capabilities for code snippets, codebases, and verification of code changes.
4+
5+
## Overview
6+
7+
Asterisk MCP Server is a middleware component that connects to the Asterisk security API to provide real-time security analysis of code. It implements the Model Context Protocol (MCP) to expose security scanning tools to AI assistants like Claude, enabling them to analyze code for security vulnerabilities.
8+
9+
## Architecture
10+
11+
```mermaid
12+
flowchart LR
13+
IDE["IDE / Code Editor"] <--> |MCP Protocol| MCP["Asterisk MCP Server"]
14+
MCP <--> |HTTP/HTTPS| API["Asterisk Vulnerability Scanner API"]
15+
16+
classDef primary fill:#6696FF,stroke:#333,stroke-width:1px,color:white;
17+
classDef secondary fill:#45556B,stroke:#333,stroke-width:1px,color:white;
18+
classDef tertiary fill:#FFCC00,stroke:#333,stroke-width:1px,color:black;
19+
20+
class IDE primary;
21+
class MCP secondary;
22+
class API tertiary;
23+
```
24+
25+
## Features
26+
27+
- **Code Snippet Scanning**: Analyze individual code snippets for security vulnerabilities
28+
- **Codebase Scanning**: Scan multiple files for security issues
29+
- **Change Verification**: Verify if code changes introduce security vulnerabilities
30+
- **Beautiful Settings UI**: Configure the server through a graphical interface
31+
- **Flexible Transport**: Support for stdio and SSE transport protocols
32+
- **Comprehensive Logging**: Detailed logging with configurable verbosity
33+
34+
## Requirements
35+
36+
- Python 3.7+
37+
- pipx
38+
- httpx
39+
- mcp[cli]
40+
- dearpygui (for settings UI)
41+
42+
## Usage
43+
```
44+
{
45+
"mcpServers": {
46+
"asterisk-mcp": {
47+
"command": "pipx run asterisk-mcp-server",
48+
"args": [
49+
"--api-url",
50+
"http://api.mcp.asterisk.so",
51+
"--transport",
52+
"stdio",
53+
"--key",
54+
"YOUR_API_KEY"
55+
],
56+
}
57+
}
58+
}
59+
```
60+
61+
### Configuration
62+
63+
Configuration can be provided through command-line arguments or the settings UI:
64+
65+
#### API Server Settings
66+
67+
- `--api-url`: Base URL for the Asterisk API server
68+
- `--key`: API key for authentication (required for API access)
69+
- `--timeout`: Timeout for API requests in seconds (0 for no timeout)
70+
71+
#### MCP Server Settings
72+
73+
- `--server-name`: Name of the MCP server
74+
- `--transport`: Transport protocol for the MCP server (stdio or sse)
75+
- `--port`: Port for the SSE server (used with --transport sse)
76+
77+
#### Logging Settings
78+
79+
- `--log-level`: Logging level (DEBUG, INFO, WARNING, ERROR, CRITICAL)
80+
- `--no-console`: Disable console output (only log to file)
81+
82+
## Available Tools
83+
84+
### scan_snippet
85+
86+
Scans individual code snippets for security vulnerabilities.
87+
88+
### scan_codebase
89+
90+
Scans multiple files for security issues.
91+
92+
### verify
93+
94+
Verifies if code changes introduce security vulnerabilities.
95+
96+
### settings
97+
98+
Opens the settings UI when the user enters "/asterisk".
99+
100+
## Data Flow
101+
102+
1. The IDE or code editor sends a request to the Asterisk MCP Server using the MCP protocol
103+
2. The MCP server processes the request and forwards it to the Asterisk Vulnerability Scanner API
104+
3. The API analyzes the code and returns security findings
105+
4. The MCP server formats the results and returns them to the IDE/editor
106+
5. The IDE/editor presents the security analysis to the user
107+
108+
## Troubleshooting
109+
110+
### Connection Issues
111+
112+
- Verify that the API URL is correct and accessible
113+
- Check that your API key is valid and has not expired
114+
- Ensure your network allows connections to the API server
115+
116+
### Authentication Errors
117+
118+
- Verify your API key is correctly set in the configuration
119+
- Check that your API key has the necessary permissions
120+
- Regenerate your API key from the dashboard if necessary
121+
122+
### Timeout Errors
123+
124+
- Increase the API timeout setting for large codebases
125+
- Consider analyzing smaller portions of code separately
126+
- Check your network connection stability
127+
128+
## License
129+
130+
This project is licensed under the Apache License, Version 2.0. See the LICENSE file in the repository for the full license text.
131+
132+
## Getting Help
133+
134+
- We're here to help! Reach out to us for any additional questions or assistance you might need at [hello@asterisk.so](hello@asterisk.so).
135+
- Get your API key from [https://app.mcp.asterisk.so](https://app.mcp.asterisk.so)

asterisk_mcp_server/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
"""Asterisk MCP Server package."""
2+
3+
__version__ = "0.1.0"

asterisk_mcp_server/cli.py

Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
#!/usr/bin/env python3
2+
3+
"""Command-line interface for Asterisk MCP Server.
4+
5+
This module provides the command-line interface for the Asterisk MCP Server.
6+
"""
7+
8+
import argparse
9+
import logging
10+
import sys
11+
12+
from asterisk_mcp_server import __version__
13+
from asterisk_mcp_server.server import AsteriskMCPMiddleware, Config, configure_logging
14+
from asterisk_mcp_server.ui.settings import SettingsUI
15+
16+
17+
def parse_args():
18+
"""
19+
Parse command-line arguments for the MCP server.
20+
21+
Returns:
22+
Parsed arguments
23+
"""
24+
parser = argparse.ArgumentParser(
25+
description="Asterisk MCP: Standalone Middleware MCP Server",
26+
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
27+
)
28+
29+
# API server settings
30+
api_group = parser.add_argument_group("API Server Settings")
31+
api_group.add_argument(
32+
"--api-url", type=str, default=None, help="Base URL for the API server"
33+
)
34+
api_group.add_argument(
35+
"--key",
36+
type=str,
37+
default=None,
38+
help="API key for authentication (REQUIRED for API access)",
39+
)
40+
api_group.add_argument(
41+
"--timeout",
42+
type=float,
43+
default=None,
44+
help="Timeout for API requests in seconds (0 for no timeout)",
45+
)
46+
47+
# Server settings
48+
server_group = parser.add_argument_group("MCP Server Settings")
49+
server_group.add_argument(
50+
"--server-name", type=str, default=None, help="Name of the MCP server"
51+
)
52+
server_group.add_argument(
53+
"--transport",
54+
type=str,
55+
choices=["stdio", "sse"],
56+
default=None,
57+
help="Transport protocol for the MCP server",
58+
)
59+
server_group.add_argument(
60+
"--port",
61+
type=int,
62+
default=None,
63+
help="Port for the SSE server (used with --transport sse)",
64+
)
65+
66+
# Logging settings
67+
logging_group = parser.add_argument_group("Logging Settings")
68+
logging_group.add_argument(
69+
"--log-level",
70+
type=str,
71+
choices=["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"],
72+
default=None,
73+
help="Logging level",
74+
)
75+
logging_group.add_argument(
76+
"--no-console",
77+
action="store_true",
78+
help="Disable console output (only log to file)",
79+
)
80+
81+
# Version
82+
parser.add_argument(
83+
"--version", action="version", version=f"%(prog)s {__version__}"
84+
)
85+
86+
# Examples
87+
examples = parser.add_argument_group("Examples")
88+
examples.add_argument("--example", action="store_true", help=argparse.SUPPRESS)
89+
# Add example usage
90+
examples = """
91+
Examples:
92+
# Start with API key (recommended)
93+
asterisk-mcp --api-url https://api.asteriskmcp.com --key YOUR_API_KEY
94+
95+
# Use sse transport instead of stdio
96+
asterisk-mcp --api-url https://api.asteriskmcp.com --key YOUR_API_KEY --transport sse --port 8080
97+
98+
# Increase logging verbosity
99+
asterisk-mcp --api-url https://api.asteriskmcp.com --key YOUR_API_KEY --log-level DEBUG
100+
101+
# Use saved configuration
102+
asterisk-mcp
103+
104+
# Open settings UI
105+
asterisk-mcp --settings
106+
"""
107+
parser.epilog = examples
108+
109+
# Add settings flag
110+
parser.add_argument("--settings", action="store_true", help="Open settings UI")
111+
112+
args = parser.parse_args()
113+
114+
# Convert timeout of 0 to None (no timeout)
115+
if args.timeout == 0:
116+
args.timeout = None
117+
118+
return args
119+
120+
121+
def main():
122+
"""Main entry point for the MCP server."""
123+
args = parse_args()
124+
125+
# Load configuration
126+
config = Config()
127+
128+
# Update config with CLI arguments if provided
129+
updates = {}
130+
if args.api_url is not None:
131+
updates["api_url"] = args.api_url
132+
if args.key is not None:
133+
updates["api_key"] = args.key
134+
if args.timeout is not None:
135+
updates["api_timeout"] = args.timeout
136+
if args.server_name is not None:
137+
updates["server_name"] = args.server_name
138+
if args.transport is not None:
139+
updates["transport"] = args.transport
140+
if args.port is not None:
141+
updates["port"] = args.port
142+
if args.log_level is not None:
143+
updates["log_level"] = args.log_level
144+
if args.no_console:
145+
updates["no_console"] = True
146+
147+
if updates:
148+
config.update(**updates)
149+
150+
# Open settings UI if requested
151+
if args.settings:
152+
ui = SettingsUI(config)
153+
ui.run()
154+
return
155+
156+
# Configure logging
157+
configure_logging(config.get("log_level"), config.get("no_console"))
158+
159+
# Validate required parameters
160+
if not config.get("api_url"):
161+
logging.error(
162+
"API URL is required. Use --api-url to specify the API server URL or configure it in settings."
163+
)
164+
sys.exit(1)
165+
166+
if not config.get("api_key"):
167+
logging.warning(
168+
"⚠️ No API key provided. Authentication will fail for API requests."
169+
)
170+
logging.warning(
171+
"📝 Get your API key from the dashboard at https://dashboard.asteriskmcp.com"
172+
)
173+
logging.warning(
174+
"🔑 Then run with: asterisk-mcp --api-url <URL> --key <YOUR_API_KEY>"
175+
)
176+
177+
# Create and run the MCP server
178+
try:
179+
mcp_server = AsteriskMCPMiddleware(config=config)
180+
181+
logging.info(
182+
f"Starting MCP server on port {config.get('port')} with {config.get('transport')} transport"
183+
)
184+
mcp_server.run(transport=config.get("transport"), port=config.get("port"))
185+
except Exception as e:
186+
logging.error(f"Error starting MCP server: {str(e)}")
187+
sys.exit(1)
188+
189+
190+
if __name__ == "__main__":
191+
main()

0 commit comments

Comments
 (0)