Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 31 additions & 4 deletions docs/tools-custom/mcp-tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,34 @@ The `McpToolset` class is ADK's primary mechanism for integrating tools from an
4. **Proxying Tool Calls:** When your `LlmAgent` decides to use one of these tools, `McpToolset` transparently proxies the call (using the `call_tool` MCP method) to the MCP server, sends the necessary arguments, and returns the server's response back to the agent.
5. **Filtering (Optional):** You can use the `tool_filter` parameter when creating an `McpToolset` to select a specific subset of tools from the MCP server, rather than exposing all of them to your agent.

### Authentication for Remote MCP Servers

When connecting to a remote MCP server that requires authentication, you can
provide authentication details to the `McpToolset`. This is particularly useful
when using `SseConnectionParams` to connect to a secure server.

The `McpToolset` constructor accepts two parameters for this purpose:

* `auth_scheme`: An `AuthScheme` object that defines the authentication method
(e.g., Bearer, Basic, API Key).
* `auth_credential`: An `AuthCredential` object that holds the credentials
(e.g., token, username/password).

These parameters are used to generate the necessary `Authorization` header for
the MCP connection. The ADK will handle the authentication flow, including
any necessary OAuth 2.0 token exchanges, and inject the correct header into
the requests sent to the MCP server.

### Accessing MCP Resources

Besides tools, MCP servers can also expose Resources, which are data blobs that can be accessed by the agent. The `McpToolset` provides two methods to interact with these resources:

* `list_resources()`: This method returns a list of the names of all available resources on the MCP server.

* `read_resource(name)`: This method reads the content of a specific resource, identified by its `name`. The content is returned as a list of content blocks.

These methods allow your agent to discover and consume data provided by the MCP server, in addition to the available tools.

The following examples demonstrate how to use `McpToolset` within the `adk web` development environment. For scenarios where you need more fine-grained control over the MCP connection lifecycle or are not using `adk web`, refer to the "Using MCP Tools in your own Agent out of `adk web`" section later in this page.

### Example 1: File System MCP Server
Expand Down Expand Up @@ -719,7 +747,7 @@ from . import agent
python3 /path/to/your/my_adk_mcp_server.py
```
It will print "Launching MCP Server..." and wait. The ADK agent (run via `adk web`) will then connect to this process if the `command` in `StdioConnectionParams` is set up to execute it.
*(Alternatively, `McpToolset` will start this server script as a subprocess automatically when the agent initializes).*
*(Alternatively, `McpToolset` will start this server script as a subprocess automatically when the agent initializes).)*

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

adding another ")" is unnecessary and incorrect.


2. **Run `adk web` for the client agent:**
Navigate to the parent directory of `mcp_client_agent` (e.g., `adk_agent_samples`) and run:
Expand Down Expand Up @@ -852,7 +880,6 @@ if __name__ == '__main__':
asyncio.run(async_main())
except Exception as e:
print(f"An error occurred: {e}")
```

### Handling progress updates

Expand Down Expand Up @@ -1040,7 +1067,7 @@ def create_mcp_server():

return app

def main(port: int = 8080, json_response: bool = False):
def main(port: int = 8080, json_response: bool = false):
"""Main server function."""
logging.basicConfig(level=logging.INFO)

Expand Down Expand Up @@ -1293,4 +1320,4 @@ McpToolset(

* [Model Context Protocol Documentation](https://modelcontextprotocol.io/ )
* [MCP Specification](https://modelcontextprotocol.io/specification/)
* [MCP Python SDK & Examples](https://github.com/modelcontextprotocol/)
* [MCP Python SDK & Examples](https://github.com/modelcontextprotocol/mcp-python)
Loading