MCP-Server

Nasreen1717/MCP-Server

3.2

If you are the rightful owner of MCP-Server and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.

The Model Context Protocol (MCP) server is a framework designed to facilitate the development and deployment of AI models and tools using a standardized protocol.

šŸ§‘ā€šŸ’» MCP Project Setup Guide (Using uv, mcp, and uvicorn)

GitHub Link: https://github.com/panaversity/learn-agentic-ai/tree/main/03_ai_protocols/01_mcp/04_fundamental_%20primitives/01_hello_mcp_server


šŸ“ Step 1: Open Terminal

Open your system terminal or integrated terminal in VS Code.


šŸ“‚ Step 2: Create and Enter the Project Folder

uv init hello_mcp
cd hello_mcp

šŸ“¦ Step 3: Install Required Packages

a. Install MCP Package:

uv add mcp

b. Install Uvicorn:

uv add uvicorn

c. Open Project in VS Code:

code .

āš™ļø Step 4: Set the Python Virtual Environment

a. Locate .venv Folder:

  • Right-click on .venv folder and copy full path.

b. Set Python Interpreter in VS Code:

  1. Press Ctrl + Shift + P to open Command Palette.
  2. Type Python: Select Interpreter and select it.
  3. Paste the copied path to activate the environment.

šŸ“ Step 5: Prepare Your main.py File

a. Open main.py

b. Delete all existing code

c. Add the following MCP server code:

from mcp.server.fastmcp import FastMCP

mcp = FastMCP(name="hello-mcp", stateless_http=True)
mcp_app = mcp.streamable_http_app()

šŸš€ Step 6: Run the MCP Server

uv run uvicorn main:mcp_app

Or with port and hot reload:

uv run uvicorn main:mcp_app --port 8000 --reload

āœ… Your MCP server should start successfully. šŸ”— Click the URL shown in the terminal to test the server.


šŸ¤– Step 7: Create and Run a Client Script

a. Stop the Server

  • Press Ctrl + C in the terminal to stop the server.

b. Install requests package:

uv add requests

c. Restart the Server:

uv run uvicorn main:mcp_app

d. Create a new file client.py and add the following code:

import requests

# Define the MCP server URL
url = "http://localhost:8000/mcp/"

# Set the headers to accept JSON and event-stream responses
headers = {
    "Accept": "application/json, text/event-stream",
}

# Create the JSON-RPC request body to list available tools
body = {
    "jsonrpc": "2.0",
    "method": "tools/list",
    "id": 1,
    "params": {},
}

# Send the POST request
response = requests.post(url, headers=headers, json=body)

# Stream and print each line of the response
for line in response.iter_lines():
    if line:
        print(line)

e. Run the Client Script:

uv run client.py

āœ… You should see the list of tools printed line-by-line from the MCP server response.


šŸ Setup Complete — You're now ready to build and test MCP tools!