# Directory Structure ``` ├── .env.example ├── .gitignore ├── Dockerfile ├── LICENSE ├── mcp_server_deepseek │ ├── config.py │ └── server.py ├── README.md └── requirements.txt ``` # Files -------------------------------------------------------------------------------- /.env.example: -------------------------------------------------------------------------------- ``` DEEPSEEK_API_KEY=your_api_key_here ``` -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- ``` # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] *$py.class # C extensions *.so # Distribution / packaging .Python build/ develop-eggs/ dist/ downloads/ eggs/ .eggs/ lib/ lib64/ parts/ sdist/ var/ wheels/ share/python-wheels/ *.egg-info/ .installed.cfg *.egg MANIFEST # PyInstaller # Usually these files are written by a python script from a template # before PyInstaller builds the exe, so as to inject date/other infos into it. *.manifest *.spec # Installer logs pip-log.txt pip-delete-this-directory.txt # Unit test / coverage reports htmlcov/ .tox/ .nox/ .coverage .coverage.* .cache nosetests.xml coverage.xml *.cover *.py,cover .hypothesis/ .pytest_cache/ cover/ # Translations *.mo *.pot # Django stuff: *.log local_settings.py db.sqlite3 db.sqlite3-journal # Flask stuff: instance/ .webassets-cache # Scrapy stuff: .scrapy # Sphinx documentation docs/_build/ # PyBuilder .pybuilder/ target/ # Jupyter Notebook .ipynb_checkpoints # IPython profile_default/ ipython_config.py # pyenv # For a library or package, you might want to ignore these files since the code is # intended to run in multiple environments; otherwise, check them in: # .python-version # pipenv # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. # However, in case of collaboration, if having platform-specific dependencies or dependencies # having no cross-platform support, pipenv may install dependencies that don't work, or not # install all needed dependencies. #Pipfile.lock # UV # Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control. # This is especially recommended for binary packages to ensure reproducibility, and is more # commonly ignored for libraries. #uv.lock # poetry # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. # This is especially recommended for binary packages to ensure reproducibility, and is more # commonly ignored for libraries. # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control #poetry.lock # pdm # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. #pdm.lock # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it # in version control. # https://pdm.fming.dev/latest/usage/project/#working-with-version-control .pdm.toml .pdm-python .pdm-build/ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm __pypackages__/ # Celery stuff celerybeat-schedule celerybeat.pid # SageMath parsed files *.sage.py # Environments .env .venv env/ venv/ ENV/ env.bak/ venv.bak/ # Spyder project settings .spyderproject .spyproject # Rope project settings .ropeproject # mkdocs documentation /site # mypy .mypy_cache/ .dmypy.json dmypy.json # Pyre type checker .pyre/ # pytype static type analyzer .pytype/ # Cython debug symbols cython_debug/ # PyCharm # JetBrains specific template is maintained in a separate JetBrains.gitignore that can # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore # and can be added to the global gitignore or merged into this file. For a more nuclear # option (not recommended) you can uncomment the following to ignore the entire idea folder. #.idea/ # PyPI configuration file .pypirc .vscode ``` -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- ```markdown # MCP Server for Deepseek Integration This repository contains a Model Control Protocol (MCP) server implementation that allows Claude Desktop to use Deepseek models running in Docker. ## Prerequisites - Docker - Python 3.11 or later - A Deepseek API key - Claude Desktop ## Installation 1. Clone the repository: ```bash git clone https://github.com/vincentf305/mcp-server-deepseek.git cd mcp-server-deepseek ``` 2. Install dependencies: ```bash pip install -r requirements.txt ``` ## Setup Environment Variables Create a `.env` file in the root directory of the project and add the following environment variable: ``` DEEPSEEK_API_KEY=your_api_key_here ``` Make sure to replace `your_api_key_here` with your actual Deepseek API key. ## Running the Server ### Using Docker 1. Build the Docker image: ```bash docker build -t mcp_server_deepseek . ``` 2. Run the container: ```bash docker run -d \ --name mcp-server-deepseek \ -p 8765:8765 \ -e DEEPSEEK_API_KEY=your_api_key_here \ mcp-server-deepseek ``` ### Running Locally ```bash python -m mcp_server_deepseek.server ``` ## Usage with Claude Desktop 1. Ensure you have a Deepseek API key 2. Add the following to your Claude Desktop configuration (claude_desktop_config.json): ```json { "mcpServers": { "deepseek-server": { "command": "docker", "args": [ "run", "-i", "--rm", "-e", "DEEPSEEK_API_KEY", "mcp_server_deepseek" ], "env": { "DEEPSEEK_API_KEY": "your_api_key_here" } } } } ``` 3. Restart Claude Desktop to load the new configuration ## Contributing 1. Fork the repository 2. Create your feature branch (`git checkout -b feature/amazing-feature`) 3. Commit your changes (`git commit -m 'Add some amazing feature'`) 4. Push to the branch (`git push origin feature/amazing-feature`) 5. Create a Pull Request ## License MIT License - see the [LICENSE](LICENSE) file for details ``` -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- ``` requests==2.31.0 pydantic==2.10.6 pydantic-settings==2.7.1 mcp>=0.9.1 ``` -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- ```dockerfile FROM python:3.13-slim WORKDIR /app COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt COPY mcp_server_deepseek/ ./mcp_server_deepseek/ EXPOSE 3000 CMD ["python", "-m", "mcp_server_deepseek.server"] ``` -------------------------------------------------------------------------------- /mcp_server_deepseek/config.py: -------------------------------------------------------------------------------- ```python from pydantic_settings import BaseSettings class Settings(BaseSettings): deepseek_base_url: str = "https://api.deepseek.com" deepseek_api_key: str = "" class Config: env_file = ".env" env_file_encoding = "utf-8" settings = Settings() ``` -------------------------------------------------------------------------------- /mcp_server_deepseek/server.py: -------------------------------------------------------------------------------- ```python import asyncio import click import json import logging import requests import sys import mcp import mcp.types as types from mcp.server import Server, NotificationOptions from mcp.server.models import InitializationOptions from .config import settings logging.basicConfig(level=logging.DEBUG) logger = logging.getLogger(__name__) def serve() -> Server: server = Server("deepseek-server") @server.list_tools() async def handle_list_tools() -> list[types.Tool]: return [ types.Tool( name="ask-deepseek", description="Generate responses using the Deepseek model", inputSchema={ "type": "object", "properties": { "messages": { "type": "array", "items": { "type": "object", "properties": { "role": {"type": "string", "enum": ["user", "assistant", "system"]}, "content": {"type": "string"} }, "required": ["role", "content"] } }, "model": {"type": "string", "default": "deepseek-coder", "enum": ["deepseek-coder", "deepseek-chat"]}, "temperature": {"type": "number", "default": 0.7, "minimum": 0, "maximum": 2}, "max_tokens": {"type": "integer", "default": 500, "minimum": 1, "maximum": 4000}, "top_p": {"type": "number", "default": 1.0, "minimum": 0, "maximum": 1}, "stream": {"type": "boolean", "default": False} }, "required": ["messages"] } ) ] @server.call_tool() async def handle_tool_call(name: str, arguments: dict | None) -> list[types.TextContent]: try: if not arguments: raise ValueError("No arguments provided") if name == "ask-deepseek": messages = arguments["messages"] model = arguments.get("model", "deepseek-coder") temperature = arguments.get("temperature", 0.7) max_tokens = arguments.get("max_tokens", 500) top_p = arguments.get("top_p", 1.0) stream = arguments.get("stream", False) deepseek_request = { "model": model, "messages": messages, "temperature": temperature, "max_tokens": max_tokens, "top_p": top_p, "stream": stream } json_data = json.dumps(deepseek_request) response = requests.post( f"{settings.deepseek_base_url}/v1/chat/completions", headers={ "Authorization": f"Bearer {settings.deepseek_api_key}", "Content-Type": "application/json" }, data=json_data ) response.raise_for_status() data = response.json() chat_response = data["choices"][0]["message"]["content"] return [types.TextContent(type="text", text=chat_response)] raise ValueError(f"Unknown tool: {name}") except Exception as e: logger.error(f"Tool call failed: {str(e)}") return [types.TextContent(type="text", text=f"Error: {str(e)}")] return server @click.command() def main(): try: async def _run(): async with mcp.server.stdio.stdio_server() as (read_stream, write_stream): server = serve() await server.run( read_stream, write_stream, InitializationOptions( server_name="deepseek-server", server_version="0.1.0", capabilities=server.get_capabilities( notification_options=NotificationOptions(), experimental_capabilities={} ) ) ) asyncio.run(_run()) except KeyboardInterrupt: logger.info("Server stopped by user") except Exception as e: logger.exception("Server failed") sys.exit(1) if __name__ == "__main__": main() ```