YO

YouTube Uploader MCP Server CLI OAuth2 Token Management

Manage YouTube uploads via MCP server CLI with OAuth2 authentication, automated access and refresh token handling, and a modular Go package structure.

Quick Install
npx -y @anwerj/youtube-uploader-mcp

Overview

This MCP (Model Context Protocol) server CLI provides a lightweight, developer-friendly way to manage YouTube uploads and OAuth2 credentials. It wraps the YouTube Data API OAuth2 flow in a small HTTP service and command-line tool so you can obtain, persist, and refresh access tokens automatically — without embedding long-lived secrets in your application code.

The project is implemented in Go with a modular package layout so you can either run the standalone CLI/server or import the authentication and token-management components into other Go services. The server exposes endpoints for initiating authorization, exchanging codes, and serving refreshed access tokens to a trusted client or downstream uploader process, making automated uploads and long-running integrations easier to manage.

Features

  • OAuth2 Authorization Code flow for Google / YouTube Data API
  • Automatic handling and refreshing of access and refresh tokens
  • CLI to run an MCP-compatible server for token management
  • Token persistence to disk (JSON or other configurable store)
  • Modular Go packages suitable for embedding in other applications
  • Minimal HTTP endpoints for initiating and completing OAuth flows
  • Local development friendly (open browser/CLI authorization flow)

Installation / Configuration

Install the CLI using Go (Go 1.18+ recommended):

# Install the server CLI (adjust command path if project layout differs)
go install github.com/anwerj/youtube-uploader-mcp/cmd/mcp-server@latest

Alternatively, clone and build locally:

git clone https://github.com/anwerj/youtube-uploader-mcp.git
cd youtube-uploader-mcp
go build ./cmd/mcp-server
./mcp-server --help

Typical environment variables and configuration:

# Environment variables (example)
export GOOGLE_CLIENT_ID="your-google-client-id.apps.googleusercontent.com"
export GOOGLE_CLIENT_SECRET="your-client-secret"
export REDIRECT_URI="http://localhost:8080/oauth2/callback"
export TOKEN_STORE="./tokens.json"

Minimal configuration file (JSON example):

{
  "client_id": "your-google-client-id.apps.googleusercontent.com",
  "client_secret": "your-client-secret",
  "redirect_url": "http://localhost:8080/oauth2/callback",
  "token_store": "./tokens.json",
  "listen_addr": ":8080"
}

Start the server (example flags — adjust to your build/CLI):

mcp-server \
  --client-id="$GOOGLE_CLIENT_ID" \
  --client-secret="$GOOGLE_CLIENT_SECRET" \
  --redirect-url="$REDIRECT_URI" \
  --token-store="$TOKEN_STORE" \
  --listen=":8080"

When you visit the server’s authorization endpoint (e.g., http://localhost:8080/auth), it will redirect you to Google’s consent screen. After consenting, the server exchanges the code for access and refresh tokens and stores them to the configured token store.

Available Resources

  • GitHub repository: https://github.com/anwerj/youtube-uploader-mcp
  • Command-line server (mcp-server) — run, authorize, and manage tokens
  • Go modules/packages for embedding:
    • auth/token manager: obtain, refresh, persist tokens
    • http/server: lightweight endpoints for OAuth initiation and callback handling

Example of embedding the token manager (pseudocode):

import "github.com/anwerj/youtube-uploader-mcp/pkg/auth"

// create manager with config
mgr := auth.NewManager(auth.Config{
  ClientID:     "xxx",
  ClientSecret: "yyy",
  RedirectURL:  "http://localhost:8080/oauth2/callback",
  TokenStore:   "./tokens.json",
})

// get a valid access token (refreshes automatically)
token, err := mgr.GetAccessToken(ctx, "default-profile")

Use Cases

  • Continuous video processing: a backend pipeline transcodes videos and uses the MCP server to obtain a valid YouTube access token at upload time without storing refresh tokens inside the pipeline.
  • Local development and testing: developers authorize a local account once via the CLI/server; the stored refresh token enables repeated uploads from dev tools and scripts.
  • Microservice integration: embed the Go token manager into a microservice that needs ephemeral access tokens; the service delegates refresh logic to the library and reads tokens from a shared token store.
  • CI/CD pipelines: obtain short-lived tokens for a job that uploads artifacts to a YouTube channel; the CI job requests a token from the MCP server instead of keeping long-lived credentials in CI secrets.

Configuration Reference

OptionDescriptionExample
client_idGoogle OAuth2 client IDyour-client-id.apps.googleusercontent.com
client_secretGoogle OAuth2 client secretyour-client-secret
redirect_urlAuthorized redirect URI for OAuth2 flowhttp://localhost:8080/oauth2/callback
token_storeFile path where tokens are persisted./tokens.json
listen_addrHTTP address for the local MCP server:8080

Notes and Best Practices

  • Use Google API Console to create OAuth2 credentials and configure redirect URIs for local and production environments.
  • Protect your token store file (permissions and encryption) because it contains refresh tokens that grant long-term access.
  • For production, consider running the server behind TLS and restricting access to the token endpoints to trusted services.
  • Review Google’s OAuth2 and YouTube API quotas and scopes; request only the scopes required for uploads (e.g., youtube.upload).

For full source, issues, and examples, see the project on GitHub: https://github.com/anwerj/youtube-uploader-mcp.