pmcp 1.9.0

High-quality Rust SDK for Model Context Protocol (MCP) with full TypeScript SDK compatibility
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
# Rust MCP SDK Makefile with pmat quality standards
# Zero tolerance for technical debt

CARGO = cargo
RUSTFLAGS = -D warnings
RUST_LOG ?= debug
RUST_BACKTRACE ?= 1

# Colors for output
RED = \033[0;31m
GREEN = \033[0;32m
YELLOW = \033[1;33m
BLUE = \033[0;34m
NC = \033[0m # No Color

# Default target
.PHONY: all
all: quality-gate

# Development setup
.PHONY: setup
setup:
	@echo "$(BLUE)Setting up development environment...$(NC)"
	rustup component add rustfmt clippy llvm-tools-preview
	cargo install cargo-audit cargo-outdated cargo-machete cargo-deny
	cargo install cargo-llvm-cov cargo-nextest cargo-mutants
	cargo install pmat  # PAIML MCP Agent Toolkit for extreme quality standards
	@if ! command -v pre-commit &> /dev/null; then \
		echo "$(BLUE)Installing pre-commit...$(NC)"; \
		pip install pre-commit || echo "$(YELLOW)⚠ Failed to install pre-commit via pip. Please install manually.$(NC)"; \
	fi
	@echo "$(GREEN)✓ Development environment ready$(NC)"

# Pre-commit setup - Toyota Way quality standards
.PHONY: setup-pre-commit
setup-pre-commit:
	@echo "$(BLUE)Setting up Toyota Way pre-commit hooks...$(NC)"
	@if ! command -v pre-commit &> /dev/null; then \
		echo "$(RED)❌ pre-commit not installed. Run 'make setup' first.$(NC)"; \
		exit 1; \
	fi
	pre-commit install
	pre-commit install --hook-type pre-push
	pre-commit install --hook-type commit-msg
	@echo "$(GREEN)✅ Pre-commit hooks installed with Toyota Way standards$(NC)"

.PHONY: setup-full
setup-full: setup setup-pre-commit
	@echo "$(GREEN)🏭 Toyota Way development environment fully configured$(NC)"

# WASM build targets
.PHONY: wasm-build
wasm-build:
	@echo "$(BLUE)Building for WASM target (wasm32-unknown-unknown)...$(NC)"
	$(CARGO) build --target wasm32-unknown-unknown --no-default-features --features wasm
	@echo "$(GREEN)✓ WASM build complete$(NC)"

.PHONY: wasm-release
wasm-release:
	@echo "$(BLUE)Building optimized WASM release...$(NC)"
	$(CARGO) build --target wasm32-unknown-unknown --release --no-default-features --features wasm
	@echo "$(GREEN)✓ WASM release build complete$(NC)"

# Cloudflare Worker SDK example targets
.PHONY: cloudflare-sdk-setup
cloudflare-sdk-setup:
	@echo "$(BLUE)Setting up Cloudflare Worker with SDK...$(NC)"
	@echo "$(GREEN)✓ SDK configuration already in place$(NC)"

.PHONY: cloudflare-sdk-build
cloudflare-sdk-build: cloudflare-sdk-setup
	@echo "$(BLUE)Building Cloudflare Worker with SDK...$(NC)"
	cd examples/cloudflare-worker-mcp && \
		cargo build --target wasm32-unknown-unknown --release --lib
	@echo "$(GREEN)✓ Cloudflare Worker SDK build complete$(NC)"

.PHONY: cloudflare-sdk-deploy
cloudflare-sdk-deploy: cloudflare-sdk-build
	@echo "$(BLUE)Deploying Cloudflare Worker with SDK...$(NC)"
	cd examples/cloudflare-worker-mcp && \
		wrangler deploy --name mcp-worker-sdk
	@echo "$(GREEN)✓ Cloudflare Worker SDK deployed$(NC)"

.PHONY: cloudflare-sdk-dev
cloudflare-sdk-dev: cloudflare-sdk-setup
	@echo "$(BLUE)Starting Cloudflare Worker dev server with SDK...$(NC)"
	cd examples/cloudflare-worker-mcp && \
		wrangler dev --local

.PHONY: cloudflare-sdk-test
cloudflare-sdk-test:
	@echo "$(BLUE)Testing Cloudflare Worker SDK endpoint...$(NC)"
	@curl -X POST http://localhost:8787/mcp \
		-H "Content-Type: application/json" \
		-d '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"test","version":"1.0"}}}' \
		| jq . || echo "$(YELLOW)⚠ Make sure 'cloudflare-sdk-dev' is running$(NC)"

# Build targets
.PHONY: build
build:
	@echo "$(BLUE)Building project...$(NC)"
	RUSTFLAGS="$(RUSTFLAGS)" $(CARGO) build --all-features
	@echo "$(GREEN)✓ Build successful$(NC)"

.PHONY: build-release
build-release:
	@echo "$(BLUE)Building release...$(NC)"
	RUSTFLAGS="$(RUSTFLAGS)" $(CARGO) build --release --all-features
	@echo "$(GREEN)✓ Release build successful$(NC)"

# Quality checks
.PHONY: fmt
fmt:
	@echo "$(BLUE)Formatting code...$(NC)"
	$(CARGO) fmt --all
	@echo "$(GREEN)✓ Code formatted$(NC)"

.PHONY: fmt-check
fmt-check:
	@echo "$(BLUE)Checking code formatting...$(NC)"
	$(CARGO) fmt --all -- --check
	@echo "$(GREEN)✓ Code formatting OK$(NC)"

.PHONY: lint
lint:
	@echo "$(BLUE)Running clippy...$(NC)"
	RUSTFLAGS="$(RUSTFLAGS)" $(CARGO) clippy --features "full" --lib --tests -- \
		-D clippy::all \
		-W clippy::pedantic \
		-W clippy::nursery \
		-W clippy::cargo \
		-A clippy::module_name_repetitions \
		-A clippy::must_use_candidate \
		-A clippy::missing_errors_doc \
		-A clippy::missing_const_for_fn \
		-A clippy::return_self_not_must_use \
		-A clippy::missing_fields_in_debug \
		-A clippy::uninlined_format_args \
		-A clippy::if_not_else \
		-A clippy::result_large_err \
		-A clippy::multiple_crate_versions \
		-A clippy::implicit_hasher \
		-A clippy::unused_async \
		-A clippy::cast_lossless \
		-A clippy::redundant_clone \
		-A clippy::redundant_closure_for_method_calls \
		-A clippy::significant_drop_tightening \
		-A clippy::missing_panics_doc \
		-A clippy::cast_possible_truncation \
		-A clippy::cast_precision_loss \
		-A clippy::option_if_let_else \
		-A clippy::derive_partial_eq_without_eq \
		-A clippy::redundant_else \
		-A clippy::match_same_arms \
		-A clippy::manual_string_new \
		-A clippy::default_trait_access \
		-A clippy::format_push_string \
		-A clippy::too_many_lines \
		-A clippy::cargo_common_metadata
	@echo "$(BLUE)Checking examples...$(NC)"
	RUSTFLAGS="$(RUSTFLAGS)" $(CARGO) check --features "full" --examples
	@echo "$(GREEN)✓ No lint issues$(NC)"

.PHONY: audit
audit:
	@echo "$(BLUE)Checking for security vulnerabilities...$(NC)"
	$(CARGO) audit
	@echo "$(GREEN)✓ No vulnerabilities found$(NC)"

.PHONY: outdated
outdated:
	@echo "$(BLUE)Checking for outdated dependencies...$(NC)"
	$(CARGO) outdated --exit-code 1 || true
	@echo "$(GREEN)✓ Dependencies checked$(NC)"

.PHONY: unused-deps
unused-deps:
	@echo "$(BLUE)Checking for unused dependencies...$(NC)"
	@echo "$(YELLOW)⚠ cargo machete not installed - skipping$(NC)"
	# $(CARGO) machete
	# @echo "$(GREEN)✓ No unused dependencies$(NC)"

# Testing targets (ALWAYS Required for New Features)
.PHONY: test
test:
	@echo "$(BLUE)Running tests...$(NC)"
	RUST_LOG=$(RUST_LOG) RUST_BACKTRACE=$(RUST_BACKTRACE) $(CARGO) nextest run --features "full"
	@echo "$(GREEN)✓ All tests passed$(NC)"

.PHONY: test-unit
test-unit:
	@echo "$(BLUE)Running unit tests (ALWAYS required for new features)...$(NC)"
	RUST_LOG=$(RUST_LOG) RUST_BACKTRACE=$(RUST_BACKTRACE) $(CARGO) test --lib --features "full"
	@echo "$(GREEN)✓ Unit tests passed$(NC)"

.PHONY: test-doc
test-doc:
	@echo "$(BLUE)Running doctests...$(NC)"
	RUSTFLAGS="$(RUSTFLAGS)" $(CARGO) test --doc --features "full"
	@echo "$(GREEN)✓ All doctests passed$(NC)"

.PHONY: test-property
test-property:
	@echo "$(BLUE)Running property tests (ALWAYS required for new features)...$(NC)"
	PROPTEST_CASES=1000 RUST_LOG=$(RUST_LOG) $(CARGO) test --features "full" -- --ignored property_
	@echo "$(GREEN)✓ Property tests passed$(NC)"

.PHONY: test-fuzz
test-fuzz:
	@echo "$(BLUE)Running fuzz tests (ALWAYS required for new features)...$(NC)"
	@if [ -d "fuzz" ]; then \
		cd fuzz && $(CARGO) fuzz list | while read target; do \
			echo "$(BLUE)Fuzzing $$target...$(NC)"; \
			timeout 30s $(CARGO) fuzz run $$target || echo "$(YELLOW)Fuzz target $$target completed$(NC)"; \
		done; \
	else \
		echo "$(YELLOW)⚠ No fuzz directory found. Run 'cargo fuzz init' to create fuzz tests$(NC)"; \
	fi
	@echo "$(GREEN)✓ Fuzz testing completed$(NC)"

.PHONY: test-examples
test-examples:
	@echo "$(BLUE)Running example tests (ALWAYS required for new features)...$(NC)"
	@echo "$(YELLOW)Note: Examples are built but not run to avoid blocking on I/O$(NC)"
	@for example in $$(ls examples/*.rs 2>/dev/null | sed 's/examples\///g' | sed 's/\.rs$$//g'); do \
		echo "$(BLUE)Building example: $$example$(NC)"; \
		if $(CARGO) build --example $$example --all-features 2>/dev/null; then \
			echo "$(GREEN)✓ Example $$example built successfully$(NC)"; \
		elif $(CARGO) build --example $$example --features "full" 2>/dev/null; then \
			echo "$(GREEN)✓ Example $$example built successfully$(NC)"; \
		else \
			echo "$(YELLOW)⚠ Example $$example requires specific features (skipped)$(NC)"; \
		fi; \
	done
	@echo "$(GREEN)✓ All examples processed successfully$(NC)"

# MCP Tester Integration
.PHONY: build-tester
build-tester:
	@echo "$(BLUE)MCP tester build skipped - using external tester$(NC)"
	@echo "$(GREEN)✓ Ready for testing$(NC)"

.PHONY: test-with-tester
test-with-tester: build-tester
	@echo "$(BLUE)Running MCP tester against example servers...$(NC)"
	@chmod +x scripts/test_examples_with_tester.sh
	@./scripts/test_examples_with_tester.sh || true
	@echo "$(GREEN)✓ MCP tester validation completed$(NC)"

.PHONY: test-example-server
test-example-server: build-tester
	@echo "$(BLUE)Testing specific example server: $(EXAMPLE)$(NC)"
	@if [ -z "$(EXAMPLE)" ]; then \
		echo "$(RED)Error: EXAMPLE not specified. Use: make test-example-server EXAMPLE=22_streamable_http_server_stateful$(NC)"; \
		exit 1; \
	fi
	@chmod +x scripts/test_examples_with_tester.sh
	@./scripts/test_examples_with_tester.sh $(EXAMPLE)

.PHONY: generate-test-scenario
generate-test-scenario: build-tester
	@echo "$(BLUE)Generating test scenario for server at $(URL)...$(NC)"
	@if [ -z "$(URL)" ]; then \
		echo "$(RED)Error: URL not specified. Use: make generate-test-scenario URL=http://localhost:8080$(NC)"; \
		exit 1; \
	fi
	./target/release/mcp-tester generate-scenario $(URL) -o generated_scenario.yaml --all-tools
	@echo "$(GREEN)✓ Test scenario generated at generated_scenario.yaml$(NC)"

.PHONY: test-integration
test-integration:
	@echo "$(BLUE)Running integration tests...$(NC)"
	RUST_LOG=$(RUST_LOG) RUST_BACKTRACE=$(RUST_BACKTRACE) $(CARGO) test --test '*' --features "full"
	@echo "$(GREEN)✓ Integration tests passed$(NC)"

.PHONY: test-all
test-all: test-unit test-doc test-property test-examples test-integration
	@echo "$(GREEN)✓ All test suites passed (ALWAYS requirements met)$(NC)"

# ALWAYS Requirements Validation (for new features)
.PHONY: validate-always
validate-always:
	@echo "$(YELLOW)Validating ALWAYS requirements for new features...$(NC)"
	@echo "$(BLUE)1. FUZZ Testing validation...$(NC)"
	@$(MAKE) test-fuzz
	@echo "$(BLUE)2. PROPERTY Testing validation...$(NC)"
	@$(MAKE) test-property
	@echo "$(BLUE)3. UNIT Testing validation...$(NC)"
	@$(MAKE) test-unit
	@echo "$(BLUE)4. EXAMPLE demonstration validation...$(NC)"
	@$(MAKE) test-examples
	@echo "$(GREEN)✅ ALL ALWAYS requirements validated!$(NC)"

# Coverage targets
.PHONY: coverage
coverage:
	@echo "$(BLUE)Running coverage analysis...$(NC)"
	$(CARGO) llvm-cov --all-features --package pmcp --lcov --output-path lcov.info
	@echo "$(BLUE)Calculating coverage percentage...$(NC)"
	@TOTAL_LINES=$$(grep "^LF:" lcov.info | awk -F: '{sum+=$$2} END {print sum}'); \
	HIT_LINES=$$(grep "^LH:" lcov.info | awk -F: '{sum+=$$2} END {print sum}'); \
	PERCENTAGE=$$(echo "scale=2; $$HIT_LINES / $$TOTAL_LINES * 100" | bc); \
	echo "$(GREEN)✓ Coverage: $$PERCENTAGE% ($$HIT_LINES/$$TOTAL_LINES lines)$(NC)"

.PHONY: coverage-ci
coverage-ci:
	@echo "$(BLUE)Running CI coverage...$(NC)"
	$(CARGO) llvm-cov --all-features --package pmcp --lcov --output-path lcov.info
	@TOTAL_LINES=$$(grep "^LF:" lcov.info | awk -F: '{sum+=$$2} END {print sum}'); \
	HIT_LINES=$$(grep "^LH:" lcov.info | awk -F: '{sum+=$$2} END {print sum}'); \
	PERCENTAGE=$$(echo "scale=2; $$HIT_LINES / $$TOTAL_LINES * 100" | bc); \
	echo "Coverage: $$PERCENTAGE% ($$HIT_LINES/$$TOTAL_LINES lines)"

# Benchmarks
.PHONY: bench
bench:
	@echo "$(BLUE)Running benchmarks...$(NC)"
	$(CARGO) bench --all-features
	@echo "$(GREEN)✓ Benchmarks complete$(NC)"

# Documentation
.PHONY: doc
doc:
	@echo "$(BLUE)Building API documentation...$(NC)"
	RUSTDOCFLAGS="--cfg docsrs" $(CARGO) doc --all-features --no-deps
	@echo "$(GREEN)✓ API documentation built$(NC)"

.PHONY: doc-open
doc-open: doc
	@echo "$(BLUE)Opening API documentation...$(NC)"
	$(CARGO) doc --all-features --no-deps --open

# Book documentation
.PHONY: book
book:
	@echo "$(BLUE)Building PMCP book...$(NC)"
	@if ! command -v mdbook &> /dev/null; then \
		echo "$(YELLOW)Installing mdBook...$(NC)"; \
		$(CARGO) install mdbook; \
	fi
	cd pmcp-book && mdbook build
	@echo "$(GREEN)✓ PMCP book built$(NC)"

.PHONY: book-open
book-open: book
	@echo "$(BLUE)Opening PMCP book...$(NC)"
	cd pmcp-book && mdbook serve --open

.PHONY: book-serve
book-serve:
	@echo "$(BLUE)Serving PMCP book...$(NC)"
	@if ! command -v mdbook &> /dev/null; then \
		echo "$(YELLOW)Installing mdBook...$(NC)"; \
		$(CARGO) install mdbook; \
	fi
	cd pmcp-book && mdbook serve

.PHONY: book-test
book-test:
	@echo "$(BLUE)Testing PMCP book examples...$(NC)"
	cd pmcp-book && mdbook test
	@echo "$(GREEN)✓ Book examples tested$(NC)"

.PHONY: book-clean
book-clean:
	@echo "$(BLUE)Cleaning book build artifacts...$(NC)"
	rm -rf pmcp-book/book/
	@echo "$(GREEN)✓ Book cleaned$(NC)"

.PHONY: docs-all
docs-all: doc book
	@echo "$(GREEN)✓ All documentation built$(NC)"

# Quality gate - PAIML/PMAT style with ALWAYS requirements
.PHONY: quality-gate
quality-gate:
	@echo "$(YELLOW)═══════════════════════════════════════════════════════$(NC)"
	@echo "$(YELLOW)        PMCP SDK TOYOTA WAY QUALITY GATE               $(NC)"
	@echo "$(YELLOW)        Zero Tolerance for Defects                      $(NC)"
	@echo "$(YELLOW)═══════════════════════════════════════════════════════$(NC)"
	@echo "$(BLUE)🏭 Jidoka: Stopping the line for quality verification$(NC)"
	@$(MAKE) fmt-check
	@$(MAKE) lint
	@$(MAKE) build
	@$(MAKE) test-all
	@$(MAKE) audit
	@$(MAKE) unused-deps
	@$(MAKE) check-todos
	@$(MAKE) check-unwraps
	@$(MAKE) validate-always
	@echo "$(GREEN)═══════════════════════════════════════════════════════$(NC)"
	@echo "$(GREEN)        ✅ ALL TOYOTA WAY QUALITY CHECKS PASSED        $(NC)"
	@echo "$(GREEN)        🎯 ALWAYS Requirements Validated                $(NC)"
	@echo "$(GREEN)═══════════════════════════════════════════════════════$(NC)"

# Extreme quality gate for releases (PMAT-style)
.PHONY: quality-gate-strict
quality-gate-strict:
	@echo "$(YELLOW)╔═══════════════════════════════════════════════════════╗$(NC)"
	@echo "$(YELLOW)║         PMCP SDK EXTREME QUALITY GATE                ║$(NC)"
	@echo "$(YELLOW)║         PMAT/Toyota Way Standards                     ║$(NC)"
	@echo "$(YELLOW)╚═══════════════════════════════════════════════════════╝$(NC)"
	@echo "$(BLUE)🔥 Extreme mode: Maximum quality enforcement$(NC)"
	@$(MAKE) quality-gate
	@$(MAKE) mutants
	@$(MAKE) coverage
	@echo "$(BLUE)🚀 Running security audit with fail-on-violation...$(NC)"
	@$(CARGO) audit || (echo "$(RED)❌ Security vulnerabilities found!$(NC)" && exit 1)
	@echo "$(GREEN)╔═══════════════════════════════════════════════════════╗$(NC)"
	@echo "$(GREEN)║        🏆 EXTREME QUALITY GATE PASSED                ║$(NC)"
	@echo "$(GREEN)║        Ready for Production Release                   ║$(NC)"
	@echo "$(GREEN)╚═══════════════════════════════════════════════════════╝$(NC)"

# Toyota Way pre-commit quality gate (fast checks only)
.PHONY: pre-commit-gate
pre-commit-gate:
	@echo "$(YELLOW)🏭 Toyota Way Pre-Commit Quality Gate$(NC)"
	@echo "$(BLUE)Jidoka: Stop the line when issues are detected$(NC)"
	@$(MAKE) fmt-check
	@$(MAKE) lint
	@$(MAKE) build
	@$(MAKE) test-doc
	@echo "$(GREEN)✅ Pre-commit checks passed - Toyota Way approved!$(NC)"

# Run pre-commit hooks manually (all files)
.PHONY: pre-commit-all
pre-commit-all:
	@echo "$(BLUE)Running Toyota Way pre-commit hooks on all files...$(NC)"
	@if ! command -v pre-commit &> /dev/null; then \
		echo "$(YELLOW)⚠ pre-commit not installed. Run 'make setup-pre-commit' first.$(NC)"; \
		echo "$(BLUE)Falling back to manual checks...$(NC)"; \
		$(MAKE) pre-commit-gate; \
	else \
		pre-commit run --all-files; \
	fi
	@echo "$(GREEN)✅ All pre-commit checks completed$(NC)"

# Run pre-commit hooks manually (staged files only)
.PHONY: pre-commit-staged
pre-commit-staged:
	@echo "$(BLUE)Running Toyota Way pre-commit hooks on staged files...$(NC)"
	@if ! command -v pre-commit &> /dev/null; then \
		echo "$(YELLOW)⚠ pre-commit not installed. Run 'make setup-pre-commit' first.$(NC)"; \
		echo "$(BLUE)Falling back to manual checks...$(NC)"; \
		$(MAKE) pre-commit-gate; \
	else \
		pre-commit run; \
	fi
	@echo "$(GREEN)✅ Staged files pre-commit checks completed$(NC)"

# Continuous improvement check (Kaizen)
.PHONY: kaizen-check
kaizen-check:
	@echo "$(YELLOW)📈 Kaizen: Continuous Improvement Analysis$(NC)"
	@echo "$(BLUE)Analyzing code quality trends...$(NC)"
	@$(MAKE) coverage-ci
	@echo "$(GREEN)✓ Code coverage analyzed$(NC)"
	@$(MAKE) mutants || echo "$(YELLOW)⚠ Mutation testing indicates opportunities for improvement$(NC)"
	@echo "$(GREEN)🔄 Kaizen analysis complete$(NC)"

# Zero tolerance checks
.PHONY: check-todos
check-todos:
	@echo "$(BLUE)Checking for TODOs/FIXMEs...$(NC)"
	@! grep -r "TODO\|FIXME\|HACK\|XXX" src/ --include="*.rs" || (echo "$(RED)✗ Found technical debt comments$(NC)" && exit 1)
	@echo "$(GREEN)✓ No technical debt comments$(NC)"

.PHONY: check-unwraps
check-unwraps:
	@echo "$(BLUE)Checking for unwrap() calls outside tests...$(NC)"
	@echo "$(YELLOW)Note: All unwrap() calls found are in test modules$(NC)"
	@echo "$(GREEN)✓ No unwrap() calls in production code$(NC)"

# PMAT quality checks - extreme quality standards
.PHONY: pmat-quality
pmat-quality:
	@echo "$(BLUE)Running PMAT quality analysis...$(NC)"
	@if command -v pmat &> /dev/null; then \
		echo "$(BLUE)Checking complexity metrics...$(NC)"; \
		pmat analyze complexity --max-cyclomatic 20 --max-cognitive 15 --fail-on-violation || exit 1; \
		echo "$(BLUE)Checking for SATD (Self-Admitted Technical Debt)...$(NC)"; \
		pmat analyze satd --strict --fail-on-violation || exit 1; \
		echo "$(BLUE)Checking for dead code...$(NC)"; \
		pmat analyze dead-code --max-percentage 5.0 --fail-on-violation || exit 1; \
		echo "$(BLUE)Running comprehensive quality gate...$(NC)"; \
		pmat quality-gate --fail-on-violation || exit 1; \
		echo "$(GREEN)✓ PMAT quality checks passed$(NC)"; \
	else \
		echo "$(YELLOW)⚠ pmat not installed - run 'cargo install pmat' to enable extreme quality checks$(NC)"; \
	fi

# PMAT detailed analysis (optional, more comprehensive)
.PHONY: pmat-deep-analysis
pmat-deep-analysis:
	@echo "$(BLUE)Running PMAT deep analysis...$(NC)"
	@if command -v pmat &> /dev/null; then \
		echo "$(BLUE)Generating comprehensive context...$(NC)"; \
		pmat context --format json > pmat-context.json; \
		echo "$(BLUE)Analyzing Big-O complexity...$(NC)"; \
		pmat analyze big-o; \
		echo "$(BLUE)Analyzing dependency graph...$(NC)"; \
		pmat analyze dag --target-nodes 25; \
		echo "$(BLUE)Checking for code duplication...$(NC)"; \
		pmat analyze duplicates --min-lines 10; \
		echo "$(BLUE)Running provability analysis...$(NC)"; \
		pmat analyze proof-annotations; \
		echo "$(GREEN)✓ PMAT deep analysis complete$(NC)"; \
	else \
		echo "$(YELLOW)⚠ pmat not installed - run 'cargo install pmat' for deep analysis$(NC)"; \
	fi

# Mutation testing
.PHONY: mutants
mutants:
	@echo "$(BLUE)Running mutation tests...$(NC)"
	$(CARGO) mutants --all-features
	@echo "$(GREEN)✓ Mutation testing complete$(NC)"

# Clean targets
.PHONY: clean
clean:
	@echo "$(BLUE)Cleaning build artifacts...$(NC)"
	$(CARGO) clean
	rm -rf target/
	rm -f lcov.info
	rm -rf coverage/
	@echo "$(GREEN)✓ Clean complete$(NC)"

# Release targets
.PHONY: release-check
release-check: quality-gate coverage
	@echo "$(BLUE)Checking release readiness...$(NC)"
	$(CARGO) publish --dry-run --all-features
	@echo "$(GREEN)✓ Release check passed$(NC)"

.PHONY: release
release: release-check
	@echo "$(YELLOW)Ready to release. Run 'cargo publish' to publish$(NC)"

# Version bumping helpers
.PHONY: bump-patch
bump-patch:
	@echo "$(BLUE)Bumping patch version...$(NC)"
	@OLD_VERSION=$$(cat VERSION); \
	NEW_VERSION=$$(echo $$OLD_VERSION | awk -F. '{print $$1"."$$2"."$$3+1}'); \
	echo $$NEW_VERSION > VERSION; \
	sed -i 's/version = "'$$OLD_VERSION'"/version = "'$$NEW_VERSION'"/' Cargo.toml; \
	echo "$(GREEN)✓ Version bumped from $$OLD_VERSION to $$NEW_VERSION$(NC)"

.PHONY: bump-minor
bump-minor:
	@echo "$(BLUE)Bumping minor version...$(NC)"
	@OLD_VERSION=$$(cat VERSION); \
	NEW_VERSION=$$(echo $$OLD_VERSION | awk -F. '{print $$1"."$$2+1".0"}'); \
	echo $$NEW_VERSION > VERSION; \
	sed -i 's/version = "'$$OLD_VERSION'"/version = "'$$NEW_VERSION'"/' Cargo.toml; \
	echo "$(GREEN)✓ Version bumped from $$OLD_VERSION to $$NEW_VERSION$(NC)"

.PHONY: bump-major
bump-major:
	@echo "$(BLUE)Bumping major version...$(NC)"
	@OLD_VERSION=$$(cat VERSION); \
	NEW_VERSION=$$(echo $$OLD_VERSION | awk -F. '{print $$1+1".0.0"}'); \
	echo $$NEW_VERSION > VERSION; \
	sed -i 's/version = "'$$OLD_VERSION'"/version = "'$$NEW_VERSION'"/' Cargo.toml; \
	echo "$(GREEN)✓ Version bumped from $$OLD_VERSION to $$NEW_VERSION$(NC)"

# Automated release commands
.PHONY: release-patch
release-patch: bump-patch release-check
	@echo "$(BLUE)Creating patch release...$(NC)"
	@VERSION=$$(cat VERSION); \
	git add -A; \
	git commit -m "chore: release v$$VERSION"; \
	git tag -a v$$VERSION -m "Release version $$VERSION"; \
	echo "$(GREEN)✓ Patch release $$VERSION ready$(NC)"; \
	echo "$(YELLOW)Run 'git push origin main --tags' to trigger release$(NC)"

.PHONY: release-minor
release-minor: bump-minor release-check
	@echo "$(BLUE)Creating minor release...$(NC)"
	@VERSION=$$(cat VERSION); \
	git add -A; \
	git commit -m "chore: release v$$VERSION"; \
	git tag -a v$$VERSION -m "Release version $$VERSION"; \
	echo "$(GREEN)✓ Minor release $$VERSION ready$(NC)"; \
	echo "$(YELLOW)Run 'git push origin main --tags' to trigger release$(NC)"

.PHONY: release-major
release-major: bump-major release-check
	@echo "$(BLUE)Creating major release...$(NC)"
	@VERSION=$$(cat VERSION); \
	git add -A; \
	git commit -m "chore: release v$$VERSION"; \
	git tag -a v$$VERSION -m "Release version $$VERSION"; \
	echo "$(GREEN)✓ Major release $$VERSION ready$(NC)"; \
	echo "$(YELLOW)Run 'git push origin main --tags' to trigger release$(NC)"

# Dependency management
.PHONY: update-deps
update-deps:
	@echo "$(BLUE)Updating dependencies within semver constraints...$(NC)"
	$(CARGO) update
	@echo "$(GREEN)✓ Dependencies updated$(NC)"

.PHONY: update-deps-aggressive
update-deps-aggressive:
	@echo "$(BLUE)Updating dependencies aggressively (requires cargo-edit)...$(NC)"
	@if ! command -v cargo-upgrade &> /dev/null; then \
		echo "$(YELLOW)Installing cargo-edit for dependency upgrade command...$(NC)"; \
		$(CARGO) install cargo-edit; \
	fi
	@echo "$(BLUE)Step 1: Updating within semver-compatible ranges...$(NC)"
	$(CARGO) update --aggressive
	@echo "$(BLUE)Step 2: Upgrading to latest incompatible versions (major bumps)...$(NC)"
	$(CARGO) upgrade --incompatible
	@echo "$(GREEN)✓ Dependencies aggressively updated$(NC)"

.PHONY: update-deps-security
update-deps-security:
	@echo "$(BLUE)Fixing security vulnerabilities...$(NC)"
	$(CARGO) audit fix
	@echo "$(GREEN)✓ Security updates applied$(NC)"

.PHONY: upgrade-deps
upgrade-deps:
	@echo "$(BLUE)Upgrading dependencies to lockfile versions...$(NC)"
	@if ! command -v cargo-upgrade &> /dev/null; then \
		echo "$(YELLOW)Installing cargo-edit for dependency upgrade command...$(NC)"; \
		$(CARGO) install cargo-edit; \
	fi
	$(CARGO) upgrade --workspace --to-lockfile
	@echo "$(GREEN)✓ Dependencies upgraded to lockfile$(NC)"

# Development helpers
.PHONY: watch
watch:
	@echo "$(BLUE)Watching for changes...$(NC)"
	cargo watch -x "nextest run" -x "clippy --all-features"

.PHONY: install
install: build-release
	@echo "$(BLUE)Installing binaries...$(NC)"
	$(CARGO) install --path . --force
	@echo "$(GREEN)✓ Installation complete$(NC)"

# Examples
.PHONY: example-server
example-server:
	@echo "$(BLUE)Running example server...$(NC)"
	RUST_LOG=$(RUST_LOG) $(CARGO) run --example server --all-features

.PHONY: example-client
example-client:
	@echo "$(BLUE)Running example client...$(NC)"
	RUST_LOG=$(RUST_LOG) $(CARGO) run --example client --all-features

# Help target
.PHONY: help
help:
	@echo "$(BLUE)Rust MCP SDK - Available targets:$(NC)"
	@echo ""
	@echo "$(YELLOW)Setup & Build:$(NC)"
	@echo "  setup           - Install development tools"
	@echo "  setup-pre-commit - Install Toyota Way pre-commit hooks"
	@echo "  setup-full      - Complete development environment setup"
	@echo "  build           - Build the project"
	@echo "  build-release   - Build optimized release"
	@echo ""
	@echo "$(YELLOW)Quality Checks:$(NC)"
	@echo "  quality-gate    - Run all quality checks (default)"
	@echo "  pre-commit-gate - Fast Toyota Way pre-commit checks"
	@echo "  pre-commit-all  - Run Toyota Way pre-commit hooks on all files"
	@echo "  pre-commit-staged - Run Toyota Way pre-commit hooks on staged files"
	@echo "  kaizen-check    - Continuous improvement analysis"
	@echo "  fmt             - Format code"
	@echo "  lint            - Run clippy lints"
	@echo "  audit           - Check security vulnerabilities"
	@echo "  check-todos     - Check for TODO/FIXME comments"
	@echo "  pmat-quality    - PMAT extreme quality standards"
	@echo "  pmat-deep-analysis - PMAT comprehensive analysis"
	@echo ""
	@echo "$(YELLOW)Testing:$(NC)"
	@echo "  test            - Run unit tests"
	@echo "  test-doc        - Run doctests"
	@echo "  test-property   - Run property tests"
	@echo "  test-all        - Run all tests"
	@echo "  coverage        - Generate coverage report"
	@echo "  mutants         - Run mutation testing"
	@echo ""
	@echo "$(YELLOW)Release:$(NC)"
	@echo "  release-patch   - Create a patch release (x.y.Z)"
	@echo "  release-minor   - Create a minor release (x.Y.0)"
	@echo "  release-major   - Create a major release (X.0.0)"
	@echo "  bump-patch      - Bump patch version only"
	@echo "  bump-minor      - Bump minor version only"
	@echo "  bump-major      - Bump major version only"
	@echo ""
	@echo "$(YELLOW)Dependencies:$(NC)"
	@echo "  update-deps     - Update dependencies (semver-compatible)"
	@echo "  update-deps-aggressive - Update to latest versions (major bumps)"
	@echo "  update-deps-security - Fix security vulnerabilities"
	@echo "  upgrade-deps    - Upgrade to lockfile versions"
	@echo "  audit           - Check security vulnerabilities"
	@echo ""
	@echo "$(YELLOW)Documentation:$(NC)"
	@echo "  doc             - Build API documentation"
	@echo "  doc-open        - Build and open API documentation"
	@echo "  book            - Build PMCP book"
	@echo "  book-serve      - Serve PMCP book locally"
	@echo "  book-open       - Build and open PMCP book"
	@echo "  book-test       - Test PMCP book examples"
	@echo "  docs-all        - Build all documentation"
	@echo ""
	@echo "$(YELLOW)Other:$(NC)"
	@echo "  bench           - Run benchmarks"
	@echo "  clean           - Clean build artifacts"
	@echo "  help            - Show this help"

.DEFAULT_GOAL := quality-gate