This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
This is a Haskell project using Cabal as its build system.
cabal build- Build the project (all executables)cabal run mcp- Run the StdIO MCP servercabal run mcp-http- Run the HTTP MCP server examplecabal test- Run the test suitecabal repl- Start a GHCi REPL with the project loadedcabal clean- Clean build artifacts
This is an implementation of the Model Context Protocol (MCP) for Haskell. The project structure follows standard Haskell conventions:
- src/MCP/Types.hs - Core MCP data types and JSON serialization
- src/MCP/Protocol.hs - JSON-RPC protocol messages and types
- src/MCP/Server.hs - Core server infrastructure and MCPServer typeclass
- src/MCP/Server/StdIO.hs - StdIO transport for process-based clients
- src/MCP/Server/HTTP.hs - HTTP transport following MCP specification
- app/Main.hs - Example MCP server implementation (StdIO mode)
- test/Main.hs - Test suite entry point (currently a placeholder)
- schema.ts - Contains the complete MCP protocol TypeScript schema definitions (2025-06-18)
The project uses GHC2021 language extensions and targets base ^>=4.18.2.1.
The schema.ts file contains the full MCP protocol specification (version 2025-06-18) including:
- Client/Server request and response types
- Notification types for both directions
- Resource, Tool, and Prompt management
- JSON-RPC message formats
- Capability negotiation structures
- Enhanced content blocks and metadata support
- Elicitation system for user input
- OAuth 2.1 authorization framework
When implementing MCP functionality, refer to the schema.ts for the exact message formats and type definitions required by the protocol.
The implementation supports two transport methods:
- Uses stdin/stdout for JSON-RPC communication
- Suitable for process-based MCP clients like Claude Desktop
- Default transport used by
cabal run mcp
- RESTful HTTP API with multiple endpoints:
/mcp- Main MCP endpoint for JSON-RPC requests/.well-known/oauth-authorization-server- OAuth metadata discovery/register- Dynamic client registration/authorize- OAuth authorization with PKCE/token- Token exchange endpoint
- Follows the official MCP HTTP transport specification
- Built with Servant and Warp for production use
- Complete OAuth 2.0 implementation:
- Metadata discovery for automatic configuration
- Dynamic client registration (no pre-registration needed)
- Authorization code flow with mandatory PKCE (S256)
- Bearer token authentication
- Refresh token support with rotation
- In-memory storage for demo (can be replaced with persistent storage)
- Security features:
- PKCE required for all OAuth flows (MCP compliance)
- 10-minute authorization code expiry
- 1-hour access token validity
- Public client support (no client secret)
- Redirect URI validation
- Configurable OAuth providers (Google, GitHub, custom)
- JWT support via servant-auth-server
Both transports use the same MCPServer typeclass, so server implementations work with either transport method.
When implementing OAuth features or modifying the authentication flow:
- HTTPServerConfig - Main server configuration with httpBaseUrl, httpProtocolVersion, etc.
- OAuthConfig - Comprehensive OAuth configuration with timing, demo settings, and parameters
- OAuthState - Server state containing auth codes, tokens, and registered clients
- ClientRegistrationRequest/Response - Dynamic client registration
- AuthorizationCode - Stores PKCE challenge and expiry
- TokenResponse - Standard OAuth token response format
- OAuthMetadata - Server metadata for discovery
- Client Registration: Returns configurable client_secret (default empty string for public clients)
- PKCE Validation: Uses validateCodeVerifier from MCP.Server.Auth
- Token Generation:
- Authorization codes: UUID v4 with configurable prefix (default "code_")
- Access tokens: JWT tokens using servant-auth-server's makeJWT
- Refresh tokens: UUID v4 with configurable prefix (default "rt_")
- Expiry Times: Configurable auth code and access token expiry (defaults: 10 min, 1 hour)
- Demo Mode: Configurable auto-approval and demo user generation
- JWT Integration: Proper JWT tokens fix authentication loops with MCP clients
- Production Ready: All hardcoded values extracted to configuration parameters
HTTPServerConfig now includes:
httpBaseUrl: Base URL for OAuth endpoints (e.g., "https://api.example.com")httpProtocolVersion: MCP protocol version (default "2025-06-18")
OAuthConfig includes comprehensive settings:
- Timing:
authCodeExpirySeconds,accessTokenExpirySeconds - OAuth parameters:
supportedScopes,supportedResponseTypes, etc. - Demo mode:
autoApproveAuth,demoUserIdTemplate,demoEmailDomain - Token prefixes:
authCodePrefix,refreshTokenPrefix,clientIdPrefix - Templates:
authorizationSuccessTemplatefor custom responses
For demo/testing, use defaultDemoOAuthConfig and override specific fields.
For production, configure all parameters according to your security requirements.
# Start server with OAuth
cabal run mcp-http -- --oauth
# Test metadata discovery
curl http://localhost:8080/.well-known/oauth-authorization-server
# Run full OAuth demo
./examples/oauth-client-demo.sh