Blog

  • Build MCP Servers in Minutes: 5 Easy Steps with FastMCP in Python

    The Model Context Protocol (MCP) is a powerful standard for connecting Large Language Models (LLMs) to external data and tools, acting like a universal bridge for AI interactions. If you’re a Python developer looking to enhance your AI workflows, FastMCP is the go-to library to simplify building MCP servers. In this blog, we’ll walk through setting up a basic MCP server using FastMCP, complete with a practical example to get you started.

    Whether you’re new to MCP or a seasoned developer, this guide will help you create a server that enables LLMs to interact with custom tools and data. Let’s dive in!

    Want to get started quickly?

    If you know python well, and you can “Click” and scroll to “Copy-and-Paste Example” section.

    What is FastMCP?

    FastMCP is a Pythonic, high-level framework that abstracts the complexities of the MCP protocol, such as server setup, protocol handlers, and error management. It allows you to focus on building tools and resources for LLMs using simple Python functions and decorators. Think of it as a way to make your Python code AI-ready with minimal effort.

    What is MCP? The Model Context Protocol (MCP) is a set of rules that lets AI models, like LLMs, connect to external data and tools. Use MCP when you need your AI to:

    • Fetch External Data: Query databases or APIs (e.g., weather updates or sales figures).
    • Run Custom Tools: Execute tasks you’ve programmed, like calculations or file editing.
    • Enhance AI Capabilities: Combine AI with your systems for practical, real-world results.

    For example, MCP can let an AI add two numbers using a tool you’ve built or pull a personalised greeting from a custom resource; similarly, you can create your own tools or integrations to empower AI with unique capabilities tailored to your needs. Even a documentation search MCP?

    Prerequisites

    Before we start, ensure you have:

    • Python 3.7+ installed on your system.
    • A terminal (macOS/Linux) or PowerShell/CMD (Windows).
    • Basic familiarity with Python and virtual environments.
    • (Optional) An MCP-compatible client like Claude Desktop or Cursor for testing.

    Step 1: Install FastMCP

    The recommended way to install FastMCP is using uv, a fast Python package manager that simplifies dependency management. If you’re new to Python, uv is a tool that makes it easy to install libraries (pre-written code) and manage project environments. It’s faster and simpler than traditional tools like pip and virtualenv, combining their features into one command. With uv, you can quickly set up projects and ensure consistent results with minimal hassle.

    If you don’t have uv installed, you can install it via:

    # On macOS/Linux
    curl -LsSf https://astral.sh/uv/install.sh | sh
    
    # On Windows (PowerShell)
    powershell -c "irm https://astral.sh/uv/install.ps1 | iex"
    

    After installing uv, create a project directory and set up a virtual environment:

    mkdir my-mcp-server
    cd my-mcp-server
    uv init
    uv venv
    source .venv/bin/activate  # On Windows: .venv\Scripts\activate

    Now, install FastMCP with the optional CLI tools for debugging:

    uv pip install "mcp[cli]"

    Verify the installation by checking the FastMCP version:

    fastmcp version

    You should see output like:

    FastMCP version: 0.4.2.dev41+ga077727.d20250410
    MCP version: 1.6.0
    Python version: 3.12.2

    Step 2: Create a Simple MCP Server

    Let’s build a basic MCP server with a tool that adds two numbers. Create a file named server.py in your project directory and add the following code:

    from mcp.server.fastmcp import FastMCP
    
    # Initialize the MCP server with a name
    mcp = FastMCP("CalculatorServer")
    
    # Define a tool to add two numbers
    @mcp.tool()
    def add(a: int, b: int) -> int:
        """Add two numbers and return the result."""
        return a + b
    
    # Run the server
    if __name__ == "__main__":
        mcp.run(transport="stdio")

    This code:

    • Imports FastMCP from the MCP library.
    • Creates a server instance named “CalculatorServer”.
    • Defines a tool called add using the @mcp.tool() decorator, which allows an LLM to call this function.
    • Runs the server using the stdio transport, ideal for local testing.

    Step 3: Test the Server with MCP Inspector

    FastMCP includes a handy debugging tool called MCP Inspector, which provides a UI to test your server without connecting to an LLM client. Start the server in development mode:

    uv run mcp dev server.py

    This command launches the server and opens the MCP Inspector in your browser (typically at http://127.0.0.1:6274).

    If it doesn’t open automatically, navigate to that URL. Once loaded:

    1. Click Connect to link to your server.
    2. In the Tools tab, you’ll see the add tool listed.
    3. Click on it, enter values (e.g., a=4, b=3), and select Run Tool to test. You should see the result: 7.

    Step 4: Integrate with an LLM Client (Optional)

    To see your server in action with an LLM, integrate it with an MCP-compatible client like Claude Desktop or Cursor. Here’s how to set it up with Cursor:

    1. Open your project directory in Cursor.
    2. Go to File → Preferences → Cursor Settings → MCP → Add New Server.
    3. Configure the server:
      • Name: “Calculator”
      • Type: Command
      • Command: uv run mcp run /path/to/your/server.py
    4. Save the configuration. A green 🟢 indicator should appear, confirming the server is running.
    5. In Cursor’s chat interface, type: “Add 5 and 3.” The LLM should call your add tool and return 8.

    If you encounter a 🟠 indicator, double-check the file path and ensure the virtual environment is activated.

    Step 5: Expand Your Server

    Now that you have a working server, you can add more tools or resources. For example, let’s add a resource to greet users:

    # Add to server.py
    @mcp.resource("greeting://{name}")
    def get_greeting(name: str) -> str:
        """Return a personalized greeting."""
        return f"Hello, {name}!"
    

    Restart the server with uv run mcp dev server.py, and test the resource in MCP Inspector by accessing greeting://John to see “Hello, John!” You can also call this resource from Cursor by asking, “Get a greeting for John.”

    Copy-and-Paste Example

    Want to get started quickly? Below is a complete, ready-to-run FastMCP server script that includes both the add tool and the greeting resource. Simply click the “Copy” button (or select and copy the code) and paste it into a file named server.py.

    from mcp.server.fastmcp import FastMCP
    
    # Initialize the MCP server
    mcp = FastMCP("MyFirstMCPServer")
    
    # Define a tool to add two numbers
    @mcp.tool()
    def add(a: int, b: int) -> int:
        """Add two numbers and return the result."""
        return a + b
    
    # Define a resource for personalized greetings
    @mcp.resource("greeting://{name}")
    def get_greeting(name: str) -> str:
        """Return a personalized greeting."""
        return f"Hello, {name}!"
    
    # Run the server
    if __name__ == "__main__":
        mcp.run(transport="stdio")
    

    How to Run:

    1. Click the “Copy” button above (or select and copy the code) and save it as server.py in your project directory.
    2. Ensure FastMCP is installed (uv pip install "mcp[cli]").
    3. Activate your virtual environment (source .venv/bin/activate or .venv\Scripts\activate on Windows).
    4. Run the server: uv run mcp dev server.py.
    5. Open http://127.0.0.1:6274 in your browser to test with MCP Inspector. Try the add tool (e.g., a=10, b=20) or the greeting resource (e.g., greeting://Alice).

    This script is a fully functional starting point you can build upon!

    Why Use FastMCP?

    FastMCP simplifies MCP server development with:

    • Minimal Boilerplate: Create tools and resources with just a few lines of code.
    • Pythonic Design: Uses decorators and type hints for a familiar experience.
    • Powerful Features: Supports async functions, OpenAPI integration, and client libraries for advanced use cases.
    • Debugging Tools: MCP Inspector makes testing straightforward.

    Next Steps

    You’ve now set up a basic MCP server with FastMCP! From here, you can:

    • Add more complex tools, like querying APIs or databases (e.g., SQLite or yfinance).
    • Deploy your server to a cloud platform like AWS or Cloudflare.
    • Explore the FastMCP documentation for advanced features like server proxying or LLM sampling.

    To dive deeper, check out the FastMCP GitHub repository or the official MCP Python SDK. Start building smarter AI workflows today!


    Happy coding, and enjoy powering your LLMs with FastMCP!

  • The simplest way to code with Copilot Instructions

    I’ve been exploring the easiest way to kickstart a new page or revamp an existing component using the company’s proprietary design system. The most straightforward approach is to use the design system’s instructions as the foundation, incorporating its documentation directly into the codebase for added context.

    Supercharging Your Development with GitHub Copilot Custom Instructions

    GitHub Copilot has become an indispensable tool for many developers, but did you know you can make it even more powerful by providing custom instructions? As of May 2025, custom instructions have evolved to become one of the most effective ways to tailor Copilot to your specific development needs and standards. In this blog post, I’ll guide you through how to leverage this feature to significantly improve your team’s productivity, especially for frontend development workflows.

    Custom instructions allow you to provide context about your project, coding standards, and preferred libraries directly to GitHub Copilot, resulting in more accurate and useful code suggestions.

    What Are GitHub Copilot Custom Instructions?

    Custom instructions are essentially specialised prompts you give to GitHub Copilot to guide its responses and code suggestions. Think of them as a way to “train” Copilot to understand your project’s specific context, coding standards, and technical preferences without having to repeatedly mention these details in every prompt.

    For example, instead of telling Copilot each time that you prefer using double quotes for JavaScript strings, you can set this preference once in your custom instructions. This context is invisibly added to every interaction you have with Copilot, making its responses more relevant and aligned with your standards.

    There are three main levels of custom instructions:

    1. Personal instructions: Apply to all your interactions with Copilot
    2. Repository instructions: Apply to everyone working with a specific repository
    3. Organisation instructions: Apply to all members of your organisation (for Enterprise users)

    Types of GitHub Copilot Custom Instructions

    Repository Custom Instructions

    Repository-level instructions are stored in a .github/copilot-instructions.md file at the root of your repository. These instructions are automatically applied whenever someone uses Copilot with that repository, ensuring consistent responses across your team.

    This approach is particularly valuable for maintaining coding standards across larger teams. When a new developer joins the project, they automatically get the same Copilot guidance as everyone else, without needing to learn and manually apply the project standards.

    Personal Custom Instructions

    Personal instructions allow individual developers to set their own preferences that will apply across all their GitHub Copilot interactions. These take precedence over repository and organisation instructions.

    To set personal instructions, you can:

    1. Click the Copilot icon in the top right of any GitHub page
    2. Select “Personal instructions” from the dropdown menu
    3. Add your custom instructions in the text box
    4. Click “Save”

    These instructions will follow you across different repositories and projects.

    VS Code-Specific Settings

    In Visual Studio Code, there are additional ways to customise GitHub Copilot through settings. You can set specific instructions for different tasks like code generation, test generation, commit message generation, and more:

    {
      "github.copilot.chat.codeGeneration.instructions": [
        {
          "file": ".copilot-code-instructions.md"
        }
      ],
    }

    Creating and Using Repository Custom Instructions

    Attention: Please verify that you are using the latest versions. The versions tested so far are VS Code Mac 1.100.2 and Copilot 0.27.1.

    Setting Up the Instructions File

    Let’s walk through how to set up repository instructions for a frontend project using the company’s design system:

    1. Create a .github directory at the root of your repository (if it doesn’t already exist)
    2. Create a file named copilot-instructions.md inside the .github directory
    3. Add your custom instructions in Markdown format

    Sample Instructions for Frontend Development with the Company’s Design System

    Here’s an example of what your .github/copilot-instructions.md file might look like for a frontend project using the company’s design system:

    - This is a React project using TypeScript and Vite.
    - Use functional components and React Hooks.
    - Follow ES6+ syntax.
    - Write unit tests using Vitest and React Testing Library.
    - Mock API responses using MSW (Mock Service Worker). Handlers are in `src/mocks/handlers.ts`.
    - Follow ESLint and Prettier rules for code consistency. You can run `yarn lint:fix` to format.
    - Component names should be in PascalCase.
    - UI components are prefixed with the company namespace (e.g., `CompanyButton`, `CompanyInput`).
    - Use the `~/*` path alias to refer to files in the `src` directory (e.g., `import MyComponent from '~/components/MyComponent';`).
    - Access environment variables using `import.meta.env.VITE_VARIABLE_NAME`.
    - Always check for errors and fix them.
    - Do not allow implicit 'any' types in TypeScript. Always specify explicit types where required.
    - Use the documentation in the company’s design system directory for reference.

    With these instructions in place, GitHub Copilot will understand your project context and provide more relevant code suggestions.

    Writing Effective Custom Instructions

    Best Practices

    1. Keep instructions concise and specific: Focus on the most important guidelines that will influence code structure and style.
    2. Use clear, self-contained statements: Each instruction should be a complete thought that can be understood on its own.
    3. Consider repository complexity: For large repositories with diverse components, avoid overly restrictive instructions that might not apply to all areas.
    4. Avoid conflicting instructions: If you have multiple types of instructions (personal, repository, organisation), try to avoid conflicts between them.
    5. Update instructions as your project evolves: As your project grows and standards change, keep your instructions file up to date.

    What to Include

    Your instructions can cover a wide range of aspects:

    • Coding standards and conventions
    • Preferred libraries and frameworks
    • Project-specific context
    • Common patterns used in your codebase
    • Documentation requirements
    • Testing approaches

    Advanced Usage: Specialised Instruction Files

    Beyond the standard .github/copilot-instructions.md file, VS Code also supports more specialised instruction files:

    Task-Specific Instructions

    You can create separate instruction files for different coding tasks. For example:

    {
      "github.copilot.chat.codeGeneration.instructions": [
        {
          "file": "copilot-code-instructions.md"
        }
      ],
      "github.copilot.chat.reviewSelection.instructions": [
        {
          "file": "copilot-review-instructions.md"
        }
      ],
      "github.copilot.chat.testGeneration.instructions": [
        {
          "file": "copilot-test-instructions.md"
        }
      ],
      "github.copilot.chat.pullRequestDescriptionGeneration.instructions": [
        {
          "file": "copilot-test-instructions.md"
        }
      ],
      "github.copilot.chat.commitMessageGeneration.instructions": [
        {
          "file": "copilot-commit-message-instructions.md"
        }
      ]
    }

    Real-World Benefits for Your Team

    Implementing custom instructions for GitHub Copilot offers several tangible benefits:

    1. Consistent Code Quality: Ensures all AI-generated code follows your established standards.
    2. Reduced Onboarding Time: New team members immediately benefit from contextual guidance about your project’s patterns and practices.
    3. Improved Collaboration: Creates alignment across teams by standardizing how Copilot assists different developers.
    4. Time Savings: Reduces the need to repeatedly correct or reformat Copilot suggestions to match your standards.
    5. Knowledge Preservation: Captures important project context and standards that can be maintained over time.

    Conclusion

    GitHub Copilot custom instructions represent a powerful way to tailor AI assistance to your specific development needs. By taking the time to set up well-crafted instructions, you can drastically improve the quality and relevance of Copilot’s suggestions, leading to more efficient workflows and more consistent code.

    For frontend teams working with the company’s design system, custom instructions can ensure that all developers—regardless of their familiarity with the system—can generate code that follows established patterns and best practices.

    I encourage you to start with a simple .github/copilot-instructions.md file in your repository and gradually refine it as you learn what instructions are most effective for your team’s needs. The investment in setting up these instructions will pay dividends in development efficiency and code consistency.

    Remember, the most effective instructions are specific, concise, and regularly updated as your project evolves. Happy coding!