MCP Tools Integration ExampleΒΆ
This guide provides a professional, step-by-step walkthrough for creating, registering, and executing a custom MCP (Model Context Protocol) tool using the MCPToolManager and MCPTool classes from the agenticaiframework package. It is intended for developers who want to extend their agent's capabilities with modular, reusable tools.
35+ Built-in Tools
Part of 400+ modules with 35+ built-in tools and 18 external connectors. See MCP Tools Documentation.
Prerequisites & ConfigurationΒΆ
- Installation: Ensure
agenticaiframeworkis installed and accessible in your Python environment. - No additional configuration is required for this example.
- Python Version: Compatible with Python 3.10+.
CodeΒΆ
Step-by-Step ExecutionΒΆ
-
Import Required Classes Import
MCPToolManagerandMCPToolfromagenticaiframework.mcp_tools. -
Define the Tool Function Create a Python function (e.g.,
greet_tool) that implements the tool's logic. -
Instantiate the Tool Manager Create an instance of
MCPToolManagerto manage tool registration and execution. -
Create the MCP Tool Object Instantiate
MCPToolwith: name: Unique identifier for the tool.capability: A short description of what the tool does.-
execute_fn: The function to execute when the tool is called. -
Register the Tool Use
register_toolto make the tool available for execution. -
List Available Tools Access the
toolslist to verify registration. -
Execute the Tool Call
execute_toolwith the tool name and required arguments.
Best Practice: Keep tool functions small and focused on a single responsibility for better maintainability.
Expected InputΒΆ
No user input is required; the script uses hardcoded values for demonstration purposes. In production, arguments could be dynamically generated from user input, API responses, or other runtime data.
Expected OutputΒΆ
| Text Only | |
|---|---|
How to RunΒΆ
Run the example from the project root:
| Bash | |
|---|---|
If installed as a package, you can also run it from anywhere:
| Bash | |
|---|---|
Tip: Use descriptive tool names and capabilities to make it easier for other developers to understand and reuse your tools.