# TASK_3: FastMCP Server Foundation
**Created By**: OUTLINER | **Priority**: HIGH | **Duration**: 6 hours
**Technique Focus**: All ADDER+ techniques (contracts, types, defensive, testing, functional)
**Size Constraint**: Target <250 lines/module, Max 400 if splitting awkward
## π¦ Status & Assignment
**Status**: COMPLETE
**Assigned**: Adder_5
**Dependencies**: TASK_1 (Core Type System), TASK_2 (Security Framework) β
**Blocking**: TASK_4, TASK_5-11 (Ready for next phase)
## π Required Reading (Complete before starting)
- [x] **Protocol**: `development/protocols/FASTMCP_PYTHON_PROTOCOL.md` - Complete FastMCP implementation guide
- [x] **Architecture**: `ARCHITECTURE.md` - FastMCP Server Layer design
- [x] **Type System**: Results from TASK_1 - Core types and domain models
- [x] **Security Framework**: Results from TASK_2 - Security contracts and validation
## π― Objective & Context
**Goal**: Implement FastMCP server foundation with authentication, routing, and error handling
**Context**: Core server infrastructure that exposes 8 MCP tools to Claude Desktop with comprehensive security and monitoring
<thinking>
FastMCP Server Analysis:
1. Server must expose 8 MCP tools with proper type validation
2. Authentication required for all agent operations
3. Request routing needs security context injection
4. Error handling must maintain security boundaries
5. Audit logging required for all operations
6. Performance monitoring for concurrent agent management
</thinking>
## β
Implementation Subtasks (Sequential completion)
### Phase 1: Core Server Infrastructure
- [x] **Subtask 1.1**: Initialize FastMCP server with security configuration
- [x] **Subtask 1.2**: Implement authentication provider with JWT validation
- [x] **Subtask 1.3**: Create request routing with security context injection
- [x] **Subtask 1.4**: Add comprehensive error handling and recovery
### Phase 2: MCP Tool Registration System
- [x] **Subtask 2.1**: Create tool registration framework with validation
- [x] **Subtask 2.2**: Implement automatic schema generation from type hints
- [x] **Subtask 2.3**: Add tool result serialization and validation
- [x] **Subtask 2.4**: Create tool execution monitoring and metrics
### Phase 3: Security Integration
- [x] **Subtask 3.1**: Integrate security contracts for all tool operations
- [x] **Subtask 3.2**: Implement comprehensive input validation pipeline
- [x] **Subtask 3.3**: Add audit logging for all MCP interactions
- [x] **Subtask 3.4**: Create rate limiting and abuse prevention
### Phase 4: Performance & Monitoring
- [x] **Subtask 4.1**: Implement async request handling with connection pooling
- [x] **Subtask 4.2**: Add performance metrics and health monitoring
- [x] **Subtask 4.3**: Create graceful shutdown and restart mechanisms
- [x] **Subtask 4.4**: Add comprehensive testing with property-based scenarios
## π§ Implementation Files & Specifications
**Files to Create/Modify**:
- `src/main.py` - FastMCP server entry point and configuration (Target: <150 lines)
- `src/core/server.py` - Core FastMCP server implementation (Target: <250 lines)
- `src/core/auth.py` - Authentication and authorization (Target: <200 lines)
- `src/core/routing.py` - Request routing and context injection (Target: <200 lines)
- `src/core/monitoring.py` - Performance monitoring and health checks (Target: <200 lines)
- `src/utils/serialization.py` - Type-safe serialization and validation (Target: <150 lines)
- `src/utils/errors.py` - Comprehensive error handling (Target: <150 lines)
- `tests/core/test_*.py` - Server infrastructure tests with property-based scenarios
**Key Requirements**:
- FastMCP server runs on stdio transport for Claude Desktop integration
- All tools registered with automatic schema generation from type hints
- Authentication via JWT with configurable security policies
- Comprehensive audit logging with cryptographic signatures
- Performance monitoring with real-time metrics collection
## ποΈ Modularity Strategy
**Size Management**:
- Separate server concerns into focused modules (auth, routing, monitoring)
- Use dependency injection for testability and modularity
- Keep tool registration logic minimal and declarative
- Break complex error handling into specialized handlers
**Organization Principles**:
- Single responsibility per server module
- Clear separation between framework and business logic
- Minimal coupling between server components
- Maximum configurability for different deployment scenarios
## β
Success Criteria & Verification
**Completion Requirements**:
- [ ] FastMCP server running with stdio transport
- [ ] All 8 MCP tools properly registered and accessible
- [ ] Authentication working with JWT validation
- [ ] Comprehensive error handling with security preservation
- [ ] Audit logging for all operations with integrity
- [ ] Performance monitoring with real-time metrics
- [ ] Property-based testing for server functionality
**Quality Gates**:
- Integration: FastMCP server integrates cleanly with Claude Desktop
- Security: All requests authenticated and validated
- Performance: Handles concurrent tool requests efficiently
- Reliability: Graceful error handling and recovery
- Observability: Comprehensive logging and monitoring
## π Handoff Information
**Next Task Dependencies**: TASK_4 (Agent & Session Management) requires server foundation
**Integration Points**: All MCP tools will use this server infrastructure
**Future Considerations**: Server extensible for additional MCP tools and transport options
## π Implementation Templates
### **FastMCP Server Entry Point**
```python
# src/main.py
import asyncio
from fastmcp import FastMCP
from src.core.server import AgentOrchestrationServer
from src.core.auth import create_auth_provider
from src.core.monitoring import ServerMonitoring
async def main():
"""Initialize and run the Agent Orchestration Platform MCP server."""
# Server configuration with security
auth_provider = create_auth_provider()
monitoring = ServerMonitoring()
# Create FastMCP server instance
server = AgentOrchestrationServer(
auth=auth_provider,
monitoring=monitoring
)
# Register all MCP tools
await server.register_agent_tools()
# Start server with stdio transport
await server.run(transport="stdio")
if __name__ == "__main__":
asyncio.run(main())
```
### **Core Server Implementation**
```python
# src/core/server.py
from fastmcp import FastMCP, Context
from src.types.agent import AgentCreationRequest, AgentCreationResult
from src.contracts.security import validate_agent_creation_request
from src.core.monitoring import ServerMonitoring
class AgentOrchestrationServer:
"""Core FastMCP server for agent orchestration platform."""
def __init__(self, auth, monitoring: ServerMonitoring):
self.mcp = FastMCP(
name="AgentOrchestrationPlatform",
auth=auth,
instructions="Sophisticated multi-agent Claude Code orchestration"
)
self.monitoring = monitoring
async def register_agent_tools(self):
"""Register all 8 MCP tools with comprehensive validation."""
# Tool registration with contracts and monitoring
self.mcp.tool()(self._create_agent_tool)
# ... other tools
@validate_agent_creation_request
async def _create_agent_tool(
self,
request: AgentCreationRequest,
ctx: Context
) -> AgentCreationResult:
"""Create new Claude Code agent with comprehensive validation."""
# Implementation with contracts and monitoring
```
### **Authentication Integration**
```python
# src/core/auth.py
from fastmcp.server.auth import BearerAuthProvider
from src.types.security import SecurityContext
from src.contracts.security import validate_authentication
def create_auth_provider() -> BearerAuthProvider:
"""Create authentication provider with security validation."""
return BearerAuthProvider(
public_key=load_public_key(),
audience="agent-orchestration-platform",
validator=validate_authentication
)
```
This FastMCP server foundation provides secure, performant, and extensible infrastructure for the 8 MCP tools with comprehensive security integration and monitoring capabilities.