### Environment Configuration Example (.env) Source: https://context7.com/shawhint/yt-mcp-remote/llms.txt Provides an example .env file for configuring Auth0, proxy, and server settings. Key variables include AUTH0_DOMAIN, AUTH0_AUDIENCE, RESOURCE_SERVER_URL, and AUTH0_ALGORITHMS. ```bash # .env file configuration AUTH0_DOMAIN=dev-abc123.us.auth0.com AUTH0_AUDIENCE=https://your-api-identifier.com RESOURCE_SERVER_URL=https://your-server.railway.app/mcp AUTH0_ALGORITHMS=RS256 ``` -------------------------------- ### Install and Run Python Dependencies Source: https://github.com/shawhint/yt-mcp-remote/blob/main/CLAUDE.md These commands use 'uv' to install project dependencies and then run the Python MCP server. Ensure Python version >=3.13 is installed. ```bash # Install dependencies uv sync # Run the server uv run python main.py ``` -------------------------------- ### Bash Commands for MCP Server Installation and Execution Source: https://context7.com/shawhint/yt-mcp-remote/llms.txt Provides bash commands for installing Python dependencies using `uv` and running the MCP server locally. It includes expected output messages indicating successful server startup and OAuth configuration. ```bash # Install dependencies using uv uv sync # Run server locally uv run python main.py # Expected output: # Server running on http://0.0.0.0:8000/mcp # OAuth configured with Auth0: dev-abc123.us.auth0.com # Required scopes: openid, profile, email, address, phone ``` -------------------------------- ### MCP Tool Registration Example (Python) Source: https://github.com/shawhint/yt-mcp-remote/blob/main/CLAUDE.md Example demonstrating how to register an MCP tool using FastMCP's decorator pattern in Python. This makes the function available to MCP clients. ```python # Assuming 'mcp' is an instance of FastMCP @mcp.tool() def fetch_video_transcript(url: str): # Function implementation here pass ``` -------------------------------- ### Python MCP Client Tool Invocation for YouTube Source: https://context7.com/shawhint/yt-mcp-remote/llms.txt Demonstrates how to use the `mcp` Python library to connect to a remote MCP server, authenticate using an OAuth token, and invoke tools like `fetch_video_transcript` and `fetch_instructions`. It shows example outputs for transcript and instructions. ```python # Example client-side MCP tool invocation import mcp # Initialize client connection client = mcp.Client("https://your-server.railway.app/mcp") # Authenticate with OAuth token await client.authenticate(oauth_token="eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...") # Fetch video transcript transcript = await client.call_tool( "fetch_video_transcript", {"url": "https://www.youtube.com/watch?v=dQw4w9WgXcQ"} ) print(transcript) # Output: # [00:00] Welcome to this video # [00:03] Today we're discussing... # Fetch writing instructions instructions = await client.call_tool( "fetch_instructions", {"prompt_name": "write_blog_post"} ) print(instructions) # Output: Markdown-formatted blog writing guidelines ``` -------------------------------- ### Fetch Writing Instructions (Python) Source: https://context7.com/shawhint/yt-mcp-remote/llms.txt Retrieves specialized writing instruction templates from the prompts directory. It takes a prompt name as input and returns Markdown-formatted instructions. It handles FileNotFoundError for unknown prompt names. ```python import os from mcp.server.fastmcp import FastMCP mcp = FastMCP("yt-mcp") @mcp.tool() def fetch_instructions(prompt_name: str) -> str: """ Fetch writing instructions for content transformation Args: prompt_name: One of 'write_blog_post', 'write_social_post', 'write_video_chapters' Returns: Markdown-formatted instructions with structure and guidelines """ script_dir = os.path.dirname(__file__) prompt_path = os.path.join(script_dir, "prompts", f"{prompt_name}.md") try: with open(prompt_path, "r") as f: return f.read() except FileNotFoundError: raise ValueError(f"Unknown prompt name: {prompt_name}. Available: write_blog_post, write_social_post, write_video_chapters") # Example usage from MCP client: # instructions = fetch_instructions("write_blog_post") # Output: # ## How to Write a Blog Post # # ### Blog Structure # - Short engaging title (format with markdown `#`) # - Short engaging subtitle... # # Example usage for social media: # social_instructions = fetch_instructions("write_social_post") # Output includes platform-specific guidelines: # - Twitter/X: 280 characters max # - LinkedIn: 1,300 characters max # - Instagram: 2,200 characters max ``` -------------------------------- ### Initialize FastMCP Server with OAuth Authentication (Python) Source: https://context7.com/shawhint/yt-mcp-remote/llms.txt Initializes and configures a FastMCP server with OAuth 2.0 authentication using Auth0 and loads server instructions from a markdown file. It requires environment variables for Auth0 domain and resource server URL. The server runs using streamable-http transport. ```python from mcp.server.fastmcp import FastMCP from mcp.server.auth.settings import AuthSettings from pydantic import AnyHttpUrl from utils.auth import create_auth0_verifier from dotenv import load_dotenv import os # Load environment variables load_dotenv() # Load server instructions from prompts directory with open("prompts/server_instructions.md", "r") as file: server_instructions = file.read() # Initialize Auth0 token verifier token_verifier = create_auth0_verifier() # Create MCP server instance mcp = FastMCP( "yt-mcp", instructions=server_instructions, host="0.0.0.0", token_verifier=token_verifier, auth=AuthSettings( issuer_url=AnyHttpUrl(f"https://{os.getenv('AUTH0_DOMAIN')}/"), resource_server_url=AnyHttpUrl(os.getenv('RESOURCE_SERVER_URL')), required_scopes=["openid", "profile", "email", "address", "phone"], ), ) # Run server with streamable-http transport if __name__ == "__main__": mcp.run(transport='streamable-http') ``` -------------------------------- ### Python Configuration Loading and Validation Source: https://context7.com/shawhint/yt-mcp-remote/llms.txt Loads environment variables for authentication (Auth0) and proxy settings using python-dotenv. It validates the presence of required variables and raises ValueErrors if any are missing, ensuring the application has the necessary credentials to run. ```python # Loading and validating configuration from dotenv import load_dotenv import os load_dotenv() # Required Auth0 configuration auth0_domain = os.getenv("AUTH0_DOMAIN") resource_server_url = os.getenv("RESOURCE_SERVER_URL") if not auth0_domain: raise ValueError("AUTH0_DOMAIN environment variable is required") if not resource_server_url: raise ValueError("RESOURCE_SERVER_URL environment variable is required") # Validate proxy configuration proxy_username = os.getenv("PROXY_USERNAME") proxy_password = os.getenv("PROXY_PASSWORD") proxy_url = os.getenv("PROXY_URL") if not all([proxy_username, proxy_password, proxy_url]): raise ValueError("Proxy credentials incomplete: Set PROXY_USERNAME, PROXY_PASSWORD, and PROXY_URL") print(f"Server configured for: {resource_server_url}") print(f"Auth0 domain: {auth0_domain}") print(f"Proxy configured: {proxy_url}") ``` -------------------------------- ### Railway Deployment Configuration for MCP Server Source: https://context7.com/shawhint/yt-mcp-remote/llms.txt Defines the `railway.toml` configuration file for deploying the MCP server on Railway. It specifies build settings, deployment commands, health check configurations, restart policies, and environment variables including Python version. ```yaml # railway.toml (for Railway deployment) [build] builder = "NIXPACKS" buildCommand = "uv sync" [deploy] startCommand = "uv run python main.py" healthcheckPath = "/mcp" healthcheckTimeout = 30 restartPolicyType = "ON_FAILURE" restartPolicyMaxRetries = 3 [env] PYTHON_VERSION = "3.13" UV_SYSTEM_PYTHON = "true" ``` -------------------------------- ### MCP Client Configuration for YouTube Remote Server Source: https://context7.com/shawhint/yt-mcp-remote/llms.txt Defines the structure for configuring an MCP client to connect to a remote YouTube server. It specifies server details, transport protocol (SSE), and OAuth2 authorization parameters including client ID, secrets, and token URLs. ```json { "mcpServers": { "youtube-remote": { "url": "https://your-server.railway.app/mcp", "transport": "sse", "authorization": { "type": "oauth2", "oauth2": { "clientId": "your-oauth-client-id", "clientSecret": "your-oauth-client-secret", "authorizationUrl": "https://dev-abc123.us.auth0.com/authorize", "tokenUrl": "https://dev-abc123.us.auth0.com/oauth/token", "scope": "openid profile email address phone offline_access" } } } } } ``` -------------------------------- ### Fetch YouTube Video Transcript with Timestamps (Python) Source: https://context7.com/shawhint/yt-mcp-remote/llms.txt Extracts timestamped transcripts from a YouTube video URL using the youtube-transcript-api library with proxy support. It requires a YouTube video URL as input and returns a formatted string of transcript lines with [MM:SS] timestamps. Proxy credentials must be set in environment variables. ```python from mcp.server.fastmcp import FastMCP from youtube_transcript_api import YouTubeTranscriptApi from youtube_transcript_api.proxies import GenericProxyConfig import re import os mcp = FastMCP("yt-mcp") @mcp.tool() def fetch_video_transcript(url: str) -> str: """ Extract transcript with timestamps from a YouTube video URL Args: url: YouTube video URL (supports multiple formats) Returns: Formatted transcript with [MM:SS] timestamps """ # Extract video ID using regex video_id_pattern = r'(?:v=|\/)([0-9A-Za-z_-]{11}).*' video_id_match = re.search(video_id_pattern, url) if not video_id_match: raise ValueError("Invalid YouTube URL") video_id = video_id_match.group(1) # Configure proxy with credentials proxy_username = os.getenv("PROXY_USERNAME") proxy_password = os.getenv("PROXY_PASSWORD") proxy_url_base = os.getenv("PROXY_URL") if not all([proxy_username, proxy_password, proxy_url_base]): raise ValueError("Proxy credentials not configured. Set PROXY_USERNAME, PROXY_PASSWORD, and PROXY_URL.") http_proxy = f"http://{proxy_username}:{proxy_password}@{proxy_url_base}" https_proxy = f"https://{proxy_username}:{proxy_password}@{proxy_url_base}" proxy_config = GenericProxyConfig( http_url=http_proxy, https_url=https_proxy ) # Fetch transcript through proxy ytt_api = YouTubeTranscriptApi(proxy_config=proxy_config) transcript = ytt_api.fetch(video_id) # Format transcript with timestamps formatted_entries = [] for entry in transcript: minutes = int(entry.start // 60) seconds = int(entry.start % 60) timestamp = f"[{minutes:02d}:{seconds:02d}]" formatted_entries.append(f"{timestamp} {entry.text}") return "\n".join(formatted_entries) # Example usage from MCP client: # result = fetch_video_transcript("https://www.youtube.com/watch?v=dQw4w9WgXcQ") # Output: # [00:00] Welcome to this video # [00:03] Today we're going to discuss # [00:07] The main topic of our presentation ``` -------------------------------- ### Auth0 JWKS Endpoint Configuration Source: https://github.com/shawhint/yt-mcp-remote/blob/main/CLAUDE.md The structure of the JWKS endpoint URL used by Auth0 for fetching public keys to verify JWT tokens. Replace '{domain}' with your Auth0 tenant domain. ```url https://{domain}/.well-known/jwks.json ``` -------------------------------- ### Auth0 JWT Token Verification (Python) Source: https://context7.com/shawhint/yt-mcp-remote/llms.txt Verifies JWT tokens issued by Auth0 using JWKS-based signature validation. It takes a JWT token and returns access information if valid, otherwise None. It requires Auth0 domain and audience, and can be configured with specific algorithms. Dependencies include 'PyJWKClient' from the 'jwt' library. ```python import os import asyncio from typing import Optional from jwt import PyJWKClient, decode, InvalidTokenError from mcp.server.auth.provider import AccessToken, TokenVerifier class Auth0TokenVerifier(TokenVerifier): """Verifies OAuth tokens issued by Auth0""" def __init__(self, domain: str, audience: str, algorithms: Optional[list[str]] = None): self.domain = domain self.audience = audience self.algorithms = algorithms or ["RS256"] self.jwks_url = f"https://{domain}/.well-known/jwks.json" self.issuer = f"https://{domain}/" self.jwks_client = PyJWKClient(self.jwks_url) async def verify_token(self, token: str) -> AccessToken | None: """Verify JWT and return access information""" try: # Get signing key from JWKS (runs in thread pool) signing_key = await asyncio.to_thread( self.jwks_client.get_signing_key_from_jwt, token ) # Decode and verify JWT payload = decode( token, signing_key.key, algorithms=self.algorithms, audience=self.audience, issuer=self.issuer, options={ "verify_signature": True, "verify_aud": True, "verify_iat": True, "verify_exp": True, "verify_iss": True, } ) # Extract scopes scopes = [] if "scope" in payload: scopes = payload["scope"].split() elif "permissions" in payload: scopes = payload["permissions"] return AccessToken( token=token, client_id=payload.get("azp") or payload.get("client_id", "unknown"), scopes=scopes, expires_at=payload.get("exp"), resource=self.audience, ) except InvalidTokenError as e: print(f"JWT verification failed: {e}") return None except Exception as e: print(f"Token verification error: {e}") return None # Factory function to create verifier from environment def create_auth0_verifier() -> Auth0TokenVerifier: """Create Auth0TokenVerifier from environment variables""" domain = os.getenv("AUTH0_DOMAIN") audience = os.getenv("AUTH0_AUDIENCE") algorithms_str = os.getenv("AUTH0_ALGORITHMS", "RS256") if not domain: raise ValueError("AUTH0_DOMAIN environment variable is required") if not audience: raise ValueError("AUTH0_AUDIENCE environment variable is required") algorithms = [alg.strip() for alg in algorithms_str.split(",")] return Auth0TokenVerifier( domain=domain, audience=audience, algorithms=algorithms ) # Example usage: # verifier = create_auth0_verifier() # access_token = await verifier.verify_token("eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...") # if access_token: # print(f"Client: {access_token.client_id}, Scopes: {access_token.scopes}") ``` -------------------------------- ### YouTube Video ID Extraction Regex Source: https://github.com/shawhint/yt-mcp-remote/blob/main/CLAUDE.md Regular expression pattern used to extract the 11-character YouTube video ID from various URL formats. This is crucial for fetching transcripts. ```regex (?:v=|\/)([0-9A-Za-z_-]{11}).* ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.