Menu
Power your AI agents with MCP tools on Google Cloud Run

Power your AI agents with MCP tools on Google Cloud Run

Google Cloud Tech

404 views 8 months ago Save 2 min 7 min read

Video Summary

MCP, or Model Context Protocol, is an open protocol developed by Anthropic that standardizes how context is provided to large language models (LLMs). It allows LLMs to interact with the real world by calling external APIs, querying databases, or running custom code through "tools." This protocol is beneficial for both API providers, enabling easier integration for AI agents, and for AI developers building agents that need to perform actions. A key aspect is that MCP abstracts away the need for developers to manually define API input and output parameters for AI agents, and it offers a standardized way to expose various services.

A particularly interesting fact is that MCP servers can be generated from existing OpenAPI specifications, simplifying the process for developers who wish to expose their current APIs to AI agents without significant code changes. The protocol also supports authentication mechanisms like OAuth and leverages existing cloud infrastructure for secure service-to-service communication.

Short Highlights

  • MCP (Model Context Protocol) is an open protocol by Anthropic that standardizes context for LLMs, focusing on "tools" which enable LLMs to take real-world actions.
  • Tools allow LLMs to discover and call external APIs, query databases, or run custom code, making AI agents more functional.
  • MCP is useful for API providers to package their services as MCP tools and for AI developers building agents that need to interact with APIs or perform actions.
  • Developers using MCP do not need to manually specify input/output parameters for AI agents, as the protocol handles this discovery.
  • MCP servers can be deployed locally or remotely, with Cloud Run on Google Cloud highlighted as a convenient serverless option for hosting these servers and agents.
  • Alice, an API provider for sprinkler systems, uses MCP to create a price quote tool deployed on Cloud Run, which David's lawn care company's AI chatbot then utilizes.
  • An MCP server can be generated directly from an OpenAPI specification, allowing developers to expose existing APIs to AI agents without rewriting them.
  • MCP supports authentication, including OAuth for user authentication and leveraging cloud infrastructure like Cloud Run for service-to-service authentication via bearer tokens.

Key Details

What is MCP and its Purpose? [00:41]

  • MCP stands for Model Context Protocol, an open protocol developed by Anthropic.
  • It standardizes how context is provided to large language models (LLMs).
  • The protocol has three main components, with a focus on "tools" in this discussion.
  • Tools empower LLMs or agents with the ability to take action in the real world.
  • This is achieved through discovering and calling external APIs, querying databases, or running custom code.

    "MCP stands for model context protocol. It's an open protocol developed by Enthropic that standardizes how we provide context to large language models or LLMs."

Who Benefits from MCP? [01:19]

  • MCP is useful for a broad audience, primarily falling into two groups.
  • API or Service Providers: They can use MCP to package their APIs into MCP tools, making them easier for clients and AI agents to use.
  • AI-Assisted Developers: Developers building AI agents find MCP simplifies how these agents use APIs or perform actions on their behalf.
  • An example is an MCP server for Cloud Run, allowing developers to deploy a service using plain English instead of complex G-Cloud commands.

    "MCP really is useful for a wide audience, but I see most users falling into one of two groups of people."

Deployment Options for MCP Servers [02:02]

  • MCP servers offer flexible deployment options.
  • Local Deployment: Useful for receiving AI assistance while coding in an editor.
  • Remote Deployment: Allows sharing MCP servers with others.
  • Cloud Run on Google Cloud: Presented as a highly recommended option for deploying MCP servers due to its serverless nature.

    "You can run an MCP server locally. For example, if you want AI help when you are writing code in your editor."

Real-World Use Case: Sprinkler Systems and Lawn Care [02:28]

  • Alice, an API provider for sprinkler systems, partners with lawn care companies.
  • She offers an MCP server with a tool to get price quotes for her sprinkler systems, deployed on serverless Cloud Run to manage infrastructure.
  • David runs a lawn care company and uses an AI chatbot for his customers.
  • By pointing his AI agent to Alice's MCP server, David's agent can now provide quotes for sprinkler system installations.
  • Eve, an end-user, can ask David's chatbot for lawn care tips and sprinkler system installation costs, with the chatbot leveraging Alice's MCP server for quotes.

    "Let's say Alice is an API provider. Her company sells sprinkler systems for lawns. She partners with lawn care companies who install these sprinkler systems."

