# alexandermolano-spec/spotify-mcp-server architecture

> Architecture diagram of the GitHub repository alexandermolano-spec/spotify-mcp-server, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-10). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/alexandermolano-spec/spotify-mcp-server
- Repository: https://github.com/alexandermolano-spec/spotify-mcp-server

## Overview

Spotify MCP Server exposes Spotify catalog, account, playback, device, playlist, and queue operations as Streamable HTTP MCP tools. An agent sends requests to the HTTP app; the MCP handler manages sessions and authentication context, then dispatches registered tools to the Spotify Web API client. Local OAuth is a separate login-and-callback path that stores and refreshes one token; delegated tokens arrive with MCP requests and are kept in session memory. Edges reflect shown calls or README-documented behavior; unsampled internals are represented only where documented.

Main entry points: [`src/spotify/auth.routes.ts`](https://github.com/alexandermolano-spec/spotify-mcp-server/blob/main/src/spotify/auth.routes.ts) (Local OAuth routes), [`src/spotify/spotifyAccountsClient.ts`](https://github.com/alexandermolano-spec/spotify-mcp-server/blob/main/src/spotify/spotifyAccountsClient.ts) (Accounts client), [`src/spotify/tokenStore.ts`](https://github.com/alexandermolano-spec/spotify-mcp-server/blob/main/src/spotify/tokenStore.ts) (Local token store), [`src/spotify/authProvider.ts`](https://github.com/alexandermolano-spec/spotify-mcp-server/blob/main/src/spotify/authProvider.ts) (Auth provider)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_http["HTTP transport"]
  node_http_app["HTTP app<br/>[app.ts]"]
  node_mcp_handler["MCP session handler<br/>[handler.ts]"]
end

subgraph group_mcp["MCP tools"]
  node_mcp_server["MCP server<br/>[server.ts]"]
  node_tool_registry["Spotify tool registry<br/>[tools.ts]"]
end

subgraph group_spotify["Spotify API"]
  node_spotify_client["Spotify API client"]
  node_spotify_api["Spotify Web API"]
end

subgraph group_auth["Authentication"]
  node_auth_routes["Local OAuth routes<br/>[auth.routes.ts]"]
  node_oauth_state["OAuth state<br/>[oauthState.ts]"]
  node_accounts_client["Accounts client"]
  node_token_store[("Local token store<br/>[tokenStore.ts]")]
  node_auth_provider["Auth provider<br/>[authProvider.ts]"]
  node_config["Environment config<br/>[env.ts]"]
end

node_agent(("AI agent"))
node_spotify_accounts["Spotify Accounts"]

node_agent -->|"sends MCP requests"| node_http_app
node_http_app -->|"routes MCP"| node_mcp_handler
node_http_app -->|"mounts OAuth"| node_auth_routes
node_mcp_handler -->|"creates server"| node_mcp_server
node_mcp_server -->|"registers tools"| node_tool_registry
node_tool_registry -->|"calls operations"| node_spotify_client
node_spotify_client -->|"gets access token"| node_auth_provider
node_spotify_client -->|"sends API requests"| node_spotify_api
node_auth_routes -->|"creates and consumes"| node_oauth_state
node_auth_routes -->|"builds URL and exchanges code"| node_accounts_client
node_auth_routes -->|"saves token"| node_token_store
node_auth_routes -->|"reads auth status"| node_auth_provider
node_accounts_client -->|"exchanges and refreshes tokens"| node_spotify_accounts
node_auth_provider -->|"uses local tokens"| node_token_store
node_token_store -->|"refreshes expired token"| node_accounts_client
node_token_store -->|"reads store path"| node_config
node_accounts_client -->|"reads OAuth settings"| node_config
node_mcp_handler -->|"sets delegated context"| node_auth_provider

click node_http_app "https://github.com/alexandermolano-spec/spotify-mcp-server/blob/main/src/http/app.ts"
click node_mcp_handler "https://github.com/alexandermolano-spec/spotify-mcp-server/blob/main/src/mcp/handler.ts"
click node_mcp_server "https://github.com/alexandermolano-spec/spotify-mcp-server/blob/main/src/mcp/server.ts"
click node_tool_registry "https://github.com/alexandermolano-spec/spotify-mcp-server/blob/main/src/mcp/tools.ts"
click node_spotify_client "https://github.com/alexandermolano-spec/spotify-mcp-server/blob/main/src/spotify/spotifyWebApiClient.ts"
click node_auth_routes "https://github.com/alexandermolano-spec/spotify-mcp-server/blob/main/src/spotify/auth.routes.ts"
click node_oauth_state "https://github.com/alexandermolano-spec/spotify-mcp-server/blob/main/src/spotify/oauthState.ts"
click node_accounts_client "https://github.com/alexandermolano-spec/spotify-mcp-server/blob/main/src/spotify/spotifyAccountsClient.ts"
click node_token_store "https://github.com/alexandermolano-spec/spotify-mcp-server/blob/main/src/spotify/tokenStore.ts"
click node_auth_provider "https://github.com/alexandermolano-spec/spotify-mcp-server/blob/main/src/spotify/authProvider.ts"
click node_config "https://github.com/alexandermolano-spec/spotify-mcp-server/blob/main/src/config/env.ts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_http_app,node_mcp_handler toneBlue
class node_mcp_server,node_tool_registry toneAmber
class node_spotify_client,node_spotify_api toneMint
class node_auth_routes,node_oauth_state,node_accounts_client,node_token_store,node_auth_provider,node_config toneRose
class node_agent,node_spotify_accounts toneIndigo
```

## Components

### HTTP transport

- [HTTP app](https://github.com/alexandermolano-spec/spotify-mcp-server/blob/main/src/http/app.ts): `src/http/app.ts`
- [MCP session handler](https://github.com/alexandermolano-spec/spotify-mcp-server/blob/main/src/mcp/handler.ts): `src/mcp/handler.ts`

### MCP tools

- [MCP server](https://github.com/alexandermolano-spec/spotify-mcp-server/blob/main/src/mcp/server.ts): `src/mcp/server.ts`
- [Spotify tool registry](https://github.com/alexandermolano-spec/spotify-mcp-server/blob/main/src/mcp/tools.ts): `src/mcp/tools.ts`

### Spotify API

- [Spotify API client](https://github.com/alexandermolano-spec/spotify-mcp-server/blob/main/src/spotify/spotifyWebApiClient.ts): `src/spotify/spotifyWebApiClient.ts`
- **Spotify Web API**

### Authentication

- [Local OAuth routes](https://github.com/alexandermolano-spec/spotify-mcp-server/blob/main/src/spotify/auth.routes.ts): `src/spotify/auth.routes.ts`
- [OAuth state](https://github.com/alexandermolano-spec/spotify-mcp-server/blob/main/src/spotify/oauthState.ts): `src/spotify/oauthState.ts`
- [Accounts client](https://github.com/alexandermolano-spec/spotify-mcp-server/blob/main/src/spotify/spotifyAccountsClient.ts): `src/spotify/spotifyAccountsClient.ts`
- [Local token store](https://github.com/alexandermolano-spec/spotify-mcp-server/blob/main/src/spotify/tokenStore.ts): `src/spotify/tokenStore.ts`
- [Auth provider](https://github.com/alexandermolano-spec/spotify-mcp-server/blob/main/src/spotify/authProvider.ts): `src/spotify/authProvider.ts`
- [Environment config](https://github.com/alexandermolano-spec/spotify-mcp-server/blob/main/src/config/env.ts): `src/config/env.ts`

### Other components

- **AI agent**
- **Spotify Accounts**

## Connections

- AI agent → HTTP app: sends MCP requests (evidence: `README.md`)
- HTTP app → MCP session handler: routes MCP (evidence: `src/http/app.ts`)
- HTTP app → Local OAuth routes: mounts OAuth (evidence: `src/http/app.ts`)
- MCP session handler → MCP server: creates server (evidence: `src/mcp/handler.ts`)
- MCP server → Spotify tool registry: registers tools (evidence: `src/mcp/server.ts`)
- Spotify tool registry → Spotify API client: calls operations (evidence: `src/mcp/tools.ts`)
- Spotify API client → Auth provider: gets access token (evidence: `src/spotify/spotifyWebApiClient.ts`)
- Spotify API client → Spotify Web API: sends API requests (evidence: `src/spotify/spotifyWebApiClient.ts`)
- Local OAuth routes → OAuth state: creates and consumes (evidence: `src/spotify/auth.routes.ts`)
- Local OAuth routes → Accounts client: builds URL and exchanges code (evidence: `src/spotify/auth.routes.ts`)
- Local OAuth routes → Local token store: saves token (evidence: `src/spotify/auth.routes.ts`)
- Local OAuth routes → Auth provider: reads auth status (evidence: `src/spotify/auth.routes.ts`)
- Accounts client → Spotify Accounts: exchanges and refreshes tokens (evidence: `src/spotify/spotifyAccountsClient.ts`)
- Auth provider → Local token store: uses local tokens (evidence: `src/spotify/authProvider.ts`)
- Local token store → Accounts client: refreshes expired token (evidence: `src/spotify/tokenStore.ts`)
- Local token store → Environment config: reads store path (evidence: `src/spotify/tokenStore.ts`)
- Accounts client → Environment config: reads OAuth settings (evidence: `src/spotify/spotifyAccountsClient.ts`)
- MCP session handler → Auth provider: sets delegated context (evidence: `src/mcp/handler.ts`)
