Skip to content

Instantly share code, notes, and snippets.

@rajivmehtaflex
Last active December 17, 2024 05:43
Show Gist options
  • Save rajivmehtaflex/574fe97f25c1b9ae7de68c14274eda74 to your computer and use it in GitHub Desktop.
Save rajivmehtaflex/574fe97f25c1b9ae7de68c14274eda74 to your computer and use it in GitHub Desktop.
Steps to set up a fast MCP server using uv

Setting Python 3.12 as Default on macOS Sequoia 15.2

This guide explains how to set Python 3.12 as the default Python version on macOS Sequoia 15.2, so that typing python in the terminal runs Python 3.12. It also covers keeping the ability to call any Python 3.x version using python3.

Understanding the Situation

  • macOS System Python: macOS has a system Python installation at /usr/bin/python, used by the OS and should not be modified.
  • Multiple Python Versions: You likely have multiple Python versions installed, possibly via Homebrew.
  • python vs. python3: Typically, python points to an older version, while python3 specifically calls Python 3. The goal is to have python point to 3.12 while still being able to use python3 for other 3.x versions.

Steps

1. Install Homebrew (if not already installed):

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

2. Install Python 3.12 with Homebrew:

brew install [email protected]

3. Verify Python 3.12 Installation:

python3.12 --version

4. Make Python 3.12 the default python (using symlink):

  • Find the path to the Python 3.12 executable:
     which python3.12
  • Create a symbolic link (replace /opt/homebrew/bin/python3.12 with the actual path obtained above):
    ln -s -f /opt/homebrew/bin/python3.12 /opt/homebrew/bin/python
  • Add Homebrew's bin directory to your system's PATH in ~/.zshrc or ~/.bash_profile
    export PATH=/opt/homebrew/bin:$PATH
* Apply changes:
    ```bash
    source ~/.zshrc  # or source ~/.bash_profile
    ```

5. Verify the Default Python:

python --version

6. Using python3:

You can still use python3 to call explicit versions such as python3.13.

Important Considerations

  • System Python: Avoid modifying the system Python at /usr/bin/python.
  • PATH Variable: Ensure /opt/homebrew/bin is in your PATH before other Python locations.
  • Avoid overriding the system python3 executable: Avoid unlinking the system's default python3 executable and relinking it to the Homebrew version.
  • Alternatives (pyenv): Consider using pyenv for more advanced Python version management.
  • Aliases: You can create aliases like alias python='python3', but it does not change the default executable of the system.

Summary

By following these steps, you can make Python 3.12 the default version when using the python command. Remember to use virtual environments to manage project dependencies.

Setting up a Fast MCP Server with uv

This guide outlines the steps to set up a fast MCP (Modular Control Program) server using uv, along with a basic client setup.

Installation Steps

  1. Install uv:

    curl -LsSf https://astral.sh/uv/install.sh | sh
    • This command downloads and executes the uv installation script.
  2. Set up environment variables:

    source $HOME/.local/bin/env
    • This command sources the environment variables to make uv available in your shell.
  3. Create a project directory:

    mkdir mcp_exp
    • This creates a new directory called mcp_exp to hold your project.
  4. Navigate to the project directory:

    cd mcp_exp/
    • This changes your current directory to the mcp_exp directory.
  5. Initialize a new uv project:

    uv init mm_check
    • This creates a new uv project named mm_check within the mcp_exp directory.
  6. Navigate to the project directory:

    cd mm_check/
    • This changes your current directory to the mm_check project directory.
  7. Add required dependencies:

    uv add mcp "mirascope[openai]"
    • This command adds the mcp and mirascope[openai] dependencies to your project.
  8. Synchronize the project dependencies:

    uv sync
    • This command synchronizes the project's dependencies, installing them into your virtual environment.
  9. Update pyproject.toml:

    • Open the pyproject.toml file in your project directory and ensure it has the following content:
    [project]
    name = "mm-check"
    version = "0.1.0"
    description = "Add your description here"
    readme = "README.md"
    requires-python = ">=3.10"
    dependencies = [
        "mcp>=1.1.2",
        "mirascope[openai]>=1.13.0",
    ]
    
    [build-system]
    requires = ["setuptools>=61.0"]
    build-backend = "setuptools.build_meta"
    
    [project.scripts]
    g-dataops = "g_dataops:main"
    • This step sets up the project metadata, dependencies, and a script entry point.
  10. Implement your server logic:

    • Create a Python file named g_dataops.py (or a module/package with an __init__.py) and implement your MCP server logic using the mcp and mirascope libraries. Ensure that you have a main function as specified in pyproject.toml.
  11. Local testing:

    uv run python -m g_dataops
    • This command runs the g_dataops script for local testing using the uv virtual environment.
  12. Global testing (run from any directory):

    uv --directory /home/user/mcpexpv2/mcp_exp/mm_check run python -m g_dataops
    • This command allows you to run the g_dataops script from any directory by specifying the full path to the project.
    • Note: You need to replace /home/user/mcpexpv2/mcp_exp/mm_check with the actual path to your mm_check project directory.
  13. Set mcp_settings.json:

    • Create a mcp_settings.json file with the following content:
    {
      "g_dataops": {
        "command": "uv",
        "args": [
          "--directory",
          "/Users/rajivmehtapy/Desktop/LLMOps/KB-Test/uv_exp/g_dataops",
          "run",
          "python",
          "-m",
          "g_dataops"
       ]
      }
    }
    • This file configures how the g_dataops script should be executed by the MCP client.
    • Note: You need to replace /Users/rajivmehtapy/Desktop/LLMOps/KB-Test/uv_exp/g_dataops with the actual path to your mm_check project directory.

Notes

  • Ensure that you create the g_dataops.py and implement the main function as specified in pyproject.toml
  • Make sure that the paths in both uv command for global test and mcp_settings.json reflect the actual path to the project on your system.

This guide provides a complete step-by-step process for setting up your MCP server using uv.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment