mcp_using_gguf_model_in_terminal / run_with_claude.py
ankitkushwaha90's picture
Upload 22 files
ba18ff2 verified
#!/usr/bin/env python3
"""
DeepSeek MCP Server for Claude CLI Integration
This script runs the MCP server optimized for Claude CLI usage.
"""
import os
import sys
import json
import logging
from pathlib import Path
def setup_claude_environment():
"""Setup environment variables optimized for Claude CLI"""
# Optimized settings for Claude CLI
os.environ['MCP_GPU_LAYERS'] = '35'
os.environ['MCP_CONTEXT_SIZE'] = '4096'
os.environ['MCP_DEFAULT_MAX_TOKENS'] = '512'
os.environ['MCP_DEFAULT_TEMPERATURE'] = '0.7'
os.environ['MCP_DEFAULT_TOP_P'] = '0.9'
os.environ['MCP_LOG_LEVEL'] = 'INFO'
os.environ['MCP_USE_MLOCK'] = 'true'
os.environ['MCP_LOW_VRAM'] = 'false'
def create_claude_config():
"""Create Claude Desktop configuration"""
config_dir = Path.home() / "AppData" / "Roaming" / "Claude"
config_file = config_dir / "claude_desktop_config.json"
# Create directory if it doesn't exist
config_dir.mkdir(parents=True, exist_ok=True)
# Current directory path
current_dir = Path(__file__).parent.absolute()
config = {
"mcpServers": {
"deepseek-mcp-server": {
"command": "python",
"args": [str(current_dir / "server.py")],
"env": {
"MCP_GPU_LAYERS": "35",
"MCP_CONTEXT_SIZE": "4096",
"MCP_DEFAULT_MAX_TOKENS": "512",
"MCP_DEFAULT_TEMPERATURE": "0.7",
"MCP_LOG_LEVEL": "INFO"
}
}
}
}
# Write configuration
with open(config_file, 'w') as f:
json.dump(config, f, indent=2)
print(f"Claude Desktop configuration created at: {config_file}")
return config_file
def main():
"""Main function to run MCP server for Claude CLI"""
print("Starting DeepSeek MCP Server for Claude CLI...")
# Setup environment
setup_claude_environment()
# Create Claude configuration
config_file = create_claude_config()
print("\nSetup Instructions:")
print("1. Restart Claude Desktop if it's running")
print("2. The MCP server will be automatically available in Claude")
print("3. You can use the following tools:")
print(" - chat: Interactive conversation with DeepSeek")
print(" - generate: Text generation and completion")
print(f"\nConfiguration file: {config_file}")
print("\nServer starting...")
# Import and run the server
try:
from mcp_interface import MCPLLMInterface
from config import config
import asyncio
# Validate configuration
config.validate()
print(f"Model file found: {config.model_path}")
# Create and run interface
interface = MCPLLMInterface(config.model_path)
print("MCP Server ready for Claude CLI!")
asyncio.run(interface.run())
except KeyboardInterrupt:
print("\nServer stopped by user")
except Exception as e:
print(f"Error: {e}")
sys.exit(1)
if __name__ == "__main__":
main()