Skip to content

MCP Architecture

Shazzadul Islam edited this page Jul 29, 2025 · 5 revisions

MCP Architecture

Understanding MCP Architecture

The Model Context Protocol (MCP) is a standardized way for AI models to interact with external tools and data sources. Each MCP server in this project follows the JSON-RPC 2.0 specification and implements specific capabilities.

Core MCP Components

1. Tools

Functions that the AI can call to perform actions:

  • Execute operations (file processing, calculations, etc.)
  • Return structured results to the AI model
  • Accept parameters for customization

2. Resources

Data sources that can be read or queried:

  • Static files or dynamic data
  • URI-based access patterns
  • Support for different MIME types

3. Prompts

Pre-defined prompt templates for common tasks:

  • Standardized interaction patterns
  • Parameterized templates
  • Context-aware suggestions

Protocol Structure

Server Initialization

# Standard MCP server setup
app = Server("server-name")

@app.list_tools()
async def handle_list_tools() -> list[Tool]:
    return [
        Tool(
            name="tool_name",
            description="Tool description",
            inputSchema={
                "type": "object",
                "properties": {
                    "param": {"type": "string"}
                }
            }
        )
    ]

Tool Implementation

@app.call_tool()
async def handle_call_tool(name: str, arguments: dict) -> list[TextContent]:
    if name == "tool_name":
        result = process_data(arguments["param"])
        return [TextContent(type="text", text=result)]

Communication Flow

  1. Client Request: AI model requests available tools
  2. Server Response: Server lists available tools with schemas
  3. Tool Execution: AI calls specific tool with parameters
  4. Result Return: Server processes and returns structured results

Best Practices

  • Use clear, descriptive tool names
  • Provide comprehensive input schemas
  • Return structured, parseable results
  • Implement proper error handling
  • Follow async/await patterns for I/O operations

Clone this wiki locally