💻

MCP Server and Client Setup Guide

Apr 23, 2025

MCP Server and Client Implementation on Linux

Introduction

  • Purpose of MCP: MCP aids the creation of agents and workflows using Large Language Models (LLMs).
  • Integration: MCP offers pre-configured integrations for LLMs to connect to data and tools.
  • Implementation Environment: Server and client implementation using Visual Studio Code with DevContainer on Linux (Debian).
  • GitHub Repository: MCP-Server-and-client-Implementation-on-Linux

Project Structure

  • Two directories with separate Python environments for server and client.
    • mcp_server_explore
    • mcp_client_explore

Setup Instructions

MCP Server Setup

  1. Create Directory:
    • uv init mcp_server_explore
    • Navigate: cd mcp_server_explore
  2. Virtual Environment:
    • Create and activate: uv venv
    • source .venv/bin/activate
  3. Install Dependencies:
    • uv add "mcp[cli]"
  4. Create Server File:
    • touch mcp_server_explore.py

MCP Client Setup

  1. Create Directory:
    • uv init mcp_client_explore
    • Navigate: cd mcp_client_explore
  2. Virtual Environment:
    • Create and activate: uv venv
    • source .venv/bin/activate
  3. Install Dependencies:
    • uv add mcp python-dotenv anthropic
  4. Create Client File:
    • touch mcp_client_explore.py

MCP Server Implementation

  • Tools Provided:
    • add_numbers: Adds two integers.
    • multiply_numbers: Multiplies two integers.
  • Server Initialization:
    • FastMCP server is initialized with FastMCP("Explore the MCP").
    • Server execution: mcp.run(transport='stdio')

MCP Client Implementation

  • Client Initialization:
    • Utilizes ClientSession, StdioServerParameters, and Anthropic.
  • Server Connection:
    • Connects to MCP server script (.py or .js files).
    • Lists available server tools.
  • Query Processing:
    • Sends queries to Claude (LLM) and evaluates which tools to utilize.
    • Executes tool calls and manages responses.
  • Interactive Chat Loop:
    • Allows user queries and tool responses until 'quit'.

Behind the Scenes

  • Query Submission:
    • Tools (addition and multiplication) are listed by the client.
    • Queries are sent to Claude with tool descriptions.
    • Claude selects tools to use.
    • Tools are executed through the server, results sent to Claude.
    • Claude returns a natural language response.

Running the Application

  • Commands:
    • Navigate: cd mcp_client_explore
    • Activate environment: source .venv/bin/activate
    • Run: uv run mcp_client_explore.py /workspaces/vsc_dev_mcp_explore/mcp_server_explore/mcp_server_explore.py