This example demonstrates how to integrate the NVIDIA NeMo Agent toolkit with Model Context Protocol (MCP) servers. You'll learn to use remote tools through MCP and publish Agent toolkit functions as MCP services.
- Agent toolkit: Ensure you have the Agent toolkit installed. If you have not already done so, follow the instructions in the Install Guide to create the development environment and install NeMo Agent Toolkit.
- Base workflow: This example builds upon the Getting Started Simple Calculator example. Make sure you are familiar with the example before proceeding.
If you have not already done so, follow the instructions in the Install Guide to create the development environment and install NeMo Agent toolkit.
Install this example:
uv pip install -e examples/MCP/simple_calculator_mcpYou can run the simple calculator workflow using Remote MCP tools. In this case, the workflow acts as a MCP client and connects to the MCP server running on the specified URL. Details are provided in the MCP Client Guide.
You can publish the simple calculator tools via MCP using the nat mcp serve command. Details are provided in the MCP Server Guide.
NeMo Agent toolkit enables workflows to use MCP tools as functions. The library handles the MCP server connection, tool discovery, and function registration. This allows the workflow to use MCP tools as regular functions.
Tools served by remote MCP servers can be leveraged as NeMo Agent toolkit functions in one of two ways:
mcp_client: A flexible configuration using function groups, that allows you to connect to a MCP server, dynamically discover the tools it serves, and register them as NeMo Agent toolkit functions.config-mcp-client.ymlexample demonstrates how to use themcp_clientfunction group with both local and remote MCP servers.mcp_tool_wrapper: A simple configuration that allows you to wrap a single MCP tool as a NeMo Agent toolkit function.config-mcp-tool-wrapper.ymlexample demonstrates how to use themcp_tool_wrapperfunction group with a remote MCP server.
The config-mcp-client.yml example demonstrates how to use the mcp_client function group with both local and remote MCP servers. This configuration shows how to use multiple MCP servers with different transports in the same workflow.
examples/MCP/simple_calculator_mcp/configs/config-mcp-client.yml:
function_groups:
mcp_time:
_type: mcp_client
server:
transport: stdio
command: "python"
args: ["-m", "mcp_server_time", "--local-timezone=America/Los_Angeles"]
mcp_math:
_type: mcp_client
server:
transport: streamable-http
url: "http://localhost:9901/mcp"
workflow:
_type: react_agent
tool_names:
- mcp_time
- mcp_mathThis configuration creates two function groups:
mcp_time: Connects to a local MCP server using stdio transport to get current date and timemcp_math: Connects to a remote MCP server using streamable-http transport to access calculator tools
To run this example:
- Start the remote MCP server:
nat mcp serve --config_file examples/getting_started/simple_calculator/configs/config.ymlThis starts an MCP server on port 9901 with endpoint /mcp and uses streamable-http transport. See the MCP Server documentation for more information.
- Run the workflow:
nat run --config_file examples/MCP/simple_calculator_mcp/configs/config-mcp-client.yml --input "Is the product of 2 * 4 greater than the current hour of the day?"