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)
š 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:
- Press
Ctrl + Shift + P
to open Command Palette. - Type
Python: Select Interpreter
and select it. - 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.