Skip to content

A FastMCP-based Model Context Protocol server providing timezone conversion tools with OAuth2 PKCE authentication support.

Notifications You must be signed in to change notification settings

gvaibhav/fastmcp-auth

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Time MCP Server with OAuth2 PKCE

A FastMCP-based Model Context Protocol server providing timezone conversion tools with OAuth2 PKCE authentication support.

Features

  • OAuth2 PKCE Authentication: Secure OAuth flow implementation
  • SSE Transport: Server-Sent Events for real-time communication
  • Timezone Tools: Get current time and convert between timezones
  • IANA Timezone Support: All standard timezone conversions
  • Mock OAuth Server: Built-in testing OAuth server

Quick Start

1. Setup Environment

# Create and activate virtual environment
python -m venv venv
.\venv\Scripts\Activate.ps1

# Install dependencies
pip install -r requirements.txt

2. Run Servers

Option A: Simple Server (No Auth)

python simplified_server.py

Option B: OAuth-Ready Server (SSE Mode)

# Terminal 1 - Mock OAuth Server
python mock_oauth_server.py

# Terminal 2 - MCP Server
python time_mcp_server.py

Option C: Clean Server (Reduced Logging)

python time_mcp_server_clean.py

Available Tools

get_current_time

Get the current time in any timezone.

{
    "timezone": "America/New_York",
    "datetime": "2025-11-05T09:30:00-05:00",
    "is_dst": false
}

convert_time

Convert time between timezones.

{
    "source": {
        "timezone": "America/New_York",
        "datetime": "2025-11-05T16:30:00-05:00",
        "is_dst": false
    },
    "target": {
        "timezone": "Asia/Tokyo",
        "datetime": "2025-11-06T06:30:00+09:00",
        "is_dst": false
    },
    "time_difference": "+14.0h"
}

Available Resources

  • time://current - Current UTC time
  • time://timezones - List of available IANA timezones

Well-Known Endpoints

Authorization Server (port 8000)

  • GET /.well-known/oauth-authorization-server - OAuth 2.0 Authorization Server Metadata (RFC 8414)
  • GET /.well-known/openid-configuration - OpenID Connect Discovery

Protected Resource (port 3000)

  • GET /.well-known/oauth-protected-resource - OAuth 2.0 Protected Resource Metadata (RFC 9728)

Testing

# Test MCP tools
python test_server.py

# Test OAuth flow
python test_oauth_flow.py

# Test integration (requires both servers running)
python test_integration.py

# Test .well-known endpoints
python test_wellknown_endpoints.py

Configuration

Edit .env for OAuth settings:

CLIENT_ID=time-mcp-client
AUTH_URL=http://localhost:8000/oauth/authorize
TOKEN_URL=http://localhost:8000/oauth/token
SCOPES=time:read,time:convert

Architecture

┌─────────────────────────────────────────┐
│         Mock OAuth Server               │
│      (http://localhost:8000)            │
│  • /oauth/authorize                     │
│  • /oauth/token                         │
│  • PKCE validation                      │
└───────────┬─────────────────────────────┘
            │ OAuth2 PKCE Flow
            ▼
┌─────────────────────────────────────────┐
│      Time MCP Server (SSE)              │
│     (http://localhost:3000/sse)         │
│  Tools:                                 │
│  • get_current_time(timezone)           │
│  • convert_time(source, time, target)   │
│  Resources:                             │
│  • time://current                       │
│  • time://timezones                     │
└─────────────────────────────────────────┘

Project Structure

├── time_mcp_server.py          # Main OAuth-ready server (SSE)
├── time_mcp_server_clean.py    # Version with reduced logging
├── simplified_server.py        # No-auth version for testing
├── mock_oauth_server.py        # OAuth2 PKCE mock server
├── server.py                   # Working server file
├── test_server.py              # Unit tests (24 tests)
├── test_oauth_flow.py          # OAuth flow tests
├── test_integration.py         # Integration tests
├── requirements.txt            # Python dependencies
├── .env                        # OAuth configuration
├── .gitignore                  # Git ignore rules
├── run_server.ps1              # Quick start script (no auth)
└── run_sse_server.ps1          # Quick start script (SSE)

Server Comparison

Feature simplified_server.py time_mcp_server.py time_mcp_server_clean.py
OAuth Support
SSE Transport
Reduced Logging
Best For Testing/Development Production Production (clean logs)

Common Issues

SSE Disconnect Errors

When running the SSE server, you may see:

ERROR: TypeError: 'NoneType' object is not callable

This is expected behavior when testing with simple HTTP clients (curl, browser). Real MCP clients maintain long-lived connections and won't trigger this error.

Solutions:

  • Ignore the errors (they're harmless)
  • Use time_mcp_server_clean.py for reduced logging
  • Use simplified_server.py for testing without SSE

Test Results

  • OAuth Tests: ✅ 100% passing
  • Unit Tests: ✅ 95.8% passing (23/24)
  • Integration Tests: ✅ Passing

Next Steps

  1. Test with Real OAuth Provider

    • Replace mock server with actual OAuth gateway
    • Update URLs in .env
  2. Connect MCP Client

    • Claude Desktop
    • Custom MCP client
    • Test authenticated requests
  3. Deploy to Production

    • Configure SSL/TLS
    • Set up proper OAuth credentials
    • Deploy to cloud platform

License

MIT

Contributing

Pull requests welcome! Please ensure tests pass before submitting.

About

A FastMCP-based Model Context Protocol server providing timezone conversion tools with OAuth2 PKCE authentication support.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published