How MCP Works
Understand the technical architecture behind Azion's Model Context Protocol and learn how to implement your own MCP server using modern technologies.
The Azion MCP server operates as a bridge between AI assistants and the Azion Platform, providing secure access to documentation, tools, and resources through a standardized protocol.
Technical Architecture
MCP implements a client-server model using Anthropic’s Model Context Protocol. The architecture consists of three main components:
Technology Stack
| Component | Technology | Purpose |
|---|---|---|
| Runtime | Node.js 20+ | JavaScript execution environment |
| Language | TypeScript | Static typing and safety |
| Protocol | MCP SDK | Anthropic protocol implementation |
| Hosting | Functions | Distributed execution on Azion |
| Authentication | Personal Token / OAuth | Secure access control |
Communication Flow
The flow works as follows:
- Connection: The MCP client establishes connection with the server using HTTP or WebSocket
- Authentication: The Personal Token validates the user’s identity
- Discovery: The client discovers available tools and resources
- Execution: The assistant invokes tools as needed
- Response: The server returns structured data to the client
MCP Components
The MCP protocol defines three main types of capabilities that a server can expose:
Tools
Tools are functions that the AI assistant can invoke to perform actions or fetch information. Each tool has:
- Name: Unique identifier (e.g.,
search_azion_docs_and_site) - Description: Explains the purpose and when to use it
- Input Schema: Defines expected parameters using JSON Schema
- Handler: Function that executes the logic
Example tool definition:
Resources
Resources are structured data that can be read by the client, similar to files. They use URIs for identification:
Resource URIs follow the format: azion://[category]/[resource]/[item]
Prompts
Prompts are pre-configured templates that help with common scenarios:
Implementing an MCP Server
To implement your own MCP server, follow these steps:
Project Structure
Entry Point
The main file initializes the server and registers capabilities:
Authentication
The MCP server supports multiple authentication methods:
Deploying to Azion
The MCP server can be deployed as a Function on Azion:
Configuration
Create an azion.config.ts file in the project root:
Deploy
Use the Azion CLI to deploy:
The deploy creates a publicly accessible URL that can be configured in MCP clients.
Best Practices
Tool Design
- Descriptive names: Use clear verbs and nouns (e.g.,
search_docs,create_rule) - Typed parameters: Define complete JSON Schema schemas
- Clear descriptions: Explain when and how to use each tool
- Error handling: Return informative error messages
- Idempotency: Tools should be safe for multiple calls
Performance
- Response caching: Implement cache for frequently accessed data
- Pagination: Use pagination for large datasets
- Timeouts: Set appropriate timeouts for long operations
- Compression: Compress large responses
Security
- Input validation: Always validate input parameters
- Rate limiting: Implement rate limits per token
- Audit logs: Log all sensitive operations
- Sanitization: Remove sensitive data before returning
Complete Example
See a complete example of a documentation search tool:
Additional Resources
- MCP Specification - Official protocol documentation
- MCP SDK - Official TypeScript SDK
- Azion MCP Repository - Azion server source code
- MCP Overview - Introduction to MCP
- Configuration Guide - Set up your environment
- Practical Examples - Real-world use cases