MCP Server with Local LLM

MCP Server with Local LLM

Integrates local language models (like Qwen3-8B) with MCP clients, providing tools for chat, code analysis, text generation, translation, and content summarization using your own hardware.

Category
访问服务器

README

MCP Server with Local LLM

A Model Context Protocol (MCP) server that integrates with your local Large Language Model, providing tools and resources that can be used by MCP-compatible clients like Claude Desktop, IDEs, and other AI assistants.

Features

  • Local LLM Integration: Uses your local language model (default: Qwen3-8B) for all operations
  • MCP-Compatible: Implements the Model Context Protocol specification
  • Multiple Tools: Provides various tools for different use cases
  • Resource Access: Exposes model information and conversation history
  • Memory Efficient: Uses 4-bit quantization for optimal performance

Available Tools

1. chat_with_llm

Basic chat interface with the local LLM.

Parameters:

  • message (required): The message to send to the LLM
  • system_prompt (optional): System prompt to guide behavior
  • temperature (optional): Temperature for generation (0-1, default: 0.7)
  • max_tokens (optional): Maximum tokens to generate (default: 512)

2. analyze_code

Analyze and review code using the local LLM.

Parameters:

  • code (required): The code to analyze
  • language (optional): Programming language
  • analysis_type (optional): Type of analysis (review, explain, optimize, debug)

3. generate_text

Generate text content in various styles and lengths.

Parameters:

  • prompt (required): The prompt for text generation
  • style (optional): Writing style (formal, casual, technical, creative)
  • length (optional): Desired length (short, medium, long)

4. translate_text

Translate text between languages.

Parameters:

  • text (required): Text to translate
  • target_language (required): Target language
  • source_language (optional): Source language (auto-detect if not provided)

5. summarize_content

Summarize content in different formats.

Parameters:

  • content (required): Content to summarize
  • summary_type (optional): Type of summary (brief, detailed, bullet_points)
  • max_length (optional): Maximum length in words (default: 150)

Available Resources

1. llm://model/info

Information about the loaded local LLM model.

2. llm://conversations/history

History of conversations with the LLM.

3. llm://system/status

Current system status and resource usage.

Installation

  1. Clone or download this repository to your local machine.

  2. Install dependencies:

    pip install -r requirements.txt
    
  3. Set up environment variables (create a .env file):

    MODEL_NAME=Qwen/Qwen3-8B
    MAX_NEW_TOKENS=512
    TEMPERATURE=0.7
    
  4. Ensure you have sufficient hardware:

    • GPU with at least 8GB VRAM (recommended)
    • 16GB+ system RAM
    • CUDA-compatible GPU (for optimal performance)

Usage

Running the Server

  1. Start the MCP server:

    python mcp_server.py
    
  2. The server will:

    • Load the specified model (Qwen3-8B by default)
    • Initialize the MCP server
    • Wait for JSON-RPC requests via stdin/stdout

Integrating with Claude Desktop

To use this server with Claude Desktop, add it to your MCP configuration:

  1. Create or edit your Claude Desktop MCP configuration file:

    • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
    • Windows: %APPDATA%\Claude\claude_desktop_config.json
  2. Add the server configuration:

    {
      "mcpServers": {
        "local-llm": {
          "command": "python",
          "args": ["/Users/sazzad/Documents/mcp-server/mcp_server.py"],
          "env": {
            "MODEL_NAME": "Qwen/Qwen3-8B"
          }
        }
      }
    }
    
  3. Restart Claude Desktop to load the new server.

Example Usage in Claude Desktop

Once configured, you can use the tools in Claude Desktop:

Please use the local LLM to analyze this Python code:

Claude will then use the analyze_code tool to get analysis from your local LLM.

Configuration

Environment Variables

  • MODEL_NAME: HuggingFace model name (default: "Qwen/Qwen3-8B")
  • MAX_NEW_TOKENS: Maximum tokens to generate (default: 512)
  • TEMPERATURE: Default temperature for generation (default: 0.7)

Supported Models

This server works with most HuggingFace transformers models that support:

  • Chat templates
  • 4-bit quantization via BitsAndBytesConfig
  • Causal language modeling

Popular choices:

  • Qwen/Qwen3-8B (default)
  • microsoft/DialoGPT-medium
  • meta-llama/Llama-2-7b-chat-hf
  • mistralai/Mistral-7B-Instruct-v0.1

Hardware Requirements

Minimum Requirements

  • 8GB RAM
  • 4GB GPU VRAM (with 4-bit quantization)
  • 10GB disk space (for model storage)

Recommended Requirements

  • 16GB+ RAM
  • 8GB+ GPU VRAM
  • CUDA-compatible GPU
  • SSD storage for faster model loading

Troubleshooting

Common Issues

  1. Out of Memory Error:

    • Reduce MAX_NEW_TOKENS
    • Use a smaller model
    • Ensure 4-bit quantization is working
  2. Model Loading Fails:

    • Check internet connection for initial download
    • Verify model name is correct
    • Ensure sufficient disk space
  3. CUDA Errors:

    • Update CUDA drivers
    • Check GPU compatibility
    • Fall back to CPU if needed

Performance Optimization

  1. Use GPU acceleration:

    pip install torch --index-url https://download.pytorch.org/whl/cu118
    
  2. Enable Flash Attention (if compatible):

    pip install flash-attn
    
  3. Adjust batch size and sequence length based on your hardware.

Development

Project Structure

mcp-server/
├── mcp_server.py          # Main MCP server implementation
├── mcp-server.py          # Legacy FastAPI server (keep for reference)
├── requirements.txt       # Python dependencies
├── mcp/                   # MCP protocol implementation
│   ├── __init__.py
│   ├── server.py         # MCP server base
│   └── types.py          # MCP protocol types
├── .env                  # Environment variables (create this)
└── README.md            # This file

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Test thoroughly
  5. Submit a pull request

License

MIT License - see LICENSE file for details.

Support

For issues and questions:

  1. Check the troubleshooting section
  2. Review the configuration
  3. Open an issue on GitHub

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选