Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,5 @@ profile.json
.vscode
.env
.venv

*.egg-info
182 changes: 182 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
# CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

## Project Overview

This is a Model Context Protocol (MCP) server that integrates with Notion's API to manage todo lists. The server provides three main functions: adding todos, viewing all todos, and marking todos as complete.

## Development Environment

- **Python Version**: 3.11 or higher (specified in `.python-version`)
- **Package Manager**: `uv` (preferred)
- **Virtual Environment**: `.venv` directory

## Setup Commands

```bash
# Set up virtual environment and install dependencies
uv venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
uv pip install -e .

# Run the MCP server
uv --directory src run server.py
```

## Configuration

The project requires environment variables defined in `.env`:

- `NOTION_TOKEN`: Notion API integration token
- `PAGE_ID`: Target Notion page ID for todo management
- `NOTION_VERSION`: API version (typically "2022-06-28")
- `NOTION_BASE_URL`: Base URL for Notion API

## Architecture

### Core Components

- **`src/server.py`**: Single main file containing the entire MCP server implementation
- **Server Class**: Uses the `mcp.server.Server` framework
- **Async Functions**: All Notion API interactions are asynchronous using `httpx.AsyncClient`

### MCP Tools

The server implements three tools:

1. `add_todo` - Creates new todo items on the Notion page
2. `show_all_todos` - Fetches and displays all todos with their completion status
3. `complete_todo` - Marks a specific todo as completed using its task_id

### Key Functions

- `fetch_todos_on_page()`: Handles pagination to retrieve all todo blocks from a Notion page
- `create_todo_on_page()`: Adds new todo blocks using PATCH to `/blocks/{PAGE_ID}/children`
- `complete_todo_on_page()`: Updates todo completion status using PATCH to `/blocks/{task_id}`

### Error Handling

The codebase includes comprehensive error handling for:

- Missing environment variables
- Notion API HTTP errors
- Invalid function arguments
- Missing todo items

## Integration with Claude Desktop

Configure in `claude_desktop_config.json`:

```json
{
"mcpServers": {
"notion-mcp": {
"command": "uv",
"args": [
"--directory",
"/path/to/notion-mcp/src",
"run",
"server.py"
]
}
}
}
```

# CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

## Project Overview

This is a Model Context Protocol (MCP) server that integrates with Notion's API to manage todo lists. The server provides three main functions: adding todos, viewing all todos, and marking todos as complete.

## Development Environment

- **Python Version**: 3.11 or higher (specified in `.python-version`)
- **Package Manager**: `uv` (preferred)
- **Virtual Environment**: `.venv` directory

## Setup Commands

```bash
# Set up virtual environment and install dependencies
uv venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
uv pip install -e .

# Run the MCP server
uv --directory src run server.py

# Test with MCP Inspector
npx @modelcontextprotocol/inspector \
uv \
--directory /Users/badhan/Projects/Python/notion-mcp/src \
run \
server.py
```

## Configuration

The project requires environment variables defined in `.env`:

- `NOTION_TOKEN`: Notion API integration token
- `PAGE_ID`: Target Notion page ID for todo management
- `NOTION_VERSION`: API version (typically "2022-06-28")
- `NOTION_BASE_URL`: Base URL for Notion API

## Architecture

### Core Components

- **`src/server.py`**: Single main file containing the entire MCP server implementation
- **Server Class**: Uses the `mcp.server.Server` framework
- **Async Functions**: All Notion API interactions are asynchronous using `httpx.AsyncClient`

### MCP Tools

The server implements three tools:

1. `add_todo` - Creates new todo items on the Notion page
2. `show_all_todos` - Fetches and displays all todos with their completion status
3. `complete_todo` - Marks a specific todo as completed using its task_id

### Key Functions

- `fetch_todos_on_page()`: Handles pagination to retrieve all todo blocks from a Notion page
- `create_todo_on_page()`: Adds new todo blocks using PATCH to `/blocks/{PAGE_ID}/children`
- `complete_todo_on_page()`: Updates todo completion status using PATCH to `/blocks/{task_id}`

### Error Handling

The codebase includes comprehensive error handling for:

- Missing environment variables
- Notion API HTTP errors
- Invalid function arguments
- Missing todo items

## Integration with Claude Desktop

Configure in `claude_desktop_config.json`:

```json
{
"mcpServers": {
"notion-mcp": {
"command": "uv",
"args": [
"--directory",
"/path/to/notion-mcp/src",
"run",
"server.py"
]
}
}
}
```

## Deployment

The project supports deployment via Smithery with configuration in `smithery.yaml`. The Smithery configuration handles environment variable mapping and provides a schema for required configuration options.
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,34 @@ notion-mcp/
└── uv.lock
```

### Testing with MCP Inspector

The [MCP Inspector](https://github.com/modelcontextprotocol/inspector) is an interactive developer tool for testing and debugging MCP servers. It provides a user-friendly interface to test your server functions without needing to integrate with Claude Desktop first.

To run the MCP Inspector with this server:

```bash
npx @modelcontextprotocol/inspector \
uv \
--directory /Users/username/Projects/Python/notion-mcp/src \
run \
server.py
```

The Inspector will:

- Start your MCP server in debug mode
- Provide a web interface to test all available tools
- Show real-time logs and responses
- Allow you to validate your Notion integration before using with Claude Desktop

This is particularly useful for:

- Testing your Notion API credentials and permissions
- Debugging tool responses and error handling
- Verifying your todo list operations work correctly
- Understanding the JSON structure of responses

## Support Functions

#### Show Tasks
Expand Down
51 changes: 51 additions & 0 deletions src/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
from mcp.server import Server
from dotenv import load_dotenv
from pathlib import Path
import os


class EnvironmentConfig:
def __init__(self):
self._load_env_file()
self._load_variables()
self._create_headers()

def _load_env_file(self):
"""Load .env file from project root"""
project_root = Path(__file__).resolve().parent.parent
env_path = project_root / '.env'

if not env_path.exists():
raise FileNotFoundError(f"No .env file found at {env_path}")

load_dotenv(env_path)

def _load_variables(self):
"""Load environment variables"""
self.NOTION_TOKEN = os.getenv("NOTION_TOKEN")
self.DATABSE_ID = os.getenv("DATABSE_ID")
self.PAGE_ID = os.getenv("PAGE_ID")
self.NOTION_VERSION = os.getenv("NOTION_VERSION")
self.NOTION_BASE_URL = os.getenv("NOTION_BASE_URL")

def _create_headers(self):
"""Create Notion API headers"""
self.headers = {
"Authorization": f"Bearer {self.NOTION_TOKEN}",
"Content-Type": "application/json",
"Notion-Version": self.NOTION_VERSION
}

def validate(self):
"""Validate required environment variables"""
if not self.NOTION_TOKEN or not self.PAGE_ID:
raise ValueError("NOTION_TOKEN and PAGE_ID environment variables are required")
return True


# Create global config instance
config = EnvironmentConfig()
config.validate()

# Create a named server
server = Server("notion-mcp")
Loading