AgentRIntegration provides a streamlined way for your Universal MCP applications to authenticate with services when your credentials and application configurations are managed through the AgentR platform (agentr.dev).
How AgentRIntegration Works
Instead of managing individual API keys or OAuth flows directly within your local Universal MCP server configuration for each service, AgentRIntegration centralizes this by communicating with the AgentR API.
-
Initialization: You initialize
AgentRIntegrationwith aname(which corresponds to the integration name defined on the AgentR platform, e.g., “github”, “google-mail”) and your AgentR API key. -
Getting Credentials: When an
Applicationneeds credentials (e.g.,my_github_app.integration.get_credentials()), theAgentRIntegrationuses itsAgentrClientto make an API call tohttps://api.agentr.dev/api/{integration_name}/credentials/.- This request is authenticated using your main AgentR API key.
- The AgentR API returns the specific credentials (e.g., an OAuth access token for GitHub) that AgentR has stored for you for that particular service integration.
-
Authorization Flow: If credentials are not found or are invalid,
AgentRIntegration.authorize()is called.- This method, via
AgentrClient, calls the AgentR API endpointhttps://api.agentr.dev/api/{integration_name}/authorize/. - The AgentR API returns an authorization URL.
- The
NotAuthorizedErrorraised byget_credentialswill include this URL, prompting the user to visit it to authorize the application via the AgentR platform. AgentR then securely handles the OAuth dance or credential input and stores the resulting token/key.
- This method, via
AgentrClient
The AgentrClient (from utils/agentr.py) is a helper class used internally by AgentRIntegration. It’s responsible for:
- Making authenticated GET requests to the AgentR API endpoints.
- Requires an
AGENTR_API_KEY(either passed during initialization or from the environment variable). - Fetching service-specific credentials.
- Fetching authorization URLs.
- Fetching a list of applications configured for your account on AgentR (used by
AgentRServer).
Usage in Applications
When you load an application that is intended to be used with AgentR-managed credentials, you pass anAgentRIntegration instance to it.
Example from examples/reddit_summary.py:
reddit_app or email_app need to make an API call, their _get_headers() method will ask their AgentRIntegration for credentials. The integration will then fetch the necessary tokens from the AgentR backend.
AgentRServer
If you configure your Universal MCP server with type: "agentr" in ServerConfig, it becomes an AgentRServer. This server type:
- Uses
AgentrClientto fetch the list of applications (AppConfig) you have enabled on the AgentR platform. - For each fetched application, it automatically configures an
AgentRIntegrationfor it. - This means you don’t need to list
appsor their specific integrations in your localServerConfigfile; AgentR becomes the source of truth for that.
AgentRIntegration simplifies credential management by delegating it to the AgentR platform, especially useful for OAuth-based services and when managing many integrations.