MCP Server-Side Code Example [03:56]

  • Alice uses the fast_mcp library in Python.
  • The @mcp.tool decorator is applied to the calculate_quote function.
  • This annotation is sufficient to expose the method via the MCP protocol for AI agents.
  • The function's logic calculates the price quote based on the customer's country and lawn square meters.

    "She has imported the fast MCP library and added this MCP.tool decorator to the calculate quote function."

David's Agent-Side Code Example [04:29]

  • When building an agent, developers can provide an array of tools or functions it can call.
  • David's agent is configured with a single tool of type MCPToolSet, containing Alice's MCP server address.
  • Crucially, David did not need to manually specify input and output parameters or provide descriptions for Alice's function; the agent discovered these from the MCP server.

    "David's provides a single tool of type MCP tool set which contains the address of Alice's MCP server."

Cloud Run's Role in MCP Deployments [05:13]

  • Alice runs her MCP server on Cloud Run, which is serverless.
  • David's agent was also built using Google's ADK (Agent Development Kit) and deployed to Cloud Run.
  • Cloud Run's serverless nature simplifies deploying agents, MCP servers, and APIs.
  • Google handles configuration and scaling, allowing for faster releases.

    "Yeah, Cloud Run is serverless which makes it really easy to deploy agents, MCP servers or APIs."

Key Advantages of MCP [06:02]

  • Simplified Agent Development: Agent developers like David don't need to manually tell the AI about input and output parameters.
  • Framework Agnosticism: Unlike previous tools tied to specific frameworks (e.g., LangChain), MCP is a common protocol usable by many clients.
  • Standardized API Exposure: API providers can expose their services (e.g., calendar, email, file system) uniformly, making them easier for AI agents to consume.

    "That's one advantage of MCP. Another reason for MCP is that previously your tools had to be built for a specific framework like lang chain or visual studio code."

Authentication in MCP [06:46]

  • MCP supports authentication to control access to servers.
  • It supports OAuth, suitable for user-to-user authentication.
  • It can also leverage existing cloud infrastructure authentication, like Cloud Run's authentication, for service-to-service authentication using bearer tokens.

    "Yes. Luckily, MCP has support for authentication. I will note that it is fairly new and still evolving."

MCP Protocol Structure and OpenAPI Comparison [07:19]

  • The MCP protocol defines tools as an array, with each tool having a name and specifying its required inputs.
  • The MCP inspector shows a "calculate_quote" tool with "square_meters" and "country_code" as required inputs.
  • This structure is compared to an OpenAPI spec, with MCP being a higher-level abstraction that skips lower-level implementation details like HTTP status codes.

    "Here we can see that the tools is an array with a single entry called calculate quote. That tool takes two inputs, square meters and country code. Both are required."

Exposing Existing APIs with MCP [08:03]

  • Developers with existing, well-tested APIs can expose them to AI agents using MCP.
  • The fast_mcp library can generate an MCP server directly from an OpenAPI spec.
  • Alternatively, a small proxy can be built using fast_mcp to forward calls to the existing API.

    "Fast MCP actually has built-in support for this exact functionality. You can point it to your open API spec and it will actually generate an MCP server."

Main Takeaways on MCP [08:33]

  • MCP serves as a common language for declaring tools for AI agents.
  • Exposing APIs with MCP makes them readily available for agents to use.
  • Running an MCP server on Cloud Run is extremely easy.

    "As I was first learning about MCP and writing my first MCP servers, here's what I learned along the way."

Other People Also See

The Best Wii Remote EVER!
The Best Wii Remote EVER!
Linus Tech Tips 515,719 views 2 min read
Top 5 WORST Butter Brands To Avoid
Top 5 WORST Butter Brands To Avoid
Bobby Parrish 745,543 views Save 14 min 5 min read
Top 5 WORST Bread Brands To Avoid
Top 5 WORST Bread Brands To Avoid
Bobby Parrish 701,557 views Save 15 min 6 min read