This project transforms the AI Code Translator into a Model Control Protocol (MCP) server, allowing other applications to interact with the translator through a standardized API. It includes an Astutely chatbot for interactive coding assistance and a vulnerability scanner for code security analysis.
- Code Translation API: Translate code between multiple programming languages
- Translation Feedback: Get detailed feedback on translations
- Astutely Chatbot: Interactive AI assistant for coding help
- Vulnerability Scanner: Detect security issues in code
- User Management: Registration, login, and subscription management
- Authentication: Secure API access with API keys and JWT tokens
- Language Support: Multiple programming languages supported
- Python 3.11 or higher
- Gemini API key
- Clone this repository
- Install dependencies:
pip install -r requirements.txt - Set up your Gemini API key:
set GEMINI_API_KEY=your_api_key_here
Use the provided batch file:
run_mcp_server.bat
Or run directly with Python:
python server.py --host 127.0.0.1 --port 8000
All API endpoints require an API key, which should be provided in the X-API-Key header.
POST /translate
Request body:
{
"source_code": "def hello():\n print('Hello, world!')",
"source_language": "python",
"target_language": "javascript",
"use_neural": false,
"use_llm": true
}Response:
{
"translated_code": "function hello() {\n console.log('Hello, world!');\n}",
"feedback": "The translation correctly converts Python's print function to JavaScript's console.log..."
}POST /feedback
Request body:
{
"source_code": "def hello():\n print('Hello, world!')",
"translated_code": "function hello() {\n console.log('Hello, world!');\n}",
"source_language": "python",
"target_language": "javascript"
}Response:
{
"feedback": "The translation correctly converts Python's print function to JavaScript's console.log..."
}POST /chat
Request body:
{
"message": "How do I implement a binary search in Python?"
}Response:
{
"response": "Here's how you can implement a binary search in Python:..."
}GET /models
GET /languages
Here's a simple Python example of how to use the API:
import requests
API_URL = "http://localhost:8000"
API_KEY = "test_api_key_1"
HEADERS = {"X-API-Key": API_KEY}
# Translate code
def translate_code(source_code, source_lang="python", target_lang="javascript"):
response = requests.post(
f"{API_URL}/translate",
headers=HEADERS,
json={
"source_code": source_code,
"source_language": source_lang,
"target_language": target_lang,
"use_llm": True
}
)
return response.json()
# Example usage
python_code = """
def factorial(n):
if n <= 1:
return 1
return n * factorial(n - 1)
"""
result = translate_code(python_code)
print(f"Translated code:\n{result['translated_code']}")
print(f"\nFeedback:\n{result['feedback']}")This MCP server can be integrated with various tools and platforms:
- IDEs and code editors through plugins
- CI/CD pipelines for automated code conversion
- Learning platforms for educational purposes
- Development tools for cross-language development
The AI Code Translator can be deployed to various hosting platforms. We've provided tools to simplify the deployment process.
Use the provided deploy.py script to set up deployment files for your preferred platform:
python deploy.py --platform render --api-key YOUR_GEMINI_API_KEY --jwt-secret YOUR_JWT_SECRETSupported platforms:
- Render.com
- Heroku
- Netlify
- Create an account at Render.com
- Create a new Web Service
- Connect your GitHub repository
- Set the following:
- Build Command:
pip install -r requirements.txt - Start Command:
gunicorn simple_mcp_server:app
- Build Command:
- Add environment variables:
GEMINI_API_KEYJWT_SECRETSTRIPE_API_KEY(if using payment processing)
- Install the Heroku CLI
- Login to Heroku:
heroku login - Create a new app:
heroku create ai-code-translator - Push your code:
git push heroku main - Set environment variables:
heroku config:set GEMINI_API_KEY=your_key heroku config:set JWT_SECRET=your_secret heroku config:set STRIPE_API_KEY=your_stripe_key
For a professional appearance, consider registering a domain and connecting it to your deployed application. Free domains are available through services like Freenom.
To create a VS Code extension for the AI Code Translator:
- Install Node.js and npm
- Install Yeoman and VS Code Extension Generator:
npm install -g yo generator-code
- Generate a new extension:
yo code
- Implement the extension to connect to your deployed API
- Publish to the VS Code Marketplace:
vsce package vsce publish
Detailed instructions for creating VS Code extensions can be found in the official documentation.
MIT