TheBuleGanteng/mcp-prototyping
If you are the rightful owner of mcp-prototyping and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to dayong@mcphub.com.
This repository demonstrates the creation and use of Model Context Protocol (MCP) implementations, showcasing both server and client architectures.
MCP Prototype Repository
Purpose
This repository demonstrates the creation and use of Model Context Protocol (MCP) implementations, showcasing both server and client architectures. It provides practical examples of:
- Building MCP servers that expose tools and functionality
- Creating MCP clients that integrate with LLMs (OpenAI/Anthropic) to consume MCP servers
- Understanding the MCP protocol through annotated examples and tutorials
Prerequisites
- Python 3.10 or higher
uvpackage manager (installation guide)- Spotify Developer Account with API credentials
- Anthropic API key (for Claude) and/or OpenAI API key
Repository Structure
The repository contains three major components:
1. example-client-spotify/ - MCP Client Implementation
What is it:
An interactive MCP client that integrates with Anthropic Claude (or OpenAI) to interact with a Spotify MCP server. Demonstrates:
- Automatic tool discovery from MCP servers
- LangChain agent integration with conversation memory
- Multi-turn conversations with context persistence
- Type-safe tool invocation with Pydantic validation
How to use it:
-
Setup environment variables
Create a.envfile in the root directory:# Spotify API Credentials SPOTIPY_CLIENT_ID=your_spotify_client_id SPOTIPY_CLIENT_SECRET=your_spotify_client_secret SPOTIPY_REDIRECT_URI=http://127.0.0.1:8888/callback # LLM API Key ANTHROPIC_API_KEY=your_anthropic_api_key # Or use OpenAI: # OPENAI_API_KEY=your_openai_api_key # Optional: Your Spotify email for personalization EMAIL_SPOTIFY=your_email@example.com -
Configure Spotify Developer App
- Go to https://developer.spotify.com/dashboard
- Create an app or use existing
- Add
http://127.0.0.1:8888/callbackto Redirect URIs - Copy Client ID and Secret to
.env
-
Install dependencies
cd mcp-mvp uv sync -
Run the interactive client
uv run python example-client-spotify/spotify_langchain_client_v2.py -
Interact with the agent
- Type natural language queries about Spotify
- Agent remembers context across messages
- Type
quit,exit, orqto end
Expected Output:
- Interactive terminal chat interface
- Real-time tool calls to Spotify API (search, create playlists, etc.)
- Results displayed in terminal
- Changes reflected in your Spotify account (playlists created, etc.)
Example Interaction:
🗣️ YOU: What are Taylor Swift's top tracks?
🤖 AGENT: [Lists Taylor Swift's popular songs with IDs]
🗣️ YOU: Create a playlist called "My Favorites" with those songs
🤖 AGENT: [Creates playlist and adds tracks]
✅ Playlist created in your Spotify account!
2. example-server/spotify_mcp.py - Custom MCP Server
What is it:
A custom-built MCP server for Spotify that exposes tools for:
- Searching tracks, albums, artists, playlists
- Getting detailed information about Spotify items
- Retrieving audio features (tempo, key, energy, etc.)
- Getting personalized recommendations
This demonstrates how to build an MCP server from scratch using the fastmcp framework.
How to use it:
-
Setup environment variables (same as client above)
-
Install dependencies
cd mcp-mvp uv sync -
Run with MCP Inspector (for testing)
cd example-server uv run mcp dev spotify_mcp.pyThis opens a web interface at
http://localhost:6274for testing tools interactively. -
Run standalone (for production)
uv run python example-server/spotify_mcp.py
Expected Output:
- MCP Inspector web interface (in dev mode)
- Server runs and waits for stdio input (in standalone mode)
- Tool call results printed to terminal
- JSON-RPC messages exchanged via stdio
Available Tools:
search_tracks- Search for tracks on Spotifyget_artist_info- Get artist details, popularity, genres, top tracksget_audio_features- Get tempo, key, energy, danceability for a trackget_recommendations- Get similar tracks based on seed tracks
3. mcp-tutorial/ - Annotated MCP Examples
What is it:
A cloned and enhanced version of the official Model Context Protocol repository from https://github.com/modelcontextprotocol/python-sdk with additional:
- Detailed logging and debug output
- Comprehensive docstrings explaining each concept
- Annotated code examples
- Custom README documentation
How to use it:
-
Navigate to the tutorial directory
cd mcp-tutorial/python-sdk/examples/snippets/servers -
Run examples with MCP Inspector
uv run mcp dev <example_file>.pyExamples to try:
lifespan_example.py- Resource lifecycle managementbasic_tool.py- Simple tool creationbasic_resource.py- Resource patternsbasic_prompt.py- Prompt templatesstructured_output.py- Typed outputs
-
Follow the tutorial README
- See
mcp-tutorial/README.mdfor detailed walkthroughs - Each example has explanations of key concepts
- Common patterns and gotchas documented
- See
Expected Output:
- MCP Inspector opens in browser (
http://localhost:6274) - Interactive testing interface for tools/resources/prompts
- Console logs showing server lifecycle events
- Detailed debug output for understanding MCP concepts
Learning Path:
- Start with
lifespan_example.pyto understand resource management - Progress through
basic_tool.py,basic_resource.py,basic_prompt.py - Review the annotated README for conceptual explanations
- Experiment with modifications to deepen understanding
Key Concepts Demonstrated
MCP Architecture
- Server: Exposes tools, resources, and prompts via stdio/HTTP
- Client: Discovers and invokes server capabilities
- Protocol: Standardized JSON-RPC communication
Tool Discovery
- Clients call
list_tools()to discover available functionality - No hardcoding - tools are discovered at runtime
- Schema-based validation ensures type safety
Conversation Memory
- LangGraph's
MemorySaverenables context persistence - Agent remembers previous messages in the conversation
- Multi-turn interactions reference earlier context
Type Safety
- Pydantic models validate all inputs/outputs
- Enums provide compile-time tool selection safety
- Schema definitions prevent runtime errors
Troubleshooting
OAuth Authentication Issues
- Ensure redirect URI in Spotify Dashboard exactly matches
.env - Use
http://127.0.0.1:8888/callback(notlocalhost) - Complete OAuth flow in browser when prompted
Port Already in Use
- Kill existing processes:
lsof -i :8888thenkill <PID> - Or change port in both
.envand Spotify Dashboard
Virtual Environment Warnings
- These are harmless -
uvautomatically uses correct venv - To suppress: don't set
VIRTUAL_ENVenvironment variable
Import Errors
- Ensure
uv synccompleted successfully - Restart VS Code/IDE to refresh language server
- Use
uv runprefix for all python commands
Additional Resources
Contributing
This is a learning/prototype repository. Feel free to:
- Add new MCP server implementations
- Enhance existing examples with better error handling
- Document additional patterns and use cases
- Create issues for bugs or unclear documentation
License
MIT License - See LICENSE file for details