A full-stack application that demonstrates how to create a Model Context Protocol (MCP) server with authentication, a React frontend, and a Python backend with SQLite database.
https://www.loom.com/share/12b6eeecdc404862a03cf5c804315aaa?sid=d9a7c09c-4356-4092-8fc8-3a1b6123e071
This project consists of three main components:
- Backend: Python FastMCP server with SQLite database
- Frontend: React application with Stytch authentication
- External Services: Stytch for authentication, ngrok for tunneling
- Python 3.13+
- Node.js 18+
- ngrok CLI tool
- Stytch account and project
cd backend
uv sync # Install Python dependencies
uv run python main.pycd frontend
npm install
npm run devngrok http 8000The backend is built using FastMCP, a framework for creating MCP servers with built-in authentication support.
- FastMCP Server: Implements the Model Context Protocol
- SQLite Database: Stores user notes with SQLAlchemy ORM
- JWT Authentication: Uses Stytch for secure user authentication
- CORS Support: Configured for cross-origin requests
class Note(Base):
__tablename__ = 'notes'
id = Column(Integer, primary_key=True, index=True)
user_id = Column(String, index=True, nullable=False)
title = Column(String, nullable=False)
content = Column(Text, nullable=False)get_my_notes(): Retrieve all notes for the authenticated useradd_note(title, content): Create a new notedelete_note(note_id): Remove a note by ID
fastmcp>=2.10.6: MCP server frameworksqlalchemy>=2.0.42: Database ORMstytch>=13.12.0: Authentication servicedotenv>=0.9.9: Environment variable managementpython-jose>=3.5.0: Jwt token unloading
The frontend is a React application built with Vite that provides a user interface for authentication and note management.
- Stytch Authentication: password-based login
- Responsive Design: Centered layout with modern styling
- Protected Routes: Authentication-based access control
- Password-based authentication
- Note: need to set redirect urls with Stytch if using Magic link or Oauth authentication
@stytch/react: Stytch React SDKreact: React frameworkvite: Build tool and dev server
-
Create Stytch Project
- Sign up at stytch.com
- Create a new project
- Note your Project ID, Secret and Domain
-
Configure Frontend SDK
- Go to Frontend SDK in Stytch dashboard
- Enable SDK in test mode
- Add authorized domains (e.g.,
http://localhost:5173for development)
-
Environment Variables Create a
.envfile in the backend directory:STYTCH_DOMAIN=https://your-project.stytch.com STYTCH_PROJECT_ID=your-project-id
-
OAuth Configuration
- Configure OAuth providers (Google, Facebook)
- Set redirect URLs for login/signup
- Enable dynamic client registration
ngrok creates a secure tunnel to your local server, making it accessible from the internet.
-
Install ngrok
# macOS brew install ngrok # Or download from https://ngrok.com/
-
Start Tunnel
ngrok http 8000
-
Use Tunnel URL
- Copy the HTTPS URL provided by ngrok
- Add
/mcpto the URL when configuring Claude - Example:
https://abc123.ngrok-free.app/mcp
To connect Claude to your MCP server:
- Start Backend:
uv run python main.py - Start ngrok:
ngrok http 8000 - Add MCP Server in Claude:
claude mcp add --transport http --url https://your-ngrok-url.ngrok-free.app/mcp
- Authentication with Claude: 'claude' then run /mcp to authenticate
MCP_Server_Creation/
βββ backend/
β βββ main.py # FastMCP server entry point
β βββ database.py # Database models and repository
β βββ pyproject.toml # Python dependencies
β βββ notes.db # SQLite database file
βββ frontend/
β βββ src/
β β βββ App.jsx # Main React component
β β βββ main.jsx # React entry point
β βββ package.json # Node.js dependencies
β βββ vite.config.js # Vite configuration
βββ README.md # This file
-
Backend Development
- Make changes to
main.pyordatabase.py - Restart the server:
uv run python main.py
- Make changes to
-
Frontend Development
- Make changes to React components
- Vite will hot-reload automatically
-
Testing MCP Integration
- Ensure backend is running
- Ensure ngrok tunnel is active
- Test MCP tools through Claude
- Localhost Limitation: Claude Code doesn't support localhost MCP servers, ngrok can help redirect an external uri to a local port
- ngrok Required: Always use ngrok for external access during development
- Stytch Configuration: Ensure authorized domains match your development URLs
- Environment Variables: Keep
.envfile secure and either never commit to version control OR remove secrets before committing
- Import Errors: Ensure all dependencies are installed with
uv sync - Authentication Failures: Check Stytch project configuration and environment variables
- CORS Errors: Verify CORS middleware configuration in backend
- ngrok Connection Issues: Ensure backend is running on port 8000 before starting ngrok
- Check Stytch documentation: docs.stytch.com
- FastMCP documentation: github.com/fastmcp/fastmcp
- ngrok documentation: ngrok.com/docs
- This project was built while following along to this tutorial from Tech With Tim