CLAUDE
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Project Overview
Raku implementation of the Model Context Protocol (MCP) SDK. MCP is an open standard that allows AI models to interact with external data and tools. This SDK enables building MCP servers and clients in Raku to integrate with LLM applications like Claude Desktop.
Build Commands
make all # Full pipeline: dependencies + build + test
make build # Validate metadata and precompile modules
make test # Run complete test suite
make test-verbose # Run tests with verbose output
make test-file FILE=t/03-builders.rakutest # Run specific test
make lint # Run syntax and META6.json validation
make check # Run lint and tests together
make coverage # Generate test coverage report
make benchmark # Run performance benchmarks
make run-example EXAMPLE=simple-server # Run example server
make repl # Start REPL with project loaded
make benchmark # Run performance benchmarks
make stress # Run stress testsEnvironment: V=1 for verbose output, NO_COLOR=1 to disable colors.
Architecture
MCP.rakumod (main entry point, re-exports all public API)
āāā MCP::Types # Protocol types: Content, Tool, Resource, Prompt, Capabilities
āāā MCP::JSONRPC # JSON-RPC 2.0 message types and parsing
āāā MCP::Server # Server initialization, request dispatch, lifecycle
āāā MCP::Client # Client initialization, sampling support
āāā MCP::Server::Tool/Resource/Prompt # Fluent builders for primitives
āāā MCP::Transport::Base/Stdio/StreamableHTTP/SSE # Transport layer
āāā MCP::OAuth / OAuth::Client / OAuth::Server # OAuth 2.1 authorizationProtocol: JSON-RPC 2.0 over Stdio, Streamable HTTP, or Legacy SSE. Targets MCP spec 2025-11-25.
Key Patterns
Builder Pattern for tools, resources, and prompts:
my $tool = tool()
.name('add')
.description('Add two numbers')
.input-schema(%schema)
.handler(-> :%params { $params<a> + $params<b> })
.build;Multi-dispatch handlers - SDK calls handlers with multiple signature styles:
&handler(:params(%args)) # Named pair
&handler(|%args) # Slip
&handler(%args) # Hash
&handler() # No args fallbackResult normalization - Handlers can return various types; SDK auto-wraps:
StrāTextContentBlobā Binary contentDirect MCP types pass through unchanged
Async model - Uses Raku's Promises and Supplies for concurrent messaging.
Test Structure
Tests in t/ numbered by layer:
01-types.rakutest- Type constructors, serialization02-jsonrpc.rakutest- JSON-RPC message handling03-builders.rakutest- Tool/Resource/Prompt builders04-transport.rakutest- Transport interface05-server.rakutest- Server initialization, dispatch06-client.rakutest- Client initialization07-mcp.rakutest- Top-level exports08-sampling.rakutest- Sampling/createMessage09-http-transport.rakutest- HTTP transport10-oauth.rakutest- OAuth 2.1 types, PKCE, server/client handlers11-tasks.rakutest- Tasks framework (async tools, polling, cancellation)12-extensions.rakutest- Extensions framework (registration, dispatch, capabilities)13-resource-templates.rakutest- Resource templates (URI templates, matching, builder)14-sse-transport.rakutest- Legacy SSE transport
Dependencies
Runtime: JSON::Fast, Cro::HTTP, MIME::Base64
Optional (loaded at runtime): Digest::SHA256::Native (for OAuth PKCE)
Dev: Test, Test::META, App::Prove6, Test::Coverage
Implementation Status
See GAP_ANALYSIS.md for detailed feature comparison with MCP spec. No significant gaps remain.