16.02 Boilerplate Setup¶
Before writing MCP servers or clients, we must set up our project scaffolding and environment using uv.
1. Initializing the Project¶
Start with a clean slate by initializing a new Python project:
This generates your boilerplate files:README.md, main.py, and pyproject.toml.
2. Virtual Environment Setup¶
Create and activate a virtual environment:
3. Installing Dependencies¶
We need the LangChain MCP Adapters and tracing modules.
[!NOTE] Notice that we did not explicitly install the
mcppackage. Thelangchain-mcp-adapterspackage automatically installs the core MCP SDK as a dependency.
4. Environment Variables¶
Create a .env file at the root of your project:
OPENAI_API_KEY=your_openai_key
LANGCHAIN_TRACING_V2=true
LANGCHAIN_API_KEY=your_langchain_key
LANGCHAIN_ENDPOINT=https://api.smith.langchain.com
LANGCHAIN_PROJECT=mcp_test
[!WARNING] Always create a
.gitignorefile and add.envto prevent accidentally committing your API keys to GitHub.
5. Main Script Sanity Check¶
Update your main.py with asynchronous boilerplate and load your environment variables to ensure everything is wired correctly.
import asyncio
import os
from dotenv import load_dotenv
load_dotenv()
async def main():
print("Welcome to MCP Adapters")
print(f"OpenAI Key Loaded: {os.getenv('OPENAI_API_KEY') is not None}")
if __name__ == "__main__":
asyncio.run(main())
Run the file to verify: