Skip to main content
Glama
AnantBisht07

Circle MCP Server

by AnantBisht07
README.md
# Circle MCP Server

[![TypeScript](https://img.shields.io/badge/TypeScript-5.6-blue.svg)](https://www.typescriptlang.org/)
[![MCP](https://img.shields.io/badge/MCP-1.19-green.svg)](https://modelcontextprotocol.io/)
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)

Production-grade **Model Context Protocol (MCP)** server for the Circle community platform. This server enables AI assistants to interact with Circle.so communities through Google OAuth 2.0 authentication and provides 20+ tools for comprehensive community management.

---

## šŸ“‹ Table of Contents

- [Features](#-features)
- [Architecture](#-architecture)
- [Prerequisites](#-prerequisites)
- [Installation](#-installation)
- [Configuration](#-configuration)
  - [Google Cloud Platform Setup](#1-google-cloud-platform-gcp-setup)
  - [Environment Variables](#2-environment-variables)
- [Building & Testing](#-building--testing)
- [IDE Integration](#-ide-integration)
  - [Claude Desktop](#1-claude-desktop)
  - [VS Code with Cline](#2-vs-code-with-cline)
  - [Other MCP Clients](#3-other-mcp-clients)
- [Available Tools](#-available-tools)
- [Usage Examples](#-usage-examples)
- [Troubleshooting](#-troubleshooting)
- [Development](#-development)
- [License](#-license)

---

## ✨ Features

### Core Capabilities
- šŸ” **Google OAuth 2.0 Integration** - Secure authentication via Google accounts
- šŸ”— **Circle API Integration** - Seamless integration with Circle.so communities
- šŸ›”ļø **JWT Token Management** - Automatic token refresh and secure storage
- 🚦 **Rate Limiting** - Built-in protection against API rate limits
- šŸ”„ **Request Retry Logic** - Exponential backoff for failed requests
- šŸ“Š **Comprehensive Logging** - Winston-based structured logging
- šŸŽÆ **20+ Tools** - Complete Circle API coverage
- šŸ”§ **Type-Safe** - Full TypeScript implementation with Zod validation

### Security Features
- āœ… Secure credential storage
- āœ… Automatic token refresh
- āœ… OAuth 2.0 authorization code flow
- āœ… Read-only mode support
- āœ… Environment-based configuration

---

## šŸ—ļø Architecture

```
ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”
│   AI Assistant  │ (Claude Desktop, VS Code, etc.)
ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¬ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜
         │ MCP Protocol (stdio)
         ā–¼
ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”
│    Circle MCP Server            │
│  ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”  │
│  │  Integrated Auth Manager │  │
│  │  ā”œā”€ GCP OAuth 2.0        │  │
│  │  └─ Circle JWT Auth      │  │
│  ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜  │
│  ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”  │
│  │  Circle API Client       │  │
│  │  ā”œā”€ Rate Limiting        │  │
│  │  ā”œā”€ Retry Logic          │  │
│  │  └─ Error Handling       │  │
│  ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜  │
│  ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”  │
│  │  20+ MCP Tools           │  │
│  ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜  │
ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¬ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜
              │ HTTPS
              ā–¼
    ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”
    │  Circle.so API   │
    ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜
```

**Authentication Flow:**
1. User triggers `authenticate_with_google` tool
2. OAuth server starts on localhost:3000
3. Browser opens for Google sign-in
4. User authorizes the application
5. Server receives OAuth callback with authorization code
6. Exchanges code for GCP access/refresh tokens
7. Retrieves user email from Google
8. Authenticates with Circle API using email
9. Stores both GCP and Circle tokens securely

---

## šŸ“¦ Prerequisites

Before you begin, ensure you have:

- **Node.js** v18 or higher ([Download](https://nodejs.org/))
- **npm** v9 or higher (comes with Node.js)
- **TypeScript** knowledge (helpful but not required)
- **Google Cloud Platform account** (free tier works)
- **Circle.so community** with headless access token
- **AI Assistant** that supports MCP (Claude Desktop, VS Code with Cline, etc.)

---

## šŸš€ Installation

### 1. Clone or Download the Project

```bash
cd /path/to/your/projects
# If you have this as a git repo:
git clone <repository-url> circle-mcp
cd circle-mcp

# Or if you already have the folder:
cd circle-mcp
```

### 2. Install Dependencies

```bash
npm install
```

This installs all required packages:
- `@modelcontextprotocol/sdk` - MCP protocol implementation
- `google-auth-library` - Google OAuth 2.0
- `googleapis` - Google APIs
- `express` - OAuth callback server
- `axios` - HTTP client
- `winston` - Logging
- `zod` - Schema validation
- And more...

---

## āš™ļø Configuration

### 1. Google Cloud Platform (GCP) Setup

#### Step 1.1: Create a GCP Project

1. Go to [Google Cloud Console](https://console.cloud.google.com/)
2. Click "Select a project" → "New Project"
3. Enter project name (e.g., "Circle MCP Auth")
4. Click "Create"

#### Step 1.2: Enable Google+ API

1. In your project, go to **APIs & Services** → **Library**
2. Search for "Google+ API"
3. Click on it and press **Enable**

#### Step 1.3: Configure OAuth Consent Screen

1. Go to **APIs & Services** → **OAuth consent screen**
2. Choose **External** (unless you have a Google Workspace)
3. Fill in the required fields:
   - **App name**: Circle MCP Server
   - **User support email**: Your email
   - **Developer contact**: Your email
4. Click **Save and Continue**
5. **Scopes**: Skip this step (click Save and Continue)
6. **Test users**: Add your Google account email
7. Click **Save and Continue**

#### Step 1.4: Create OAuth 2.0 Credentials

1. Go to **APIs & Services** → **Credentials**
2. Click **Create Credentials** → **OAuth 2.0 Client ID**
3. Choose **Web application**
4. Configure:
   - **Name**: Circle MCP OAuth Client
   - **Authorized redirect URIs**: Add `http://localhost:3000/auth/google/callback`
5. Click **Create**
6. **Save your credentials**:
   - Copy the **Client ID** (ends with `.apps.googleusercontent.com`)
   - Copy the **Client Secret** (starts with `GOCSPX-`)

### 2. Environment Variables

Create a `.env` file in the project root:

```bash
# Create .env file
touch .env
```

Add the following configuration:

```env
# Circle.so Configuration
CIRCLE_HEADLESS_TOKEN=your_circle_headless_token
CIRCLE_COMMUNITY_URL=https://your-community.circle.so
CIRCLE_HEADLESS_BASE_URL=https://app.circle.so

# Google Cloud Platform OAuth 2.0
GCP_CLIENT_ID=your-client-id-here.apps.googleusercontent.com
GCP_CLIENT_SECRET=GOCSPX-your-client-secret-here
GCP_REDIRECT_URI=http://localhost:3000/auth/google/callback
OAUTH_PORT=3000

# Server Configuration
READ_ONLY_MODE=false
LOG_LEVEL=info
```

#### How to Get Circle Credentials:

1. **Circle Headless Token**:
   - Log in to your Circle community admin panel
   - Go to Settings → API
   - Generate a headless access token
   - Copy the token

2. **Circle Community URL**:
   - Your community's URL (e.g., `https://learn.1to10x.ai`)

#### Configuration Options:

| Variable | Required | Description | Example |
|----------|----------|-------------|---------|
| `CIRCLE_HEADLESS_TOKEN` | Yes | Circle API headless token | `abc123...` |
| `CIRCLE_COMMUNITY_URL` | Yes | Your Circle community URL | `https://community.circle.so` |
| `GCP_CLIENT_ID` | Yes | Google OAuth Client ID | `123-abc.apps.googleusercontent.com` |
| `GCP_CLIENT_SECRET` | Yes | Google OAuth Client Secret | `GOCSPX-abcd1234` |
| `GCP_REDIRECT_URI` | Yes | OAuth callback URL | `http://localhost:3000/auth/google/callback` |
| `OAUTH_PORT` | No | OAuth server port (default: 3000) | `3000` |
| `READ_ONLY_MODE` | No | Disable write operations (default: false) | `false` |
| `LOG_LEVEL` | No | Logging level (default: info) | `info` |

---

## šŸ”Ø Building & Testing

### Build the Project

```bash
npm run build
```

This compiles TypeScript to JavaScript in the `dist/` folder.

### Verify Setup

```bash
node verify-setup.js
```

This checks:
- āœ… All required files exist
- āœ… Dependencies are installed
- āœ… Environment variables are configured
- āœ… TypeScript compiles without errors
- āœ… Port 3000 is available
- āœ… GCP credentials are valid

### Test OAuth Flow

```bash
# Configuration test
node test-oauth-flow.js

# Automated server test
node test-oauth-automated.js

# Interactive OAuth testing
node test-oauth-interactive.js
```

### Run the Server

```bash
npm start
```

---

## šŸ–„ļø IDE Integration

### 1. Claude Desktop

Claude Desktop is Anthropic's official desktop app that supports MCP servers.

#### Step 1.1: Install Claude Desktop

Download from [claude.ai](https://claude.ai/download)

#### Step 1.2: Locate Configuration File

The configuration file location depends on your OS:

**macOS:**
```bash
~/Library/Application Support/Claude/claude_desktop_config.json
```

**Windows:**
```bash
%APPDATA%\Claude\claude_desktop_config.json
```

**Linux:**
```bash
~/.config/Claude/claude_desktop_config.json
```

#### Step 1.3: Edit Configuration

Open `claude_desktop_config.json` and add:

```json
{
  "mcpServers": {
    "circle": {
      "command": "node",
      "args": ["C:\\Users\\admin\\Desktop\\circle-mcp\\dist\\index.js"],
      "env": {
        "CIRCLE_HEADLESS_TOKEN": "your_circle_token_here",
        "CIRCLE_COMMUNITY_URL": "https://your-community.circle.so",
        "CIRCLE_HEADLESS_BASE_URL": "https://app.circle.so",
        "GCP_CLIENT_ID": "your-client-id.apps.googleusercontent.com",
        "GCP_CLIENT_SECRET": "GOCSPX-your-secret",
        "GCP_REDIRECT_URI": "http://localhost:3000/auth/google/callback",
        "OAUTH_PORT": "3000",
        "LOG_LEVEL": "info"
      }
    }
  }
}
```

**Important Notes:**
- Replace `C:\\Users\\admin\\Desktop\\circle-mcp\\dist\\index.js` with your actual path
- On Windows, use double backslashes (`\\`) or forward slashes (`/`)
- On macOS/Linux, use forward slashes (`/`)
- Replace all credential placeholders with your actual values

#### Step 1.4: Restart Claude Desktop

1. Quit Claude Desktop completely
2. Relaunch Claude Desktop
3. The Circle MCP server will start automatically

#### Step 1.5: Verify Integration

In Claude Desktop, type:

```
Can you check if the Circle MCP server is connected?
```

If connected, Claude can use tools like:
```
Please authenticate with Google so I can access Circle features.
```

### 2. VS Code with Cline

Cline is a VS Code extension that supports MCP servers.

#### Step 2.1: Install Cline Extension

1. Open VS Code
2. Go to Extensions (Ctrl+Shift+X / Cmd+Shift+X)
3. Search for "Cline"
4. Click Install

#### Step 2.2: Configure Cline

1. Open Command Palette (Ctrl+Shift+P / Cmd+Shift+P)
2. Type "Cline: Open Settings"
3. Navigate to MCP Servers section
4. Click "Edit in settings.json"

Add this configuration:

```json
{
  "cline.mcpServers": {
    "circle": {
      "command": "node",
      "args": ["/absolute/path/to/circle-mcp/dist/index.js"],
      "env": {
        "CIRCLE_HEADLESS_TOKEN": "your_token",
        "CIRCLE_COMMUNITY_URL": "https://your-community.circle.so",
        "GCP_CLIENT_ID": "your-client-id.apps.googleusercontent.com",
        "GCP_CLIENT_SECRET": "GOCSPX-your-secret",
        "GCP_REDIRECT_URI": "http://localhost:3000/auth/google/callback"
      }
    }
  }
}
```

#### Step 2.3: Reload VS Code

1. Open Command Palette
2. Type "Developer: Reload Window"
3. Press Enter

#### Step 2.4: Use Circle Tools in Cline

Open Cline chat and try:
```
Authenticate with Google to access Circle community
```

### 3. Other MCP Clients

#### MCP Inspector (Testing Tool)

For development and debugging:

```bash
npx @modelcontextprotocol/inspector node dist/index.js
```

Then open http://localhost:6274 in your browser.

#### Custom Integration

Any MCP-compatible client can connect using stdio transport:

```typescript
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';

const transport = new StdioClientTransport({
  command: 'node',
  args: ['/path/to/circle-mcp/dist/index.js'],
  env: { /* environment variables */ }
});

const client = new Client({
  name: 'my-client',
  version: '1.0.0'
}, {
  capabilities: {}
});

await client.connect(transport);
```

---

## šŸ› ļø Available Tools

The Circle MCP server provides 20+ tools across multiple categories:

### Authentication Tools

| Tool | Description | Auth Required |
|------|-------------|---------------|
| `authenticate_with_google` | Start Google OAuth flow | No |
| `check_auth_status` | Check current authentication status | No |
| `logout` | Logout and clear tokens | Yes |

### Profile Tools

| Tool | Description | Auth Required |
|------|-------------|---------------|
| `get_my_profile` | Get your Circle profile | Yes |
| `update_my_profile` | Update your profile | Yes |

### Course Tools

| Tool | Description | Auth Required |
|------|-------------|---------------|
| `get_my_courses` | Get courses you're enrolled in | Yes |
| `get_course_details` | Get detailed course information | Yes |

### Post Tools

| Tool | Description | Auth Required |
|------|-------------|---------------|
| `get_posts` | Get posts from community | Yes |
| `create_post` | Create a new post | Yes |
| `update_post` | Update an existing post | Yes |
| `delete_post` | Delete a post | Yes |
| `like_post` | Like a post | Yes |
| `unlike_post` | Unlike a post | Yes |

### Space Tools

| Tool | Description | Auth Required |
|------|-------------|---------------|
| `get_spaces` | Get all community spaces | Yes |
| `get_space_members` | Get members of a space | Yes |

### Event Tools

| Tool | Description | Auth Required |
|------|-------------|---------------|
| `get_events` | Get upcoming events | Yes |
| `get_event_details` | Get event details | Yes |
| `rsvp_event` | RSVP to an event | Yes |

### Notification Tools

| Tool | Description | Auth Required |
|------|-------------|---------------|
| `get_notifications` | Get your notifications | Yes |
| `mark_notification_read` | Mark notification as read | Yes |

### Message Tools

| Tool | Description | Auth Required |
|------|-------------|---------------|
| `get_direct_messages` | Get your direct messages | Yes |
| `send_direct_message` | Send a direct message | Yes |

### Feed Tools

| Tool | Description | Auth Required |
|------|-------------|---------------|
| `get_feed` | Get your personalized feed | Yes |

### Comment Tools

| Tool | Description | Auth Required |
|------|-------------|---------------|
| `get_post_comments` | Get comments on a post | Yes |
| `create_comment` | Create a comment | Yes |
| `update_comment` | Update a comment | Yes |
| `delete_comment` | Delete a comment | Yes |

---

## šŸ“š Usage Examples

### Example 1: Authenticate with Google

**User prompt in Claude Desktop:**
```
Please authenticate with Google so I can access Circle features
```

**What happens:**
1. MCP server receives `authenticate_with_google` tool call
2. OAuth server starts on http://localhost:3000
3. Browser opens for Google sign-in
4. User signs in and authorizes
5. Tokens are exchanged and stored
6. Circle authentication completes

### Example 2: Get Your Profile

**User prompt:**
```
Show me my Circle profile
```

**MCP tool called:**
```json
{
  "name": "get_my_profile",
  "arguments": {}
}
```

**Response:**
```json
{
  "name": "John Doe",
  "email": "john@example.com",
  "bio": "Community member",
  "member_since": "2024-01-15"
}
```

### Example 3: Get Your Courses

**User prompt:**
```
What courses am I enrolled in?
```

**MCP tool called:**
```json
{
  "name": "get_my_courses",
  "arguments": {}
}
```

### Example 4: Create a Post

**User prompt:**
```
Create a post in the General space with title "Hello World" and body "This is my first post!"
```

**MCP tool called:**
```json
{
  "name": "create_post",
  "arguments": {
    "space_id": "12345",
    "title": "Hello World",
    "body": "This is my first post!"
  }
}
```

### Example 5: Get Events

**User prompt:**
```
Show me upcoming events in the community
```

**MCP tool called:**
```json
{
  "name": "get_events",
  "arguments": {}
}
```

---

## šŸ› Troubleshooting

### Issue: "GCP_CLIENT_ID not configured"

**Solution:**
1. Ensure `.env` file exists in project root
2. Add `GCP_CLIENT_ID` with your actual Google OAuth Client ID
3. Verify the Client ID ends with `.apps.googleusercontent.com`

### Issue: "redirect_uri_mismatch"

**Error Message:**
```
Error 400: redirect_uri_mismatch
```

**Solution:**
1. Go to [Google Cloud Console](https://console.cloud.google.com/)
2. Navigate to APIs & Services → Credentials
3. Click on your OAuth 2.0 Client ID
4. Under "Authorized redirect URIs", add exactly:
   ```
   http://localhost:3000/auth/google/callback
   ```
5. Click Save
6. Wait 5 minutes for changes to propagate

### Issue: "Port 3000 already in use"

**Solution:**
Change the port in `.env`:
```env
OAUTH_PORT=3001
GCP_REDIRECT_URI=http://localhost:3001/auth/google/callback
```

**Remember:** Update the redirect URI in Google Cloud Console too!

### Issue: "User not found in Circle community"

**Error Message:**
```
Circle authentication failed: User not found
```

**Solution:**
1. Ensure your Google account email is registered in the Circle community
2. Go to your Circle community and check your account email
3. Make sure it matches the Google account you're using to authenticate

### Issue: Browser doesn't open during OAuth

**Solution:**
1. Check the terminal for the OAuth URL
2. Manually copy and paste the URL into your browser
3. Complete the authentication flow

### Issue: TypeScript compilation errors

**Solution:**
```bash
# Clean and rebuild
rm -rf dist node_modules
npm install
npm run build
```

### Issue: "Cannot find module" errors

**Solution:**
```bash
# Reinstall dependencies
npm install
```

### Issue: MCP Server not showing in Claude Desktop

**Solution:**
1. Check `claude_desktop_config.json` syntax (valid JSON)
2. Verify the path to `dist/index.js` is absolute and correct
3. Ensure the server builds successfully (`npm run build`)
4. Restart Claude Desktop completely (quit and relaunch)
5. Check Claude Desktop logs:
   - macOS: `~/Library/Logs/Claude/mcp*.log`
   - Windows: `%APPDATA%\Claude\logs\mcp*.log`

### Issue: OAuth authentication fails silently

**Solution:**
1. Check if you added your email as a test user in GCP OAuth consent screen
2. Verify your GCP project has Google+ API enabled
3. Check server logs for detailed error messages
4. Try the interactive test: `node test-oauth-interactive.js`

---

## šŸ‘Øā€šŸ’» Development

### Project Structure

```
circle-mcp/
ā”œā”€ā”€ src/
│   ā”œā”€ā”€ index.ts                 # Entry point
│   ā”œā”€ā”€ server.ts                # MCP server implementation
│   ā”œā”€ā”€ config/
│   │   └── config.ts            # Configuration management
│   ā”œā”€ā”€ auth/
│   │   ā”œā”€ā”€ gcp-auth.ts          # Google OAuth 2.0
│   │   ā”œā”€ā”€ integrated-auth-manager.ts  # Auth orchestration
│   │   ā”œā”€ā”€ oauth-server.ts      # OAuth callback server
│   │   ā”œā”€ā”€ token-manager.ts     # Token refresh logic
│   │   └── user-storage.ts      # User data persistence
│   ā”œā”€ā”€ api/
│   │   ā”œā”€ā”€ client.ts            # Circle API client
│   │   └── endpoints.ts         # API endpoints
│   ā”œā”€ā”€ tools/
│   │   ā”œā”€ā”€ auth-wrapper.ts      # Authentication wrapper
│   │   ā”œā”€ā”€ profile.ts           # Profile tools
│   │   ā”œā”€ā”€ courses.ts           # Course tools
│   │   ā”œā”€ā”€ posts.ts             # Post tools
│   │   ā”œā”€ā”€ spaces.ts            # Space tools
│   │   ā”œā”€ā”€ events.ts            # Event tools
│   │   ā”œā”€ā”€ notifications.ts     # Notification tools
│   │   ā”œā”€ā”€ messages.ts          # Message tools
│   │   ā”œā”€ā”€ feed.ts              # Feed tools
│   │   └── comments.ts          # Comment tools
│   ā”œā”€ā”€ types/
│   │   └── circle.ts            # TypeScript types
│   └── utils/
│       ā”œā”€ā”€ error-handler.ts     # Error handling
│       ā”œā”€ā”€ logger.ts            # Winston logger
│       └── validators.ts        # Input validation
ā”œā”€ā”€ dist/                        # Compiled JavaScript
ā”œā”€ā”€ test-oauth-flow.js           # Configuration test
ā”œā”€ā”€ test-oauth-automated.js      # Automated tests
ā”œā”€ā”€ test-oauth-interactive.js    # Interactive OAuth test
ā”œā”€ā”€ verify-setup.js              # Setup verification
ā”œā”€ā”€ package.json
ā”œā”€ā”€ tsconfig.json
ā”œā”€ā”€ .env                         # Environment variables (create this)
└── README.md
```

### Available Scripts

```bash
# Development
npm run build          # Compile TypeScript
npm run typecheck      # Type check without building
npm start              # Start the MCP server
npm run dev            # Development mode with watch

# Testing
node verify-setup.js              # Verify complete setup
node test-oauth-flow.js           # Test OAuth configuration
node test-oauth-automated.js      # Automated server tests
node test-oauth-interactive.js    # Interactive OAuth testing

# Debugging
npx @modelcontextprotocol/inspector node dist/index.js  # MCP Inspector
```

### Adding New Tools

1. Create a new file in `src/tools/your-tool.ts`
2. Import the authentication wrapper:
   ```typescript
   import { withAuthentication } from './auth-wrapper.js';
   ```
3. Define your tool with authentication:
   ```typescript
   export function registerYourTools(
     server: McpServer,
     apiClient: CircleAPIClient,
     authManager: IntegratedAuthManager
   ) {
     server.registerTool(
       'your_tool_name',
       {
         description: 'What your tool does',
         inputSchema: zodToJsonSchema(YourInputSchema)
       },
       withAuthentication(authManager, async (params) => {
         const email = (params as any).authenticatedEmail;
         // Your implementation
       })
     );
   }
   ```
4. Register in `src/server.ts`

### Environment Variables for Development

```env
# Enable debug logging
LOG_LEVEL=debug

# Test with read-only mode
READ_ONLY_MODE=true

# Use different OAuth port
OAUTH_PORT=3001
```

### Running Tests

```bash
# Full test suite
npm run build
node verify-setup.js
node test-oauth-automated.js
node test-oauth-interactive.js
```

### Debugging Tips

1. **Enable debug logging:**
   ```env
   LOG_LEVEL=debug
   ```

2. **Check MCP Inspector:**
   ```bash
   npx @modelcontextprotocol/inspector node dist/index.js
   ```

3. **Monitor server logs:**
   - Logs are output to stderr
   - In Claude Desktop, check log files in the Claude logs directory

4. **Test authentication separately:**
   ```bash
   node test-oauth-interactive.js
   ```

---

## šŸ“„ License

MIT License - see LICENSE file for details

---

## šŸ¤ Contributing

Contributions are welcome! Please:

1. Fork the repository
2. Create a feature branch
3. Make your changes
4. Add tests if applicable
5. Submit a pull request

---

## šŸ“ž Support

If you encounter issues:

1. Check the [Troubleshooting](#-troubleshooting) section
2. Review server logs for detailed error messages
3. Run `node verify-setup.js` to check configuration
4. Test OAuth flow with `node test-oauth-interactive.js`
5. Check GCP OAuth consent screen configuration
6. Verify your email is added as a test user (if app is in testing mode)

---

## šŸŽ‰ Quick Start Summary

```bash
# 1. Install dependencies
npm install

# 2. Create .env file with your credentials
cp .env.example .env  # Then edit with your values

# 3. Build the project
npm run build

# 4. Verify setup
node verify-setup.js

# 5. Test OAuth
node test-oauth-interactive.js

# 6. Add to Claude Desktop config
# Edit claude_desktop_config.json (see IDE Integration section)

# 7. Restart Claude Desktop and start chatting!
```

---

**Built with ā¤ļø using [Model Context Protocol](https://modelcontextprotocol.io/)**