te

term_mcp_deepseek

A DeepSeek MCP-like Server for Terminal

Publisherterm_mcp_deepseek
Submitted date4/13/2025

Bridging the Gap: A DeepSeek-Powered MCP Prototype for Terminal Interaction

This project showcases a prototype implementation of a server inspired by the Model Context Protocol (MCP), leveraging the DeepSeek API to facilitate seamless interaction between Large Language Models (LLMs) and a terminal environment. It demonstrates how AI assistants can be empowered to:

  • Discover Available Tools: Enumerate the capabilities of the terminal environment.
  • Execute Commands: Invoke shell commands within an active session.
  • Integrate with AI Chat: Utilize a DeepSeek-powered chat interface that interprets special instructions (e.g., CMD: directives) to trigger command execution.

Important Note: This implementation, while embodying the core principles of MCP, is not a fully compliant MCP server as defined by Anthropic. It serves as a proof-of-concept, highlighting the potential of MCP and requiring further development for production-ready deployment. Key areas for improvement include adherence to the JSON-RPC protocol, implementation of real-time updates via Server-Sent Events (SSE), robust session management, and enhanced security measures.

Core Features

  • Interactive Chat Interface: A user-friendly web-based chat client, built with Flask and styled with Tailwind CSS, provides a platform for interacting with the server.
  • DeepSeek API Integration: Leverages the DeepSeek API to generate intelligent responses, enabling the AI to understand user requests and formulate appropriate actions. The AI can instruct the server to execute terminal commands by embedding lines prefixed with CMD:.
  • Persistent Terminal Session: Utilizes the pexpect library to establish and maintain a persistent Bash session, allowing for the execution of shell commands and the capture of their output, which is then relayed back to the client.
  • MCP-Inspired Endpoints: Exposes /mcp/list_tools and /mcp/call_tool endpoints, mimicking the MCP's mechanism for tool discovery and invocation, providing a standardized interface for LLMs to interact with the terminal environment.

Getting Started: A Step-by-Step Guide

Essential Prerequisites

  • Python 3.8 or higher
  • pip (Python package installer)
  • A valid DeepSeek API key

Installation Procedure

  1. Clone the Repository:

    git clone https://github.com/OthmaneBlial/term_mcp_deepseek.git cd term_mcp_deepseek
  2. Create and Activate a Virtual Environment:

    python3 -m venv venv source venv/bin/activate # On Windows, use `venv\Scripts\activate`
  3. Install Dependencies:

    pip install -r requirements.txt
  4. Configure API Key:

    Edit the .env file and replace the placeholder value for DEEPSEEK_API_KEY with your actual DeepSeek API key.

Running the Server

Execute the following command to start the Flask server:

python server.py

Access the chat interface by navigating to http://127.0.0.1:5000 in your web browser.

API Endpoints: A Detailed Overview

Chat Endpoint

  • URL: /chat
  • Method: POST
  • Payload: { "message": "your message here" }
  • Description: This endpoint is the primary interface for interacting with the AI. It accepts user messages, appends them to the conversation history, sends the complete conversation to the DeepSeek API for processing, identifies any command instructions (lines starting with CMD:), executes those commands in the terminal, and returns the AI's response, incorporating the results of the command execution.

MCP-Inspired Endpoints

List Tools

  • URL: /mcp/list_tools
  • Method: POST
  • Response: A JSON payload containing a list of available tools, such as write_to_terminal, read_terminal_output, and send_control_character, along with their descriptions and expected arguments.

Call Tool

  • URL: /mcp/call_tool

  • Method: POST

  • Payload:

    { "name": "tool_name", "arguments": { ... } }
  • Description: This endpoint allows for the direct invocation of a specific tool on the server. The name field specifies the tool to be called, and the arguments field provides the necessary parameters for the tool's execution.

Roadmap: Future Enhancements

  • Protocol Standardization: Transition to JSON-RPC for a more robust and standardized communication protocol, ensuring interoperability and adherence to industry best practices.
  • Real-time Communication: Implement Server-Sent Events (SSE) or WebSockets to enable live streaming of command output, providing users with immediate feedback and a more interactive experience.
  • Session Management and Security: Introduce per-user sessions to isolate user environments and enhance security. Implement robust authentication mechanisms, input sanitization techniques, and comprehensive error handling to protect against potential vulnerabilities.
  • Modular Code Architecture: Further decouple API logic from business logic to improve code maintainability, scalability, and testability. This will facilitate future development and allow for easier integration of new features.

Visit More

View All