Model Context Protocol (MCP)
MCP SDK 2.3
Implement, test and secure MCP servers and clients, from stdio to a remote OAuth-protected service with scoped database access.
What is Model Context Protocol (MCP)?
Model Context Protocol (MCP) is a protocol that connects a client application to a server that describes and executes capabilities. A tool declaration tells a model what it may propose; the client and server still validate requests and enforce their own rules. Resources and prompts provide separate ways to supply content and reusable instructions.
Start with a task tracker: discover its tool schema, propose a task operation and follow the result or error back to the client. Then reuse that server through agent adapters and compare local process transport with a remote service that checks scoped tokens.
What you'll learn
- Implement typed MCP tools, serve them over stdio and Streamable HTTP, and pin their contracts in tests.
- Build an MCP client that acts on discovery, checks each call before sending it and traces it across processes.
- Expose resources, resource templates and prompts from an MCP server, and test each primitive.
- Give MCP tools to Google ADK and LangGraph agents running Gemma, and handle a failing tool.
- Secure a remote MCP server with OAuth 2.1 and scoped tokens, and serve a read-only database with scoped roles and row caps.
Lessons
Implement an MCP server with typed tool contractsRead
Implement a task-tracker server with the MCP Python SDK whose typed tool schemas reject bad arguments and keep tool errors apart from protocol errors.
Serve MCP over stdio and Streamable HTTP, and test the contractsRead
Serve one MCP Python SDK server over stdio and Streamable HTTP, read the JSON-RPC requests the client sends, and pin its tool contracts with pytest.
Build an MCP client with discovery, calls and tracingRead
Build an MCP client that discovers tools, checks arguments before calling them, distinguishes failures and traces calls across client and server.
Expose resources and prompts from an MCP serverRead
Build a docs server with the MCP Python SDK that offers a search tool, pages as resources and a review prompt, and returns the specified error codes.
Integrate MCP tools into ADK and LangGraph agentsRead
Connect one MCP server to a Google ADK agent with McpToolset and a LangGraph agent with langchain-mcp-adapters, and compare how each handles tool failures.
Secure a remote MCP server with OAuth 2.1 and scoped tokensRead
Serve an MCP server over Streamable HTTP that accepts only tokens issued for it, publishes Protected Resource Metadata and returns 403 for a missing scope.
Build a read-only database MCP server with scoped rolesRead
Let a model run SQL through an MCP tool on PostgreSQL 17 with a read-only role, a statement timeout and row and byte limits, and test what each layer stops.