Getting Started with Model Context Protocol By the end of this lesson, students should be able to: MCP SDKs. Anthropic provides official MCP SDKs for Python and TypeScript (verify current SDK availability and installation at modelcontextprotocol.io/sdk). The SDK handles the protocol layer – you define the tools and implement the handlers. Server initialization (Python pattern). “`python from mcp.server import Server from mcp.server.stdio import stdio_server import mcp.types as types app = Server("my-first-server") @app.list_tools() async def list_tools() -> list[types.Tool]: return [ types.Tool( name="get_weather", description="Get the current weather for a city. Returns temperature in Celsius and conditions.", inputSchema={ "type": "object", "properties": { "city": { "type": "string", "description": "The city name to get weather for" } }, "required": ["city"] } ) ] @app.call_tool() async def call_tool(name: str, arguments: dict) -> list[types.TextContent]: if name == "get_weather": city = arguments["city"] return [types.TextContent(type="text", text=f"Weather in {city}: 18°C, partly cloudy")] raise ValueError(f"Unknown tool: {name}") async def main(): async with stdio_server() as (read_stream, write_stream): await app.run(read_stream, write_stream, app.create_initialization_options()) “` This is a minimal working pattern. Verify current SDK API at modelcontextprotocol.io/sdk – method signatures may change between SDK versions. Tool definition quality. The same tool description quality rules from the Anthropic API apply here: the description is read by Claude to decide when and how to use the tool. Precise, specific descriptions produce reliable tool invocation. Testing locally with Claude Code. “ A developer builds his first MCP tool: a server that queries an internal project tracking system. He defines one tool: get_project_status with a project_id parameter. The handler calls the internal REST API, parses the response, and returns a formatted status string. He adds it to his Claude Code config, restarts, and asks "what's the status of project P-1234?" – Claude calls the tool, gets the status, and presents it in a useful summary. Build-to-working time: ninety minutes. Zero new API integrations – the existing REST API is wrapped, not replaced. MCP tool handlers execute with the permissions of the server process. Validate all tool arguments in the handler before using them – Claude's arguments are generated output and should be treated as untrusted input. For tools that access databases or file systems, sanitize inputs to prevent injection attacks. An MCP server that passes Claude's tool arguments directly to a database query without validation is vulnerable to prompt injection. Log in and enroll to access lesson quizzes.
Lesson 3: Building Your First MCP Tool
Lesson Objectives
Lesson Content
Your actual weather API call here
.claude/mcp_servers.json:json { "mcpServers": { "weather": { "command": "python", "args": ["/path/to/your/server.py"] } } } “Practical Example
Safety Notes