The Role of an Application
An Application in Universal MCP is responsible for:- Connection Management: Establishing and maintaining communication with the external service. This could involve setting base URLs for HTTP APIs or handling GraphQL client instances.
- Authentication: Securely managing and applying the necessary credentials (API keys, OAuth tokens, etc.) to authenticate requests to the service. This is often handled in conjunction with an Integration.
- Defining Operations (Actions/Tools): Exposing the capabilities of the external service as a list of well-defined functions (Actions or Tools) that an AI agent can call.
- Data Transformation: Potentially transforming data to and from the format expected by the external service and the format understood by the AI agent.
- Error Handling: Managing and standardizing errors that might occur during interaction with the external service.
Base Application Classes
Universal MCP provides several base classes to simplify the development of new applications, catering to common communication patterns:-
BaseApplication: This is the abstract base class that all applications must inherit from. It defines the common interface, including the essentiallist_tools()method which every application must implement to declare the tools it provides. -
APIApplication: This class extendsBaseApplicationand is designed for applications that interact with standard HTTP/RESTful APIs. It includes:- An integrated
httpx.Clientfor making HTTP requests (_get,_post,_put,_delete,_patch). - Logic to automatically include authentication headers based on the configured
Integration. - Management of a
base_urlfor the API.
- An integrated
-
GraphQLApplication: A specialized class extendingBaseApplicationfor services that use GraphQL APIs. It provides:- An integrated
gql.Clientfor executing GraphQL queries and mutations. - Similar to
APIApplication, it handles authentication headers derived from itsIntegration. - Methods like
query()andmutate()for interacting with the GraphQL endpoint.
- An integrated
Creating a New Application
When you need to connect to a new service not yet supported, you’ll typically create a new Python class that inherits from one of these base classes. For example, if you’re integrating a new REST API, you’d likely inherit fromAPIApplication.
The key aspects you’ll implement are:
- The constructor (
__init__) to set up any specific configurations (like thebase_url). - Methods that represent the individual tools (Actions) the application offers.
- The
list_tools()method to return a list of these tool methods.
applications/application.py for more information.